/* State tabs */
.state-tabs {
  display: flex; gap: 4px; padding: 10px 16px 0;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.state-tab {
  padding: 8px 18px; border: none; border-radius: 6px 6px 0 0;
  background: var(--bg-deeper); color: var(--text-muted);
  cursor: pointer; font-size: 0.8rem; font-weight: 600;
  white-space: nowrap; transition: all 0.15s;
}
.state-tab:hover { background: var(--border); color: var(--text); }
.state-tab.active { background: var(--accent); color: #fff; }

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

:root {
  --bg: #08091a;
  --surface: #0f1228;
  --card: #121630;
  --card-hover: #161a38;
  --border: #1e2245;
  --border-light: #252a50;
  --text: #e4e8ff;
  --text-muted: #6b729a;
  --text-dim: #9299bf;
  --accent: #5b7fff;
  --accent-dim: rgba(91,127,255,0.15);
  --green: #22c55e;
  --green-dim: rgba(34,197,94,0.15);
  --amber: #f59e0b;
  --amber-dim: rgba(245,158,11,0.15);
  --red: #f43f5e;
  --red-dim: rgba(244,63,94,0.15);
  --nota: #a78bfa;
  --nota-dim: rgba(167,139,250,0.15);
  --majority: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --bg-card: #0f1228;
  --bg-deeper: #0b0d1f;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  min-height: 100vh;
  padding-bottom: 80px;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
header {
  background: linear-gradient(180deg, #0d0f24 0%, #0f1228 100%);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px 10px;
  position: sticky;
  top: 0;
  z-index: 200;
  backdrop-filter: blur(12px);
}
.header-top {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.header-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  flex: 1;
  min-width: 200px;
  letter-spacing: -0.01em;
}
.header-title .accent { color: var(--accent); }
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(244,63,94,0.12);
  border: 1px solid rgba(244,63,94,0.3);
  color: #fb7185;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.06em;
}
.live-dot {
  width: 6px; height: 6px;
  background: #fb7185;
  border-radius: 50%;
  animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { opacity:1; transform:scale(1); }
  50% { opacity:0.3; transform:scale(0.7); }
}
.header-meta { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

/* enrichment bar */
.enrich-wrap {
  max-width: 1440px;
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.enrich-label { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; }
.enrich-track {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.enrich-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  border-radius: 2px;
  transition: width 0.4s ease;
}
.enrich-pct { font-size: 0.68rem; color: var(--accent); font-weight: 600; }

/* ══════════════════════════════════════
   LAYOUT
══════════════════════════════════════ */
main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 16px;
}

.section-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ══════════════════════════════════════
   SEAT TALLY BAR
══════════════════════════════════════ */
.tally-section { margin-bottom: 28px; }
.tally-outer { position: relative; padding-top: 22px; }

.tally-bar {
  height: 44px;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  background: var(--border);
  box-shadow: var(--shadow-sm);
}
@keyframes segSlideIn {
  from { opacity: 0; transform: scaleX(0); transform-origin: left; }
  to   { opacity: 1; transform: scaleX(1); }
}
.tally-seg {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: width 0.7s cubic-bezier(0.4,0,0.2,1);
  position: relative;
  cursor: default;
  flex-shrink: 0;
}
.tally-seg-new { animation: segSlideIn 0.4s cubic-bezier(0.4,0,0.2,1); }
.tally-seg-label {
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  padding: 0 6px;
  pointer-events: none;
}

.majority-marker {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 5;
  pointer-events: none;
}
.majority-line {
  width: 2px;
  height: 44px;
  background: var(--majority);
  box-shadow: 0 0 8px rgba(251,191,36,0.6);
}
.majority-label-top {
  position: absolute;
  top: -18px;
  font-size: 0.62rem;
  color: var(--majority);
  font-weight: 700;
  white-space: nowrap;
  transform: translateX(-50%);
  background: var(--bg);
  padding: 0 3px;
}

.tally-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.tally-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
}
.tally-pill-seats { font-size: 1rem; }
.tally-pill-pct { font-size: 0.65rem; opacity: 0.7; font-weight: 400; }

/* ══════════════════════════════════════
   SUMMARY STATS
══════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}
@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 400px) { .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; } }

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0.4;
}
.stat-card.nota::before { background: var(--nota); opacity: 0.6; }
.stat-card.win::before { background: var(--green); opacity: 0.5; }
.stat-card.closest::before { background: var(--amber); opacity: 0.6; }

.stat-label { font-size: 0.62rem; color: var(--text-muted); letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 6px; }
.stat-value { font-size: 1.5rem; font-weight: 800; color: #fff; letter-spacing: -0.02em; line-height: 1; }
.stat-sub { font-size: 0.7rem; color: var(--text-dim); margin-top: 5px; line-height: 1.3; }
@keyframes valFlip {
  0%   { opacity: 0.3; transform: translateY(6px) scale(0.96); }
  100% { opacity: 1;   transform: none; }
}
.val-flip { animation: valFlip 0.3s cubic-bezier(0.34,1.56,0.64,1); }
.stat-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: 4px;
}

/* mandate overview strip */
.mandate-strip {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.mandate-chip {
  flex: 1;
  min-width: 100px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: center;
}
.mandate-chip-count { font-size: 1.6rem; font-weight: 800; color: #fff; line-height: 1; }
.mandate-chip-label { font-size: 0.65rem; color: var(--text-muted); margin-top: 4px; }
.mandate-chip.landslide { border-top: 2px solid var(--green); }
.mandate-chip.clear { border-top: 2px solid var(--accent); }
.mandate-chip.plurality { border-top: 2px solid var(--amber); }
.mandate-chip.thin { border-top: 2px solid var(--red); }

/* ══════════════════════════════════════
   NOTA PROTEST SECTION
══════════════════════════════════════ */
.nota-section {
  background: linear-gradient(135deg, #12102e 0%, #14102c 50%, #100e2a 100%);
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}
.nota-section::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(167,139,250,0.12) 0%, transparent 70%);
  pointer-events: none;
}
.nota-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.nota-headline {
  flex: 1;
}
.nota-icon { font-size: 1.2rem; margin-bottom: 4px; }
.nota-title {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--nota);
  margin-bottom: 6px;
}
.nota-big-number {
  font-size: 2.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.03em;
  line-height: 1;
}
.nota-big-sub {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 5px;
}
.nota-big-sub strong { color: var(--nota); }

.nota-stats-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.nota-stat-item {
  background: rgba(167,139,250,0.08);
  border: 1px solid rgba(167,139,250,0.15);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 120px;
}
.nota-stat-label { font-size: 0.6rem; color: var(--nota); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 3px; }
.nota-stat-val { font-size: 1rem; font-weight: 700; color: #fff; }

.nota-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.nota-list-title { font-size: 0.68rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.nota-list { display: flex; flex-direction: column; gap: 6px; }
.nota-item {
  display: grid;
  grid-template-columns: 18px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(167,139,250,0.06);
  border-radius: 8px;
  border: 1px solid rgba(167,139,250,0.1);
}
.nota-rank { font-size: 0.7rem; color: var(--text-muted); font-weight: 700; text-align: center; }
.nota-item-name { font-size: 0.78rem; font-weight: 600; color: var(--text); }
.nota-item-district { font-size: 0.62rem; color: var(--text-muted); }
.nota-item-bar-wrap {
  width: 80px;
}
.nota-item-bar-track { height: 5px; background: rgba(167,139,250,0.15); border-radius: 3px; overflow: hidden; }
.nota-item-bar-fill { height: 100%; background: var(--nota); border-radius: 3px; }
.nota-item-pct { font-size: 0.72rem; font-weight: 700; color: var(--nota); text-align: right; min-width: 36px; }
.nota-item-votes { font-size: 0.65rem; color: var(--text-muted); text-align: right; }

@media (max-width: 600px) {
  .nota-big-number { font-size: 1.8rem; }
  .nota-item { grid-template-columns: 18px 1fr auto; }
  .nota-item-bar-wrap { display: none; }
  .nota-section { padding: 16px; }
}

/* ══════════════════════════════════════
   DISTRICT TABS
══════════════════════════════════════ */
.district-scroll {
  overflow-x: auto;
  margin-bottom: 16px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.district-scroll::-webkit-scrollbar { display: none; }
.district-tabs {
  display: flex;
  gap: 6px;
  white-space: nowrap;
  padding: 2px 0;
}
.d-tab {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.d-tab:hover { border-color: var(--accent); color: var(--text); }
.d-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ══════════════════════════════════════
   FILTERS
══════════════════════════════════════ */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.search-input {
  flex: 1;
  min-width: 180px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.search-input::placeholder { color: var(--text-muted); }
.filter-select {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--accent); }
.filter-select option { background: var(--surface); }
.results-count { font-size: 0.73rem; color: var(--text-muted); margin-left: auto; }

/* ══════════════════════════════════════
   CONSTITUENCY CARDS GRID
══════════════════════════════════════ */
.c-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 960px) { .c-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .c-grid { grid-template-columns: 1fr; } }

/* ══════════════════════════════════════
   CONSTITUENCY CARD
══════════════════════════════════════ */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.c-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  position: relative;
  overflow: hidden;
  animation: cardIn 0.3s ease both;
  animation-delay: calc(var(--i, 0) * 18ms);
}
.c-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  background: var(--card-hover);
}
.c-card.updated { animation: flash 0.5s ease both; }
@keyframes flash {
  0%  { background: rgba(91,127,255,0.12); box-shadow: 0 0 0 2px rgba(91,127,255,0.3); }
  100%{ background: var(--card); box-shadow: none; }
}
.c-card.awaited { opacity: 0.45; }

/* card header */
.c-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 8px;
}
.c-title-block {}
.c-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.c-meta { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }
.c-district-pill {
  font-size: 0.6rem;
  background: var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  align-self: flex-start;
}

/* EVM progress */
.evm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.evm-label-text { font-size: 0.6rem; color: var(--text-muted); white-space: nowrap; }
.evm-count { font-size: 0.6rem; color: var(--text-dim); white-space: nowrap; }
.evm-track {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.evm-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* winner row */
.winner-block {
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  padding: 10px 11px 8px;
  margin-bottom: 8px;
}
.winner-top {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}
.party-badge {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.winner-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.winner-votes { font-size: 1.05rem; font-weight: 800; color: #fff; white-space: nowrap; }
.winner-pct {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  margin-left: 4px;
}

/* vote share bar */
.vote-bar-track {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.vote-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* mandate badge */
.mandate-badge {
  display: inline-flex;
  font-size: 0.58rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 4px;
}
.mandate-landslide { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.2); }
.mandate-clear { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(91,127,255,0.2); }
.mandate-plurality { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(245,158,11,0.2); }
.mandate-thin { background: var(--red-dim); color: var(--red); border: 1px solid rgba(244,63,94,0.2); }

/* runner-up row */
.runner-block {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  padding: 0 2px;
}
.runner-name { font-size: 0.73rem; color: var(--text-muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.runner-votes { font-size: 0.73rem; color: var(--text-dim); white-space: nowrap; }
.runner-pct { font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; margin-left: 2px; }
.runner-margin { font-size: 0.65rem; color: var(--red); white-space: nowrap; font-weight: 600; }

/* card footer */
.c-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
}
.total-votes-label { font-size: 0.63rem; color: var(--text-muted); }
.nota-inline {
  font-size: 0.63rem;
  color: var(--nota);
  font-weight: 600;
}
.expand-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  cursor: pointer;
  padding: 2px 0;
  white-space: nowrap;
  flex-shrink: 0;
}
.expand-btn:hover { color: var(--text); }
.expand-icon { transition: transform 0.2s; display: inline-block; }
.expand-icon.open { transform: rotate(180deg); }

/* extra candidates */
.extra-wrap {
  display: none;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.extra-wrap.open { display: block; }

.extra-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.extra-row:last-child { border-bottom: none; }
.extra-party { font-size: 0.58rem; font-weight: 700; padding: 1px 5px; border-radius: 4px; white-space: nowrap; }
.extra-name { font-size: 0.7rem; color: var(--text-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.extra-bar-wrap { width: 50px; }
.extra-bar-track { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.extra-bar-fill { height: 100%; border-radius: 2px; background: var(--border-light); }
.extra-votes { font-size: 0.68rem; color: var(--text-muted); text-align: right; white-space: nowrap; }
.extra-pct { font-size: 0.63rem; color: var(--text-muted); text-align: right; white-space: nowrap; min-width: 32px; }

.nota-extra-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  margin-top: 2px;
  border-top: 1px dashed rgba(167,139,250,0.2);
}
.nota-extra-label { font-size: 0.62rem; font-weight: 700; color: var(--nota); font-style: italic; padding: 1px 5px; }
.nota-extra-bar-wrap { width: 50px; }
.nota-extra-bar-track { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.nota-extra-bar-fill { height: 100%; background: var(--nota); border-radius: 2px; }
.nota-extra-votes { font-size: 0.68rem; color: var(--nota); text-align: right; white-space: nowrap; }
.nota-extra-pct { font-size: 0.63rem; color: var(--nota); text-align: right; white-space: nowrap; min-width: 32px; font-weight: 600; }

/* loading hint */
.loading-hint { font-size: 0.7rem; color: var(--text-muted); animation: blink 1.5s ease-in-out infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.35; } }

/* awaited badge */
.awaited-badge {
  font-size: 0.68rem;
  background: var(--border);
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 10px;
}

/* ══════════════════════════════════════
   TOAST
══════════════════════════════════════ */
#toast-wrap {
  position: fixed;
  bottom: 20px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 999;
  pointer-events: none;
  max-width: 280px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  font-size: 0.73rem;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease;
}
.toast.out { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:none; } }
@keyframes toastOut { to { opacity:0; transform:translateX(10px); } }

/* ══════════════════════════════════════
   MOBILE TWEAKS
══════════════════════════════════════ */
@media (max-width: 560px) {
  main { padding: 16px 12px; }
  .header-title { font-size: 0.9rem; }
  .tally-bar { height: 36px; }
  .nota-big-number { font-size: 1.7rem; }
  .stat-value { font-size: 1.25rem; }
  .mandate-strip { gap: 6px; }
  .mandate-chip { min-width: 80px; padding: 8px 10px; }
  .mandate-chip-count { font-size: 1.3rem; }
  .extra-row { grid-template-columns: auto 1fr auto auto; }
  .extra-bar-wrap { display: none; }
  .nota-extra-bar-wrap { display: none; }
  #toast-wrap { right: 8px; left: 8px; max-width: none; }
}
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .c-name { font-size: 0.82rem; }
}

/* ══════════════════════════════════════
   DISTRICT MAP SECTION
══════════════════════════════════════ */
.map-section {
  margin-bottom: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}

.map-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  background: linear-gradient(90deg, rgba(91,127,255,0.06) 0%, transparent 60%);
  border-bottom: 1px solid transparent;
  transition: background 0.15s;
}
.map-section-header:hover { background: linear-gradient(90deg, rgba(91,127,255,0.1) 0%, transparent 60%); }
.map-section-header .section-label { color: var(--text-dim); }
.map-toggle-icon { font-size: 0.75rem; color: var(--text-muted); }

.map-body {
  display: none;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.map-body.open { display: block; }

.map-layout {
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 12px;
  height: 520px;
}

#wb-map {
  height: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #08091a;
  z-index: 1;
}

/* Leaflet overrides */
.leaflet-container { background: #08091a !important; font-family: inherit; }
.leaflet-control-zoom a {
  background: var(--card) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--card-hover) !important; }
.leaflet-control-attribution {
  background: rgba(8,9,26,0.7) !important;
  color: var(--text-muted) !important;
  font-size: 0.6rem !important;
}
.leaflet-control-attribution a { color: var(--text-muted) !important; }

.map-tooltip {
  background: #0f1228 !important;
  border: 1px solid var(--border-light) !important;
  color: var(--text) !important;
  font-size: 0.78rem !important;
  font-family: inherit !important;
  border-radius: 6px !important;
  box-shadow: var(--shadow-sm) !important;
  padding: 6px 10px !important;
}
.map-tooltip b { color: #fff; }
.leaflet-tooltip-top.map-tooltip::before { border-top-color: var(--border-light) !important; }

.map-unavail {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 24px;
  text-align: center;
}

/* ── District Panel ── */
#map-district-panel {
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
}

.dpanel-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 10px;
}
.dpanel-placeholder-icon { font-size: 2rem; opacity: 0.3; }
.dpanel-placeholder-text { font-size: 0.75rem; color: var(--text-muted); line-height: 1.6; }

.dpanel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
.dpanel-title { font-size: 0.95rem; font-weight: 700; color: #fff; line-height: 1.2; }
.dpanel-sub   { font-size: 0.65rem; color: var(--text-muted); margin-top: 3px; }
.dpanel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.dpanel-close:hover { background: var(--border); color: var(--text); }

.dpanel-nota-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(167,139,250,0.06);
  border-bottom: 1px solid var(--border);
}
.dpanel-nota-label { font-size: 0.62rem; font-weight: 700; color: var(--nota); text-transform: uppercase; letter-spacing: 0.06em; }
.dpanel-nota-val   { font-size: 0.88rem; font-weight: 700; color: var(--nota); }
.dpanel-nota-pct   { font-size: 0.65rem; color: var(--text-muted); margin-left: auto; }

.dpanel-section-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 14px 6px;
}
.dpanel-parties { padding: 0 14px 4px; }
.dpanel-party-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.dpanel-party-row:last-child { border-bottom: none; }
.dpanel-party-badge {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
}
.dpanel-party-bar-wrap { flex: 1; }
.dpanel-party-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.dpanel-party-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.dpanel-party-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  min-width: 38px;
  text-align: right;
}
.dpanel-party-pct { font-size: 0.62rem; color: var(--text-muted); font-weight: 400; }

.dpanel-const-list {
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dpanel-const-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}
.dpanel-const-row:hover { background: var(--border); }
.dpanel-const-no   { font-size: 0.6rem; color: var(--text-muted); text-align: right; }
.dpanel-const-name { font-size: 0.73rem; color: var(--text-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dpanel-const-party {
  font-size: 0.58rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}
.dpanel-empty { font-size: 0.73rem; color: var(--text-muted); padding: 8px 0; }

@media (max-width: 768px) {
  .map-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  #wb-map { height: 360px; }
  #map-district-panel {
    height: 320px;
    max-height: 400px;
  }
}
@media (max-width: 480px) {
  #wb-map { height: 280px; }
  .map-section-header { padding: 10px 12px; }
}

/* ══════════════════════════════════════
   MAP MODE TABS (2026 / 2021 / Swing)
══════════════════════════════════════ */
.map-mode-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-deeper);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px;
  flex-shrink: 0;
}
.map-mode-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  letter-spacing: 0.03em;
}
.map-mode-tab:hover { color: var(--text); background: var(--border); }
.map-mode-tab.active {
  background: var(--accent);
  color: #fff;
}
@media (max-width: 480px) {
  .map-mode-tab { padding: 3px 8px; font-size: 0.65rem; }
}

