/* ─── Reset & Base ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #334155;
  --border:    #475569;
  --text:      #f1f5f9;
  --text-muted:#94a3b8;
  --accent:    #38bdf8;
  --danger:    #f87171;
  --warning:   #fbbf24;
  --success:   #4ade80;
  --critical:  #b91c1c;
  --high:      #ea580c;
  --medium:    #eab308;
  --low:       #22c55e;
  --none:      #475569;
  --header-h:  64px;
  --panel-w:   380px;
  --radius:    10px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }

/* ─── Header ─────────────────────────────────────────────────────────── */
#site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: rgba(15,23,42,0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.header-inner {
  max-width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; gap: 16px;
}
.header-title { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.header-icon { font-size: 28px; filter: drop-shadow(0 0 8px #f87171); }
h1 { font-size: 1.25rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.subtitle { font-size: 0.7rem; color: var(--text-muted); }

.header-controls { display: flex; align-items: center; gap: 12px; flex: 1; justify-content: flex-end; }

/* Search */
.search-wrap { position: relative; width: 280px; }
#school-search {
  width: 100%; padding: 8px 14px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 0.85rem; outline: none; transition: border .2s;
}
#school-search:focus { border-color: var(--accent); }
.search-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 200;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-top: 4px;
  list-style: none; overflow-y: auto; max-height: 260px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.search-dropdown li {
  padding: 9px 14px; cursor: pointer; font-size: 0.82rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--surface2); transition: background .15s;
}
.search-dropdown li:hover { background: var(--surface2); }
.search-dropdown .tier-badge {
  font-size: 0.7rem; padding: 2px 7px; border-radius: 20px; font-weight: 600;
}
.tier-Critical { background: var(--critical); color: #fff; }
.tier-High     { background: var(--high);     color: #fff; }
.tier-Medium   { background: var(--medium);   color: #000; }
.tier-Low      { background: var(--low);      color: #000; }
.tier-None     { background: var(--none);     color: #fff; }

/* Layer toggles */
.layer-toggles { display: flex; gap: 6px; }
.toggle-btn {
  padding: 5px 10px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); font-size: 0.75rem;
  cursor: pointer; transition: all .2s; white-space: nowrap;
}
.toggle-btn.active {
  background: var(--surface2); color: var(--text); border-color: var(--accent);
}
.toggle-btn:hover { border-color: var(--accent); color: var(--text); }

/* ─── Map ─────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  top: var(--header-h); left: 0; right: 0; bottom: 0;
}

/* ─── Legend ─────────────────────────────────────────────────────────── */
#legend {
  position: fixed; bottom: 24px; left: 16px; z-index: 50;
  background: rgba(30,41,59,0.92); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; min-width: 160px;
  backdrop-filter: blur(6px);
}
#legend h3 { font-size: 0.78rem; font-weight: 700; margin-bottom: 8px; color: var(--text-muted); text-transform: uppercase; letter-spacing:.05em; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; margin: 4px 0; color: var(--text); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.facility-dot { background: #60a5fa; border: 2px solid #fff; }
.carc-dot     { background: #f472b6; border: 2px solid #fff; }
#legend hr { border-color: var(--border); margin: 8px 0; }
.legend-stats { font-size: 0.72rem; color: var(--text-muted); line-height: 1.6; }

/* ─── Side Panel ─────────────────────────────────────────────────────── */
.side-panel {
  position: fixed; top: var(--header-h); right: 0; bottom: 0; z-index: 80;
  width: var(--panel-w); background: var(--surface);
  border-left: 1px solid var(--border); overflow-y: auto;
  transition: transform .3s ease; padding: 20px;
}
.side-panel.hidden { transform: translateX(100%); }
.close-btn {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 1.1rem; cursor: pointer; padding: 2px 6px; border-radius: 4px;
  position: absolute; top: 16px; right: 16px; transition: color .2s;
}
.close-btn:hover { color: var(--danger); }

/* Panel content */
.panel-type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted); margin-bottom: 4px; }
.panel-name { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.panel-city { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 14px; }

.tier-banner {
  border-radius: 8px; padding: 12px 16px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px;
}
.tier-banner.Critical { background: rgba(185,28,28,.2); border: 1px solid var(--critical); }
.tier-banner.High     { background: rgba(234,88,12,.2);  border: 1px solid var(--high); }
.tier-banner.Medium   { background: rgba(234,179,8,.2);  border: 1px solid var(--medium); }
.tier-banner.Low      { background: rgba(34,197,94,.15); border: 1px solid var(--low); }
.tier-banner.None     { background: rgba(71,85,105,.2);  border: 1px solid var(--none); }
.tier-banner .tier-label { font-size: 1rem; font-weight: 700; }
.tier-banner .tier-desc  { font-size: 0.75rem; color: var(--text-muted); line-height: 1.3; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card { background: var(--surface2); border-radius: 8px; padding: 10px 12px; }
.stat-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.stat-value.danger { color: var(--danger); }
.stat-value.warning { color: var(--warning); }
.stat-value.success { color: var(--success); }

.section-title {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted); margin: 16px 0 8px;
  border-bottom: 1px solid var(--border); padding-bottom: 4px;
}

/* Facility list */
.facility-item {
  background: var(--surface2); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
  border-left: 3px solid var(--border); transition: border-color .2s;
}
.facility-item.carc { border-left-color: #f472b6; }
.facility-item.high-risk { border-left-color: var(--danger); }
.fac-name { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.fac-dist { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }
.fac-chem { font-size: 0.7rem; color: var(--accent); margin-top: 4px; }
.fac-air  { font-size: 0.7rem; color: var(--text-muted); }
.carc-tag {
  display: inline-block; background: rgba(244,114,182,.15);
  border: 1px solid #f472b6; color: #f472b6;
  font-size: 0.65rem; padding: 1px 6px; border-radius: 10px; margin-left: 6px; vertical-align: middle;
}
.no-facilities { color: var(--text-muted); font-size: 0.82rem; text-align: center; padding: 20px; }

/* Chart container */
.chart-wrap { position: relative; height: 180px; margin-top: 8px; }

/* ─── About button & modal ────────────────────────────────────────────── */
.about-btn {
  position: fixed; bottom: 24px; right: 16px; z-index: 60;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.78rem; padding: 7px 14px;
  border-radius: 20px; cursor: pointer; transition: all .2s;
}
.about-btn:hover { color: var(--text); border-color: var(--accent); }

.modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 32px; max-width: 580px; width: 90%;
  max-height: 80vh; overflow-y: auto; position: relative; font-size: 0.85rem; line-height: 1.6;
}
.modal-box h2 { font-size: 1.2rem; margin-bottom: 14px; color: var(--text); }
.modal-box p  { margin-bottom: 10px; color: var(--text-muted); }
.modal-box ul { padding-left: 18px; color: var(--text-muted); margin-bottom: 10px; }
.modal-box li { margin-bottom: 4px; }
.modal-box a  { color: var(--accent); }
.modal-box strong { color: var(--text); }
.small { font-size: 0.72rem; color: var(--border); }

/* ─── Loading overlay ─────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(15,23,42,.85); display: flex; align-items: center; justify-content: center;
}
.loading-overlay.hidden { display: none; }
.loading-box { text-align: center; color: var(--text); }
.spinner {
  width: 40px; height: 40px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── MapLibre overrides ──────────────────────────────────────────────── */
.maplibregl-popup-content {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px; font-size: 0.8rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.maplibregl-popup-tip { display: none; }
.popup-name { font-weight: 700; margin-bottom: 4px; }
.popup-meta { color: var(--text-muted); font-size: 0.73rem; }
.popup-tier { font-size: 0.75rem; font-weight: 600; margin-top: 4px; }

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .header-controls { gap: 8px; }
  .search-wrap { width: 200px; }
  .layer-toggles { display: none; }
  .side-panel { width: 100%; top: auto; bottom: 0; height: 70vh; border-left: none; border-top: 1px solid var(--border); }
  #legend { bottom: 12px; }
}
