/* ============================================================================
   TechSchool — "command center" design system
   Warm-neutral canvas, a single deep-teal accent, hairline borders,
   quiet chrome / loud data. No build step; hand-authored tokens + components.
   ============================================================================ */

:root {
    --canvas:      #faf9f7;
    --surface:     #ffffff;
    --surface-alt: #f5f3f0;
    --ink:         #1c1b19;
    --muted:       #78716c;
    --faint:       #a8a29e;
    --hairline:    #e7e5e4;
    --accent:      #0f766e;
    --accent-700:  #0b5f59;
    --accent-soft: #ccfbf1;
    --ok:          #15803d;
    --warn:        #b45309;
    --danger:      #b91c1c;
    --radius:      9px;
    --shadow-sm:   0 1px 2px rgba(28,27,25,.04);
    --shadow-md:   0 6px 24px -8px rgba(28,27,25,.18);
    --sidebar-w:   232px;
    --topbar-h:    58px;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* Type roles — default to the base font; themes may remap them (e.g. Northwind
       uses Sora for display, Manrope for body, JetBrains Mono for numeric data). */
    --font-display: var(--font);
    --font-body:    var(--font);
    --font-mono:    var(--font);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--ink);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 4px; }
h2 { font-family: var(--font-display); font-size: 16px; font-weight: 600; letter-spacing: -.01em; margin: 26px 0 12px; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.muted { color: var(--muted); }

/* ---- Top bar ------------------------------------------------------------ */
.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; justify-content: space-between;
    height: var(--topbar-h); padding: 0 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--hairline);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar .brand {
    display: flex; align-items: center; gap: 10px;
    font-family: var(--font-display);
    font-weight: 700; letter-spacing: -.02em; font-size: 16px; color: var(--ink);
}
.topbar .brand:hover { text-decoration: none; }
.nav-toggle {
    display: none;               /* hidden on desktop; shown on mobile */
    align-items: center; justify-content: center;
    width: 38px; height: 38px; padding: 0;
    border: 1px solid var(--hairline); border-radius: 8px;
    background: var(--surface); color: #44403c; cursor: pointer;
}
.nav-toggle:hover { background: var(--surface-alt); }
.nav-backdrop { display: none; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 8px;
    background: var(--accent); color: #fff; font-weight: 700; font-size: 14px;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.who { font-size: 13px; color: var(--muted); }
.who strong { color: var(--ink); font-weight: 600; }
.logout-form { margin: 0; }

/* ---- Shell + sidebar ---------------------------------------------------- */
.shell { display: flex; flex: 1; }
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--hairline);
    padding: 14px 12px;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 12px; margin: 1px 0;
    border-radius: 8px;
    color: #44403c; font-size: 13.5px; font-weight: 500;
    border-left: 2px solid transparent;
}
.sidebar li a:hover { background: var(--surface-alt); text-decoration: none; color: var(--ink); }
.sidebar li a.active {
    background: var(--accent-soft);
    color: var(--accent-700);
    border-left-color: var(--accent);
    font-weight: 600;
}
.sidebar .nav-group { padding: 0; }
.nav-group-btn {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; padding: 16px 12px 6px; margin: 0;
    background: none; border: none; cursor: pointer; font-family: inherit; text-align: left;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
    color: var(--faint); transition: color var(--dur, .18s) ease;
}
.nav-group-btn:hover { color: var(--muted); }
.nav-chevron {
    width: 13px; height: 13px; flex-shrink: 0; opacity: .75;
    transition: transform var(--dur, .18s) ease;
}
.nav-group.collapsed .nav-chevron { transform: rotate(-90deg); }

/* ---- Content ------------------------------------------------------------ */
.content { flex: 1; padding: 30px 36px; max-width: 1180px; display: flex; flex-direction: column; }

