:root {
    --bg: #f5f6f8;
    --card-bg: #ffffff;
    --text: #1b1f27;
    --muted: #6b7280;
    --muted-2: #9aa1ac;
    --border: #e5e7eb;
    --border-soft: #eef0f3;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eef2ff;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --warn-bg: #fef9c3;
    --warn-text: #854d0e;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 2px 8px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Shared inline-SVG icon (see icon() in _bootstrap.php) -- sized to the current font-size so it
   drops into text/buttons/badges at any scale without a separate size class per context. */
.icon {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    vertical-align: -0.15em;
}

.topnav {
    padding: 0.7rem 1.5rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.topnav-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

/* Groups the AI-provider badge and logout icon as one right-aligned unit -- without this wrapper
   they'd sit as siblings of .brand under .topnav-row's space-between and get spread apart instead
   of sitting close together. */
.topnav-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.topnav .brand {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}
.topnav .brand .icon { color: var(--primary); width: 1.15em; height: 1.15em; }

.topnav .links {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.topnav a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    transition: background 0.12s ease, color 0.12s ease;
    white-space: nowrap;
}
.topnav a:hover { color: var(--text); background: var(--bg); }
.topnav a.active { color: var(--primary); background: var(--primary-soft); }

/* Compact queue-state badge on the "Progress" nav link -- icon plus a bare number (no label text,
   the nav has no room for one), so a processing/stalled queue is noticeable from any page. */
.nav-queue-badge {
    display: inline-flex;
    align-items: center;
    line-height: 1;
    gap: 0.15rem;
    padding: 0;
    background: none;
    box-shadow: none;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: none;
}
.nav-queue-badge.badge-partial { color: #92400e; }
.nav-queue-badge.badge-unverified { color: var(--muted-2); }
.nav-queue-badge.badge-not_found { color: var(--error-text); }
.nav-queue-badge .icon { width: 0.75em; height: 0.75em; }

.topnav .ai-model-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}
.topnav .ai-model-badge:hover { color: var(--text); border-color: var(--primary); background: var(--primary-soft); }

/* Reachability dot on the AI model badge -- local/remote Ollama in particular can be off at any
   given moment, so this surfaces that at a glance rather than only on task failure. Checked async
   via assets/ai-status.js after page load so a slow/unreachable server never blocks rendering. */
.ai-status-dot {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    flex-shrink: 0;
}
.ai-status-checking { background: var(--muted-2); animation: ai-status-pulse 1.2s ease-in-out infinite; }
.ai-status-online { background: #22c55e; }
.ai-status-offline { background: var(--error-text); }
@keyframes ai-status-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* Mobile: the nav's two rows (brand+badge, then link list) already stack well at any width, but
   a wrapping link list eats a lot of vertical space on a phone -- scroll it horizontally instead,
   like a tab strip, so the sticky nav stays compact. */
@media (max-width: 640px) {
    .topnav { padding: 0.6rem 1rem; }
    .topnav .brand span { display: none; }
    .topnav .links {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.15rem;
        scrollbar-width: thin;
    }
    .topnav a span { display: none; }
    .topnav a { padding: 0.5rem; }
    .container { padding: 1.1rem 1rem 2.5rem; }
    h1 { font-size: 1.35rem; }
    h2 { font-size: 1.05rem; }
    .card { padding: 1rem; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
}

.container {
    max-width: 1150px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
}

h1 { margin-top: 0; margin-bottom: 0.4rem; font-size: 1.6rem; letter-spacing: -0.01em; display: flex; align-items: center; gap: 0.5rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 0.75rem; letter-spacing: -0.01em; display: flex; align-items: center; gap: 0.45rem; }
h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }
h1 .icon, h2 .icon { color: var(--primary); }

p { color: var(--text); }
p.hint, .hint { color: var(--muted); font-size: 0.85rem; }

a { color: var(--primary); }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    max-width: 520px;
}

.card-wide { max-width: none; }
.card h3:first-child { margin-top: 0; }

.card label {
    display: block;
    margin-top: 0.75rem;
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
}

/* Reference Docs page: Basic Knowledge / Type Training shown side by side on wide screens,
   stacking on narrow ones (each is a full card-like block, not a tight grid). */
.category-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.5rem;
    margin-top: 0.75rem;
}
.category-section h3 { margin-top: 0; }

/* Small circular icon-only button -- shared look for lightweight inline actions (e.g. "edit
   this") that don't need a full labeled button. */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    text-decoration: none;
    flex: none;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.icon-btn .icon { width: 0.85em; height: 0.85em; }
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

.category-line { display: flex; align-items: center; gap: 0.5rem; margin: 0.3rem 0 1rem; }
.category-edit-form { display: inline-flex; align-items: center; gap: 0.4rem; }
.category-edit-form select { padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.82rem; }
.category-edit-form button { margin-top: 0; padding: 0.3rem 0.65rem; font-size: 0.78rem; }

/* Basic Knowledge / Type Training radio choice -- overrides .card label's block stacking so the
   two options sit side by side instead of one per line. */
.category-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin-top: 0.3rem;
}
.category-radio-group label {
    display: inline-flex !important;
    align-items: center;
    gap: 0.35rem;
    margin: 0 !important;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text);
    cursor: pointer;
}

