:root {
  --accent: #005EB8;
  --accent-dark: #00457F;
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --border: #DCE1E6;
  --text-primary: #1B1F23;
  --text-secondary: #5B6470;
  --success-bg: #EAF6EC;
  --success-text: #1E6B33;
}

* { box-sizing: border-box; }

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

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.phase-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.phase-badge.phase-training { background: #FFF3E0; color: #9A5B13; }
.phase-badge.phase-test { background: #E8F0FE; color: var(--accent-dark); }
.phase-badge.phase-questionnaire { background: #F1EAFB; color: #5B3A9E; }

.action-confirm {
  margin-left: 10px;
  color: var(--success-text);
  font-size: 13px;
  font-weight: 600;
}
/* The unconditional display rule above would otherwise override the
   browser's default [hidden] { display: none }, since author CSS always
   wins over the UA stylesheet regardless of specificity — keeping it
   scoped to :not([hidden]) is what actually lets the hidden attribute
   hide the element until JS reveals it. */
.action-confirm:not([hidden]) {
  display: inline-block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
body { animation: fadeIn 0.25s ease; }

/* Explicit, consistent focus styling instead of relying on inconsistent
   browser UA defaults (which look clipped against these elements'
   border-radius). */
a.button:focus-visible, button:focus-visible, .lang-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  margin-top: 12px;
}

h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 16px;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 12px;
}

p { color: var(--text-primary); }
.muted { color: var(--text-secondary); font-size: 14px; }

a.button, button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  margin-top: 8px;
}

a.button:hover, button:hover { background: var(--accent-dark); }

a.button.secondary, button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
a.button.secondary:hover, button.secondary:hover { background: #EAF2FB; }

/* The "do this first" action (open tool / open questionnaire) is visually
   distinct from the plain accent "Continue" button, so it's obvious which
   one to click first. */
a.button.action {
  background: #B5580A;
}
a.button.action:hover { background: #8F4507; }

button:disabled {
  background: #B7C0C9;
  cursor: not-allowed;
}
button:disabled:hover { background: #B7C0C9; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}
.topbar .id-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.topbar form { margin: 0; }
.topbar .logout-link {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 4px 8px;
  text-decoration: underline;
  cursor: pointer;
  margin: 0;
}
.topbar .logout-link:hover { background: none; color: var(--text-primary); }

.back-link {
  display: inline-block;
  color: var(--text-secondary);
  font-size: 14px;
  text-decoration: none;
  margin-top: 16px;
}
.back-link:hover { color: var(--accent); text-decoration: underline; }

.guideline-block {
  background: #F5F7FA;
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin: 12px 0;
  border-radius: 0 6px 6px 0;
}
.guideline-block h3 { margin: 0 0 6px; font-size: 14px; }
.guideline-block p { margin: 0; font-size: 14px; }

/* Collapsible reference on the test screen (views/tool_annotate.ejs) —
   native <details>/<summary> so it's keyboard/screen-reader accessible
   with no JS. */
details.quick-reference {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  background: #F5F7FA;
}
details.quick-reference summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
details.quick-reference[open] summary { margin-bottom: 10px; }
details.quick-reference summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.label-legend { margin-top: 12px; }
.label-legend h3 { font-size: 13px; margin: 0 0 6px; }
.label-legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}
.label-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: middle;
}

/* Non-blocking post-task micro-check (views/tool_annotate.ejs) — a real
   <fieldset>/<legend> since it's a genuine grouped-radio question, not
   decorative markup. Styled to match .guideline-block/.quick-reference
   (same background, border, radius) rather than looking like a stray
   browser-default form. */
.difficulty-check {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  background: #F5F7FA;
}
.difficulty-check legend {
  font-size: 14px;
  font-weight: 600;
  padding: 0 4px;
}
.difficulty-check:disabled,
fieldset.difficulty-check[disabled] {
  opacity: 0.55;
}

/* Pill-style number picker: the native radio is visually hidden (kept in
   the DOM for keyboard/screen-reader use) and its label styled as the
   selectable control instead — reads as part of this app's design system
   rather than a bare row of browser radio buttons. */
.difficulty-options {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.difficulty-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.difficulty-option input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.difficulty-option.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.difficulty-option:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
fieldset:disabled .difficulty-option {
  cursor: not-allowed;
}
.difficulty-scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-top: 6px;
  max-width: 232px;
}
.difficulty-hint {
  margin: 10px 0 0;
}

/* Numbered walkthrough on the training step (views/tool_training.ejs) —
   text on one side, a screenshot slot on the other; stacks on narrow
   viewports since there's no room for two columns there. */
.training-steps { margin: 8px 0 4px; }
.training-step {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
  padding: 20px 0;
  border-top: 1px solid var(--border);
}
.training-step:first-child { border-top: none; padding-top: 8px; }
.training-step-number {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.training-step-text { flex: 1 1 260px; min-width: 220px; }
.training-step-text h3 { margin: 0 0 6px; font-size: 15px; }
.training-step-text p { margin: 0; font-size: 14px; color: var(--text-secondary); }
.training-step-image { flex: 1 1 260px; max-width: 320px; }
.training-step-image img {
  width: 100%;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
}

@media (max-width: 640px) {
  .training-step-image { max-width: 100%; }
}

.lang-options { display: flex; gap: 16px; margin-top: 24px; }

.lang-option {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
}
.lang-option:hover { border-color: var(--accent); }
.lang-option { color: var(--text-primary); }
.lang-option .flag { font-size: 32px; display: block; margin-bottom: 8px; }

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  margin-top: 8px;
}

.id-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.id-input-row .id-prefix {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
}
.id-input-row input { margin-top: 0; }

.admin-add-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 16px;
}
.admin-add-form input { width: 120px; margin-top: 0; }
.admin-add-form button { margin-top: 0; }

.notice-success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #B9DEC0;
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 12px;
  font-size: 14px;
}

