/* =============================================================================
   EV Delay – forms (zglos.html, newsletter.html).
   Sections 1–3 and the component rules marked [tokens.css] are copied verbatim from
   web/evdelay-design/tokens.css (spec: web/evdelay-design/DESIGN.md); the rest is form-specific.
   No external requests except the Turnstile widget script loaded by forms-common.js.
   ============================================================================= */

/* ---------- 1. Tokens: light (default) ---------- */
:root {
  color-scheme: light;

  /* planes & ink */
  --page: #f9f9f7;          /* page plane */
  --surface: #fcfcfb;       /* cards, chart surface (validator surface) */
  --surface-2: #f2f1ed;     /* inset fills: segmented control track, code */
  --ink: #0b0b0b;           /* primary text, hero numbers           19.2:1 */
  --ink-2: #52514e;         /* secondary text, labels                7.7:1 */
  --ink-3: #6b6a65;         /* hints, captions (AA small text)       5.3:1 */
  --muted: #898781;         /* axis ticks only (graphical text)      3.5:1 */
  --grid: #e1e0d9;          /* gridlines, row rules (hairline) */
  --axis: #c3c2b7;          /* baseline, table header rule */
  --ring: rgba(11, 11, 11, 0.10);        /* hairline card ring */
  --ring-strong: rgba(11, 11, 11, 0.28); /* chip / input ring on hover */
  --wash: rgba(11, 11, 11, 0.045);       /* hover wash */
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.12);
  --scroll-shade: rgba(11, 11, 11, 0.16);  /* edge shade of horizontally scrollable areas */
  --tap: 44px;                             /* minimum touch target */

  /* categorical – fixed order, never cycled (slot n = --s<n>) */
  --s1: #2a78d6;  /* blue    */
  --s2: #eb6834;  /* orange  */
  --s3: #1baf7a;  /* aqua    */
  --s4: #eda100;  /* yellow  */
  --s5: #e87ba4;  /* magenta */
  --s6: #008300;  /* green   */
  --s7: #6250d6;  /* violet  */
  --s8: #e34948;  /* red     */
  --s-other: #c3c2b7;       /* folded "Other" – always labelled */
  --mark-neutral: #6b6a65;  /* single non-model measure (e.g. data lag) */

  /* entity → slot (colour follows the entity, never its rank) */
  --m-ex60: var(--s1);
  --m-ix3:  var(--s2);
  --m-glc:  var(--s3);
  --c-pl: var(--s1); --c-nl: var(--s2); --c-es: var(--s3); --c-fi: var(--s4);
  --c-ee: var(--s5); --c-il: var(--s6); --c-de: var(--s7); --c-se: var(--s8);
  --v-1: var(--s1); --v-2: var(--s2); --v-3: var(--s3); /* versions in model order */

  /* delay scale 0–4 – ordinal plum ramp (OKLCH h≈328°, C 0.10), light → dark */
  --lvl-0: #d197ce; --lvl-1: #aa73a8; --lvl-2: #855083; --lvl-3: #612f60; --lvl-4: #3b1b3a;
  --lvl-0-on: #0b0b0b; --lvl-1-on: #0b0b0b; --lvl-2-on: #ffffff; --lvl-3-on: #ffffff; --lvl-4-on: #ffffff;

  /* status – fixed, never themed; always icon + label */
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;

  /* type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 12px; --fs-s: 13px; --fs-m: 15px; --fs-l: 17px;
  --fs-h3: 15px; --fs-h2: 20px; --fs-h1: 28px;
  --fs-tile: 26px; --fs-hero: clamp(48px, 12vw, 76px);
  --lh: 1.5;

  /* space, radius, layout */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --r-s: 6px; --r-m: 10px; --r-l: 14px; --r-pill: 999px;
  --wrap: 1120px; --gutter: 16px; --pad: 16px;
}
@media (min-width: 720px) { :root { --pad: 24px; --fs-h1: 32px; } }