.card input[type="file"],
.card select,
.card input[type="text"],
.card input[type="password"],
.card textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--card-bg);
    color: var(--text);
}
.card input:focus, .card select:focus, .card textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

button, .btn-primary, .btn-secondary {
    margin-top: 1rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--primary);
    background: var(--primary);
    color: white;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
    /* inline-flex (not inline-block + vertical-align on the icon) guarantees a leading <svg
       class="icon"> is truly vertically centered against the button's text, regardless of font
       metrics -- vertical-align alone looked off-center in some buttons. */
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
}

button:hover, .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:active, .btn-primary:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); border-color: var(--muted-2); }

.btn-danger {
    background: var(--card-bg);
    color: var(--error-text);
    border-color: #fecaca;
}
.btn-danger:hover { background: var(--error-bg); border-color: var(--error-text); }

.material-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}
.material-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border-soft);
}
.material-list li:last-child { border-bottom: none; }
.material-info { display: flex; flex-direction: column; gap: 0.1rem; }
.material-list form { margin: 0; }
.material-list .btn-danger { margin-top: 0; padding: 0.35rem 0.75rem; font-size: 0.78rem; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.flash-success { background: var(--success-bg); color: var(--success-text); border-color: #bbf7d0; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: #fecaca; }

.table-scroll { overflow-x: auto; max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }

.data-table {
    border-collapse: collapse;
    width: 100%;
    background: var(--card-bg);
}

.data-table th, .data-table td {
    border-bottom: 1px solid var(--border-soft);
    padding: 0.6rem 0.85rem;
    text-align: left;
    font-size: 0.85rem;
    vertical-align: top;
}
.data-table td { border-right: 1px solid var(--border-soft); }
.data-table th:last-child, .data-table td:last-child { border-right: none; }

.data-table th {
    background: #fafbfc;
    position: sticky;
    top: 0;
    font-weight: 600;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--border);
}

.data-table tbody tr:hover { background: #fafbfc; }

/* A button/link-styled action dropped into a table cell (Reference Docs) shouldn't carry the
   normal margin-top:1rem meant for standalone/card buttons -- it should sit flush like the rest
   of the row's content, and all such actions in a row should look the same compact size. */
.data-table td form { margin: 0; }
.data-table td form button,
.data-table td > a.btn-primary,
.data-table td > a.btn-secondary,
.data-table td > a.btn-danger { margin-top: 0; padding: 0.3rem 0.65rem; font-size: 0.78rem; }

/* Jumping in from a Progress-page "question no." link lands on #question-row-N -- scroll-margin
   keeps the row clear of the sticky thead, and :target briefly highlights it so it's easy to spot
   among hundreds of rows. */
#questions-table tbody tr { scroll-margin-top: 3rem; }
#questions-table tbody tr:target { animation: target-row-highlight 2.5s ease-out; }
@keyframes target-row-highlight {
    from { background: #fff3cd; }
    to { background: transparent; }
}

/* Question revisions (question_set.php): a manually-edited alternate version of a question,
   shown as its own row directly under the original, with a small indent marker instead of
   repeating the group name. */
.revision-row { background: var(--primary-soft); }
.revision-row:hover { background: #e0e7ff; }
.revision-marker { color: var(--primary); font-weight: 600; cursor: help; }

.row-actions { margin-top: 0.3rem; display: flex; justify-content: space-between; }
.row-actions a { font-size: 0.78rem; text-decoration: none; }

.revision-edit-row td { background: var(--bg); padding: 1rem; }
.revision-delete-form { max-width: 520px; margin-top: 0.75rem; }

/* One unified row per choice -- radio to mark it correct, letter, then the text field -- instead
   of a separate choice grid plus a disconnected correct-answer dropdown below it. */
.revision-choices-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.3rem;
}
.revision-choice-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.revision-choice-row input[type="radio"] { flex: none; width: auto; margin: 0; }
.revision-choice-row .revision-choice-letter {
    flex: none;
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    margin: 0;
    cursor: pointer;
}
.revision-choice-row:has(input:checked) .revision-choice-letter { background: var(--success-bg); color: var(--success-text); }
.revision-choice-row input[type="text"] { flex: 1; margin: 0; }

.revision-form-actions { margin-top: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.revision-form-actions button { margin-top: 0; }
.data-table tbody tr:last-child td { border-bottom: none; }

.cell-run-all { text-align: center; }
.cell-run-all .suggest-toggle { display: inline-block; margin-top: 0.3rem; font-size: 0.72rem; text-decoration: none; }

.suggestions-row td { background: var(--bg); padding: 1rem; }
.suggestions-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}
.suggestion-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 0.85rem;
    font-size: 0.85rem;
}
.suggestion-card strong { display: block; margin-bottom: 0.4rem; color: var(--primary); }
.suggestion-card button { margin-top: 0.6rem; }
.suggestion-card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.4rem; }
.suggestion-card-header strong { margin-bottom: 0; }

.suggestions-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.suggestions-header form { margin: 0; }
.suggestions-header button { margin-top: 0; }

.imported-level { display: inline-block; margin-top: 0.25rem; cursor: help; }
.imported-level-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    height: 1.4rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: help;
    margin-top: 0.25rem;
}