/* ══════════════════════════════════════
   CLICKABLE STAT CARDS & MANDATE CHIPS
══════════════════════════════════════ */
.stat-card { cursor: pointer; }
.stat-card:hover { border-color: rgba(255,255,255,0.18); }
.mandate-chip { cursor: pointer; }
.mandate-chip:hover { border-color: rgba(255,255,255,0.18); }
.tally-pill { cursor: pointer; transition: opacity 0.15s, transform 0.12s; }
.tally-pill:hover { opacity: 0.85; transform: scale(1.04); }

/* ══════════════════════════════════════
   DETAIL DRAWER
══════════════════════════════════════ */
#detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#detail-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

#detail-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border-light);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
  max-height: 72vh;
  z-index: 901;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
}
#detail-drawer.open {
  transform: translateY(0);
}

.drawer-handle-bar {
  width: 36px;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}
.drawer-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.drawer-close {
  background: var(--border);
  border: none;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.drawer-close:hover { background: var(--border-light); color: var(--text); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px 24px;
  -webkit-overflow-scrolling: touch;
}

/* Drawer district section */
.drawer-district-section {
  margin-bottom: 16px;
}
.drawer-district-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.drawer-chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Constituency chip inside drawer */
.drawer-const-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  color: var(--text-dim);
}
.drawer-const-chip:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text);
}
.drawer-const-chip .chip-no {
  font-size: 0.62rem;
  color: var(--text-muted);
}
.drawer-const-chip .chip-margin {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-left: 2px;
}

