/* ============================================================
   DESIGN SYSTEM v2 — Corporate/institutional redesign
   Source Serif 4 (headings) + Public Sans (UI/body) + IBM Plex Mono (data).
   Flat, neutral-first, single-accent — no gradients/glow.
   ============================================================ */
 
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:wght@500;600;700&family=Public+Sans:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@500;600;700&display=swap');
 
:root {
    /* --- Color: institutional navy + muted teal, flat neutral surfaces --- */
    --accent: #1F4E79;
    --accent-hover: #193F63;
    --accent-active: #142F4B;
    --accent-subtle: #E7EEF4;
    --accent-subtle-strong: #D3E0EA;
    --accent-glow: rgba(31, 78, 121, 0.14);

    --teal: #3D7A68;
    --teal-subtle: #EAF1EC;

    --bg: #F6F7F9;
    --bg-grad-1: #F6F7F9;
    --bg-grad-2: #F6F7F9;
    --bg-grad-3: #F6F7F9;
    --surface: #ffffff;
    --surface-sunken: #F1F3F5;
 
    --text-primary: #1C2530;
    --text-secondary: #5B6470;
    --text-tertiary: #8A93A0;
    --text-on-accent: #ffffff;
 
    --border: #DCE1E8;
    --border-strong: #C4CCD6;
 
    --success: #2E7D5C;
    --success-subtle: #EAF1EC;
    --danger: #B3392E;
    --danger-subtle: #FBEAE8;
    --warning: #A66A0C;
    --warning-subtle: #FDF1DE;

    /* --- Sidebar (always dark, independent of light/dark theme) --- */
    --sidebar-bg: #1C2530;
    --sidebar-ink: #C4CAD3;
    --sidebar-ink-active: #ffffff;
    --sidebar-active-bg: #2A3646;
    --sidebar-control-bg: #2A3646;
    --sidebar-border: #435168;
 
    /* --- Spacing scale (4px base) --- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 28px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
 
    /* --- Radii: smaller/flatter for a corporate feel --- */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-full: 999px;
 
    /* --- Shadows: flatter, mostly border-led --- */
    --shadow-xs: 0 1px 2px rgba(23, 24, 28, 0.03);
    --shadow-sm: 0 1px 2px rgba(23, 24, 28, 0.04);
    --shadow-md: 0 2px 4px rgba(23, 24, 28, 0.05), 0 6px 12px rgba(23, 24, 28, 0.04);
    --shadow-lg: 0 4px 8px rgba(23, 24, 28, 0.05), 0 12px 24px rgba(23, 24, 28, 0.05);
    --shadow-focus: 0 0 0 4px var(--accent-subtle-strong);
 
    /* --- Type --- */
    --font-heading: 'Source Serif 4', Georgia, serif;
    --font-ui: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
 
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
 
[data-theme="dark"] {
    --accent: #4A83AD;
    --accent-hover: #5D93BB;
    --accent-active: #3D6F94;
    --accent-subtle: #16222C;
    --accent-subtle-strong: #1C2E3B;
    --accent-glow: rgba(74, 131, 173, 0.22);

    --teal: #5FA98F;
    --teal-subtle: #16241E;
 
    --bg: #10151E;
    --bg-grad-1: #10151E;
    --bg-grad-2: #10151E;
    --bg-grad-3: #10151E;
    --surface: #1A2230;
    --surface-sunken: #141B27;
 
    --text-primary: #EDEFF2;
    --text-secondary: #A6AEBA;
    --text-tertiary: #747E8C;
    --text-on-accent: #ffffff;
 
    --border: #2A3340;
    --border-strong: #3A4453;
 
    --success: #4FAE8A;
    --success-subtle: #14261D;
    --danger: #E0685C;
    --danger-subtle: #2C1815;
    --warning: #D3963F;
    --warning-subtle: #2B2213;

    --sidebar-bg: #0D1219;
    --sidebar-ink: #A6AEBA;
    --sidebar-ink-active: #ffffff;
    --sidebar-active-bg: #1C2531;
    --sidebar-control-bg: #1C2531;
    --sidebar-border: #354256;
 
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28), 0 2px 4px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.28), 0 12px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.32), 0 8px 16px rgba(0, 0, 0, 0.32), 0 24px 48px rgba(0, 0, 0, 0.36);
    --shadow-focus: 0 0 0 4px var(--accent-subtle-strong);
}
 
