/* Sharevy — mobile-first styles. Base rules target phones; wider screens are enhanced below.
   Corporate look: IBM Plex Sans, square corners, thin 1px rules, a muted slate palette. */

/* ---------- Font: IBM Plex Sans (OFL-1.1, public/fonts/LICENSE-IBM-Plex.txt), self-hosted ---------- */
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/public/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2");
}

/* ---------- Design tokens ----------
   Every color and the corner radius live here. Text pairs meet WCAG AA (>= 4.5:1) in both
   themes; --border-strong (form controls) is >= 3:1 against --surface.
   60-30-10: neutrals (--bg, --surface) carry most of the page, the blue brand the structure
   (topbar, borders, links, secondary buttons), and the copper --accent, the blue's complement,
   only the primary actions and the stripe under the topbar. */
:root {
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --brand: #2b4a6f;          /* primary buttons, accents */
  --brand-dark: #1f3753;     /* primary hover */
  --brand-soft: #e6ecf3;     /* selected / hover tint */
  --brand-text: #2b4a6f;     /* brand-colored text and links */
  --accent: #a65d16;         /* 10%: primary actions (complement of the blue) */
  --accent-dark: #8a4b12;    /* primary hover */
  --on-accent: #fff;
  --accent-line: #c27a2c;    /* stripe under the topbar */
  --topbar: #1e2a3a;
  --text: #1c232c;
  --muted: #56606c;
  --border: #d5dae1;         /* panel and table rules */
  --border-strong: #7d8794;  /* inputs, secondary buttons */
  --bg: #f3f4f6;
  --surface: #fff;
  --surface-alt: #f7f8fa;    /* table headers, respondent-name box */
  --danger: #a33a32;
  --danger-soft: #f7e9e7;
  --ok: #2f6b45;
  --ok-soft: #e7f0ea;
  --on-ok: #fff;
  --warn: #7a5a14;
  --warn-soft: #f6f0de;
  --closed: #4f565e;
  --closed-soft: #e8eaed;
  --on-topbar: #fff;
  --on-topbar-muted: #c3cdd9;
  --shadow: rgba(16, 24, 40, .1);
  --radius: 0;
  --tap: 44px; /* minimum touch target */
}

/* Dark palette: applied when chosen with the theme button, or by the OS setting when no choice was made.
   Keep the two dark blocks identical. */
:root { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #3a5f8a;
  --brand-dark: #2f5079;
  --brand-soft: #22303f;
  --brand-text: #9fbbdc;
  --accent: #d9954a;
  --accent-dark: #e0a25a;
  --on-accent: #12171e;
  --accent-line: #d9954a;
  --topbar: #1b2633;
  --text: #e4e8ee;
  --muted: #a0aab6;
  --border: #2f3946;
  --border-strong: #6b7685;
  --bg: #12171e;
  --surface: #1a212b;
  --surface-alt: #161c24;
  --danger: #e39a90;
  --danger-soft: #3a2224;
  --ok: #8cc5a0;
  --ok-soft: #1b2e23;
  --on-ok: #10261a;
  --warn: #d9b871;
  --warn-soft: #322b17;
  --closed: #b8bec6;
  --closed-soft: #2c333c;
  --shadow: rgba(0, 0, 0, .45);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #3a5f8a;
    --brand-dark: #2f5079;
    --brand-soft: #22303f;
    --brand-text: #9fbbdc;
    --accent: #d9954a;
    --accent-dark: #e0a25a;
    --on-accent: #12171e;
    --accent-line: #d9954a;
    --topbar: #1b2633;
    --text: #e4e8ee;
    --muted: #a0aab6;
    --border: #2f3946;
    --border-strong: #6b7685;
    --bg: #12171e;
    --surface: #1a212b;
    --surface-alt: #161c24;
    --danger: #e39a90;
    --danger-soft: #3a2224;
    --ok: #8cc5a0;
    --ok-soft: #1b2e23;
    --on-ok: #10261a;
    --warn: #d9b871;
    --warn-soft: #322b17;
    --closed: #b8bec6;
    --closed-soft: #2c333c;
    --shadow: rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 16px/1.55 var(--font);
  color: var(--text);
  background: var(--bg);
  font-kerning: normal;
}
a { color: var(--brand-text); text-underline-offset: .15em; }
h1 { font-size: 1.4rem; font-weight: 600; line-height: 1.25; letter-spacing: -.005em; margin: .5rem 0 1rem; }
/* Section labels: small uppercase with letter spacing, like a report. */
h2 { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 .9rem; display: flex; align-items: center; gap: .5rem; }
h3 { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1.75rem 0 .75rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }
h4 { font-size: .95rem; font-weight: 600; margin: 0 0 .75rem; }
p { margin: 0 0 1rem; }
strong { font-weight: 600; }