/* ---------- 2. Tokens: dark (selected steps, not an automatic flip) ---------- */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422;
    --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #a3a29b; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10); --ring-strong: rgba(255, 255, 255, 0.30); --wash: rgba(255, 255, 255, 0.06);
    --shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.5); --scroll-shade: rgba(255, 255, 255, 0.14);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --s-other: #5f5e59; --mark-neutral: #a3a29b;
    --lvl-0: #723f71; --lvl-1: #945e92; --lvl-2: #b77fb4; --lvl-3: #dba1d8; --lvl-4: #f5cbf3;
    --lvl-0-on: #ffffff; --lvl-1-on: #ffffff; --lvl-2-on: #0b0b0b; --lvl-3-on: #0b0b0b; --lvl-4-on: #0b0b0b;
    --good-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422;
  --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #a3a29b; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10); --ring-strong: rgba(255, 255, 255, 0.30); --wash: rgba(255, 255, 255, 0.06);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.5); --scroll-shade: rgba(255, 255, 255, 0.14);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --s-other: #5f5e59; --mark-neutral: #a3a29b;
  --lvl-0: #723f71; --lvl-1: #945e92; --lvl-2: #b77fb4; --lvl-3: #dba1d8; --lvl-4: #f5cbf3;
  --lvl-0-on: #ffffff; --lvl-1-on: #ffffff; --lvl-2-on: #0b0b0b; --lvl-3-on: #0b0b0b; --lvl-4-on: #0b0b0b;
  --good-text: #0ca30c;
}

/* ---------- 3. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 120px; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: var(--fs-m)/var(--lh) var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, dl, dd, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- [tokens.css] wrap, header, segmented control, page head, card, rows, empty, buttons, footer ---------- */
.wrap {
  max-width: var(--wrap); margin: 0 auto;
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
}
.ext::after { content: " ↗"; font-size: 0.85em; }
.site { background: var(--page); padding-top: env(safe-area-inset-top); }
.site-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); height: 56px; }
.brand { font-weight: 680; font-size: 17px; letter-spacing: -0.02em; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--ink-3); font-weight: 500; }
.site-tools { display: flex; align-items: center; gap: var(--sp-2); }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: var(--r-m);
  border: 1px solid var(--ring); background: var(--surface); color: var(--ink-2); cursor: pointer; font: inherit;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ring-strong); }
.icon-btn svg { width: 16px; height: 16px; }
.seg { display: inline-flex; flex: none; background: var(--surface-2); border-radius: var(--r-m); padding: 3px; gap: 2px; }
.seg button, .seg a {
  font: inherit; font-size: var(--fs-s); font-weight: 520; color: var(--ink-2); background: none; border: 0;
  border-radius: 7px; padding: 4px 11px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg [aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring), 0 1px 2px rgba(0,0,0,.06); }
.seg [aria-disabled="true"] { color: var(--muted); cursor: not-allowed; }
.page-head { padding-top: var(--sp-5); padding-bottom: var(--sp-4); }
.eyebrow { font-size: var(--fs-s); color: var(--ink-3); font-weight: 500; letter-spacing: 0.01em; }
.page-head h1 { font-size: var(--fs-h1); font-weight: 680; letter-spacing: -0.025em; line-height: 1.15; }
.lede { color: var(--ink-2); max-width: 640px; margin-top: var(--sp-2); }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: var(--r-l); padding: var(--sp-4); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-2) var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.card-head h3 { font-size: var(--fs-h3); font-weight: 620; line-height: 1.35; }
.card-head .hint, .hint { font-size: var(--fs-s); color: var(--ink-3); }
.rows > li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--grid); font-size: 14px; align-items: baseline; }
.rows > li:first-child { border-top: 0; padding-top: 2px; }
.rows .main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.rows .when { color: var(--ink-3); font-size: var(--fs-s); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.rows .meta { grid-column: 1 / -1; color: var(--ink-3); font-size: var(--fs-s); }
.empty { display: grid; justify-items: start; gap: 6px; padding: var(--sp-5) var(--sp-4); border-radius: var(--r-m); background: repeating-linear-gradient(0deg, transparent 0 100%); box-shadow: inset 0 0 0 1px var(--grid); }
.empty .t1 { font-weight: 600; font-size: 14px; }
.empty .t2 { color: var(--ink-3); font-size: var(--fs-s); max-width: 520px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: var(--r-m);
  border: 1px solid var(--ring); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-s); font-weight: 520;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ring-strong); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.input {
  height: 34px; padding: 0 12px; border-radius: var(--r-m); border: 1px solid var(--ring); background: var(--surface);
  color: var(--ink); font: inherit; font-size: 14px; min-width: 0; flex: 1 1 220px; max-width: 360px;
}
.input::placeholder { color: var(--ink-3); }
/* ---------- 18. Footer ---------- */
.site-foot { margin-top: var(--sp-8); padding: var(--sp-6) 0 calc(var(--sp-7) + env(safe-area-inset-bottom)); border-top: 1px solid var(--grid); font-size: var(--fs-s); color: var(--ink-2); }
.site-foot .cols { display: grid; gap: var(--sp-5); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) { .site-foot .cols { grid-template-columns: 2fr 1fr 1fr; } }
.site-foot h4 { font-size: 14px; color: var(--ink); margin-bottom: 6px; }
.site-foot p + p { margin-top: 8px; }
.site-foot li { padding: 2px 0; }