.level-badge-clickable { cursor: pointer; }
.level-badge-clickable:hover { filter: brightness(0.95); }
.manual-level-marker { cursor: help; margin-left: 0.25rem; display: inline-flex; vertical-align: -0.15em; }
.manual-level-marker .icon { width: 0.85em; height: 0.85em; }

/* Spinning icon shown inside a badge, left of its label, when a queued/running task is actively
   (re-)checking it -- see pending_badge_icon() in _bootstrap.php. Inherits the badge's own text
   color (currentColor) rather than a fixed color, so it matches whichever badge variant it's in. */
.pending-indicator { display: inline-flex; align-items: center; justify-content: center; cursor: help; vertical-align: middle; }
.pending-indicator .icon { width: 0.85em; height: 0.85em; animation: pending-spin 1.1s linear infinite; }
@keyframes pending-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Streamlined override dropdown -- replaces the raw browser <select> with something that reads
   as part of this app's design instead of native chrome, while staying a real <select> for free
   keyboard/accessibility behavior. */
.manual-level-select {
    margin-left: 0.4rem;
    padding: 0.15rem 1.4rem 0.15rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 0.5rem center / 0.6rem;
    -webkit-appearance: none;
    appearance: none;
    font-size: 0.72rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
}
.manual-level-select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.manual-level-select:disabled { opacity: 0.6; cursor: wait; }

