:root {
    --bg-page: #f5f7fa;
    --bg-panel: #ffffff;
    --bg-soft: #fafbfc;
    --bg-hover: #eef2f7;
    --text-primary: #000F1E;
    --text-secondary: #4a5568;
    --text-muted: #8a94a6;
    --border: #e3e8ee;
    --border-soft: #eef2f7;
    --shadow-sm: 0 1px 3px rgba(0, 15, 30, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 15, 30, 0.06);
    --shadow-lg: 0 12px 32px rgba(0, 15, 30, 0.10);
    --color-low: #22c55e;
    --color-medium: #f59e0b;
    --color-high: #ef4444;
    --color-critical: #8b0000;
    --color-error: #ef4444;
    --color-error-bg: #fef2f2;
}

/* ---- Appearance & accessibility modes (Advanced Settings) ----
   Each toggle adds a class to <body>; the page is built on :root CSS
   vars, so a mode just re-points those vars. Modes compose (e.g. dark
   + high-contrast both apply). The generated reports are unaffected -
   these styles live on the upload/settings page only. See D64. */

/* Dark mode: gold-on-black, matching the BlackOut tool. Panels stay a
   warm light tone so dense report tables and forms remain readable. */
body.theme-gold {
    --bg-page: #0a0a0c;
    --bg-panel: #f7f1dc;
    --bg-soft: #efe6c9;
    --bg-hover: #e7dcb8;
    --text-primary: #15140d;
    --text-secondary: #4c4733;
    --text-muted: #6f6a52;
    --accent: #8a6d12;
    --accent-soft: #e7d9a4;
    --accent-text-on: #0a0a0c;
    --accent-dark: #8a6d12;
    --border: #d8c98c;
    --color-error: #9b1c1c;
    --color-error-bg: #f6e6cf;
}
/* On the near-black page background, the brand/hero text goes light-gold. */
body.theme-gold .brand-wordmark { color: #f4e7b6; }
body.theme-gold .brand-tagline { color: #c5b063; }
body.theme-gold .hero h1 { color: #f4e7b6; }
body.theme-gold .hero p { color: #d9c98e; }
body.theme-gold .brand-monogram { background: #000; color: #d4af37; }

/* High-contrast / colour-blind: raise contrast to WCAG AA, never rely
   on colour alone (underline links, outline badges), always show focus. */
body.high-contrast {
    --text-secondary: #1b222c;
    --text-muted: #2a313c;
    --border: #4a5462;
    --accent: #00386e;
    --color-error: #a3091b;
}
body.high-contrast .brand-tagline,
body.high-contrast .drop-hint,
body.high-contrast .ai-note { color: var(--text-secondary); }
body.high-contrast a,
body.high-contrast .link { text-decoration: underline; }
body.high-contrast .badge,
body.high-contrast .risk-badge { border: 1px solid currentColor; font-weight: 700; }
/* !important so the always-visible focus ring wins over the per-input
   `outline: none` rules (which substitute a low-contrast box-shadow) -
   in high-contrast mode the strong ring must show on every control. */
body.high-contrast :focus-visible { outline: 3px solid var(--accent) !important; outline-offset: 2px; }

/* Screen-reader friendly: announce() (JS) flips the live region to
   assertive; here we reveal the otherwise-hidden .sr-help labels. */
body.sr-mode .sr-help {
    position: static; width: auto; height: auto; margin: 8px 0 0; clip: auto;
    white-space: normal; font-size: 12.5px; color: var(--text-secondary);
    padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--bg-soft);
}

/* Visually-hidden text exposed to assistive tech (skip-link target,
   the aria-live status region, and sr-mode help labels). */
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 100;
    background: var(--accent); color: var(--accent-text-on);
    padding: 10px 16px; border-radius: 0 0 8px 0; font-weight: 600;
    text-decoration: none;
}
.skip-link:focus { left: 0; }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Libre Franklin', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 48px 16px;
    line-height: 1.5;
}

.brand-bar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 18px;
    margin-bottom: 28px;
}

.brand-bar .brand-avatar {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    object-fit: cover;
    background: #000F1E;
    border: 1.5px solid #d4af37;
    flex-shrink: 0;
}

.brand-bar .brand-monogram {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    border: 1.5px solid #d4af37;
    background: #000F1E;
    color: #e5b900;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Libre Franklin', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    font-weight: 800;
    font-size: 18px;
    line-height: 1;
    letter-spacing: -0.01em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.brand-bar .brand-text {
    text-align: left;
}

.brand-bar .brand-wordmark {
    font-weight: 800;
    font-size: 17px;
    letter-spacing: -0.01em;
    text-transform: uppercase;
    color: var(--text-primary);
    line-height: 1.05;
}

.brand-bar .brand-tagline {
    font-family: 'Source Code Pro', 'SF Mono', Monaco, Consolas, monospace;
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 4px;
}

.hero-image {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    border-radius: 16px;
    margin-bottom: 28px;
    box-shadow: var(--shadow-sm);
}

.page { max-width: 640px; margin: 0 auto; }

.hero {
    text-align: center;
    margin-bottom: 32px;
}

.hero h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.hero p {
    color: var(--text-secondary);
    margin-top: 8px;
    font-size: 14px;
}

.card {
    background: var(--bg-panel);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    padding: 32px;
    margin-bottom: 24px;
}

/* ---- Drop zone ---- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 14px;
    padding: 48px 24px;
    text-align: center;
    background: var(--bg-soft);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.drop-zone .upload-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--accent-soft);
    color: var(--accent);
    margin-bottom: 16px;
}

.drop-zone .drop-text {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

.drop-zone .drop-text .link {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.drop-zone .drop-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ---- File list with progress bars ---- */
.file-list {
    margin-top: 20px;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 8px;
    background: var(--bg-panel);
}

.file-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}
/* Per-filetype colour coding so a glance separates a PDF from a
   spreadsheet from JSON. Untyped files keep the accent default above. */
.file-icon[data-filetype="pdf"]   { background: #fdecea; color: #e2574c; }
.file-icon[data-filetype="word"]  { background: #e8f1fb; color: #2b6cb0; }
.file-icon[data-filetype="excel"] { background: #e7f4ec; color: #1d8a4c; }
.file-icon[data-filetype="csv"]   { background: #e6f4f1; color: #0d9488; }
.file-icon[data-filetype="json"]  { background: #f1ecfb; color: #7c3aed; }
.file-icon[data-filetype="ppt"]   { background: #fdeee0; color: #e07b39; }
.file-icon[data-filetype="txt"]   { background: #eef0f3; color: #5b6472; }
.file-icon[data-filetype="image"] { background: #fdeaf3; color: #d6398e; }

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.file-progress {
    margin-top: 6px;
    height: 4px;
    background: var(--bg-hover);
    border-radius: 2px;
    overflow: hidden;
}

.file-progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.2s;
}

.file-row.error .file-progress-bar { background: var(--color-error); }
.file-row.error .file-meta { color: var(--color-error); }

.file-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 6px;
}

.file-remove:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ---- Historic-mode file row extras: drag handle, date badge,
       manual position input, drag-state styling ---- */
.file-row.historic-mode {
    cursor: default;
}

.file-row.dragging {
    opacity: 0.5;
}

.file-row.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.file-drag-handle {
    flex-shrink: 0;
    width: 20px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: grab;
    border-radius: 4px;
}

.file-drag-handle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.file-row.dragging .file-drag-handle { cursor: grabbing; }

.file-date-badge {
    display: inline-block;
    margin-top: 4px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--accent-soft);
    padding: 2px 8px;
    border-radius: 999px;
}

.file-date-badge.pending {
    color: var(--text-muted);
    background: var(--bg-hover);
    font-style: italic;
}

.file-position {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-right: 4px;
}

.file-position label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.file-position-input {
    width: 48px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    text-align: center;
    color: var(--text-primary);
    background: var(--bg-soft);
}

.file-position-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* Role pill that labels each historic-mode row as either the
   Current event or one of the Historic lists. The current pill
   uses the brand accent to draw the eye; historic pills use a
   muted neutral so the current row reads as the "primary one." */
.file-role-pill {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-right: 4px;
}

.file-role-pill.current {
    background: var(--accent);
    color: var(--accent-text-on);
}

.file-role-pill.historic {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

/* The current row sits slightly elevated so it reads as the
   primary subject of the validation; historic rows are quieter. */
.file-row.is-current {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-soft);
}

.file-row.is-historic {
    background: var(--bg-soft);
}

/* Gap between the current row (position 1) and the first historic
   row (position 2). Using margin-top on the first historic row
   keeps the spacing tight when there's no historic group yet. */
.file-row.first-historic {
    margin-top: 18px;
    position: relative;
}

/* A faint label-divider above the first historic row makes the
   grouping explicit without taking real vertical space. */
.file-row.first-historic::before {
    content: 'HISTORIC ATTENDANCE';
    position: absolute;
    top: -12px;
    left: 4px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    background: var(--bg-panel);
    padding: 0 6px;
}

/* ---- Dedupe-by-email toggle ---- */
.dedupe-row {
    margin-top: 16px;
    padding: 12px 14px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dedupe-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.dedupe-toggle input[type=checkbox] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

/* ---- Per-upload host prompt ---- */
.host-prompt-row {
    margin-top: 16px;
    padding: 12px 14px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.host-prompt-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}
.host-prompt-row input[type=text] {
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-panel);
    color: var(--text-primary);
    box-sizing: border-box;
}
.host-prompt-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- Action buttons ---- */
.actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

button, .button-link {
    padding: 10px 18px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text-primary);
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

button:hover, .button-link:hover {
    border-color: var(--accent);
    color: var(--accent);
}

button.primary, .button-link.primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

button.primary:hover, .button-link.primary:hover {
    background: var(--accent-dark);
    color: white;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---- Results panel ---- */
.results {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-soft);
}

.results h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

/* ---- Encryption status banner shown above the summary grid after
       validation runs. The variant class (.ok / .info) is applied by
       JS based on the encryption_status returned by the server.
       .ok = report is actually encrypted; .info = encryption is off.
       (A failed encryption is refused by the server, not bannered.) */
.encryption-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 16px;
}

.encryption-status .es-icon {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.encryption-status.ok {
    background: rgba(34, 197, 94, 0.08);
    color: #166534;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.encryption-status.info {
    background: var(--bg-soft);
    color: var(--text-secondary);
    border: 1px solid var(--border-soft);
}

.encryption-status .es-hint {
    color: inherit;
    opacity: 0.85;
    font-size: 12px;
}

.summary-tile {
    text-align: center;
    padding: 14px 8px;
    border-radius: 10px;
    background: var(--bg-soft);
    border: 1px solid var(--border-soft);
}

.summary-tile .num {
    font-size: 22px;
    font-weight: 700;
    color: #000;
}

.summary-tile .label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    font-weight: 600;
    margin-top: 2px;
}

.summary-tile.low .num { color: var(--color-low); }
.summary-tile.medium .num { color: var(--color-medium); }
.summary-tile.high .num { color: var(--color-high); }
.summary-tile.critical .num { color: var(--color-critical); }

.result-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---- Status messages ---- */
.status-message {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    margin-top: 12px;
}

.status-message.error {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.status-message.success {
    background: #ecfdf5;
    color: var(--color-low);
}

.status-message.warning {
    background: #fef3c7;
    color: #b45309;
}

/* ---- Watchlist editor (collapsible details) ---- */
details.watchlist-section {
    background: var(--bg-panel);
    border-radius: 16px;
    /* A defined line around the settings button/panel so it reads as a
       button (matching the BlackOut tool), not just a shadowed card. */
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: 0;
    overflow: hidden;
}

details.watchlist-section[open] {
    padding-bottom: 24px;
    /* Allow tooltips on the first row of inputs to escape upward
       when the panel is open - otherwise overflow:hidden clips them */
    overflow: visible;
}

details.watchlist-section summary {
    padding: 20px 32px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

details.watchlist-section summary::-webkit-details-marker { display: none; }

details.watchlist-section summary::after {
    content: '▼';
    color: var(--text-muted);
    font-size: 10px;
    transition: transform 0.2s;
}

details.watchlist-section[open] summary::after {
    transform: rotate(180deg);
}

.watchlist-body { padding: 0 32px; }

.watchlist-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

textarea.watchlist {
    width: 100%;
    min-height: 200px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 12px;
    resize: vertical;
    color: var(--text-primary);
    background: var(--bg-soft);
}

textarea.watchlist:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--bg-panel);
}

.watchlist-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.watchlist-status {
    font-size: 12px;
    color: var(--text-muted);
}

.watchlist-status.saved { color: var(--color-low); }
.watchlist-status.error { color: var(--color-error); }

/* Spinner used in the file-row meta line and the validate button while
   the server is doing its work. Pure CSS - no JS framework needed. */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 6px;
    vertical-align: -2px;
}

.spinner-lg {
    width: 14px;
    height: 14px;
    border-width: 2px;
    margin-right: 8px;
}

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

/* Countdown text that sits beside the file-row spinner during AI
   generation. Tabular numerals so 1:30 → 1:29 → 1:28 doesn't jitter. */
.ai-countdown {
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    margin-left: 4px;
    font-weight: 500;
}

/* ---- Hidden file input (still functional, just visually swapped for the drop zone) ---- */
input[type=file] { display: none; }

/* While validation is in flight, settings/watchlist/appearance buttons
   are locked so the user can't kick off a Save mid-validation (which
   would race against the in-progress run's CONFIG snapshot). The class
   grays the element and blocks clicks - and chaining through child
   selectors covers <button>, <label>, and <a> uniformly. */
.is-busy {
    opacity: 0.55;
    pointer-events: none;
    cursor: not-allowed;
}
.is-busy * { pointer-events: none; }

/* ---- Appearance section: avatar + form-field row inspired by the
       Dribbble settings reference. Soft accent-tinted card on the
       left, fields on the right that flow under the avatar on
       narrow viewports. */
.appearance-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 24px;
    align-items: start;
    padding: 20px;
    background: var(--accent-soft);
    border-radius: 14px;
    margin-bottom: 16px;
}

@media (max-width: 540px) {
    .appearance-card {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
    }
}

.appearance-avatar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 96px;
}

.appearance-avatar-wrap {
    position: relative;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: var(--bg-panel);
    border: 2px solid var(--bg-panel);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.appearance-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.appearance-avatar-placeholder {
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.appearance-photo-btn {
    display: inline-block;
    padding: 6px 14px;
    background: var(--accent);
    color: var(--accent-text-on);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: opacity 0.15s;
}

.appearance-photo-btn:hover { opacity: 0.88; }

.appearance-clear-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    padding: 2px 6px;
    text-decoration: underline;
}

.appearance-clear-link:hover { color: var(--text-primary); }

.appearance-fields-col {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.appearance-field {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.appearance-field .label-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.appearance-field input,
.appearance-field select {
    font: inherit;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text-primary);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.appearance-field input:focus,
.appearance-field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.appearance-hero-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-soft);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    margin-bottom: 24px;
}

@media (max-width: 540px) {
    .appearance-hero-row {
        grid-template-columns: 1fr;
    }
}

.appearance-hero-preview-wrap {
    position: relative;
    min-height: 64px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-hover);
}

.appearance-hero-preview {
    display: block;
    width: 100%;
    max-height: 120px;
    object-fit: cover;
}

.appearance-hero-placeholder {
    padding: 22px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
}

.appearance-hero-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    min-width: 140px;
}

.appearance-hero-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ---- Historic analysis settings (radio + slider pair) ---- */
.ha-settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (min-width: 720px) {
    .ha-settings-grid {
        grid-template-columns: 1.4fr 1fr;
    }
}

.ha-settings-block {
    background: var(--bg-soft);
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ha-settings-block .label-row {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ha-radio {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px 0;
    line-height: 1.45;
}

.ha-radio input[type=radio] {
    margin-top: 2px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.ha-radio-hint {
    color: var(--text-muted);
    font-weight: 400;
}

.ha-slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ha-slider-row input[type=range] {
    flex: 1;
    accent-color: var(--accent);
}

.ha-slider-out {
    min-width: 28px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 14px;
    color: var(--accent);
}

.ha-slider-help {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0;
}

/* AI timeout slider re-uses the historic-analysis layout so the look
   of the two adjacent sliders stays consistent. The .ai-timeout-block
   class lets us tweak only the AI version if we ever need to. */
.ai-timeout-block {
    margin-top: 14px;
}

.ai-timeout-unit {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

/* "Optimized for" dropdown sits above the slider. Compact label +
   select on one row; the detected-OS hint slots underneath. */
.ai-timeout-preset-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.ai-timeout-preset-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

#ai-timeout-preset {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-panel);
}

#ai-timeout-preset:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.ai-detected-os-hint {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.ai-detected-os-hint:empty {
    display: none;
}

/* ---- Advanced Settings panel ---- */
.settings-section { margin-bottom: 24px; }

.settings-section summary .gear {
    margin-right: 8px;
    color: var(--accent);
    transition: transform 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}

.settings-section[open] summary .gear { transform: rotate(45deg); }

.settings-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.settings-row label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.settings-row .label-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.settings-row input[type=number] {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    background: #ffffff;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}

.settings-row input[type=number]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.settings-row input[type=number].invalid {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px #fef2f2;
}

.settings-h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 18px 0 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Live Ollama-detection status pill that sits above the AI toggle.
   Indicator dot is grey while we're probing, then green/red. */
.ollama-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    font-size: 13px;
}

.ollama-status {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.ollama-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    transition: background 0.2s;
}

.ollama-indicator.unknown { background: var(--text-muted); }
.ollama-indicator.available { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.ollama-indicator.unavailable { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15); }

.ollama-text {
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.4;
}

.ollama-text .ollama-model-name {
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    color: var(--accent);
    font-size: 12px;
}

.ollama-text .ollama-url {
    color: var(--text-muted);
    font-size: 12px;
}

.ollama-recheck {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s;
    flex-shrink: 0;
}

.ollama-recheck:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ollama-recheck:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Model picker - shown below the status row when Ollama is reachable
   and has at least one model. Lets the user override the auto-pick. */
.ollama-model-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
}

.ollama-model-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    flex-shrink: 0;
}

.ollama-model-select {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-soft);
    cursor: pointer;
}

