/* =========================================================================
   Design tokens
   ========================================================================= */

:root {
  color-scheme: light dark;

  /* Surfaces */
  --bg: #ffffff;
  --bg-subtle: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e5ea;
  --border-strong: #cdd0d8;

  /* Text */
  --fg: #14161a;
  --fg-secondary: #43464e;
  --muted: #6b7078;

  /* Accent (Zeus brand burgundy, from racunovodski-servis-zeus.si) */
  --accent: #813233;
  --accent-hover: #93383b;
  --accent-active: #501f20;
  --accent-fg: #ffffff;
  --accent-subtle: #f9ebec;
  --accent-ring: rgba(129, 50, 51, 0.35);

  /* Semantic */
  --error: #d3352c;
  --error-subtle: #fbeceb;
  --success: #1a8a4a;
  --success-subtle: #e9f8ef;
  --warning: #a3610a;
  --warning-subtle: #fdf3e0;

  /* Scale */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 26, 0.05);
  --shadow-md: 0 4px 12px rgba(20, 22, 26, 0.08), 0 1px 2px rgba(20, 22, 26, 0.06);
  --shadow-lg: 0 12px 32px rgba(20, 22, 26, 0.12), 0 2px 6px rgba(20, 22, 26, 0.06);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

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

  --transition-fast: 120ms ease;
  --transition-base: 180ms cubic-bezier(0.2, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101217;
    --bg-subtle: #16181e;
    --surface: #1a1d24;
    --border: #2a2d36;
    --border-strong: #3c3f4a;

    --fg: #edeef1;
    --fg-secondary: #c2c5cd;
    --muted: #8b8f9a;

    --accent: #d3696a;
    --accent-hover: #da7a7b;
    --accent-active: #bd5d5e;
    --accent-fg: #101217;
    --accent-subtle: #3a2323;
    --accent-ring: rgba(211, 105, 106, 0.4);

    --error: #f47066;
    --error-subtle: #34191a;
    --success: #4fc785;
    --success-subtle: #12291d;
    --warning: #e3a63f;
    --warning-subtle: #332508;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* =========================================================================
   Reset / base
   ========================================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg-subtle);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem 0;
}

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }

p { margin: 0 0 0.75rem 0; }

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
}

blockquote {
  margin: 0 0 0.75rem 0;
  padding: 0.5rem 0.9rem;
  border-left: 3px solid var(--border-strong);
  background: var(--bg-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* =========================================================================
   Layout shell
   ========================================================================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-user {
  font-size: 0.85rem;
}

.brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--fg);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  letter-spacing: -0.01em;
}

.brand:hover { text-decoration: none; }

/* The Zeus logo is a flat asset drawn for a light background, so it always
   sits inside a small white chip - that keeps it legible in the topbar
   regardless of light/dark mode, rather than needing a separate dark-mode
   logo variant. */
.brand-logo {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  box-shadow: var(--shadow-sm);
  line-height: 0;
}

.brand-logo img {
  display: block;
  height: 20px;
  width: auto;
}

.brand-suffix {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--fg-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.landing-logo {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  box-shadow: var(--shadow-md);
  line-height: 0;
  margin-bottom: var(--space-5);
}

.landing-logo img {
  display: block;
  height: 48px;
  width: auto;
}

.container {
  max-width: 460px;
  margin: 3.5rem auto;
  padding: 0 1.25rem;
}

.container-wide {
  max-width: 960px;
  margin: 2.5rem auto;
  padding: 0 1.25rem 3rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* =========================================================================
   Cards / surfaces
   ========================================================================= */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.auth-shell {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.auth-shell h1 {
  text-align: center;
}

.auth-shell .muted {
  text-align: center;
  margin-top: -0.75rem;
}

/* =========================================================================
   Forms
   ========================================================================= */

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--fg-secondary);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
input[type="tel"],
textarea,
select {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font-size: 0.95rem;
  font-weight: 400;
  font-family: inherit;
  /* Form controls don't inherit line-height from body by default (a
     long-standing browser quirk) - without this they fall back to
     "normal" (~1.2), noticeably tighter than body's 1.55. That mismatch
     is invisible on single-line inputs but makes a wrapped textarea's
     scrollHeight (used to auto-size .retype-input to match its reference
     text, see candidate.js) come out visibly shorter than the matching
     prose it's meant to line up with. */
  line-height: 1.55;
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--border-strong);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

select {
  cursor: pointer;
}

textarea { resize: vertical; min-height: 4.5rem; }

.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  color: var(--fg);
}

.checkbox-row input {
  width: auto;
  accent-color: var(--accent);
}

/* =========================================================================
   Buttons
   ========================================================================= */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    box-shadow var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
}

