/* =====================================================
   Bike Walk Joplin — Crash Dashboard
   Editorial infographic style. Light bg, big numbers.
   Fonts: Work Sans (shared with map)
   ===================================================== */

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

:root {
  --teal:        #00527A;
  --teal-dark:   #003d5c;
  --blue:        #1370AF;
  --blue-dark:   #0f5a8f;
  --blue-light:  #8EB5DB;
  --blue-pale:   #EEF3F8;

  --red:         #e8453c;
  --red-pale:    #fdf1f0;
  --amber:       #f5a623;
  --amber-pale:  #fdf6e8;
  --green:       #16a34a;

  --ink:         #1a2430;
  --ink-mid:     #4a5568;
  --ink-light:   #8896a8;
  --border:      #dce3ec;
  --bg:          #f5f7fa;
  --white:       #ffffff;

  --header-h:    56px;
  --tabbar-h:    44px;
  --chrome-h:    calc(var(--header-h) + var(--tabbar-h));

  --radius:      12px;
  --radius-sm:   8px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow:      0 4px 16px rgba(0,0,0,0.09), 0 1px 4px rgba(0,0,0,0.06);
}

html, body {
  min-height: 100%;
  font-family: 'Work Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Header ---- */
#dash-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--teal);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  z-index: 100;
}
.header-inner {
  height: 100%; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo-img { height: 36px; width: auto; flex-shrink: 0; }
.brand-tagline {
  font-size: 10px; font-weight: 700;
  color: rgba(255,255,255,0.6); letter-spacing: 0.12em; text-transform: uppercase;
}
.header-meta { display: flex; align-items: center; }
.data-note {
  font-size: 11px; color: rgba(255,255,255,0.45);
  font-weight: 400;
}

/* ---- Tab Bar ---- */
#tab-bar {
  position: fixed; top: var(--header-h); left: 0; right: 0;
  height: var(--tabbar-h);
  background: var(--white);
  border-bottom: 2px solid var(--border);
  z-index: 99;
  display: flex; align-items: stretch;
  overflow-x: auto; scrollbar-width: none;
  padding: 0 8px;
  gap: 2px;
}
#tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
  background: none; border: none; border-bottom: 3px solid transparent;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-mid); padding: 0 16px;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -2px;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

/* ---- Main scroll area ---- */
#dash-main {
  margin-top: var(--chrome-h);
  min-height: calc(100vh - var(--chrome-h) - 40px);
}

/* ---- Tab panels ---- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}
.panel-inner--wide {
  max-width: 1280px;
}

/* ---- Hero section (Overview) ---- */
.hero-section {
  margin-bottom: 36px;
}
.hero-headline {
  font-size: clamp(22px, 3.5vw, 32px);
  font-weight: 800;
  line-height: 1.2;
  color: var(--ink);
  max-width: 700px;
  margin-bottom: 12px;
}
.hero-sub {
  font-size: 15px; font-weight: 400;
  color: var(--ink-mid); line-height: 1.65;
  max-width: 680px;
}

/* ---- Hero stat cards ---- */
.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 48px;
}
.hero-stat {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  box-shadow: var(--shadow-sm);
}
.hero-stat--fatal { border-top: 3px solid var(--red); }
.hero-stat--accent { border-top: 3px solid var(--amber); }
.hero-num {
  font-size: clamp(36px, 5vw, 52px);
  font-weight: 800;
  line-height: 1;
  color: var(--teal);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.hero-stat--fatal .hero-num { color: var(--red); }
.hero-stat--accent .hero-num { color: var(--amber); }
.hero-label {
  font-size: 13px; font-weight: 600;
  color: var(--ink); margin-bottom: 4px;
}
.hero-sub-label {
  font-size: 11px; color: var(--ink-light);
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* ---- Tab headers ---- */
.tab-header {
  margin-bottom: 32px;
}
.tab-header h2 {
  font-size: clamp(20px, 2.5vw, 26px);
  font-weight: 800; color: var(--ink);
  margin-bottom: 8px;
}
.tab-header p {
  font-size: 14px; color: var(--ink-mid); line-height: 1.6;
  max-width: 680px;
}

/* ---- Chart cards ---- */
.chart-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.chart-header { margin-bottom: 16px; }
.chart-title {
  font-size: 15px; font-weight: 700;
  color: var(--ink); margin-bottom: 4px;
}
.chart-desc {
  font-size: 12px; color: var(--ink-light); line-height: 1.55;
}

/* ---- Chart size wrappers ---- */
.chart-wrap { position: relative; }
.chart-wrap--bar  { height: 260px; }
.chart-wrap--donut { height: 260px; max-width: 320px; margin: 0 auto; }
.chart-wrap--hbar { height: 280px; }

/* ---- Grids ---- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}
.grid-2:last-child { margin-bottom: 0; }

/* ---- Time heatmap ---- */
.heatmap-container {
  overflow-x: auto;
}
.heatmap-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 340px;
  font-size: 11px;
}
.heatmap-table th {
  font-weight: 600; color: var(--ink-light);
  padding: 3px 6px; text-align: center;
  white-space: nowrap;
}
.heatmap-table td {
  width: 30px; height: 26px;
  text-align: center; border-radius: 3px;
  font-size: 10px; font-weight: 600;
  color: transparent;
  transition: opacity 0.1s;
}
.heatmap-table td:hover { opacity: 0.75; cursor: default; }
.heatmap-table td.has-value { color: rgba(255,255,255,0.85); }
.heatmap-table td.heatmap-row-label {
  font-weight: 600; color: var(--ink-light);
  padding-right: 8px; white-space: nowrap;
  text-align: right; font-size: 11px;
  background: none; width: auto;
}

/* ---- Where tab layout ---- */
.where-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}
.where-map-col, .where-tables-col { min-width: 0; }