.ollama-model-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Toggle rows live below their h4 - one boolean checkbox per row,
   with the label and a (?) info icon */
.settings-toggle-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
}

.settings-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 500;
}

.settings-toggle:hover {
    border-color: var(--accent-soft);
    background: var(--bg-soft);
}

.settings-toggle input[type=checkbox] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

/* Encryption section: small explainer paragraph + password input row */
.encryption-explainer {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.55;
    background: var(--bg-soft);
    border-left: 3px solid var(--accent);
    padding: 10px 14px;
    border-radius: 6px;
    margin: 10px 0 14px;
}

/* Smaller variant used inside .ha-settings-block for per-setting
   explainers (Identity match, First-time attendee weight, etc.). */
.ha-explainer {
    font-size: 11.5px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 6px 0 10px;
    padding: 8px 10px;
    background: var(--bg-soft);
    border-left: 2px solid var(--accent);
    border-radius: 4px;
}

/* Subheading inside the Privacy & Security cluster so Redact PII and
   Password Protection visually read as sibling sub-areas under one h4. */
.settings-subhead {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 18px 0 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.encryption-pwd-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.encryption-pwd-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

/* Password field with an inline show/hide eye button. The wrapper
   grows to fill the row; the button absolute-positions inside it. */
.pwd-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.pwd-input-wrap input[type=password],
.pwd-input-wrap input[type=text] {
    flex: 1;
    min-width: 0;
    padding: 9px 40px 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-soft);
}