/* ---------- [tokens.css] touch targets, motion, forced colours ---------- */
@media (max-width: 719px), (pointer: coarse) {
  .btn, .icon-btn, .input { min-height: var(--tap); height: auto; }
  .seg button, .seg a { position: relative; min-height: 38px; padding: 0 12px; display: inline-flex; align-items: center; }
  .seg button::after, .seg a::after { content: ""; position: absolute; inset: -3px 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* ============================================================ form-specific */
:root { --err: #b3261e; --ok-bg: rgba(12, 163, 12, 0.08); --input-h: 46px; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) { --err: #ff8a80; --ok-bg: rgba(12, 163, 12, 0.14); } }
:root[data-theme="dark"] { --err: #ff8a80; --ok-bg: rgba(12, 163, 12, 0.14); }

.form-page { max-width: 640px; }
.site-bar .seg a[aria-current="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring), 0 1px 2px rgba(0,0,0,.06); }
.form-page .page-head h1 { font-size: 26px; }
@media (min-width: 720px) { .form-page .page-head h1 { font-size: var(--fs-h1); } }

form.card, .card.panel { padding: var(--sp-5) var(--sp-4); }
@media (min-width: 480px) { form.card, .card.panel { padding: var(--sp-5); } }
.card + .card, .card + .empty, .empty + .card { margin-top: var(--sp-4); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.group { margin-top: var(--sp-6); padding-top: var(--sp-5); border-top: 1px solid var(--grid); }
form > .group:first-of-type, #edit-head + .group { margin-top: 0; padding-top: 0; border-top: 0; }
/* float the legend so it sits inside the fieldset like a heading (no border cut-through) */
.group > legend { float: left; width: 100%; }
.group > legend + * { clear: both; }
.group > legend, .group-title { font-size: var(--fs-h3); font-weight: 650; padding: 0; margin-bottom: var(--sp-4); }
#edit-head { margin-bottom: var(--sp-5); }

.field { display: grid; gap: 6px; margin-bottom: var(--sp-5); min-width: 0; }
.field:last-child { margin-bottom: 0; }
.lbl { font-weight: 580; font-size: var(--fs-m); line-height: 1.35; }
.lbl .opt-tag { font-weight: 450; color: var(--ink-3); font-size: var(--fs-s); margin-left: 4px; }
.help { font-size: var(--fs-s); color: var(--ink-3); line-height: 1.45; }
.err { font-size: var(--fs-s); color: var(--err); font-weight: 520; }
.err:empty { display: none; }
.field.invalid .input, .field.invalid select.input { border-color: var(--err); box-shadow: 0 0 0 1px var(--err); }

/* inputs: full width, 16 px text (no iOS zoom on focus), 46 px tall */
.form-page .input, .form-page select.input, .form-page textarea.input {
  width: 100%; max-width: none; flex: none; height: var(--input-h); min-height: var(--input-h); font-size: 16px; padding: 0 12px;
}
.form-page textarea.input { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.45; resize: vertical; }
.form-page select.input {
  appearance: none; -webkit-appearance: none; padding-right: 36px; background-repeat: no-repeat; background-position: right 12px center; background-size: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b6a65' stroke-width='1.6'/%3E%3C/svg%3E");
}
.form-page input[type="date"].input { appearance: none; -webkit-appearance: none; display: flex; align-items: center; }
.form-page input[type="date"].input::-webkit-date-and-time-value { text-align: left; }
.input:focus-visible, select.input:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-2); }
.row2.w-13 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }

/* option chips (radio / checkbox) – same look as .chip in the app; checked = inverted */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--ring); border-radius: var(--r-pill); background: var(--surface); font-size: 14px; font-weight: 520;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.opt:hover { border-color: var(--ring-strong); }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.opt:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.opt:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.opt:has(input:disabled) { cursor: not-allowed; opacity: .55; }
.opt .key { width: 8px; height: 8px; border-radius: 50%; background: var(--k); flex: none; }
.opt .sub { color: var(--ink-3); font-weight: 450; font-size: var(--fs-s); }
.opt:has(input:checked) .sub { color: color-mix(in srgb, var(--surface) 72%, transparent); }
.opts.wide .opt { flex: 1 1 calc(50% - 4px); justify-content: center; }
@media (min-width: 480px) { .opts.wide .opt { flex: 0 1 auto; } }

/* checkbox rows (consent, frequency, alerts) */
.check { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; align-items: start; padding: 8px 0; cursor: pointer; min-height: var(--tap); }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--ink); cursor: pointer; }
.check .t { font-size: var(--fs-m); line-height: 1.45; }
.check .t small { display: block; color: var(--ink-3); font-size: var(--fs-s); margin-top: 2px; }
.checks { display: grid; gap: 0; }