button:hover, .button:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

button:active, .button:active {
  background: var(--accent-active);
  transform: translateY(1px);
}

button:disabled, .button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.button-secondary {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border-strong);
}

.button-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.button-secondary:active {
  background: var(--bg-subtle);
}

.button-danger {
  background: var(--error);
  color: #fff;
}

.button-danger:hover { filter: brightness(0.92); background: var(--error); }
.button-danger:active { filter: brightness(0.85); background: var(--error); }

.button-small {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.button-icon {
  padding: 0.35rem;
  width: 1.9rem;
  height: 1.9rem;
  line-height: 1;
}

.link-button {
  background: none;
  color: var(--muted);
  padding: 0;
  border: none;
  font-weight: 500;
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.link-button:hover {
  color: var(--fg);
  background: none;
  text-decoration: underline;
}

.link-button:active { transform: none; background: none; }

.inline-form { margin: 0; display: inline; }

.button-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* =========================================================================
   Flash messages
   ========================================================================= */

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.flash::before {
  flex-shrink: 0;
  font-weight: 700;
  line-height: 1.4;
}

.flash-error {
  background: var(--error-subtle);
  border-color: color-mix(in srgb, var(--error) 35%, transparent);
  color: var(--error);
}
.flash-error::before { content: "!"; }

.flash-success {
  background: var(--success-subtle);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  color: var(--success);
}
.flash-success::before { content: "✓"; }

.field-errors {
  list-style: none;
  padding: 0;
  margin: 0.3rem 0 0 0;
  color: var(--error);
  font-size: 0.82rem;
  font-weight: 500;
}

/* =========================================================================
   Tables
   ========================================================================= */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.25rem 0 1rem;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

th .icon {
  /* th text is already small/uppercase/letter-spaced; keep the icon from
     reading oversized or drifting off the text's baseline in that context. */
  font-size: 0.95em;
  vertical-align: -0.1em;
}

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:hover {
  background: var(--bg-subtle);
}

tbody tr:last-child td {
  border-bottom: none;
}

table code {
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

/* Card-ify tables on narrow screens so wide rows don't force horizontal
   scrolling on a candidate's phone. */
@media (max-width: 640px) {
  .container-wide table.responsive-table,
  .container-wide table.responsive-table thead,
  .container-wide table.responsive-table tbody,
  .container-wide table.responsive-table th,
  .container-wide table.responsive-table td,
  .container-wide table.responsive-table tr {
    display: block;
  }
  .responsive-table thead { display: none; }
  .responsive-table tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: var(--surface);
  }
  .responsive-table td {
    border-bottom: none;
    padding: 0.4rem 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    text-align: right;
  }
  .responsive-table td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    text-align: left;
  }
  .responsive-table td.button-row {
    justify-content: flex-end;
  }
  .responsive-table td.button-row::before {
    content: none;
  }
}

/* =========================================================================
   Badges
   ========================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}

.badge-active {
  background: var(--success-subtle);
  color: var(--success);
}

.badge-inactive {
  background: var(--bg-subtle);
  color: var(--muted);
}

.badge-inactive::before {
  background: var(--border-strong);
}

/* =========================================================================
   Banners
   ========================================================================= */

.preview-banner {
  background: var(--warning-subtle);
  border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
  color: var(--warning);
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  margin-bottom: 1.5rem;
  transition: background var(--transition-base), border-color var(--transition-base), color var(--transition-base);
}

.preview-banner.timer-critical {
  background: var(--error-subtle);
  border-color: color-mix(in srgb, var(--error) 40%, transparent);
  color: var(--error);
}

#timer-banner {
  position: sticky;
  top: 4.2rem;
  z-index: 10;
}

