:root {
  --primary:  #d97706;
  --danger:   #dc2626;
  --warning:  #f59e0b;
  --success:  #16a34a;
  --muted:    #9ca3af;
  --bg:       #0f1117;
  --surface:  #1a1f2e;
  --border:   #2d3748;
  --text:     #e2e8f0;
  --text-dim: #94a3b8;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  min-height: 100vh;
}

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

/* ── Nav ── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 0;
  height: 48px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-right: 28px;
  letter-spacing: .3px;
  text-decoration: none;
}
.nav-brand:hover { text-decoration: none; color: var(--warning); }

.nav-link {
  color: var(--text-dim);
  padding: 0 14px;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--primary); border-bottom-color: var(--primary); }

.nav-search {
  margin-left: auto;
  position: relative;
}
.nav-search input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  width: 220px;
}
.nav-search input:focus { outline: 1px solid var(--primary); }
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 200;
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.search-dropdown.open { display: block; }
.search-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: rgba(217,119,6,.1); }
.search-item-name { font-weight: 600; color: var(--text); }
.search-item-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* ── Page layout ── */
.page { padding: 24px 20px; max-width: 1400px; margin: 0 auto; }
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.page-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
select, input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  min-width: 140px;
}
select:focus, input[type="text"]:focus {
  outline: 1px solid var(--primary);
}

.btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 5px 14px;
  cursor: pointer;
  font-size: 12px;
  height: 30px;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover { background: var(--warning); border-color: var(--warning); color: #000; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
thead th {
  background: var(--surface);
  color: var(--muted);
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  letter-spacing: .3px;
}
thead th:hover { color: var(--primary); }
thead th.sort-asc::after { content: " ↑"; color: var(--primary); }
thead th.sort-desc::after { content: " ↓"; color: var(--primary); }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover td { background: rgba(217,119,6,.05); }
td { padding: 8px 12px; vertical-align: middle; }
.tr-repeat td { background: rgba(217,119,6,.06); }

/* ── Badges / pills ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .3px;
}
.badge-danger  { background: rgba(220,38,38,.2);  color: #fca5a5; }
.badge-warning { background: rgba(245,158,11,.2); color: #fcd34d; }
.badge-amber   { background: rgba(217,119,6,.2);  color: #fbbf24; }
.badge-success { background: rgba(22,163,74,.2);  color: #86efac; }
.badge-muted   { background: rgba(156,163,175,.15); color: var(--muted); }
.badge-air     { background: rgba(59,130,246,.2);  color: #93c5fd; }
.badge-industrial { background: rgba(168,85,247,.2); color: #d8b4fe; }
.badge-municipal  { background: rgba(20,184,166,.2); color: #99f6e4; }

.domain-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  margin-right: 3px;
  font-weight: 500;
}

.ratio-cell {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ratio-high   { color: #fca5a5; }
.ratio-medium { color: #fcd34d; }
.ratio-low    { color: #fbbf24; }
.ratio-bdl    { color: #86efac; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Stat row ── */
.stat-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 20px;
  min-width: 140px;
}
.stat-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.stat-sub   { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* ── Tabs ── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 8px 18px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: -1px;
  transition: color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Map page ── */
#map-page {
  display: flex;
  height: calc(100vh - 48px);
  overflow: hidden;
}
#map-sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  gap: 14px;
}
#map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

.map-title { font-size: 14px; font-weight: 700; color: var(--primary); }
.sidebar-section { display: flex; flex-direction: column; gap: 6px; }
.sidebar-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .5px; }
#map-sidebar select { min-width: unset; width: 100%; }

.legend { display: flex; flex-direction: column; gap: 5px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-red    { background: #dc2626; }
.legend-amber  { background: #d97706; }
.legend-yellow { background: #f59e0b; }
.legend-green  { background: #16a34a; }

/* ── Facility panel (map slide-in) ── */
#facility-panel {
  position: absolute;
  top: 0;
  right: -420px;
  width: 420px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 10;
  transition: right .25s ease;
  overflow-y: auto;
  padding: 20px;
}
#facility-panel.open { right: 0; }
#panel-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
#panel-close:hover { color: var(--text); }

.panel-name { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 4px; padding-right: 24px; }
.panel-meta { color: var(--muted); font-size: 11px; margin-bottom: 12px; }
.panel-section { margin-bottom: 16px; }
.panel-section-title { color: var(--primary); font-size: 10px; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.panel-events table { width: 100%; }
.panel-link { display: block; margin-top: 14px; text-align: center; }

/* ── Satellite toggle ── */
#satellite-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 11px;
  cursor: pointer;
}
#satellite-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Plotly chart containers ── */
.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}
.chart-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 10px;
}

/* ── Two-panel triage layout ── */
.triage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .triage-grid { grid-template-columns: 1fr; } }

/* ── Facility header ── */
.facility-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 20px;
}
.facility-name { font-size: 22px; font-weight: 700; }
.facility-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.facility-domains { margin-top: 8px; }

/* ── Loading / empty states ── */
.loading { color: var(--muted); padding: 40px; text-align: center; }
.empty { color: var(--muted); padding: 20px; text-align: center; font-size: 12px; }

/* ── MapLibre popup override ── */
.maplibregl-popup-content {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  padding: 12px 14px !important;
  font-size: 12px !important;
  font-family: system-ui, sans-serif !important;
  box-shadow: 0 4px 20px rgba(0,0,0,.5) !important;
}
.maplibregl-popup-tip { display: none !important; }
.popup-name { font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.popup-meta { color: var(--muted); margin-bottom: 6px; }
.popup-ratio { font-weight: 700; font-size: 14px; }
.ratio-red    { color: #fca5a5; }
.ratio-amber  { color: #fbbf24; }
.ratio-yellow { color: #fde68a; }
.ratio-green  { color: #86efac; }

/* ── Cluster count badge (HTML marker, no glyph dependency) ── */
.cluster-badge {
  width: 32px;
  height: 32px;
  background: rgba(217,119,6,.85);
  border: 2px solid #d97706;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
}
