/* ==========================================================================
   QuizWeb design system
   1. Tokens
   2. Base / typography
   3. Layout primitives  (.page-head, .surface, .section-head, .empty-state)
   4. Bootstrap override layer  (buttons, forms, cards, tables, alerts)
   5. App-specific shared pieces
   ========================================================================== */

/* ------------------------------------------------------------------ *
 * 1. Tokens
 * ------------------------------------------------------------------ */
:root {
    /* Brand - indigo */
    --brand-50: #eef2ff;
    --brand-100: #e0e7ff;
    --brand-200: #c7d2fe;
    --brand-300: #a5b4fc;
    --brand-400: #818cf8;
    --brand-500: #6366f1;
    --brand-600: #4f46e5;
    --brand-700: #4338ca;
    --brand-800: #3730a3;

    /* Neutrals - slate */
    --ink-900: #0f172a;
    --ink-800: #1e293b;
    --ink-700: #334155;
    --ink-600: #475569;
    --ink-500: #64748b;
    --ink-400: #94a3b8;
    --ink-300: #cbd5e1;
    --ink-200: #e2e8f0;
    --ink-100: #f1f5f9;
    --ink-50: #f8fafc;

    /* Semantic */
    --success: #059669;
    --success-soft: #ecfdf5;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --info: #0284c7;
    --info-soft: #f0f9ff;
    --gold: #f59e0b;

    /* Roles */
    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-muted: var(--ink-50);
    --border: #e6e9f2;
    --border-strong: var(--ink-300);
    --text: var(--ink-800);
    /* Darker than the ink-500/400 pair these used to point at: on the #f5f6fb page
       background those measured 4.4:1 and 2.4:1, under the 4.5:1 WCAG AA needs for text
       this size. These are 5.4:1 and 5.0:1 and keep the same light-to-dark order. */
    --text-muted: #5a6675;
    --text-faint: #5f6b7d;
    --heading: var(--ink-900);
    --accent: var(--brand-600);
    --accent-soft: var(--brand-50);

    /* Gradients */
    --grad-brand: linear-gradient(135deg, var(--brand-500) 0%, var(--brand-700) 100%);
    --grad-brand-soft: linear-gradient(135deg, var(--brand-50) 0%, var(--brand-100) 100%);

    /* Radii */
    --r-xs: 6px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 20px;
    --r-pill: 999px;

    /* Elevation - slate tinted, never pure black */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.08), 0 4px 8px rgba(15, 23, 42, 0.04);
    --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.10), 0 8px 16px rgba(15, 23, 42, 0.04);
    --ring: 0 0 0 3px rgba(99, 102, 241, 0.25);

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --t-fast: 0.15s var(--ease);
    --t-base: 0.22s var(--ease);

    /* Type */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    /* Chrome */
    --header-h: 4rem;

    /* Bootstrap bridge */
    --bs-body-font-family: var(--font-sans);
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--text);
    --bs-emphasis-color: var(--heading);
    --bs-secondary-color: var(--text-muted);
    --bs-border-color: var(--border);
    --bs-border-radius: var(--r-md);
    --bs-border-radius-sm: var(--r-sm);
    --bs-border-radius-lg: var(--r-lg);
    --bs-primary: var(--brand-600);
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: var(--brand-600);
    --bs-link-color-rgb: 79, 70, 229;
    --bs-link-hover-color: var(--brand-700);
    --bs-focus-ring-color: rgba(99, 102, 241, 0.25);
}

/* ------------------------------------------------------------------ *
 * 2. Base / typography
 * ------------------------------------------------------------------ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

html,
body {
    font-family: var(--font-sans);
}

/* Sticky-footer shell. The header/main/footer are direct children of body,
   so this plumbing lives here rather than in MainLayout's scoped stylesheet. */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: var(--bg);
    color: var(--text);
    font-size: 1rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body > .site-main {
    flex: 1 0 auto;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--heading);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

h1:focus,
h1:focus-visible {
    outline: none;
}

a {
    color: var(--brand-600);
    text-decoration: none;
    transition: color var(--t-fast);
}

a:hover {
    color: var(--brand-700);
    text-decoration: underline;
}

a.btn:hover,
a.nav-link:hover,
a.dropdown-item:hover,
a.list-group-item:hover,
a.card:hover {
    text-decoration: none;
}

