/*
 * Ardagh live view.
 *
 * Same visual system as apps/capture/app.css and the dashboard prototype --
 * one product, one look, and two of these to maintain is one too many. The
 * token block below is deliberately identical to the capture screen's;
 * tests/test_live_view.py fails if the two drift.
 *
 * What differs, and why: this is read at a glance during a production run,
 * often on a phone held in one hand on a factory floor. So the projection is
 * the largest thing on a card by a wide margin, the sample size is physically
 * attached to it rather than merely nearby, and nothing that matters is
 * carried by colour alone -- a green dot and a red dot are also hollow and
 * filled, because roughly one man in twelve cannot tell those two colours
 * apart and this is exactly the audience.
 */
:root {
  color-scheme: light;
  --page:#f9f9f7; --surface:#fcfcfb; --sunken:#f2f1ed;
  --ink:#0b0b0b; --ink-2:#52514e; --muted:#898781;
  --border:rgba(11,11,11,0.12); --hair:rgba(11,11,11,0.07);
  --series:#2a78d6; --series-ink:#ffffff;
  --critical:#d03b3b; --critical-wash:rgba(208,59,59,0.07);
  --good:#2f7d54; --good-wash:rgba(47,125,84,0.09);
  --chip:#f0efec;
  --warn-bg:#fdf6e3; --warn-line:#fab219;
  --radius:14px;
  --tap:52px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:#0d0d0d; --surface:#1a1a19; --sunken:#141413;
    --ink:#ffffff; --ink-2:#c3c2b7; --muted:#898781;
    --border:rgba(255,255,255,0.13); --hair:rgba(255,255,255,0.07);
    --series:#3987e5; --series-ink:#ffffff;
    --critical:#e05c5c; --critical-wash:rgba(224,92,92,0.12);
    --good:#57ab7d; --good-wash:rgba(87,171,125,0.12);
    --chip:#262623;
    --warn-bg:#2a2413; --warn-line:#fab219;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:#0d0d0d; --surface:#1a1a19; --sunken:#141413;
  --ink:#ffffff; --ink-2:#c3c2b7; --muted:#898781;
  --border:rgba(255,255,255,0.13); --hair:rgba(255,255,255,0.07);
  --series:#3987e5; --series-ink:#ffffff;
  --critical:#e05c5c; --critical-wash:rgba(224,92,92,0.12);
  --good:#57ab7d; --good-wash:rgba(87,171,125,0.12);
  --chip:#262623;
  --warn-bg:#2a2413; --warn-line:#fab219;
}

* { box-sizing:border-box; }
html { -webkit-text-size-adjust:100%; }
body {
  margin:0; background:var(--page); color:var(--ink);
  font-family:system-ui,-apple-system,"Segoe UI",sans-serif;
  font-size:17px; line-height:1.5;
}
.wrap { max-width:820px; margin:0 auto; padding:14px 16px 80px; }
[hidden] { display:none !important; }
a { color:inherit; }

/* ---------- top bar: what is live, and how old ---------- *
 * Sticky because it is the answer to "can I trust what I am looking at", and
 * that question is asked while scrolled halfway down. */
.topbar {
  position:sticky; top:0; z-index:5;
  display:flex; align-items:center; gap:10px; flex-wrap:wrap;
  padding:10px 0 12px; margin-bottom:6px;
  background:var(--page); border-bottom:1px solid var(--hair);
}
.topbar__title { font-size:15px; font-weight:700; margin:0; letter-spacing:-0.01em; }
.topbar__spacer { flex:1 1 auto; }