/* ============================================================
   RESET / BASE
   ============================================================ */
* { box-sizing: border-box; }
 
body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text-primary);
    margin: 0;
    padding: var(--space-6);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition), color var(--transition);
    letter-spacing: -0.01em;
    position: relative;
}

/* App-shell pages (dashboard/sidebar layouts) manage their own full-bleed
   layout — undo the centering flex/padding the standalone cards use. */
body.app-shell-page {
    display: block;
    padding: 0;
}
 
::selection { background: var(--accent-subtle-strong); }
 
/* ============================================================
   CONTAINER / CARD
   ============================================================ */
.container {
    max-width: 480px;
    width: 100%;
    margin: var(--space-8) auto;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: var(--space-8);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(6, 10, 35, 0.35), 0 4px 16px rgba(6, 10, 35, 0.2);
    position: relative;
    overflow: hidden;
    z-index: 1;
}
.container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent);
}
.container.wide {
    max-width: 880px;
}
 
h1 {
    text-align: left;
    color: var(--text-primary);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1.5rem;
    letter-spacing: -0.01em;
    margin: 0 0 var(--space-6);
}
h2, h3 {
    color: var(--text-primary);
    font-family: var(--font-heading);
    font-weight: 600;
    letter-spacing: -0.01em;
}
h2 { font-size: 1.15rem; margin: 0 0 var(--space-4); }
h3 { font-size: 1rem; margin: 0 0 var(--space-3); }
label {
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
label::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}
p, span, td, th, div { color: var(--text-primary); }
 
/* ============================================================
   FORMS
   ============================================================ */
form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}
.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.stat-field {
    background: var(--accent-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}
.stat-field label { color: var(--accent); }
.stat-field label::before { background: var(--accent); }
.stat-field input {
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    border-color: var(--border-strong);
    max-width: 140px;
}
textarea, input, select {
    padding: var(--space-3) var(--space-4);
    font-size: 0.95rem;
    font-family: var(--font-ui);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}
textarea::placeholder, input::placeholder { color: var(--text-tertiary); }
textarea:focus, input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-focus);
}
textarea {
    resize: vertical;
    min-height: 96px;
    font-family: var(--font-ui);
}
input[type="number"] { font-family: var(--font-mono); }
 
/* ============================================================
   BUTTONS
   ============================================================ */