hr {
    border-color: var(--border);
    opacity: 1;
}

code, pre, .font-monospace {
    font-family: var(--font-mono);
}

::selection {
    background: var(--brand-100);
    color: var(--brand-800);
}

:focus-visible {
    outline: 2px solid var(--brand-500);
    outline-offset: 2px;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* ------------------------------------------------------------------ *
 * 3. Layout primitives
 * ------------------------------------------------------------------ */

/* Page header: title on the left, actions on the right. */
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.page-head-text {
    min-width: 0;
}

.page-kicker {
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-faint);
    margin-bottom: 0.3rem;
}

.page-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.75rem;
    margin: 0;
}

.page-title > .bi {
    color: var(--brand-600);
}

.page-sub {
    color: var(--text-muted);
    margin: 0.35rem 0 0;
    max-width: 62ch;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

/* Section heading inside a page. */
.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
}

.section-title {
    font-size: 1.25rem;
    margin: 0;
}

.section-note {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Generic elevated white panel. */
.surface {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}

.surface-pad {
    padding: 1.35rem 1.4rem;
}

/* Empty / zero states. */
.empty-state {
    text-align: center;
    padding: 2.75rem 1.25rem;
    color: var(--text-muted);
}

.empty-state > .bi {
    display: block;
    font-size: 2.25rem;
    color: var(--ink-300);
    margin-bottom: 0.75rem;
}

.empty-state p {
    margin-bottom: 1rem;
}

.empty-state-title {
    color: var(--heading);
    font-weight: 650;
    font-size: 1.05rem;
    margin-bottom: 0.25rem;
}

/* Centred loading block. */
.loading-state {
    text-align: center;
    padding: 3.5rem 1rem;
    color: var(--text-muted);
}

.loading-state p {
    margin: 0.85rem 0 0;
}

/* Stat tiles - shared by dashboard and profile. */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.9rem;
}

.stat-tile {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.1rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--t-base), transform var(--t-base);
}

.stat-tile:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    width: 2.5rem;
    height: 2.5rem;
    flex: none;
    border-radius: var(--r-md);
    background: var(--accent-soft);
    color: var(--brand-600);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.stat-label,
.stat-hint {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.stat-value {
    display: block;
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--heading);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

/* Small pill label. */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.7rem;
    border-radius: var(--r-pill);
    font-size: 0.75rem;
    font-weight: 650;
    line-height: 1.5;
    background: var(--ink-100);
    color: var(--ink-600);
    white-space: nowrap;
}

.pill-brand { background: var(--accent-soft); color: var(--brand-700); }
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-warning { background: var(--warning-soft); color: var(--warning); }

/* ------------------------------------------------------------------ *
 * 4. Bootstrap override layer
 * ------------------------------------------------------------------ */

/* --- Buttons --- */
.btn {
    --bs-btn-border-radius: var(--r-sm);
    --bs-btn-font-weight: 600;
    --bs-btn-padding-x: 1rem;
    --bs-btn-padding-y: 0.5rem;
    transition: background-color var(--t-fast), border-color var(--t-fast),
                color var(--t-fast), box-shadow var(--t-base), transform var(--t-fast);
}

.btn:active {
    transform: translateY(1px);
}

.btn-sm {
    --bs-btn-border-radius: var(--r-xs);
    --bs-btn-padding-x: 0.7rem;
    --bs-btn-padding-y: 0.32rem;
}

.btn-lg {
    --bs-btn-border-radius: var(--r-md);
    --bs-btn-padding-x: 1.35rem;
    --bs-btn-padding-y: 0.7rem;
    --bs-btn-font-size: 1.02rem;
}

.btn-primary {
    --bs-btn-bg: var(--brand-600);
    --bs-btn-border-color: var(--brand-600);
    --bs-btn-hover-bg: var(--brand-700);
    --bs-btn-hover-border-color: var(--brand-700);
    --bs-btn-active-bg: var(--brand-800);
    --bs-btn-active-border-color: var(--brand-800);
    --bs-btn-disabled-bg: var(--brand-300);
    --bs-btn-disabled-border-color: var(--brand-300);
    box-shadow: var(--shadow-xs);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand-600);
    --bs-btn-border-color: var(--brand-200);
    --bs-btn-hover-bg: var(--brand-600);
    --bs-btn-hover-border-color: var(--brand-600);
    --bs-btn-active-bg: var(--brand-700);
    --bs-btn-active-border-color: var(--brand-700);
}

