/* Energy Provider Pilot Survey — shared base styles (survey + dashboard).
   Fonts, brand tokens, reset, typography, form controls, buttons, cards,
   badges. Mobile-first; comfortable at 360px. No horizontal scrolling.

   Brand: CL Science (powered by Nexus), October 2026 brand board — charcoal,
   concrete, paper, industrial green, energy ochre and slate blue; radii 0/4/8
   (default 4); thin rules; chamfered primary buttons; mono labels. Every
   text/background pair below meets WCAG AA; ochre is never used as text on
   light backgrounds (only on charcoal or slate). */

/* ---------- Self-hosted fonts ----------
   The CSP allows fonts from this origin only (font-src 'self'), so the
   latin-subset files live in /fonts/ (copied from @fontsource by
   scripts/copy-fonts.js; SIL Open Font License, see /fonts/LICENSE-*.txt). */
@font-face {
  font-family: 'Inter Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('/fonts/inter-latin-wght-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  src: url('/fonts/archivo-latin-wdth-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url('/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-display: swap;
  font-weight: 500;
  src: url('/fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Brand palette (brand board, October 2026). */
  --charcoal: #0f1113;
  --concrete: #d9dbd6;
  --paper: #fafaf8;
  --green: #2e6b4e;         /* industrial green: links, choices, progress */
  --ochre: #d49a2a;         /* energy ochre: accents (harmonises with the gold logo) — text only on charcoal/slate */
  --slate: #1e2d3a;         /* slate blue: secondary dark surfaces */
  /* Derived tints and shades. */
  --green-700: #245a41;     /* 8.0:1 on white */
  --green-800: #1f4d37;
  --green-50: #eaf2ed;
  --ochre-300: #e7b24c;     /* focus ring on charcoal, 9.8:1 */
  --ochre-700: #94650f;     /* focus ring on light surfaces, 5.1:1 on white */
  --ochre-50: #fbf1dc;
  --concrete-50: #f1f2ee;
  --concrete-100: #e7e9e4;
  --concrete-600: #6e726b;  /* control borders, 4.9:1 on white */
  --slate-50: #e8ecef;

  --font: 'Inter Variable', Inter, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-display: 'Archivo Variable', Archivo, 'Inter Variable', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: var(--paper);
  --surface: #ffffff;
  --surface-2: var(--concrete-50);
  --text: var(--charcoal);
  --text-2: #3a3f44;        /* 10.6:1 on white */
  --hint: #5a5f63;          /* light grey hint, 6.5:1 on white, 5.7:1 on --surface-2 */
  --border: var(--concrete);
  --border-strong: var(--concrete-600);

  --primary: var(--charcoal);
  --primary-hover: var(--slate);
  --primary-soft: var(--concrete-50);
  --on-primary: var(--paper);

  --accent: var(--green);           /* chosen answers, progress */
  --accent-soft: var(--green-50);
  --link: var(--green);             /* 6.3:1 on white */
  --link-hover: var(--green-800);

  --ok: var(--green);
  --ok-soft: var(--green-50);
  --warn: #7a4b00;          /* 6.6:1 on --warn-soft */
  --warn-soft: var(--ochre-50);
  --danger: #b42318;
  --danger-soft: #fdecea;
  --info: var(--slate);
  --info-soft: var(--slate-50);
  --special: #5b3d8c;       /* not known / partner to confirm / n/a */
  --special-soft: #f1edf7;
  --demo: #7a4b00;
  --demo-soft: var(--ochre-50);

  --focus: var(--ochre-700);
  --radius: 4px;            /* default: cards, panels, inputs */
  --radius-sm: 4px;
  --radius-lg: 8px;         /* dialogs */
  --shadow: 0 1px 0 rgba(15, 17, 19, 0.04);
  --chamfer: 10px;          /* the cut corner of primary buttons */
  --tap: 48px;              /* minimum touch target */
  --gutter: 16px;
  --maxw: 720px;
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* Long words, links and codes still break, but ordinary words are never
     split mid-word (narrow screens, 200% zoom). */
  overflow-wrap: break-word;
}

img, svg { max-width: 100%; height: auto; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; }
h1, h2 { font-family: var(--font-display); font-weight: 700; font-stretch: 104%; letter-spacing: -0.005em; }
h1 { font-size: 1.6rem; line-height: 1.15; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; font-weight: 650; }
p { margin: 0 0 0.75em; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--link-hover); text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--surface); color: var(--charcoal); padding: 12px 16px; font-weight: 600;
  border: 2px solid var(--charcoal); border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- Brand lockup (survey and dashboard headers) ----------
   The original gold CL Science mark (brand/logo-original.svg, inline in the
   page with its gradient) next to "CL SCIENCE" / "POWERED BY NEXUS". */
.brand-lockup { display: inline-flex; align-items: center; gap: 10px; min-width: 0; margin: 0; }
.brand-mark { display: block; flex: 0 0 auto; width: 32px; height: 32px; }
.brand-words { display: grid; gap: 1px; min-width: 0; line-height: 1; }
.brand-name {
  font-family: var(--font-display); font-weight: 800; font-stretch: 118%;
  font-size: 0.9rem; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}
.brand-sub {
  font-family: var(--font-mono); font-weight: 500; font-size: 0.62rem;
  letter-spacing: 0.16em; text-transform: uppercase; white-space: nowrap; opacity: 0.85;
}

/* ---------- Form controls ---------- */
.field { margin: 0 0 22px; }
.field > label, .field-label, fieldset > legend {
  display: block; font-weight: 600; margin: 0 0 4px; color: var(--text); padding: 0;
}
.hint { color: var(--hint); font-size: 0.95rem; margin: 0 0 8px; }
.req-mark { color: var(--danger); font-weight: 700; }
.key-mark { color: var(--hint); font-weight: 400; font-size: 0.85rem; }

fieldset { border: 0; margin: 0 0 22px; padding: 0; min-width: 0; }

input[type="text"], input[type="email"], input[type="tel"], input[type="url"],
input[type="number"], input[type="date"], input[type="password"], input[type="search"],
select, textarea {
  display: block; width: 100%; min-height: var(--tap);
  font: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px;
}
input:not([type="radio"]):not([type="checkbox"]):focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--charcoal); }
textarea { min-height: 120px; resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }

