/* ------------------------------------------------------------------
   Staff stylesheet — qbank and admin.

   Every colour comes from tokens.css. A hard-coded value here looks
   right in whichever mode it was written in and wrong in the other,
   and nobody notices until a user switches. That includes rgba() —
   the rule is about colour, not about notation.
------------------------------------------------------------------ */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-ui);
    background: var(--surface-page);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ==================================================================
   Shell
   ================================================================== */

.shell {
    display: flex;
    min-height: 100vh;
}

/* -- sidebar ------------------------------------------------------ */

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface-raised);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    z-index: 40;
}

.sidebar-head {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--border);
    position: relative;
    font-weight: 600;
}

.brand-short {
    display: none;
}

.brand-full {
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-toggle {
    position: absolute;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.sidebar-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Only useful while the drawer covers the page. */
.drawer-close {
    display: none;
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    line-height: 1;
    padding: var(--space-1) var(--space-2);
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4) 0;
    overflow-y: auto;
}

.nav-group {
    margin-bottom: var(--space-6);
}

.nav-label {
    padding: 0 var(--space-4);
    margin-bottom: var(--space-2);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
}

.sidebar-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    color: var(--text-secondary);
    white-space: nowrap;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--surface-sunken);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-nav a[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 500;
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: var(--space-3);
    background: var(--surface-sunken);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.sidebar-nav a[aria-current="page"] .nav-icon {
    background: var(--accent);
    color: var(--text-on-accent);
}

/* -- collapsed ---------------------------------------------------- */

.sidebar-collapsed .sidebar {
    width: var(--sidebar-w-collapsed);
}

.sidebar-collapsed .brand-full,
.sidebar-collapsed .nav-text,
.sidebar-collapsed .nav-label {
    display: none;
}

.sidebar-collapsed .brand-short {
    display: block;
}

.sidebar-collapsed .sidebar-head {
    justify-content: center;
    padding: 0;
}

.sidebar-collapsed .sidebar-toggle {
    transform: translateY(-50%) rotate(180deg);
}

.sidebar-collapsed .sidebar-nav a {
    padding: var(--space-2) 0;
    justify-content: center;
}

.sidebar-collapsed .nav-icon {
    margin-right: 0;
}

/* -- main column -------------------------------------------------- */

.main-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.header {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-5);
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.hamburger {
    display: none;
    background: none;
    border: none;
    padding: 4px;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
}

.page-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.theme-select {
    padding: var(--space-1) var(--space-2);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
}

.user-name {
    font-size: 14px;
    color: var(--text-secondary);
}

.signout-form {
    margin: 0;
    padding: 0;
    display: inline-flex;
}

.btn-signout {
    background: none;
    border: none;
    padding: 4px;
    font-size: 16px;
    line-height: 1;
    color: var(--text-faint);
    cursor: pointer;
}

.btn-signout:hover {
    color: var(--state-danger);
}

.content {
    flex: 1;
    padding: var(--space-6);
}

/* ==================================================================
   Components
   ================================================================== */

/* -- buttons ------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-raised);
    color: var(--text-primary);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.1s, border-color 0.1s;
}

.btn:hover {
    background: var(--surface-sunken);
    text-decoration: none;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-on-accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--text-on-accent);
}

.btn-danger {
    color: var(--state-danger);
}

.btn-danger:hover {
    background: var(--state-danger-soft);
    border-color: var(--state-danger);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
}

/* -- panels ------------------------------------------------------- */

.panel {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-6);
}

.panel-head {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.panel-body {
    padding: var(--space-5);
}

/* -- stats -------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.stat-card {
    padding: var(--space-5);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.stat-val {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: var(--space-1);
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 13px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* -- tables -------------------------------------------------------
   The question bank is the screen the teacher lives in, so the rows
   get the attention: hairline rules, a sticky header, no per-row card
   chrome competing with the content.                                */

.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.table th {
    /* Sticky resolves inside .table-wrap, not the viewport, because
     overflow-x makes that a scroll container. An offset here pushes
     the header down and hides whatever row sits under it. */

    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface-page);
    font-weight: 600;
    color: var(--text-secondary);
}

.table th,
.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-strong);
}

