:root {
  --ink: #14181f;
  --muted: #5b6472;
  --line: #dfe3ea;
  --bg: #f6f7f9;
  --card: #fff;
  --brand: #0b6b3a;
  --brand-dark: #084d2a;
  --accent: #b3261e;
  --ok: #0b6b3a;
}

* { box-sizing: border-box; }

/* The browser's own [hidden] rule is display:none, but any class that sets a
   display -- .btn does -- outranks it, and the element stays on screen. That
   silently exposed the admin-only buttons to every visitor, so make [hidden]
   win outright. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 8px 14px;
  background: var(--ink);
}

.admin-flag {
  margin-right: auto;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .6px;
  color: #ffd66b;
}

.btn-small {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  border-color: #4a5261;
}
.btn-small:hover { background: #262c37; }

.notice {
  margin: 0;
  padding: 12px 16px;
  background: #fff6d8;
  border-bottom: 1px solid #e6d089;
  font-weight: 600;
  text-align: center;
}

/* dialogs */
.dlg {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  max-width: min(420px, 92vw);
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.dlg::backdrop { background: rgba(10,14,20,.45); }
.dlg h2 { margin: 0 0 6px; font-size: 20px; }
.dlg-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.btn-quiet { border: 0; background: none; color: var(--muted); }
.btn-quiet:hover { background: none; text-decoration: underline; }
.fld { display: block; margin-top: 12px; }
.fld span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.login-err { color: var(--accent); font-weight: 600; font-size: 14px; margin: 10px 0 0; }

.btn-breakdown {
  background: #123a63;
  border-color: #123a63;
  color: #fff;
}
.btn-breakdown:hover { background: #0d2a49; }

/* breakdown table */
.wide { max-width: 1500px; }
.scroller { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.scroller table { border: 0; border-radius: 0; }
.bd th, .bd td { white-space: nowrap; }
/* A full ballot is a lot of columns, so keep the numeric ones tight and let
   the table scroll sideways under a pinned polling unit name. */
.bd th.num, .bd td.num { padding-left: 10px; padding-right: 10px; min-width: 54px; }
.bd td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bd th.num { text-align: right; }
.bd tbody tr:hover td { background: #f9fafc; }
.bd .pu { position: sticky; left: 0; background: var(--card); white-space: normal; min-width: 240px; }
.bd tbody tr:hover .pu { background: #f9fafc; }
.bd thead .pu { background: #eef1f5; }
.bd tfoot td {
  font-weight: 700;
  font-size: 17px;
  background: #e6ebf1;
  border-top: 3px solid #8f9bab;
  border-bottom: 0;
}
.bd tfoot .pu { background: #e6ebf1; letter-spacing: .6px; }

.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill-none { background: #eef1f5; color: var(--muted); }
.pill-added { background: #e2f2e8; color: var(--brand-dark); }
.pill-revoked { background: #fde9e7; color: var(--accent); }

.bd td.struck { color: var(--muted); text-decoration: line-through; }
.why {
  margin-top: 5px;
  font-size: 12px;
  font-style: italic;
  color: #6b5416;
  white-space: normal;
  max-width: 260px;
}
.btn-revoke { color: var(--accent); border-color: #e9b7b2; background: #fff; }
.btn-revoke:hover { background: #fde9e7; }

.wd-h { font-size: 18px; margin: 26px 0 4px; }
.wd-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--card);
  margin-bottom: 8px;
}

.msg-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  background: var(--card);
}
.msg-head {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.audit { margin: 16px 0 22px; }
.audit h2 { font-size: 18px; margin: 0 0 10px; }
.audit-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  margin-bottom: 8px;
}

.toolbar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar label.grow { flex: 1 1 260px; display: flex; flex-direction: column; gap: 4px; }
.toolbar span { font-size: 13px; font-weight: 600; color: var(--muted); }
.chk { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; color: var(--muted); }
.chk input { width: auto; }

/* admin-only affordances on the public page */
.admin-box {
  margin-top: 8px;
  padding: 10px;
  border: 1px dashed #c8a54a;
  border-radius: 8px;
  background: #fffbef;
}
.admin-box p { margin: 0 0 8px; font-size: 13px; color: #6b5416; }

/* editable extracted result */
.edit-tbl { width: auto; min-width: 280px; border: 0; background: none; }
.edit-tbl th {
  background: none;
  border-bottom: 1px solid #e3d3a4;
  font-size: 12px;
  color: #6b5416;
  padding: 2px 6px;
}
.edit-tbl td { border: 0; padding: 3px 6px; }
.edit-tbl input {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
.edit-tbl .p-in { width: 120px; text-transform: uppercase; font-weight: 600; }
.edit-tbl .v-in { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.row-x {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
}
.row-x:hover { color: #7d1a15; }
.edit-err { color: var(--accent); font-weight: 600; font-size: 13px; margin: 6px 0 0; }

.hero {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 24px 16px 20px;
  text-align: center;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(26px, 5.2vw, 46px);
  letter-spacing: .5px;
  color: var(--brand-dark);
}

.sub {
  margin: 0 auto 20px;
  max-width: 760px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.totals h2 {
  margin: 0 0 10px;
  font-size: 18px;
  letter-spacing: 1px;
}

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 900px;
  margin: 0 auto;
}

.tile {
  min-width: 104px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tile .p { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .5px; }
.tile .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* One row per election: the label sits to the left of that election's tiles so
   the two contests can never be read as a single running total. Below the
   narrow breakpoint the label moves above its own tiles rather than shrinking
   into a column too thin to read. */
.totals-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  max-width: 900px;
  margin: 0 auto 12px;
  text-align: left;
}
.totals-row:last-child { margin-bottom: 0; }

.totals-label {
  flex: 0 0 auto;
  min-width: 190px;
  text-align: right;
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-dark);
}

/* The tiles keep their own centring inside the row. */
.totals-row .tiles { margin: 0; justify-content: flex-start; }

@media (max-width: 640px) {
  .totals-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .totals-label { min-width: 0; text-align: center; }
  .totals-row .tiles { justify-content: center; }
}

/* The Safe Harbour control sits above the site title, so it reads as a
   statement about the whole site rather than about the results below it. */
.hero-top { display: flex; justify-content: center; margin-bottom: 6px; }
#safe-harbour-btn { text-decoration: underline; font-weight: 600; }

.hero-note {
  margin: 0 auto 20px;
  max-width: 760px;
  font-size: 14px;
  font-weight: 700;
  color: var(--brand-dark);
  letter-spacing: .3px;
}

.sh-text { margin: 0 0 8px; line-height: 1.55; }

/* Uploads closed is a state of the whole portal, so it is coloured as a
   warning rather than as the ordinary location hint it replaces. */
.notice-closed {
  background: #fff4f3;
  border-color: #f0c9c6;
  color: #7d1a15;
  font-weight: 600;
}

.btn:disabled,
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.admin-actions { margin-top: 18px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #eef1f5; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-up { width: 100%; }

/* Declared after .btn and .btn-small on purpose: all three are single-class
   selectors, so at equal specificity the LAST one wins. Sitting above .btn,
   this rule was silently overridden and the button never turned red. */
.btn-danger,
.btn-small.btn-danger {
  background: #b3261e;
  border-color: #8f1e17;
  color: #fff;
}
.btn-danger:hover,
.btn-small.btn-danger:hover { background: #8f1e17; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }

.searches { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.searches label { flex: 1 1 280px; display: flex; flex-direction: column; gap: 4px; }
.searches span { font-size: 13px; font-weight: 600; color: var(--muted); }
.searches input {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--card);
}

.muted { color: var(--muted); font-size: 14px; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #eef1f5; font-size: 13px; letter-spacing: .3px; }
.col-upload { width: 200px; }
.col-ward { width: 230px; }
.col-extract { width: 210px; }

.pu-name { font-weight: 600; }
.pu-code { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.uploads-done {
  display: block;
  margin-top: 6px;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--brand);
  text-decoration: underline;
  cursor: pointer;
  text-align: left;
}
.done-note { color: var(--ok); font-weight: 700; }

.link-extract { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); text-decoration: underline; cursor: pointer; }

.detail td { background: #fbfcfd; }
/* The admin console renders the same card outside .detail, so the base rule
   lives here and .detail keeps only what differs. */
.card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 12px 0; background: #fff; }
.detail .card { padding: 10px; margin: 0 0 10px; }
.detail img { max-width: 220px; border-radius: 6px; border: 1px solid var(--line); display: block; margin-bottom: 8px; pointer-events: none; }
.detail table { border: 0; }
.detail td, .detail th { border-bottom: 1px dotted var(--line); padding: 4px 8px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge-ok { background: #e2f2e8; color: var(--brand-dark); }
.badge-no { background: #fde9e7; color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(560px, 92vw);
  background: #14181f;
  color: #fff;
  padding: 14px 18px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  z-index: 50;
}

footer { border-top: 1px solid var(--line); background: var(--card); padding: 18px 16px; text-align: center; }
footer p { margin: 0; color: var(--muted); font-size: 13px; }

/* messages + admin pages */
.page { max-width: 780px; margin: 0 auto; padding: 24px 16px 60px; }
.page h1 { font-size: 26px; text-align: left; }
.thread { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.msg { padding: 10px 12px; border-radius: 10px; max-width: 78%; }
.msg.user { align-self: flex-end; background: #dcefe3; }
.msg.admin { align-self: flex-start; background: #eef1f5; }
.msg .who { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
textarea, input[type=text], input[type=password] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: var(--card);
}
.row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .col-ward { display: none; }
  th.col-ward { display: none; }
  .col-upload { width: 130px; }
  .col-extract { width: 120px; }
  td, th { padding: 8px; }
}

/* Election tabs on the breakdown and upload-count pages. The active one is
   given .btn-primary in script, so the reader can see which contest is on
   screen without reading the URL. */
.election-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}

/* The archive is a different subject on the same page, so it is marked in a
   calmer colour than the "uploads closed" warning it sits beside. */
.notice-archive {
  background: #eef4fb;
  border-color: #c6d8ee;
  color: #1d3f66;
  font-weight: 600;
}

/* Test mode is loud on purpose: an admin looking at figures needs to know at a
   glance whether they are real or about to be deleted. */
.notice-test {
  background: #fff8e6;
  border: 1px solid #e8cf8a;
  color: #6b4e00;
  font-weight: 600;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 10px 0;
}

.totals-row[data-election="test"] .totals-label { color: #8a6100; }
.totals-row[data-election="test"] .tile { border-color: #e8cf8a; background: #fffdf6; }

/* "Click to approve uploaded results: N uploads" -- admin only. The count is
   polling units with photos, not photos, so it reads as a number of decisions
   waiting rather than a volume of traffic. */
.approve-line {
  margin: 16px auto 0;
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  font-weight: 700;
  color: var(--brand-dark);
}
.approve-line a {
  font-weight: 700;
  color: var(--brand-dark);
  text-decoration: underline;
}
.approve-line a:hover { color: #0b6b3a; }

/* One polling unit on the approve page: a header that opens the photos and the
   figures beneath it, so the decision and the evidence stay together. */
.pu-block { border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin: 10px 0; }

.pu-head {
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.pu-head:hover { background: var(--bg); }
.pu-head-main { display: flex; flex-direction: column; gap: 2px; }
.pu-head-meta { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.pu-head .chev { transition: transform .15s; display: inline-block; }
.pu-head.open .chev { transform: rotate(90deg); }

.pu-body { padding: 0 14px 14px; }
.pu-body .card:first-child { margin-top: 0; }

/* The figures under a photo after approval. These are what was COUNTED, which
   is not always what OCR read -- the caption says which, so a corrected figure
   is never mistaken for a misreading that went into the totals. */
.fig-caption {
  margin: 8px 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--brand-dark);
}
.fig-was { margin: 6px 0 0; font-size: 12px; font-style: italic; }
.fig-final { max-width: 320px; }

/* Upload video sits beneath Upload photo. It is deliberately the quieter of
   the two: a photo is what feeds the count, a video is supporting evidence. */
.btn-video {
  margin-top: 6px;
  background: var(--card);
  color: var(--brand-dark);
  border-color: var(--brand-dark);
}
.btn-video:hover { background: #eef4ef; }

/* The video block under a polling unit. An ordinary visitor sees the count and
   the notice; an admin sees the recordings and the uploader's email. */
.video-note {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand-dark);
  border-radius: 8px;
  background: var(--card);
}
.video-note .btn { margin-left: 10px; }
.video-held-inline { margin: 8px 0 0; font-style: italic; }

.video-item { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.video-item:first-of-type { border-top: 0; }
.video-item video {
  display: block;
  margin: 8px 0;
  max-width: 100%;
  width: 420px;
  border-radius: 8px;
  background: #000;
}
.video-email { font-size: 13px; }