.btn-outline-secondary {
    --bs-btn-color: var(--ink-700);
    --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-bg: var(--ink-100);
    --bs-btn-hover-border-color: var(--ink-400);
    --bs-btn-hover-color: var(--ink-900);
    --bs-btn-active-bg: var(--ink-200);
    --bs-btn-active-border-color: var(--ink-400);
    --bs-btn-active-color: var(--ink-900);
}

.btn-outline-danger {
    --bs-btn-color: var(--danger);
    --bs-btn-border-color: #fecaca;
    --bs-btn-hover-bg: var(--danger);
    --bs-btn-hover-border-color: var(--danger);
}

.btn-danger {
    --bs-btn-bg: var(--danger);
    --bs-btn-border-color: var(--danger);
    --bs-btn-hover-bg: #b91c1c;
    --bs-btn-hover-border-color: #b91c1c;
}

.btn-link {
    --bs-btn-color: var(--brand-600);
    --bs-btn-hover-color: var(--brand-700);
    --bs-btn-font-weight: 600;
    text-decoration: none;
}

.btn-link:hover {
    text-decoration: underline;
}

.btn:focus-visible,
.btn:focus {
    box-shadow: var(--ring);
    outline: none;
}

/* --- Forms --- */
.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink-700);
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border-radius: var(--r-sm);
    border-color: var(--border-strong);
    color: var(--text);
    padding: 0.55rem 0.8rem;
    background-color: var(--surface);
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background-color var(--t-fast);
}

.form-control::placeholder {
    color: var(--text-faint);
}

.form-control:hover:not(:disabled):not(:focus),
.form-select:hover:not(:disabled):not(:focus) {
    border-color: var(--ink-400);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand-500);
    box-shadow: var(--ring);
}

.form-control:disabled,
.form-select:disabled {
    background-color: var(--ink-100);
    color: var(--text-muted);
}

.form-control-sm,
.form-select-sm {
    border-radius: var(--r-xs);
    padding: 0.35rem 0.6rem;
}

.form-text {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.form-check-input {
    border-color: var(--border-strong);
    cursor: pointer;
}

.form-check-input:checked {
    background-color: var(--brand-600);
    border-color: var(--brand-600);
}

.form-check-input:focus {
    border-color: var(--brand-500);
    box-shadow: var(--ring);
}

.form-check-label {
    cursor: pointer;
}

.form-switch .form-check-input {
    width: 2.25rem;
    height: 1.25rem;
}

/* Blazor template default focus ring, remapped to the brand ring. */
.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: var(--ring);
}

.form-floating > label {
    color: var(--text-muted);
    padding-left: 0.85rem;
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--text-faint);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

.input-group > .form-control:focus,
.input-group > .form-select:focus {
    z-index: 4;
}

.darker-border-checkbox.form-check-input {
    border-color: var(--border-strong);
}

/* Validation */
.valid.modified:not([type=checkbox]) {
    border-color: var(--success);
    outline: none;
}

.invalid {
    border-color: var(--danger) !important;
    outline: none;
}

.validation-message,
.text-danger {
    color: var(--danger) !important;
    font-size: 0.85rem;
}

.validation-message {
    display: block;
    margin-top: 0.3rem;
}

/* --- Cards --- */
.card {
    --bs-card-border-color: var(--border);
    --bs-card-border-radius: var(--r-lg);
    --bs-card-inner-border-radius: calc(var(--r-lg) - 1px);
    --bs-card-bg: var(--surface);
    --bs-card-spacer-x: 1.35rem;
    --bs-card-spacer-y: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card-header,
.card-footer {
    background: var(--surface-muted);
    border-color: var(--border);
    font-weight: 650;
    color: var(--heading);
}

.card-title {
    color: var(--heading);
    font-weight: 700;
}

/* --- Tables --- */
.table {
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-hover-bg: var(--ink-50);
    margin-bottom: 0;
}

.table > thead {
    border-bottom: 1px solid var(--border);
}

.table > thead th {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--surface-muted);
    border-bottom-color: var(--border);
    padding: 0.75rem 0.9rem;
    white-space: nowrap;
}