.pwd-input-wrap input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.pwd-input-wrap input.invalid {
    border-color: var(--color-error);
    background: var(--color-error-bg);
}

/* Disabled state used when a feature's enable-toggle is off. The
   input + its show/hide eye button both gray out so the operator
   can see at a glance that they need to flip the toggle before
   the field will accept input. */
.pwd-input-wrap input:disabled {
    color: var(--text-muted);
    background: var(--bg-hover);
    cursor: not-allowed;
    opacity: 0.65;
}
.pwd-input-wrap input:disabled::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

/* Generic outline applied by showFieldError() when the server returns
   a validation error tied to a specific field. Works on any element -
   inputs, selects, textareas, radio-group containers, slider rows. */
.settings-invalid,
.settings-invalid input,
.settings-invalid select,
.settings-invalid textarea {
    outline: 2px solid var(--color-error) !important;
    outline-offset: 2px;
}
input.settings-invalid,
select.settings-invalid,
textarea.settings-invalid {
    border-color: var(--color-error);
    background: var(--color-error-bg);
}

.pwd-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
}

.pwd-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.pwd-toggle:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}
.pwd-toggle:disabled:hover {
    color: var(--text-muted);
    background: none;
}

.encryption-pwd-status {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    flex-basis: 100%;
}

.encryption-pwd-status.set {
    color: #22c55e;
}

