/* ============================================================
   Missouri Term Limits Map — style.css
   jonesmarkh.com/termlimits/
   ============================================================ */

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

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg: #141c2e;
  --surface: #1a2438;
  --surface2: #202d42;
  --border: rgba(255,255,255,0.09);
  --text-primary: #eef1f6;
  --text-secondary: #b8bec9;
  --text-muted: #8a94a8;
  --gold: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --muted-district: #252d3d;
  --muted-border: #2e3a50;
  --font: 'Cabinet Grotesk', 'General Sans', system-ui, sans-serif;
  --font-sans: 'General Sans', system-ui, sans-serif;
  --font-display: 'Cabinet Grotesk', 'General Sans', sans-serif;
  --radius: 10px;
}

/* Light theme overrides */
[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface2: #eef1f6;
  --border: rgba(0,0,0,0.1);
  --text-primary: #111827;
  --text-secondary: #374151;
  --text-muted: #6b7280;
  --muted-district: #d1d9e6;
  --muted-border: #b8c2d4;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Nav ───────────────────────────────────────────────────── */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 1rem;
}
.nav-brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1rem;
  color: #f1f5f9;
  text-decoration: none;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.nav-links {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}
.nav-links a {
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  transition: color 0.2s;
}
.nav-links a:hover { color: #f1f5f9; }

.nav-main {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex: 1;
}


/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  min-width: 44px;
  min-height: 44px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
  padding: 0;
  margin-left: 0.5rem;
}
.theme-toggle:hover { background: var(--surface2); color: var(--text-primary); }

/* ── Main Layout ───────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
  text-align: center;
  padding: 3.5rem 1rem 2rem;
}
.eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.6rem;
}
.page-header h1 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}
.subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ── Controls Bar ──────────────────────────────────────────── */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

/* Chamber toggle */
.chamber-toggle {
  display: flex;
  gap: 0.5rem;
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.25rem;
}
.chamber-btn {
  background: none;
  border: 1.5px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  min-height: 38px;
}
.chamber-btn:hover { color: var(--text-primary); }
.chamber-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(245, 158, 11, 0.08);
}

/* Year slider */
.year-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
  min-width: 200px;
  max-width: 380px;
}
.year-labels {
  display: flex;
  justify-content: space-between;
  padding: 0 2px;
}
.year-labels span {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* Range input */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  border: 1px solid var(--border);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  border: 2px solid rgba(245,158,11,0.3);
  box-shadow: 0 0 0 3px rgba(245,158,11,0.12);
  transition: box-shadow 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px rgba(245,158,11,0.2);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  border: 2px solid rgba(245,158,11,0.3);
}
input[type="range"]::-webkit-slider-runnable-track {
  background: var(--surface2);
  height: 4px;
  border-radius: 2px;
}

/* ── Stat Bar ──────────────────────────────────────────────── */
.stat-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.stat-pill {
  flex: 1;
  min-width: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.stat-num {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
}
.stat-num.stat-r { color: var(--red); }
.stat-num.stat-d { color: var(--blue); }
.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ── Map Container ─────────────────────────────────────────── */
.map-container {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
  height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#mo-map {
  width: 100%;
  height: 100%;
  display: block;
}
#mo-map path {
  transition: opacity 0.2s, filter 0.15s;
}
#mo-map path:hover {
  filter: brightness(1.25);
  cursor: pointer;
}

/* Map tooltip */
.map-tooltip {
  position: absolute;
  background: rgba(15, 20, 35, 0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  font-size: 0.8rem;
  color: var(--text-primary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  white-space: nowrap;
  max-width: 220px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  line-height: 1.55;
}
.map-tooltip.visible { opacity: 1; }
.tooltip-name {
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.15rem;
}
.tooltip-district {
  color: var(--text-muted);
  font-size: 0.73rem;
}
.tooltip-open {
  font-weight: 600;
  margin-top: 0.2rem;
}
.tooltip-open.R { color: var(--red); }
.tooltip-open.D { color: var(--blue); }

/* ── Chart Section ─────────────────────────────────────────── */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.5rem 1.25rem;
  margin-bottom: 1.5rem;
}
.section-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-bottom: 1rem;
}
.chart-wrap {
  position: relative;
  height: 220px;
}

/* ── List Section ──────────────────────────────────────────── */
.list-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  overflow: hidden;
}
.list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.list-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Filter row */
.filter-row {
  display: flex;
  gap: 0.35rem;
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.2rem;
}
.filter-btn {
  background: none;
  border: 1.5px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  min-height: 32px;
}
.filter-btn:hover { color: var(--text-primary); }
.filter-btn.active {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border);
}

/* Export button */
.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  min-height: 36px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.export-btn:hover {
  background: var(--surface2);
  color: var(--text-primary);
}