/* fuzzy date: precision switch + inputs */
.fuzzy { display: grid; gap: 8px; }
.fuzzy .seg { justify-self: start; }
.fuzzy .wk-range { font-size: var(--fs-s); color: var(--ink-3); }

/* buttons */
.actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin-top: var(--sp-5); }
.form-page .btn { height: var(--tap); min-height: var(--tap); font-size: 15px; padding: 0 18px; }
.form-page .btn.primary { font-weight: 620; }
.btn.block { width: 100%; justify-content: center; }
@media (min-width: 480px) { .btn.block { width: auto; } }
.btn.danger { color: var(--err); }
.btn[disabled] { opacity: .55; cursor: progress; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px; cursor: pointer; }

/* disclosure */
.more { margin-top: var(--sp-5); border-top: 1px solid var(--grid); padding-top: var(--sp-2); }
.more > summary { list-style: none; cursor: pointer; min-height: var(--tap); display: flex; align-items: center; gap: 8px; font-weight: 580; }
.more > summary::-webkit-details-marker { display: none; }
.more > summary::before { content: "+"; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--surface-2); font-weight: 600; }
.more[open] > summary::before { content: "−"; }
.more > .inner { padding-top: var(--sp-3); }

/* notices */
.notice { border-radius: var(--r-m); padding: 12px 14px; font-size: 14px; line-height: 1.45; background: var(--surface-2); color: var(--ink-2); }
.notice.ok { background: var(--ok-bg); color: var(--ink); }
.notice.bad { background: color-mix(in srgb, var(--err) 10%, transparent); color: var(--ink); }
.notice b { color: var(--ink); }
.form-msg:empty { display: none; }
.form-msg { margin-top: var(--sp-4); }
.copyrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: var(--sp-3); }
.copyrow .input { font-size: 14px !important; font-family: var(--mono); }
.kv-list { display: grid; gap: 4px; font-size: 14px; margin-top: var(--sp-3); }
.kv-list div { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--grid); padding-top: 6px; }
.kv-list dt { color: var(--ink-3); }
.kv-list dd { text-align: right; font-variant-numeric: tabular-nums; }
.turnstile-box { margin-top: var(--sp-4); }
.turnstile-box:empty { display: none; }
.badge { display: inline-block; font-size: var(--fs-xs); font-weight: 600; padding: 2px 8px; border-radius: var(--r-s); background: var(--surface-2); color: var(--ink-2); }
.privacy { font-size: var(--fs-s); color: var(--ink-3); line-height: 1.5; }
.privacy p + p { margin-top: 6px; }
.center-load { padding: var(--sp-6) 0; color: var(--ink-3); font-size: 14px; }
[hidden] { display: none !important; }
.rows .meta.change { color: var(--ink); font-size: 14px; }
