/* TCE911 PSAP NENA Metrics Dashboard — original styles */
:root {
  --bg: #0b1220;
  --bg-elev: #121a2b;
  --bg-card: #162033;
  --bg-card-hover: #1a2740;
  --border: #243049;
  --border-soft: #1c2740;
  --text: #e8eef8;
  --text-muted: #8b9bb8;
  --text-dim: #6a7a96;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --good: #22c55e;
  --good-soft: rgba(34, 197, 94, 0.15);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --bad: #ef4444;
  --bad-soft: rgba(239, 68, 68, 0.15);
  --nena: #38bdf8;
  --chart-bar: #3b82f6;
  --chart-line: #38bdf8;
  --heatmap-0: #1a2336;
  --heatmap-miss: #7f1d1d;
  --heatmap-low: #854d0e;
  --heatmap-ok: #14532d;
  --heatmap-high: #166534;
  --heatmap-perfect: #22c55e;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Consolas", monospace;
}

[data-theme="light"] {
  --bg: #f0f4fa;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f7f9fc;
  --border: #d4dde8;
  --border-soft: #e8eef5;
  --text: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --good-soft: rgba(22, 163, 74, 0.1);
  --warn-soft: rgba(217, 119, 6, 0.1);
  --bad-soft: rgba(220, 38, 38, 0.1);
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  --heatmap-0: #e2e8f0;
  --heatmap-miss: #fecaca;
  --heatmap-low: #fde68a;
  --heatmap-ok: #bbf7d0;
  --heatmap-high: #86efac;
  --heatmap-perfect: #22c55e;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); }

.app-header {
  background: linear-gradient(135deg, #0a1628 0%, #132340 50%, #0e1a30 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

[data-theme="light"] .app-header {
  background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%);
  color: #fff;
}

[data-theme="light"] .app-header .subtitle,
[data-theme="light"] .app-header .nena-note { color: rgba(255,255,255,0.85); }

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.brand { display: flex; align-items: center; gap: 0.85rem; }

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(145deg, #2563eb, #0ea5e9);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.7rem;
  letter-spacing: -0.02em;
  color: #fff;
  box-shadow: 0 2px 12px rgba(37, 99, 235, 0.45);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.nena-note {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--nena);
  font-weight: 500;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: var(--bg-card-hover); border-color: var(--accent); }

.btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.25);
  color: inherit;
}

[data-theme="light"] .btn-ghost {
  border-color: rgba(255,255,255,0.4);
  color: #fff;
}

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.control-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 700;
  margin-right: 0.25rem;
}

.period-btns, .grain-btns { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.hero {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

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

.hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
}

.hero-card.primary {
  background: linear-gradient(145deg, #132a4a, #1a3a5c);
  border-color: #2a4a6e;
}

[data-theme="light"] .hero-card.primary {
  background: linear-gradient(145deg, #1e40af, #2563eb);
  border-color: #1d4ed8;
  color: #fff;
}

[data-theme="light"] .hero-card.primary .hero-label,
[data-theme="light"] .hero-card.primary .hero-sub { color: rgba(255,255,255,0.8); }

.hero-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 700;
}

.hero-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0.25rem 0;
  font-variant-numeric: tabular-nums;
}

.hero-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.narrative {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.narrative strong { color: var(--text); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.kpi-card .label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 700;
}

.kpi-card .value {
  font-size: 1.35rem;
  font-weight: 750;
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}

.kpi-card .hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

.kpi-card.good .value { color: var(--good); }
.kpi-card.warn .value { color: var(--warn); }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem 1.15rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.panel-note {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.chart-wrap {
  position: relative;
  height: 320px;
  width: 100%;
}

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

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

.chart-wrap.sm { height: 260px; }

/* Heatmap */
.heatmap-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  margin-right: 0.25rem;
  vertical-align: middle;
  border: 1px solid var(--border);
}

.heatmap-scroll {
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.heatmap {
  display: inline-grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 16px);
  gap: 3px;
  min-width: min-content;
}

.hm-cell {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--heatmap-0);
  cursor: default;
  position: relative;
}

.hm-cell.has-calls { cursor: pointer; }
.hm-cell:hover { outline: 1px solid var(--accent); outline-offset: 1px; }

.hm-cell.miss { background: var(--heatmap-miss); }
.hm-cell.low { background: var(--heatmap-low); }
.hm-cell.ok { background: var(--heatmap-ok); }
.hm-cell.high { background: var(--heatmap-high); }
.hm-cell.perfect { background: var(--heatmap-perfect); }
.hm-cell.empty { background: transparent; border: 1px dashed var(--border-soft); }

.hm-tooltip {
  display: none;
  position: fixed;
  z-index: 100;
  background: #0a1220;
  color: #e8eef8;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.75rem;
  pointer-events: none;
  max-width: 220px;
  box-shadow: var(--shadow);
}

.hm-tooltip.visible { display: block; }

.dow-labels {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-right: 6px;
  font-size: 0.65rem;
  color: var(--text-dim);
  justify-content: space-between;
  height: calc(7 * 16px + 6 * 3px);
}

.heatmap-layout {
  display: flex;
  align-items: flex-start;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.detail {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

table.detail thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-elev);
}

table.detail th {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  white-space: nowrap;
}

table.detail td {
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border-soft);
}

table.detail tbody tr:hover { background: var(--bg-card-hover); }

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}

.badge.yes { background: var(--good-soft); color: var(--good); }
.badge.no { background: var(--bad-soft); color: var(--bad); }
.badge.na { background: var(--accent-soft); color: var(--text-muted); }

.app-footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem 2.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.app-footer h3 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.app-footer ul { margin: 0.35rem 0; padding-left: 1.2rem; }

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.error-box {
  background: var(--bad-soft);
  border: 1px solid var(--bad);
  color: var(--bad);
  padding: 1rem;
  border-radius: var(--radius);
  margin: 1rem 0;
}