.ref-links { margin-top: 0.3rem; font-size: 0.72rem; }
.ref-links a.ref-link {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.ref-links a.ref-link:hover { text-decoration: underline; }

/* Question-set pipeline cells: display-only badges now -- the &#9654; Validate icon (below) is
   the only way to queue a question's checks, .cell-clickable just tags which <td>s it should
   collect data-stage/data-doc from and mark "queued" afterward. */

.run-all-one {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    background: var(--bg);
    color: var(--primary);
    text-decoration: none;
    font-size: 0.8rem;
    line-height: 1;
    transition: background 0.12s ease, transform 0.1s ease;
}
.run-all-one:hover { background: var(--primary-soft); transform: scale(1.08); }

/* Progress page: small refresh icon next to a "(cached)" result, click to force a fresh re-run */
.force-rerun-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.3rem;
    height: 1.3rem;
    margin-left: 0.3rem;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    line-height: 1;
    vertical-align: -0.2em;
    transition: background 0.12s ease, color 0.12s ease, transform 0.1s ease;
}
.force-rerun-link:hover { background: var(--primary-soft); color: var(--primary); transform: rotate(90deg); }
.force-rerun-link.force-rerun-pending { color: var(--primary); opacity: 0.6; pointer-events: none; animation: force-rerun-spin 0.8s linear infinite; }
@keyframes force-rerun-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Settings page: each AI provider's radio + its own config fields grouped into one card, instead
   of a separate radio list above four detached fields -- so it's unambiguous which fields belong
   to which provider, and which ones actually matter (the selected one is highlighted). Plain
   <div>s, not <fieldset>/<legend> -- legend's content-sizing/overflow behavior is inconsistent
   enough across browsers that long description text inside it kept overflowing the card. */
.ai-provider-form .ai-provider-option {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem;
    transition: border-color 0.12s ease, background 0.12s ease;
    max-width: 100%;
    overflow: hidden;
}
.ai-provider-form .ai-provider-option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.ai-provider-form .ai-provider-option-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    cursor: pointer;
    font-size: 0.95rem;
    max-width: 100%;
}
.ai-provider-form .ai-provider-option label > input[type="text"] {
    margin-top: 0.25rem;
}

/* Tables not wrapped in .table-scroll (e.g. small fixed-width ones) still get the same look */
.data-table:not(.table-scroll .data-table) {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.choices-list {
    margin-top: 0.4rem;
    padding-left: 0.6rem;
    border-left: 2px solid var(--border);
    font-size: 0.8rem;
    color: var(--muted);
}

.choices-list div { padding: 0.15rem 0; }

.spinner {
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 0.35em;
    vertical-align: -0.1em;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.5rem;
}

/* Progress page controls card: status line + action buttons, laid out so buttons wrap cleanly
   instead of the browser's default inline-form spacing (each <form> used to add its own margin). */
.progress-controls .worker-status-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.85rem;
    font-weight: 500;
}
.progress-controls .worker-status-line .icon { color: var(--primary); }
.progress-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.progress-actions form { margin: 0; }
.progress-actions button { margin-top: 0; }
#toggle-btn { display: inline-flex; align-items: center; gap: 0.4rem; }

.stat-tile {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    text-align: center;
    transition: box-shadow 0.12s ease, transform 0.12s ease;
    /* Grid rows equalize tile height to the tallest sibling (e.g. a label that wraps to 2 lines) --
       flex-column here, plus flex:1 on the inner <a> below, lets the link stretch to fill that
       full equalized height instead of just its own (shorter) content height. */
    display: flex;
    flex-direction: column;
}
.stat-tile:has(a):hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-tile strong { display: block; font-size: 1.6rem; letter-spacing: -0.02em; }
.stat-tile span { color: var(--muted); font-size: 0.78rem; }

