:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #1f2231;
  --bg-bar: #252836;
  --text: #e8eaed;
  --text-dim: #9aa0a6;
  --text-muted: #5f6368;
  --accent: #2B5797;
  --accent-light: #4a7bc7;
  --rep: #E30202;
  --rep-bg: rgba(227,2,2,0.12);
  --rep-bar: #c62828;
  --dem: #007BBD;
  --dem-bg: rgba(0,123,189,0.12);
  --dem-bar: #1565c0;
  --green: #2e7d32;
  --yellow: #f9a825;
  --border: #2a2d3a;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Top Bar */
.top-bar {
  background: linear-gradient(135deg, #1a1d27 0%, #0f1117 100%);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(10px);
}
.top-bar-inner {
  max-width: 1440px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
}
.branding { display: flex; align-items: center; gap: 14px; }
.logo-mark {
  background: var(--accent);
  color: white; font-weight: 900; font-size: 20px;
  width: 44px; height: 44px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: -1px;
}
.branding h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { font-size: 13px; color: var(--text-dim); font-weight: 400; }
.meta-info { display: flex; align-items: center; gap: 16px; }
.update-badge {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-bar); padding: 6px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 500; color: var(--text-dim);
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.4; }
}
.refresh-timer { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Progress Strip */
.progress-strip {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.progress-strip-inner {
  max-width: 1440px; margin: 0 auto;
  display: flex; gap: 32px; align-items: center; flex-wrap: wrap;
}
.progress-item { display: flex; align-items: center; gap: 10px; }
.progress-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.progress-bar-wrap { width: 140px; height: 6px; background: var(--bg-bar); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width 1s ease; }
.progress-num { font-size: 13px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.last-updated { margin-left: auto; }

/* Nav Bar */
.nav-bar {
  background: var(--bg); border-bottom: 1px solid var(--border);
  padding: 0 24px; position: sticky; top: 77px; z-index: 90;
}
.nav-inner {
  max-width: 1440px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px;
}
.party-toggle { display: flex; gap: 4px; padding: 8px 0; }
.party-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  padding: 8px 18px; border-radius: 6px; cursor: pointer;
  font: 600 13px 'Inter', sans-serif; display: flex; align-items: center; gap: 6px;
  transition: all 0.2s;
}
.party-btn:hover { border-color: var(--text-muted); color: var(--text); }
.party-btn.active[data-party="republican"] {
  background: var(--rep-bg); border-color: var(--rep); color: #ff6b6b;
}
.party-btn.active[data-party="democratic"] {
  background: var(--dem-bg); border-color: var(--dem); color: #64b5f6;
}
.party-dot { width: 8px; height: 8px; border-radius: 50%; }
.party-dot.rep { background: var(--rep); }
.party-dot.dem { background: var(--dem); }

.tab-bar { display: flex; gap: 2px; padding: 8px 0; }
.tab-btn {
  background: transparent; border: none; color: var(--text-muted);
  padding: 8px 14px; border-radius: 6px; cursor: pointer;
  font: 500 13px 'Inter', sans-serif; transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); background: var(--bg-bar); }
.tab-btn.active { color: var(--text); background: var(--bg-bar); }

/* Main Layout */
.main-layout {
  max-width: 1440px; margin: 0 auto; padding: 20px 24px;
  display: grid; grid-template-columns: 300px 1fr; gap: 24px;
}

/* Sidebar */
.sidebar {
  position: sticky; top: 140px; align-self: start;
  max-height: calc(100vh - 160px); overflow-y: auto;
}
.sidebar-title { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.sidebar-subtitle { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.key-race-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  cursor: pointer; transition: all 0.2s;
}
.key-race-card:hover { background: var(--bg-card-hover); border-color: var(--text-muted); }
.key-race-name { font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.3px; }
.key-race-candidates { display: flex; flex-direction: column; gap: 4px; }
.key-candidate { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.key-candidate .name { font-weight: 500; }
.key-candidate .pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.margin-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; margin-top: 6px;
  background: rgba(249,168,37,0.15); color: var(--yellow);
}

/* Race Grid */
.race-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 16px; align-content: start;
}

/* Race Card */
.race-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: all 0.3s; animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.race-card:hover { border-color: var(--text-muted); box-shadow: var(--shadow); }
.race-header {
  padding: 14px 16px 10px; display: flex; justify-content: space-between; align-items: flex-start;
}
.race-name { font-size: 14px; font-weight: 700; letter-spacing: -0.2px; }
.race-type { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; margin-top: 2px; }
.race-badge {
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 4px;
  white-space: nowrap;
}
.badge-winner { background: rgba(46,125,50,0.2); color: #66bb6a; }
.badge-runoff { background: rgba(249,168,37,0.15); color: var(--yellow); }
.badge-tooclose { background: rgba(255,152,0,0.15); color: #ffb74d; }

.candidates { padding: 0 16px 14px; }
.candidate-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; position: relative;
}
.candidate-rank {
  width: 22px; height: 22px; border-radius: 50%; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.rank-rep { background: var(--rep-bg); color: #ff6b6b; }
.rank-dem { background: var(--dem-bg); color: #64b5f6; }
.rank-other { background: var(--bg-bar); color: var(--text-muted); }
.candidate-info { flex: 1; min-width: 0; }
.candidate-name {
  font-size: 13px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.candidate-name .winner-check { color: var(--green); margin-left: 4px; }
.vote-bar-wrap {
  height: 4px; background: var(--bg-bar); border-radius: 2px;
  margin-top: 3px; overflow: hidden;
}
.vote-bar { height: 100%; border-radius: 2px; transition: width 1s ease; }
.vote-bar.rep { background: var(--rep); }
.vote-bar.dem { background: var(--dem); }
.vote-bar.other { background: var(--text-muted); }
.candidate-stats { text-align: right; flex-shrink: 0; }
.candidate-pct { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.candidate-votes { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.race-footer {
  padding: 8px 16px; background: rgba(0,0,0,0.15);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--text-muted);
}
.vote-split { display: flex; gap: 12px; }
.vote-split span { display: flex; align-items: center; gap: 4px; }
.ev-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-light); }
.ed-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }

/* Loading State */
.loading-state {
  grid-column: 1 / -1; text-align: center; padding: 80px 0;
  color: var(--text-muted);
}
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* No Data */
.no-races {
  grid-column: 1 / -1; text-align: center; padding: 60px 0;
  color: var(--text-muted); font-size: 14px;
}

/* Responsive */
@media (max-width: 1024px) {
  .main-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; display: flex; flex-wrap: wrap; gap: 10px; }
  .sidebar-title, .sidebar-subtitle { width: 100%; }
  .key-race-card { flex: 1; min-width: 250px; }
}
@media (max-width: 768px) {
  .top-bar { padding: 12px 16px; }
  .branding h1 { font-size: 17px; }
  .progress-strip-inner { gap: 16px; }
  .nav-inner { flex-direction: column; align-items: stretch; }
  .tab-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .race-grid { grid-template-columns: 1fr; }
  .main-layout { padding: 16px; }
}
@media (max-width: 480px) {
  .progress-bar-wrap { width: 80px; }
  .party-toggle { width: 100%; }
  .party-btn { flex: 1; justify-content: center; }
}

/* Expand/collapse candidates */
.expand-btn {
  display: block; width: 100%; background: transparent;
  border: 1px dashed var(--border); color: var(--text-dim);
  padding: 6px 0; margin-top: 4px; border-radius: 6px;
  font: 500 11px 'Inter', sans-serif; cursor: pointer;
  transition: all 0.2s;
}
.expand-btn:hover { border-color: var(--text-muted); color: var(--text); background: var(--bg-bar); }
.expand-candidates { animation: fadeIn 0.3s ease; }