.table tbody tr:hover td {
    background: var(--surface-sunken);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table td.num {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.table td.actions {
    text-align: right;
    white-space: nowrap;
}

/* -- forms -------------------------------------------------------- */

.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font: inherit;
    font-size: 14px;
}

.form-control:focus {
    outline: none;
    border-color: var(--focus-ring);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

::placeholder {
    color: var(--text-muted);
}

.hint {
    margin-top: var(--space-1);
    font-size: 12px;
    color: var(--text-muted);
    max-width: 70ch;
}

/* -- notices ------------------------------------------------------
   Class names are success / error / warn / info. flash() uses the
   same four words; a fifth spelling silently renders unstyled.     */

.notice {
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 14px;
}

.notice-success {
    background: var(--state-success-soft);
    color: var(--state-success);
    border-color: currentColor;
}

.notice-error {
    background: var(--state-danger-soft);
    color: var(--state-danger);
    border-color: currentColor;
}

.notice-warn {
    background: var(--state-warning-soft);
    color: var(--state-warning);
    border-color: currentColor;
}

.notice-info {
    background: var(--state-info-soft);
    color: var(--state-info);
    border-color: currentColor;
}

/* -- pills --------------------------------------------------------
   These appear hundreds of times down a list, so they carry the type
   in the text colour and a hairline, not in a filled background.   */

.pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface-sunken);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
}

.pill-type-single {
    color: var(--type-single-text);
    border-color: var(--type-single-border);
}

.pill-type-multiple {
    color: var(--type-multiple-text);
    border-color: var(--type-multiple-border);
}

.pill-type-numerical {
    color: var(--type-numerical-text);
    border-color: var(--type-numerical-border);
}

.pill-type-passage {
    color: var(--type-passage-text);
    border-color: var(--type-passage-border);
}

.pill-warn {
    color: var(--state-warning);
    border-color: var(--state-warning);
}

/* -- empty state -------------------------------------------------- */

.empty-state {
    padding: var(--space-7) var(--space-5);
    text-align: center;
    color: var(--text-muted);
}

.empty-state strong {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--text-primary);
    font-weight: 600;
}

/* ==================================================================
   Mobile drawer
   ================================================================== */

.drawer-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay-scrim);
    z-index: 45;
}

@media (max-width: 899px) {
    .hamburger {
        display: block;
    }

    .sidebar-toggle {
        display: none;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: calc(var(--sidebar-w) * -1);
        /* The collapsed-to-icons idea does not apply here: off-canvas is
       already the space saving, and icon-only in a drawer is worse
       than useless. */
        width: var(--sidebar-w) !important;
        box-shadow: var(--shadow-md);
        transition: transform 0.25s ease;
        z-index: 50;
    }

    .brand-full,
    .nav-label,
    .nav-text {
        display: block !important;
    }

    .brand-short {
        display: none !important;
    }

    .drawer-close {
        display: block;
    }

    .sidebar-head {
        justify-content: flex-start !important;
        padding: 0 var(--space-4) !important;
    }

    .sidebar-nav a {
        padding: var(--space-2) var(--space-4) !important;
        justify-content: flex-start !important;
    }

    .nav-icon {
        margin-right: var(--space-3) !important;
    }

    .drawer-open .sidebar {
        transform: translateX(100%);
    }

    .drawer-open .drawer-scrim {
        display: block;
    }

    .content {
        padding: var(--space-4);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ==================================================================
   Results screens — attempts list and per-attempt review

   Append to assets/css/admin.css. Staff tokens only: the --s- and
   --cbt- families belong to the student side, which is always light,
   so using one here looks correct until somebody switches to dark.
   ================================================================== */

/* -- filter bar --------------------------------------------------- */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-end;
}

.filter-bar .form-group {
    margin-bottom: 0;
    flex: 1 1 160px;
}

.filter-actions {
    margin-left: auto;
    display: flex;
    gap: var(--space-2);
}

/* -- table cells -------------------------------------------------- */

.cell-main {
    font-weight: 600;
}

.cell-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.num-strong {
    font-variant-numeric: tabular-nums;
    font-size: 16px;
}

.col-id {
    width: 70px;
}

.sort-link {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.sort-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

.inline-form {
    display: inline;
    margin: 0;
}

.actions-wrap {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
    flex-wrap: wrap;
}

.tally-correct {
    color: var(--state-success);
    font-weight: 600;
}

.tally-wrong {
    color: var(--state-danger);
    font-weight: 600;
}

.tally-partial {
    color: var(--state-warning);
    font-weight: 600;
}

/* -- extra pills --------------------------------------------------
   The base .pill carries the border and the muted text; these only
   change the colour, so a pill never becomes a solid block competing
   with the row it sits in.                                          */

.pill-ok {
    color: var(--state-success);
    border-color: var(--state-success);
}

.pill-live {
    color: var(--state-info);
    border-color: var(--state-info);
}

/* -- pager -------------------------------------------------------- */

.pager {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4);
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.pager-gap {
    color: var(--text-faint);
}

.pager-count {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-muted);
}

/* -- attempt header ----------------------------------------------- */

.attempt-head {
    display: flex;
    justify-content: space-between;
    gap: var(--space-5);
    flex-wrap: wrap;
    align-items: flex-start;
}

.attempt-head h2 {
    margin: 0 0 var(--space-1);
}

.attempt-score {
    text-align: right;
}

.score-big {
    font-size: 30px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.score-max {
    font-size: 15px;
    font-weight: 400;
    color: var(--text-muted);
}

/* -- section divider ---------------------------------------------- */

.section-head {
    margin: var(--space-6) 0 var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--border);
}

.section-head h3 {
    margin: 0;
}

/* -- one reviewed question ---------------------------------------- */

.review-q {
    margin-bottom: var(--space-5);
}

.review-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.review-marks {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.review-text {
    font-size: 16px;
    margin-bottom: var(--space-4);
}

.review-img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: var(--space-3) 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-sunken);
}