/* Candidate breakdown row in drawer */
.drawer-candidate-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.drawer-candidate-row.winner {
  border-color: var(--border-light);
  background: rgba(255,255,255,0.04);
}
.drawer-cand-party {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  flex-shrink: 0;
  min-width: 42px;
  text-align: center;
}
.drawer-cand-info { flex: 1; min-width: 0; }
.drawer-cand-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-cand-sub { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }
.drawer-cand-votes {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
}
.drawer-cand-pct {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.drawer-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 20px 0;
  text-align: center;
}
.drawer-section-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 14px 0 8px;
}

/* Top-votes rows */
.drawer-votes-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 7px;
  margin-bottom: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.drawer-votes-rank { font-size: 0.65rem; color: var(--text-muted); width: 18px; text-align: right; flex-shrink: 0; }
.drawer-votes-name { flex: 1; font-size: 0.78rem; color: var(--text-dim); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-votes-val  { font-size: 0.82rem; font-weight: 700; color: #fff; white-space: nowrap; }

@media (max-width: 560px) {
  #detail-drawer { max-height: 88vh; border-radius: 12px 12px 0 0; }
  .drawer-header { padding: 6px 14px 10px; }
  .drawer-title { font-size: 0.95rem; }
  .drawer-close { width: 32px; height: 32px; font-size: 1rem; }
  .drawer-body { padding: 10px 12px 28px; }

  /* Switch chips to full-width rows on mobile */
  .drawer-chips-wrap { flex-direction: column; gap: 0; }
  .drawer-const-chip {
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 0.8rem;
    width: 100%;
    justify-content: flex-start;
    border-left-width: 3px;
    border-top: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
  }
  .drawer-const-chip:first-child { border-radius: 6px 6px 0 0; }
  .drawer-const-chip:last-child { border-bottom: none; border-radius: 0 0 6px 6px; }
  .drawer-chips-wrap { background: var(--surface); border-radius: 6px; border: 1px solid var(--border); }
  .chip-margin { margin-left: auto; font-weight: 700; }

  /* Candidate rows on mobile */
  .drawer-candidate-row { padding: 10px 0; gap: 8px; }
  .drawer-cand-name { font-size: 0.82rem; }
  .drawer-cand-votes { font-size: 0.9rem; }

  .drawer-district-label { font-size: 0.65rem; margin-top: 14px; }
}

/* ══════════════════════════════════════
   DISTRICT PANEL — 2026 vs 2021
══════════════════════════════════════ */
.dpanel-comp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}
.dpanel-comp-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.58rem;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.dpanel-comp-dot-26 {
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.9;
  display: inline-block;
}
.dpanel-comp-dot-21 {
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--text-muted);
  opacity: 0.45;
  display: inline-block;
}

