/* Sigrow lamp app: design system.
   Brand tokens (from the Sigrow brand guide, unchanged): blue #0091DB, headings #285172, body #2D3A49,
   pale panel #EAF2F2, hairline #EAECED, muted #777777, Helvetica Neue / Helvetica / Arial.
   Contrast notes: #0091DB on white is 3.4:1, so it is used for focus rings, rails, graphics and large shapes;
   small text and buttons use the AA-safe derivative --accent-text. #777777 is 4.5:1 only on white, so
   small muted text uses --muted-text. tests/test_features.py checks every pair below against WCAG AA. */
:root {
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --brand: #0091DB;
  --heading: #285172;
  --text: #2D3A49;
  --panel: #EAF2F2;
  --line: #EAECED;
  --muted: #777777;
  --muted-text: #5F6B76;
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --accent-text: #006FA8;
  --accent-fill: #006FA8;
  --accent-hover: #005A8C;
  --on-accent: #FFFFFF;
  --danger: #B3261E;
  --danger-bg: #FDECEA;
  --ok: #17703F;
  --ok-bg: #E6F4EC;
  --warn-text: #7A4F00;
  --warn-bg: #FFF4DB;
  --base-slice: #BEDCFF;   /* the reserved white-blue the lamp shows when nothing has been touched */
  --shadow: 0 1px 2px rgba(40, 81, 114, .08), 0 4px 16px rgba(40, 81, 114, .06);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-sm: 8px; --r-md: 14px; --r-lg: 24px; --r-pill: 999px;
  --tap: 44px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #38B2F0;
  --heading: #BCD8EE;
  --text: #D5E0E9;
  --panel: #1B2E3F;
  --line: #2A3D4F;
  --muted: #8DA0B0;
  --muted-text: #9DB0C0;
  --bg: #0E1A25;
  --surface: #142331;
  --accent-text: #5CC0F4;
  --accent-fill: #5CC0F4;
  --accent-hover: #7ACDF7;
  --on-accent: #08141D;
  --danger: #FF8F86;
  --danger-bg: #3A1A1A;
  --ok: #7ED6A1;
  --ok-bg: #12301F;
  --warn-text: #F2C46B;
  --warn-bg: #33270E;
  --base-slice: #3C5C80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #38B2F0; --heading: #BCD8EE; --text: #D5E0E9; --panel: #1B2E3F; --line: #2A3D4F; --muted: #8DA0B0;
    --muted-text: #9DB0C0; --bg: #0E1A25; --surface: #142331; --accent-text: #5CC0F4; --accent-fill: #5CC0F4;
    --accent-hover: #7ACDF7; --on-accent: #08141D; --danger: #FF8F86; --danger-bg: #3A1A1A; --ok: #7ED6A1;
    --ok-bg: #12301F; --warn-text: #F2C46B; --warn-bg: #33270E; --base-slice: #3C5C80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 400 1rem/1.5 var(--font);
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
}
h1, h2, h3 { color: var(--heading); font-weight: 700; line-height: 1.2; margin: 0 0 var(--s3); letter-spacing: -.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--s3); max-width: 62ch; }
a { color: var(--accent-text); text-underline-offset: 3px; }
.muted { color: var(--muted-text); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .02em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---- shell ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.wordmark { font-weight: 700; font-size: 1.25rem; color: var(--heading); letter-spacing: -.02em; text-decoration: none; }
.wordmark span { color: var(--accent-text); font-weight: 400; margin-left: var(--s2); font-size: .95rem; letter-spacing: 0; }
main { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: var(--s5) var(--s4) calc(var(--s7) + var(--s6)); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: center; z-index: 5; padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner { display: flex; width: 100%; max-width: 560px; }
.tab {
  flex: 1; min-height: 56px; background: none; border: 0; color: var(--muted-text); font: 500 .8125rem var(--font);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
  border-top: 3px solid transparent;
}
.tab[aria-current="page"] { color: var(--accent-text); border-top-color: var(--brand); font-weight: 700; }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- components ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4); margin-bottom: var(--s4); }
.card.panel { background: var(--panel); border-color: transparent; }
.card.raised { box-shadow: var(--shadow); }
.stack > * + * { margin-top: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.btn {
  min-height: var(--tap); padding: 0 var(--s5); border-radius: var(--r-pill); border: 1px solid transparent;
  background: var(--accent-fill); color: var(--on-accent); font: 700 1rem var(--font); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); text-decoration: none;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--accent-text); border-color: var(--accent-text); }
