/* light theme (default) — "engineering report" reading: warm paper, ink
   text, same hazard-signage accent language as the dark theme so the
   brand doesn't shift between modes, just the surface. */
:root,
:root[data-theme="light"] {
  --bg-0: #f4efe2;
  --bg-1: #fbf8f0;
  --bg-2: #ece5d2;
  --bg-3: #e1d8c0;
  --line: #cfc4a3;
  --text: #201d16;
  --text-dim: #6b6250;
  --hazard: #b8790a;
  --hazard-on: #fbf8f0;
  --hazard-dim: #d9ad5c;
  --danger: #a92c22;
  --danger-on: #fbf8f0;
  --danger-glow: rgba(169, 44, 34, 0.18);
  --safe: #2f6b4e;
  --shadow: rgba(40, 32, 10, 0.18);
}

/* dark theme — "nighttime highway instrumentation" */
:root[data-theme="dark"] {
  --bg-0: #0a0b0c;
  --bg-1: #121416;
  --bg-2: #1a1d20;
  --bg-3: #24282c;
  --line: #33383d;
  --text: #ece6d6;
  --text-dim: #a8a297;
  --hazard: #f0a202;
  --hazard-on: #0a0b0c;
  --hazard-dim: #8a6218;
  --danger: #d1382f;
  --danger-on: #ece6d6;
  --danger-glow: rgba(209, 56, 47, 0.35);
  --safe: #3a7d5c;
  --shadow: rgba(0, 0, 0, 0.5);
}

:root {
  --font-display: "Big Shoulders Display", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
  --font-body: "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body { flex: 1; min-height: 0; }

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  opacity: 0.04;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
}

/* header */

.hdr {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: var(--bg-1);
  border-bottom: 2px solid var(--hazard);
  position: relative;
  z-index: 10;
  flex-wrap: wrap;
}

.hdr-brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.hdr-mark {
  color: var(--hazard);
  font-size: 20px;
  line-height: 1;
  margin-top: 3px;
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.hdr h1 {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 26px;
  letter-spacing: 0.5px;
  margin: 0;
  line-height: 1;
  text-transform: uppercase;
  color: var(--text);
}

.hdr h1 .hl { color: var(--hazard); }

.hdr-sub {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.hdr-controls {
  display: flex;
  gap: 16px;
}

.control-group {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.ctl-btn {
  background: var(--bg-2);
  color: var(--text-dim);
  border: none;
  border-right: 1px solid var(--line);
  padding: 9px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ctl-btn:last-child { border-right: none; }
.ctl-btn:hover { background: var(--bg-3); color: var(--text); }
.ctl-btn.is-active {
  background: var(--hazard);
  color: var(--hazard-on);
  font-weight: 600;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.3s;
}
.theme-toggle:hover { background: var(--bg-3); transform: rotate(20deg); }

.hdr-controls { flex-wrap: wrap; row-gap: 8px; justify-content: flex-end; }

/* layout */

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  flex: 1;
  min-height: 0;
}

#map {
  height: 100%;
  width: 100%;
  background: var(--bg-0);
}

/* maplibre popup override */
.maplibregl-popup-content {
  background: var(--bg-1);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 14px;
  box-shadow: 0 4px 24px var(--shadow);
}
.maplibregl-popup-tip { border-top-color: var(--bg-1) !important; border-bottom-color: var(--bg-1) !important; }
.maplibregl-popup-close-button { color: var(--text-dim); font-size: 16px; }
.popup-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; color: var(--hazard); text-transform: uppercase; margin-bottom: 6px; }
.popup-row { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; }
.popup-row .k { color: var(--text-dim); }
.popup-flag { margin-top: 8px; padding: 4px 8px; background: var(--danger); color: var(--danger-on); border-radius: 2px; font-size: 10px; letter-spacing: 0.5px; display: inline-block; }

/* side panel */

.panel {
  background: var(--bg-1);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px;
}

.panel-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 10px;
  text-align: center;
}
.stat-danger { border-color: var(--danger); box-shadow: 0 0 16px -6px var(--danger-glow) inset; }

.stat-num {
  display: block;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.stat-danger .stat-num { color: var(--danger); }

.stat-label {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  margin: 0 0 4px;
  color: var(--text);
}

.panel-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  margin: 0 0 16px;
  line-height: 1.5;
}

.legend {
  margin-bottom: 18px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
}
.legend-title { color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }
.legend-scale {
  height: 8px;
  border-radius: 2px;
  margin-bottom: 4px;
}
.legend-labels { display: flex; justify-content: space-between; color: var(--text-dim); }

.poi-key { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--text-dim); }
.poi-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; border: 1px solid rgba(255,255,255,0.6); }

.ranked-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ranked-item {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--danger);
  border-radius: 3px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.ranked-item:hover { background: var(--bg-3); transform: translateX(2px); }
.ranked-item.is-selected {
  background: var(--bg-3);
  border-left-color: var(--hazard);
  border-color: var(--hazard);
  box-shadow: 0 0 0 1px var(--hazard);
  transform: translateX(2px);
}

.ranked-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.ranked-rank {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-right: 6px;
}

.ranked-road {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-transform: capitalize;
}

.ranked-score {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  color: var(--danger);
}

.ranked-reason {
  font-family: var(--font-body);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-dim);
}

.ranked-reason b { color: var(--hazard); font-weight: 600; }

.tag {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 7px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.tag-vue { background: var(--danger-glow); color: var(--danger); border: 1px solid var(--danger); }

.tag-class { margin-top: 4px; margin-right: 4px; }
.tag-class-critical { background: var(--danger); color: var(--danger-on); }
.tag-class-high { background: var(--danger-glow); color: var(--danger); border: 1px solid var(--danger); }
.tag-class-moderate { background: var(--bg-3); color: var(--text-dim); border: 1px solid var(--line); }
.tag-class-low { background: var(--bg-3); color: var(--text-dim); border: 1px solid var(--line); }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -8px 0 18px;
}
.filter-chip {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 5px 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.filter-chip:hover { opacity: 0.75; }

.filter-chip[data-class="Critical"].is-active { opacity: 1; background: var(--danger); color: var(--danger-on); border-color: var(--danger); }
.filter-chip[data-class="High"].is-active { opacity: 1; background: var(--danger-glow); color: var(--danger); border-color: var(--danger); }
.filter-chip[data-class="Moderate"].is-active { opacity: 1; background: var(--bg-3); color: var(--text); border-color: var(--hazard-dim); }
.filter-chip[data-class="Low"].is-active { opacity: 1; background: var(--bg-3); color: var(--text); border-color: var(--line); }

/* scrollbar */
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-track { background: var(--bg-1); }
.panel::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr 280px; }
  .panel { border-left: none; border-top: 1px solid var(--line); }
  .hdr-controls { display: none; }
}