.timer-progress {
  margin-top: 0.6rem;
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--warning) 20%, var(--bg));
  overflow: hidden;
}

.timer-critical .timer-progress {
  background: color-mix(in srgb, var(--error) 20%, var(--bg));
}

/* Optional free-text note shown just above the candidate's "Start test"
   button (Test.start_button_note) - lighter weight than .preview-banner
   above since it's one line of admin-authored copy, not a system state
   banner, but uses the same warning color so it still reads as "pay
   attention before you click". */
.start-note {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  color: var(--warning);
  font-weight: 600;
  transition: color var(--transition-base);
}

.start-note .icon {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.timer-progress-fill {
  height: 100%;
  border-radius: inherit;
  background: currentColor;
  transition: width 1s linear;
}

#save-status {
  font-weight: 500;
}

/* =========================================================================
   Page structure helpers
   ========================================================================= */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.page-header h1,
.page-header h2 {
  margin-bottom: 0.2rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 2.25rem 0 1rem;
  flex-wrap: wrap;
}

.section-header:first-of-type { margin-top: 0; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 1rem;
}

.back-link:hover { color: var(--fg); }

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

.empty-state {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
}

.empty-state p { margin: 0; }

/* =========================================================================
   Question / option cards
   ========================================================================= */

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.2rem;
  margin-bottom: 0.85rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.question-card .prompt {
  font-weight: 650;
  font-size: 1rem;
  margin: 0 0 0.3rem 0;
  color: var(--fg);
}

.question-card .question-index {
  /* Numbered but visually lighter than the prompt itself, so the
     question text still reads as the main thing on the line. */
  color: var(--muted);
  font-weight: 700;
  margin-right: 0.3rem;
}

.question-card .question-meta {
  margin: 0 0 0.85rem 0;
}

.option-row {
  display: flex;
  /* The global `label` rule sets flex-direction: column (for stacked
     label+input form fields) and text-align isn't touched by it, but
     without an explicit row here the column direction wins, stacking the
     radio/checkbox above centered text instead of beside left-aligned
     text - the same class of bug as the earlier th icon-wrapping issue,
     just on a different property. */
  flex-direction: row;
  align-items: center;
  text-align: left;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  margin-bottom: 0.15rem;
}

label.option-row {
  cursor: pointer;
  font-weight: 400;
  color: var(--fg);
}

label.option-row:hover {
  background: var(--bg-subtle);
}

/* =========================================================================
   Attachment / document lists (test-level reference docs, per-question
   attachments) — admin management lists and the candidate-facing
   download links share this one class.
   ========================================================================= */

.attachment-list {
  list-style: none;
  margin: 0 0 0.6rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.attachment-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.attachment-list a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  overflow-wrap: anywhere;
  color: var(--fg);
}

.attachment-list a:hover {
  color: var(--accent);
}

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

input[type="text"].attachment-label-input {
  width: 14rem;
  max-width: 100%;
}

/* =========================================================================
   New question types: passage, retype, fill_blank, extraction_table
   ========================================================================= */

.question-card-passage {
  background: var(--bg-subtle);
  border-style: dashed;
}

.passage-text {
  white-space: pre-wrap;
}

.retype-reference {
  white-space: pre-wrap;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--fg-secondary);
  margin-bottom: 0.5rem;
}

/* Pre-filled with the reference text, so it needs real room by default
   (not the generic 4.5rem textarea min-height) - candidate.js grows it
   further to exactly match its content on load, but this keeps it close
   even if JS doesn't run. */
.retype-input {
  min-height: 9rem;
}

/* An inline blank sits inside a sentence (the prompt itself), not below
   it like every other input type here - sized to content rather than
   stretched full-width, so the sentence still reads naturally. */
input.inline-blank {
  /* Specificity note: the generic input[type="text"] rule above is
     (0,1,1) — a bare class selector like .inline-blank is only (0,1,0)
     and loses to it regardless of source order, which is exactly what
     was happening here (the blank was stretching to 100% width and
     pushing the rest of the sentence onto its own line). Qualifying
     with the input element ties the specificity at (0,1,1), so source
     order (this block comes later) correctly lets it win. */
  width: auto;
  min-width: 8ch;
  max-width: 100%;
  display: inline-block;
  margin: 0 0.25em;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
}