.table > tbody td {
    padding: 0.85rem 0.9rem;
    border-color: var(--border);
    vertical-align: middle;
}

.table > tbody tr:last-child td {
    border-bottom: 0;
}

/* A table wrapped in a .surface keeps the rounded corners. */
.surface > .table-responsive {
    border-radius: inherit;
}

.surface > .table-responsive > .table > thead tr:first-child th:first-child {
    border-top-left-radius: inherit;
}

.surface > .table-responsive > .table > thead tr:first-child th:last-child {
    border-top-right-radius: inherit;
}

/* --- Badges --- */
.badge {
    --bs-badge-border-radius: var(--r-pill);
    --bs-badge-padding-x: 0.65rem;
    --bs-badge-padding-y: 0.35rem;
    --bs-badge-font-weight: 650;
    font-size: 0.75rem;
    letter-spacing: 0.01em;
}

.text-bg-primary { background-color: var(--brand-600) !important; color: #fff !important; }
.text-bg-success { background-color: var(--success) !important; color: #fff !important; }
.text-bg-danger { background-color: var(--danger) !important; color: #fff !important; }

/* --- Alerts --- */
.alert {
    --bs-alert-border-radius: var(--r-md);
    border-width: 1px;
    padding: 0.85rem 1.1rem;
    box-shadow: var(--shadow-xs);
}

.alert-success {
    --bs-alert-bg: var(--success-soft);
    --bs-alert-border-color: #a7f3d0;
    --bs-alert-color: #065f46;
}

.alert-danger {
    --bs-alert-bg: var(--danger-soft);
    --bs-alert-border-color: #fecaca;
    --bs-alert-color: #991b1b;
}

.alert-warning {
    --bs-alert-bg: var(--warning-soft);
    --bs-alert-border-color: #fde68a;
    --bs-alert-color: #92400e;
}

.alert-info {
    --bs-alert-bg: var(--info-soft);
    --bs-alert-border-color: #bae6fd;
    --bs-alert-color: #075985;
}

.alert-secondary {
    --bs-alert-bg: var(--ink-100);
    --bs-alert-border-color: var(--border);
    --bs-alert-color: var(--ink-700);
}

/* --- List group --- */
.list-group {
    --bs-list-group-border-color: var(--border);
    --bs-list-group-border-radius: var(--r-lg);
    --bs-list-group-action-hover-bg: var(--ink-50);
    --bs-list-group-bg: var(--surface);
}

.list-group-item {
    padding: 0.95rem 1.15rem;
}

.list-group-item-action {
    transition: background-color var(--t-fast);
}

/* --- Nav pills (account settings menu) --- */
.nav-pills {
    --bs-nav-pills-border-radius: var(--r-sm);
    --bs-nav-link-color: var(--ink-700);
    --bs-nav-pills-link-active-bg: var(--brand-600);
    --bs-nav-link-font-weight: 600;
}

.nav-pills .nav-link {
    padding: 0.55rem 0.9rem;
    transition: background-color var(--t-fast), color var(--t-fast);
}

.nav-pills .nav-link:not(.active):hover {
    background: var(--accent-soft);
    color: var(--brand-700);
}

/* --- Dropdowns --- */
.dropdown-menu {
    --bs-dropdown-border-color: var(--border);
    --bs-dropdown-border-radius: var(--r-md);
    --bs-dropdown-link-hover-bg: var(--accent-soft);
    --bs-dropdown-link-hover-color: var(--brand-700);
    --bs-dropdown-link-active-bg: var(--accent-soft);
    --bs-dropdown-link-active-color: var(--brand-700);
    --bs-dropdown-padding-y: 0.4rem;
    box-shadow: var(--shadow-lg);
}

.dropdown-item {
    padding: 0.55rem 1rem;
    font-weight: 500;
    border-radius: var(--r-xs);
    width: calc(100% - 0.7rem);
    margin: 0 0.35rem;
}

.dropdown-divider {
    border-color: var(--border);
    margin: 0.4rem 0.35rem;
}

/* --- Modals --- */
.modal-content {
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
}

.modal-header,
.modal-footer {
    border-color: var(--border);
    padding: 1.1rem 1.35rem;
}

.modal-body {
    padding: 1.35rem;
}

.modal-title {
    font-weight: 700;
}

.modal-backdrop {
    --bs-backdrop-bg: var(--ink-900);
    --bs-backdrop-opacity: 0.45;
}

/* --- Misc --- */
.spinner-border {
    --bs-spinner-border-width: 0.18em;
}

.progress {
    --bs-progress-bg: var(--ink-100);
    --bs-progress-border-radius: var(--r-pill);
    --bs-progress-bar-bg: var(--brand-600);
}

pre {
    background: var(--ink-50);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--ink-700);
    padding: 1rem;
}

.content {
    padding-top: 1.1rem;
}

/* ------------------------------------------------------------------ *
 * 5. App-specific shared pieces
 * ------------------------------------------------------------------ */

/* ---------------------------------------------------------------- *
 * Simple auth-flow pages (forgot password, confirm email, lockout).
 * A narrow centred card so these read as part of the sign-in flow
 * rather than as bare scaffolding.
 * ---------------------------------------------------------------- */
.auth-simple {
    max-width: 27rem;
    margin: 1rem auto 3rem;
    padding: 2rem 1.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-md);
}

.auth-simple-wide {
    max-width: 34rem;
}

.auth-simple-mark {
    width: 3rem;
    height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.1rem;
    border-radius: var(--r-md);
    background: var(--accent-soft);
    color: var(--brand-600);
    font-size: 1.35rem;
}

.auth-simple-mark.is-success { background: var(--success-soft); color: var(--success); }
.auth-simple-mark.is-danger { background: var(--danger-soft); color: var(--danger); }
.auth-simple-mark.is-warning { background: var(--warning-soft); color: var(--warning); }

.auth-simple h1 {
    font-size: 1.4rem;
    margin: 0 0 0.4rem;
}

.auth-simple-sub {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.auth-simple-sub:last-child {
    margin-bottom: 0;
}

.auth-simple-foot {
    margin: 1.35rem 0 0;
    padding-top: 1.1rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auth-simple-foot:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

/* ---------------------------------------------------------------- *
 * Account settings shell.
 * Global rather than scoped: these rules must cascade into the
 * settings pages rendered through ManageLayout's @Body.
 * ---------------------------------------------------------------- */
.manage-shell {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    align-items: start;
}

.manage-side {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 0.6rem;
    box-shadow: var(--shadow-sm);
}

.manage-nav {
    display: grid;
    gap: 0.15rem;
}

.manage-nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--r-sm);
    color: var(--ink-700);
    font-size: 0.92rem;
    font-weight: 600;
    text-decoration: none;
    transition: background-color var(--t-fast), color var(--t-fast);
}

.manage-nav-link .bi {
    font-size: 1rem;
    color: var(--text-faint);
    transition: color var(--t-fast);
}

.manage-nav-link:hover {
    background: var(--accent-soft);
    color: var(--brand-700);
    text-decoration: none;
}

.manage-nav-link:hover .bi {
    color: var(--brand-500);
}

.manage-nav-link.active {
    background: var(--brand-600);
    color: #fff;
}

.manage-nav-link.active .bi {
    color: rgba(255, 255, 255, 0.85);
}

.manage-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 1.5rem 1.6rem;
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

/* The scaffolded settings pages open with an <h3>; give it a
   consistent panel-title treatment without editing each page. */
.manage-panel > h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0 0 1.25rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.manage-panel > h4,
.manage-panel h4.h5 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--heading);
}

