/* VALVIA-RESEARCH license portal. Grounds, lines and text come from the Microscape / Cardioscape
   design system; the accent is the VALVIA Research blue of the desktop app (its Variable.uss:
   --accent, --accent-2, --accent-ink), which replaced the Valvia red and orange. See
   docs/dev-notes/portal-design.md. Dark is the default; light follows the OS. The amber
   research-use legend (L1, #FAB219, as in the desktop app) sits beside the logo and in the footer
   of every page. Fonts are the system's own: the portal loads nothing from other sites (Privacy
   Policy, Section 5). */

:root {
  color-scheme: dark;
  --ground: #09080a;
  --chrome: #0c0a0e;
  --well: #0e0c11;
  --surface: #131116;
  --raised: #1b181f;
  --line: #332e39;
  --line-strong: #453f4d;
  --accent: #1a8cff;
  --accent-hi: #4dabff;
  --accent-ink: #04111f;
  --accent-text: #5cb8ff;
  --tint-accent: rgba(26, 140, 255, 0.14);
  --check-fill: #0848aa;
  --red-deep: #4e0a12;
  --red-text: #e79aa2;
  --green-text: #8fd19e;
  --green-line: #3b7a4a;
  --text: #eceef2;
  --gray: #cfd3d9;
  --dim: #a0a6b1;
  --label: #959ba7;
  --faint: #848a96;
  --ghost: #4a4552;
  --tint-red: #1a0b0e;
  --tint-green: #0b1a10;
  --tint-amber: #201305;
  --tint-amber-line: #3a2208;
  --amber: #fab219;
  --amber-text: #fab219;
  --amber-ink: #1a1200;
  --veil: rgba(12, 10, 14, 0.86);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  --font-display: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo, Consolas, monospace;
  --fs-micro: 11px;
  --fs-small: 12px;
  --fs-body: 14px;
  --fs-lead: 16px;
  --fs-h2: 18px;
  --fs-h1: 28px;
  --track-micro: 0.14em;
  --r-chip: 3px;
  --r-control: 5px;
  --r-panel: 8px;
  --gutter: max(28px, env(safe-area-inset-left, 0px));
  --gutter-r: max(28px, env(safe-area-inset-right, 0px));
  --maxw: 1080px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --ground: #f4f2f5;
    --chrome: #ffffff;
    --well: #ffffff;
    --surface: #ffffff;
    --raised: #f7f5f8;
    --line: #dcd7e0;
    --line-strong: #c4bdc9;
    --accent: #0a6cf0;
    --accent-hi: #0852c8;
    --accent-ink: #ffffff;
    --accent-text: #0852c8;
    --tint-accent: rgba(10, 108, 240, 0.08);
    --check-fill: #0a6cf0;
    --red-text: #8f0f1c;
    --green-text: #1f6b35;
    --green-line: #7fc08f;
    --text: #17141a;
    --gray: #2d2933;
    --dim: #5a5562;
    --label: #6b6672;
    --faint: #7d7884;
    --ghost: #cbc5d0;
    --tint-red: #fbe9ea;
    --tint-green: #e7f5ea;
    --tint-amber: #fff4d6;
    --tint-amber-line: #f0d08a;
    --amber-text: #8a5a00;
    --veil: rgba(244, 242, 245, 0.9);
    --shadow: 0 18px 40px rgba(20, 10, 30, 0.14);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--gray);
  font: var(--fs-body)/1.55 var(--font-body);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hi); text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-display); color: var(--text); margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: var(--fs-h1); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-h2); font-weight: 600; }
h3, .label {
  font: 600 var(--fs-micro)/1.4 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--label);
}
p { margin: 0 0 12px; }
code, .mono { font-family: var(--font-mono); }
.muted { color: var(--dim); }
.small { font-size: var(--fs-small); }
.lead { font-size: var(--fs-lead); color: var(--gray); }

