/* TrackedSurvey — foundation styles.
   System font stack on purpose: respondents arrive on every kind of device and
   connection, and a webfont round-trip is latency we get nothing back for. */

:root {
  --ink:        #1b2027;
  --ink-soft:   #5a636e;
  --ink-faint:  #868f9a;
  --ground:     #f7f8f9;
  --surface:    #ffffff;
  --line:       #e2e5e9;
  --accent:      #1f6f8b;
  --accent-ink:  #16576e;
  --accent-wash: #eef5f8;
  --danger:      #b23b3b;
  --danger-bg:   #fdf1f1;
  --ok:          #2f7a4f;
  --star:        #d9a521;
  --radius: 6px;
  --measure: 34rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink:        #e6e9ed;
    --ink-soft:   #a7b0bb;
    --ink-faint:  #79828d;
    --ground:     #14181d;
    --surface:    #1b2027;
    --line:       #2b323b;
    --accent:      #6bb6cf;
    --accent-ink:  #93cde1;
    --accent-wash: #1d2830;
    --danger:      #e88585;
    --danger-bg:   #2a1c1c;
    --ok:          #77c497;
    --star:        #e5bb4d;
  }
}

:root[data-theme="dark"] {
  --ink:        #e6e9ed;
  --ink-soft:   #a7b0bb;
  --ink-faint:  #79828d;
  --ground:     #14181d;
  --surface:    #1b2027;
  --line:       #2b323b;
  --accent:      #6bb6cf;
  --accent-ink:  #93cde1;
  --accent-wash: #1d2830;
  --danger:      #e88585;
  --danger-bg:   #2a1c1c;
  --ok:          #77c497;
  --star:        #e5bb4d;
}

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

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* ---------------------------------------------------------- splash page */

body.splash .wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
}

.mark {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.lede   { margin: 0.5rem 0 0; color: var(--ink-soft); }
.note   { margin: 0; color: var(--ink-faint); font-size: 0.9rem; max-width: 26rem; }

.foot {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  width: 100%;
  max-width: 26rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--ink-faint);
}

/* ------------------------------------------------------ document pages */

body.doc .wrap { text-align: left; }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 0.25rem; text-wrap: balance; }
h2 { font-size: 1.05rem; margin: 2rem 0 0.4rem; text-wrap: balance; }
p, li { color: var(--ink-soft); }
ul { padding-left: 1.15rem; }
li { margin-bottom: 0.35rem; }
strong { color: var(--ink); font-weight: 600; }
.updated { color: var(--ink-faint); font-size: 0.85rem; margin-top: 0; }

/* -------------------------------------------------------------- links */

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-ink); }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ======================================================== survey pages */

body.survey .wrap { max-width: 40rem; text-align: left; }

.progress {
  position: sticky; top: 0; z-index: 5;
  height: 4px; background: var(--line); border-radius: 2px;
  margin: -0.5rem 0 1.75rem;
}
.progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s ease; }

.page-title { font-size: 1.35rem; margin: 0 0 0.5rem; }
.page-intro { color: var(--ink-soft); margin-bottom: 1.5rem; }

.q { padding: 1.5rem 0; border-top: 1px solid var(--line); }
.q:first-of-type { border-top: 0; padding-top: 0; }
.q-title { font-size: 1.05rem; font-weight: 600; color: var(--ink); margin: 0 0 0.25rem; line-height: 1.4; }
.q-help  { font-size: 0.9rem; color: var(--ink-faint); margin: 0 0 0.75rem; }
.req     { color: var(--danger); margin-left: 0.15rem; }

.q-error { border-left: 3px solid var(--danger); padding-left: 0.9rem; margin-left: -1.2rem; }
.q-errors { list-style: none; padding: 0; margin: 0 0 0.75rem; }
.q-errors li { color: var(--danger); font-size: 0.9rem; }
.alert {
  background: var(--danger-bg); border: 1px solid var(--danger);
  border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1.5rem;
}
.alert p { margin: 0; color: var(--danger); font-size: 0.925rem; }

.descriptive { color: var(--ink-soft); }
.descriptive p:first-child { margin-top: 0; }

/* ---- choices: large tap targets, not native controls ---------------- */

.choices { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }

