/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --sidebar-w: 250px;
    --topbar-h: 60px;

    --c-primary:        #2563eb;
    --c-primary-dark:   #1d4ed8;
    --c-sidebar-bg:     #1e293b;
    --c-sidebar-text:   #94a3b8;
    --c-sidebar-hover:  rgba(255,255,255,0.08);
    --c-sidebar-active: rgba(37,99,235,0.25);
    --c-sidebar-active-text: #60a5fa;
    --c-topbar-bg:      #ffffff;
    --c-body-bg:        #f1f5f9;
    --c-card-bg:        #ffffff;
    --c-text:           #0f172a;
    --c-text-muted:     #64748b;
    --c-border:         #e2e8f0;

    --c-success:     #16a34a;
    --c-success-bg:  #dcfce7;
    --c-danger:      #dc2626;
    --c-danger-bg:   #fee2e2;
    --c-warning:     #b45309;
    --c-warning-bg:  #fef3c7;
    --c-info:        #0284c7;
    --c-info-bg:     #e0f2fe;
    --c-secondary:   #475569;
    --c-secondary-bg: #f1f5f9;

    --radius:    6px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--c-text);
    background: var(--c-body-bg);
    line-height: 1.5;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Auth layout ───────────────────────────────────────────────────────────── */
.page-auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.auth-wrapper {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    background: var(--c-card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.brand-abbr-large {
    display: inline-block;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--c-primary);
    letter-spacing: -.05em;
}

.auth-subtitle {
    color: var(--c-text-muted);
    font-size: .875rem;
    margin-top: .25rem;
}

/* ─── App layout ────────────────────────────────────────────────────────────── */
.page-app {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--c-sidebar-bg);
    color: var(--c-sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .75rem;
}

.brand-abbr {
    font-size: 1.25rem;
    font-weight: 800;
    color: #fff;
    background: var(--c-primary);
    padding: .15rem .5rem;
    border-radius: 4px;
    letter-spacing: -.03em;
}

.brand-name {
    font-weight: 600;
    font-size: .875rem;
    color: #cbd5e1;
}

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
}

.nav-section {
    padding: .75rem 1.25rem .25rem;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #475569;
}

.nav-item {
    display: block;
    padding: .65rem 1.25rem;
    color: var(--c-sidebar-text);
    font-size: .875rem;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: var(--c-sidebar-hover);
    color: #e2e8f0;
    text-decoration: none;
}

.nav-item.active {
    background: var(--c-sidebar-active);
    color: var(--c-sidebar-active-text);
    border-left-color: var(--c-primary);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .75rem;
    color: #64748b;
    line-height: 1.4;
}

.sidebar-footer strong {
    color: #94a3b8;
}