button {
    background-color: var(--accent);
    color: var(--text-on-accent);
    cursor: pointer;
    border: 1px solid transparent;
    padding: var(--space-3) var(--space-5);
    font-size: 0.95rem;
    font-family: var(--font-ui);
    font-weight: 600;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 4px var(--accent-glow);
    transition: background-color var(--transition), box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
button:hover {
    background-color: var(--accent-hover);
    box-shadow: 0 4px 12px var(--accent-glow), 0 2px 4px var(--accent-glow);
    transform: translateY(-1px);
}
button:active { background-color: var(--accent-active); transform: translateY(0); }
button:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
 
button:disabled, button[disabled] {
    background-color: var(--border-strong);
    color: var(--text-tertiary);
    box-shadow: none;
    cursor: not-allowed;
}
button:disabled:hover, button[disabled]:hover {
    background-color: var(--border-strong);
    box-shadow: none;
    transform: none;
}
 
.btn-danger { background-color: var(--danger); margin-top: var(--space-2); }
.btn-danger:hover { background-color: #b32820; }
.btn-secondary {
    background-color: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}
.btn-secondary:hover { background-color: var(--surface-sunken); border-color: var(--border-strong); }
.btn-small { padding: var(--space-2) var(--space-3); font-size: 0.8rem; width: auto; }
 
/* ============================================================
   QUIZ OPTION BUTTONS
   ============================================================ */
.option-btn {
    background-color: var(--surface);
    border: 1px solid var(--border);
    text-align: start;
    color: var(--text-primary);
    font-weight: 500;
    box-shadow: var(--shadow-xs);
    transition: border-color var(--transition), background-color var(--transition), box-shadow var(--transition);
}
.option-btn:hover {
    background-color: var(--accent-subtle);
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}
.option-btn:disabled { cursor: not-allowed; opacity: 0.7; }
.option-btn.selected {
    background-color: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: 0 0 0 1px var(--accent) inset;
}
.option-btn.correct { background-color: var(--success); color: #fff; border-color: var(--success); }
.option-btn.wrong { background-color: var(--danger); color: #fff; border-color: var(--danger); }
.option-btn:disabled:hover { box-shadow: var(--shadow-xs); }
 
/* ============================================================
   NAVIGATION / RESULTS
   ============================================================ */
.nav-links {
    text-align: center;
    margin-top: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.nav-links a {
    text-decoration: none;
    color: var(--text-on-accent);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-sm);
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    background-color: var(--accent);
    box-shadow: var(--shadow-xs);
    transition: background-color var(--transition), box-shadow var(--transition);
}
.nav-links a[href="results.html"] { background-color: var(--success); }
.nav-links a[href="results.html"]:hover { background-color: #157a41; }
.nav-links a:hover { background-color: var(--accent-hover); box-shadow: var(--shadow-sm); }
.separator { border: none; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
 
table { width: 100%; border-collapse: collapse; margin-top: var(--space-5); font-size: 0.9rem; }
th, td { border: 1px solid var(--border); padding: var(--space-3); text-align: left; }
th {
    background-color: var(--surface-sunken);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
td { font-family: var(--font-mono); font-size: 0.85rem; }
tr:nth-child(even) { background-color: var(--surface-sunken); }
 
.result-item {
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--space-4);
    margin-bottom: var(--space-4);
}
.result-item p { margin: var(--space-1) 0; }
.correct-answer { color: var(--success); font-weight: 600; }
.wrong-answer { color: var(--danger); font-weight: 600; }
 
/* ============================================================
   VISIBILITY / STATE
   ============================================================ */
.hidden { display: none !important; }
#option-d-wrapper.hidden { display: none; }
#login-container, #quiz-container, #result-container, #admin-panel, #teacher-login-container { display: none; }
#teacher-login-container { display: block; }
#login-container { display: block; }
 
#loading-container {
    display: none;
    text-align: center;
    padding: var(--space-10) 0;
}
#loading-container h2 { color: var(--accent); font-weight: 600; }
#loading-container p { font-size: 0.9rem; color: var(--text-secondary); }
 
/* ============================================================
   TIMER
   ============================================================ */
#timer-display {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 96px;
    height: 96px;
    margin: var(--space-2) auto var(--space-5);
    border: 3px solid var(--accent);
    border-radius: 50%;
    background: var(--accent-subtle);
    box-shadow: 0 0 0 6px var(--accent-subtle), 0 4px 14px var(--accent-glow);
}
#time-left {
    font-family: var(--font-mono);
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
}
#timer-display.time-warning { border-color: var(--danger); background: var(--danger-subtle); }
#timer-display.time-warning #time-left { color: var(--danger); }
 
/* ============================================================
   SPINNER
   ============================================================ */
.spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
    margin-left: var(--space-2);
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
 
/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-wrapper { margin-bottom: var(--space-4); }
.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}
.progress-track {
    width: 100%;
    height: 6px;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}
 
/* ============================================================
   THEME / LANG TOGGLE
   ============================================================ */
.theme-toggle {
    display: block;
    margin-left: auto;
    margin-bottom: var(--space-5);
    width: auto;
    padding: var(--space-2) var(--space-3);
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}
.theme-toggle:hover { background: var(--surface-sunken); color: var(--text-primary); box-shadow: none; }
 
.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
.header-actions .theme-toggle {
    display: inline-flex;
    margin-left: 0;
    margin-bottom: 0;
}
 
.lang-toggle {
    width: auto;
    padding: var(--space-2) var(--space-3);
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}
.lang-toggle:hover { background: var(--surface-sunken); color: var(--text-primary); box-shadow: none; }
 
.quiz-header-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}
.quiz-header-actions .theme-toggle { display: inline-flex; margin-left: 0; margin-bottom: 0; }
 
/* ============================================================
   ANTI-CHEATING UI
   ============================================================ */
.violation-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: var(--danger);
    color: #fff;
    text-align: center;
    padding: var(--space-3) var(--space-4);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}