/* ------------------------------------------------------------------------- top bar */
/* Raised strip so it reads as chrome, not page. Wordmark, then the menu, then the session
   cluster (email bubble + Sign out, or Sign in + Create account) pushed right. */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 60px;
  padding: 0 var(--gutter-r) 0 var(--gutter);
  background: var(--raised);
  border-bottom: 1px solid var(--line-strong);
}
.topbar .brand { display: flex; align-items: center; color: var(--text); }
.topbar .brand img { height: 40px; width: auto; display: block; }
.topbar .ru-badge { margin-left: 12px; padding: 2px 8px; border: 1px solid var(--tint-amber-line); border-radius: var(--r-chip); background: var(--tint-amber); color: var(--amber-text); font: 600 var(--fs-micro)/1.6 var(--font-mono); letter-spacing: 0.04em; white-space: nowrap; }
@media (max-width: 720px) { .topbar .ru-badge { display: none; } }
.topbar .menu { display: flex; gap: 4px; align-items: stretch; align-self: stretch; }
/* Every link carries the same padding and a transparent bottom bar so the active one does
   not change height and shift the row. */
.topbar .menu a {
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--gray);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  border-top: 2px solid transparent;
}
.topbar .menu a:hover { color: var(--text); text-decoration: none; background: var(--surface); }
.topbar .menu a.active { color: var(--text); border-bottom-color: var(--accent); }
.topbar .session { display: flex; gap: 12px; align-items: center; margin-left: auto; }
.topbar .session > a:not(.btn) { color: var(--gray); }
.topbar .session > a.active { color: var(--text); }
.topbar .who {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--well);
  color: var(--dim);
  font: 400 var(--fs-small)/1.5 var(--font-mono);
}

/* ------------------------------------------------------------------------- layout */
main.page {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px var(--gutter-r) 48px var(--gutter);
  flex: 1;
}
main.page.narrow { max-width: 460px; }
main.page.wide { max-width: var(--maxw); }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

footer {
  border-top: 1px solid var(--line);
  padding: 18px var(--gutter-r) 24px var(--gutter);
  color: var(--dim);
  font-size: var(--fs-small);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: space-between;
}
footer .ru { color: var(--amber); font-family: var(--font-mono); }

/* ------------------------------------------------------------------------- panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 20px 22px;
}
.panel > h2 { margin-bottom: 12px; }
.panel.highlight { border-color: var(--accent); background: var(--tint-accent); }
.hero { padding: 40px 0 24px; }
.hero h1 { font-size: 36px; }
.hero .lead { max-width: 640px; }

/* -------------------------------------------------------------------------- forms */
form.stack label { display: block; }
.field { display: block; margin-bottom: 14px; }
/* Author display rules (.field etc.) would otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }
.field > span { display: block; margin-bottom: 5px; }
.field > span.label { margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%;
  background: var(--well);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  padding: 9px 11px;
  font: inherit;
  font-size: 16px;
}
@media (min-width: 640px) {
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="search"], select, textarea { font-size: var(--fs-body); }
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); vertical-align: -3px; margin-right: 8px; }
.check { display: flex; gap: 0; align-items: flex-start; margin-bottom: 12px; color: var(--gray); }
.check input { flex: none; margin-top: 3px; }
.hint { color: var(--dim); font-size: var(--fs-small); margin-top: 4px; }

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--r-control);
  border: 1px solid var(--line-strong);
  background: var(--line);
  color: var(--text);
  font: 600 var(--fs-body) var(--font-body);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn svg { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button:hover, .btn:hover { background: var(--line-strong); border-color: var(--faint); text-decoration: none; color: var(--text); }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover, button.primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); color: var(--accent-ink); }
.btn.quiet, button.quiet { background: transparent; border-color: transparent; color: var(--accent); padding: 6px 8px; }
.btn.quiet:hover, button.quiet:hover { color: var(--accent-hi); text-decoration: underline; }
.btn.small, button.small { padding: 5px 10px; font-size: var(--fs-small); }
.btn.danger, button.danger { color: var(--red-text); border-color: var(--red-deep); background: var(--tint-red); }
.btn.block, button.block { width: 100%; justify-content: center; }
button[disabled] { opacity: 0.5; cursor: default; }
form.inline { display: inline; }

/* --------------------------------------------------------------------- messages */
.flash, .errors {
  border-radius: var(--r-control);
  padding: 10px 14px;
  margin-bottom: 18px;
  border: 1px solid;
}
.flash.ok { background: var(--tint-green); border-color: var(--green-line); color: var(--green-text); }
.flash.warn, .errors { background: var(--tint-amber); border-color: var(--tint-amber-line); color: var(--text); }
.errors ul { margin: 0; padding-left: 18px; }
.flash[data-flash] { display: flex; align-items: flex-start; gap: 12px; transition: opacity 0.2s; }
.flash[data-flash] > span { flex: 1; }
.flash[data-flash].closing { opacity: 0; }
button.flash-close {
  background: transparent;
  border: 0;
  padding: 0 2px;
  font-size: 1.25em;
  line-height: 1;
  color: inherit;
  opacity: 0.6;
}
button.flash-close:hover { background: transparent; opacity: 1; }