.btn.secondary:hover { background: var(--panel); }
.btn.quiet { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
.btn.quiet:hover { background: var(--panel); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 1.15rem; }
.btn.small { min-height: var(--tap); padding: 0 var(--s4); font-size: .9375rem; }
label, .label { display: block; font-weight: 700; color: var(--heading); margin-bottom: var(--s1); font-size: .9375rem; }
.field { margin-bottom: var(--s4); }
.hint { color: var(--muted-text); font-size: .875rem; margin-top: var(--s1); }
input[type="text"], input[type="password"], input[type="search"], input[type="number"], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px var(--s3); border: 1px solid var(--muted); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font: 400 1rem var(--font);
}
textarea { min-height: 88px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--brand); outline-offset: 1px; }
input[aria-invalid="true"] { border-color: var(--danger); }
input[type="range"] { width: 100%; min-height: var(--tap); accent-color: var(--accent-fill); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: var(--tap); }
.switch input { width: 24px; height: 24px; accent-color: var(--accent-fill); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--r-pill); font-size: .8125rem; font-weight: 700; background: var(--panel); color: var(--heading); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.bad { background: var(--danger-bg); color: var(--danger); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); }
.notice { border-radius: var(--r-sm); padding: var(--s3) var(--s4); margin-bottom: var(--s4); border: 1px solid transparent; }
.notice.error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.info { background: var(--panel); color: var(--text); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--muted-text); }
.empty h3 { color: var(--heading); }
.skeleton { background: linear-gradient(90deg, var(--panel), var(--line), var(--panel)); background-size: 200% 100%; border-radius: var(--r-sm); min-height: 20px; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: var(--s2); margin-bottom: var(--s4); }
.chip { min-height: var(--tap); padding: 0 var(--s4); border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 500 .9375rem var(--font); cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--heading); color: var(--bg); border-color: var(--heading); }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s3); }
.swatch { min-height: 56px; border-radius: var(--r-md); border: 3px solid transparent; cursor: pointer; position: relative; padding: 0; }
.swatch[aria-pressed="true"] { border-color: var(--heading); box-shadow: 0 0 0 2px var(--bg) inset; }
.swatch[disabled] { opacity: .35; cursor: not-allowed; }
.swatch .tick { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; color: #fff; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.swatch[aria-pressed="true"] .tick { display: flex; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); min-height: var(--tap); }
.list > li:last-child { border-bottom: 0; }
.color-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.15); }
.copy { display: flex; gap: var(--s2); align-items: center; }
.copy code { flex: 1; padding: var(--s2) var(--s3); background: var(--panel); border-radius: var(--r-sm); overflow-wrap: anywhere; }
.qr { background: #fff; padding: var(--s3); border-radius: var(--r-md); display: inline-block; border: 1px solid var(--line); }
.qr img { display: block; width: 200px; height: 200px; image-rendering: pixelated; }

/* ---- onboarding stepper: a real sequence, so it is numbered ---- */
.stepper { display: flex; list-style: none; padding: 0; margin: 0 0 var(--s5); gap: var(--s2); }
.stepper li { flex: 1; text-align: center; font-size: .8125rem; color: var(--muted-text); position: relative; padding-top: 38px; }
.stepper li::before {
  content: attr(data-n); position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 30px; height: 30px;
  border-radius: 50%; border: 2px solid var(--line); background: var(--surface); color: var(--muted-text);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9375rem;
}
.stepper li::after { content: ""; position: absolute; top: 14px; left: calc(50% + 20px); right: calc(-50% + 20px); height: 2px; background: var(--line); }
.stepper li:last-child::after { display: none; }
.stepper li[data-state="done"]::before { content: "\2713"; background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
.stepper li[data-state="done"]::after { background: var(--brand); }
.stepper li[aria-current="step"] { color: var(--heading); font-weight: 700; }
.stepper li[aria-current="step"]::before { border-color: var(--brand); color: var(--heading); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 22%, transparent); }

/* ---- the pie ---- */
.pie-wrap { display: grid; place-items: center; padding: var(--s3) 0 var(--s4); }
.pie { width: min(300px, 80vw); height: auto; }
.pie circle { fill: none; stroke-width: 15; transition: stroke-dasharray .6s ease, stroke-dashoffset .6s ease; }
.pie .track { stroke: var(--line); }
.pie-center { fill: var(--heading); font: 700 9px var(--font); text-anchor: middle; }
.pie-center-sub { fill: var(--muted-text); font: 400 4.2px var(--font); text-anchor: middle; }
.legend { list-style: none; margin: 0; padding: 0; }
.legend li { display: grid; grid-template-columns: 14px 1fr auto; gap: var(--s3); align-items: center; padding: var(--s2) 0; border-bottom: 1px solid var(--line); min-height: var(--tap); }
.legend li:last-child { border-bottom: 0; }
.legend .pct { font-weight: 700; color: var(--heading); font-variant-numeric: tabular-nums; }
.legend .when { display: block; font-size: .8125rem; color: var(--muted-text); }
.msg { padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.msg .who { font-weight: 700; color: var(--heading); }
.msg .meta { color: var(--muted-text); font-size: .8125rem; }
.keypad { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); background: var(--heading); color: var(--bg); padding: var(--s3) var(--s5); border-radius: var(--r-pill); z-index: 20; max-width: 90vw; box-shadow: var(--shadow); }

@media (min-width: 720px) { main { padding-top: var(--s6); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print { .tabbar, .topbar { display: none; } }
.skeleton.h1 { height: 28px; width: 60%; } .skeleton.h2 { height: 180px; }
[hidden] { display: none !important; }
.legend { margin-bottom: var(--s4); }