@media (min-width: 992px) {
    .manage-shell {
        grid-template-columns: 16.5rem minmax(0, 1fr);
    }
}

/* Form-heavy pages read better on a narrower measure. */
.editor-shell {
    max-width: 52rem;
}

/* Filter chips (quiz category filter). */
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border-radius: var(--r-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-700);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    transition: all var(--t-fast);
}

.chip:hover {
    border-color: var(--brand-300);
    background: var(--accent-soft);
    color: var(--brand-700);
    text-decoration: none;
}

.chip.is-active {
    background: var(--brand-600);
    border-color: var(--brand-600);
    color: #fff;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

.chip.is-active:hover {
    background: var(--brand-700);
    border-color: var(--brand-700);
    color: #fff;
}

/* Score pill used on result lists. */
.score-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 0.3rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--r-pill);
    font-weight: 700;
    font-size: 0.85rem;
    background: var(--accent-soft);
    color: var(--brand-700);
    white-space: nowrap;
}

.score-pill.is-strong { background: var(--success-soft); color: var(--success); }
.score-pill.is-mid { background: var(--warning-soft); color: var(--warning); }
.score-pill.is-weak { background: var(--danger-soft); color: var(--danger); }

/* Blazor error boundary. */
.blazor-error-boundary {
    background: var(--danger);
    border-radius: var(--r-md);
    padding: 1rem 1rem 1rem 3.2rem;
    color: white;
    position: relative;
}