/* ------------------------------------------------------------------------ pills */
.pill {
  display: inline-block;
  font: 600 var(--fs-micro)/1.2 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: var(--r-chip);
  border: 1px solid var(--line-strong);
  color: var(--dim);
  background: var(--raised);
  white-space: nowrap;
}
.pill.active { color: var(--green-text); border-color: var(--green-line); background: var(--tint-green); }
.pill.unused { color: var(--amber-text); border-color: var(--tint-amber-line); background: var(--tint-amber); }
.pill.expired, .pill.lapsed { color: var(--red-text); border-color: var(--red-deep); background: var(--tint-red); }
.pill.revoked { color: var(--faint); border-color: var(--line); background: transparent; text-decoration: line-through; }
.pill.trial { color: var(--amber-text); border-color: var(--tint-amber-line); background: var(--tint-amber); }
.pill.paid { color: var(--green-text); border-color: var(--green-line); background: var(--tint-green); }
.pill.service { color: var(--gray); }
.pill.fulfilled { color: var(--green-text); border-color: var(--green-line); }
.pill.pending, .pill.paid-status { color: var(--amber-text); }
.pill.refunded { color: var(--red-text); }
.pill.closed { color: var(--faint); }

/* ------------------------------------------------------------------------ tables */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font: 600 var(--fs-micro)/1.4 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--label);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table td.nowrap { white-space: nowrap; }
/* Cells holding unbroken tokens (emails, provider refs, keys, IPs): let them break anywhere so
   they don't set the column's minimum width and push the table out of its panel. */
.table td.long { overflow-wrap: anywhere; min-width: 14ch; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions form { display: inline; }
.table td.actions > * + * { margin-left: 6px; }
.table .code { font-family: var(--font-mono); color: var(--text); letter-spacing: 0.04em; }
.table .code-cell { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; white-space: nowrap; }
.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  background: var(--well);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
}
.code-chip .code { font-weight: 600; }
.code-chip .code-mask .dots { color: var(--faint); letter-spacing: 0.12em; margin-right: 0.5ch; }
.icon-btn {
  padding: 4px;
  background: transparent;
  border-color: transparent;
  color: var(--faint);
}
.icon-btn:hover { background: var(--raised); border-color: transparent; color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-expanded="true"] { color: var(--accent); }
.table .action-stack { display: inline-flex; flex-direction: column; align-items: stretch; gap: 6px; }
.table td .action-stack form { display: flex; gap: 6px; }
.table .action-stack input { flex: none; }
.table .action-stack input[type="number"] + button { width: auto; flex: 1; }
.table a.code { white-space: nowrap; }
.table .action-stack .btn, .table .action-stack button { width: 100%; justify-content: center; }
.table .mono { color: var(--dim); font-size: var(--fs-small); }
.table .detail { color: var(--dim); font-size: var(--fs-small); margin-top: 4px; white-space: nowrap; }
.table td.status .detail { white-space: normal; min-width: 16ch; }
.table-wrap { overflow-x: auto; }