/* The whole tile is the click target, not just the title text -- negative margin expands the
   link box out to the tile's own padding so hovering/clicking anywhere on the tile (including
   the description line below the title) works, not just the bold text itself. */
.stat-tile a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    margin: -1rem;
    padding: 1rem;
    border-radius: inherit;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.12s ease;
}
.stat-tile a:hover { background: var(--primary-soft); }
.stat-tile a span { display: block; margin-top: 0.2rem; font-weight: 400; }
.stat-tile a .icon { display: block; margin: 0 auto 0.4rem; color: var(--muted-2); width: 1.3em; height: 1.3em; }
.stat-tile a:hover .icon { color: var(--primary); }
.stat-tile a strong { display: block; }
.stat-tile-warn strong { color: var(--error-text); }

/* Dashboard "no data yet" placeholder -- centered icon + message + primary action, instead of a
   single bare line of text easy to miss. */
.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--muted);
    background: var(--card-bg);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}
.empty-state .icon { width: 2.25rem; height: 2.25rem; color: var(--muted-2); margin-bottom: 0.75rem; }
.empty-state p { color: var(--muted); margin: 0 0 1rem; }

.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 0.2rem;
    border-bottom: 1px solid var(--border-soft);
}
.recent-list li:last-child { border-bottom: none; }
.recent-list a { display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; font-weight: 500; }
.recent-list a:hover { text-decoration: underline; }
.recent-list .icon { color: var(--muted-2); }

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.01em;
    text-align: center;
    line-height: 1.4;
}

.badge[data-tooltip] {
    cursor: help;
    border-bottom: 1px dotted currentColor;
}