.fullscreen-notice {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    text-align: center;
    margin: var(--space-3) 0 0;
}
[dir="rtl"] .violation-banner,
[dir="rtl"] .fullscreen-notice,
[dir="rtl"] label,
[dir="rtl"] h1,
[dir="rtl"] h2,
[dir="rtl"] h3,
[dir="rtl"] p {
    text-align: right;
}
[dir="rtl"] .quiz-header-actions { justify-content: flex-start; }
[dir="rtl"] .theme-toggle { margin-left: 0; margin-right: auto; }
[dir="rtl"] label { flex-direction: row-reverse; justify-content: flex-end; }
 
/* ============================================================
   ASSIGNMENT SECTION (student-facing, inside login form)
   ============================================================ */
#assignment-section {
    background: var(--accent-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
#assignment-section.hidden { display: none; }
#assignment-section h3 { margin: 0; color: var(--accent); }
#assignment-section .field { margin: 0; }
#assignment-name { margin: 0; font-size: 0.9rem; color: var(--text-secondary); }
 
/* ============================================================
   ADMIN — QUESTION LIST / TABS / BADGES
   ============================================================ */
.question-list { margin-top: var(--space-2); display: flex; flex-direction: column; gap: var(--space-3); }
.question-card {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition), transform var(--transition);
}
.question-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.question-card p { margin: var(--space-1) 0; }
.question-card .q-options { font-size: 0.85rem; color: var(--text-secondary); margin: var(--space-2) 0; }
.question-card .q-actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); align-items: center; flex-wrap: wrap; }
.question-card .q-actions button { flex: 1; margin: 0; min-height: 40px; }
.question-card .q-actions .marks-input { flex: 0 0 auto; width: auto; font-family: var(--font-mono); }
.question-card .q-actions .save-marks-btn { flex: 0 0 auto; }
.empty-state { text-align: center; color: var(--text-tertiary); padding: var(--space-6) 0; }
 
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-5);
    gap: var(--space-3);
    flex-wrap: wrap;
}
 
.badge {
    background: var(--accent-subtle);
    color: var(--accent);
    padding: 2px var(--space-3);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-mono);
    box-shadow: 0 0 0 1px var(--border-strong) inset;
}
 
.error-text {
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
    min-height: 1.2em;
}
 
.tabs {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-5);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-1);
}
.tabs button {
    flex: 1;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    box-shadow: none;
    font-weight: 600;
}
.tabs button:hover { background: var(--surface); box-shadow: none; }
.tabs button.active {
    background: var(--accent);
    color: var(--text-on-accent);
    border-color: var(--accent);
    box-shadow: 0 2px 6px var(--accent-glow);
}
 
.rank-1 { font-weight: 700; color: var(--accent); }
.rank-medal { margin-right: var(--space-2); }
 