.sidebar-logout {
    display: inline-block;
    font-size: .75rem;
    color: #64748b;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 4px;
    padding: .25rem .65rem;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.sidebar-logout:hover {
    background: rgba(255,255,255,.08);
    color: #94a3b8;
    text-decoration: none;
}

/* ─── Main wrapper ──────────────────────────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--c-topbar-bg);
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--c-border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
    gap: 1rem;
}

.page-title {
    font-size: 1rem;
    font-weight: 600;
    flex: 1;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: .25rem;
}

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--c-text-muted);
    border-radius: 2px;
}

.content {
    flex: 1;
    padding: 1.75rem 1.5rem;
}

/* ─── Cards ─────────────────────────────────────────────────────────────────── */
.card {
    background: var(--c-card-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}

.card-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    font-size: .875rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    background: #f8fafc;
    border-radius: var(--radius) var(--radius) 0 0;
}

.card-body {
    padding: 1.25rem;
}

.mt-4 { margin-top: 1.25rem; }

/* ─── Stats grid ────────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--c-card-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--c-primary);
    line-height: 1;
}

.stat-label {
    font-size: .8rem;
    color: var(--c-text-muted);
    margin-top: .35rem;
}

/* ─── Tables ────────────────────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.table th {
    padding: .65rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--c-text-muted);
    border-bottom: 2px solid var(--c-border);
    background: #f8fafc;
}

.table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}

.table tbody tr:hover td { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }
.table-sm th, .table-sm td { padding: .5rem .75rem; }
.row-inactive td { opacity: .55; }

.text-right { text-align: right; }
.float-right { float: right; }

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: .4rem;
    color: var(--c-text);
}

.form-label small, .form-label .text-muted {
    font-weight: 400;
}

.form-control {
    display: block;
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: .875rem;
    color: var(--c-text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    line-height: 1.5;
}

.form-control:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

input[type="file"].form-control {
    padding: .4rem .75rem;
}

.form-actions {
    display: flex;
    gap: .5rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary);
}
.btn-primary:hover {
    background: var(--c-primary-dark);
    border-color: var(--c-primary-dark);
    color: #fff;
}

.btn-secondary {
    background: var(--c-secondary-bg);
    color: var(--c-secondary);
    border-color: var(--c-border);
}
.btn-secondary:hover {
    background: #e2e8f0;
    color: var(--c-text);
}

.btn-danger {
    background: var(--c-danger);
    color: #fff;
    border-color: var(--c-danger);
}
.btn-danger:hover { background: #b91c1c; }

.btn-warning {
    background: #f59e0b;
    color: #fff;
    border-color: #f59e0b;
}
.btn-warning:hover { background: #d97706; }

.btn-success {
    background: var(--c-success);
    color: #fff;
    border-color: var(--c-success);
}
.btn-success:hover { background: #15803d; }

.btn-outline-light {
    background: transparent;
    color: #fff;
    border-color: rgba(255,255,255,.35);
    font-size: .8rem;
    padding: .35rem .85rem;
}
.btn-outline-light:hover { background: rgba(255,255,255,.15); color: #fff; }

.btn-sm  { padding: .35rem .75rem; font-size: .8rem; }
.btn-xs  { padding: .25rem .55rem; font-size: .75rem; }
.btn-block { width: 100%; margin-top: .5rem; padding: .65rem 1rem; font-size: 1rem; }

/* ─── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
    padding: .85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .875rem;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--c-success-bg);
    color: #14532d;
    border-color: #bbf7d0;
}

.alert-danger {
    background: var(--c-danger-bg);
    color: #7f1d1d;
    border-color: #fecaca;
}

.alert-warning {
    background: var(--c-warning-bg);
    color: #78350f;
    border-color: #fde68a;
}

.alert-info {
    background: var(--c-info-bg);
    color: #0c4a6e;
    border-color: #bae6fd;
}

/* ─── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .2em .55em;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .03em;
}

.badge-primary   { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-success   { background: var(--c-success-bg); color: #15803d; }
.badge-danger    { background: var(--c-danger-bg); color: #b91c1c; }
.badge-warning   { background: var(--c-warning-bg); color: #92400e; }
.badge-info      { background: var(--c-info-bg); color: #0369a1; }

/* ─── Utilities ─────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--c-text-muted); }
.text-sm     { font-size: .8rem; }
.mb-2        { margin-bottom: .5rem; }
.mt-3        { margin-top: .75rem; }

/* ─── Document info box ─────────────────────────────────────────────────────── */
.doc-info-box {
    background: #f8fafc;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: .875rem 1rem;
    margin-bottom: 1.25rem;
    font-size: .875rem;
}

/* ─── Checkbox list ─────────────────────────────────────────────────────────── */
.checkbox-list {
    display: grid;
    gap: .35rem;
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: .5rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .5rem .65rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: .875rem;
    transition: background .12s;
}

.checkbox-item:hover { background: #f1f5f9; }

.checkbox-item input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    accent-color: var(--c-primary);
}

.checkbox-item .text-muted {
    margin-left: auto;
}

/* ─── Wizard steps ──────────────────────────────────────────────────────────── */
.wizard-steps {
    display: flex;
    gap: 0;
    margin-bottom: 1.25rem;
    background: var(--c-card-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.wizard-step {
    flex: 1;
    text-align: center;
    padding: .65rem .5rem;
    font-size: .8rem;
    font-weight: 500;
    color: var(--c-text-muted);
    border-right: 1px solid var(--c-border);
    background: #f8fafc;
}

.wizard-step:last-child { border-right: none; }

.wizard-step.active {
    background: var(--c-primary);
    color: #fff;
    font-weight: 600;
}

.wizard-step.done {
    background: var(--c-success-bg);
    color: var(--c-success);
}

/* ─── Drop zone ──────────────────────────────────────────────────────────────── */
.drop-zone {
    border: 2px dashed var(--c-border);
    border-radius: var(--radius);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    user-select: none;
}

.drop-zone:hover       { border-color: #94a3b8; background: #fafafa; }
.drop-zone.drag-over   { border-color: var(--c-primary); background: #eff6ff; }

.drop-zone-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--c-text);
    margin: 0;
}

.drop-zone-sub {
    font-size: .8rem;
    color: var(--c-text-muted);
    margin: 0;
}

.file-tag {
    display: inline-flex;
    align-items: center;
    background: #e0f2fe;
    color: #0369a1;
    border-radius: var(--radius);
    padding: .3rem .7rem;
    font-size: .78rem;
    margin: .2rem;
    max-width: 100%;
    word-break: break-all;
}

.file-tag-error {
    background: var(--c-danger-bg);
    color: var(--c-danger);
}

/* ─── Apply-all bar ──────────────────────────────────────────────────────────── */
.apply-all-bar {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
    flex-wrap: wrap;
    background: #f8fafc;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
}

.apply-all-field {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    cursor: default;
}

.apply-all-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--c-text-muted);
}

/* ─── Bulk metadata table ────────────────────────────────────────────────────── */
.bulk-table th { white-space: nowrap; }

.bulk-input {
    width: 100%;
    padding: .3rem .5rem;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    font-size: .8rem;
    color: var(--c-text);
    background: #fff;
    transition: border-color .15s;
}

.bulk-input:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,.3);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: flex;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .table th:nth-child(4),
    .table td:nth-child(4),
    .table th:nth-child(6),
    .table td:nth-child(6) {
        display: none;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .content {
        padding: 1rem;
    }
}