/* ---- Flash messages ----------------------------------------------------- */
.flash {
    padding: 11px 15px; border-radius: var(--radius); margin-bottom: 20px;
    font-size: 13.5px; border: 1px solid transparent;
}
.flash-success { background: #ecfdf5; color: #066e4b; border-color: #a7f3d0; }
.flash-error   { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

/* ---- Tables ------------------------------------------------------------- */
table {
    width: 100%; border-collapse: separate; border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
thead th {
    text-align: left; padding: 11px 16px;
    background: var(--surface-alt);
    color: var(--muted); font-weight: 600; font-size: 11px;
    text-transform: uppercase; letter-spacing: .05em;
    border-bottom: 1px solid var(--hairline);
}
tbody td { padding: 12px 16px; font-size: 13.5px; border-bottom: 1px solid var(--hairline); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfaf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-family: var(--font-mono); }
/* key-value detail tables (th in first column) */
table tr > th:first-child {
    background: var(--surface-alt); color: var(--muted);
    width: 210px; vertical-align: top;
}

/* ---- Buttons ------------------------------------------------------------ */
.btn, button.btn {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--accent); color: #fff; border: 1px solid var(--accent);
    padding: 8px 15px; border-radius: 8px;
    font-size: 13.5px; font-weight: 600; font-family: inherit;
    cursor: pointer; text-decoration: none; line-height: 1.2;
    transition: background .12s ease;
}
.btn:hover { background: var(--accent-700); border-color: var(--accent-700); text-decoration: none; }
.btn-secondary { background: var(--surface); color: #44403c; border-color: var(--hairline); }
.btn-secondary:hover { background: var(--surface-alt); border-color: #d6d3d1; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }
.btn-link {
    background: none; border: none; padding: 0; cursor: pointer;
    color: var(--accent); font-size: 13px; font-family: inherit; text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.inline-form { display: inline; margin: 0; }

/* ---- Forms -------------------------------------------------------------- */
form.card {
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: 12px; padding: 24px; max-width: 580px; box-shadow: var(--shadow-sm);
}
.field { margin-bottom: 16px; }
.field > label {
    display: block; font-size: 12px; font-weight: 600; color: #57534e;
    margin-bottom: 6px; letter-spacing: .01em;
}
.field input[type=text], .field input[type=number], .field input[type=date],
.field input[type=email], .field input[type=password], .field select, .field textarea,
input[type=text], input[type=password], select {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--hairline); border-radius: 8px;
    font-size: 14px; font-family: inherit; color: var(--ink);
    background: var(--surface); transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus, .field textarea:focus,
input:focus, select:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15,118,110,.15);
}
.field input::placeholder { color: var(--faint); }

/* Custom-styled select (kills the "cheap" native dropdown look) */
select {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    padding-right: 38px; cursor: pointer;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 13px center;
}
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 5px; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.checks label {
    display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--ink);
    margin: 0; font-size: 13.5px;
}
.checks input[type=checkbox], .field input[type=checkbox] { width: auto; accent-color: var(--accent); }
.field label input[type=checkbox] { margin-right: 8px; }

/* ---- Long sectioned forms (e.g. student application) -------------------- */
/* Override the default 580px cap so multi-section capture forms can breathe. */
form.card.form-wide { max-width: 900px; }

.form-section {
    border: 1px solid var(--hairline); border-radius: var(--radius);
    padding: 6px 20px 18px; margin: 0 0 22px; background: var(--surface);
}
.form-section > legend {
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--accent-700); padding: 2px 10px; margin-left: -2px;
    background: var(--accent-soft); border-radius: 999px;
}
.form-section .section-hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 14px; }

/* Two-column field layout that collapses on narrow screens. */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
.form-grid .field.span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* Repeated guardian sub-block within a section. */
.subblock { border-top: 1px dashed var(--hairline); margin-top: 14px; padding-top: 14px; }
.subblock > h4 {
    font-size: 12.5px; font-weight: 700; color: var(--ink); margin: 0 0 12px;
    letter-spacing: .01em;
}
/* Inline yes/no + checkbox-set row */
.checks-inline { display: flex; flex-wrap: wrap; gap: 16px; }
.checks-inline label { display: inline-flex; align-items: center; gap: 7px; font-weight: 400; font-size: 13.5px; margin: 0; }

/* ---- Pills / badges ----------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
    background: var(--surface-alt); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: var(--faint); }
.badge-core { background: var(--accent-soft); color: var(--accent-700); }
.badge-core::before { background: var(--accent); }

/* ---- KPI / overview cards ---------------------------------------------- */
.kpi-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px; margin: 22px 0 8px;
}
.kpi {
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.kpi .kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi .kpi-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: 12.5px; color: var(--faint); margin-top: 2px; }