.badge-supported { background: var(--success-bg); color: var(--success-text); }
.badge-partial { background: var(--warn-bg); color: var(--warn-text); }
.badge-not_found { background: var(--error-bg); color: var(--error-text); }
.badge-error { background: var(--error-bg); color: var(--error-text); }
.badge-unverified { background: #eceef1; color: var(--muted); }
.badge-level-1 { background: #dbeafe; color: #1e40af; }
.badge-level-2 { background: #ede9fe; color: #5b21b6; }
.badge-level-3 { background: #fce7f3; color: #9d174d; }
/* Manually overridden level -- yellow regardless of level number, so an admin correction is
   visually distinct from the AI's own verdict at a glance, not just via the marker icon. */
.badge-level-manual { background: var(--warn-bg); color: var(--warn-text); }

.generate-section-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 0.6rem 0.8rem; margin-bottom: 1rem; }
.generate-section-group { display: flex; flex-direction: column; gap: 0.15rem; }
.generate-section-group label { display: flex; align-items: center; gap: 0.4rem; font-weight: 400; margin: 0; font-size: 0.88rem; }
/* depth 2 = a topic ("7.1: ..."), bolded and slightly spaced from the previous topic's subtopics;
   depth 3 = a subtopic ("7.1.1: ..."), indented under its topic; depth 4/5 = a further-nested
   variant-lettered subtopic ("6.1(a).1: ...", "6.3.1(a).1: ..."), indented one/two steps deeper
   still; depth 1 = no numbering detected (flat fallback list), same styling as a topic since
   there's no hierarchy to show. */
.generate-section-group label.generate-section-depth-2 { font-weight: 600; margin-top: 0.5rem; }
.generate-section-group label.generate-section-depth-3 { margin-left: 0.75rem; }
.generate-section-group label.generate-section-depth-4 { margin-left: 1.5rem; }
.generate-section-group label.generate-section-depth-5 { margin-left: 2.25rem; }
.generate-section-group label.generate-section-depth-1 { font-weight: 500; }
/* One card per level (rather than 3 cramped inline inputs) -- bigger, easier-to-hit number field,
   and the level's own badge color as a top accent so the 3 counts stay visually distinct. */
.generate-level-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.generate-level-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 1.1rem 0.75rem;
    border: 1px solid var(--border);
    border-top: 3px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
}
.generate-level-card-1 { border-top-color: #1e40af; }
.generate-level-card-2 { border-top-color: #5b21b6; }
.generate-level-card-3 { border-top-color: #9d174d; }
.generate-level-card-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.generate-level-card input[type="number"] {
    width: 100%;
    max-width: 6.5rem;
    padding: 0.6rem;
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* Excel Questions tab toolbar: compact buttons that open modals, instead of the two management
   cards permanently taking up vertical space above the actual question table. Shares one card
   with the group filter -- filter on the left, buttons on the right. */
.excel-toolbar-card { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; max-width: none; }
.excel-group-filter { display: flex; align-items: center; gap: 0.6rem; margin: 0; }
.excel-group-filter label { display: inline; margin: 0; font-size: 0.85rem; font-weight: 500; color: var(--muted); white-space: nowrap; }
.excel-group-filter select { width: auto; margin: 0; }
.excel-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; margin-left: auto; }
/* The base button/.btn-secondary rule has margin-top: 1rem for buttons that follow other form
   content -- inside this flex toolbar it just pushes whichever element it hits (button OR an
   <a class="btn-secondary"> like the Print link) down out of line with its siblings. */
.excel-toolbar button, .excel-toolbar a { margin-top: 0; }
.excel-toolbar .tab-count { position: relative; top: -1px; }

.text-preview {
    background: #f6f7f8;
    border: 1px solid var(--border-soft);
    padding: 0.85rem;
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.8rem;
}

.verify-log {
    list-style: none;
    padding: 0;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.85rem;
}

.verify-log li { padding: 0.3rem 0; border-bottom: 1px solid var(--border-soft); }
.verify-log .verdict-supported { color: var(--success-text); }
.verify-log .verdict-not_found { color: var(--error-text); }
.verify-log .verdict-partial { color: var(--warn-text); }
.verify-log .verdict-error { color: var(--error-text); }

/* Tabs -- toggled by JS; server renders the first tab already marked active so the page
   looks correct even before JS runs. */
.tab-nav {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.tab-btn {
    background: none;
    border: none;
    margin: 0;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    transform: none;
    position: relative;
    top: 1px;
}
.tab-btn:hover { color: var(--text); background: none; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn .tab-count {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
}
.tab-btn.active .tab-count { background: var(--primary-soft); color: var(--primary); }
.tab-count-warn { background: var(--error-bg) !important; color: var(--error-text) !important; cursor: help; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Custom tooltip -- replaces native title="" attributes, which are slow to appear, can't wrap
   multi-line content cleanly, and render with a look the browser controls, not this app.
   Single shared element (see assets/tooltip.js), positioned in JS via getBoundingClientRect
   since its placement depends on the hovered element and viewport space. */
.custom-tooltip {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    max-width: 320px;
    background: #1b1f27;
    color: #f3f4f6;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.5;
    white-space: pre-line;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.16), 0 2px 6px rgba(16, 24, 40, 0.1);
    opacity: 0;
    transform: translateY(4px) scale(0.98);
    transition: opacity 0.1s ease, transform 0.1s ease;
    pointer-events: none;
}

.custom-tooltip.visible { opacity: 1; transform: translateY(0) scale(1); }

.custom-tooltip::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 9px;
    height: 9px;
    margin-left: -4.5px;
    background: inherit;
    transform: rotate(45deg);
}

.custom-tooltip.pos-top::after { bottom: -4.5px; }
.custom-tooltip.pos-bottom::after { top: -4.5px; }

.custom-tooltip .tt-label {
    color: #9aa3b2;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
}

/* Type-to-confirm modal for irreversible destructive actions (e.g. deleting a whole question
   set) -- a plain browser confirm() is too easy to click through without reading; requiring the
   word "delete" to be typed forces a moment of actual attention. */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.25), 0 4px 10px rgba(16, 24, 40, 0.12);
    padding: 1.5rem;
    max-width: 420px;
    width: 100%;
    /* .modal-overlay already centers this with 1rem of viewport padding on each side --
       cap height to whatever's left so a modal with a lot of content (e.g. a long group list)
       scrolls internally instead of pushing past the top/bottom of the screen. */
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}
.modal-wide { max-width: 640px; }
.modal h3 { margin-top: 0; color: var(--error-text); }
.modal h3 .icon { color: var(--error-text); }
/* Red heading suits a destructive confirmation (delete, override-save) but not a constructive
   action like generating questions -- this modifier resets both back to normal styling. */
.modal-neutral h3 { color: var(--text); }
.modal-neutral h3 .icon { color: var(--primary); }

.modal-field { margin-bottom: 1.2rem; }
.modal-field:last-of-type { margin-bottom: 1rem; }
.modal-field-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}
.generate-material-name { font-size: 0.82rem; font-weight: 600; color: var(--text); margin: 0.7rem 0 0.3rem; }
.generate-material-name:first-child { margin-top: 0; }
.modal input[type="text"] {
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
}
.modal input[type="text"]:focus {
    outline: none;
    border-color: var(--error-text);
    box-shadow: 0 0 0 3px var(--error-bg);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }
.modal-actions button { margin-top: 0; }

/* Checkbox confirmation on destructive/high-impact modals -- replaces the old "type DELETE to
   confirm" text-input pattern with a single acknowledgement checkbox. */
.modal-confirm-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 0.75rem;
}
.modal-confirm-checkbox input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    cursor: pointer;
}

/* Read-only disclosure of prompt rules hardcoded in the AI client source (see reference_docs.php)
   -- collapsed by default since the rule lists run long and this is reference material, not
   something an admin needs open by default the way the editable sections above it are. */
.hardcoded-rules-details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}
.hardcoded-rules-details summary .icon { vertical-align: -0.15em; margin-right: 0.2rem; }
.hardcoded-rules-details[open] summary { margin-bottom: 0.75rem; }
.hardcoded-rules-details ul { margin: 0.4rem 0 1rem; padding-left: 1.3rem; }
.hardcoded-rules-details li { margin-bottom: 0.45rem; font-size: 0.92rem; color: var(--text); }
.hardcoded-rules-details li:last-child { margin-bottom: 0; }