.icon { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: square; stroke-linejoin: miter; vertical-align: middle; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar { background: var(--topbar); color: var(--on-topbar); border-bottom: 3px solid var(--accent-line); }
.topbar-inner { max-width: 960px; margin: 0 auto; padding: .4rem 1rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem 1rem; min-height: 56px; }
.brand { color: var(--on-topbar); font-weight: 600; font-size: 1.15rem; letter-spacing: .03em; text-decoration: none; display: inline-flex; align-items: center; gap: .6rem; min-height: var(--tap); }
.brand-logo { width: 28px; height: 28px; flex: none; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
.topbar nav a, .topbar nav button.link { color: var(--on-topbar); text-decoration: none; font-size: .9rem; font-weight: 500; min-height: var(--tap); display: inline-flex; align-items: center; gap: .35rem; }
.topbar nav a:hover, .topbar nav button.link:hover { text-decoration: underline; }
.topbar :focus-visible { outline-color: var(--on-topbar); }
.who { color: var(--on-topbar-muted); font-size: .85rem; padding-left: 1rem; border-left: 1px solid rgba(255, 255, 255, .2); }

main { max-width: 960px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.respondent main { max-width: 720px; }
/* Public results (/r/<token>) use the respondent top bar but the results page width. */
.respondent main:has(> .public-results-view) { max-width: 960px; }

/* ---------- Forms ---------- */
input, select, textarea {
  font: inherit;
  font-weight: 400;
  font-size: 1rem; /* >=16px avoids iOS zoom on focus */
  width: 100%;
  min-height: var(--tap);
  padding: .55rem .75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-text); outline-offset: -1px; border-color: var(--brand-text); }
input[type=checkbox], input[type=radio] { width: 1.2rem; height: 1.2rem; min-height: 0; margin: 0; accent-color: var(--brand); flex: none; }
label { font-weight: 500; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: .875rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack > label { display: flex; flex-direction: column; gap: .35rem; }
.stack > label.choice { flex-direction: row; align-items: flex-start; gap: .75rem; }
.stack > label.choice > input { margin-top: .2rem; }
.field > label { display: block; margin-bottom: .2rem; }
.inline { display: inline; }

/* ---------- Buttons ---------- */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: var(--tap);
  padding: .5rem 1.1rem;
  font: inherit; font-weight: 500; font-size: .95rem; letter-spacing: .01em;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent); color: var(--on-accent);
  text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:hover, .button:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.secondary, .button.secondary { background: var(--surface); color: var(--brand-text); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--brand-soft); border-color: var(--brand-text); }
button.danger, .button.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.done { background: var(--ok); border-color: var(--ok); color: var(--on-ok); }
button.link { background: none; border: none; padding: 0; min-height: 0; color: inherit; font-weight: 400; }
button:disabled { opacity: .35; cursor: not-allowed; }
.big { min-height: 48px; font-size: 1rem; padding: .6rem 1.4rem; }
.block { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.button-row > * { flex: 1 1 100%; }
.button-row > form > button { width: 100%; }
.page-head > .button-row { width: 100%; }

.icon-button {
  width: var(--tap); height: var(--tap); min-height: var(--tap); padding: 0;
  background: var(--surface); color: var(--brand-text); border-color: var(--border);
}
.icon-button:hover { background: var(--brand-soft); border-color: var(--brand-text); }
.icon-button.danger { color: var(--danger); border-color: var(--border); }
.icon-button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.icon-button:disabled:hover { background: var(--surface); border-color: var(--border); }

/* ---------- Surfaces & messages ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.muted { color: var(--muted); font-weight: 400; }
.back { display: inline-flex; align-items: center; gap: .25rem; min-height: var(--tap); text-decoration: none; font-size: .9rem; font-weight: 500; }
.description { white-space: pre-wrap; color: var(--muted); }

/* Messages: a tinted box with a solid colored rule on the left. */
.flash, .notice, .errors { display: flex; gap: .6rem; align-items: flex-start; padding: .7rem 1rem; border: 0; border-left: 3px solid currentColor; border-radius: var(--radius); margin-bottom: 1rem; }
.update-banner { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; padding: .6rem 1rem; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid currentColor; }
.update-banner > span { flex: 1 1 16rem; }
.flash { background: var(--ok-soft); color: var(--ok); font-weight: 500; }
.notice { background: var(--warn-soft); color: var(--warn); }
.errors { background: var(--danger-soft); color: var(--danger); }
.errors ul { margin: 0; padding-left: 1rem; }
.errors li:first-child:not(:only-child) { list-style: none; margin-left: -1rem; font-weight: 600; }
.errors a { color: inherit; }
.flash .icon, .notice .icon, .errors .icon { margin-top: .2rem; }

.badge { display: inline-block; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; line-height: 1.5; padding: .1rem .5rem; border: 1px solid currentColor; border-radius: var(--radius); vertical-align: middle; }
.badge.open { background: var(--ok-soft); color: var(--ok); }
.badge.closed { background: var(--closed-soft); color: var(--closed); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.empty > .icon { width: 2.5rem; height: 2.5rem; stroke-width: 1.25; }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 2rem 0 1.5rem; }
.hero h1 { font-size: 2rem; letter-spacing: .01em; color: var(--brand-text); margin-bottom: .75rem; }
.lead { font-size: 1.1rem; color: var(--muted); }
.steps { text-align: left; max-width: 440px; margin: 0 auto 1.75rem; padding: 1rem 1rem 1rem 2.5rem; display: grid; gap: .5rem; background: var(--surface); border: 1px solid var(--border); }
.hero .button-row { max-width: 440px; margin: 0 auto; }

/* ---------- Survey list ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-head h1, .page-head h2 { margin: 0; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.card-link { color: inherit; text-decoration: none; border-top: 3px solid var(--border); }
.card-link:hover { border-color: var(--border-strong); border-top-color: var(--brand); box-shadow: 0 1px 3px var(--shadow); }
.cards > li { display: flex; }
.survey-card { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.card-main { display: block; flex: 1; color: inherit; text-decoration: none; }
.card-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.card-actions > * { flex: 1 1 0; justify-content: center; padding-inline: .6rem; white-space: nowrap; }
.card-title { display: block; font-weight: 600; font-size: 1.05rem; color: var(--brand-text); margin-bottom: .4rem; }
.card .muted { display: block; margin-top: .4rem; font-size: .85rem; }

/* ---------- Editor / question builder ---------- */
.field-list { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: 1rem; }
.field-item { display: flex; flex-direction: column; gap: .75rem; margin: 0; border-left: 3px solid var(--brand); }
.field-item > label, .field-item .options, .field-item .options > label, .field-settings > label:not(.choice) { display: flex; flex-direction: column; gap: .35rem; }
.field-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; padding-bottom: .6rem; border-bottom: 1px solid var(--border); }
.field-number { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--brand-text); }
.icon-group { display: flex; gap: .35rem; }
.field-settings { display: flex; flex-direction: column; gap: .75rem; }
.field-item .field-error { margin: -.35rem 0 0; }
.editor-form [aria-invalid="true"] { border-color: var(--danger); }
.add-question { width: 100%; background: var(--surface-alt); color: var(--brand-text); border: 1px solid var(--border-strong); }
.add-question:hover { background: var(--brand-soft); border-color: var(--brand-text); }
.form-footer { display: flex; flex-direction: column; gap: .5rem; position: sticky; bottom: 0; padding: .75rem 0; background: linear-gradient(transparent, var(--bg) 25%); }
/* Editor below the desktop width: one column (basics, questions, then the buttons stuck to the
   bottom of the screen). The side wrapper only groups them on desktop. */