/* ---- Card grid of links (dashboard) ------------------------------------ */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 8px; }
.tile {
    display: block; background: var(--surface); border: 1px solid var(--hairline);
    border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow-sm);
    transition: border-color .12s, box-shadow .12s, transform .12s;
}
.tile:hover { text-decoration: none; border-color: #d6d3d1; box-shadow: var(--shadow-md); transform: translateY(-1px); }
.tile .tile-title { font-weight: 600; color: var(--ink); font-size: 14.5px; }
.tile .tile-desc { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* ---- Timetable grid ----------------------------------------------------- */
.tt-table { table-layout: fixed; }
.tt-table thead th { text-align: center; }
.tt-table thead th:first-child { text-align: left; width: 120px; }
.tt-table td { vertical-align: top; padding: 6px; }
.tt-time { background: var(--surface-alt); white-space: nowrap; font-size: 12.5px; }
.tt-break { background: repeating-linear-gradient(45deg, #faf9f7, #faf9f7 8px, #f3f1ee 8px, #f3f1ee 16px); color: var(--muted); text-align: center; font-size: 12px; }
.tt-lesson { background: var(--accent-soft); border: 1px solid #99f6e4; border-radius: 7px; padding: 7px 9px; }
.tt-subject { font-weight: 600; font-size: 12.5px; color: var(--accent-700); }
.tt-meta { font-size: 11.5px; color: #57534e; }
.tt-remove { font-size: 11px; color: var(--danger); margin-top: 3px; display: inline-block; }
.tt-add { display: block; text-align: center; color: var(--faint); font-size: 12px; padding: 10px 4px; border: 1px dashed var(--hairline); border-radius: 7px; }
.tt-add:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; background: #fbfaf9; }
.pub-tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-alt); border: 1px solid var(--hairline); border-radius: 10px; }
.pub-tab { padding: 7px 16px; border-radius: 7px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.pub-tab:hover { text-decoration: none; color: var(--ink); }
.pub-tab.active { background: var(--surface); color: var(--accent-700); box-shadow: var(--shadow-sm); }

/* ---- Print / Save-as-PDF (timetables) ----------------------------------- */
.print-only { display: none; }
@media print {
    @page { size: A4 landscape; margin: 12mm; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    /* Hide all on-screen chrome — print only the header + the grid. */
    .topbar, .sidebar, .nav-backdrop, .pub-tabs, .actions, .flash,
    .app-footer, .tt-add, .tt-lesson form, .no-print, select, .logout-form { display: none !important; }
    .print-only { display: block !important; }
    body { background: #fff; color: #1c1b19; font-size: 11px; }
    .shell { display: block !important; }
    .content, main { padding: 0 !important; margin: 0 !important; max-width: none !important; }

    /* Polished print header */
    .print-head { border-bottom: 2px solid var(--accent); padding-bottom: 8px; margin-bottom: 14px; }
    .ph-row { display: flex; align-items: baseline; justify-content: space-between; }
    .ph-brand { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
    .ph-label { font-size: 10px; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); font-weight: 700; }
    .ph-title { font-size: 13px; font-weight: 600; color: #44403c; margin-top: 4px; }

    /* Clean grid for paper */
    .tt-table { box-shadow: none; border: 1px solid #cbd5e1; border-radius: 0; }
    .tt-table thead th { background: #eef2f1 !important; color: var(--accent-700);
        border-bottom: 1.5px solid var(--accent); font-size: 10px; }
    .tt-table td, .tt-table th { padding: 5px 7px; }
    .tt-time { background: #f6f7f8 !important; }
    .tt-lesson { background: #f0fdfa !important; border: 1px solid #99f6e4 !important; padding: 4px 6px; }
    .tt-subject { color: var(--accent-700) !important; font-size: 11px; }
    .tt-meta { color: #57534e; }
}

/* ---- Auth / landing ----------------------------------------------------- */
.auth { display: grid; grid-template-columns: 1.05fr 1fr; flex: 1; min-height: 0; }
.auth-brand {
    position: relative; overflow: hidden;
    background: linear-gradient(150deg, #0f766e 0%, #115e59 55%, #134e4a 100%);
    color: #fff; padding: 56px 60px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-brand::after {
    content: ""; position: absolute; right: -120px; bottom: -120px;
    width: 360px; height: 360px; border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,.10), transparent 70%);
}
.auth-brand .brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.auth-brand .brand .brand-mark { background: rgba(255,255,255,.16); width: 34px; height: 34px; }
.auth-hero h1 { font-size: 38px; line-height: 1.12; letter-spacing: -.02em; margin: 0 0 16px; }
.auth-hero p { font-size: 15.5px; line-height: 1.6; color: rgba(255,255,255,.82); max-width: 30em; margin: 0; }
.auth-points { list-style: none; padding: 0; margin: 24px 0 0; display: flex; flex-direction: column; gap: 10px; }
.auth-points li { display: flex; align-items: center; gap: 10px; font-size: 14px; color: rgba(255,255,255,.9); }
.auth-points li::before { content: "✓"; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 999px; background: rgba(255,255,255,.18); font-size: 12px; }
.auth-foot { font-size: 12.5px; color: rgba(255,255,255,.6); }
.auth-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; background: var(--canvas); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 24px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 4px; text-transform: none; color: var(--ink); }
.auth-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 26px; }
.auth-card .field input { padding: 11px 13px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 14.5px; margin-top: 4px; }
.auth-alert { padding: 10px 13px; border-radius: 8px; font-size: 13px; margin-bottom: 18px; }
.auth-alert.err { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.auth-alert.ok { background: #ecfdf5; color: #066e4b; border: 1px solid #a7f3d0; }
.auth-hint { margin-top: 22px; font-size: 12.5px; color: var(--faint); text-align: center; }

@media (max-width: 860px) {
    .auth { grid-template-columns: 1fr; }
    .auth-brand { padding: 40px 32px; min-height: 220px; }

    /* Hamburger reveals the menu; the sidebar slides in as a drawer. */
    .nav-toggle { display: inline-flex; }
    .shell { display: block; }
    .sidebar {
        position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
        width: 264px; max-width: 82vw; z-index: 40;
        padding: 14px 12px; overflow-y: auto;
        border-right: 1px solid var(--hairline); border-bottom: none;
        transform: translateX(-102%);
        transition: transform .22s ease;
        box-shadow: var(--shadow-md);
    }
    .sidebar.open { transform: translateX(0); }
    .nav-backdrop.show {
        display: block; position: fixed; inset: var(--topbar-h) 0 0 0;
        background: rgba(28,27,25,.38); z-index: 35;
    }
    .content { padding: 22px 18px; }
}

/* Attribution footer — slim full-width bar pinned to the bottom of every page */
.app-footer {
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 4px 18px;
    background: var(--surface);
    border-top: 1px solid var(--hairline);
    color: var(--muted);
    font-family: var(--font);   /* Inter */
    font-size: 11px;
    line-height: 1.25;
    text-align: center;
}
.app-footer-credit { letter-spacing: .01em; }
.app-footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }
.app-version { color: var(--faint); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---- System resources page --------------------------------------------- */
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 8px; }
.res-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.res-card .res-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.res-card .res-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.res-card .res-sub { font-size: 12.5px; color: var(--faint); margin-top: 2px; font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-alt); margin-top: 12px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .4s ease, background .4s ease; }
.meter-fill.warn { background: var(--warn); }
.meter-fill.danger { background: var(--danger); }
.res-meta { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-top: 18px; color: var(--muted); font-size: 13px; }
.res-meta b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.res-updated { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ============================================================================
   UI POLISH LAYER (Phase 1): motion · animated buttons · toasts · dark mode · responsive
   ============================================================================ */
:root { --ease: cubic-bezier(.4, 0, .2, 1); --dur: .18s; }

/* Respect users who prefer less motion — kill animation/transition globally for them. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important; animation-iteration-count: 1 !important;
        transition-duration: .001ms !important; scroll-behavior: auto !important;
    }
}

/* Keyboard focus ring (accessible, only on keyboard nav) */
a:focus-visible, .btn:focus-visible, button:focus-visible, .btn-link:focus-visible,
.tile:focus-visible, select:focus-visible, .pub-tab:focus-visible, .theme-toggle:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px;
}

/* Animated buttons: hover lift, press, loading spinner */
.btn, button.btn {
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
                box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0) scale(.985); box-shadow: var(--shadow-sm); }
.btn[disabled], .btn.is-loading { opacity: .65; pointer-events: none; }
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
    content: ""; position: absolute; top: 50%; left: 50%; width: 15px; height: 15px;
    margin: -7.5px 0 0 -7.5px; border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Content entrance + card/row motion */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.content > section { animation: fadeInUp .32s var(--ease) both; }
.kpi, .res-card { transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
.kpi:hover, .res-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.sidebar li a { transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease); }
tbody tr { transition: background var(--dur) var(--ease); }

/* Theme toggle button (topbar) */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0; border-radius: 8px;
    border: 1px solid var(--hairline); background: var(--surface); color: var(--muted);
    cursor: pointer; transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.theme-toggle:hover { background: var(--surface-alt); color: var(--ink); }
.theme-toggle .icon-sun { display: none; }
[data-mode="dark"] .theme-toggle .icon-sun { display: block; }
[data-mode="dark"] .theme-toggle .icon-moon { display: none; }

/* Toasts (flash messages float in, auto-dismiss) */
.toast-stack {
    position: fixed; top: calc(var(--topbar-h) + 12px); right: 16px; z-index: 60;
    display: flex; flex-direction: column; gap: 10px; max-width: min(92vw, 360px);
}
.toast {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
    border-radius: 10px; font-size: 13.5px; color: var(--ink);
    background: var(--surface); border: 1px solid var(--hairline); box-shadow: var(--shadow-md);
    animation: toastIn .26s var(--ease) both;
}
.toast.hide { animation: toastOut .25s var(--ease) forwards; }
.toast.success { border-left: 3px solid var(--ok); }
.toast.error { border-left: 3px solid var(--danger); }
.toast-close { margin-left: auto; background: none; border: none; color: var(--faint); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(16px); } }

/* ---- Dark mode: remap tokens (token-driven components flip automatically) ---- */
[data-mode="dark"] {
    --canvas:      #1a1816;
    --surface:     #221f1c;
    --surface-alt: #2b2723;
    --ink:         #f3f0ec;
    --muted:       #b3aaa1;
    --faint:       #837a70;
    --hairline:    #36312b;
    --accent:      #2dd4bf;
    --accent-700:  #5eead4;
    --accent-soft: rgba(45, 212, 191, .15);
    --ok:          #34d399;
    --warn:        #fbbf24;
    --danger:      #f87171;
    --shadow-sm:   0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md:   0 8px 28px -8px rgba(0, 0, 0, .6);
}
/* Dark fixes for the handful of hard-coded colours */
[data-mode="dark"] .sidebar li a { color: #cfc8c0; }
[data-mode="dark"] .btn-secondary, [data-mode="dark"] .nav-toggle { color: var(--ink); }
[data-mode="dark"] tbody tr:hover { background: #2b2723; }
[data-mode="dark"] .tile:hover { border-color: #4a443d; }
[data-mode="dark"] .flash-success { background: rgba(52, 211, 153, .12); color: #6ee7b7; border-color: rgba(52, 211, 153, .3); }
[data-mode="dark"] .flash-error,
[data-mode="dark"] .auth-alert.err { background: rgba(248, 113, 113, .12); color: #fca5a5; border-color: rgba(248, 113, 113, .3); }
[data-mode="dark"] .auth-alert.ok { background: rgba(52, 211, 153, .12); color: #6ee7b7; border-color: rgba(52, 211, 153, .3); }
[data-mode="dark"] .tt-break { background: repeating-linear-gradient(45deg, #221f1c, #221f1c 8px, #2b2723 8px, #2b2723 16px); }
[data-mode="dark"] .tt-lesson { border-color: rgba(45, 212, 191, .4); }
[data-mode="dark"] .tt-meta { color: var(--muted); }

/* ---- Responsive refinements ---- */
@media (max-width: 680px) {
    .content { padding: 18px 14px; }
    h1 { font-size: 20px; }
    /* Wide tables (esp. the timetable) scroll horizontally instead of squashing */
    .content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tt-table { min-width: 560px; }
    .btn, button.btn { padding: 9px 14px; }   /* comfortable tap targets */
    .actions { gap: 8px; }
    .toast-stack { left: 12px; right: 12px; max-width: none; }
    form.card { padding: 18px; }
}

/* ---- Address autocomplete ---------------------------------------------- */
.addr-search { position: relative; }
.addr-suggestions {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
    background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
    box-shadow: var(--shadow-md); margin-top: 4px; max-height: 260px; overflow-y: auto;
}
.addr-suggestion { padding: 9px 12px; font-size: 13.5px; cursor: pointer; }
.addr-suggestion:hover, .addr-suggestion.active { background: var(--surface-alt); }
.addr-hint { font-size: 12px; margin-top: 5px; }
.addr-geo { font-size: 12.5px; margin-top: 8px; color: var(--ok); font-variant-numeric: tabular-nums; }

/* ---- Reporting / map --------------------------------------------------- */
.report-map {
    height: 70vh; min-height: 420px; margin-top: 12px;
    border: 1px solid var(--hairline); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); z-index: 0;
}

/* ============================================================================
   UI POLISH LAYER (Phase 2): iconography · page headers · empty states
   ============================================================================ */

/* Generic icon sizing (sprite symbols inherit colour via currentColor) */
.btn svg, .btn-link svg { width: 15px; height: 15px; flex-shrink: 0; }

/* Sidebar nav icons — quiet by default, accent when the row is active */
.nav-ico { width: 16px; height: 16px; flex-shrink: 0; color: var(--faint);
    transition: color var(--dur) var(--ease); }
.sidebar li a:hover .nav-ico { color: var(--muted); }
.sidebar li a.active .nav-ico { color: var(--accent); }

/* Dashboard tile: icon chip that fills with accent on hover */
.tile-ico {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 9px; margin-bottom: 12px;
    background: var(--accent-soft); color: var(--accent-700); flex-shrink: 0;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tile-ico svg { width: 18px; height: 18px; }
.tile:hover .tile-ico { background: var(--accent); color: #fff; }

/* KPI card corner icon */
.kpi { position: relative; }
.kpi-ico {
    position: absolute; top: 15px; right: 15px;
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--surface-alt); color: var(--muted);
}
.kpi-ico svg { width: 16px; height: 16px; }

/* Page header — title + subtitle on the left, primary action on the right */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px 20px; flex-wrap: wrap; margin-bottom: 24px;
}
.page-header .page-header-text { min-width: 0; }
.page-header h1 { margin: 0; }
.page-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; }
.page-header .actions { margin: 2px 0 0; }

/* Empty state — friendly placeholder where a table/list would be */
.empty-state {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    gap: 3px; padding: 54px 24px;
    background: var(--surface); border: 1px dashed var(--hairline); border-radius: 12px;
    animation: fadeInUp .32s var(--ease) both;
}
.empty-ico { width: 44px; height: 44px; color: var(--faint); margin-bottom: 10px; }
.empty-title { font-weight: 600; font-size: 15px; color: var(--ink); }
.empty-msg { margin: 0; color: var(--muted); font-size: 13.5px; max-width: 36em; }
.empty-state .btn { margin-top: 14px; }

/* ============================================================================
   THEME SYSTEM: two axes — data-theme (palette) × data-mode (light|dark)
   :root defines the default "Teal" palette (light). [data-mode="dark"] above
   remaps tokens for night. Each additional palette overrides the same tokens
   under [data-theme="<id>"] (light) and [data-theme="<id>"][data-mode="dark"].
   To add a theme: copy a block below, pick new tokens, and register it in the
   THEMES list in layout/base.html. Components are token-driven, so they reflow.
   ============================================================================ */

/* ---- Top-bar theme picker (dropdown next to the light/dark toggle) ---- */
.theme-picker { position: relative; }
.theme-menu {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
    min-width: 184px; padding: 6px;
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: 10px; box-shadow: var(--shadow-md);
    animation: toastIn .16s var(--ease) both;
}
.theme-menu[hidden] { display: none; }
.theme-menu-label {
    padding: 6px 10px 4px; font-size: 10.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .07em; color: var(--faint);
}
.theme-option {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 8px 10px; border: none; border-radius: 7px;
    background: none; cursor: pointer; font-family: inherit; font-size: 13.5px;
    color: var(--ink); text-align: left;
    transition: background var(--dur) var(--ease);
}
.theme-option:hover { background: var(--surface-alt); }
.theme-swatch {
    width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, .12); background: var(--sw, var(--accent));
}
.theme-option .theme-check { margin-left: auto; color: var(--accent); opacity: 0; }
.theme-option .theme-check svg { width: 15px; height: 15px; display: block; }
.theme-option[aria-checked="true"] { font-weight: 600; }
.theme-option[aria-checked="true"] .theme-check { opacity: 1; }

/* ============================================================================
   ENRICHED COMPONENTS (theme-agnostic — token-driven, used across all themes)
   ============================================================================ */

/* Button variants: soft (tinted) and ghost (text-only) */
.btn-soft { background: var(--accent-soft); color: var(--accent-700); border-color: transparent; }
.btn-soft:hover { filter: brightness(.97); border-color: transparent; }
.btn-ghost { background: transparent; color: var(--accent-700); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-alt); border-color: transparent; }

/* Semantic status pills — extend .badge (pill shape + leading dot already provided) */
.badge-success { background: color-mix(in srgb, var(--ok) 14%, var(--surface)); color: var(--ok); }
.badge-success::before { background: var(--ok); }
.badge-warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); color: var(--warn); }
.badge-warn::before { background: var(--warn); }
.badge-danger { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.badge-danger::before { background: var(--danger); }
.badge-neutral { background: var(--surface-alt); color: var(--muted); }
.badge-neutral::before { background: var(--faint); }

/* Avatar: initials on a colour from a fixed palette (caller picks .avatar-cN) */
.avatar {
    position: relative; overflow: hidden;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 36px; height: 36px; border-radius: 50%;
    font-size: 12.5px; font-weight: 600; line-height: 1; letter-spacing: .02em;
    color: #fff; background: var(--av, #475067);
}
/* Profile photo layered over the initials; if the image 404s it's removed and initials show. */
.avatar-img {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: cover; border-radius: inherit; background: var(--av, #475067);
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 56px; height: 56px; font-size: 19px; }
.avatar-xl { width: 84px; height: 84px; font-size: 28px; }

/* Profile-picture manager (upload/remove widget) */
.photo-manager { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin: 6px 0 4px; }
.photo-manager-forms { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.photo-upload-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.photo-upload-form input[type=file] { font-size: 13px; max-width: 260px; }
.avatar-c0 { --av: #2563eb; } .avatar-c1 { --av: #11875a; } .avatar-c2 { --av: #0e7c86; }
.avatar-c3 { --av: #6b4fd1; } .avatar-c4 { --av: #b07314; } .avatar-c5 { --av: #475067; }

/* People cell: avatar + name/email stack (for list rows) */
.person-cell { display: flex; align-items: center; gap: 11px; }
.person-cell .person-name { font-weight: 600; color: var(--ink); }
.person-cell .person-sub { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Profile header card (detail pages): avatar + identity + right-aligned actions */
.profile-header {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--hairline);
    border-radius: 12px; padding: 20px 22px; box-shadow: var(--shadow-sm);
    margin-bottom: 22px;
}
.profile-header h1 { margin: 0; }
.profile-header .ph-meta { margin: 7px 0 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.profile-header .ph-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ============================================================================
   THEME: Northwind — cool-gray neutrals · blue accent · geometric type
   (Sora display · Manrope body · JetBrains Mono numerics)
   ============================================================================ */
[data-theme="northwind"] {
    --canvas:      #f4f6f9;
    --surface:     #ffffff;
    --surface-alt: #fafbfc;
    --ink:         #1a2233;
    --muted:       #7a8499;
    --faint:       #9aa3b2;
    --hairline:    #e4e8ee;
    --accent:      #2563eb;
    --accent-700:  #1f56ce;
    --accent-soft: #e9f0fe;
    --ok:          #11875a;
    --warn:        #b07314;
    --danger:      #d03a3a;
    --radius:      8px;
    --shadow-sm:   0 1px 3px rgba(16, 24, 40, .06);
    --shadow-md:   0 6px 20px rgba(16, 24, 40, .10);
    --font-display: "Sora", var(--font);
    --font-body:    "Manrope", var(--font);
    --font-mono:    "JetBrains Mono", ui-monospace, monospace;
}
/* Northwind component nudges (light) */
[data-theme="northwind"] thead th { letter-spacing: .04em; }
[data-theme="northwind"] tbody tr:hover { background: #f7f9fc; }
[data-theme="northwind"] .btn { border-radius: 7px; }
[data-theme="northwind"] .field input, [data-theme="northwind"] .field select,
[data-theme="northwind"] .field textarea,
[data-theme="northwind"] input[type=text], [data-theme="northwind"] input[type=password],
[data-theme="northwind"] select { border-color: #d2d8e0; }
[data-theme="northwind"] .field input:focus, [data-theme="northwind"] .field select:focus,
[data-theme="northwind"] input:focus, [data-theme="northwind"] select:focus {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

[data-theme="northwind"][data-mode="dark"] {
    --canvas:      #0e1320;
    --surface:     #161c2b;
    --surface-alt: #1b2233;
    --ink:         #e8ecf3;
    --muted:       #9aa3b2;
    --faint:       #6b7689;
    --hairline:    #283044;
    --accent:      #5b8def;
    --accent-700:  #93b4f7;
    --accent-soft: rgba(91, 141, 239, .16);
    --ok:          #34d39e;
    --warn:        #e0a93f;
    --danger:      #f06a6a;
    --shadow-sm:   0 1px 3px rgba(0, 0, 0, .4);
    --shadow-md:   0 8px 28px -8px rgba(0, 0, 0, .6);
}
[data-theme="northwind"][data-mode="dark"] tbody tr:hover { background: #1b2233; }
[data-theme="northwind"][data-mode="dark"] .sidebar li a { color: #c2c9d4; }
[data-theme="northwind"][data-mode="dark"] .field input, [data-theme="northwind"][data-mode="dark"] select,
[data-theme="northwind"][data-mode="dark"] input[type=text] { border-color: #2f3850; }

/* ============================================================================
   REPORT CARDS — printable end-of-term / end-of-year report (A4 portrait)
   ============================================================================ */
.rc-toolbar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px;
    padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--hairline);
}
.rc-sheet { background: var(--surface-alt); padding: 24px 0; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.report-card {
    width: 210mm; max-width: 100%; box-sizing: border-box;
    background: #fff; color: #1c1b19; padding: 15mm 16mm 13mm; box-shadow: var(--shadow-md);
    font-family: var(--font-body);
}
.rc-head { display: flex; align-items: center; gap: 16px; border-bottom: 2px solid var(--accent); padding-bottom: 12px; }
.rc-logo { height: 58px; width: auto; max-width: 150px; object-fit: contain; }
.rc-school { flex: 1; min-width: 0; }
.rc-school-name { font-family: var(--font-display); font-size: 20px; font-weight: 700; color: #1a2233; }
.rc-school-meta { font-size: 11.5px; color: #555; margin-top: 3px; }
.rc-label { font-family: var(--font-display); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); text-align: right; }
.rc-student { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px 22px; margin: 16px 0; }
.rc-k { display: block; font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; color: #888; }
.rc-v { font-size: 13px; font-weight: 600; color: #1a2233; }
.rc-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12px; }
.rc-table th, .rc-table td { border: 1px solid #d8dce2; padding: 6px 9px; text-align: left; }
.rc-table thead th { background: #f2f4f7; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #555; }
.rc-table td.num, .rc-table th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.rc-cover { margin: 12px 0; }
.rc-cover-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px 22px; margin-bottom: 10px; }
.rc-comment { font-size: 12px; margin-top: 6px; min-height: 20px; border-bottom: 1px dotted #ccc; padding-bottom: 4px; }
.rc-comment .rc-k { display: inline; margin-right: 8px; }
.rc-legend { font-size: 9.5px; color: #666; margin: 14px 0; line-height: 1.7; }
.rc-sign { display: flex; gap: 26px; margin-top: 28px; }
.rc-sign-line { flex: 1; border-top: 1px solid #333; padding-top: 4px; font-size: 10px; color: #555; text-align: center; }

@page rcPortrait { size: A4 portrait; margin: 12mm; }
@media print {
    .rc-toolbar { display: none !important; }
    .rc-sheet { background: #fff; padding: 0; gap: 0; display: block; }
    .report-card { width: auto; box-shadow: none; padding: 0; page: rcPortrait; page-break-after: always; }
    .report-card:last-child { page-break-after: auto; }
}

/* ---- Error pages (404 / 403 / 500 / generic) --------------------------- */
.error-wrap {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 48px 20px;
}
.error-card { max-width: 460px; }
.error-code {
    font-family: var(--font-display); font-size: 66px; font-weight: 700;
    letter-spacing: -.03em; line-height: 1; color: var(--accent);
}
.error-card h1 { font-size: 22px; margin: 12px 0 6px; }
.error-card p { color: var(--muted); margin: 0 0 22px; }
.error-card .actions { justify-content: center; }