.extraction-table {
  width: 100%;
  /* Fixed layout: columns share the available width evenly instead of
     growing to fit whatever the longest unbroken answer happens to be -
     that growth is what used to push the table wider than its container
     and crop everything else. Long answers now wrap/grow in height
     instead (see td/textarea rules below), which is what 3.5 asked for. */
  table-layout: fixed;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

.extraction-table th,
.extraction-table td {
  border: 1px solid var(--border);
  padding: 0.4rem;
  text-align: left;
  /* Applies to the plain-text grading view (admin/attempt_grade.html)
     too, not just the editable textarea below - a long answer with no
     spaces (an account number, a concatenated code) needs this to wrap
     at all; without it the browser lets it overflow the cell instead. */
  overflow-wrap: anywhere;
  word-break: break-word;
}

.extraction-table th {
  background: var(--bg-subtle);
  font-weight: 650;
  font-size: 0.85rem;
}

.extraction-table td {
  /* Preserves a line break a candidate typed into the textarea when this
     same markup renders the read-only grading view (plain text, no
     textarea - admin/attempt_grade.html) - without this the browser
     collapses it back to a single line. */
  white-space: pre-wrap;
}

.extraction-table td textarea {
  display: block;
  width: 100%;
  min-height: 1.6em;
  padding: 0.3rem;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  line-height: 1.4;
  /* Auto-grown by candidate.js on input, same pattern as the retype
     question's textarea - resize/scroll handles would fight that. */
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
}

.extraction-table td textarea:focus {
  border-color: var(--border-strong);
  background: var(--surface);
}

.option-row input[type="checkbox"],
.option-row input[type="radio"] {
  width: auto;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Editable option row inside the question form */
.option-row-edit {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0;
}

.option-row-edit label {
  flex: 1;
  gap: 0;
}

.option-row-edit .checkbox-row {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.option-remove-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  line-height: 1;
}

.option-remove-btn:hover {
  background: var(--error-subtle);
  border-color: color-mix(in srgb, var(--error) 35%, transparent);
  color: var(--error);
  transform: none;
}

.add-option-btn {
  align-self: flex-start;
  margin-top: 0.4rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  margin: 0;
}

legend {
  padding: 0 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

/* =========================================================================
   Drag-and-drop question reordering
   ========================================================================= */

.sortable-list {
  display: flex;
  flex-direction: column;
}

.question-card.sortable-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  /* So a #q<id> redirect (e.g. after editing or reordering a question)
     lands the card clear of the sticky .topbar instead of tucked under it. */
  scroll-margin-top: 4.5rem;
}

.drag-handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  margin-top: 0.1rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.drag-handle:hover {
  background: var(--bg-subtle);
  color: var(--fg);
}

.drag-handle svg { pointer-events: none; }

.sortable-item.dragging {
  opacity: 0.5;
}

.sortable-item.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-ring);
}

.question-card-body {
  flex: 1;
  min-width: 0;
}

.reorder-fallback {
  display: flex;
  gap: 0.4rem;
}

/* JS hides the fallback buttons once drag-and-drop is wired up. */
.js-dnd-enabled .reorder-fallback {
  display: none;
}

.js-dnd-enabled .drag-handle {
  display: flex;
}

.drag-handle {
  display: none;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 640px) {
  body { font-size: 15px; }

  .topbar { padding: 0.7rem 1rem; }

  .container { margin: 2rem auto; }
  .container-wide { margin: 1.5rem auto; padding: 0 1rem 2.5rem; }

  .card { padding: 1.5rem; }

  h1 { font-size: 1.3rem; }

  .page-header,
  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .button-row { width: 100%; }

  #timer-banner { top: 3.4rem; }
}

/* =========================================================================
   Landing page
   ========================================================================= */

.landing {
  max-width: 760px;
}

.landing-hero {
  padding: var(--space-8) 0 var(--space-6);
  text-align: center;
}