.editor-side { display: contents; }
.editor-basics { order: 1; }
.editor-questions { order: 2; }
.editor-side > .form-footer { order: 3; }

/* ---------- Choices (respondent + builder) ---------- */
.choice { display: flex; align-items: center; gap: .75rem; font-weight: 400; cursor: pointer; }
.choices { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; }
.choices .choice { min-height: 48px; padding: .55rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.choices .choice:hover { border-color: var(--border-strong); }
.choices .choice:has(input:checked) { border-color: var(--brand-text); background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
/* Yes / No: two large side-by-side choices, even on phones. */
.choices.yesno { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.choices.yesno .choice { min-height: 56px; justify-content: center; font-size: 1.1rem; font-weight: 500; }
/* Scale (slider): the native range with its ends labelled and the chosen value shown big. Until the
   person moves it, the thumb is faded and the value shows a dash (no answer yet). */
input[type=range] { padding: 0; border: none; background: none; accent-color: var(--brand); cursor: pointer; min-width: 0; }
input[type=range]:focus { outline: none; }
input[type=range]:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 4px; }
input[type=range]:disabled { cursor: default; }
.scale-control { display: grid; grid-template-columns: auto minmax(0, 1fr) auto 3.5rem; align-items: center; gap: .75rem; margin-top: .35rem; }
.scale-range { height: var(--tap); }
.scale-end { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.scale-value { font-size: 1.75rem; font-weight: 600; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; color: var(--brand-text); }
.scale-control.is-unset .scale-value { color: var(--muted); }
.scale-control.is-unset .scale-range { accent-color: var(--border-strong); }
.scale-control.is-unset .scale-range::-webkit-slider-thumb { opacity: .45; }
.scale-control.is-unset .scale-range::-moz-range-thumb { opacity: .45; }
.scale-status { margin: 0; }
.field-item .scale-settings { display: flex; flex-direction: column; gap: .5rem; }
.scale-ends { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.scale-ends > label { display: flex; flex-direction: column; gap: .35rem; }
.scale-track { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .75rem; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.scale-preview { display: flex; flex-direction: column; gap: .2rem; }
fieldset { border: none; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 500; padding: 0; }

/* ---------- Respondent form ---------- */
.intro { border-top: 3px solid var(--accent); }
.intro h1 { margin-top: 0; }
.respondent-form .field { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.respondent-form .field.has-error { border-color: var(--danger); box-shadow: inset 3px 0 0 var(--danger); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); margin: .25rem 0 0; font-weight: 500; font-size: .9rem; display: flex; align-items: center; gap: .35rem; }
.q-number { color: var(--muted); font-variant-numeric: tabular-nums; }
.req { color: var(--danger); }
.result { text-align: center; padding: 2rem 1rem; }
.result-icon { width: 3.5rem; height: 3.5rem; margin: 0 auto 1rem; border-radius: 100px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-text); border: 1px solid currentColor; }
.result-icon.ok { background: var(--ok-soft); color: var(--ok); }
.result-icon .icon { width: 2rem; height: 2rem; }

/* ---------- Survey detail ---------- */
.share h2 .icon { color: var(--brand-text); }
.share-url { font-size: .9rem; margin-bottom: .75rem; background: var(--surface-alt); border-color: var(--border); font-variant-numeric: tabular-nums; }
.hbars { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.hbars li { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; align-items: center; }
.bar-label { grid-column: 1 / -1; overflow-wrap: anywhere; font-size: .9rem; }
.bar-value { font-size: .85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Report-style table: uppercase header on a tinted band, horizontal rules only. */
table { border-collapse: collapse; width: 100%; background: var(--surface); border: 1px solid var(--border); font-size: .9rem; }
th, td { border-bottom: 1px solid var(--border); padding: .55rem .75rem; text-align: left; vertical-align: top; }
th { background: var(--surface-alt); color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; border-bottom: 1px solid var(--border-strong); }
tbody tr:hover { background: var(--surface-alt); }
td { font-variant-numeric: tabular-nums; }
/* Long paragraph answers: cut to 5 lines with an ellipsis; a tap opens the whole text. Looks like
   plain text (it is a button only so keyboards and screen readers can open it too). */
.answer-clamp {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; line-clamp: 5; overflow: hidden;
  min-width: 14rem; max-width: 32rem; min-height: 0; padding: 0; border: 0; background: none;
  color: inherit; font: inherit; font-weight: 400; text-align: left; white-space: pre-line; cursor: zoom-in;
}
.answer-clamp:hover { background: none; border: 0; text-decoration: underline dotted var(--muted); }
.answer-clamp[aria-expanded="true"] { display: block; -webkit-line-clamp: unset; line-clamp: none; overflow: visible; cursor: zoom-out; }
.nowrap { white-space: nowrap; }
.row-actions { width: 1%; }

/* Every answer: "All answers" with the Table / By question switch on the same rule. */
.answers-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .5rem 1rem; margin: 1.75rem 0 .75rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }
.answers-head h3 { margin: 0; padding: 0; border: 0; }
.view-switch { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); }
.view-switch button { min-height: 36px; padding: .3rem .9rem; border: 0; border-radius: 0; background: var(--surface); color: var(--brand-text); font-size: .85rem; }
.view-switch button + button { border-left: 1px solid var(--border-strong); }
.view-switch button:hover { background: var(--brand-soft); }
.view-switch button[aria-pressed="true"] { background: var(--brand-text); color: var(--surface); }

/* Table scroll buttons: hidden on phones (cards, no sideways scroll) and when the table fits. On
   wider screens they stick to the top of the window while the table is in view. */
.table-scrollbar, .table-scroll-hint { display: none; }

/* By question: one question at a time, each answer in its own row. */
.question-picker { display: grid; gap: .35rem; margin-bottom: 1rem; }
.question-picker label { font-weight: 600; font-size: .9rem; }
.picker-row { display: flex; gap: .5rem; align-items: center; }
.picker-row select { flex: 1; min-width: 0; margin: 0; }
.picker-row .icon-button { flex: none; }
.answer-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.answer-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem .75rem; padding: .6rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.answer-value { white-space: pre-line; overflow-wrap: anywhere; }
.answer-value .answer-clamp { min-width: 0; max-width: none; }
.answer-meta { grid-column: 1; margin: 0; display: flex; flex-wrap: wrap; gap: .15rem .9rem; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.answer-name { color: var(--text); font-weight: 500; }
.answer-actions { grid-column: 2; grid-row: 1 / span 2; }
.unanswered { margin: 0 0 .75rem; }

/* Phones: each response row becomes a card, with the column name next to every value. */
@media (max-width: 699px) {
  table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive { background: none; border: none; }
  table.responsive tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .75rem; padding: .5rem .75rem; position: relative; }
  table.responsive td { border: none; padding: .35rem 0; overflow-wrap: anywhere; }
  table.responsive td[data-label]::before { content: attr(data-label); display: block; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
  table.responsive td.row-actions { position: absolute; top: .5rem; right: .5rem; width: auto; padding: 0; }
}

/* ---------- Wider screens ---------- */
@media (min-width: 700px) {
  h1 { font-size: 1.6rem; }
  main { padding: 1.5rem 1.5rem 3rem; }
  .panel { padding: 1.25rem 1.5rem; }
  .button-row > * { flex: 0 0 auto; }
  .button-row > form > button { width: auto; }
  .page-head > .button-row { width: auto; }
  .form-footer { flex-direction: row; }
  .field-settings { flex-direction: row; align-items: flex-end; gap: 1.5rem; }
  .field-settings > label:not(.choice) { flex: 1; }
  .field-settings .switch { min-height: var(--tap); }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .hbars li { grid-template-columns: minmax(8rem, 30%) 1fr auto; }
  .bar-label { grid-column: auto; }
  .table-wrap { overflow-x: auto; }
  /* Answers table scroll bar: under the header row, thick and in the accent color so it is noticed
     at once (the table's own bar is hidden; wheel, touchpad and arrow keys keep working). */
  .table-scroller { position: relative; }
  .table-scroller.has-scrollbar .responses-table thead th { padding-bottom: calc(.55rem + 18px); }
  .table-scroller.has-scrollbar .table-wrap { scrollbar-width: none; }
  .table-scroller.has-scrollbar .table-wrap::-webkit-scrollbar { display: none; }
  .table-scrollbar { display: block; }
  .table-scrollbar[hidden] { display: none; }
  .table-scrollbar { position: absolute; left: 1px; right: 1px; z-index: 2; height: 16px; margin-top: -17px; overflow-x: auto; overflow-y: hidden; background: var(--surface-alt); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  .table-scrollbar-size { height: 1px; }
  .table-scrollbar::-webkit-scrollbar { height: 14px; }
  .table-scrollbar::-webkit-scrollbar-track { background: var(--surface-alt); }
  .table-scrollbar::-webkit-scrollbar-thumb { background: var(--accent); border: 2px solid var(--surface-alt); }
  .table-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--accent-dark); }
  @supports not selector(::-webkit-scrollbar) { .table-scrollbar { scrollbar-color: var(--accent) var(--surface-alt); } }
  .table-scroll-hint { display: flex; align-items: center; gap: .4rem; margin: 0 0 .5rem; font-size: .85rem; font-weight: 600; color: var(--accent); }
  .table-scroll-hint[hidden] { display: none; }
  .table-wrap:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; }
  .hero h1 { font-size: 2.6rem; }
  .hero .button-row { justify-content: center; }
}

/* Optional respondent name: visually separated from the survey questions (tinted, neutral rule). */
.respondent-form .respondent-name { background: var(--surface-alt); box-shadow: inset 3px 0 0 var(--border-strong); }

/* Theme switch in the top bar: shows a moon in light mode and a sun in dark mode. */
.topbar-actions { display: flex; align-items: center; gap: .25rem .75rem; flex-wrap: wrap; }
.theme-toggle { width: var(--tap); height: var(--tap); min-height: var(--tap); padding: 0; background: transparent; border-color: rgba(255, 255, 255, .3); color: var(--on-topbar); }
.theme-toggle:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .7); }
/* Language menu: a native <details>, styled like the theme button, with the list as a floating panel. */
.lang-menu { position: relative; }
.lang-summary { list-style: none; height: var(--tap); padding: 0 .65rem; gap: .35rem; background: transparent; border-color: rgba(255, 255, 255, .3); color: var(--on-topbar); font-size: .8rem; font-weight: 600; letter-spacing: .08em; user-select: none; }
.lang-summary::-webkit-details-marker { display: none; }
.lang-summary:hover, .lang-menu[open] > .lang-summary { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .7); }
.lang-list { position: absolute; right: 0; top: calc(100% + .3rem); z-index: 20; min-width: 10rem; margin: 0; padding: .25rem 0; list-style: none; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 4px 12px var(--shadow); }
.lang-list a { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: var(--tap); padding: 0 .9rem; border-radius: var(--radius); color: var(--text); text-decoration: none; font-size: .95rem; }
.lang-list a:hover, .lang-list a:focus-visible { background: var(--brand-soft); }
.lang-list a[aria-current="true"] { color: var(--brand-text); font-weight: 600; box-shadow: inset 3px 0 0 var(--brand); }
.lang-list a[aria-current="true"]::after { content: "✓"; }
/* Phones: the top bar wraps, so the button can sit at the left edge; open the panel under the whole bar instead. */
@media (max-width: 699px) {
  .topbar-inner { position: relative; }
  .lang-menu { position: static; }
  .lang-list { left: 1rem; right: 1rem; top: calc(100% - .25rem); }
}
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* Closing date line under survey titles. */
.meta { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; }