.pill {
  display:inline-flex; align-items:center; gap:7px;
  font-size:12px; font-weight:700; letter-spacing:0.05em; text-transform:uppercase;
  border-radius:999px; padding:5px 11px;
  background:var(--chip); color:var(--ink-2);
}
.pill::before {
  content:""; width:8px; height:8px; border-radius:50%; background:currentColor;
}
.pill[data-state="live"] { background:var(--good-wash); color:var(--good); }
.pill[data-state="live"]::before { animation:beat 2.4s ease-in-out infinite; }
.pill[data-state="connecting"] { background:var(--warn-bg); color:#8a6400; }
.pill[data-state="stale"],
.pill[data-state="offline"] { background:var(--critical-wash); color:var(--critical); }
.pill[data-state="demo"],
.pill[data-state="demo-done"] { background:var(--warn-bg); color:#8a6400; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill[data-state="connecting"],
  :root:not([data-theme="light"]) .pill[data-state="demo"],
  :root:not([data-theme="light"]) .pill[data-state="demo-done"] { color:var(--warn-line); }
}
:root[data-theme="dark"] .pill[data-state="connecting"],
:root[data-theme="dark"] .pill[data-state="demo"],
:root[data-theme="dark"] .pill[data-state="demo-done"] { color:var(--warn-line); }
@keyframes beat { 0%,100% { opacity:1; } 50% { opacity:0.35; } }
@media (prefers-reduced-motion: reduce) {
  .pill[data-state="live"]::before { animation:none; }
}

.stamp {
  font-size:13px; color:var(--muted); font-variant-numeric:tabular-nums;
}
.stamp--stale { color:var(--critical); font-weight:700; }

/* ---------- banners ---------- */
.banner {
  display:flex; gap:12px; align-items:flex-start;
  border:1px solid var(--border); border-left-width:4px;
  border-radius:10px; padding:12px 14px; margin:14px 0;
}
.banner b { display:block; }
.banner p { margin:2px 0 0; font-size:15px; color:var(--ink-2); }
.banner--demo { background:var(--warn-bg); border-left-color:var(--warn-line); }
.banner--error { background:var(--critical-wash); border-left-color:var(--critical); }

/* ---------- page header ---------- */
header.page { margin:10px 0 20px; }
header.page h1 { font-size:clamp(23px,5vw,31px); margin:0 0 4px; letter-spacing:-0.02em; }
header.page .sub { color:var(--ink-2); font-size:15px; margin:0; }
.whoami {
  display:inline-block; margin-top:9px; font-size:12px; font-weight:600;
  letter-spacing:0.04em; text-transform:uppercase; color:var(--ink-2);
  background:var(--chip); border-radius:999px; padding:4px 10px;
}

/* ---------- groups ---------- */
.group { margin:0 0 30px; }
.group__head {
  display:flex; align-items:center; gap:9px; margin:0 0 12px;
  font-size:13px; font-weight:700; letter-spacing:0.08em; text-transform:uppercase;
  color:var(--muted);
}
.group__count {
  font-size:12px; letter-spacing:0; font-variant-numeric:tabular-nums;
  background:var(--chip); color:var(--ink-2); border-radius:999px;
  min-width:22px; text-align:center; padding:1px 7px;
}
.group__count:empty { display:none; }
.group__list { display:flex; flex-direction:column; gap:12px; }

/* An empty board is the NORMAL case and must read as deliberate, never as
 * broken (ADR-0011 section 9). "Nothing to show" is what a failed fetch looks
 * like; this says what is true instead. */
.empty {
  border:1px dashed var(--border); border-radius:var(--radius);
  padding:22px; text-align:center; color:var(--ink-2); font-size:15px;
}
.empty b { display:block; color:var(--ink); font-size:17px; margin-bottom:3px; }

/* ---------- cards ---------- */
.card {
  display:block; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); padding:18px;
}
a.card { text-decoration:none; color:inherit; }
a.card:hover { border-color:var(--series); }
a.card:focus-visible { outline:3px solid var(--series); outline-offset:2px; }

.card--new { animation:appear 1.6s ease-out; }
.card--flash { animation:flash 1.4s ease-out; }
@keyframes appear { from { border-color:var(--series); } }
@keyframes flash { 0%,40% { background:var(--good-wash); } }
@media (prefers-reduced-motion: reduce) {
  .card--new, .card--flash { animation:none; }
}

.card__head {
  display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:12px;
}
.card__ref {
  font-size:15px; font-weight:700; letter-spacing:0.02em;
  font-variant-numeric:tabular-nums;
}

.state {
  font-size:11px; font-weight:700; letter-spacing:0.06em; text-transform:uppercase;
  border-radius:999px; padding:4px 9px; background:var(--chip); color:var(--ink-2);
}
.state--progress { background:var(--good-wash); color:var(--good); }
.state--complete { background:var(--chip); color:var(--ink-2); }
.state--retro { background:var(--warn-bg); color:#8a6400; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .state--retro { color:var(--warn-line); }
}
:root[data-theme="dark"] .state--retro { color:var(--warn-line); }

/* ---------- meta ---------- */
.meta {
  display:grid; grid-template-columns:auto 1fr; gap:3px 14px;
  margin:0 0 16px; font-size:15px;
}
.meta dt {
  font-size:12px; font-weight:600; letter-spacing:0.05em; text-transform:uppercase;
  color:var(--muted); align-self:baseline;
}
.meta dd { margin:0; color:var(--ink); min-width:0; overflow-wrap:anywhere; }