.input-affix { display: flex; align-items: stretch; }
.input-affix > .affix {
  display: flex; align-items: center; padding: 0 10px; background: var(--surface-2);
  border: 1.5px solid var(--border-strong); color: var(--text-2); white-space: nowrap;
  font-family: var(--font-mono); font-size: 0.9rem;
}
.input-affix > .affix.prefix { border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-affix > .affix.suffix { border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-affix > input { border-radius: 0; flex: 1 1 auto; min-width: 0; }
.input-affix > .affix.prefix + input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-affix > input:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }

/* Choice lists: radios and checkboxes as large tappable rows */
/* minmax(0, 1fr): long option labels wrap instead of widening the page. */
.choices { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.choices.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap);
  padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.choice:hover { border-color: var(--border-strong); }
.choice input { width: 22px; height: 22px; margin: 0; flex: 0 0 auto; accent-color: var(--accent); }
/* Chosen: green rule on the left, as well as the native tick or dot. */
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice:has(input:disabled) { cursor: default; opacity: 0.75; }

/* Pill radio groups (compact, wrap on phones) */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
  font-size: 0.95rem; cursor: pointer; user-select: none;
}
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: #ffffff; }
/* A tick as well as colour, so the choice shows in every colour mode. The
   second declaration gives it empty alternative text where supported. */
.pill input:checked + span::before { content: '✓\00a0'; content: '✓\00a0' / ''; }
.pill input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.pill input:disabled + span { cursor: default; opacity: 0.7; }
.pill.special input:checked + span { background: var(--special); border-color: var(--special); }

/* Windows High Contrast and other forced-colour modes drop backgrounds, so
   the chosen pill uses the system highlight colours instead. */