.landing-hero h1 {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.landing-lede {
  color: var(--fg-secondary);
  font-size: 1.05rem;
  max-width: 46ch;
  margin: 0 auto;
}

.landing-steps-section {
  margin-top: var(--space-6);
}

.landing-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.landing-step {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.landing-step h3 { margin-bottom: 0.2rem; }
.landing-step p { margin: 0; }

.landing-step-num {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}

.landing-note {
  margin-top: var(--space-6);
  text-align: center;
}

.landing-footer {
  text-align: center;
  padding: var(--space-6) 0 var(--space-8);
}

@media (max-width: 640px) {
  .landing-hero { padding: var(--space-6) 0 var(--space-5); }
  .landing-hero h1 { font-size: 1.6rem; }
  .landing-step { padding: var(--space-4); gap: var(--space-3); }
  .landing-logo img { height: 36px; }
}

/* =========================================================================
   Icon font

   A self-hosted, hand-subset copy of Bootstrap Icons (MIT licensed,
   https://icons.getbootstrap.com/) - only the ~20 glyphs this app actually
   uses, built with fonttools' pyftsubset. Result is ~2.6KB woff2, served
   from this app's own origin so it works under the strict CSP (no
   font-src directive, which falls back to default-src 'self' - an
   external font CDN would be blocked, and would also be one more
   third-party request this lightweight app doesn't need).
   ========================================================================= */

@font-face {
  font-family: "Zeus Icons";
  src: url("../fonts/zeus-icons.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

.icon {
  font-family: "Zeus Icons";
  font-style: normal;
  font-weight: normal;
  display: inline-block;
  line-height: 1;
  vertical-align: -0.125em;
  text-transform: none;
  -webkit-font-smoothing: antialiased;
}

.icon-gear::before { content: "\f3e5"; }
.icon-logout::before { content: "\f1c3"; }
.icon-add::before { content: "\f64d"; }
.icon-edit::before { content: "\f4ca"; }
.icon-delete::before { content: "\f78b"; }
.icon-preview::before { content: "\f341"; }
.icon-candidates::before { content: "\f4d0"; }
.icon-questions::before { content: "\f224"; }
.icon-active::before { content: "\f4b5"; }
.icon-inactive::before { content: "\f2e6"; }
.icon-check::before { content: "\f26b"; }
.icon-check-fill::before { content: "\f26a"; }
.icon-refresh::before { content: "\f116"; }
.icon-time::before { content: "\f292"; }
.icon-link::before { content: "\f470"; }
.icon-key::before { content: "\f44e"; }
.icon-stopwatch::before { content: "\f597"; }
.icon-play::before { content: "\f4f4"; }
.icon-send::before { content: "\f6b9"; }
.icon-error::before { content: "\f623"; }
.icon-mail::before { content: "\f32f"; }

/* =========================================================================
   Rich text: Test.description's rendered output (sanitized HTML, see
   app/sanitize.py) and the Quill editor it's written in
   (admin/test_form.html, static/js/admin.js's description-editor block)
   ========================================================================= */

/* Rendered output - candidate/start.html and admin/test_detail.html.
   Only the tags app/sanitize.py's allowlist permits ever appear here. */
.rich-text p { margin: 0 0 0.75em 0; }
.rich-text p:last-child { margin-bottom: 0; }
.rich-text ul, .rich-text ol { margin: 0 0 0.75em 0; padding-left: 1.4em; }
.rich-text ul:last-child, .rich-text ol:last-child { margin-bottom: 0; }
.rich-text li { margin-bottom: 0.25em; }
.rich-text a { color: var(--accent); }

/* Quill editor shell - matched to this app's own input styling (border,
   radius, focus ring) rather than Quill's default look, so it reads as
   one of this form's fields instead of a visibly bolted-on widget. */
#description-editor .ql-toolbar.ql-snow {
  border: 1px solid var(--border-strong);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--bg-subtle);
  font-family: inherit;
}
#description-editor .ql-container.ql-snow {
  border: 1px solid var(--border-strong);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
}
#description-editor .ql-editor {
  min-height: 7rem;
  line-height: 1.55;
}
#description-editor .ql-editor.ql-blank::before {
  color: var(--muted);
  font-style: normal;
}
#description-editor.ql-container-focused .ql-toolbar.ql-snow,
#description-editor:focus-within .ql-toolbar.ql-snow {
  border-color: var(--accent);
}
#description-editor:focus-within .ql-container.ql-snow {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.icon-play-circle::before { content: "\f4f3"; }