.encryption-pwd-status.error {
    color: var(--color-error);
}

/* The confirm row is visually a continuation of the password row,
   so trim the top margin to keep them visually grouped. */
.encryption-pwd-confirm-row {
    margin-top: -4px;
}

/* Reusable (?) info icon, same hover-tooltip pattern as the report */
.info-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    color: white;
    font-size: 10px;
    font-weight: 700;
    cursor: help;
    flex-shrink: 0;
    transition: background 0.15s;
    text-transform: none;
    letter-spacing: normal;
}

.info-icon:hover { background: var(--accent); }

.info-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    /* Anchor the tooltip's left edge to the icon's left edge instead
       of centering. Most icons here sit near the left side of their
       labels, so extending rightward keeps the tooltip on-screen on
       narrow viewports where a centered tooltip would clip off the
       left side. */
    left: -8px;
    min-width: 220px;
    /* Cap width so the tooltip can't overflow the viewport on mobile.
       min() picks whichever is smaller: 320px or "viewport minus a
       16px gutter on each side" */
    max-width: min(320px, calc(100vw - 32px));
    padding: 10px 12px;
    background: var(--text-primary);
    color: #ffffff;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(28, 28, 60, 0.10);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    z-index: 100;
    pointer-events: none;
    white-space: normal;
    text-align: left;
}

.info-icon:hover::after { opacity: 1; visibility: visible; }

/* Page footer with the version string - small and muted */
.page-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---- Hosted mode: sign-in page and the signed-in account bar ---- */
.login-card {
    max-width: 380px;
    margin: 0 auto;
}
.login-card h1 {
    font-size: 1.25rem;
    margin: 0 0 16px;
}
.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.login-field input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    color: var(--text-primary);
    background: var(--bg-panel);
}
.login-error {
    color: var(--color-error);
    background: var(--color-error-bg);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
}
.account-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.account-bar form {
    margin: 0;
}

/* Advanced Settings > Organization data (hosted mode, org admins) */
button.danger {
    background: var(--color-error);
    border-color: var(--color-error);
    color: #fff;
}
button.danger:hover {
    filter: brightness(0.92);
}

/* Advanced Settings > Organization users (hosted mode, org admins) */
.org-users-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0 16px;
    font-size: 0.9rem;
}
.org-users-table th,
.org-users-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}
.org-users-table td button {
    margin-right: 6px;
}
.org-users-add {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
