/*
 * One stylesheet for all three pages. Tokens first, then components.
 *
 * The chart colors are the data-viz palette's validated steps, declared here as
 * roles so light and dark swap in one place and nothing downstream ever names a
 * hex. Dark values are declared twice on purpose: the media query answers the OS
 * setting, the [data-theme] scope answers the page's own toggle, and the toggle
 * has to win in both directions.
 */

:root {
  color-scheme: light;

  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --surface-sunk: #f2f1ed;

  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;

  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);

  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.13);
  --accent-ink: #184f95;
  --series-2: #eb6834;
  --series-2-soft: rgba(235, 104, 52, 0.13);

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --grid: #e1e0d9;
  --individual: #898781;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 8px 24px -12px rgba(11, 11, 11, 0.14);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --surface-sunk: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --line: #2c2c2a;
    --line-strong: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.18);
    --accent-ink: #86b6ef;
    --series-2: #d95926;
    --series-2-soft: rgba(217, 89, 38, 0.18);
    --grid: #2c2c2a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --surface-sunk: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;
  --line: #2c2c2a;
  --line-strong: #383835;
  --ring: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.18);
  --accent-ink: #86b6ef;
  --series-2: #d95926;
  --series-2-soft: rgba(217, 89, 38, 0.18);
  --grid: #2c2c2a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
}

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

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

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 20px 96px;
}
.wrap--wide {
  max-width: 1180px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}
.masthead h1 {
  font-size: 1.3rem;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
}
.masthead p {
  margin: 2px 0 0;
  color: var(--ink-2);
  font-size: 0.9rem;
}
.masthead .org {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-muted);
  font-weight: 600;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card + .card {
  margin-top: 18px;
}
.card h2 {
  margin: 0 0 4px;
  font-size: 1.02rem;
  font-weight: 640;
}
.card .sub {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: 0.88rem;
}

/* ---------- ballot ---------- */