.dpanel-comp-list {
  padding: 0 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.dpanel-comp-row {
  display: grid;
  grid-template-columns: 40px 1fr 36px 18px;
  align-items: center;
  gap: 6px;
}
.dpanel-comp-badge { font-size: 0.58rem !important; padding: 2px 5px !important; min-width: 36px; text-align: center; }
.dpanel-comp-bars {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dpanel-comp-bar {
  height: 5px;
  border-radius: 2px;
  transition: width 0.5s ease;
  min-width: 2px;
}
.dpanel-comp-bar-26 { opacity: 0.9; }
.dpanel-comp-bar-21 { opacity: 0.3; }
.dpanel-comp-nums {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}
.dpanel-comp-cur  { font-size: 0.72rem; font-weight: 700; color: #fff; }
.dpanel-comp-prev { font-size: 0.6rem;  color: var(--text-muted); }
.dpanel-comp-delta {
  font-size: 0.65rem;
  font-weight: 700;
  text-align: center;
  border-radius: 4px;
  padding: 1px 4px;
}
.dpanel-comp-delta.pos { color: var(--green); background: var(--green-dim); }
.dpanel-comp-delta.neg { color: var(--red);   background: var(--red-dim); }
.dpanel-comp-delta.neu { color: var(--text-muted); }

/* Swing tag on constituency list rows */
.dpanel-swing-tag {
  font-size: 0.56rem;
  color: var(--amber);
  background: var(--amber-dim);
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 4px;
  white-space: nowrap;
  font-weight: 600;
  vertical-align: middle;
}