/* ---- Leaflet mini-maps ---- */
.dash-map {
  height: 480px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.map-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-top: 10px;
  font-size: 11px; color: var(--ink-mid);
}
.legend-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; border: 1.5px solid rgba(0,0,0,0.15);
  vertical-align: middle; margin-right: 3px;
}
.legend-dot--fatal  { background: var(--red); }
.legend-dot--injury { background: var(--amber); }
.legend-dot--pdo    { background: #aab4c0; }
.legend-line {
  display: inline-block; width: 18px; height: 3px;
  vertical-align: middle; border-radius: 2px; margin-right: 3px;
}
.legend-line--trail { background: #16a34a; }
.legend-line--road  { background: #0d9488; }
.map-note {
  font-size: 11px; color: var(--ink-light); margin-top: 6px;
}

/* ---- Rank table ---- */
.rank-table {
  width: 100%; border-collapse: collapse;
  font-size: 12px;
}
.rank-table th {
  font-size: 11px; font-weight: 700; color: var(--ink-light);
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  padding: 6px 8px; text-align: left;
}
.rank-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #f0f3f6;
  vertical-align: middle;
  line-height: 1.35;
}
.rank-table tr:last-child td { border-bottom: none; }
.rank-table .rank-num {
  font-weight: 700; color: var(--ink-light); text-align: center;
}
.rank-table .crash-count {
  font-weight: 700; color: var(--teal);
  text-align: center;
}
.rank-table .fatal-count {
  font-weight: 700; color: var(--red);
  text-align: center;
}
.rank-table .fatal-count.zero { color: var(--ink-light); font-weight: 400; }

/* ---- Risk & Equity tab ---- */
.callout-banner {
  display: flex; align-items: center; gap: 24px;
  background: var(--red-pale);
  border: 1px solid rgba(232,69,60,0.2);
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 28px;
}
.callout-number {
  font-size: clamp(40px, 6vw, 60px);
  font-weight: 800;
  color: var(--red);
  line-height: 1;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.callout-text {
  font-size: 15px; color: var(--ink); line-height: 1.6;
}
.callout-text strong { color: var(--red); }

.risk-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  align-items: start;
}
.risk-map-col, .risk-table-col { min-width: 0; }

.loading-inline {
  font-size: 13px; color: var(--ink-light); padding: 16px 0;
}

/* ---- Footer ---- */
#dash-footer {
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
}
.footer-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-light);
}
.footer-dot {
  width: 3px; height: 3px; border-radius: 50%;
  background: var(--border); flex-shrink: 0;
}

/* ---- Leaflet popup overrides for dashboard ---- */
.leaflet-popup-content-wrapper {
  background: var(--white) !important;
  color: var(--ink) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; min-width: 180px; max-width: 260px; }
.leaflet-popup-tip { background: var(--white) !important; }
.leaflet-popup-close-button { color: var(--ink-light) !important; top: 8px !important; right: 10px !important; }
.crash-popup { padding: 12px 14px; }
.crash-popup-type {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; margin-bottom: 5px;
}
.crash-popup-type.fatal   { color: var(--red); }
.crash-popup-type.injury  { color: var(--amber); }
.crash-popup-type.pdo     { color: var(--ink-light); }
.crash-popup-loc { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.crash-popup-meta { font-size: 12px; color: var(--ink-mid); line-height: 1.5; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .where-layout,
  .risk-layout {
    grid-template-columns: 1fr;
  }
  .dash-map { height: 320px; }
}
@media (max-width: 640px) {
  .panel-inner { padding: 20px 14px 48px; }
  .hero-stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .callout-banner { flex-direction: column; gap: 10px; }
}
