/* ============================================================
   style.css  –  TeachHub Design System
   Mobile-first, responsive, cross-platform
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
    --primary: #22c55e;
    --primary-dark: #16a34a;
    --primary-light: #dcfce7;
    --primary-gradient: linear-gradient(135deg,#22c55e 0%,#16a34a 100%);
    --accent: #7c3aed;
    --success: #059669; --success-light: #d1fae5;
    --danger: #dc2626;  --danger-light: #fee2e2;
    --warning: #d97706; --warning-light: #fef3c7;
    --info: #3b82f6;    --info-light: #dbeafe;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-focus: #86efac;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.06);
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --navbar-h: 56px;
    --bottomnav-h: 58px;          /* mobile bottom navigation bar */
    --tap: 44px;                  /* minimum touch target */
    --sidebar-min: 280px;
    --sidebar-max: 600px;
    --sidebar-default: 380px;
    --transition: 200ms ease;
    /* Fluid type ramp — scales smoothly from 360px → 1440px instead of
       jumping at each breakpoint. Used by content displays + headings. */
    --fs-body: clamp(0.875rem, 0.82rem + 0.3vw, 0.95rem);
    --fs-h1: clamp(1.2rem, 1.05rem + 0.9vw, 1.5rem);
    --fs-h2: clamp(1.05rem, 0.95rem + 0.6vw, 1.25rem);
    --fs-h3: clamp(0.95rem, 0.9rem + 0.35vw, 1.05rem);
}

/* ---------- Reset / Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
}
.no-select { user-select: none !important; -webkit-user-select: none !important; }

/* ---------- App Shell ---------- */
.app-navbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--navbar-h);
    /* Was space-between (only correct with 2 children). Account chip
       became a 3rd child, so we switch to flex-start and let the
       chip's margin-left:auto + nav-links margin push them to the right. */
    display: flex; align-items: center; justify-content: flex-start;
    gap: 12px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.nav-brand {
    display: flex; align-items: center; gap: 8px;
    font-weight: 700; font-size: .95rem; color: var(--primary-dark);
    text-decoration: none;
}
.nav-brand .nav-logo { font-size: 24px; color: var(--primary); }
.nav-hamburger {
    display: none;
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--text-secondary); border-radius: 6px;
    align-items: center; justify-content: center;
}
.nav-hamburger:hover { background: var(--primary-light); color: var(--primary-dark); }
/* margin-left:auto lives on .nav-account; .nav-links sits naturally to its left. */
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-link {
    display: flex; align-items: center; gap: 4px;
    padding: 6px 12px; border-radius: 6px;
    font-size: .82rem; font-weight: 500; text-decoration: none;
    color: var(--text-secondary); transition: all var(--transition);
}
.nav-link:hover { background: var(--primary-light); color: var(--primary-dark); }
.nav-link.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
/* ============================================================
   Workflow chooser overlay — first-touch screen on /lessons + /paper
   so users pick "Use Database / Upload / Manual" before the form
   appears. Built by TA.ui.showWorkflowChooser in shared.js.
   ============================================================ */