/* ----------------------------------------------------------------- licence card */
.code-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--well);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-control);
  padding: 10px 12px;
  font: 600 var(--fs-lead) var(--font-mono);
  color: var(--text);
  letter-spacing: 0.06em;
  word-break: break-all;
}
.code-box.big { font-size: 22px; justify-content: center; padding: 18px; }
.copy {
  font: 600 var(--fs-micro)/1.2 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: var(--r-chip);
}
.kv { display: grid; grid-template-columns: max-content 1fr; margin: 0; }
.kv dt, .kv dd { padding: 7px 0; border-bottom: 1px solid var(--line); }
.kv dt { padding-right: 20px; }
.kv dt:nth-last-of-type(1), .kv dd:last-of-type { border-bottom: none; }
.kv dt { color: var(--label); font: 600 var(--fs-micro)/1.9 var(--font-mono); text-transform: uppercase; letter-spacing: var(--track-micro); }
.kv dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.hash { display: block; font-size: var(--fs-micro); line-height: 1.5; color: var(--dim); word-break: break-all; }
.download-cta { margin-top: 16px; }
.download-cta .hint { margin-top: 8px; }
.steps { margin: 0 0 14px; padding-left: 22px; }
.steps li { margin-bottom: 8px; }
.steps li::marker { color: var(--accent); font-weight: 600; }

/* --------------------------------------------------------------------- stepper */
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input[type="number"] { width: 80px; text-align: center; }
.total { font: 600 var(--fs-h1) var(--font-display); color: var(--text); }
.choice { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.choice label {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--raised);
}
.choice label:has(input:checked) { border-color: var(--accent); background: var(--tint-accent); color: var(--accent-text); }
.choice input[type="radio"] { accent-color: var(--accent); margin-right: 8px; }