.item {
  padding: 22px 0;
  border-top: 1px solid var(--line);
}
.item:first-of-type {
  border-top: 0;
  padding-top: 4px;
}
.item h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 620;
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.item h3 .n {
  color: var(--ink-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  flex: none;
}
.item .blurb {
  margin: 0 0 16px 26px;
  color: var(--ink-2);
  font-size: 0.87rem;
}

.scale {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  /* It is a <fieldset> so the five radios are one labelled group for screen
     readers; the reset is what stops the UA drawing its box around them. */
  border: 0;
  padding: 0;
  margin: 0 0 0 26px;
  min-width: 0;
}
.scale label {
  flex: 1 1 96px;
  min-width: 88px;
  cursor: pointer;
}
.scale input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.scale .box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.scale .box .v {
  font-size: 1.02rem;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
}
.scale .box .t {
  font-size: 0.7rem;
  color: var(--ink-2);
  text-align: center;
  line-height: 1.25;
}
.scale label:hover .box {
  border-color: var(--accent);
}
.scale input:focus-visible + .box {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.scale input:checked + .box {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.scale input:checked + .box .t {
  color: rgba(255, 255, 255, 0.9);
}

/* ---------- buttons & controls ---------- */

.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: filter 0.12s, opacity 0.12s;
}
.btn:hover:not(:disabled) {
  filter: brightness(1.07);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn--ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn--ghost:hover:not(:disabled) {
  border-color: var(--ink-muted);
  filter: none;
}
.btn--danger {
  background: var(--critical);
  border-color: var(--critical);
}
.btn--sm {
  padding: 6px 12px;
  font-size: 0.83rem;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row--end {
  justify-content: flex-end;
}
.spacer {
  flex: 1;
}

input[type="text"],
input[type="password"],
select {
  font: inherit;
  font-size: 0.92rem;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
}
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
label.field {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--ink-2);
}
.toggle input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

/* ---------- notices ---------- */

.notice {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.88rem;
  border: 1px solid var(--ring);
  background: var(--surface-sunk);
  color: var(--ink-2);
  display: flex;
  gap: 9px;
  align-items: flex-start;
}
.notice b {
  color: var(--ink);
  font-weight: 640;
}
.notice--error {
  border-color: var(--critical);
  color: var(--ink);
}
.notice--good {
  border-color: var(--good);
}
.notice .ico {
  flex: none;
  line-height: 1.5;
}

/* ---------- empty / big states ---------- */

.state {
  text-align: center;
  padding: 64px 20px;
}
.state .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-muted);
  display: inline-block;
  margin-right: 8px;
}
.state[data-live="yes"] .dot {
  background: var(--good);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}
.state h2 {
  font-size: 1.15rem;
  margin: 0 0 8px;
  font-weight: 640;
}
.state p {
  color: var(--ink-2);
  margin: 0 auto;
  max-width: 44ch;
  font-size: 0.92rem;
}

/* ---------- big count ---------- */

.count {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.count .fig {
  font-size: 3.6rem;
  font-weight: 680;
  line-height: 1;
  letter-spacing: -0.03em;
}
.count .cap {
  color: var(--ink-2);
  font-size: 0.9rem;
}

/* ---------- tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.tile {
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--surface);
}
.tile .k {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 660;
  margin-bottom: 7px;
}
.tile .v {
  font-size: 1.02rem;
  font-weight: 620;
  line-height: 1.3;
}
.tile .m {
  font-size: 0.82rem;
  color: var(--ink-2);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- table ---------- */

.tablewrap {
  overflow-x: auto;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}
th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}
th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
  font-weight: 660;
  white-space: nowrap;
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tbody tr:hover {
  background: var(--surface-sunk);
}

/* range bar inside the table */
.bar {
  position: relative;
  height: 10px;
  min-width: 120px;
}
.bar .track {
  position: absolute;
  inset: 4px 0;
  background: var(--line);
  border-radius: 2px;
}
.bar .span {
  position: absolute;
  top: 3px;
  height: 4px;
  background: var(--accent-soft);
  border-radius: 2px;
}
.bar .mean {
  position: absolute;
  top: 0;
  width: 3px;
  height: 10px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---------- chart ---------- */

.chartbox {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.radar {
  width: 100%;
  max-width: 820px;
  height: auto;
  display: block;
  /* The host div is full-card-width; without this the capped SVG hugs the left
     edge instead of sitting under the middle of the card. */
  margin: 0 auto;
  overflow: visible;
}
.radar text {
  font-family: var(--font);
}

.legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
  font-size: 0.84rem;
  color: var(--ink-2);
}
.legend .key {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.legend .swatch {
  width: 22px;
  height: 3px;
  border-radius: 2px;
  flex: none;
}
.legend .swatch--band {
  height: 12px;
  border-radius: 3px;
}
.legend .swatch--thin {
  height: 1.5px;
}

.tip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--ring);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 0.83rem;
  max-width: 260px;
  opacity: 0;
  transition: opacity 0.1s;
}
.tip[data-show="yes"] {
  opacity: 1;
}
.tip .tt {
  font-weight: 640;
  margin-bottom: 5px;
}
.tip dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 12px;
}
.tip dt {
  color: var(--ink-2);
}
.tip dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---------- "the next poll has started" bar ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--ring);
  box-shadow: 0 6px 20px -12px rgba(11, 11, 11, 0.35);
  font-size: 0.9rem;
}
.topbar-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  flex: none;
  animation: pulse 2s ease-in-out infinite;
}
.topbar-text {
  min-width: 0;
}
.topbar-text b {
  font-weight: 660;
}
#topbarCount {
  color: var(--ink-2);
}
.topbar .btn {
  text-decoration: none;
  white-space: nowrap;
}
/* Push the page down so the bar never covers the masthead. */
body.has-topbar .wrap {
  padding-top: 84px;
}

@media (max-width: 560px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar .spacer {
    display: none;
  }
  body.has-topbar .wrap {
    padding-top: 116px;
  }
}

/* ---------- misc ---------- */

.hint {
  font-size: 0.82rem;
  color: var(--ink-muted);
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}
.linkline {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface-sunk);
  border: 1px solid var(--ring);
  border-radius: 8px;
  padding: 8px 8px 8px 12px;
}
.linkline .u {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a {
  color: var(--accent-ink);
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media print {
  body {
    background: #fff;
  }
  .no-print {
    display: none !important;
  }
  .card {
    box-shadow: none;
    border-color: #ccc;
    break-inside: avoid;
  }
}

@media (max-width: 560px) {
  .wrap {
    padding: 20px 14px 72px;
  }
  .scale {
    margin-left: 0;
  }
  .item .blurb {
    margin-left: 0;
  }
  .count .fig {
    font-size: 2.8rem;
  }
}