/* ---------- the projection ---------- *
 * The largest thing on the card, because it is the only number that answers
 * the question Ardagh asked. Its denominator is inside the same box, on
 * purpose: ADR-0011 section 3 requires the sample to travel WITH the rate, and
 * anything that can be screenshotted separately eventually is. */
.proj {
  background:var(--sunken); border-radius:11px; padding:15px 16px; margin-bottom:14px;
}
.proj__value {
  font-size:clamp(34px,9vw,46px); font-weight:700; line-height:1.05;
  letter-spacing:-0.03em; font-variant-numeric:tabular-nums;
}
.proj__unit { font-size:15px; color:var(--ink-2); margin-top:2px; }
.proj__basis {
  font-size:13px; color:var(--muted); margin-top:7px;
  font-variant-numeric:tabular-nums;
}

/* Muted, NOT hidden. Ardagh would ask for the number anyway and someone would
 * read them the raw count, which is worse than an honest early figure. */
.proj--early .proj__value { color:var(--muted); font-weight:600; }
.proj--early { border:1px dashed var(--border); }
.proj__early-note {
  margin:9px 0 0; font-size:13px; font-weight:600; color:#8a6400;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .proj__early-note { color:var(--warn-line); }
}
:root[data-theme="dark"] .proj__early-note { color:var(--warn-line); }

/* ---------- dots ---------- */
.dots { display:flex; flex-wrap:wrap; align-items:center; gap:5px; }
.dot {
  width:11px; height:11px; border-radius:50%;
  border:1.5px solid var(--good); background:transparent;
}
.dot--hit { background:var(--critical); border-color:var(--critical); }
.dots__label {
  margin-left:5px; font-size:12px; color:var(--muted);
  font-variant-numeric:tabular-nums;
}
.dots--none { font-size:13px; color:var(--muted); }

/* ---------- resort page ---------- */
.back {
  display:inline-block; margin-bottom:10px; font-size:14px;
  color:var(--ink-2); text-decoration:none;
}
.back:hover { color:var(--series); }
.section { margin-top:26px; }
.section > h2 {
  font-size:13px; font-weight:700; letter-spacing:0.08em; text-transform:uppercase;
  color:var(--muted); margin:0 0 12px;
}
.facts {
  display:grid; grid-template-columns:auto 1fr; gap:6px 16px;
  margin:0; font-size:15px;
}
.facts dt {
  font-size:12px; font-weight:600; letter-spacing:0.05em; text-transform:uppercase;
  color:var(--muted);
}
.facts dd { margin:0; overflow-wrap:anywhere; font-variant-numeric:tabular-nums; }

.table-scroll { overflow-x:auto; -webkit-overflow-scrolling:touch; }
table { border-collapse:collapse; width:100%; font-size:15px; }
th, td { text-align:left; padding:9px 12px; border-bottom:1px solid var(--hair); }
th {
  font-size:12px; font-weight:600; letter-spacing:0.05em; text-transform:uppercase;
  color:var(--muted); white-space:nowrap;
}
td.n, th.n { text-align:right; font-variant-numeric:tabular-nums; }
tr.hit td { background:var(--critical-wash); }

.note-box {
  background:var(--sunken); border-radius:11px; padding:14px 16px;
  font-size:15px; color:var(--ink-2); white-space:pre-wrap; overflow-wrap:anywhere;
}

/* ---------- sign in ---------- */
.signin { max-width:400px; margin:11vh auto; padding:0 16px; }
.signin h1 { font-size:24px; margin:0 0 4px; }
.signin .sub { color:var(--ink-2); font-size:15px; margin:0 0 20px; }
.field { display:flex; flex-direction:column; gap:6px; margin-bottom:14px; }
label {
  font-size:13px; font-weight:600; letter-spacing:0.05em; text-transform:uppercase;
  color:var(--ink-2);
}
input {
  font:inherit; color:var(--ink); background:var(--surface);
  border:1px solid var(--border); border-radius:10px;
  padding:0 12px; height:var(--tap); width:100%;
}
input:focus-visible { outline:3px solid var(--series); outline-offset:1px; }
.btn {
  font:inherit; font-weight:600; height:var(--tap); width:100%;
  border:1px solid transparent; border-radius:10px; cursor:pointer;
  background:var(--series); color:var(--series-ink);
}
.err { color:var(--critical); font-size:15px; margin:0 0 12px; }

footer.foot {
  margin-top:40px; padding-top:16px; border-top:1px solid var(--hair);
  font-size:13px; color:var(--muted);
}