/* ------------------------------------------------------------------------ admin */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--dim); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"] { max-width: 360px; }
details.inline-form { border: 1px solid var(--line); border-radius: var(--r-control); padding: 10px 14px; margin-bottom: 16px; background: var(--surface); }
details.inline-form summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.inline-form form { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
details.inline-form form .field { margin: 0; flex: 1 1 180px; }
/* Button keeps its own width; line-height matches the inputs so the bottoms and tops line up. */
details.inline-form form button { flex: none; line-height: 1.55; }
.events { list-style: none; margin: 0; padding: 0; }
.events li { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: var(--fs-small); overflow-wrap: anywhere; }
.events .when { color: var(--faint); font-family: var(--font-mono); margin-right: 8px; }

/* ------------------------------------------------------------------------ legal */
.prose { max-width: 760px; }
.prose h2 { margin-top: 28px; }
.prose li { margin-bottom: 4px; }
.prose table { border-collapse: collapse; }
.prose td, .prose th { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }

/* ----------------------------------------------------------------------- phones */
@media (max-width: 640px) {
  :root { --gutter: max(16px, env(safe-area-inset-left, 0px)); --gutter-r: max(16px, env(safe-area-inset-right, 0px)); }
  main.page { padding-top: 18px; }
  .hero { padding-top: 16px; }
  .hero h1 { font-size: 28px; }
  .topbar { gap: 14px; min-height: 52px; }
  .topbar .brand img { height: 24px; }
  .topbar .menu a { padding: 0 8px; }
  .topbar .who { display: none; }
  .choice { grid-template-columns: 1fr; }
  .table thead { display: none; }
  .table tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table td { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 4px 10px; border: none; padding: 4px 0; }  .table td > * { grid-column: 2; justify-self: start; }
  .table td.nowrap, .table a.code { white-space: normal; }
  .table .action-stack { flex-direction: row; flex-wrap: wrap; }
  .table .action-stack .btn, .table .action-stack button { width: auto; }
  .table td::before { content: attr(data-label); font: 600 var(--fs-micro)/1.6 var(--font-mono); text-transform: uppercase; letter-spacing: var(--track-micro); color: var(--label); }
  .table td.actions { display: flex; justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
  .table td.actions > * + * { margin-left: 0; }
  .table .detail { white-space: normal; }
  .table td.actions::before { display: none; }
  .row.end button, .row.end .btn { flex: 1 1 auto; justify-content: center; }
}

/* ----------------------------------------------------------------- payment receipt */
main.page.narrow:has(.receipt) { max-width: 640px; }
.receipt {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 26px 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.receipt-head h1 { margin: 6px 0 8px; }
.receipt-head .lead { margin: 0; }
.receipt-head .lead + p { margin: 10px 0 0; }
.status-label {
  display: inline-block;
  font: 600 var(--fs-micro)/1.2 var(--font-mono);
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: var(--r-chip);
  border: 1px solid var(--line-strong);
  color: var(--dim);
}
.status-label.ok { color: var(--green-text); border-color: var(--green-line); background: var(--tint-green); }
.status-label.warn { color: var(--amber-text); border-color: var(--tint-amber-line); background: var(--tint-amber); }
.status-label.wait { color: var(--amber-text); border-color: var(--tint-amber-line); background: var(--tint-amber); }
.code-hero {
  background: var(--well);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-panel);
  padding: 20px 28px 18px;
  text-align: center;
}
.code-hero > .label { display: block; margin-bottom: 10px; }
.code-hero .hint { margin: 12px 0 0; }
.code-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.code-text {
  font: 600 clamp(14px, 3.6vw, 21px)/1.3 var(--font-mono);
  color: var(--text);
  letter-spacing: 0.05em;
  white-space: nowrap;
  user-select: all;
  padding: 6px 4px;
}
.copy-btn { flex: none; min-width: 84px; justify-content: center; }
.copy-btn.copied { color: var(--green-text); border-color: var(--green-line); background: var(--tint-green); }
.steps { margin: 0; padding-left: 22px; color: var(--gray); }
.steps li { margin-bottom: 8px; }
.steps li::marker { color: var(--accent-text); font-weight: 600; }
.receipt-details { border-top: 1px solid var(--line); padding-top: 8px; }
@media (max-width: 480px) {
  .receipt { padding: 20px 16px 18px; }
  .code-line { flex-direction: column; align-items: stretch; gap: 10px; }
  .copy-btn { width: 100%; }
}

/* L2 above the price table on the Buy page (Product Notices and Labels, Section 2). */
.notice-l2 { margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--tint-amber-line); border-radius: var(--r-panel); background: var(--tint-amber); color: var(--amber-text); font-size: var(--fs-small); line-height: 1.5; }

/* ------------------------------------------------------ research access application */
/* Laid out like a case report form. Each section is a panel and each question a ruled row.
   On a desktop the row runs the width of the page: the number (Q1 to Q12, the numbers the error
   messages use), the question on the left and its answer on the right, with options in two
   columns, so the form is wide and short. Under 900 px the answer moves below the question;
   on a phone the number sits beside the question and the options take one column. */
.apply-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px 48px;
  align-items: start;
  margin-bottom: 24px;
}
.apply-head h1 { grid-column: 1 / -1; margin: 0; text-wrap: balance; }
.apply-head .lead { max-width: 64ch; margin: 0; }
.apply-notes { display: grid; gap: 10px; }
.apply-notes p { margin: 0; }
.apply-note {
  padding: 10px 12px;
  border: 1px solid var(--tint-amber-line);
  border-radius: var(--r-control);
  background: var(--tint-amber);
  color: var(--amber-text);
}
/* On the amber tint a link takes the text colour and an underline: the link blue on amber is too faint. */
.apply-note a, .apply-page .errors a { color: inherit; text-decoration: underline; }

.apply { display: grid; gap: 20px; }
.apply .hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.apply-sec {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  background: var(--surface);
  scroll-margin-top: 16px;
}
/* A floated legend lays out as an ordinary block inside the panel instead of on its border. */
.apply-sec > legend {
  float: left;
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
  border-radius: calc(var(--r-panel) - 1px) calc(var(--r-panel) - 1px) 0 0;
  background: var(--raised);
}
.apply-sec .sec-title { font: 600 var(--fs-h2)/1.3 var(--font-display); color: var(--text); }
.apply-sec .sec-step {
  font: 600 var(--fs-micro)/1.4 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--label);
  white-space: nowrap;
}
.apply-sec .sec-body { clear: both; }

.apply .q {
  display: grid;
  grid-template-columns: 40px minmax(0, 5fr) minmax(0, 8fr);
  gap: 12px 16px;
  padding: 18px 22px;
  scroll-margin-top: 16px;
}
.apply .q + .q { border-top: 1px solid var(--line); }
/* The 9 px on the number and the question puts their first line level with the text of the
   first answer (inside an input or an option). */