.choice {
  display: flex; align-items: center; gap: 0.75rem;
  min-height: 3rem; padding: 0.7rem 0.9rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.choice:hover { border-color: var(--accent); }
.choice input { flex: 0 0 auto; width: 1.15rem; height: 1.15rem; accent-color: var(--accent); margin: 0; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice-label { color: var(--ink); line-height: 1.4; }

.other-text {
  margin: -0.25rem 0 0.25rem 2.4rem;
  width: calc(100% - 2.4rem);
  display: none;
}
/* Revealed by CSS, not JavaScript: with a script-driven reveal a respondent
   without JS could select "Other" and never see the box they are then told to
   fill in. :has() keeps this working with no script at all. */
.choice:has(input[data-other]:checked) + .other-text { display: block; }
@supports not selector(:has(*)) {
  .other-text { display: block; }   /* older browsers: always show it */
}

/* ---- inputs ---------------------------------------------------------- */

.input, .select {
  width: 100%; min-height: 3rem; padding: 0.7rem 0.9rem;
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.textarea { min-height: 6rem; resize: vertical; line-height: 1.5; }
.input-number { max-width: 9rem; text-align: right; font-variant-numeric: tabular-nums; }
.input-date { max-width: 14rem; }
.number-wrap { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.75rem; }
.unit { color: var(--ink-faint); font-size: 0.9rem; }
.select { max-width: 22rem; }

/* ---- numeric scales -------------------------------------------------- */

.scale { display: flex; gap: 0.35rem; margin-top: 0.75rem; flex-wrap: wrap; }
.scale-point { flex: 1 1 2.5rem; min-width: 2.5rem; }
.scale-point input { position: absolute; opacity: 0; width: 0; height: 0; }
.scale-num {
  display: flex; align-items: center; justify-content: center;
  height: 3rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font-variant-numeric: tabular-nums;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.scale-point:hover .scale-num { border-color: var(--accent); }
.scale-point input:checked + .scale-num { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.scale-point input:focus-visible + .scale-num { outline: 2px solid var(--accent); outline-offset: 2px; }
.scale-ends { display: flex; justify-content: space-between; gap: 1rem; margin-top: 0.5rem; font-size: 0.8rem; color: var(--ink-faint); }

.stars { display: flex; gap: 0.25rem; margin-top: 0.75rem; }
.star input { position: absolute; opacity: 0; width: 0; height: 0; }
.star svg { width: 2.5rem; height: 2.5rem; fill: var(--line); cursor: pointer; transition: fill 0.12s ease; }
.star.on svg, .stars:not(:hover) .star.on svg { fill: var(--star); }
.star input:focus-visible + svg { outline: 2px solid var(--accent); outline-offset: 2px; }

.slider-wrap { margin-top: 0.75rem; }
.slider { width: 100%; accent-color: var(--accent); height: 2rem; }
.slider-value {
  display: block; font-size: 1.5rem; font-weight: 600; color: var(--accent);
  font-variant-numeric: tabular-nums; margin-bottom: 0.25rem;
}

/* ---- matrices: table on wide screens, cards on phones ---------------- */

.matrix-scroll { overflow-x: auto; margin-top: 0.75rem; }
.matrix { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.matrix th, .matrix td { padding: 0.6rem 0.4rem; text-align: center; }
.matrix thead th { color: var(--ink-faint); font-weight: 500; font-size: 0.8rem; vertical-align: bottom; }
.matrix tbody th { text-align: left; font-weight: 400; color: var(--ink); min-width: 11rem; }
.matrix tbody tr { border-top: 1px solid var(--line); }
.matrix tbody tr:hover { background: var(--accent-wash); }
.cell { display: flex; align-items: center; justify-content: center; min-height: 2.75rem; cursor: pointer; }
.cell input { position: absolute; opacity: 0; width: 0; height: 0; }
.cell .dot, .cell .box {
  width: 1.3rem; height: 1.3rem; border: 1.5px solid var(--line); background: var(--surface);
  transition: border-color 0.12s ease, background 0.12s ease;
}
.cell .dot { border-radius: 50%; }
.cell .box { border-radius: 3px; }
.cell:hover .dot, .cell:hover .box { border-color: var(--accent); }
.cell input:checked + .dot,
.cell input:checked + .box { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }
.cell input:focus-visible + .dot, .cell input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }

.matrix-cards { display: none; flex-direction: column; gap: 1rem; margin-top: 0.75rem; }
.matrix-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem; margin: 0; }
.matrix-card legend { padding: 0 0.35rem; font-size: 0.95rem; color: var(--ink); }
.matrix-card .choices { margin-top: 0.5rem; }

@media (max-width: 44rem) {
  .matrix-scroll { display: none; }
  .matrix-cards  { display: flex; }
}

/* ---- ranking and constant sum ---------------------------------------- */

.ranking { list-style: none; padding: 0; margin: 0.75rem 0 0; display: flex; flex-direction: column; gap: 0.5rem; }
.rank-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0.9rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.rank-label { flex: 1 1 auto; color: var(--ink); }
.select-rank { width: 4.5rem; min-width: 4.5rem; flex: 0 0 auto; text-align: center; }

.sumgrid { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }
.sum-row { display: flex; align-items: center; gap: 0.75rem; }
.sum-label { flex: 1 1 auto; color: var(--ink); }
.sum-input { flex: 0 0 auto; width: 6rem; }
.sum-total { margin: 0.5rem 0 0; font-size: 0.9rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.sum-total.over  { color: var(--danger); }
.sum-total.exact { color: var(--ok); }

/* ---- image choice ---------------------------------------------------- */

.images { display: grid; grid-template-columns: repeat(var(--cols, 2), 1fr); gap: 0.75rem; margin-top: 0.75rem; }
.image-choice {
  display: flex; flex-direction: column; gap: 0.5rem; padding: 0.6rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
.image-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); }
.image-choice input { align-self: flex-start; accent-color: var(--accent); }
.image-choice img { width: 100%; height: auto; border-radius: 3px; }
.image-missing { display: block; aspect-ratio: 4 / 3; background: var(--line); border-radius: 3px; }

/* ---- navigation ------------------------------------------------------ */

.nav { display: flex; gap: 0.75rem; margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.btn {
  font: inherit; font-weight: 600; min-height: 3rem; padding: 0.75rem 1.75rem;
  border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; margin-left: auto; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-quiet { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-quiet:hover { color: var(--ink); border-color: var(--ink-faint); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.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;
}

/* ------------------------------------------------- non-production echo */

.verdict { font-weight: 600; padding: 0.6rem 0.9rem; border-radius: var(--radius); }
.verdict.ok  { color: var(--ok);     background: var(--accent-wash); }
.verdict.bad { color: var(--danger); background: var(--danger-bg); }
.kv { border-collapse: collapse; width: 100%; margin-bottom: 1rem; }
.kv th { text-align: left; font-weight: 500; color: var(--ink-faint); padding: 0.3rem 0.9rem 0.3rem 0; white-space: nowrap; vertical-align: top; }
.kv td { padding: 0.3rem 0; }
.kv code { font-size: 0.85rem; word-break: break-all; }
pre.wrapped {
  white-space: pre-wrap; word-break: break-all; font-size: 0.8rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.75rem; overflow-x: auto;
}

/* ---- submit status -------------------------------------------------- */

.submit-note {
  margin: 1.25rem 0 0;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  background: var(--accent-wash);
  color: var(--ink-soft);
  font-size: 0.925rem;
}
.submit-note.is-error {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* ---- read-only survey preview (/preview/<token>) -------------------------
   Shown to people who cannot be sent a real invitation: security reviewers
   checking the domain, prospective clients, colleagues. Deliberately looks
   like the real thing so what is reviewed is what respondents see. */
.preview-banner {
  border: 1px solid var(--rule, #d8dee2);
  border-left: 3px solid var(--accent, #1f7a6b);
  background: #f4f8f7;
  border-radius: 4px;
  padding: 1rem 1.15rem;
  margin: 0 0 1.75rem;
  font-size: .94rem;
  line-height: 1.55;
}
.preview-banner p { margin: .4rem 0; }
.preview-banner p:first-child { margin-top: 0; }
.preview-banner p:last-child { margin-bottom: 0; }
.preview-head { margin-bottom: 1.5rem; }
.preview-meta { color: #5a6569; font-size: .9rem; margin-top: .3rem; }
.preview-page { border-top: 1px solid var(--rule, #d8dee2); padding-top: 1.5rem; margin-top: 2rem; }
.preview-page:first-of-type { border-top: 0; margin-top: 0; }
.preview-page-title {
  font-size: .74rem; letter-spacing: .12em; text-transform: uppercase;
  color: #6b7579; margin: 0 0 .75rem;
}
.preview-body { border: 0; padding: 0; margin: 0; min-width: 0; }
.preview-body input, .preview-body select, .preview-body textarea, .preview-body button { cursor: not-allowed; }
.preview-foot { margin-top: 3rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