.error-box {
  background: #FDEDED;
  color: #A32D2D;
  border: 1px solid #F0C1C1;
  border-radius: 6px;
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 14px;
}

.break-box {
  background: #FFF8E8;
  border: 1px solid #F2DFAE;
  border-radius: 14px;
  padding: 36px;
  text-align: center;
}
.milestone-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #B9DEC0;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* A row of equal segments, one per step in STEPS — filled solid as they're
   completed, with a soft halo on the current one. Reads as precise
   progress (like a multi-step form indicator) rather than a decorative
   animation, matching the study's clean/scientific tone. */
.step-tracker {
  display: flex;
  gap: 4px;
  margin: 4px 0 22px;
}
.step-seg {
  flex: 1;
  height: 6px;
  min-width: 3px;
  border-radius: 999px;
  background: var(--border);
  transition: background-color 0.4s ease, box-shadow 0.4s ease;
}
.step-seg.is-done { background: var(--accent); }
.step-seg.is-current {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 94, 184, 0.18);
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-top: 16px;
}
table.admin-table th, table.admin-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
table.admin-table th { color: var(--text-secondary); font-weight: 500; }

/* The admin table has enough columns to overflow narrow/mobile viewports —
   scroll the table itself rather than letting it blow out the page. */
.table-scroll {
  overflow-x: auto;
}

tr.stale-row {
  background: #FDEDED;
}

video { width: 100%; border-radius: 8px; margin-bottom: 16px; }

/* Topbar items can collide on narrow viewports once the step label grows
   past a couple of digits ("Step 10 of 13") — let them wrap instead of
   overflowing horizontally. */
@media (max-width: 420px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 6px;
  }
}

/* --- Admin dashboard --------------------------------------------------- */

/* The admin dashboard is data-dense (participant table, stat cards) and
   doesn't benefit from the narrow reading-width column every participant-
   facing page uses. */
.page-wide { max-width: 1180px; }

/* The training walkthrough hosts numbered steps with screenshot slots
   side-by-side with instructions — needs more room than the narrow reading
   column but less than the data-dense admin dashboard. */
.page-training { max-width: 1040px; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}
.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.stat-card.stat-stale .stat-value { color: #A32D2D; }

.admin-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.refresh-indicator {
  font-size: 13px;
  color: var(--text-secondary);
}
.refresh-indicator .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2E9E4C;
  margin-right: 6px;
  vertical-align: middle;
}
.refresh-indicator.stale-fetch .dot { background: #C9922C; }

.export-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.export-row + .export-row { margin-top: 4px; }
.export-tool-label { font-weight: 600; }
.export-missing { color: var(--text-secondary); }
.export-refresh-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  margin: 0;
}
.export-refresh-btn:hover { color: var(--accent-dark); }
.export-refresh-btn:disabled { color: var(--text-secondary); cursor: default; text-decoration: none; }

tr.done-row { background: var(--success-bg); }