/* ── Table ─────────────────────────────────────────────────── */
.tl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.tl-table thead tr {
  border-bottom: 1px solid var(--border);
}
.tl-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  white-space: nowrap;
}
.tl-table td {
  padding: 0.65rem 0.75rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tl-table tbody tr:last-child td { border-bottom: none; }
.tl-table tbody tr:hover td {
  background: rgba(255,255,255,0.025);
}
.tl-table td:first-child {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Party badge */
.party-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
}
.party-badge.R {
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.25);
}
.party-badge.D {
  background: rgba(59,130,246,0.15);
  color: #60a5fa;
  border: 1px solid rgba(59,130,246,0.25);
}
.party-badge.I {
  background: rgba(245,158,11,0.12);
  color: #fbbf24;
  border: 1px solid rgba(245,158,11,0.2);
}

/* Open seat tag */
.open-seat-cell { white-space: nowrap; }
.open-seat-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  background: rgba(245,158,11,0.1);
  color: var(--gold);
  border: 1px solid rgba(245,158,11,0.2);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Empty state */
.list-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

/* ── Footer ────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  max-width: 1100px;
  margin: 2rem auto 0;
}
.site-footer .footer-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.site-footer .footer-brand {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-primary);
  text-decoration: none;
}
.site-footer .footer-links {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.site-footer .footer-links a {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}
.site-footer .footer-links a:hover { color: var(--text-primary); }
.footer-icon-link {
  display: flex;
  align-items: center;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.footer-icon-link:hover { opacity: 1; }
.footer-copy {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}

.share-strip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 1.5rem 0.75rem;
  max-width: 1100px;
  margin: 0 auto;
}
.share-strip-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.share-strip-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--surface2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.share-strip-btn:hover { background: var(--surface); color: var(--text-primary); }

/* ── Nav two-row mobile ─────────────────────────────────────── */
@media (max-width: 680px) {
  .nav-links { gap: 0.9rem; }
  .nav-brand { display: none; }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 700px) {
  main { padding: 0 1rem 3rem; }

  .page-header { padding: 2.5rem 0.5rem 1.5rem; }
  .page-header h1 { font-size: 1.7rem; }

  .controls-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .year-slider-wrap {
    width: 100%;
    max-width: 100%;
  }

  .map-container { height: 320px; }

  .stat-bar { gap: 0.5rem; }
  .stat-pill { min-width: 80px; padding: 0.65rem 0.9rem; }
  .stat-num { font-size: 1.4rem; }

  .chart-section, .list-section { padding: 1rem; }
  .chart-wrap { height: 180px; }

  .list-header { flex-direction: column; align-items: flex-start; }
  .list-controls { flex-wrap: wrap; }

  /* Collapse less-important table columns on mobile */
  .tl-table th:nth-child(4),
  .tl-table td:nth-child(4) { display: none; }
  .tl-table th, .tl-table td { padding: 0.55rem 0.5rem; }

  /* nav two-row handled globally */
}

@media (max-width: 480px) {
  /* Further collapse on very small screens */
  .tl-table th:nth-child(5),
  .tl-table td:nth-child(5) { display: none; }
}

/* ── Print ─────────────────────────────────────────────────── */
@media print {
  /* Hide interactive UI */
  nav,
  .controls-bar,
  .stat-bar,
  .map-container,
  .chart-section,
  .filter-row,
  .export-btn,
  footer,
  .theme-toggle {
    display: none !important;
  }

  body {
    background: #fff;
    color: #111;
    font-size: 12pt;
  }

  main { max-width: 100%; padding: 0; }

  .page-header {
    padding: 1rem 0 1rem;
    text-align: left;
  }
  .page-header h1 {
    font-size: 18pt;
    color: #111;
  }
  .eyebrow { color: #555; }
  .subtitle { color: #444; }

  .list-section {
    background: none;
    border: none;
    padding: 0;
  }
  .list-header { margin-bottom: 0.5rem; }
  .section-title { font-size: 14pt; color: #111; }

  .tl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10pt;
  }
  .tl-table th,
  .tl-table td {
    padding: 6pt 8pt;
    border-bottom: 1px solid #ddd;
    color: #111;
  }
  .tl-table th {
    background: #f5f5f5;
    color: #333;
  }
  .tl-table tbody tr:last-child td { border-bottom: none; }

  /* Re-show all hidden columns */
  .tl-table th, .tl-table td { display: table-cell !important; }

  .party-badge.R { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
  .party-badge.D { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }
  .open-seat-tag { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

  .list-empty { display: none !important; }

  /* Show URLs after links for paper */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #555;
  }

  @page {
    margin: 1in;
  }
}