/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 600px) {
    body { padding: var(--space-3); align-items: flex-start; }
    .container { padding: var(--space-5); margin: var(--space-3) auto; border-radius: var(--radius-md); }
    h1 { font-size: 1.3rem; margin-bottom: var(--space-5); }
    h2 { font-size: 1.05rem; }
    input, select, button, textarea { padding: var(--space-3); font-size: 16px; }
    table { display: block; overflow-x: auto; white-space: nowrap; }
    th, td { padding: var(--space-2); }
    #timer-display { width: 84px; height: 84px; }
    #time-left { font-size: 1.4rem; }
    .theme-toggle { margin-bottom: var(--space-4); }
    .quiz-header-actions { margin-bottom: var(--space-4); }
    .field-row { grid-template-columns: 1fr; }

    /* Tabs: shrink to fit narrow phones; swipe horizontally as a fallback
       on the very smallest screens instead of squeezing/overlapping text. */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tabs button {
        flex: 0 0 auto;
        white-space: nowrap;
        font-size: 0.78rem;
        padding: var(--space-2) var(--space-3);
    }
    .tabs button .badge { font-size: 0.65rem; padding: 1px var(--space-2); }

    /* q-actions buttons: let them wrap onto their own line instead of
       staying flex:1 side-by-side, which got too narrow to tap comfortably. */
    .question-card .q-actions button { flex: 1 1 auto; min-width: 120px; }
}
/* ============================================================
   APP SHELL — sidebar + main content (dashboard-style pages)
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    padding: var(--space-5) 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-5) var(--space-6);
    color: #fff;
}
.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: block;
    object-fit: contain;
    flex-shrink: 0;
}
.sidebar-brand-text {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 16px;
    color: #fff;
    line-height: 1.4;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 var(--space-3);
    flex: 1;
}
.sidebar .sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-ink);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    min-height: 44px;
    line-height: 1.45;
    box-shadow: none;
    transform: none;
}
.sidebar .sidebar-link:hover { background: rgba(255,255,255,0.06); color: #fff; box-shadow: none; transform: none; }
.sidebar .sidebar-link.active { background: var(--sidebar-active-bg); color: #fff; }
.sidebar .sidebar-link:focus-visible { outline: 2px solid #B7D5F0; outline-offset: -2px; box-shadow: none; }
.sidebar .sidebar-label { min-width: 0; flex: 1; color: inherit; }
.sidebar .sidebar-link .icon { flex: 0 0 18px; display: flex; color: inherit; }
.sidebar .sidebar-link .icon svg { display: block; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar .badge { flex-shrink: 0; color: #D9E9F7; background: var(--sidebar-control-bg); box-shadow: none; border: 1px solid var(--sidebar-border); padding: 1px 8px; font-size: 11px; }

.sidebar-footer {
    padding: var(--space-3) var(--space-5) 0;
    border-top: 1px solid var(--sidebar-border);
    margin-top: var(--space-3);
}
.sidebar-footer .theme-toggle, .sidebar-footer .btn-danger { display: block; min-height: 44px; margin-left: 0; padding: 10px 12px; font-size: 13px; box-shadow: none; transform: none; }
.sidebar-footer .theme-toggle { color: #fff; background: var(--sidebar-control-bg); border: 1px solid var(--sidebar-border); }
.sidebar-footer .theme-toggle:hover { color: #fff; background: var(--sidebar-active-bg); box-shadow: none; transform: none; }
.sidebar-footer .btn-danger { color: #fff; background: #B3392E; }
.sidebar-footer .btn-danger:hover { background: #9C2B22; box-shadow: none; transform: none; }
.sidebar-footer button:focus-visible { outline: 2px solid #B7D5F0; outline-offset: 2px; box-shadow: none; }
.sidebar-user { display: flex; align-items: center; gap: var(--space-3); padding-top: var(--space-4); }
.sidebar-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #fff; }
.sidebar-user-role { font-size: 11.5px; color: var(--sidebar-ink); }

.shell-main {
    flex: 1;
    min-width: 0;
    padding: var(--space-8) var(--space-10);
    max-width: 1200px;
}

.shell-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-7);
    flex-wrap: wrap;
    gap: var(--space-3);
}
.shell-page-title { font-family: var(--font-heading); font-weight: 600; font-size: 24px; color: var(--text-primary); margin: 0 0 4px; }
.shell-page-subtitle { font-size: 13.5px; color: var(--text-secondary); margin: 0; font-family: var(--font-ui); }
.shell-page-date { font-size: 12.5px; color: var(--text-tertiary); font-family: var(--font-mono); }

/* ---- Stat cards ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); }
.stat-icon {
    width: 34px; height: 34px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; margin-bottom: var(--space-4);
}
.stat-icon.blue { background: var(--accent-subtle); color: var(--accent); }
.stat-icon.teal { background: var(--teal-subtle); color: var(--teal); }
.stat-icon.warn { background: var(--warning-subtle); color: var(--warning); }
.stat-label { font-size: 12.5px; color: var(--text-secondary); margin: 0 0 4px; font-family: var(--font-ui); }
.stat-value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; color: var(--text-primary); }

/* ---- Panel / v2 table ---- */
.shell-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5) var(--space-6); }
.shell-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-4); }
.shell-panel-title { font-family: var(--font-heading); font-weight: 600; font-size: 15.5px; color: var(--text-primary); margin: 0; }
.shell-panel-link { font-size: 12.5px; color: var(--accent); text-decoration: none; font-weight: 500; font-family: var(--font-ui); }

