:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2530;
  --muted: #6b7785;
  --line: #e3e7ec;
  --sidebar-w: 380px;
}
* { box-sizing: border-box; }
html, body {
  height: 100%; margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}

/* Layout: map fills, sidebar fixed width on the right */
#app { display: flex; height: 100vh; width: 100vw; overflow: hidden; }
#map { flex: 1; min-width: 0; background: var(--bg); }
.leaflet-container { background: var(--bg); outline: none; }

/* Polygons render as SVG → crisp on hi-dpi / large screens */
.lga-path { transition: filter 120ms ease, stroke-width 120ms ease; }
.lga-path:hover { filter: brightness(1.08); cursor: pointer; }

/* Right sidebar — aggregate view (statewide summary / LGA aggregate). */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  box-shadow: -6px 0 18px rgba(28,37,48,.04);
}

/* Left sidebar — submission feed view (top-100 globally / PU table for LGA). */
#left-sidebar {
  width: var(--left-w, 340px); flex: 0 0 var(--left-w, 340px);
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  box-shadow: 6px 0 18px rgba(28,37,48,.04);
}
.left-head {
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fafbfc 0%, var(--panel) 100%);
}
.left-head h2 { margin: 0; font-size: 16px; letter-spacing: .2px; }
.left-head .sub { margin-top: 3px; font-size: 11px; color: var(--muted); }
.left-body {
  flex: 1; overflow-y: auto;
  padding: 14px 14px 18px;
  opacity: 1; transition: opacity 160ms ease;
}
.left-body.swapping { opacity: 0; }
.side-head {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fafbfc 0%, var(--panel) 100%);
}
.side-head .crumb {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: none; padding: 0; cursor: pointer;
  color: var(--muted); font-size: 12px; margin-bottom: 6px;
}
.side-head .crumb[hidden] { display: none; }
.side-head .crumb:hover { color: var(--ink); }
.side-head h2 { margin: 0; font-size: 22px; letter-spacing: .2px; }
.side-head .sub { margin-top: 4px; font-size: 12px; color: var(--muted); }
.side-head .eyebrow {
  display: inline-block; font-size: 11px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  color: #1f78b4; margin-bottom: 6px;
}

/* Live update indicator */
.live-pill { display: inline-flex; align-items: center; gap: 6px; }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #2ecc71;
  animation: livePulse 2.2s ease-out infinite;
}
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0   rgba(46, 204, 113, .55); }
  70%  { box-shadow: 0 0 0 8px rgba(46, 204, 113, 0);   }
  100% { box-shadow: 0 0 0 0   rgba(46, 204, 113, 0);   }
}

.side-body {
  padding: 16px 20px; overflow-y: auto; flex: 1;
  opacity: 1; transition: opacity 160ms ease;
}
.side-body.swapping { opacity: 0; }

.leader {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 6px;
  background: #f7f9fb; border: 1px solid var(--line);
  margin-bottom: 12px;
}
.leader .lead-marks { display: flex; align-items: center; gap: 8px; }
.leader .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.leader .name  { font-size: 14px; font-weight: 600; }

.stat-row { display: flex; gap: 12px; margin-bottom: 14px; }
.stat {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fafbfc;
}
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 16px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v .sub { font-size: 11px; color: var(--muted); font-weight: 400; }

table.results { width: 100%; border-collapse: collapse; font-size: 13px; }
table.results th, table.results td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.results th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
table.results td.num { text-align: left; font-variant-numeric: tabular-nums; }
/* Color swatch — always rendered; mirrors what fills the LGA polygon on the
   map so the panel doubles as a legend even when every party has a logo. */
.pswatch {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; vertical-align: middle;
  border: 1px solid rgba(0,0,0,.08);
  margin-right: 6px;
}
.pswatch-lg {
  width: 16px; height: 16px; border-radius: 50%;
}
/* Logo is appended next to the swatch when the party has one uploaded.
   object-fit:contain keeps non-square logos readable inside a fixed box. */
.plogo {
  display: inline-block; width: 18px; height: 18px;
  object-fit: contain; vertical-align: middle; margin-right: 8px;
  border-radius: 3px;
}
.plogo-lg {
  width: 30px; height: 30px; border-radius: 4px; margin-right: 0;
}
.empty-note { color: var(--muted); font-size: 13px; padding: 10px 2px; }

/* ── Side panel feed tables (statewide top-100 + LGA PU list) ─────────── */
.side-body .hint {
  font-size: 11px; color: var(--muted); margin-bottom: 8px;
}
table.feed {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
}
table.feed th, table.feed td {
  padding: 6px 8px; text-align: left;
  border-bottom: 1px solid #f4f6f8; vertical-align: top;
}
table.feed th {
  position: sticky; top: 0; background: #fafbfc; z-index: 1;
  font-weight: 500; color: var(--muted);
  font-size: 10px; text-transform: uppercase; letter-spacing: .3px;
}
table.feed td.num, table.feed th.num {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
table.feed td.t { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
table.feed .pu { font-weight: 500; line-height: 1.25; }
table.feed .meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
table.feed .lead-id { font-weight: 500; }
table.feed tbody tr { cursor: pointer; }
table.feed tbody tr:hover { background: #f0f4f8; }
table.feed tr.pending td { color: #aab2bc; }
table.feed td.pending    { color: #aab2bc; }

/* PU table (LGA view) — non-clickable rows */
table.feed.pu-table tbody tr { cursor: default; }
table.feed.pu-table tbody tr:hover { background: transparent; }

.side-foot {
  padding: 10px 20px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; gap: 4px;
}
.side-foot-row { display: flex; justify-content: space-between; }
.side-foot-row.links a { color: var(--muted); text-decoration: none; }
.side-foot-row.links a:hover { color: var(--ink); text-decoration: underline; }

@media (max-width: 980px) {
  /* Stack panels: right (aggregate) on top, then map, then left (feed). */
  #app { flex-direction: column; }
  #sidebar      { order: 1; width: 100%; flex: 0 0 auto; border-left: none; border-bottom: 1px solid var(--line); box-shadow: none; }
  #map          { order: 2; min-height: 320px; flex: 1 1 320px; }
  #left-sidebar { order: 3; width: 100%; flex: 0 0 auto; border-right: none; border-top: 1px solid var(--line); box-shadow: none; }
}