@media (forced-colors: active) {
  .pill input:checked + span,
  .pills .pill.special input:checked + span {
    forced-color-adjust: none; background: Highlight; color: HighlightText; border: 3px solid Highlight;
  }
  .pill input:focus-visible + span { outline: 3px solid Highlight; }
}

/* ---------- Buttons ----------
   Primary: charcoal with one chamfered (cut) top-right corner. The cut is
   painted by the background gradient, so the square focus outline stays
   visible (clip-path would clip it). */
.btn {
  --btn-bg: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 20px; font: inherit; font-weight: 600; font-size: 1rem; letter-spacing: 0.005em;
  border-radius: 0; border: 1.5px solid transparent;
  background: linear-gradient(225deg, transparent calc(var(--chamfer) * 0.7071), var(--btn-bg) calc(var(--chamfer) * 0.7071)) border-box;
  color: var(--on-primary); cursor: pointer; text-decoration: none;
}
.btn:hover { --btn-bg: var(--primary-hover); color: var(--on-primary); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); border-color: var(--primary); color: var(--primary); }
.btn-secondary:hover { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--link); border-radius: var(--radius-sm); }
.btn-ghost:hover { background: var(--primary-soft); color: var(--link-hover); border-color: transparent; }
.btn-danger { --btn-bg: var(--danger); }
.btn-danger:hover { --btn-bg: #8f1c13; }
.btn-small { --chamfer: 8px; min-height: 44px; padding: 6px 12px; font-size: 0.95rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
/* Forward actions carry an arrow (decorative: empty alternative text). */
.btn-arrow::after { content: '→'; content: '→' / ''; font-weight: 500; transition: transform 0.15s ease; }
.btn-arrow:hover::after { transform: translateX(3px); }
@media (forced-colors: active) {
  .btn { background-image: none; border-color: ButtonText; }
}

/* ---------- Surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin: 0 0 16px; box-shadow: var(--shadow);
}
.notice { border-radius: 0; padding: 12px 14px; margin: 0 0 16px; border-left: 3px solid; }
.notice-info { background: var(--info-soft); border-color: var(--info); }
.notice-warn { background: var(--warn-soft); border-color: var(--ochre); }
.notice-danger { background: var(--danger-soft); border-color: var(--danger); }
.notice-ok { background: var(--ok-soft); border-color: var(--ok); }

/* Badges / tags: mono, upper case, tight corners (brand board tags). */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 2px;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase;
  line-height: 1.7; border: 1px solid transparent; white-space: nowrap;
}
.badge-neutral { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.badge-ok { background: var(--ok-soft); color: var(--green-700); border-color: #b9d3c3; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: #ecd3a0; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: #f2c1bb; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: #c9d2da; }
.badge-special { background: var(--special-soft); color: var(--special); border-color: #d6cbe8; }
.badge-demo { background: var(--demo-soft); color: var(--demo); border-color: var(--ochre); }

/* Disclosure panels */
details.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 16px; }
details.panel > summary {
  list-style: none; cursor: pointer; min-height: var(--tap); padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary > * { min-width: 0; }
/* The +/− icon is decorative (the open state is already announced), so it gets
   empty alternative text where supported. */
details.panel > summary::after {
  content: '+'; content: '+' / ''; font-size: 1.4rem; font-weight: 400; line-height: 1; color: var(--accent);
}
details.panel[open] > summary::after { content: '−'; content: '−' / ''; }
details.panel > .panel-body { padding: 0 16px 16px; }

/* Progress: green fill on a concrete track, square ends. */
.progress { height: 6px; background: var(--concrete-100); border-radius: 0; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

/* Native dialog */
dialog {
  border: 0; border-top: 3px solid var(--charcoal); border-radius: var(--radius-lg); padding: 0; width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 48px); box-shadow: 0 12px 40px rgba(15, 17, 19, 0.28);
}
dialog::backdrop { background: rgba(15, 17, 19, 0.55); }
dialog .dialog-body { padding: 20px; }

.muted { color: var(--hint); }
.small { font-size: 0.9rem; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.stack > * + * { margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