/* Password gate (login.php) -- a standalone page with no topnav, so it gets its own small
   layout rather than reusing .container/.card verbatim (avoids inheriting nav-page assumptions
   like max-width scoped to a sidebar-less dashboard). Faint graph-paper background nods to the
   technical/engineering-drawing material this tool verifies questions against, without competing
   with the card itself. */
.gate-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background-color: var(--bg);
    background-image:
        linear-gradient(var(--border-soft) 1px, transparent 1px),
        linear-gradient(90deg, var(--border-soft) 1px, transparent 1px);
    background-size: 32px 32px;
}

.gate-card {
    width: 100%;
    max-width: 360px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.1rem 1.85rem 1.85rem;
}

.gate-mark {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.1rem;
}
.gate-mark .icon { width: 1.35rem; height: 1.35rem; }

.gate-title {
    margin: 0 0 1.6rem;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    text-align: center;
    text-wrap: balance;
}

.gate-subtitle {
    margin: 0 0 1.6rem;
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
    line-height: 1.5;
}

.gate-card label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.45rem;
}

.gate-card input[type="password"] {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--bg);
    color: var(--text);
}
.gate-card input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--card-bg);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.gate-card button {
    width: 100%;
    justify-content: center;
    margin-top: 1.15rem;
}

.gate-error {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0 0 1.1rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid #fecaca;
    font-size: 0.82rem;
}
.gate-error .icon { flex: none; }