/* =========================================================================
   Candidate dashboard / groups
   ========================================================================= */

.dashboard-group { margin-bottom: 1.25rem; }
.dashboard-group h2 { margin: 0 0 0.2rem; }
.dashboard-step {
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
}
.dashboard-step h3 { margin: 0; font-size: 1.05rem; }
.dashboard-step-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.4rem;
}
.outcome-message {
  white-space: pre-line;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  margin: 0.4rem 0 0;
}
.deadline-box {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
}
.deadline-box p { margin: 0.15rem 0; }

/* Admin: group invite + funnel */
.invite-box { display: grid; gap: 0.75rem; }
.invite-link {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  word-break: break-all;
}
.invite-email {
  width: 100%;
  font-family: inherit;
  min-height: 21rem;
}
.decision-card { margin-bottom: 1.25rem; }
.funnel-table td, .funnel-table th { text-align: right; }
.funnel-table td:first-child, .funnel-table th:first-child { text-align: left; }
.stat-pill {
  display: inline-block;
  min-width: 2rem;
  text-align: center;
}
.decision-passed { color: var(--success); font-weight: 600; }
.decision-failed { color: var(--error); font-weight: 600; }
.decision-pending { color: var(--warning); font-weight: 600; }
.step-cell { white-space: nowrap; }
.visually-hidden-copy {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.form-section-title { font-size: 1.1rem; margin: 0.8rem 0 0; }

/* A text input with its button beside it: line the button up with the
   input, not with the label above it. */
.inline-field-row { align-items: flex-end; flex-wrap: nowrap; }
.inline-field-row > button { flex-shrink: 0; }
/* Series step actions: compact icon buttons on one line. */
.step-actions { flex-wrap: nowrap; justify-content: flex-end; }
.step-actions .button-icon { width: 1.9rem; height: 1.9rem; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.step-actions .button-icon .icon { font-size: 0.8rem; }
.step-actions .button-icon svg { width: 13px; height: 13px; }
.step-actions .button-secondary:not(:disabled) { color: var(--fg); border-color: var(--border-strong); }
.step-actions .button-icon:disabled { opacity: 0.35; }
.inline-field-row > button {
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
  border-width: 1px;
  font-size: 0.95rem;
  line-height: inherit;
  box-sizing: border-box;
}

/* Admin top bar on phones: the nav (Tests/Series/Groups/Candidates/...)
   wraps under the logo instead of pushing the page sideways. */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; row-gap: 0.4rem; padding: 0.6rem 1rem; }
  .topbar-nav { flex-wrap: wrap; gap: 0.35rem 0.9rem; font-size: 0.9rem; }
  .topbar-user { display: none; }
}

/* List filter bar (admin candidates list): fields side by side, buttons
   lined up with the inputs, wrapping on narrow screens. */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.filter-bar label { flex: 1 1 12rem; min-width: 0; }
.filter-bar label.filter-search { flex: 2 1 16rem; }
.filter-bar .filter-actions { display: flex; gap: 0.5rem; align-items: center; }
.filter-bar .filter-actions button,
.filter-bar .filter-actions .button {
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
  border-width: 1px;
  font-size: 0.95rem;
  line-height: 1.55;
}
.filter-summary { margin: -0.5rem 0 1rem; }
/* Same height for search box and dropdowns so they line up. */
.filter-bar input, .filter-bar select { height: 2.85rem; }

/* Phones: hide the table header row - each row already shows its own
   labels. (The ".container-wide table.responsive-table thead {display:block}"
   rule above out-ranked the plain ".responsive-table thead {display:none}",
   so the header used to show up as a stacked list on every admin table.) */
@media (max-width: 640px) {
  .container-wide table.responsive-table thead { display: none; }
}
