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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
  background: #1a1d27;
  border-bottom: 1px solid #2d3148;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 56px;
  flex-shrink: 0;
}
.header h1 { font-size: 16px; font-weight: 600; color: #fff; letter-spacing: 0.3px; }
.header .subtitle { font-size: 12px; color: #64748b; }

.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #94a3b8;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: #23263a; color: #e2e8f0; }
.tab-btn.active { background: #3b82f6; color: #fff; }

.summary-pills { display: flex; gap: 12px; margin-left: 16px; }
.pill {
  font-size: 11px;
  color: #64748b;
  background: #1e2235;
  border-radius: 12px;
  padding: 3px 10px;
}
.pill span { color: #94a3b8; font-weight: 600; }

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

/* ── Global filter bar (agency + type) ───────────────────────── */
.global-controls {
  background: #111420;
  border-bottom: 1px solid #252840;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.global-controls label { font-size: 12px; color: #64748b; }
.global-controls select {
  background: #1e2235;
  border: 1px solid #2d3148;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}

/* ── Per-tab controls bar ────────────────────────────────────── */
.controls {
  background: #141620;
  border-bottom: 1px solid #2d3148;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
.controls label { font-size: 12px; color: #64748b; }
.controls select {
  background: #1e2235;
  border: 1px solid #2d3148;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
}
.controls select:focus { outline: 2px solid #3b82f6; }

/* ── Map tab ─────────────────────────────────────────────────── */
/* Height is set explicitly by JS (window.innerHeight - container.top). */
/* This bypasses flex height propagation issues with Leaflet.           */
.map-container { position: relative; overflow: hidden; }
#leaflet-map { width: 100%; /* height set by JS */ }

.legend {
  position: absolute;
  bottom: 24px;
  right: 12px;
  z-index: 1000;
  background: rgba(20, 22, 32, 0.92);
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 11px;
}
.legend h4 { color: #94a3b8; margin-bottom: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.legend-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ── Route detail tab ────────────────────────────────────────── */
.route-detail { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 24px; }

.chart-card {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 20px 24px;
}
.chart-card h2 { font-size: 14px; font-weight: 600; color: #94a3b8; margin-bottom: 4px; }
.chart-card .chart-sub { font-size: 12px; color: #475569; margin-bottom: 16px; }

/* ── Reliability banner ──────────────────────────────────────── */
.reliability-banner {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  flex-shrink: 0;
}
.reliability-score { display: flex; align-items: center; gap: 16px; }
.grade { font-size: 56px; font-weight: 800; line-height: 1; }
.reliability-stats { display: flex; gap: 32px; }
.rstat { display: flex; flex-direction: column; gap: 2px; }
.rstat-val { font-size: 20px; font-weight: 700; color: #e2e8f0; }
.rstat-label { font-size: 11px; color: "#64748b"; }

/* ── Worst offenders / rankings table ───────────────────────── */
.offenders-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.offenders-table th {
  text-align: left;
  padding: 6px 12px;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #2d3148;
}
.offenders-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #1e2235;
  color: #e2e8f0;
}
.offenders-table tbody tr:hover { background: #1e2235; }

/* ── Empty / loading states ──────────────────────────────────── */
.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 48px;
  color: #475569;
  font-size: 13px;
  text-align: center;
}
.state-box .icon { font-size: 32px; }

/* ── Recharts customization ──────────────────────────────────── */
.recharts-tooltip-wrapper { font-size: 12px; }
.recharts-cartesian-axis-tick-value { font-size: 11px; fill: #64748b; }