/* ─── PDF Preview Modal ──────────────────────────────────────────────────────── */
.preview-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.preview-modal.is-open {
    display: flex;
}

.preview-modal-box {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 960px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--c-border);
    gap: 1rem;
    flex-shrink: 0;
}

.preview-modal-title {
    font-weight: 600;
    font-size: .875rem;
    color: var(--c-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--c-text-muted);
    padding: 0 .2rem;
    flex-shrink: 0;
}
.preview-modal-close:hover { color: var(--c-text); }

.preview-modal-frame {
    flex: 1;
    border: none;
    width: 100%;
    background: #f1f5f9;
}

/* ─── Filter bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--c-border);
    background: #fafafa;
}

.filter-form {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
    flex-wrap: wrap;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    min-width: 130px;
}

.filter-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--c-text-muted);
}

.filter-select {
    min-width: 130px;
}

.filter-actions {
    display: flex;
    gap: .4rem;
    align-items: center;
    padding-bottom: 1px;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--c-border);
    color: var(--c-text-muted);
    padding: .3rem .75rem;
    border-radius: var(--radius);
    font-size: .8rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.btn-outline:hover {
    background: var(--c-border);
    color: var(--c-text);
    text-decoration: none;
}

/* ─── Year group rows ────────────────────────────────────────────────────────── */
.year-group-header td {
    padding: 0;
    background: #f1f5f9;
    border-bottom: 1px solid var(--c-border);
}

.year-toggle {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .45rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-size: .85rem;
    color: var(--c-text);
    text-align: left;
}

.year-toggle::before {
    content: '▾';
    font-size: .75rem;
    transition: transform .15s;
    display: inline-block;
    width: .8rem;
}

.year-toggle.collapsed::before {
    transform: rotate(-90deg);
}

.year-count {
    font-size: .72rem;
    font-weight: 600;
    background: var(--c-border);
    color: var(--c-text-muted);
    border-radius: 10px;
    padding: .1rem .5rem;
}
