/* ═══════════════════════════════════════════════════
   CSS — Design System & Layout
   ═══════════════════════════════════════════════════ */
:root {
  --sidebar-bg: #0F172A;
  --sidebar-hover: #1E293B;
  --sidebar-active: #334155;
  --sidebar-text: #94A3B8;
  --sidebar-text-active: #F8FAFC;
  --content-bg: #F1F5F9;
  --card-bg: #FFFFFF;
  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --moderate: #3B82F6;
  --progressive: #8B5CF6;
  --swing: #F59E0B;
  --tech-highlight: #10B981;
  --executive: #2563EB;
  --legislative: #7C3AED;
  --commission: #0891B2;
  --department: #059669;
  --independent: #DC2626;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--content-bg);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 0;
  z-index: 10;
}

#sidebar .logo {
  padding: 24px 20px 8px;
  color: var(--sidebar-text-active);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

#sidebar .logo-sub {
  padding: 0 20px 24px;
  color: var(--sidebar-text);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav-section {
  padding: 8px 12px 4px;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: calc(100% - 16px);
  margin: 2px 8px;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
  text-align: left;
}

.nav-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.nav-btn.active { background: var(--sidebar-active); color: var(--sidebar-text-active); font-weight: 600; }

.nav-btn .icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

#sidebar .bottom-info {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--sidebar-active);
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.5;
}

/* Main content */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
}

#header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

#header .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Power Structure — Card Layout */
.power-layout { display: flex; flex-direction: column; gap: 20px; }

.power-top-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 0.8fr;
  gap: 20px;
}

.power-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.col-header {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 0 4px 4px;
}

.power-card {
  background: white;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 16px 20px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  border-left: 4px solid var(--border);
}
.power-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.08); }
.power-card.executive { border-left-color: var(--executive); }
.power-card.legislative { border-left-color: var(--legislative); }

.power-card h4 { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.power-card .card-sub { font-size: 13px; color: var(--text-secondary); }
.power-card .card-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  background: var(--content-bg);
  color: var(--text-secondary);
}

.power-card-sm {
  background: white;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.power-card-sm:hover { background: var(--content-bg); }
.power-card-sm .sm-name { font-weight: 600; color: var(--text-primary); }
.power-card-sm .sm-person { color: var(--text-secondary); font-size: 12px; }

.flow-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
.flow-label::before, .flow-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  max-width: 30px;
}

.relationship-banner {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: 10px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  font-size: 13px;
  color: #92400E;
  flex-wrap: wrap;
}
.relationship-banner .rel-arrow { font-weight: 700; font-size: 18px; }

.commission-section {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px 24px;
}
.commission-section .section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.commission-section .section-header h3 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.commission-section .section-header p {
  font-size: 12px;
  color: var(--text-muted);
}

.commission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.commission-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}
.commission-stack .cm-card {
  background: rgba(8,145,178,0.06);
  border: 1px solid rgba(8,145,178,0.18);
  border-radius: 8px;
  padding: 12px 10px;
  cursor: pointer;
  transition: background 0.1s;
}
.commission-stack .cm-card:hover { background: rgba(8,145,178,0.12); }
.commission-stack .cm-card h5 {
  font-size: 13px;
  font-weight: 700;
  color: var(--commission);
  margin-bottom: 2px;
}
.commission-stack .cm-card p { font-size: 11px; color: var(--text-muted); }
.commission-stack .cm-arrow { font-size: 10px; color: var(--text-muted); }
.commission-stack .dept-card {
  background: rgba(5,150,105,0.06);
  border: 1px solid rgba(5,150,105,0.18);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--department);
}

@media (max-width: 900px) {
  .power-top-row { grid-template-columns: 1fr; }
}

/* Detail Panel */
.detail-panel {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
  margin-top: 16px;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-panel h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.detail-panel .role {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
}

.detail-panel .detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.detail-item label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.detail-item span {
  font-size: 14px;
  color: var(--text-primary);
}

/* District Map */
.districts-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}