/* QR code in the share section. The code keeps a white background in both themes so phones can read it. */
.qr-block { display: flex; flex-direction: column; align-items: center; gap: 1rem; margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); text-align: center; }
.qr { width: min(240px, 70vw); background: #fff; padding: .5rem; border-radius: var(--radius); border: 1px solid var(--border); line-height: 0; }
.qr svg { width: 100%; height: auto; }
/* The web client shows the QR code as an image (fetched with the Bearer token); it keeps its square box while loading. */
.qr img { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.qr-help h3 { margin: 0 0 .5rem; padding: 0; border: none; display: flex; align-items: center; justify-content: center; gap: .4rem; }
@media (min-width: 700px) {
  .qr-block { flex-direction: row; align-items: center; text-align: left; }
  .qr { width: 200px; flex: none; }
  .qr-help h3 { justify-content: flex-start; }
}

/* Brief highlight when a live update replaces a section. */
@keyframes live-flash { from { box-shadow: 0 0 0 2px var(--brand-text); } to { box-shadow: 0 0 0 2px transparent; } }
.live-updated { animation: live-flash 1s ease-out; }
@media (prefers-reduced-motion: reduce) { .live-updated { animation: none; } }

/* ---------- Survey state tone ----------
   Content of an open survey (its page, its card) turns the brand accents green: it still accepts
   answers. Closed and expired surveys keep the blue brand. Text pairs are >= 4.5:1 and the bar fill
   passed the dataviz validator (>= 3:1 on the panel) in both themes. Categorical donut colors never
   change: they name answers, not the survey's state. */
.tone-open { --brand: #2f6b45; --brand-dark: #245536; --brand-soft: #e7f0ea; --brand-text: #2f6b45; --bar-fill: #3d8a5a; }
:root[data-theme="dark"] .tone-open { --brand: #3d7a52; --brand-dark: #336846; --brand-soft: #1d2f24; --brand-text: #8cc5a0; --bar-fill: #5aa877; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tone-open { --brand: #3d7a52; --brand-dark: #336846; --brand-soft: #1d2f24; --brand-text: #8cc5a0; --bar-fill: #5aa877; }
}
.survey-card { border-top-color: var(--brand); }

/* ---------- Charts and key figures (survey detail) ----------
   Categorical colors: a muted order checked with the dataviz validator (lightness band, chroma
   floor, colorblind separation, >= 3:1 on the panel surface) for each theme. Never cycled;
   donuts stop at 6 slices. Text never takes a series color: the swatch next to it carries the identity. */
:root {
  --cat-1: #3a6ea5; --cat-2: #c07a3a; --cat-3: #00917a; --cat-4: #a68a1e; --cat-5: #9a5f8f; --cat-6: #5f7f3a;
  --bar-fill: #3a6ea5;
  --chart-track: #e6e9ed;
}
:root[data-theme="dark"] {
  --cat-1: #4f86c0; --cat-2: #c07636; --cat-3: #20a089; --cat-4: #ab8c22; --cat-5: #b56ca9; --cat-6: #7c9a52;
  --bar-fill: #4f86c0;
  --chart-track: #2a323d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cat-1: #4f86c0; --cat-2: #c07636; --cat-3: #20a089; --cat-4: #ab8c22; --cat-5: #b56ca9; --cat-6: #7c9a52;
    --bar-fill: #4f86c0;
    --chart-track: #2a323d;
  }
}
.slice-1 { --slice: var(--cat-1); }
.slice-2 { --slice: var(--cat-2); }
.slice-3 { --slice: var(--cat-3); }
.slice-4 { --slice: var(--cat-4); }
.slice-5 { --slice: var(--cat-5); }
.slice-6 { --slice: var(--cat-6); }

.charts { display: grid; gap: 1rem; }
.charts > .panel { margin: 0; }
.summary > .hint { margin: .75rem 0 0; }

.donut-chart { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; }
.donut { width: 120px; height: 120px; flex: none; }
.donut-track, .donut-slice { fill: none; stroke-width: 6; }
.donut-track { stroke: var(--chart-track); }
.donut-slice { stroke: var(--slice); }
.donut-total { fill: var(--text); font-family: var(--font); font-size: 8px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; flex: 1 1 11rem; min-width: 0; font-size: .9rem; }
.legend li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .6rem; }
.swatch { width: 10px; height: 10px; border-radius: var(--radius); background: var(--slice); }
.legend-label { overflow-wrap: anywhere; }
.legend-value { font-size: .85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.hbar { display: block; width: 100%; height: 12px; }
.hbar-track { fill: var(--chart-track); }
.hbar-fill { fill: var(--bar-fill); }

/* Scale histogram: one column per value on a shared baseline, a 2px gap between columns, the count
   above and the value below. Wide ranges scroll inside the chart, never the page. */
.scale-stats { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin: 0 0 1rem; }
.scale-stats dt { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.scale-stats dd { margin: 0; font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.vbars { list-style: none; padding: 0 0 .25rem; margin: 0; display: flex; gap: 2px; overflow-x: auto; }
.vbars li { flex: 1 1 0; min-width: 1.6rem; display: grid; grid-template-rows: auto 120px auto; justify-items: center; gap: .25rem; }
.vbar { display: block; border-bottom: 1px solid var(--border-strong); overflow: visible; }
.vbar-fill { fill: var(--bar-fill); }
.vbar-count, .vbar-label { font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vbar-count { color: var(--muted); }
.vbar-label { color: var(--text); }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin: 0 0 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: var(--radius); padding: .75rem 1rem; min-width: 0; }
.kpi dt { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.kpi dd { margin: 0; overflow-wrap: anywhere; }
.kpi-value { font-size: 1.35rem; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .8rem; color: var(--muted); }
@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .charts { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
}

/* ---------- Desktop (>= 1100px): wider container and two-column pages ----------
   Phones and tablets keep the single column above; the respondent form stays narrow on purpose. */
@media (min-width: 1100px) {
  main, .topbar-inner { max-width: 1280px; }
  .respondent main:has(> .public-results-view) { max-width: 1280px; }
  main { padding: 2rem 2rem 4rem; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }

  /* Survey detail: results on the left, share and manage in a sticky side column. */
  .detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.5rem; align-items: start; }
  .detail-main { grid-column: 1; grid-row: 1; min-width: 0; }
  .detail-side { grid-column: 2; grid-row: 1; position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
  .detail-side .button-row > * { flex: 1 1 100%; }
  .detail-side .button-row > form > button { width: 100%; }
  .detail-side .qr-block { flex-direction: column; text-align: center; }
  .detail-side .qr { width: 180px; }
  .detail-side .qr-help h3 { justify-content: center; }

  /* Editor: "1. Basic information" on the left with the buttons right below it, "2. Questions" on
     the right. The column follows the scroll as one block, so the buttons never cover the basics. */
  .editor-form { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 1rem 1.5rem; align-items: start; }
  .editor-side { display: flex; flex-direction: column; gap: 1rem; grid-column: 1; grid-row: 1; }
  .editor-basics { margin: 0; }
  .editor-questions { grid-column: 2; grid-row: 1; }
  .editor-side > .form-footer { position: static; flex-direction: column; padding: 0; background: none; }
}
/* Only screens tall enough to show the whole column keep it in view; shorter ones scroll it normally. */
@media (min-width: 1100px) and (min-height: 720px) {
  .editor-side { position: sticky; top: 1rem; }
}

/* ---------- Motion ----------
   Sober and cheap: short fades and small slides with a standard easing, only on transform and
   opacity (plus stroke-dashoffset for the thanks check mark), which the browser animates on the
   compositor without re-layout. No spins, bounces or overshoot. Everything is turned off for
   people who ask for reduced motion (end of this section). */
:root { --ease: cubic-bezier(.2, 0, 0, 1); }
@media (prefers-reduced-motion: no-preference) {
  /* Cross-page fade where supported (View Transitions); the top bar stays put. */
  @view-transition { navigation: auto; }
}
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }
/* Its own layer, so the language panel stays above the animated page content. */
.topbar { view-transition-name: topbar; position: relative; z-index: 10; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes drop { from { opacity: 0; transform: translateY(-4px); } }
@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Page content enters in a short cascade. */
main > * { animation: rise .22s var(--ease) both; }
main > :nth-child(2) { animation-delay: .03s; }
main > :nth-child(3) { animation-delay: .06s; }
main > :nth-child(n+4) { animation-delay: .09s; }
.flash { animation: drop .2s var(--ease) both; }

/* Cards, key figures and charts: a light staggered fade. */
.cards > li, .kpi, .charts > .panel { animation: rise .22s var(--ease) both; }
.cards > li:nth-child(2), .kpi:nth-child(2), .charts > :nth-child(2) { animation-delay: .03s; }
.cards > li:nth-child(3), .kpi:nth-child(3), .charts > :nth-child(3) { animation-delay: .06s; }
.cards > li:nth-child(n+4), .kpi:nth-child(n+4), .charts > :nth-child(n+4) { animation-delay: .09s; }
.donut { animation: fade .25s var(--ease) .05s both; }
.hbar-fill { transform-box: fill-box; transform-origin: left center; animation: grow-x .25s var(--ease) .05s both; }
.vbar-fill { animation: fade .25s var(--ease) .05s both; }

/* A live update swaps fresh HTML in: no entrance cascade there, only the highlight ring. */
.live-updated * { animation: none; }

/* Hover feedback: color only. */
button, .button { transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.choices .choice { transition: border-color .15s ease, background-color .15s ease; }

/* Menus and the theme switch. */
.lang-menu[open] > .lang-list { animation: drop .15s var(--ease); }
.theme-toggle .icon { animation: fade .15s ease-out; }

/* Short color fade on the main surfaces when the theme changes (not on every element). */
body, .topbar, .panel, .card, .kpi, .empty, input, select, textarea {
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.card-link { transition: box-shadow .15s ease, border-color .15s ease, background-color .2s ease; }

/* Thanks page: the box fades in and the check mark draws itself. */
.result-icon.ok { animation: fade .2s var(--ease) both; }
.result-icon.ok .icon path { stroke-dasharray: 22; stroke-dashoffset: 22; animation: draw .3s ease-out .15s forwards; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
