/* VDS. Colours come from the old app's logo and buttons: ballot cyan #49b8d3,
   tally magenta (old logout #d24980 / hover #b13d6c), roll purple #5749d2.
   Text on colour uses the darker shade of each so it passes WCAG AA.
   Theme: tokens on :root; dark applies when the OS asks and the person has not
   picked Light, or when they picked Dark (data-theme, set by theme.js). */

/* Public Sans for everything: interface, tables, filters, pick lists and charts.
   Tables add tabular figures so numbers line up. The file name carries a content
   hash (cached for a year) and layout.js preloads it, so text is drawn once in
   the right font: no fallback flash on each page. Rename + update FONTS together. */
@font-face { font-family: "Public Sans"; src: url("/static/fonts/public-sans.5ed4d31c.woff2") format("woff2"); font-weight: 100 900; font-display: block; }

:root {
  color-scheme: light;
  --cyan: #49b8d3;
  --cyan-ink: #1d6a7e;
  --cyan-wash: #e1f3f8;
  --magenta: #b13d6c;
  --magenta-hover: #96325b;
  --magenta-text: #b13d6c;
  --purple: #5749d2;
  --page: #e6e9ec;
  --surface: #ffffff;
  --sunk: #f3f5f7;
  --stripe: #f6f8f9;
  --ink: #1a2026;
  --muted: #59646f;
  --line: #cdd4da;
  --line-strong: #98a4af;
  --error: #b3261e;
  --warn: #8a5a00;
  --shadow: 0 6px 20px rgb(16 24 32 / 0.16);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --cyan-ink: #7fd3e6;
    --cyan-wash: #163640;
  --magenta-text: #f08ab3;
    --page: #121619;
    --surface: #191e22;
    --sunk: #20262b;
    --stripe: #1d2327;
    --ink: #e4e9ed;
    --muted: #9ba7b2;
    --line: #2d363d;
    --line-strong: #4a5660;
    --error: #ff8f87;
    --warn: #f0b85a;
    --shadow: 0 6px 20px rgb(0 0 0 / 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --cyan-ink: #7fd3e6;
  --cyan-wash: #163640;
  --magenta-text: #f08ab3;
  --page: #121619;
  --surface: #191e22;
  --sunk: #20262b;
  --stripe: #1d2327;
  --ink: #e4e9ed;
  --muted: #9ba7b2;
  --line: #2d363d;
  --line-strong: #4a5660;
  --error: #ff8f87;
  --warn: #f0b85a;
  --shadow: 0 6px 20px rgb(0 0 0 / 0.5);
}

/* State classes toggled by app.js (CSP forbids style attributes). */
.hidden { display: none; }
.stale { opacity: 0.45; }

* { box-sizing: border-box; }
/* The window behind a short page takes the theme too, not the browser default. */
html { background: var(--page); }
body {
  margin: 0;
  font: 15px/1.45 "Public Sans", system-ui, sans-serif;
  /* The font for tables and charts (charts.js reads it). */
  --data: "Public Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}
a { color: var(--cyan-ink); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
h1 { font-size: 1.5rem; line-height: 1.2; font-weight: 700; margin: 0.25rem 0 0.75rem; }
main { padding: 1rem 1.25rem; }
footer { padding: 1rem 1.25rem; color: var(--muted); font-size: 0.8rem; }

/* Buttons. One shape everywhere; colour says what kind. */
.button, button {
  font: inherit; font-weight: 600; font-size: 0.875rem;
  display: inline-flex; align-items: center; gap: 0.4em;
  border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--surface); color: var(--ink);
  padding: 0.4rem 0.8rem; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.button:hover, button:hover { background: var(--sunk); }
.button.primary, button.primary { background: var(--cyan); border-color: var(--cyan); color: #0c2a33; }
.button.primary:hover, button.primary:hover { background: #63c4dc; }
:where(select, input[type="text"], input[type="email"], input[type="search"], input:not([type])) {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 0.3rem 0.5rem;
}

/* The brand: logo.svg is the old logo's pixel tile and an outlined VDS in a black pill. */
.brand { display: block; line-height: 0; border-radius: 9px; }
.brand img { height: 2.6rem; width: auto; display: block; }

/* Top bar */
nav { display: flex; align-items: center; gap: 1.25rem; padding: 0.6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
nav > a:not(.brand) { color: var(--ink); font-weight: 600; text-decoration: none; padding: 0.3rem 0; border-bottom: 3px solid transparent; }
nav > a:not(.brand):hover { border-bottom-color: var(--line-strong); }
nav > a[aria-current="page"] { border-bottom-color: var(--cyan); }
nav .end { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }
nav .logout { margin: 0; }
nav .logout button { background: var(--magenta); border-color: var(--magenta); color: #fff; }
nav .logout button:hover { background: var(--magenta-hover); }
.theme-toggle { color: var(--muted); }
.theme-toggle .mode { color: var(--ink); }

/* Search page: the table is wider than the window, so the page scrolls sideways.
   The top bar, controls and footer stay pinned at the left, one window wide
   (100cqw = the window without its scrollbar; <html> is the container). */
html { container-type: inline-size; }
body.search { width: max-content; min-width: 100%; }
body.search nav, body.search footer { position: sticky; left: 0; width: 100cqw; }
body.search main > :not(.grid-wrap) { position: sticky; left: 1.25rem; width: calc(100cqw - 2.5rem); }

/* Search bar: counts, activity, actions */
.bar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin: 0 0 0.75rem; }
#pills { display: inline-flex; gap: 0.5rem; }
.pill { color: #fff; border-radius: 999px; padding: 0.3rem 0.8rem; font-weight: 600; font-size: 0.875rem; font-variant-numeric: tabular-nums; background: var(--purple); }
.pill + .pill { background: var(--magenta); }
.updating { color: var(--cyan-ink); font-weight: 600; visibility: hidden; }
.updating.htmx-request, .updating.busy { visibility: visible; }
.actions { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }
.note { color: var(--muted); margin: 0 0 0.75rem; font-size: 0.875rem; }
#controls { display: flex; gap: 1.25rem; margin-bottom: 0.75rem; align-items: center; }
#controls label { display: inline-flex; gap: 0.4rem; align-items: center; color: var(--muted); font-size: 0.875rem; font-weight: 600; }
#hidden-note { color: var(--warn); font-weight: 600; font-size: 0.875rem; }
#hidden-note:empty { display: none; }
.error { color: var(--error); border: 1px solid currentColor; border-radius: 6px; background: var(--surface); padding: 0.6rem 0.8rem; }
#error-slot .error { margin-bottom: 0.75rem; }

/* Results table (headers, filters and pick lists too), with tabular figures.
   Columns size to their content: the widest of label, values and filter box.
   No overflow wrapper: it would clip the dropdowns, so wide
   tables scroll the page and the header row sticks to the top of the window. */
#grid { font-variant-numeric: tabular-nums; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-family: var(--data); font-size: 0.9rem; }
#grid th, #grid td { padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; white-space: nowrap; border-bottom: 1px solid var(--line); }
#grid td + td, #grid th + th { border-left: 1px solid var(--line); }
#grid th:focus-within { z-index: 3; }
#grid th { position: sticky; top: 0; z-index: 2; background: var(--sunk); font-weight: 600; vertical-align: top; border-bottom: 2px solid var(--line-strong); }
#grid th .label { display: block; }
#grid tbody tr:nth-child(even) td { background: var(--stripe); }
#grid tbody tr:hover td { background: var(--cyan-wash); }
#grid tbody tr:last-child td { border-bottom: 0; }
#grid td a { font-weight: 600; }
#grid td.empty { color: var(--muted); white-space: normal; padding: 1.5rem 0.75rem; }
#rows { transition: opacity 0.1s; }
/* Simple view: the server leaves full-only cells out of the rows; hide their headers to match. */
#grid:has(> tbody[data-view="simple"]) .full-only { display: none; }

/* Filter boxes and chips */
.fbox { border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); padding: 2px 4px; margin-top: 0.35rem; min-height: 1.9rem; font-weight: 400; cursor: pointer; display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.fbox:focus-within { border-color: var(--cyan); }
.chips { display: contents; }
.chip { display: inline-flex; align-items: center; background: var(--cyan); color: #0c2a33; font-weight: 600; border-radius: 999px; padding: 1px 3px 1px 9px; font-size: 0.8rem; }
.chip .x { border: 0; background: none; color: inherit; padding: 0 4px; margin-left: 2px; font-size: 0.9rem; }
.chip .x:hover { background: rgb(0 0 0 / 0.12); border-radius: 999px; }
.fbox[data-kind="pick"]:not(:has(.chip))::before { content: "All"; color: var(--muted); padding-left: 4px; }
.fbox .toggle { border: 0; background: none; padding: 0 4px; margin-left: auto; color: var(--muted); }
.typein { border: 0; outline: 0; background: transparent; font: inherit; color: inherit; width: 0; min-width: 4.5rem; flex: 1 1 4.5rem; } /* width 0: an input otherwise brings its ~20-character default width and props the column open */
.typein::placeholder, .facet-search::placeholder { color: var(--muted); }

/* Dropdowns */
.drop { position: absolute; z-index: 10; left: 0.5rem; top: calc(100% - 2px); width: 17rem; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); font-weight: 400; overflow: hidden; }
.drop.flip { left: auto; right: 0.5rem; }
.drop .facet-search { width: calc(100% - 12px); margin: 6px; }
.opts { max-height: 18rem; overflow-y: auto; scrollbar-color: var(--line-strong) var(--surface); }
.opt { display: flex; justify-content: space-between; width: 100%; border: 0; border-radius: 0; background: none; padding: 0.35rem 0.7rem; text-align: left; font-weight: 400; }
.opt:hover { background: var(--sunk); }
.opt[data-selected="true"] { background: var(--cyan-wash); font-weight: 600; }
.opt[data-selected="true"] .v::before { content: "☑ "; color: var(--cyan-ink); }
.opt[data-selected="false"] .v::before { content: "☐ "; color: var(--muted); }
.opt .n { color: var(--muted); margin-left: 1rem; font-variant-numeric: tabular-nums; }
.none { color: var(--muted); padding: 0.35rem 0.7rem; margin: 0; }

/* Content pages (Changes, Charts): the full window width, like Search,
   sections spaced apart, each with its heading. */
.page { width: 100%; }
.page-head { margin: 0.25rem 0 1.75rem; }
.page-head h1 { margin: 0 0 0.3rem; }
.lede { margin: 0; color: var(--muted); font-size: 1rem; }
.page h2 { font-size: 1rem; line-height: 1.3; margin: 0 0 0.75rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem 1.25rem 1rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Changes: the per-load summary beside its explainer, then the log. */
.change-top { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.5rem 2.5rem; align-items: start; margin-bottom: 2.25rem; }
#change-summary { font-variant-numeric: tabular-nums; width: 100%; border-collapse: collapse; font-family: var(--data); font-size: 0.95rem; }
#change-summary th { text-align: left; font-weight: 600; color: var(--muted); padding: 0 0.6rem 0.5rem; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
#change-summary td { padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
#change-summary :is(th, td):first-child { padding-left: 0; }
#change-summary :is(th, td):last-child { padding-right: 0; }
#change-summary tbody tr:last-child td { border-bottom: 0; }
#change-summary td a { font-weight: 600; }
#change-summary tr[aria-current] td { background: var(--cyan-wash); }
#change-summary td.empty { color: var(--muted); }
#change-summary .bar-cell { width: 45%; padding-left: 0.9rem; padding-right: 0.9rem; }
.split { display: block; width: 100%; height: 0.85rem; overflow: visible; }
.split .rm, .key.rm { fill: var(--magenta); background: var(--magenta); }
.split .add, .key.add { fill: var(--cyan); background: var(--cyan); }
.split line { stroke: var(--line-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.rm-n { color: var(--magenta-text); }
.add-n { color: var(--cyan-ink); }
.legend { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; }
.legend .keys { display: flex; gap: 1rem; }
.legend .keys > span { display: inline-flex; align-items: center; gap: 0.4rem; }
.key { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 2px; }
.about { max-width: 40rem; color: var(--ink); font-size: 0.9rem; }
.about h2 { margin-bottom: 0.5rem; }
.about p, .about ul { margin: 0 0 0.65rem; }
.about ul { padding-left: 1.1rem; }
.about li { margin-bottom: 0.35rem; }
.about p:last-child { margin-bottom: 0; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem 1.5rem; margin: 0 0 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; margin: 0; }
.filters label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.filters select { min-width: 10rem; padding: 0.4rem 0.55rem; color: var(--ink); }
.toolbar .count { display: flex; align-items: center; gap: 0.75rem; margin-right: auto; padding-bottom: 0.2rem; }
.toolbar .count .note { margin: 0; }
.toolbar .button { margin-bottom: 0.05rem; }

#grid.changes { width: 100%; font-size: 0.95rem; }
#grid.changes th, #grid.changes td { padding: 0.55rem 0.9rem; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.chg { font-weight: 600; }
.chg-added { color: var(--cyan-ink); }
.chg-removed { color: var(--magenta-text); }
.pager { display: flex; gap: 1rem; align-items: center; margin: 1rem 0 0.5rem; }
.pager .note { margin: 0; }

/* History and charts */
.facts { display: flex; gap: 1.5rem; color: var(--muted); margin: 0 0 1rem; }
.facts b { color: var(--ink); font-variant-numeric: tabular-nums; }
#chart-wrap { position: relative; box-sizing: content-box; padding: 1.25rem 1.5rem 1.5rem; }
.charts-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
/* Two-way switch: the current choice is filled. */
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg a { padding: 0.45rem 1.1rem; font-weight: 600; font-size: 0.9rem; color: var(--ink); text-decoration: none; background: var(--surface); }
.seg a + a { border-left: 1px solid var(--line-strong); }
.seg a:hover { background: var(--sunk); }
.seg a[aria-current="page"] { background: var(--cyan); color: #0c2a33; }
/* .seg clips overflow for its rounded corners, so draw the focus ring inside. */
.seg a:focus-visible { outline-offset: -3px; }

/* Login: the one bold moment. The tile's dot grid becomes the page. */
body.auth {
  min-height: 100vh; display: flex; flex-direction: column;
  background-color: var(--page);
  background-image: radial-gradient(circle, rgb(73 184 211 / 0.28) 2px, transparent 2.5px);
  background-size: 26px 26px;
}
body.auth main { flex: 1; display: grid; place-items: center; padding: 2rem 1rem; }
body.auth footer { text-align: center; }
.login-card { width: min(24rem, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 2rem 1.75rem 1.5rem; }
.login-card { padding: 2.5rem 2rem 2rem; }
.login-card .logo { display: block; height: 5.5rem; width: auto; margin: 0 auto 2rem; }
.login-card h1, .login-card > .note, .login-card > .error { text-align: center; }
.login-card form { display: flex; flex-direction: column; gap: 0.5rem; }
.login-card label { font-weight: 600; }
.login-card input { font-size: 1.05rem; padding: 0.6rem 0.75rem; border-width: 2px; }
.login-card input:focus-visible { border-color: var(--cyan); outline-offset: 0; }
.login-card input#code { font-size: 1.6rem; letter-spacing: 0.35em; font-variant-numeric: tabular-nums; text-align: center; }
.login-card button { justify-content: center; padding: 0.65rem; font-size: 1rem; margin-top: 0.5rem; }
.login-card .note, .login-card .error { margin: 0 0 1.5rem; }
.login-card .again { margin: 1.25rem 0 0; font-size: 0.875rem; }

/* Narrower than the log table: the summary stacks above the explainer, and the
   table scrolls inside its own box (its header then no longer sticks to the window). */
@media (max-width: 64rem) {
  .change-top { grid-template-columns: minmax(0, 1fr); }
  .table-wrap { overflow-x: auto; border-radius: 8px; }
}
@media (max-width: 40rem) {
  nav { gap: 0.75rem; padding: 0.5rem 1rem; flex-wrap: wrap; }
  main { padding: 0.75rem 1rem; }
  body.search main > :not(.grid-wrap) { left: 1rem; width: calc(100cqw - 2rem); }
  .actions { margin-left: 0; }
  /* Phone: the split bars have no room; the numbers carry the summary. */
  #change-summary { font-size: 0.85rem; }
  #change-summary th, #change-summary td { padding-left: 0.35rem; padding-right: 0.35rem; }
  #change-summary .bar-cell, .legend .keys { display: none; }
  .panel { padding: 0.9rem 0.9rem 0.8rem; }
  .filters select { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #rows { transition: none; }
}