#map-container {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
}

#map-svg { width: 100%; }

.district-path {
  stroke: white;
  stroke-width: 2;
  cursor: pointer;
  transition: opacity 0.15s;
}

.district-path:hover { opacity: 0.8; stroke-width: 3; stroke: var(--text-primary); }
.district-path.selected { stroke: var(--text-primary); stroke-width: 3; }

.district-label {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  fill: white;
  text-anchor: middle;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.district-sublabel {
  font-family: var(--font);
  font-size: 9px;
  fill: rgba(255,255,255,0.85);
  text-anchor: middle;
  pointer-events: none;
}

.tech-badge {
  font-family: var(--font);
  font-size: 8px;
  font-weight: 700;
  fill: white;
  text-anchor: middle;
  pointer-events: none;
}

#district-info {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
}

#district-info h3 { font-size: 16px; margin-bottom: 16px; color: var(--text-secondary); }

.district-card {
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.district-card h4 {
  font-size: 15px;
  margin-bottom: 4px;
}

.district-card .sup-name { font-size: 13px; color: var(--text-secondary); }
.district-card .lean-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  margin-top: 8px;
}

.lean-moderate { background: var(--moderate); }
.lean-progressive { background: var(--progressive); }

/* Election Timeline */
.timeline-container {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
  margin-top: 24px;
}

.timeline-container h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}

#timeline-svg { width: 100%; }

.timeline-event { cursor: pointer; }
.timeline-event circle { transition: r 0.15s; }
.timeline-event:hover circle { r: 8; }
.timeline-label {
  font-family: var(--font);
  font-size: 11px;
  fill: var(--text-primary);
}
.timeline-date {
  font-family: var(--font);
  font-size: 10px;
  fill: var(--text-muted);
}

/* Leverage Points */
.leverage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}

.leverage-card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
  transition: box-shadow 0.2s;
}

.leverage-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.leverage-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.leverage-card h3 {
  font-size: 16px;
  font-weight: 700;
}