.blazor-error-boundary::before {
    content: "\F33A";
    font-family: "bootstrap-icons";
    position: absolute;
    left: 1.1rem;
    top: 0.95rem;
    font-size: 1.25rem;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

[data-busy-submit] button[type="submit"]:disabled {
    pointer-events: none;
    opacity: 0.85;
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- Quiz list pager ---- */
.quiz-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.75rem;
    flex-wrap: wrap;
}

.quiz-pager-step {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.95rem;
    border: 1px solid var(--line, #dfe3ec);
    border-radius: 0.6rem;
    background: #fff;
    color: inherit;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
}

.quiz-pager-step:hover {
    border-color: var(--brand-600, #1f6fe0);
    color: var(--brand-600, #1f6fe0);
}

.quiz-pager-step.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

.quiz-pager-status {
    font-size: 0.85rem;
    color: var(--text-faint, #7b869c);
}


/* ------------------------------------------------------------------ *
 * 6. Quiz authoring  (shared by the standard editor and the admin
 *    rich-text editor, so these live here rather than in scoped CSS)
 * ------------------------------------------------------------------ */
.qe-summary {
    display: block;
    margin-bottom: 1rem;
}

/* ------------------------------------------------------------------ *
 * Cards
 * ------------------------------------------------------------------ */
.qe-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.25rem;
    overflow: hidden;
}

.qe-card-head {
    padding: 1.1rem 1.35rem;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}

.qe-card-head-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.qe-card-head h2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.02rem;
    font-weight: 700;
    margin: 0;
}

.qe-card-head h2 .bi {
    color: var(--brand-600);
}

.qe-card-head p {
    margin: 0.2rem 0 0;
    color: var(--text-muted);
    font-size: 0.86rem;
}

.qe-card-body {
    padding: 1.35rem;
}

.qe-optional {
    font-weight: 500;
    color: var(--text-faint);
    font-size: 0.8rem;
}

/* ------------------------------------------------------------------ *
 * Publish toggle
 * ------------------------------------------------------------------ */
.qe-publish {
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
}

.qe-publish .form-check {
    padding-top: 0.15rem;
    min-height: auto;
}

.qe-publish-label {
    display: block;
    font-weight: 700;
    color: var(--heading);
    cursor: pointer;
}

.qe-publish-help {
    margin: 0.15rem 0 0;
    color: var(--text-muted);
    font-size: 0.86rem;
    max-width: 60ch;
}

.qe-publish-error {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0.5rem 0 0;
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ------------------------------------------------------------------ *
 * Question list
 * ------------------------------------------------------------------ */
.qe-questions {
    display: grid;
    gap: 0.85rem;
}

.qe-question {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    padding: 1.1rem 1.15rem;
    transition: border-color var(--t-fast), box-shadow var(--t-base);
}

.qe-question:hover {
    border-color: var(--brand-200);
    box-shadow: var(--shadow-sm);
}

.qe-question-head {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.75rem;
}

.qe-question-num {
    width: 1.75rem;
    height: 1.75rem;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-xs);
    background: var(--accent-soft);
    color: var(--brand-700);
    font-size: 0.78rem;
    font-weight: 700;
}

.qe-question-label {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.qe-question-tools {
    display: flex;
    gap: 0.35rem;
    flex: none;
}

.qe-question-text {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--heading);
    line-height: 1.5;
}

.qe-question-text.is-empty {
    color: var(--text-faint);
    font-style: italic;
    font-weight: 400;
}

/* Read-only option preview (Edit page). */
.qe-preview-options {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.35rem;
}

.qe-preview-options li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.7rem;
    border-radius: var(--r-sm);
    background: var(--ink-50);
    border: 1px solid transparent;
    font-size: 0.9rem;
}

.qe-preview-options li.is-correct {
    background: var(--success-soft);
    border-color: #a7f3d0;
}

.qe-preview-letter {
    width: 1.5rem;
    height: 1.5rem;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-xs);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink-600);
    font-size: 0.72rem;
    font-weight: 700;
}