.th-flow-overlay {
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(15, 23, 42, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: thFlowFade .12s ease-out;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
@keyframes thFlowFade { from { opacity: 0; } to { opacity: 1; } }
.th-flow-card {
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .25);
    padding: 24px 22px 18px;
    width: 100%;
    max-width: 520px;
    max-height: 92dvh;
    overflow-y: auto;
}
.th-flow-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: #0f172a;
    margin: 0 0 6px;
    letter-spacing: -.01em;
    line-height: 1.2;
}
.th-flow-sub {
    font-size: .85rem;
    color: #64748b;
    margin: 0 0 18px;
    line-height: 1.5;
}
.th-flow-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}
.th-flow-option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    text-align: left;
    cursor: pointer;
    font: inherit;
    transition: border-color .15s ease, background .15s ease, transform .08s ease;
}
.th-flow-option:hover { border-color: var(--primary); background: #f8fafc; }
.th-flow-option:active { transform: translateY(1px); }
.th-flow-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 24px;
}
.th-flow-icon-green  { background: #dcfce7; color: #16a34a; }
.th-flow-icon-purple { background: #ede9fe; color: #7c3aed; }
.th-flow-icon-amber  { background: #fef3c7; color: #d97706; }
.th-flow-meta { display: flex; flex-direction: column; min-width: 0; }
.th-flow-label {
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}
.th-flow-desc {
    font-size: .8rem;
    color: #64748b;
    margin-top: 2px;
    line-height: 1.4;
}
.th-flow-skip {
    margin-top: 4px;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    width: 100%;
    padding: 8px;
    font-family: inherit;
}
.th-flow-skip:hover { color: var(--primary-dark); }
@media (max-width: 480px) {
    .th-flow-card { padding: 18px 14px 12px; border-radius: 14px; }
    .th-flow-title { font-size: 1.1rem; }
}

/* Legacy navbar Install link — replaced by .pwa-install-chip mounted
   in the navbar root by shared.js. Kept hidden for back-compat with any
   page that still ships the old HTML node. */
.pwa-install-link { display: none !important; }

/* New install chip — small, subtle, sits next to the account chip. */
.pwa-install-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--primary-light);
    border: 1px solid var(--primary-light);
    color: var(--primary-dark);
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
    font-family: inherit;
    transition: background var(--transition), border-color var(--transition);
}
.pwa-install-chip:hover { background: #bbf7d0; border-color: #bbf7d0; }
.pwa-install-chip[hidden] { display: none; }
.pwa-install-chip .material-symbols-outlined { font-size: 16px; }
@media (max-width: 767px) {
    .pwa-install-chip { padding: 6px 10px; min-width: 36px; min-height: 36px; }
}

/* ---------- Mobile Bottom Navigation ----------
   Primary page navigation on phones. Hidden on desktop (where the navbar
   links are used). Thumb-reachable, fixed to the bottom edge, and it
   respects the home-indicator safe area so it sits like a native tab bar. */
.bottom-nav { display: none; }
@media (max-width: 767px) {
    .bottom-nav {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0;
        z-index: 95;
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 12px rgba(0,0,0,.06);
        padding-bottom: env(safe-area-inset-bottom);
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    }
    .bottom-nav-item {
        display: flex; flex-direction: column;
        align-items: center; justify-content: center; gap: 2px;
        min-height: var(--tap);
        padding: 8px 4px 6px;
        text-decoration: none;
        color: var(--text-muted);
        font-size: .62rem; font-weight: 600;
        transition: color var(--transition);
        -webkit-tap-highlight-color: transparent;
    }
    .bottom-nav-item .material-symbols-outlined { font-size: 22px; }
    .bottom-nav-item.active { color: var(--primary-dark); }
    .bottom-nav-item.active .material-symbols-outlined { font-variation-settings: 'FILL' 1; }
    .bottom-nav-item:active { background: var(--primary-light); }
}

/* ---------- App Body (sidebar + main) ---------- */
.app-body {
    display: flex;
    margin-top: var(--navbar-h);
    height: calc(100dvh - var(--navbar-h));
    overflow: hidden;
}
/* When .app-body is nested inside .tab-content, the .page-tabs row above
   has already cleared the fixed navbar. Without this override the default
   margin-top doubles up and pushes the sidebar's sticky footer (Generate
   button) ~96px below the viewport on laptops. */
.tab-content > .app-body {
    margin-top: 0;
    height: calc(100dvh - var(--navbar-h) - var(--page-tabs-h, 41px));
}
.app-sidebar {
    width: var(--sidebar-default);
    min-width: 0;
    flex-shrink: 0;
    display: flex; flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow: hidden;
    transition: width .25s ease;
}
.app-sidebar.collapsed { width: 0 !important; overflow: hidden; border-right: none; }

/* Floating expand button – visible only when sidebar is collapsed */
.sidebar-expand-btn {
    display: none;
    position: fixed;
    top: calc(var(--navbar-h) + 12px);
    left: 8px;
    z-index: 50;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    align-items: center; justify-content: center;
    color: var(--primary-dark);
    transition: all var(--transition);
}
.sidebar-expand-btn:hover {
    background: var(--primary-light);
    box-shadow: var(--shadow-lg);
    transform: scale(1.08);
}
.app-sidebar.collapsed ~ .sidebar-expand-btn { display: flex; }
.app-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ---------- Resize Handle ---------- */
.sidebar-resize-handle {
    width: 6px; flex-shrink: 0;
    cursor: col-resize;
    background: transparent;
    position: relative;
    z-index: 10;
    transition: background var(--transition);
}
.sidebar-resize-handle:hover,
.sidebar-resize-handle.active { background: var(--primary-light); }
.sidebar-resize-handle::after {
    content: '';
    position: absolute; top: 50%; left: 1px;
    width: 4px; height: 40px;
    border-radius: 2px;
    background: var(--border);
    transform: translateY(-50%);
    transition: background var(--transition);
}
.sidebar-resize-handle:hover::after,
.sidebar-resize-handle.active::after { background: var(--primary); }

/* ---------- Sidebar Overlay (mobile) ---------- */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 89;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ---------- Sidebar Internal Structure ---------- */
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-header h2 {
    font-size: .85rem; font-weight: 700; color: var(--text);
    display: flex; align-items: center; gap: 6px;
}
.sidebar-collapse-btn {
    background: none; border: none; cursor: pointer;
    padding: 4px; border-radius: 6px;
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.sidebar-collapse-btn:hover { background: var(--primary-light); color: var(--primary-dark); }

.sidebar-scroll {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 12px 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface);
}

/* ---------- Sidebar Tabs ---------- */
.sidebar-tabs {
    display: flex; gap: 2px;
    padding: 2px;
    background: #f1f5f9;
    border-radius: 8px;
    margin-bottom: 12px;
}
.sidebar-tab {
    flex: 1;
    padding: 7px 8px;
    border: none; border-radius: 6px;
    font-size: .75rem; font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    cursor: pointer;
    transition: all var(--transition);
    display: flex; align-items: center; justify-content: center; gap: 4px;
}
.sidebar-tab:hover { color: var(--text); }
.sidebar-tab.active {
    background: var(--surface);
    color: var(--primary-dark);
    box-shadow: var(--shadow-sm);
}

/* ---------- Form Components ---------- */
.field { margin-bottom: 10px; }
.field-label {
    display: block;
    font-size: .7rem; font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: .02em;
}
.field-select, .field-input, .field-textarea {
    width: 100%;
    padding: 7px 10px;
    font-size: .8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    font-family: inherit;
}
.field-select:focus, .field-input:focus, .field-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(34,197,94,.12);
}
.field-select:disabled, .field-input:disabled { opacity: .5; cursor: not-allowed; }
.field-textarea { resize: vertical; min-height: 60px; }
.field-hint {
    font-size: .65rem; color: var(--text-muted);
    margin-top: 2px;
}
.field-row { display: flex; gap: 8px; }
.field-row > .field { flex: 1; }

/* inline loading spinner */
.field-loading {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: .7rem; color: var(--text-muted);
}
.field-loading .spin { animation: spin .8s linear infinite; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px;
    border: none; border-radius: 6px;
    font-size: .8rem; font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1.4;
    font-family: inherit;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-secondary {
    background: #f1f5f9; color: var(--text-secondary); border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: .72rem; }
.btn-block { width: 100%; }
.btn-icon {
    padding: 6px; background: none; border: none; cursor: pointer;
    color: var(--text-secondary); border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.btn-icon:hover { background: var(--primary-light); color: var(--primary-dark); }

/* large generate button */
.btn-generate {
    width: 100%;
    padding: 12px;
    background: var(--primary-gradient);
    color: #fff;
    border: none; border-radius: var(--radius);
    font-size: .85rem; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    box-shadow: var(--shadow-md);
    transition: all var(--transition);
    font-family: inherit;
}
.btn-generate:hover:not(:disabled) { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.btn-generate:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ---------- Cards ---------- */
.glass-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.toolbar .meta {
    flex: 1; font-size: .78rem; color: var(--text-secondary);
    min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tool-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 5px 10px; border-radius: 6px;
    font-size: .72rem; font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface); color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.tool-btn:hover { background: #f1f5f9; color: var(--text); }
.tool-btn .material-symbols-outlined { font-size: 16px; }
.tool-btn-primary { background: var(--primary-light); color: var(--primary-dark); border-color: var(--primary-light); }
.tool-btn-primary:hover { background: var(--primary); color: #fff; }

/* ---------- Content Display ---------- */
.plan-display, .paper-display {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    padding: 24px;
    min-height: 200px;
    line-height: 1.7;
    font-size: .9rem;
}
.plan-display h1, .paper-display h1 {
    font-size: var(--fs-h1); font-weight: 700; color: var(--primary-dark);
    margin: 16px 0 8px; border-bottom: 2px solid var(--primary-light); padding-bottom: 4px;
}
.plan-display h2, .paper-display h2 {
    font-size: var(--fs-h2); font-weight: 700; color: #000;
    margin: 14px 0 6px; text-decoration: underline; text-align: center;
}
.plan-display h3, .paper-display h3 {
    font-size: var(--fs-h3); font-weight: 600; color: #333; margin: 10px 0 4px;
}
.plan-display h4, .paper-display h4 {
    font-size: .92rem; font-weight: 600; color: var(--accent); margin: 8px 0 4px;
}
.plan-display ul, .paper-display ul { padding-left: 20px; margin: 4px 0; }
.plan-display li, .paper-display li { margin-bottom: 2px; }
/* Markdown tables inside content displays */
.plan-display .md-table, .paper-display .md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.plan-display .md-table th, .paper-display .md-table th {
    background: #f1f5f9;
    padding: 6px 10px;
    text-align: center;
    font-weight: 600;
    font-size: .75rem;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    border-right: 1px solid var(--border);
}
.plan-display .md-table th:last-child, .paper-display .md-table th:last-child { border-right: none; }
.plan-display .md-table td, .paper-display .md-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #f1f5f9;
    border-right: 1px solid #f1f5f9;
    vertical-align: top;
    line-height: 1.5;
}
.plan-display .md-table td:last-child, .paper-display .md-table td:last-child { border-right: none; }
.plan-display .md-table tr:last-child td, .paper-display .md-table tr:last-child td { border-bottom: none; }
.plan-display .md-table tr:hover td, .paper-display .md-table tr:hover td { background: #f8fafc; }
/* Key-value tables (no thead) — more compact */
.plan-display .md-table:not(:has(thead)) td,
.paper-display .md-table:not(:has(thead)) td { padding: 4px 10px; }
.plan-display .md-table:not(:has(thead)),
.paper-display .md-table:not(:has(thead)) { margin: 6px 0; }

/* Responsive table on mobile */
@media (max-width: 767px) {
    .plan-display .md-table, .paper-display .md-table { font-size: .74rem; }
    .plan-display .md-table th, .plan-display .md-table td,
    .paper-display .md-table th, .paper-display .md-table td { padding: 4px 6px; }
}

/* Lesson Plan school header: [Logo LEFT] [School Name CENTER] [QR RIGHT] */
.lp-school-header {
    display: flex;
    align-items: center;
    margin-bottom: 2px;
}
.lp-school-header h2 {
    flex: 1;
    margin: 0 !important;
    border: none !important;
    padding: 0 !important;
    text-decoration: none !important;
    text-align: center !important;
}
.lp-school-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    flex-shrink: 0;
}
.lp-logo-left { margin-right: 8px; }
.lp-qr-right { margin-left: 8px; }
@media print {
    .lp-school-logo { width: 38px; height: 38px; }
}

.plan-display[contenteditable="true"], .paper-display[contenteditable="true"] {
    outline: 2px solid var(--warning); outline-offset: -2px;
    background: #fffbeb;
}

/* Urdu font classes */
.paper-display.urdu-paper { direction: rtl; text-align: right; }
.paper-display.urdu-paper h2 { text-align: center; }
.paper-display.font-nastaliq { font-family: 'Noto Nastaliq Urdu','Jameel Noori Nastaleeq',serif; line-height: 2.4; }
.paper-display.font-naskh   { font-family: 'Noto Naskh Arabic','Traditional Arabic',serif;      line-height: 1.8; }
.paper-display.font-amiri   { font-family: 'Amiri','Traditional Arabic',serif;                  line-height: 1.9; }
.paper-display.font-gulzar  { font-family: 'Gulzar',serif;                                      line-height: 2.0; }

/* ---------- Empty / Loading States ---------- */
.empty-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    padding: 60px 20px;
}
.empty-state .material-symbols-outlined { font-size: 64px; color: var(--border); margin-bottom: 12px; }
.empty-state h2 { font-size: 1.1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: .82rem; color: var(--text-muted); max-width: 320px; }

.loading-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 60px 20px; gap: 12px;
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed; top: 12px; right: 12px;
    z-index: 200;
    display: flex; justify-content: flex-end;
}
.toast {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    background: #fee2e2; color: #991b1b;
    border-radius: var(--radius); border: 1px solid #fecaca;
    font-size: .8rem; font-weight: 500;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
}
.toast-success { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.toast .icon-fill { font-variation-settings: 'FILL' 1; font-size: 20px; }
.toast-close {
    background: none; border: none; cursor: pointer; opacity: .5;
    padding: 2px; color: inherit;
}
.toast-close:hover { opacity: 1; }
.toast-anim { animation: slideInRight .3s ease; }

/* ---------- PWA Install ---------- */
/* Legacy giant popup card — neutralized. Install is now driven by the
   small .pwa-install-chip in the navbar (see TA.pwa in shared.js). */
.install-card { display: none !important; }
.install-card-old {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 180;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 14px;
}
.install-card-text strong {
    display: block;
    font-size: .9rem;
    color: var(--text);
    margin-bottom: 4px;
}
.install-card-text p {
    font-size: .77rem;
    color: var(--text-secondary);
}
.install-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* ---------- Compact TOS ---------- */
.tos-section { margin-bottom: 10px; }
.tos-section-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 5px 8px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
    font-size: .7rem; font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
}
.tos-rows {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    overflow: hidden;
}
.tos-row {
    display: grid;
    grid-template-columns: 1fr 50px 50px 50px auto 32px;
    gap: 3px;
    padding: 4px 6px;
    border-bottom: 1px solid #f1f5f9;
    align-items: center;
    font-size: .72rem;
}
.tos-row:last-child { border-bottom: none; }
.tos-row select, .tos-row input {
    width: 100%;
    padding: 3px 4px;
    font-size: .7rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}
.tos-row input[type="number"] { text-align: center; -moz-appearance: textfield; }
.tos-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.tos-subtotal {
    font-weight: 700; font-size: .7rem;
    color: var(--primary-dark);
    text-align: center;
    min-width: 32px;
}
.tos-remove {
    background: none; border: none; cursor: pointer; padding: 2px;
    color: var(--text-muted); border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
}
.tos-remove:hover { color: var(--danger); background: var(--danger-light); }
.tos-add-btn {
    display: flex; align-items: center; justify-content: center; gap: 3px;
    padding: 4px 8px;
    font-size: .68rem; font-weight: 600;
    color: var(--primary-dark);
    background: var(--primary-light);
    border: 1px dashed var(--primary);
    border-radius: 4px;
    cursor: pointer;
    margin-top: 4px;
    transition: all var(--transition);
}
.tos-add-btn:hover { background: var(--primary); color: #fff; }

.tos-total-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 8px;
    font-size: .75rem; font-weight: 600;
}
.tos-total-val { color: var(--primary-dark); font-size: .85rem; }

/* Blooms badges */
.blooms-badge {
    display: inline-block; padding: 1px 5px; border-radius: 3px;
    font-size: .6rem; font-weight: 600;
}
.blooms-knowledge     { background: #dcfce7; color: #166534; }
.blooms-understanding { background: #dbeafe; color: #1e40af; }
.blooms-application   { background: #fef3c7; color: #92400e; }
.blooms-analysis      { background: #fce7f3; color: #9d174d; }
.blooms-synthesis     { background: #ede9fe; color: #6d28d9; }
.blooms-evaluation    { background: #fee2e2; color: #991b1b; }

/* ---------- Sources Tab ---------- */
.sources-inner { display: flex; flex-direction: column; gap: 10px; }
.source-toggle {
    display: flex; align-items: center; gap: 8px;
    font-size: .75rem; font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 8px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.source-toggle input { accent-color: var(--primary); width: 15px; height: 15px; }
.source-section { }
.source-label {
    font-size: .7rem; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: .02em;
    margin-bottom: 4px; display: flex; align-items: center; gap: 6px;
}
.source-count {
    background: var(--primary-light); color: var(--primary-dark);
    font-size: .6rem; padding: 1px 6px; border-radius: 10px;
}
.source-textarea {
    width: 100%; padding: 8px 10px;
    font-size: .78rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    resize: vertical; min-height: 50px;
    outline: none; color: var(--text);
    font-family: inherit;
}
.source-textarea:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(34,197,94,.12); }
.source-add-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; margin-top: 4px;
    font-size: .7rem; font-weight: 600;
    background: var(--primary-light); color: var(--primary-dark);
    border: 1px solid transparent; border-radius: 5px;
    cursor: pointer;
    transition: all var(--transition);
}
.source-add-btn:hover { background: var(--primary); color: #fff; }

.source-dropzone {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 4px;
    padding: 16px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}
.source-dropzone:hover, .source-dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.source-dropzone-text { font-size: .75rem; font-weight: 500; color: var(--text-secondary); }
.source-dropzone-sub { font-size: .65rem; color: var(--text-muted); }

.source-list { display: flex; flex-direction: column; gap: 4px; }
.source-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .75rem;
}
.source-item-icon { font-size: 18px; color: var(--text-secondary); flex-shrink: 0; }
.source-item-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.source-item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.source-item-meta { font-size: .64rem; color: var(--text-muted); margin-top: 1px; }
.source-item-badge {
    padding: 1px 6px; border-radius: 3px;
    font-size: .6rem; font-weight: 600; flex-shrink: 0;
}
.badge-manual { background: #ede9fe; color: #6d28d9; }
.badge-upload { background: #dbeafe; color: #1e40af; }
.badge-book   { background: #dcfce7; color: #166534; }
.source-item-active {
    border-color: #93c5fd;
    background: #eff6ff;
}
.source-item-use {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: .68rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.source-item-use:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
}
.source-item-active .source-item-use {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1d4ed8;
}
.source-item-manage {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    border-radius: 4px;
    padding: 3px 7px;
    font-size: .66rem;
    cursor: pointer;
    flex-shrink: 0;
}
.source-item-manage:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
}
.source-item-remove {
    background: none; border: none; cursor: pointer;
    padding: 2px; border-radius: 4px; color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
}
.source-item-remove:hover { color: var(--danger); background: var(--danger-light); }
.source-empty {
    text-align: center; padding: 12px;
    font-size: .72rem; color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: 6px;
}

/* ---------- Active Uploaded-Source Banner ---------- */
.active-source-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px; margin: 0 0 12px;
    background: linear-gradient(135deg, var(--primary-light) 0%, #ecfdf5 100%);
    border: 1px solid #86efac;
    border-radius: var(--radius);
    color: var(--primary-dark);
    font-size: .8rem;
    box-shadow: var(--shadow-sm);
}
.active-source-bar > .material-symbols-outlined { color: var(--primary-dark); }
.active-source-meta { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.active-source-meta strong { font-weight: 600; }
.active-source-chip {
    display: inline-flex; align-items: center;
    background: rgba(22, 163, 74, .12);
    border: 1px solid rgba(22, 163, 74, .25);
    color: var(--primary-dark);
    font-size: .68rem; font-weight: 600;
    padding: 1px 8px; border-radius: 999px;
}
.active-source-bar .btn { flex-shrink: 0; }

/* ---------- Topic Tree (Lesson plan chapter/sub-topic selection) ---------- */
.topic-item {
    display: flex; align-items: flex-start; gap: 6px;
    padding: 4px 6px; border-radius: 4px;
    font-size: .75rem; cursor: pointer;
    transition: background var(--transition);
}
.topic-item:hover { background: #fff; }
.topic-item input[type="checkbox"] {
    margin-top: 2px; flex-shrink: 0;
    accent-color: var(--primary);
}
.topic-item-label { flex: 1; min-width: 0; line-height: 1.4; }
.topic-item-page {
    font-size: .65rem; color: var(--text-muted);
    white-space: nowrap; flex-shrink: 0;
}
.topic-item.selected { background: var(--primary-light); }
.subtopic-item {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 6px 3px 20px; border-radius: 4px;
    font-size: .72rem; cursor: pointer;
    transition: background var(--transition);
}
.subtopic-item:hover { background: #fff; }
.subtopic-item input[type="checkbox"] {
    accent-color: var(--accent); flex-shrink: 0;
}

/* ---------- Collapsible Sections ---------- */
.collapsible { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.collapsible-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px;
    background: #f8fafc;
    cursor: pointer;
    font-size: .75rem; font-weight: 600; color: var(--text-secondary);
    transition: background var(--transition);
    user-select: none;
}
.collapsible-header:hover { background: #f1f5f9; }
.collapsible-body {
    max-height: 0; overflow: hidden;
    transition: max-height .3s ease;
}
.collapsible.open .collapsible-body { max-height: 2000px; }
.collapsible.open .collapse-icon { transform: rotate(180deg); }
.collapse-icon { transition: transform .2s ease; font-size: 18px; }

/* ---------- Scope badges (Paper) ---------- */
.scope-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 4px;
    font-size: .68rem; font-weight: 600;
    background: var(--primary-light); color: var(--primary-dark);
}

/* ---------- Page-level Tabs ---------- */
.page-tabs {
    display: flex; gap: 2px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    padding: 0 16px;
}
.page-tab {
    padding: 10px 16px;
    font-size: .8rem; font-weight: 600;
    color: var(--text-secondary);
    border: none; background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    font-family: inherit;
}
.page-tab:hover { color: var(--text); }
.page-tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ---------- Workflow Dashboard (slice A) ---------- */
.wf-hero {
    background: var(--primary-gradient);
    color: #fff;
    padding: 36px 20px 48px;
    margin-top: var(--navbar-h);
}
.wf-hero-inner { max-width: 1100px; margin: 0 auto; }
.wf-greeting { font-size: clamp(1.35rem, 3.4vw, 1.9rem); font-weight: 700; margin-bottom: 4px; line-height: 1.15; }
.wf-sub { font-size: clamp(.85rem, 1.8vw, 1rem); opacity: .92; margin: 0; }

.wf-content {
    max-width: 1100px;
    margin: -22px auto 0;     /* lift content to overlap hero edge */
    padding: 0 16px 36px;
    position: relative;
    z-index: 2;
}
.wf-section-title {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    margin: 24px 0 12px;
}
.wf-content > .wf-section-title:first-child { margin-top: 0; }

.wf-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
@media (min-width: 600px) { .wf-grid { grid-template-columns: 1fr 1fr; gap: 14px; } }
@media (min-width: 960px) { .wf-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; } }

.wf-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    text-decoration: none;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 88px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.wf-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}
.wf-card:active { transform: translateY(0); }
.wf-card-icon {
    width: 56px; height: 56px;
    border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}
.wf-card-body { min-width: 0; flex: 1; }
.wf-card-title {
    font-size: 1rem; font-weight: 700;
    margin: 0 0 4px;
    color: var(--text);
    display: flex; align-items: center; gap: 6px;
}
.wf-card-desc {
    font-size: .8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
}
.wf-card.is-soon {
    background: var(--bg);
    cursor: not-allowed;
    opacity: .85;
}
.wf-card.is-soon:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
    border-color: var(--border);
}
.wf-soon-badge {
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: .05em;
}

.wf-icon-green  { background: #dcfce7; color: #16a34a; }
.wf-icon-blue   { background: #dbeafe; color: #3b82f6; }
.wf-icon-purple { background: #ede9fe; color: #7c3aed; }
.wf-icon-amber  { background: #fef3c7; color: #d97706; }
.wf-icon-pink   { background: #fce7f3; color: #db2777; }
.wf-icon-teal   { background: #ccfbf1; color: #0d9488; }

.wf-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
@media (min-width: 600px) { .wf-stats { grid-template-columns: repeat(4, 1fr); } }
.wf-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.wf-stat-num { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.wf-stat-label { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }

.wf-recent {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.wf-recent-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: .85rem;
}
.wf-recent-empty .material-symbols-outlined {
    font-size: 36px;
    opacity: .35;
    display: block;
    margin: 0 auto 6px;
}
.wf-recent-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: background var(--transition);
}
.wf-recent-row:hover { background: var(--bg); }
.wf-recent-row:last-child { border-bottom: none; }
.wf-recent-kind {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.wf-recent-meta { flex: 1; min-width: 0; }
.wf-recent-title {
    font-weight: 600; font-size: .85rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wf-recent-sub { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }
.wf-recent-time { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }

@media (max-width: 480px) {
    .wf-card-icon { width: 48px; height: 48px; font-size: 24px; }
    .wf-card-title { font-size: .95rem; }
}

/* ============================================================
   Dashboard (clean / Notion-Linear feel) — replaces giant cards
   ============================================================ */
/* ============================================================
   Hero band — full-width premium header with glass card.
   Layered visuals (back→front):
     1. dark→deep-green base gradient
     2. two large translucent gradient blobs (radial), positioned
        absolutely + softly blurred so the corner color shifts feel
        organic and modern instead of flat.
     3. a low-opacity noise overlay so the gradient never bands.
     4. .hero-card — translucent white "glass" with backdrop-blur,
        elegant interior typography, optional inline mini-stats.
   ============================================================ */
.hero-band {
    position: relative;
    margin-top: var(--navbar-h);
    padding: 56px 24px 64px;
    background:
        radial-gradient(1200px 700px at 110% -10%, #14532d 0%, transparent 55%),
        radial-gradient(1100px 700px at -10% 110%, #064e3b 0%, transparent 50%),
        linear-gradient(135deg, #0f3a26 0%, #166534 55%, #15803d 100%);
    overflow: hidden;
    isolation: isolate;
}
.hero-blob {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    filter: blur(80px);
    opacity: .55;
    will-change: transform;
}
.hero-blob-1 {
    width: 520px; height: 520px;
    top: -180px; right: -120px;
    background: radial-gradient(circle, #34d399 0%, transparent 65%);
}
.hero-blob-2 {
    width: 460px; height: 460px;
    bottom: -200px; left: -80px;
    background: radial-gradient(circle, #4ade80 0%, transparent 60%);
    opacity: .45;
}
.hero-noise {
    position: absolute; inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: .045;
    mix-blend-mode: overlay;
    background-image:
        radial-gradient(rgba(255, 255, 255, .8) 0.6px, transparent 0.6px),
        radial-gradient(rgba(0, 0, 0, .6) 0.6px, transparent 0.6px);
    background-position: 0 0, 2px 2px;
    background-size: 4px 4px, 4px 4px;
}
.hero-inner {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
}
.hero-card {
    background: rgba(255, 255, 255, .92);
    border: 1px solid rgba(255, 255, 255, .55);
    border-radius: 20px;
    padding: 28px 30px;
    box-shadow:
        0 22px 48px -16px rgba(6, 78, 59, .45),
        0 6px 14px -8px rgba(6, 78, 59, .25),
        inset 0 0 0 1px rgba(255, 255, 255, .35);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    backdrop-filter: blur(18px) saturate(140%);
}
.hero-eyebrow {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: var(--primary-dark);
    margin: 0 0 8px;
}
.hero-greeting {
    font-size: clamp(1.55rem, 3.4vw, 2.05rem);
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -.02em;
    line-height: 1.15;
    margin: 0 0 10px;
}
.hero-greeting span { font-weight: 400; }
.hero-blurb {
    font-size: clamp(.85rem, 1.5vw, .94rem);
    line-height: 1.6;
    color: #475569;
    margin: 0;
    max-width: 64ch;
    font-weight: 400;
}
.hero-stats {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid #e2e8f0;
}
.hero-stat {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
}
.hero-stat-num {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -.01em;
    line-height: 1;
}
.hero-stat-lbl {
    font-size: .76rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: lowercase;
    letter-spacing: .01em;
}
.hero-stat-divider {
    width: 1px; height: 14px;
    background: #e2e8f0;
}
@media (max-width: 600px) {
    .hero-band { padding: 36px 16px 44px; }
    .hero-card { padding: 22px 20px; border-radius: 16px; }
    .hero-blob-1 { width: 360px; height: 360px; top: -150px; right: -120px; }
    .hero-blob-2 { width: 320px; height: 320px; bottom: -160px; left: -100px; }
    .hero-stats { gap: 12px; margin-top: 18px; padding-top: 14px; }
    .hero-stat-divider { display: none; }
}

.dash-shell {
    max-width: 1100px;
    margin: 0 auto;
    /* Hero band sits above the shell. Shell starts immediately below it
       with breathing room — pulled UP slightly to overlap the hero edge,
       which is a common premium-SaaS pattern (Linear / Stripe). */
    padding: 28px 20px calc(40px + env(safe-area-inset-bottom));
    margin-top: -24px;
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 22px;
}
@media (max-width: 600px) {
    .dash-shell { padding: 22px 14px calc(40px + env(safe-area-inset-bottom)); margin-top: -20px; gap: 16px; }
}
.dash-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.dash-greeting {
    font-size: clamp(1.25rem, 2.6vw, 1.6rem);
    font-weight: 700;
    margin: 0 0 4px;
    line-height: 1.2;
    letter-spacing: -.01em;
}
.dash-sub { font-size: .85rem; color: var(--text-muted); margin: 0; }
.dash-quick {
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;
}
.dash-quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: .82rem;
    font-weight: 600;
    text-decoration: none;
    min-height: 38px;
    transition: background var(--transition), border-color var(--transition);
}
.dash-quick-btn:hover { background: var(--bg); border-color: var(--text-muted); }
.dash-quick-btn .material-symbols-outlined { font-size: 18px; }
.dash-quick-primary {
    background: var(--primary-dark);
    color: #fff;
    border-color: var(--primary-dark);
}
.dash-quick-primary:hover { background: #15803d; border-color: #15803d; }

.dash-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 16px 14px;
}
.dash-section-tight { padding: 14px 14px 12px; }
.dash-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}
.dash-section-title {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    margin: 0;
}
.dash-section-link,
.dash-section-meta {
    font-size: .72rem;
    color: var(--text-muted);
    text-decoration: none;
}
.dash-section-link:hover { color: var(--primary-dark); }

/* ---- Usage strip ---- */
.dash-usage {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
@media (min-width: 720px) { .dash-usage { grid-template-columns: repeat(4, 1fr); } }
.dash-usage-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 4px;
}
.dash-usage-num { font-size: 1.25rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.dash-usage-lbl { font-size: .7rem; color: var(--text-muted); margin-bottom: 6px; }
.dash-usage-bar {
    display: block;
    width: 100%;
    height: 4px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 4px;
}
.dash-usage-fill {
    display: block;
    height: 100%;
    background: var(--primary);
    border-radius: inherit;
    transition: width .3s ease;
}
.dash-usage-fill.is-warn  { background: #f59e0b; }
.dash-usage-fill.is-full  { background: #ef4444; }

/* ---- Two-column grid for Recent Activity + Recent Sources ---- */
.dash-two-col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
}
@media (min-width: 860px) { .dash-two-col { grid-template-columns: 1fr 1fr; } }

/* ---- Recent / list rows ---- */
.dash-list { display: flex; flex-direction: column; }
.dash-empty {
    padding: 22px 8px;
    text-align: center;
    color: var(--text-muted);
    font-size: .82rem;
}
.dash-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 6px;
    border-top: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: background var(--transition);
}
.dash-row:first-child { border-top: none; }
.dash-row:hover { background: var(--bg); }
.dash-row-icon {
    width: 30px; height: 30px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 16px;
    flex-shrink: 0;
}
.dash-row-icon.is-plan  { background: #dcfce7; color: #16a34a; }
.dash-row-icon.is-paper { background: #dbeafe; color: #2563eb; }
.dash-row-icon.is-source { background: #ede9fe; color: #7c3aed; }
.dash-row-meta { flex: 1; min-width: 0; }
.dash-row-title {
    font-weight: 600;
    font-size: .85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dash-row-sub {
    font-size: .72rem;
    color: var(--text-muted);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dash-row-time { font-size: .7rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }

/* ---- Compact secondary tiles (NOT giant) ---- */
.dash-mini-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}
@media (min-width: 600px) { .dash-mini-grid { grid-template-columns: repeat(3, 1fr); } }
.dash-mini {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    transition: border-color var(--transition), background var(--transition);
}
.dash-mini:hover { border-color: var(--text-muted); background: var(--bg); }
.dash-mini .material-symbols-outlined {
    font-size: 20px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.dash-mini-text {
    display: flex;
    flex-direction: column;
    font-size: .85rem;
    font-weight: 600;
    line-height: 1.2;
    min-width: 0;
}
.dash-mini-text small {
    font-size: .68rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: 1px;
}
/* "Coming soon" disabled tile state. Still rendered so users can see what's
   on the roadmap, but visibly inert — no hover lift, no link cursor. */
.dash-mini.is-soon {
    cursor: not-allowed;
    opacity: .7;
    background: var(--bg);
}
.dash-mini.is-soon:hover { border-color: var(--border); background: var(--bg); }
.dash-mini-badge {
    margin-left: auto;
    flex-shrink: 0;
    font-size: .62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 2px 8px;
    border-radius: 999px;
}

@media (max-width: 600px) {
    .dash-shell { padding-left: 14px; padding-right: 14px; gap: 16px; }
    .dash-section { padding: 14px 14px 12px; border-radius: 10px; }
    .dash-quick { width: 100%; }
    .dash-quick-btn { flex: 1 1 0; justify-content: center; }
}

/* ============================================================
   Account / Logout menu (always visible — desktop + mobile)
   Lives directly inside .app-navbar (not inside the
   bottom-nav-hidden .nav-links), so the chip + Sign out are
   reachable on every screen size.
   ============================================================ */
.nav-account {
    position: relative;
    margin-left: auto;
    display: flex;
    align-items: center;
    padding-right: 12px;
}
.nav-account-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 4px 4px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 999px;
    color: var(--text);
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition);
}
.nav-account-btn:hover { background: var(--bg); border-color: var(--text-muted); }
.nav-account-btn-anon {
    padding: 6px 12px;
    color: var(--primary-dark);
    border-color: var(--primary-light);
    background: var(--primary-light);
}
.nav-account-btn-anon:hover { background: #bbf7d0; }
.nav-account-btn .material-symbols-outlined { font-size: 18px; }
.nav-account-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-account-caret { font-size: 18px !important; margin-left: -2px; color: var(--text-muted); }

.nav-account-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--primary-dark);
    color: #fff;
    font-weight: 700;
    font-size: .8rem;
    line-height: 1;
    flex-shrink: 0;
}
.nav-account-avatar-lg { width: 40px; height: 40px; font-size: 1rem; }
.nav-account-avatar-guest {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.nav-account-avatar-guest .material-symbols-outlined { font-size: 16px !important; }
.nav-account-avatar-lg.nav-account-avatar-guest .material-symbols-outlined { font-size: 22px !important; }

/* ---- Dropdown / sheet panel ---- */
.nav-account-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 280px;
    max-width: calc(100vw - 24px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .12);
    padding: 12px;
    z-index: 200;
    animation: navAccountFade .12s ease-out;
}
@keyframes navAccountFade {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.nav-account-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 4px 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}
.nav-account-id { min-width: 0; flex: 1; }
.nav-account-id-name {
    font-size: .92rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-account-id-email {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-account-id-role {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}
.nav-account-role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--bg);
    color: var(--text-secondary);
}
.nav-account-role-badge.is-admin { background: #fef3c7; color: #92400e; }
.nav-account-school { font-size: .7rem; color: var(--text-muted); }

.nav-account-quota {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 10px;
    font-size: .76rem;
    color: var(--text-secondary);
}
.nav-account-quota .material-symbols-outlined {
    font-size: 14px !important;
    margin-right: 4px;
    vertical-align: middle;
}
.nav-account-quota-admin {
    flex-direction: row;
    align-items: center;
    background: #fef3c7;
    color: #92400e;
    font-weight: 600;
}

.nav-account-actions { display: flex; flex-direction: column; gap: 2px; }
.nav-account-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    background: none;
    border: none;
    text-align: left;
    width: 100%;
    color: var(--text);
    text-decoration: none;
    font: inherit;
    font-size: .85rem;
    cursor: pointer;
    transition: background var(--transition);
}
.nav-account-item:hover { background: var(--bg); }
.nav-account-item .material-symbols-outlined { font-size: 18px; color: var(--text-secondary); }
.nav-account-primary { color: var(--primary-dark); font-weight: 600; }
.nav-account-primary .material-symbols-outlined { color: var(--primary-dark); }
.nav-account-danger { color: #b91c1c; }
.nav-account-danger .material-symbols-outlined { color: #b91c1c; }
.nav-account-danger:hover { background: #fef2f2; }

/* On mobile: drop "name" text + caret, keep avatar only. Menu becomes a
   compact sheet anchored top-right (still inside the navbar bounds). */
@media (max-width: 767px) {
    .nav-account { padding-right: 8px; }
    .nav-account-btn { padding: 4px; min-width: 36px; min-height: 36px; }
    .nav-account-btn-anon { padding: 6px 10px; }
    .nav-account-menu {
        position: fixed;
        top: calc(var(--navbar-h) + 6px);
        right: 8px;
        left: auto;
        min-width: min(320px, calc(100vw - 16px));
    }
}

/* ---------- Stats / Dashboard ---------- */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex; align-items: center; gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; flex-shrink: 0;
}
.stat-icon-green  { background: #dcfce7; color: #16a34a; }
.stat-icon-blue   { background: #dbeafe; color: #3b82f6; }
.stat-icon-amber  { background: #fef3c7; color: #d97706; }
.stat-icon-purple { background: #ede9fe; color: #7c3aed; }
.stat-number { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.stat-label { font-size: .75rem; color: var(--text-secondary); }

.action-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-decoration: none; color: var(--text);
    display: flex; flex-direction: column; align-items: center;
    text-align: center; gap: 10px;
    transition: transform var(--transition), box-shadow var(--transition);
}
.action-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.action-icon {
    width: 52px; height: 52px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
}

/* ---------- Settings Page ---------- */
.settings-layout {
    display: flex; gap: 24px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px;
}
.settings-nav {
    position: sticky; top: calc(var(--navbar-h) + 20px);
    width: 200px; flex-shrink: 0;
    align-self: flex-start;
    display: flex; flex-direction: column; gap: 2px;
}
.settings-nav-link {
    padding: 7px 12px; border-radius: 6px;
    font-size: .78rem; font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition);
    display: block;
}
.settings-nav-link:hover { background: #f1f5f9; color: var(--text); }
.settings-nav-link.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.settings-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.settings-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    scroll-margin-top: calc(var(--navbar-h) + 16px);
}
.settings-section h3 {
    font-size: .9rem; font-weight: 700; color: var(--text);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
}
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Logo preview */
.logo-upload-area {
    display: flex; align-items: center; gap: 14px;
    padding: 12px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
}
.logo-thumb {
    width: 56px; height: 56px;
    border-radius: var(--radius);
    object-fit: contain;
    border: 1px solid var(--border);
    background: #f8fafc;
}

/* Past-list wrapper: no inner padding on desktop (table fills the card),
   and on mobile the table dissolves into stacked cards so the wrapper
   becomes invisible. */
.past-list-card { padding: 0; overflow: hidden; }
@media (max-width: 767px) {
    .past-list-card {
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
    }
}

/* ---------- Past Papers / Plans Table ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8rem;
}
.data-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: .7rem; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 2px solid var(--border);
}
.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.data-table tr:hover td { background: #f8fafc; }

/* On phones, transform `.data-table.responsive` into stacked cards.
   Each <tr> becomes a card; each <td> stacks with its label coming
   from a `data-label="…"` attribute set by the row renderer. Action
   buttons stretch full-width and stay tappable (≥44px tall). */
@media (max-width: 767px) {
    .data-table.responsive,
    .data-table.responsive thead,
    .data-table.responsive tbody,
    .data-table.responsive tr,
    .data-table.responsive td {
        display: block;
        width: 100%;
    }
    .data-table.responsive thead { display: none; }
    .data-table.responsive tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 10px;
        margin: 0 0 10px;
        padding: 10px 12px 8px;
        box-shadow: var(--shadow-sm);
    }
    .data-table.responsive tr:hover td { background: transparent; }
    .data-table.responsive td {
        padding: 6px 0;
        border-bottom: 1px dashed #f1f5f9;
        text-align: left !important;
        display: flex;
        align-items: baseline;
        gap: 8px;
    }
    .data-table.responsive td:last-child {
        border-bottom: none;
        padding-top: 10px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .data-table.responsive td::before {
        content: attr(data-label);
        flex: 0 0 84px;
        font-size: .68rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--text-muted);
    }
    /* The first cell (title + sub) gets the full width — drop the label. */
    .data-table.responsive td.cell-title {
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
    }
    .data-table.responsive td.cell-title::before { display: none; }
    /* Action cell: stack buttons full-width side-by-side, NOT label-stacked. */
    .data-table.responsive td.cell-actions { padding-top: 12px; }
    .data-table.responsive td.cell-actions::before { display: none; }
    .data-table.responsive td.cell-actions .btn {
        flex: 1 1 0;
        min-height: 40px;
        margin: 0 !important;
    }
}

/* ---------- Analytics ---------- */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.analytics-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
}
.analytics-stat .stat-val { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.analytics-stat .stat-lbl { font-size: .72rem; color: var(--text-secondary); margin-top: 2px; }

/* Quality insights */
.insight-alert {
    padding: 10px 14px; border-radius: var(--radius);
    font-size: .78rem; font-weight: 500;
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 6px;
}
.insight-success { background: var(--success-light); color: #065f46; }
.insight-warning { background: var(--warning-light); color: #92400e; }
.insight-danger  { background: var(--danger-light);  color: #991b1b; }
.insight-info    { background: var(--info-light);    color: #1e40af; }

/* ---------- Answer Key Panel ---------- */
.answer-key-panel {
    margin-top: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.answer-key-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: .82rem; font-weight: 600;
}
.answer-key-body { padding: 16px; }

/* ---------- Hero (Dashboard) ---------- */
.hero {
    background: var(--primary-gradient);
    color: #fff;
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}
.hero h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 6px; }
.hero p { font-size: .9rem; opacity: .9; margin-bottom: 16px; }
.hero::before {
    content: '';
    position: absolute; top: -40px; right: -40px;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,.1);
}

/* ---------- Animations ---------- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
.animate-spin { animation: spin .8s linear infinite; }
.fade-in-up { animation: fadeInUp .4s ease both; }
.anim-delay-1 { animation-delay: .1s; }
.anim-delay-2 { animation-delay: .2s; }
.anim-delay-3 { animation-delay: .3s; }
.anim-delay-4 { animation-delay: .4s; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }

/* ============================================================
   RESPONSIVE SYSTEM  (mobile-first cascade)
   Breakpoints, largest → smallest:
     >= 1440   roomy desktop
     <= 1024   tablet / small laptop
     <= 768    phone landscape & tablet portrait  → mobile shell
     <= 480    phones
     <= 360    small phones
   The <=768 block is where the desktop shell (navbar links + side form
   + inline preview) is re-architected into a mobile app shell
   (bottom nav + form drawer + full-screen preview). One block per
   breakpoint — no duplicated/conflicting media queries.
   ============================================================ */

/* ===== Roomy desktop (>= 1440px) ===== */
@media (min-width: 1440px) {
    .app-main { padding: 28px 44px; }
    .plan-display, .paper-display { padding: 32px; }
}

/* ===== Tablet / small laptop (<= 1024px) ===== */
@media (max-width: 1024px) {
    .app-sidebar { width: 320px; }
    .settings-nav { width: 160px; }
    .settings-grid { grid-template-columns: 1fr; }
    .tos-row { grid-template-columns: 1fr 46px 46px 46px auto 30px; font-size: .68rem; }
}

/* ===== MOBILE SHELL (<= 768px) ===== */
@media (max-width: 768px) {

    body { font-size: 16px; }

    /* ---- Navbar: brand + (form drawer) hamburger only.
            Page navigation moves to the fixed .bottom-nav. ---- */
    .app-navbar { height: var(--navbar-h); }
    .nav-links { display: none !important; }     /* replaced by bottom-nav */
    .nav-hamburger { display: flex; min-width: var(--tap); min-height: var(--tap); }
    /* Dashboard/Settings have no form drawer — their menu hamburger is
       redundant once the bottom nav exists, so hide it. */
    #mobileMenuToggle { display: none !important; }

    /* ---- App body: leave room for the bottom nav so nothing hides behind it ---- */
    .app-body { height: calc(100dvh - var(--navbar-h)); }

    /* ---- Form sidebar → slide-in drawer (footer clears the bottom nav) ---- */
    .app-sidebar {
        position: fixed;
        top: var(--navbar-h);
        left: 0;
        /* End above the bottom nav so the sticky Generate button is never
           hidden behind it (the bottom nav has a higher stacking order). */
        bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
        width: min(88vw, 400px) !important;
        max-width: 400px;
        transform: translateX(-100%);
        transition: transform .3s ease;
        z-index: 90;
        box-shadow: none;
    }
    .app-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }
    .sidebar-resize-handle,
    .sidebar-collapse-btn { display: none; }
    .sidebar-expand-btn { display: none !important; }
    .sidebar-scroll { padding: 14px 16px; }
    .sidebar-footer { padding: 12px 16px; }

    /* ---- Touch-legible form controls (>=44px tall, 16px so iOS won't zoom) ---- */
    .field-select, .field-input, .field-textarea {
        font-size: 16px; padding: 11px 12px; min-height: var(--tap); border-radius: 8px;
    }
    .field-textarea { min-height: 96px; }
    .field { margin-bottom: 14px; }
    .field-label { font-size: .8rem; margin-bottom: 5px; }
    .field-hint { font-size: .74rem; }
    .field-row { flex-direction: column; gap: 0; }   /* stack two-up rows */

    /* ---- Touch-friendly buttons ---- */
    .btn { min-height: var(--tap); padding: 11px 18px; font-size: .9rem; }
    .btn-sm { min-height: 38px; padding: 8px 14px; }
    .btn-generate { min-height: 52px; font-size: 1rem; padding: 14px; }
    .btn-icon { min-width: 42px; min-height: 42px; }
    .tool-btn { min-height: 40px; padding: 9px 12px; font-size: .8rem; }
    .sidebar-tab { min-height: var(--tap); padding: 11px 8px; font-size: .82rem; }

    /* ---- FULL-SCREEN PREVIEW ----
       The generated plan/paper takes the whole screen (the form is a drawer,
       not a side column), reads at a comfortable size, and a wide table scrolls
       inside its card instead of dragging the whole page sideways. The export
       toolbar sticks to the top so PDF/Word/Copy stay one tap away. Bottom
       padding keeps the last lines clear of the bottom nav. */
    .app-main {
        padding: 0 0 calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 12px);
    }
    .empty-state, .loading-state { padding: 48px 20px; }
    .toolbar {
        position: sticky; top: 0; z-index: 20;
        border-radius: 0;
        padding: 10px 12px; gap: 6px;
    }
    .toolbar .meta { width: 100%; order: -1; white-space: normal; }
    .tool-btn .hide-mobile { display: none; }
    .plan-display, .paper-display {
        border-radius: 0; border-left: none; border-right: none;
        font-size: var(--fs-body); line-height: 1.75; padding: 16px;
        overflow-x: auto; -webkit-overflow-scrolling: touch;
    }
    /* a wide markdown table scrolls within the card, never the page */
    .plan-display .md-table, .paper-display .md-table { min-width: max-content; }

    /* ---- Paper TOS: rows WRAP — no horizontal scroll, nothing overflows ----
       The fixed 6-column grid is dropped for a flex-wrap layout: the question
       type takes a full row, then count / marks / Bloom's flow underneath and
       wrap as needed, with the subtotal + delete pinned to the right. */
    .tos-rows { overflow: visible; }
    .tos-row {
        display: flex; flex-wrap: wrap; align-items: center;
        gap: 6px; min-width: 0; padding: 8px;
        font-size: .8rem;
    }
    .tos-row .qt-type { flex: 1 1 100%; }
    .tos-row .qt-count { flex: 1 1 70px; }
    .tos-row .qt-marks { flex: 1 1 70px; }
    .tos-row .qt-blooms { flex: 1 1 90px; }
    .tos-row input, .tos-row select { min-height: 40px; font-size: 15px; padding: 6px 8px; }
    .tos-subtotal { margin-left: auto; }
    .tos-remove { min-width: 36px; min-height: 36px; }
    .tos-add-btn { min-height: 38px; font-size: .78rem; }

    /* ---- Settings: single column, no sticky side nav ----
       (bottom-nav clearance is handled by the page wrapper rule below) ---- */
    .settings-layout { flex-direction: column; padding: 14px; gap: 14px; }
    .settings-nav { display: none; }
    .settings-grid { grid-template-columns: 1fr; }

    /* ---- Page-level (Generate / History) tabs ---- */
    .page-tabs { padding: 0 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .page-tab { padding: 10px 12px; font-size: .8rem; min-height: var(--tap); white-space: nowrap; }

    /* ---- Past-papers / plans tables + dashboard ---- */
    .data-table { font-size: .74rem; }
    .data-table th, .data-table td { padding: 8px; }
    .stat-card { padding: 14px; }
    .hero { padding: 28px 20px; }

    /* Pages without an app-body (Dashboard) still need bottom-nav clearance */
    body > [style*="margin-top:var(--navbar-h)"],
    .dashboard-page { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 16px); }

    /* Install card sits above the bottom nav */
    .install-card { bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 8px); }
}

/* ===== Phones (<= 480px) ===== */
@media (max-width: 480px) {
    .app-sidebar { width: 100vw !important; max-width: 100vw; }
    .empty-state { padding: 40px 16px; }
    .install-card-actions { flex-direction: column; }
    /* tighter preview gutters on small screens */
    .plan-display, .paper-display { padding: 14px; }
    .tos-row .qt-count, .tos-row .qt-marks { flex: 1 1 60px; }
}

/* ===== Small phones (<= 360px) ===== */
@media (max-width: 360px) {
    .bottom-nav-item { font-size: .58rem; }
    .bottom-nav-item .material-symbols-outlined { font-size: 20px; }
    .plan-display, .paper-display { padding: 12px; }
    .toolbar { padding: 8px; }
    /* Bloom's select can wrap to its own line on the narrowest screens */
    .tos-row .qt-blooms { flex: 1 1 100%; }
}

/* ===== Install card width on desktop ===== */
@media (min-width: 768px) {
    .install-card { left: auto; width: 360px; }
}

/* ===== Installed PWA: honor the notch / status bar so the app opens flush,
         like a native mobile app, instead of clipping under the system bar. ===== */
@media (display-mode: standalone) {
    .app-navbar {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--navbar-h) + env(safe-area-inset-top));
    }
    .app-body {
        margin-top: calc(var(--navbar-h) + env(safe-area-inset-top));
        height: calc(100dvh - var(--navbar-h) - env(safe-area-inset-top));
    }
    .tab-content > .app-body {
        margin-top: 0;
        height: calc(100dvh - var(--navbar-h) - env(safe-area-inset-top) - var(--page-tabs-h, 41px));
    }
}
@media (display-mode: standalone) and (max-width: 768px) {
    .app-sidebar { top: calc(var(--navbar-h) + env(safe-area-inset-top)); }
}

/* ---------- Print ---------- */
@media print {
    .app-navbar, .app-sidebar, .sidebar-resize-handle,
    .sidebar-overlay, .toolbar, .toast-container,
    .page-tabs, .no-print { display: none !important; }
    .app-body { height: auto; margin-top: 0; display: block; }
    .app-main { padding: 0; overflow: visible; }
    .plan-display, .paper-display {
        border: none; box-shadow: none; border-radius: 0;
        padding: 0; font-size: 11pt;
    }
    body { background: #fff; }
}

/* ───── Modal (TA.ui.modal) ───── */
.ta-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .55);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; padding: 16px;
    animation: ta-modal-fade .15s ease-out;
}
@keyframes ta-modal-fade { from { opacity: 0 } to { opacity: 1 } }
.ta-modal-card {
    background: #fff; border-radius: 10px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, .25);
    width: 100%; max-width: 520px; max-height: 88vh;
    display: flex; flex-direction: column; overflow: hidden;
    animation: ta-modal-pop .18s ease-out;
}
@keyframes ta-modal-pop { from { transform: translateY(8px); opacity: .7 } to { transform: none; opacity: 1 } }
.ta-modal-md { max-width: 640px; }
.ta-modal-lg { max-width: 880px; }
.ta-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.ta-modal-title { margin: 0; font-size: 1rem; font-weight: 600; color: var(--text); }
.ta-modal-close {
    background: transparent; border: none; cursor: pointer;
    padding: 4px; border-radius: 4px; color: var(--text-muted);
    display: inline-flex;
}
.ta-modal-close:hover { background: #f1f5f9; color: var(--text); }
.ta-modal-body { padding: 16px 18px; overflow: auto; flex: 1; font-size: .85rem; }

/* Parsed-outline modal contents */
.outline-warning {
    background: #fef3c7; color: #92400e;
    padding: 8px 10px; border-radius: 6px;
    font-size: .78rem; margin-bottom: 12px;
    display: flex; gap: 6px; align-items: center;
}
.outline-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.outline-chip {
    padding: 2px 8px; border-radius: 999px;
    font-size: .68rem; font-weight: 600;
    background: #f1f5f9; color: var(--text);
}
.outline-chip-success { background: #d1fae5; color: #065f46; }
.outline-chip-info { background: #dbeafe; color: #1e40af; }
.outline-tree { list-style: none; padding: 0; margin: 0; }
.outline-tree ul { list-style: none; padding-left: 16px; margin: 4px 0; }
.outline-node {
    padding: 4px 0; border-left: 2px solid transparent;
    display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
}
.outline-node-title { font-weight: 500; }
.outline-node-meta { font-size: .68rem; color: var(--text-muted); }
.outline-level-tag {
    padding: 1px 6px; border-radius: 3px;
    font-size: .58rem; font-weight: 700; text-transform: uppercase;
}
.outline-level-chapter   { background: #ede9fe; color: #6d28d9; }
.outline-level-topic     { background: #dbeafe; color: #1e40af; }
.outline-level-subtopic  { background: #e0e7ff; color: #3730a3; }
.outline-level-exercise  { background: #fef3c7; color: #92400e; }
.outline-level-activity  { background: #fce7f3; color: #9d174d; }
.outline-level-example   { background: #ccfbf1; color: #115e59; }
.outline-level-review    { background: #ffe4e6; color: #9f1239; }
.outline-rtl { direction: rtl; text-align: right; }
.outline-section { margin-top: 14px; }
.outline-section-title {
    margin: 0 0 8px;
    font-size: .82rem;
    font-weight: 700;
    color: var(--text);
}
.outline-helper {
    margin: 0 0 8px;
    font-size: .72rem;
    color: var(--text-muted);
}
.outline-recovery-hint {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: .74rem;
    display: grid;
    gap: 4px;
}
.outline-candidates {
    display: grid;
    gap: 8px;
}
.outline-candidate {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
}
.outline-candidate-accepted {
    border-color: #86efac;
    background: #f0fdf4;
}
.outline-candidate-rejected {
    border-color: #fecaca;
    background: #fef2f2;
}
.outline-candidate-meta {
    margin-top: 3px;
    font-size: .68rem;
    color: var(--text-muted);
}
.outline-candidate-lines {
    margin-top: 5px;
    font-size: .72rem;
    color: var(--text-secondary);
}
.outline-editor,
.outline-editor-notes {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: #fff;
    resize: vertical;
}
.outline-editor-notes {
    min-height: 72px;
    margin-bottom: 8px;
}
.outline-editor {
    min-height: 220px;
}
.outline-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

/* Source badge row under the book select */
.book-meta-row {
    display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 0;
    align-items: center;
}
.book-meta-chip {
    padding: 1px 7px; border-radius: 3px;
    font-size: .62rem; font-weight: 600;
}
.book-meta-system   { background: #dcfce7; color: #166534; }
.book-meta-uploaded { background: #dbeafe; color: #1e40af; }
.book-meta-remote   { background: #f3f4f6; color: #374151; }
.book-meta-type     { background: #fef3c7; color: #92400e; }
.book-meta-lang     { background: #e0f2fe; color: #075985; }
.book-meta-pages    { background: #f3f4f6; color: #475569; }
.book-meta-conf-low { background: #fee2e2; color: #991b1b; }

.book-actions-row {
    display: flex; gap: 4px; margin-top: 4px;
    flex-wrap: wrap;
}
.book-action-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    padding: 3px 8px; border-radius: 5px;
    font-size: .68rem;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 3px;
}
.book-action-btn:hover { background: #f1f5f9; color: var(--text); }
.book-action-btn:disabled { opacity: .5; cursor: not-allowed; }
.book-action-btn .material-symbols-outlined { font-size: 14px; }

/* ============================================================
   Source workflow: inline panel, Sources page (stepper + manager),
   shared status badges, modal forms. Added for the source UX work.
   ============================================================ */

/* Shared small buttons */
.btn-soft {
    background: #fff; color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 6px 12px; font-size: .78rem; font-weight: 600;
    cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
    transition: background var(--transition), color var(--transition);
}
.btn-soft:hover { background: #f1f5f9; color: var(--text); }
.btn-soft.btn-danger { color: var(--danger); border-color: var(--danger-light); }
.btn-soft.btn-danger:hover { background: var(--danger-light); }
.btn-primary-sm {
    background: var(--primary-gradient); color: #fff; border: none;
    border-radius: var(--radius); padding: 7px 16px;
    font-size: .8rem; font-weight: 700; cursor: pointer;
    display: inline-flex; align-items: center; gap: 5px;
    box-shadow: var(--shadow-sm);
}
.btn-primary-sm:hover { filter: brightness(1.05); }

/* Shared status badges (from TA.sources.describeStatus) */
.src-badge {
    display: inline-flex; align-items: center;
    padding: 2px 9px; border-radius: 999px;
    font-size: .68rem; font-weight: 700; white-space: nowrap;
}
.src-badge-success { background: var(--success-light); color: var(--success); }
.src-badge-warn    { background: var(--warning-light); color: var(--warning); }
.src-badge-error   { background: var(--danger-light);  color: var(--danger); }
.src-badge-muted   { background: #f1f5f9; color: var(--text-secondary); }

.src-status-line {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 12px 14px; border-radius: var(--radius-lg);
    font-size: .82rem; line-height: 1.4; margin-bottom: 12px;
}
.src-status-line .material-symbols-outlined { font-size: 22px; flex-shrink: 0; }
.src-status-line span { color: var(--text-secondary); }
.src-status-line strong { color: var(--text); }
.src-status-success { background: var(--success-light); }
.src-status-success .material-symbols-outlined { color: var(--success); }
.src-status-warn { background: var(--warning-light); }
.src-status-warn .material-symbols-outlined { color: var(--warning); }
.src-status-error { background: var(--danger-light); }
.src-status-error .material-symbols-outlined { color: var(--danger); }
.src-status-muted { background: #f1f5f9; }

/* Modal form bits (metadata editor, manual outline, move) */
.src-form-hint { font-size: .76rem; color: var(--text-secondary); margin: 0 0 12px; line-height: 1.45; }
.src-meta-form, .src-manual-form { display: flex; flex-direction: column; gap: 12px; }
.src-field { display: flex; flex-direction: column; gap: 4px; }
.src-field > span { font-size: .72rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }
.src-checkline { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--text); }
.src-form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.src-manual-rows { display: flex; flex-direction: column; gap: 8px; }
.src-manual-row { display: flex; gap: 8px; align-items: center; }
.src-manual-row .src-mr-title { flex: 1; }
.src-mr-del { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.src-mr-del:hover { color: var(--danger); background: var(--danger-light); }
.ta-modal-sm { max-width: 440px; }

/* Outline list */
.src-outline { margin: 0; padding-left: 20px; font-size: .82rem; color: var(--text); }
.src-outline > li { margin-bottom: 8px; }
.src-outline ul { margin: 4px 0 0; padding-left: 18px; color: var(--text-secondary); }
.src-outline ul li { margin-bottom: 2px; }
.src-outline-box { max-height: 360px; overflow-y: auto; }

/* ---------- Inline source panel (Lesson Plan / Paper sidebars) ---------- */
.inline-source-panel {
    background: #f8fafc; border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 12px; margin-bottom: 14px;
}
.isp-row { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.isp-select-wrap { flex: 1 1 160px; min-width: 0; }
.isp-optional { font-weight: 400; text-transform: none; font-size: .62rem; color: var(--text-muted); }
.isp-upload-btn {
    background: var(--primary-gradient); color: #fff; border: none;
    border-radius: var(--radius); padding: 8px 12px; font-size: .76rem; font-weight: 700;
    cursor: pointer; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.isp-upload-btn:hover { filter: brightness(1.05); }
.isp-manage {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: .74rem; font-weight: 600; color: var(--primary-dark);
    text-decoration: none; padding: 8px 6px; white-space: nowrap;
}
.isp-manage:hover { text-decoration: underline; }
.isp-status { margin-top: 8px; }
.isp-summary { margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.isp-summary-meta { font-size: .74rem; color: var(--text-secondary); }
.isp-edit {
    margin-left: auto; background: none; border: none; color: var(--primary-dark);
    font-size: .74rem; font-weight: 600; cursor: pointer; text-decoration: underline;
}

/* ---------- Dedicated Sources page ---------- */
.sources-page {
    max-width: 940px; margin: 0 auto; padding: 24px 20px calc(var(--bottomnav-h) + 40px);
}
.sources-page-head h1 { font-size: var(--fs-h1); margin: 0 0 4px; color: var(--text); }
.sources-page-head p { font-size: .86rem; color: var(--text-secondary); margin: 0 0 20px; max-width: 640px; line-height: 1.5; }

.src-stepper-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
    padding: 20px; margin-bottom: 28px;
}
.src-stepper {
    display: flex; gap: 4px; list-style: none; margin: 0 0 20px; padding: 0;
    flex-wrap: wrap;
}
.src-step {
    flex: 1 1 auto; display: flex; align-items: center; gap: 8px;
    font-size: .8rem; font-weight: 600; color: var(--text-muted);
    padding: 8px 10px; border-radius: var(--radius); white-space: nowrap;
}
.src-step-num {
    width: 22px; height: 22px; border-radius: 50%;
    background: #e2e8f0; color: var(--text-secondary);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 700; flex-shrink: 0;
}
.src-step.active { color: var(--text); background: var(--primary-light); cursor: default; }
.src-step.active .src-step-num { background: var(--primary); color: #fff; }
.src-step.done { color: var(--success); cursor: pointer; }
.src-step.done .src-step-num { background: var(--success); color: #fff; }

.src-dropzone-lg { padding: 32px 16px; margin-bottom: 12px; }
.src-done { text-align: center; padding: 12px 0 18px; }
.src-done h3 { margin: 8px 0 4px; font-size: var(--fs-h3); color: var(--text); }
.src-use-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.src-use-actions .btn-generate { flex: 1 1 200px; }

/* Source manager */
.sources-manager { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); padding: 20px; }
.sources-manager-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sources-manager-head h2 { font-size: var(--fs-h3); margin: 0; color: var(--text); display: flex; align-items: center; gap: 8px; }
.src-mgr-list { display: flex; flex-direction: column; gap: 10px; }
.src-mgr-card {
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 14px; display: flex; justify-content: space-between; gap: 14px;
    align-items: flex-start; flex-wrap: wrap;
}
.src-mgr-card:hover { border-color: var(--border-focus); }
.src-mgr-main { min-width: 0; flex: 1 1 280px; }
.src-mgr-title { display: flex; align-items: center; gap: 6px; color: var(--text); margin-bottom: 4px; }
.src-mgr-title .material-symbols-outlined { font-size: 18px; color: var(--primary-dark); }
.src-mgr-title strong { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-mgr-origin { font-size: .62rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); background: #f1f5f9; padding: 1px 7px; border-radius: 999px; }
.src-mgr-meta { font-size: .74rem; color: var(--text-secondary); margin-bottom: 6px; }
.src-mgr-actions { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 600px) {
    .src-step span:not(.src-step-num) { display: none; }
    .src-step { flex: 0 0 auto; justify-content: center; }
    .src-mgr-actions { width: 100%; }
}

/* ============================================================
   Chapter parsing-failure fallback panel (Lesson Plan sidebar)
   + mobile sticky Generate action bar.
   ============================================================ */
.chapter-fallback {
    background: var(--warning-light);
    border: 1px solid #fcd9a0;
    border-radius: var(--radius-lg);
    padding: 12px;
    margin-bottom: 14px;
}
.chapter-fallback-msg {
    display: flex; gap: 8px; align-items: flex-start;
    font-size: .8rem; color: #7c4a03; line-height: 1.4;
    margin-bottom: 10px;
}
.chapter-fallback-msg .material-symbols-outlined { font-size: 20px; color: var(--warning); flex-shrink: 0; }
.chapter-fallback-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.chapter-fallback-actions .btn-primary-sm,
.chapter-fallback-actions .btn-soft { flex: 1 1 auto; justify-content: center; }

/* Desktop: the sidebar footer already pins the Generate button. On mobile the
   drawer footer becomes an explicit sticky action bar with safe-area padding so
   the button is always visible and never hidden below the scroll or the notch. */
@media (max-width: 768px) {
    .sidebar-footer {
        position: sticky; bottom: 0; z-index: 5;
        box-shadow: 0 -2px 12px rgba(0,0,0,.08);
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    .chapter-fallback-actions .btn-primary-sm,
    .chapter-fallback-actions .btn-soft { flex: 1 1 100%; min-height: 42px; }
}

/* ============================================================
   TeachHub premium dashboard (.th-*)
   Full-bleed hero band (green→teal gradient with content directly
   on it), today's usage panel, and recent activity / sources grid.
   ============================================================ */

/* Top-level page wrapper — full-bleed, no centering constraint here.
   Hero stretches edge-to-edge; the inner .dash-shell centers the
   panels below it without affecting the hero.

   --dash-max:   shared content max-width for hero-inner + dash-shell
   --dash-gutter: shared horizontal padding so the hero text and the
                  cards below sit on identical left/right edges. Updated
                  at the same breakpoints so they always stay aligned. */
.dash-main {
    width: 100%;
    margin-top: var(--navbar-h);
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
    --dash-max: 1240px;
    --dash-gutter: 28px;
}
@media (max-width: 900px) {
    .dash-main { --dash-gutter: 18px; }
}
@media (max-width: 480px) {
    .dash-main { --dash-gutter: 14px; }
}
@media (max-width: 360px) {
    .dash-main { --dash-gutter: 12px; }
}
@media (max-width: 767px) {
    .dash-main {
        /* Bottom-nav is fixed at viewport bottom (~58px + safe-area).
           Leave generous slack so the last panel never sits under it. */
        padding-bottom: calc(var(--bottomnav-h) + 40px + env(safe-area-inset-bottom));
    }
}

/* Inner centered shell — only wraps the panel sections below the hero. */
.dash-shell {
    max-width: var(--dash-max);
    margin: 0 auto;
    margin-top: 28px;
    padding: 0 var(--dash-gutter);
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-sizing: border-box;
    width: 100%;
}
@media (max-width: 900px) {
    .dash-shell { margin-top: 22px; gap: 16px; }
}
@media (max-width: 480px) {
    .dash-shell { margin-top: 16px; gap: 14px; }
}

/* ---------- HERO (full-bleed, edge-to-edge) ----------
   No border-radius, no outer max-width, no shadow card feel —
   the green band IS the page background at the top, like Linear /
   Stripe hero sections.

   Color direction: matches the TeachHub logo/name green in the navbar
   (#22c55e / #16a34a) with a soft cyan-teal accent. No olive, no warm
   yellow stops, no dull forest-emerald — fresh, glossy, premium. */
.th-hero {
    position: relative;
    width: 100%;
    color: #fff;
    isolation: isolate;
    overflow: hidden;
    padding: 60px 0 68px;
    background:
        /* Glossy top-right highlight (mint, pure cool) */
        radial-gradient(70% 90% at 100% 0%, rgba(187, 247, 208, .42) 0%, transparent 58%),
        /* Bottom-left cyan/teal accent for depth — never warms the band */
        radial-gradient(75% 90% at 0% 100%, rgba(20, 184, 166, .35) 0%, transparent 65%),
        /* Soft cyan kiss along the bottom edge */
        radial-gradient(60% 50% at 50% 115%, rgba(6, 182, 212, .22) 0%, transparent 70%),
        /* Brand-green base — straight from the logo/name */
        linear-gradient(135deg, #22c55e 0%, #16a34a 55%, #15803d 100%);
}
.th-hero-inner {
    position: relative;
    z-index: 2;
    max-width: var(--dash-max);
    margin: 0 auto;
    padding: 0 var(--dash-gutter);
    box-sizing: border-box;
    width: 100%;
}
@media (max-width: 900px) {
    .th-hero { padding: 40px 0 42px; }
}
@media (max-width: 480px) {
    .th-hero { padding: 26px 0 28px; }
}
.th-hero-eyebrow {
    font-size: clamp(.66rem, .6rem + .2vw, .74rem);
    font-weight: 700;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: rgba(255,255,255,.88);
    margin: 0 0 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.th-hero-eyebrow span { font-size: .95rem; }
.th-hero-greeting {
    font-size: clamp(1.55rem, 1.1rem + 2.6vw, 3rem);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -.025em;
    margin: 0 0 16px;
    color: #fff;
    text-shadow: 0 1px 0 rgba(0,0,0,.06);
    /* Allow clean wrap on narrow screens, never overflow horizontally. */
    overflow-wrap: break-word;
    word-break: normal;
    max-width: 100%;
}
.th-hero-name {
    font-weight: 800;
    /* Light mint-cyan accent — brighter than the base green, brand-aligned,
       and reads as a cool highlight (never warm/yellow). */
    background: linear-gradient(180deg, #ecfff7 0%, #a7f3d0 60%, #67e8f9 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
@media (min-width: 641px) {
    /* Keep "Welcome back, Tabassam!" on one line on desktop / tablet wide. */
    .th-hero-name { white-space: nowrap; }
}
.th-hero-blurb {
    font-size: clamp(.88rem, .82rem + .35vw, 1.05rem);
    line-height: 1.65;
    color: rgba(255,255,255,.94);
    margin: 0 0 28px;
    max-width: 62ch;
    font-weight: 400;
}

/* Hero decorations (behind content, purely visual) */
.th-hero-wave {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: .35;
    background-image:
        radial-gradient(ellipse 70% 50% at 100% 30%, rgba(255,255,255,.22) 0, transparent 60%),
        radial-gradient(ellipse 60% 40% at 100% 75%, rgba(255,255,255,.16) 0, transparent 55%);
}
.th-hero-glass {
    position: absolute;
    z-index: 0;
    pointer-events: none;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(255,255,255,.22), rgba(255,255,255,0));
    border: 1px solid rgba(255,255,255,.18);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.th-hero-glass-1 {
    width: 360px; height: 360px;
    right: -120px; top: -140px;
    transform: rotate(-18deg);
    border-radius: 42% 58% 56% 44% / 48% 40% 60% 52%;
}
.th-hero-glass-2 {
    width: 260px; height: 260px;
    right: 60px; bottom: -120px;
    opacity: .7;
    border-radius: 60% 40% 48% 52% / 52% 56% 44% 48%;
}
.th-hero-stars {
    position: absolute; inset: 0; z-index: 0; pointer-events: none;
}
.th-hero-stars span {
    position: absolute;
    width: 4px; height: 4px;
    background: #fff;
    border-radius: 50%;
    box-shadow:
        0 0 6px rgba(255,255,255,.95),
        0 0 12px rgba(255,255,255,.55);
    opacity: .85;
}
.th-hero-stars span:nth-child(1) { top: 18%;  right: 12%; width: 5px; height: 5px; }
.th-hero-stars span:nth-child(2) { top: 32%;  right: 6%;  opacity: .55; }
.th-hero-stars span:nth-child(3) { top: 55%;  right: 28%; opacity: .65; width: 3px; height: 3px; }
.th-hero-stars span:nth-child(4) { top: 72%;  right: 8%;  opacity: .8; }
.th-hero-stars span:nth-child(5) { top: 12%;  right: 36%; opacity: .45; width: 3px; height: 3px; }
.th-hero-stars span:nth-child(6) { top: 80%;  right: 40%; opacity: .55; width: 3px; height: 3px; }
.th-hero-stars span:nth-child(7) { top: 42%;  right: 18%; opacity: .7; }
.th-hero-stars span:nth-child(8) { top: 62%;  right: 48%; opacity: .35; width: 3px; height: 3px; }
.th-hero-glow {
    position: absolute;
    z-index: 0;
    pointer-events: none;
    border-radius: 50%;
    filter: blur(80px);
}
.th-hero-glow-1 {
    width: 380px; height: 380px;
    top: -140px; left: -110px;
    /* Mint highlight — cool, brand-aligned, never yellow-leaning. */
    background: radial-gradient(circle, rgba(187,247,208,.55) 0%, transparent 70%);
}
.th-hero-glow-2 {
    width: 300px; height: 300px;
    bottom: -130px; right: 28%;
    /* Soft cyan kiss at the bottom for a glossy SaaS feel. */
    background: radial-gradient(circle, rgba(103,232,249,.30) 0%, transparent 70%);
    opacity: .75;
}

/* ---------- HERO ACTIONS (3 compact pill rows on hero) ---------- */
.th-hero-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    position: relative;
    z-index: 2;
    margin-top: 6px;
    width: 100%;
    box-sizing: border-box;
}
.th-action {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 14px;
    text-decoration: none;
    color: #fff;
    min-height: 60px;
    min-width: 0;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition), border-color var(--transition);
    cursor: pointer;
    border: 1px solid rgba(255,255,255,.26);
    background: rgba(255,255,255,.13);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    backdrop-filter: blur(20px) saturate(160%);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,.28),
        0 6px 18px -12px rgba(0,0,0,.30);
    box-sizing: border-box;
}
.th-action:hover {
    transform: translateY(-2px);
    background: rgba(255,255,255,.18);
    border-color: rgba(255,255,255,.38);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,.30),
        0 12px 24px -14px rgba(0,0,0,.40);
}
.th-action:active { transform: translateY(0); }
.th-action-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.25);
    color: #fff;
}
.th-action-icon .material-symbols-outlined {
    font-size: 20px;
    font-variation-settings: 'FILL' 1, 'wght' 500;
}
.th-action-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.2;
}
.th-action-title {
    font-size: .98rem;
    font-weight: 700;
    letter-spacing: -.005em;
}
.th-action-sub {
    font-size: .74rem;
    font-weight: 400;
    color: rgba(255,255,255,.82);
}
.th-action-arrow {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,.14);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), transform var(--transition);
}
.th-action-arrow .material-symbols-outlined { font-size: 16px; }
.th-action:hover .th-action-arrow {
    background: rgba(255,255,255,.24);
    transform: translateX(2px);
}

/* Solid (white) middle button */
.th-action-solid {
    background: #fff;
    color: var(--text);
    border-color: rgba(255,255,255,.7);
    box-shadow:
        0 10px 24px -10px rgba(0, 80, 30, .35),
        0 2px 6px -2px rgba(0,0,0,.08);
}
.th-action-solid:hover {
    background: #fff;
    border-color: #fff;
    box-shadow:
        0 18px 32px -12px rgba(0, 80, 30, .45),
        0 4px 10px -4px rgba(0,0,0,.10);
}
.th-action-solid .th-action-icon {
    background: var(--primary-light);
    border-color: transparent;
    color: var(--primary-dark);
}
.th-action-solid .th-action-sub { color: var(--text-secondary); }
.th-action-solid .th-action-arrow {
    background: var(--primary-light);
    color: var(--primary-dark);
}
.th-action-solid:hover .th-action-arrow {
    background: var(--primary);
    color: #fff;
}

/* Glass tinted (green-glass) — first + third buttons */
.th-action-glass .th-action-icon {
    background: rgba(255,255,255,.22);
    border-color: rgba(255,255,255,.30);
}

/* Hero responsive */
@media (max-width: 960px) {
    .th-hero-actions { grid-template-columns: 1fr 1fr; gap: 12px; }
    .th-action:nth-child(3) { grid-column: span 2; }
}
@media (max-width: 640px) {
    .th-hero-eyebrow { font-size: .64rem; letter-spacing: .14em; margin-bottom: 8px; }
    .th-hero-greeting { font-size: clamp(1.4rem, 6.6vw, 1.85rem); margin-bottom: 10px; line-height: 1.12; }
    .th-hero-blurb { font-size: .82rem; line-height: 1.55; margin-bottom: 16px; }

    /* Mobile action grid: 2-up first row (Lesson Plan + Generate Paper),
       Upload Source spans both columns on the second row. */
    .th-hero-actions { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 0; }
    .th-action:nth-child(3) { grid-column: 1 / -1; }

    /* Compact chip variant for the first two — hide subtitle + arrow
       so they fit cleanly side-by-side at narrow widths. */
    .th-action { min-height: 48px; padding: 8px 10px; gap: 8px; border-radius: 11px; }
    .th-action:nth-child(1) .th-action-sub,
    .th-action:nth-child(2) .th-action-sub,
    .th-action:nth-child(1) .th-action-arrow,
    .th-action:nth-child(2) .th-action-arrow { display: none; }
    .th-action:nth-child(1) .th-action-title,
    .th-action:nth-child(2) .th-action-title { font-size: .82rem; }

    /* Upload Source keeps full detail since it has a full-width row. */
    .th-action:nth-child(3) { min-height: 52px; padding: 9px 12px; gap: 10px; border-radius: 12px; }
    .th-action:nth-child(3) .th-action-title { font-size: .9rem; }
    .th-action:nth-child(3) .th-action-sub { font-size: .7rem; }

    .th-action-icon { width: 30px; height: 30px; border-radius: 8px; }
    .th-action-icon .material-symbols-outlined { font-size: 16px; }
    .th-action:nth-child(3) .th-action-icon { width: 32px; height: 32px; border-radius: 9px; }
    .th-action:nth-child(3) .th-action-icon .material-symbols-outlined { font-size: 17px; }
    .th-action-arrow { width: 24px; height: 24px; }
    .th-action-arrow .material-symbols-outlined { font-size: 14px; }

    .th-hero-glass-1 { width: 200px; height: 200px; right: -90px; top: -70px; }
    .th-hero-glass-2 { display: none; }
    .th-hero-glow-1 { width: 200px; height: 200px; }
    .th-hero-glow-2 { display: none; }
    .th-hero-stars span:nth-child(3),
    .th-hero-stars span:nth-child(6),
    .th-hero-stars span:nth-child(8) { display: none; }
}

/* ---------- PANELS (white cards: usage, recent, etc.) ---------- */
.th-panel {
    background: var(--surface);
    border-radius: 18px;
    padding: 20px 22px;
    border: 1px solid var(--border);
    box-shadow:
        0 1px 2px rgba(15, 23, 42, .03),
        0 6px 18px -14px rgba(15, 23, 42, .08);
}
@media (max-width: 640px) {
    .th-panel { padding: 16px 14px; border-radius: 14px; }
}
.th-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}
.th-panel-title {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--text-muted);
    margin: 0;
}
.th-panel-link {
    font-size: .8rem;
    font-weight: 600;
    color: var(--primary-dark);
    text-decoration: none;
    transition: color var(--transition);
}
.th-panel-link:hover { color: var(--primary); }
.th-panel-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .78rem;
    color: var(--text-muted);
    font-weight: 500;
}
.th-panel-meta .material-symbols-outlined {
    font-size: 16px;
    color: var(--text-muted);
}

/* ---------- USAGE ---------- */
.th-usage {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}
@media (max-width: 900px) { .th-usage { grid-template-columns: repeat(2, 1fr); gap: 14px 16px; } }
@media (max-width: 360px) { .th-usage { gap: 12px; } }
.th-usage-stat {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.th-usage-icon {
    width: 44px; height: 44px;
    border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.th-usage-icon-green {
    background: #e6f9ed;
    color: var(--primary-dark);
}
.th-usage-icon .material-symbols-outlined {
    font-size: 22px;
    font-variation-settings: 'FILL' 1, 'wght' 500;
}
.th-usage-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.th-usage-num {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.05;
    letter-spacing: -.01em;
}
.th-usage-lbl {
    font-size: .78rem;
    color: var(--text-secondary);
    font-weight: 500;
}
@media (max-width: 640px) {
    .th-usage-stat { gap: 10px; }
    .th-usage-icon { width: 38px; height: 38px; border-radius: 10px; }
    .th-usage-icon .material-symbols-outlined { font-size: 19px; }
    .th-usage-num { font-size: 1.2rem; }
    .th-usage-lbl { font-size: .72rem; }
}
.th-usage-bar {
    display: block;
    width: 100%;
    height: 4px;
    background: #eef2f7;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 4px;
}
.th-usage-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #16a34a);
    border-radius: inherit;
    transition: width .4s ease;
}
.th-usage-fill.is-warn { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.th-usage-fill.is-full { background: linear-gradient(90deg, #f87171, #ef4444); }

/* ---------- TWO COLUMN (Recent activity + Recent sources) ---------- */
.th-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
@media (max-width: 900px) { .th-two-col { grid-template-columns: 1fr; gap: 16px; } }

/* ---------- LIST ROWS ---------- */
.th-list {
    display: flex;
    flex-direction: column;
}
.th-empty {
    padding: 28px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: .85rem;
}
.th-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 4px;
    border-top: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    border-radius: 8px;
    transition: background var(--transition);
}
.th-row:first-child { border-top: none; }
.th-row:hover { background: #f8fafc; }
.th-row-icon {
    width: 34px; height: 34px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}
.th-row-icon .material-symbols-outlined { font-size: 18px; }
.th-row-icon.is-plan   { background: #e6f9ed; color: var(--primary-dark); }
.th-row-icon.is-paper  { background: #e6f9ed; color: var(--primary-dark); }
.th-row-icon.is-source { background: #fff1f2; color: #be123c; font-weight: 700; font-size: .55rem; letter-spacing: .04em; }
.th-row-meta {
    flex: 1;
    min-width: 0;
}
.th-row-title {
    font-weight: 600;
    font-size: .88rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.th-row-sub {
    font-size: .74rem;
    color: var(--text-secondary);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.th-row-time {
    font-size: .72rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 500;
}
@media (max-width: 640px) {
    .th-row { gap: 10px; padding: 9px 2px; }
    .th-row-icon { width: 30px; height: 30px; border-radius: 8px; }
    .th-row-icon .material-symbols-outlined { font-size: 16px; }
    .th-row-icon.is-source { font-size: .5rem; }
    .th-row-title { font-size: .84rem; }
    .th-row-sub { font-size: .7rem; }
    .th-row-time { font-size: .68rem; }
}

/* ---------- COMING SOON TILES ---------- */
.th-soon-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}
@media (max-width: 900px) { .th-soon-grid { grid-template-columns: 1fr; gap: 10px; } }
.th-soon {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px dashed var(--border);
    color: var(--text-secondary);
    cursor: not-allowed;
    min-height: 64px;
}
.th-soon-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: var(--primary-dark);
}
.th-soon-icon .material-symbols-outlined {
    font-size: 19px;
    font-variation-settings: 'FILL' 1, 'wght' 500;
}
.th-soon-meta { flex: 1; min-width: 0; }
.th-soon-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .88rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}
.th-soon-sub {
    font-size: .72rem;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.35;
}
.th-soon-badge {
    font-size: .58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--primary-light);
    color: var(--primary-dark);
}
@media (max-width: 640px) {
    .th-soon { min-height: 56px; padding: 10px 12px; gap: 10px; border-radius: 11px; }
    .th-soon-icon { width: 32px; height: 32px; border-radius: 9px; }
    .th-soon-icon .material-symbols-outlined { font-size: 17px; }
    .th-soon-title { font-size: .84rem; }
    .th-soon-sub { font-size: .7rem; }
}

/* ============================================================
   Google sign-in button (login.html + signup.html)
   Follows Google's brand guidelines: white surface, neutral border,
   official multi-color "G" mark, sentence-case label. Sized to match
   the existing .btn-block primary button so the two CTAs line up. */
.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    margin-bottom: 14px;
    background: #fff;
    border: 1px solid #dadce0;
    border-radius: 12px;
    color: #3c4043;
    font: 600 .95rem/1 'Inter', system-ui, -apple-system, sans-serif;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
    -webkit-tap-highlight-color: transparent;
}
.btn-google:hover {
    background: #f8f9fa;
    border-color: #c6c9ce;
    box-shadow: 0 1px 2px rgba(60,64,67,.10), 0 2px 6px rgba(60,64,67,.08);
}
.btn-google:active { background: #f1f3f4; }
.btn-google:focus-visible {
    outline: 2px solid #4285F4;
    outline-offset: 2px;
}
.btn-google-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* "or" divider between Google and the email/password form. */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0 16px;
    color: #94a3b8;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}