table.v2-table { width: 100%; border-collapse: collapse; font-family: var(--font-ui); }
table.v2-table th {
    text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.03em; color: var(--text-tertiary); padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
}
table.v2-table td { padding: var(--space-3); font-size: 13.5px; border-bottom: 1px solid var(--border); color: var(--text-primary); }
table.v2-table tr:last-child td { border-bottom: none; }
td.mono { font-family: var(--font-mono); font-size: 12.5px; }

.pill { display: inline-block; padding: 3px 10px; border-radius: var(--radius-full); font-size: 11.5px; font-weight: 600; font-family: var(--font-ui); }
.pill.good { background: var(--teal-subtle); color: var(--teal); }
.pill.warn { background: var(--warning-subtle); color: var(--warning); }
.pill.bad { background: var(--danger-subtle); color: var(--danger); }

.shell-empty { color: var(--text-tertiary); font-size: 13px; padding: var(--space-4) 0; text-align: center; }

@media (max-width: 860px) {
    .sidebar { position: fixed; left: -240px; z-index: 30; transition: left 0.2s ease; }
    .sidebar.open { left: 0; }
    .shell-main { padding: var(--space-5) var(--space-4); }
    .mobile-menu-btn {
        display: inline-flex; align-items: center; justify-content: center;
        width: 36px; height: 36px; border-radius: var(--radius-sm);
        border: 1px solid var(--border); background: var(--surface);
        color: var(--text-primary); cursor: pointer; margin-bottom: var(--space-4);
    }
}
@media (min-width: 861px) {
    .mobile-menu-btn { display: none; }
}