.passage-box,
.solution-box {
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--surface-sunken);
}

.solution-box {
    margin: var(--space-4) 0 0;
    border-left-color: var(--state-info);
}

/* -- options ------------------------------------------------------ */

.review-options {
    list-style: none;
    margin: 0;
    padding: 0;
}

.review-option {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Correct and chosen are separate facts and can both be true, so they
   are separate classes rather than one state. A wrong pick and the
   right answer must both be visible on the same question. */
.review-option.is-correct {
    border-color: var(--state-success);
    background: var(--state-success-soft);
}

.review-option.is-wrong {
    border-color: var(--state-danger);
    background: var(--state-danger-soft);
}

.review-option.is-right {
    border-width: 2px;
}

.opt-letter {
    flex: none;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    background: var(--surface-raised);
}

.opt-body {
    flex: 1;
    min-width: 0;
}

.opt-img {
    display: block;
    max-width: 320px;
    width: 100%;
    height: auto;
    margin-top: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-raised);
}

.opt-tags {
    flex: none;
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.tag {
    font-size: 12px;
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text-muted);
    white-space: nowrap;
}

.tag-ok {
    color: var(--state-success);
    border-color: var(--state-success);
}

/* -- numerical ---------------------------------------------------- */

.numeric-compare {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.numeric-box {
    flex: 1 1 180px;
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-sunken);
}

.numeric-val {
    font-size: 17px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-top: var(--space-1);
}

@media (max-width: 700px) {
    .attempt-score {
        text-align: left;
    }

    .filter-actions {
        margin-left: 0;
    }

    .review-option {
        flex-wrap: wrap;
    }
}

/* ==================================================================
   Form layout helpers — append to assets/css/admin.css, after the
   results block.
   ================================================================== */

/* A row of fields that wraps on narrow screens. Replaces the inline
   flex declarations that were repeated on every form. */
.field-row {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.field-row .form-group {
    flex: 1 1 200px;
    margin-bottom: 0;
}

.field-row .grow-2 {
    flex: 2 1 320px;
}

/* A panel header with something on the right, usually a button. */
.panel-head-split {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

/* Narrow inputs inside a table read badly at the default width. */
.table .form-control {
    min-width: 72px;
}

.table td .hint {
    margin-top: var(--space-1);
}

/* ==================================================================
   Chapters screen — append to assets/css/admin.css
   ================================================================== */

.tab-row {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.cell-center {
    text-align: center;
}

.col-narrow {
    flex: 0 0 90px;
    width: 90px;
}

.col-auto {
    flex: 0 0 auto;
}

.check-inline {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: 8px 0;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
}

.check-inline input {
    width: auto;
    margin: 0;
    accent-color: var(--accent);
}

.is-hidden {
    display: none;
}

.field-row {
    display: flex;
    gap: var(--space-4);
    align-items: flex-end;
    flex-wrap: wrap;
}

.grow-2 {
    flex: 2 1 200px;
}
.publish-status {
    margin: 20px 0;
}

.publish-warnings {
    margin-bottom: 20px;
}

.table-publish-preview {
    max-width: 400px;
}

@media print {
    .sidebar, .header { display: none !important; }
    .main-col { margin-left: 0 !important; padding: 0 !important; }
    body { background: transparent; }
}

@media print {
    .btn, .no-print { display: none !important; }
}