.qe-preview-options li.is-correct .qe-preview-letter {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.qe-preview-text {
    flex: 1;
    min-width: 0;
    color: var(--ink-700);
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ *
 * Footer actions
 * ------------------------------------------------------------------ */
.qe-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    position: sticky;
    bottom: 0;
    padding: 1rem 0 0.25rem;
    background: linear-gradient(180deg, rgba(245, 246, 251, 0) 0%, var(--bg) 35%);
}

.quiz-option-hint {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.7rem;
    color: var(--text-muted);
    font-size: 0.83rem;
}

.quiz-option-hint .bi {
    color: var(--brand-500);
}

.quiz-option-row {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.quiz-option-mark {
    width: 2.5rem;
    flex: none;
    border: 1.5px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink-600);
    font-weight: 700;
    border-radius: var(--r-sm);
    transition: all var(--t-fast);
}

.quiz-option-mark:hover {
    border-color: var(--brand-400);
    background: var(--accent-soft);
    color: var(--brand-700);
}

.quiz-option-mark:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.quiz-option-row.is-correct .quiz-option-mark {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.quiz-option-row.is-correct .form-control {
    border-color: #a7f3d0;
    background: var(--success-soft);
}

/* ------------------------------------------------------------------ *
 * 7. Rich text
 *    .rich-content wraps sanitised markup written in the admin editor.
 *    Its children come from a MarkupString, so they carry no scoped-CSS
 *    attribute and can only be styled from here.
 * ------------------------------------------------------------------ */
.rich-content {
    overflow-wrap: anywhere;
}

.rich-content > :first-child {
    margin-top: 0;
}

.rich-content > :last-child {
    margin-bottom: 0;
}

.rich-content p {
    margin: 0 0 0.6rem;
}

.rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--r-sm);
}

.rich-content table {
    border-collapse: collapse;
    margin: 0.5rem 0;
    max-width: 100%;
}

.rich-content th,
.rich-content td {
    border: 1px solid var(--border);
    padding: 0.35rem 0.6rem;
    text-align: left;
}

.rich-content th {
    background: var(--surface-muted);
}

.rich-content pre {
    background: var(--ink-50);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 0.7rem 0.9rem;
    overflow-x: auto;
    font-size: 0.86rem;
}

.rich-content code {
    font-size: 0.9em;
}

.rich-content blockquote {
    margin: 0.5rem 0;
    padding-left: 0.9rem;
    border-left: 3px solid var(--border-strong);
    color: var(--text-muted);
}

.rich-content ul,
.rich-content ol {
    margin: 0 0 0.6rem;
    padding-left: 1.4rem;
}

/* sub/sup are how powers and indices are written, so they must not stretch the line. */
.rich-content sub,
.rich-content sup {
    line-height: 0;
    font-size: 0.75em;
}

.rich-content-inline {
    display: inline-block;
}

.rich-content-inline p {
    margin: 0;
}

.rich-content-empty {
    color: var(--text-faint);
    font-style: italic;
}

/* ------------------------------------------------------------------ *
 * 8. Rich text editor shell
 *    TinyMCE builds its own DOM outside Blazor, so these are global too.
 * ------------------------------------------------------------------ */
.rte {
    position: relative;
}

.rte .tox-tinymce {
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
}

.rte .tox .tox-editor-header {
    box-shadow: none;
    border-bottom: 1px solid var(--border);
}

/* The editor sits inside the question modal, which Bootstrap puts at z-index 1055;
   TinyMCE's own dialogs and menus render into a separate container that has to clear it. */
.tox-tinymce-aux,
.tox .tox-silver-sink {
    z-index: 1200 !important;
}