.leverage-card .impact-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.impact-high { background: #DCFCE7; color: #166534; }
.impact-medium { background: #FEF3C7; color: #92400E; }
.impact-low { background: #F1F5F9; color: #475569; }

.leverage-card .description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.leverage-card .ratings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rating-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.rating-row .rating-label { min-width: 65px; }

.rating-bar {
  flex: 1;
  height: 6px;
  background: #E2E8F0;
  border-radius: 3px;
  overflow: hidden;
}

.rating-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.leverage-card .details {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: none;
}

.leverage-card.expanded .details { display: block; }

.leverage-card .details ul {
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.leverage-card .expand-btn {
  background: none;
  border: none;
  color: var(--moderate);
  font-size: 13px;
  cursor: pointer;
  padding: 8px 0 0;
  font-family: var(--font);
  font-weight: 600;
}

.leverage-card .expand-btn:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════
   Election Results View
   ═══════════════════════════════════════════════════ */
.election-results-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.chart-card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
}

.chart-card h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.chart-card .chart-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.flippable-callout {
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  border-radius: 10px;
  padding: 16px 20px;
}

.flippable-callout h4 {
  font-size: 14px;
  font-weight: 700;
  color: #92400E;
  margin-bottom: 8px;
}

.flippable-race {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #FDE68A;
  font-size: 13px;
  color: #92400E;
}

.flippable-race:last-child { border-bottom: none; }

.margin-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  background: #DC2626;
  color: white;
}

.turnout-grid {
  display: grid;
  grid-template-columns: auto repeat(3, 1fr);
  gap: 2px;
  font-size: 12px;
}

.turnout-cell {
  padding: 8px 12px;
  text-align: center;
  border-radius: 4px;
  font-weight: 600;
}

.turnout-header {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  padding: 8px 12px;
}

.shift-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.shift-right { background: #DBEAFE; color: #1E40AF; }
.shift-left { background: #EDE9FE; color: #5B21B6; }
.shift-stable { background: #F1F5F9; color: #475569; }

/* ═══════════════════════════════════════════════════
   Money Map View
   ═══════════════════════════════════════════════════ */
.money-map-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.pac-leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pac-leaderboard th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.pac-leaderboard td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.pac-leaderboard tr:hover td {
  background: var(--content-bg);
}

.win-rate-bar {
  display: inline-block;
  height: 6px;
  border-radius: 3px;
  background: var(--tech-highlight);
  vertical-align: middle;
  margin-right: 6px;
}

/* ═══════════════════════════════════════════════════
   Board Voting Patterns View
   ═══════════════════════════════════════════════════ */
.voting-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.alignment-matrix {
  overflow-x: auto;
}

.matrix-table {
  border-collapse: collapse;
  font-size: 11px;
}

.matrix-table th, .matrix-table td {
  padding: 6px 8px;
  text-align: center;
  min-width: 44px;
}

.matrix-table th {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 10px;
}

.matrix-cell {
  border-radius: 4px;
  font-weight: 700;
  font-size: 10px;
  cursor: pointer;
  transition: transform 0.1s;
}

.matrix-cell:hover { transform: scale(1.15); }

.vote-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
}

.vote-yes { background: #DCFCE7; color: #166534; }
.vote-no { background: #FEE2E2; color: #991B1B; }
.vote-absent { background: #F1F5F9; color: #64748B; }

.category-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.category-pill {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  transition: all 0.15s;
}

.category-pill:hover { border-color: var(--moderate); color: var(--moderate); }
.category-pill.active { background: var(--moderate); color: white; border-color: var(--moderate); }

.swing-highlight {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: 10px;
  padding: 16px 20px;
}

.swing-highlight h4 {
  font-size: 14px;
  font-weight: 700;
  color: #92400E;
  margin-bottom: 8px;
}

.vote-timeline-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.vote-timeline-row:last-child { border-bottom: none; }

.vote-topic {
  min-width: 200px;
  font-weight: 600;
  color: var(--text-primary);
}

.vote-result {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 60px;
}

.vote-pills {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════
   Action Pipeline View
   ═══════════════════════════════════════════════════ */
.action-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.budget-progress {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px 24px;
}

.budget-progress h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

.progress-track {
  display: flex;
  gap: 2px;
  height: 32px;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: white;
  transition: flex 0.3s;
}

.progress-segment.completed { background: var(--tech-highlight); }
.progress-segment.current { background: var(--moderate); animation: pulse 2s infinite; }
.progress-segment.upcoming { background: #CBD5E1; color: var(--text-secondary); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.time-buckets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.time-bucket h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.action-card {
  background: white;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 12px;
  transition: box-shadow 0.15s;
}

.action-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

.action-card .action-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.action-card h5 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.urgency-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.urgency-high { background: #FEE2E2; color: #991B1B; }
.urgency-medium { background: #FEF3C7; color: #92400E; }
.urgency-low { background: #DBEAFE; color: #1E40AF; }

.action-card .action-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 8px;
}

.action-card .countdown {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.action-category-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  margin-top: 6px;
}

/* Tooltip */
.tooltip {
  position: fixed;
  background: var(--sidebar-bg);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  z-index: 100;
  max-width: 250px;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.15s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.tooltip.visible { opacity: 1; }

/* Responsive */
@media (max-width: 900px) {
  #sidebar { width: 60px; min-width: 60px; }
  #sidebar .logo, #sidebar .logo-sub, .nav-section, .nav-btn span, #sidebar .bottom-info { display: none; }
  .nav-btn { justify-content: center; padding: 12px; }
  .nav-btn .icon { width: 24px; height: 24px; font-size: 20px; }
  .districts-layout { grid-template-columns: 1fr; }
  #content { padding: 16px; }
  #header { padding: 12px 16px; }
  .time-buckets { grid-template-columns: 1fr; }
}
