:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eef1f7; --border: rgba(30,41,59,.12);
  --text: #16202f; --muted: #5b6b84; --accent: #0e7fa8;
  --sev-severe: #b0203a; --sev-flood: #e0522f; --sev-slight: #d99a1d; --sev-normal: #1f9d6e;
  --font-ui: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #121b2d; --surface-2: #182238; --border: rgba(148,163,184,.16);
    --text: #e7ecf5; --muted: #93a2bd; --accent: #59c3ea;
    --sev-severe: #e0536a; --sev-flood: #f0784f; --sev-slight: #f0b93b; --sev-normal: #34d399;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #121b2d; --surface-2: #182238; --border: rgba(148,163,184,.16);
  --text: #e7ecf5; --muted: #93a2bd; --accent: #59c3ea;
  --sev-severe: #e0536a; --sev-flood: #f0784f; --sev-slight: #f0b93b; --sev-normal: #34d399;
}
:root[data-theme="light"] {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eef1f7; --border: rgba(30,41,59,.12);
  --text: #16202f; --muted: #5b6b84; --accent: #0e7fa8;
  --sev-severe: #b0203a; --sev-flood: #e0522f; --sev-slight: #d99a1d; --sev-normal: #1f9d6e;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); }
body { color: var(--text); font-family: var(--font-ui); line-height: 1.45; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
a { color: var(--accent); }

#app { position: relative; height: 100vh; height: 100dvh; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--text); }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { font-family: var(--font-ui); font-size: .85rem; line-height: 1.4; }
.leaflet-control-zoom { margin-bottom: 1.1rem !important; }

/* ---- side panel (Google Maps style) ---- */
.panel {
  position: absolute; top: 0; left: 0; bottom: 0; width: 400px; max-width: 88vw;
  background: var(--surface); border-right: 1px solid var(--border);
  box-shadow: 2px 0 16px rgba(0,0,0,.18);
  display: flex; flex-direction: column; z-index: 500;
  transition: transform .22s ease;
}
.panel.collapsed { transform: translateX(-100%); }

.hdr { padding: .9rem 1rem .6rem; border-bottom: 1px solid var(--border); flex: none; }
.hdr-top { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
h1 { font-size: 1.12rem; font-weight: 750; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
.hdr-sub { margin: .3rem 0 0; color: var(--muted); font-size: .78rem; }
.hdr-sub #asOf { font-variant-numeric: tabular-nums; font-family: var(--font-mono); color: var(--text); }

.live-pill {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .65rem; font-weight: 700;
  letter-spacing: .04em; color: var(--sev-flood); border: 1px solid currentColor; border-radius: 999px;
  padding: .12rem .5rem .12rem .4rem; flex: none;
}
.live-pill .dot { width: .42rem; height: .42rem; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .live-pill .dot { animation: none; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.search-row { padding: .7rem 1rem 0; flex: none; }
#search {
  width: 100%; padding: .55rem .75rem; font-size: .88rem; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-family: inherit;
}
#search:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.zones { display: flex; flex-wrap: wrap; gap: .35rem; padding: .55rem 1rem 0; flex: none; }
.zone-btn {
  font: inherit; font-size: .74rem; padding: .3rem .65rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.zone-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.zone-btn.on { background: var(--accent); color: #04141c; border-color: var(--accent); font-weight: 650; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; padding: .7rem 1rem; flex: none; }
.kpi { background: var(--surface-2); border-radius: 9px; padding: .5rem .3rem; text-align: center; }
.kpi .v { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .62rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: .05rem; }
.kpi:nth-child(1) .v { color: var(--sev-severe); }
.kpi:nth-child(2) .v { color: var(--sev-flood); }
.kpi:nth-child(3) .v { color: var(--sev-slight); }
.kpi.muted .v { color: var(--sev-normal); }

.list-wrap { flex: 1 1 auto; overflow-y: auto; border-top: 1px solid var(--border); padding: .7rem 1rem; min-height: 0; }
.list-hdr { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .5rem; }
.list-hdr .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
.road-list { display: grid; gap: .5rem; }
.loading { padding: 1.5rem 0; text-align: center; color: var(--muted); font-size: .85rem; }

.road-card {
  background: var(--surface-2); border-left: .28rem solid var(--sev);
  border-radius: 8px; padding: .55rem .7rem; cursor: pointer; transition: background .1s;
}
.road-card:hover, .road-card:focus-visible { background: var(--border); }
.road-card .rc-top { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; }
.road-card .rc-name { font-weight: 700; font-size: .87rem; }
.road-card .rc-peak { font-family: var(--font-mono); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--sev); font-size: .82rem; white-space: nowrap; }
.road-card .rc-district { color: var(--muted); font-size: .74rem; margin-top: .1rem; }
.rc-sources { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.rc-sources:empty { display: none; }
.src-tag { font-size: .62rem; padding: .1rem .4rem; border-radius: 999px; background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.src-tag.src-itic { color: var(--sev-flood); border-color: var(--sev-flood); }
.src-tag.src-traffy { color: var(--sev-slight); border-color: var(--sev-slight); }

.foot { padding: .8rem 1rem 1rem; font-size: .68rem; color: var(--muted); border-top: 1px solid var(--border); flex: none; }
.foot p { margin: 0 0 .4rem; }
.muted { color: var(--muted); }

#panelToggle {
  position: absolute; top: 1rem; left: 400px; z-index: 501; transform: translateX(-50%);
  width: 1.9rem; height: 1.9rem; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 1px 5px rgba(0,0,0,.25); transition: left .22s ease;
}
#panelToggle.collapsed { left: 0; }
#panelToggle svg { transition: transform .22s ease; }
#panelToggle.collapsed svg { transform: rotate(180deg); }

.legend {
  position: absolute; right: .75rem; bottom: .75rem; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .5rem .7rem; font-size: .72rem; display: flex; flex-direction: column; gap: .3rem;
  box-shadow: 0 1px 8px rgba(0,0,0,.18);
}
.lg-item { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
.lg-item .sw { width: 1rem; height: .35rem; border-radius: 3px; background: var(--c); flex: none; }

.layers-ctl {
  position: absolute; right: .75rem; top: .75rem; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .55rem .7rem; font-size: .78rem; box-shadow: 0 1px 8px rgba(0,0,0,.18);
  display: flex; flex-direction: column; gap: .3rem; min-width: 9.5rem;
}
.lc-title { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .1rem; }
.lc-row { display: flex; align-items: center; gap: .45rem; cursor: pointer; }
.lc-row input { accent-color: var(--accent); width: .95rem; height: .95rem; flex: none; }

.radar-ctl {
  position: absolute; left: .75rem; bottom: .75rem; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .35rem .6rem; font-size: .74rem; box-shadow: 0 1px 8px rgba(0,0,0,.18);
  display: flex; align-items: center; gap: .5rem; font-family: var(--font-mono);
}
.radar-ctl.hidden { display: none; }
.radar-ctl button {
  width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
}
.radar-ctl button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.leaflet-popup-content .m { color: var(--muted); font-size: .78rem; }
.leaflet-popup-content .big { font-size: 1.2rem; font-weight: 700; font-family: var(--font-mono); }
.leaflet-popup-content h3 { margin: .2rem 0; font-size: .95rem; }

@media (max-width: 720px) {
  .layers-ctl { top: auto; bottom: .5rem; right: .5rem; font-size: .72rem; }
  .radar-ctl { left: .5rem; bottom: .5rem; }

  .panel { width: 100%; max-width: 100%; bottom: auto; height: 62vh; top: auto; bottom: 0;
    border-right: none; border-top: 1px solid var(--border); border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.25); }
  .panel.collapsed { transform: translateY(calc(100% - 3.2rem)); }
  #panelToggle { top: auto; bottom: calc(62vh - .95rem); left: 50%; transform: translateX(-50%) rotate(-90deg); }
  #panelToggle.collapsed { bottom: 2.25rem; transform: translateX(-50%) rotate(90deg); }
  .legend { right: .5rem; bottom: .5rem; font-size: .66rem; }
}