.apply .q-num {
  padding-top: 9px;
  font: 600 var(--fs-micro)/22px var(--font-mono);
  letter-spacing: 0.06em;
  color: var(--label);
}
.apply .q-head { grid-column: 2; min-width: 0; display: grid; gap: 4px; align-content: start; padding: 9px 24px 0 0; }
.apply .q-body { grid-column: 3; min-width: 0; display: grid; gap: 10px; align-content: start; }
.apply .q-text { font: 600 var(--fs-lead)/22px var(--font-display); color: var(--text); }
.apply .q-help { color: var(--dim); }
.apply .q-err { display: block; color: var(--red-text); font-weight: 600; }
.apply .q.bad .q-num { color: var(--red-text); }

.apply .f { display: grid; gap: 6px; min-width: 0; }
.apply .f-label { color: var(--dim); font-size: var(--fs-small); line-height: 1.4; }
.apply .pair, .apply .opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.apply .pair { align-items: end; }
.apply select { min-height: calc(1.55em + 20px); } /* as tall as the input beside it */
.apply textarea { display: block; min-height: 104px; resize: vertical; }

/* An option is a whole tile to press; the chosen one takes the accent of a selected choice. The
   ticked box is the app's toggle: a deep blue fill inside the accent border, white glyph. */
.apply .opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: var(--well);
  color: var(--gray);
  cursor: pointer;
}
.apply .opt:hover { border-color: var(--faint); }
.apply .opt:has(input:checked) { border-color: var(--accent); background: var(--tint-accent); color: var(--text); }
.apply .opt input, .apply .attest input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  border: 1.5px solid var(--faint);
  background: var(--well) center / 14px no-repeat;
  cursor: pointer;
}
.apply .opt input[type="radio"] { border-radius: 50%; }
.apply .opt input[type="checkbox"], .apply .attest input { border-radius: 4px; }
.apply .opt input:checked, .apply .attest input:checked { border-color: var(--accent); background-color: var(--check-fill); }
.apply .opt input[type="radio"]:checked { background-image: radial-gradient(circle, #fff 0 3px, transparent 3.5px); background-size: auto; }
.apply .opt input[type="checkbox"]:checked, .apply .attest input:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E");
}
/* The keyboard focus ring goes round the whole tile; a click leaves no ring behind. */
.apply .opt input:focus:not(:focus-visible), .apply .attest input:focus:not(:focus-visible) { outline: none; }
@supports selector(:has(*)) {
  .apply .opt input:focus-visible { outline: none; }
  .apply .opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
}

.apply .attest { color: var(--gray); cursor: pointer; }
.apply .attest input { width: 20px; height: 20px; margin: 1px 0 0; }
.apply .attest .attest-text { grid-column: 2 / -1; max-width: 80ch; }
.apply .attest:has(input:checked) { color: var(--text); }
.apply .attest.bad input:not(:checked) { border-color: var(--red-text); }
.apply .attest .q-err { margin-top: 4px; }
.apply .submit .q-body { justify-items: start; gap: 12px; }
.apply .submit button { padding: 11px 22px; }
.apply .submit p { margin: 0; }

@media (max-width: 899px) {
  .apply-head { grid-template-columns: minmax(0, 1fr); }
  .apply .q { grid-template-columns: 40px minmax(0, 1fr); }
  .apply .q-num { padding-top: 0; }
  .apply .q-head { padding: 0; }
  .apply .q-body { grid-column: 2; }
}
@media (max-width: 640px) {
  .apply-sec > legend { padding: 12px 16px; }
  .apply .q { grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; padding: 18px 16px; }
  .apply .q-body, .apply .sig .q-head { grid-column: 1 / -1; }
  .apply .attest .attest-text { grid-column: 2; }
  .apply .pair, .apply .opts { grid-template-columns: minmax(0, 1fr); }
  .apply .opts.yn { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .apply .opts { gap: 8px; }
  .apply .opt { padding: 11px 12px; }
  .apply .submit button { width: 100%; justify-content: center; }
}