/* Student accounts and personal reports */
.portal-section-title { margin-top: 28px; }
.student-page-header { display:flex; align-items:center; justify-content:space-between; gap:16px; padding-bottom:20px; border-bottom:1px solid var(--border); }
.dashboard-back-link { display:inline-flex; align-items:center; gap:10px; min-height:42px; padding:10px 16px; border:1px solid var(--border-strong); border-radius:var(--radius-md); background:var(--surface); color:var(--accent); font-family:var(--font-ui); font-size:13px; font-weight:600; text-decoration:none; transition:background var(--transition),border-color var(--transition); }
.dashboard-back-link:hover { background:var(--accent-subtle); border-color:var(--accent); }
.dashboard-back-link:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.dashboard-back-link svg { flex-shrink:0; }
.page-context,.field-help { color:var(--text-secondary); font-size:12px; }
.report-filters { display:grid; grid-template-columns:1fr 1fr 1.2fr; gap:16px; margin:20px 0; }
.report-filters input,.report-filters select { width:100%; margin-bottom:0; }
.report-toolbar { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:16px; }
.report-toolbar button { width:auto; margin-top:0; }
.section-edit-form { padding:8px 0 20px; margin-bottom:16px; border-bottom:1px solid var(--border); }
.student-delete-btn { width:100%; margin-top:16px; }
@media (max-width:600px) { .report-filters { grid-template-columns:1fr; } .student-page-header,.report-toolbar { align-items:flex-start; flex-direction:column; } .page-context { display:none; } }
.portal-actions { display: flex; gap: 12px; align-items: center; margin: 16px 0; }
.portal-actions button { flex: 1; margin-top: 0; }
.portal-actions span { white-space: nowrap; }
.assignment-report-card { padding: 20px; margin: 16px 0; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-sunken); }
#assignments-list .assignment-report-card > label { display: block; margin: 20px 0 8px; line-height: 1.5; }
#assignments-list .assignment-report-card > input[type="file"] { display: block; margin: 0 0 16px; }
#assignments-list .assignment-report-card > button { margin: 0; max-width: 100%; }
.question-image-preview { display:block; max-width:100%; max-height:320px; object-fit:contain; margin:16px 0; border:1px solid var(--border); border-radius:var(--radius-md); }
.question-thumbnail { display:block; max-width:180px; max-height:110px; object-fit:contain; margin:8px 0; border-radius:var(--radius-sm); }
.assignment-status { font-weight: 600; }
.report-table-wrap { overflow-x: auto; }
.mobile-result-list { display: none; }
.home-page { align-items: center; }
.home-card { text-align: center; max-width: 520px; box-shadow: var(--shadow-md); }
.home-logo { display: block; margin: 0 auto 20px; border-radius: var(--radius-md); }
.home-eyebrow { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; line-height: 1.6; margin: 0 0 12px; }
.home-card h1 { text-align: center; margin: 0 0 16px; font-size: 38px; }
.home-description { font-size: 14px; color: var(--text-secondary); line-height: 1.8; margin: 0; }
.home-features { display: grid; gap: 8px; list-style: none; padding: 20px 0; margin: 20px 0 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.home-features li { font-size: 13px; color: var(--text-primary); line-height: 1.6; }
.home-links { gap: 12px; }
.home-links a { display: flex; align-items: center; justify-content: center; min-height: 48px; text-align: center; }
.home-links a:last-child { background: var(--surface); border: 1px solid var(--border-strong); color: var(--accent); }
.home-links a:last-child:hover { background: var(--accent-subtle); }
.home-grades { margin: 20px 0 0; color: var(--text-secondary); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* Result tables remain available on desktop; narrow screens use readable cards. */
@media (max-width: 860px) {
    .result-desktop-table { display: none; }
    .mobile-result-list { display: grid; gap: 12px; }
    .mobile-result-card { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
    .mobile-result-header { display: flex; align-items: flex-start; gap: 10px; padding: 16px; }
    .result-rank { flex: 0 0 28px; height: 28px; display: grid; place-items: center; background: var(--accent-subtle); color: var(--accent); border-radius: 50%; font-size: 12px; font-weight: 700; }
    .result-rank-first { background: var(--warning-subtle); color: var(--warning); }
    .mobile-result-student { min-width: 0; flex: 1; }
    .mobile-result-student h3 { margin: 0; font-family: var(--font-ui); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
    .mobile-result-meta { margin: 5px 0 0; font-size: 11px; line-height: 1.6; color: var(--text-secondary); overflow-wrap: anywhere; }
    .mobile-result-score { flex-shrink: 0; text-align: end; }
    .mobile-result-score strong { display: block; color: var(--accent); font-family: var(--font-ui); font-size: 19px; line-height: 1.4; }
    .mobile-result-score > span { display: block; margin-top: 5px; font-size: 11px; color: var(--text-secondary); }
    .mobile-result-metrics { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin: 0 16px 16px; }
    .mobile-result-metrics > div { min-width: 0; padding: 12px; background: var(--surface-sunken); border-radius: var(--radius-md); }
    .mobile-result-metrics span { display: block; font-size: 10px; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 6px; }
    .mobile-result-metrics strong { display: block; font-family: var(--font-mono); font-size: 14px; color: var(--accent); overflow-wrap: anywhere; }
    .mobile-result-details { border-top: 1px solid var(--border); }
    .mobile-result-details summary { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--accent); cursor: pointer; list-style: none; }
    .mobile-result-details summary::-webkit-details-marker { display: none; }
    .mobile-result-details summary::after { content: '⌄'; font-size: 16px; }
    .mobile-result-details[open] summary::after { content: '⌃'; }
    .mobile-result-details summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; border-radius: var(--radius-sm); }
    .mobile-result-detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin: 0; padding: 4px 16px 16px; }
    .mobile-result-detail-grid dt { font-size: 10px; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 6px; }
    .mobile-result-detail-grid dd { font-size: 12px; font-weight: 600; margin: 0; overflow-wrap: anywhere; }
    .results-page .report-filters { grid-template-columns: minmax(0, 1fr); padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
    .results-page .report-filters > div { min-width: 0; }
    .results-page .results-summary-toolbar { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 12px; }
    .results-page .results-summary-toolbar p { margin: 0; font-size: 12px; }
    .results-page .results-summary-toolbar button { flex: 0 1 auto; font-size: 12px; padding: 12px; }
    .results-page .results-actions { flex-wrap: wrap; gap: 12px; }
    .results-page .results-actions button { flex: 1 1 180px; margin-top: 0; }
    .student-portal:has(#dashboard:not(.hidden)) { background: var(--bg); box-shadow: none; }
    .student-portal #student-heading, .student-portal .assignment-report-card { overflow-wrap: anywhere; }
    .student-portal .portal-start-actions { display: flex; flex-wrap: wrap; gap: 12px; }
    .student-portal .portal-start-actions button { flex: 1 1 140px; margin: 0; }
    .student-portal #dashboard > .portal-actions { flex-wrap: nowrap; }
    .student-portal #dashboard > .portal-actions button { min-width: 0; font-size: 13px; padding-inline: 10px; }
}
@media (max-width: 600px) {
    .home-page { padding: 16px; }
    .home-card { padding: 24px; margin: 16px auto; }
    #dashboard-tab-content .stat-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-bottom: 24px; }
    #dashboard-tab-content .stat-card { padding: 16px; min-width: 0; }
    #dashboard-tab-content .stat-label { font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
    #dashboard-tab-content .stat-icon { margin-bottom: 12px; }
    #dashboard-tab-content .shell-panel { padding: 0; border: 0; background: transparent; }
    #dashboard-tab-content .shell-page-header > div { min-width: 0; }
    #dashboard-tab-content .shell-page-date { display: none; }
    .results-page { background: var(--bg); padding: 20px 16px; box-shadow: none; }
}
#message, #account-message, #save-status { overflow-wrap: anywhere; }
.student-portal #login-container { max-width: 420px; margin-inline: auto; }
.student-portal #question-title { margin-top: 24px; }
.translation-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-block: 16px; }
.translation-toolbar button { width: auto; margin: 0; }
.translation-status { color: var(--text-secondary); font-size: 13px; }
.urdu-preview { margin-block: 12px; }
.urdu-preview summary { cursor: pointer; color: var(--accent); }
.urdu-preview p, [lang="ur"]#question-title, .option-btn[lang="ur"] { font-family: "Noto Nastaliq Urdu", "Segoe UI", sans-serif; line-height: 2; }
.translation-notice { color: var(--text-secondary); font-size: 13px; line-height: 1.8; }
.student-portal #question-title[dir="ltr"] { text-align: left; }
.student-portal #options-container { display: grid; gap: 10px; }
.student-portal #options-container .option-btn { width: 100%; margin: 0; overflow-wrap: anywhere; }
/* Keep the active quiz compact without shrinking profile and report controls. */
.student-portal #quiz-container { max-width: 720px; margin-inline: auto; }
.quiz-countdown { display: grid; justify-items: center; gap: 6px; margin: 8px auto 16px; }
.student-portal #timer-display { position: relative; width: 96px; height: 96px; margin: 0; border: 0; background: transparent; box-shadow: none; color: var(--accent); }
.timer-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.timer-ring circle { fill: none; stroke-width: 6; }
.timer-ring-track { stroke: var(--accent-subtle-strong); }
#timer-ring-progress { stroke: currentColor; stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.student-portal #time-left { position: relative; color: var(--text-primary); font-size: 23px; direction: ltr; font-variant-numeric: tabular-nums; line-height: 1; letter-spacing: -0.04em; white-space: nowrap; }
.timer-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); line-height: 1.5; }
.student-portal #timer-display.time-warning { color: var(--danger); background: transparent; }
.student-portal #timer-display.time-warning .timer-ring-track { stroke: var(--danger-subtle); }
@media (prefers-reduced-motion: reduce) { #timer-ring-progress { transition: none; } }
.student-portal #progress-text, .student-portal #save-status { font-size: 13px; line-height: 1.5; margin: 10px 0; }
.student-portal #save-status { min-height: 20px; }
.student-portal #question-title { font-family: var(--font-ui); font-size: 17px; line-height: 1.6; margin: 16px 0; overflow-wrap: anywhere; }
.student-portal #question-title[lang="ur"] { font-family: "Noto Nastaliq Urdu", "Segoe UI", sans-serif; font-size: 18px; line-height: 1.8; }
.student-portal #options-container { gap: 8px; }
.student-portal #options-container .option-btn { min-height: 44px; padding: 8px 14px; font-size: 14px; line-height: 1.5; }
.student-portal #options-container .option-btn[lang="ur"] { font-size: 16px; line-height: 1.7; }
.student-portal #quiz-container .portal-actions { gap: 10px; margin: 12px 0; }
.student-portal #quiz-container .portal-actions button, .student-portal #finish-btn { min-height: 44px; padding: 8px 14px; font-size: 14px; line-height: 1.5; }
.student-portal #quiz-container .portal-actions button { min-width: 0; }
.student-portal #finish-btn { margin-top: 0; }
@media (max-width: 600px) { .portal-actions { flex-wrap: wrap; } .portal-actions button { min-width: 120px; } }