.rte-loading,
.rte-failed {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.2rem;
    color: var(--text-muted);
    font-size: 0.86rem;
}

.rte-failed {
    color: var(--danger);
}

.rte-source {
    /* Hidden until TinyMCE claims it; a bare textarea flashing first looks broken. */
    visibility: hidden;
    height: 0;
    border: 0;
    padding: 0;
    width: 100%;
}

.rte-fallback {
    visibility: visible;
    height: auto;
    font-size: 0.85rem;
}

/* ------------------------------------------------------------------ *
 * 9. Admin rich-text quiz editor
 * ------------------------------------------------------------------ */
.rq-shell {
    max-width: 64rem;
}

.rq-empty {
    text-align: center;
    padding: 2rem 1rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-md);
    background: var(--surface-muted);
}

.rq-empty .bi {
    font-size: 1.8rem;
    color: var(--brand-500);
}

.rq-hint {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    padding: 0.6rem 0.8rem;
    margin-bottom: 1.1rem;
    border-radius: var(--r-sm);
    background: var(--accent-soft);
    color: var(--ink-700);
    font-size: 0.85rem;
}

.rq-hint .bi {
    color: var(--brand-600);
}

.rq-hint-sm {
    margin: 0 0 0.6rem;
    color: var(--text-muted);
    font-size: 0.83rem;
}

.rq-option {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.7rem;
}

.rq-option .quiz-option-mark {
    height: 2.5rem;
}

.rq-option-editor {
    flex: 1;
    min-width: 0;
}

.rq-option.is-correct .rq-option-editor .tox-tinymce {
    border-color: #a7f3d0;
    box-shadow: 0 0 0 1px #a7f3d0;
}

/* The modal holds five editors; on a laptop it needs the height. */
.rq-modal .modal-dialog {
    max-width: min(64rem, calc(100vw - 2rem));
}

.rq-modal .modal-body {
    max-height: calc(100vh - 12rem);
}

.qe-question-text.rich-content {
    font-weight: 600;
}

/* ------------------------------------------------------------------ *
 * 10. Formulas (KaTeX)
 *     A formula is stored as <span class="math-tex" data-latex="...">
 *     holding its own source, and typeset in the browser by
 *     js/math-render.js. Everything here has to work both before and
 *     after that happens.
 * ------------------------------------------------------------------ */
.math-tex[data-display="block"] {
    display: block;
    margin: 0.7rem 0;
    text-align: center;
}

/* Long formulas scroll rather than stretching the question out of the card. */
.math-tex .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.2rem 0;
}

/* Until KaTeX arrives - or if it never does - the LaTeX source is what shows. */
.math-tex:not([data-rendered]) {
    font-family: var(--font-mono, ui-monospace, "SFMono-Regular", Menlo, monospace);
    font-size: 0.92em;
    background: var(--ink-50);
    border-radius: var(--r-xs, 4px);
    padding: 0 0.25rem;
}

.math-tex[data-rendered="error"] {
    color: var(--danger);
}

/* Formula dialog inside the editor. */
.rte-math-preview {
    min-height: 3.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem;
    border: 1px solid var(--border, #ccd3e0);
    border-radius: var(--r-sm, 6px);
    background: var(--surface, #fff);
    overflow-x: auto;
    font-size: 1.05rem;
}

.rte-math-hint {
    color: var(--text-faint, #7b869c);
    font-size: 0.85rem;
    font-style: italic;
}

.rte-math-help {
    margin-top: 0.6rem;
    font-size: 0.84rem;
}

.rte-math-help summary {
    cursor: pointer;
    color: var(--brand-600, #4f46e5);
    font-weight: 600;
}

.rte-math-help table {
    margin-top: 0.4rem;
    border-collapse: collapse;
    width: 100%;
}

.rte-math-help th {
    text-align: left;
    font-weight: 600;
    padding: 0.2rem 0.6rem 0.2rem 0;
    white-space: nowrap;
    vertical-align: top;
}

.rte-math-help td {
    padding: 0.2rem 0;
}

.rte-math-help code {
    font-size: 0.86em;
}

/* A search that misses every quiz title can still match questions further down. */
.quiz-none-note {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-muted);
}

.quiz-none-note .bi {
    color: var(--text-faint);
}
