:root {
  --bg: #0f1720;
  --panel: #16212c;
  --panel-2: #1d2b38;
  --line: #2a3a4a;
  --text: #e6edf3;
  --muted: #8ea1b3;
  --accent: #4cc2ff;
  --accent-ink: #04121c;
  --warn: #ffb020;
  --danger: #ff5a5f;
  --ok: #3ecf8e;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --radius: 14px;
  --topbar-h: 56px;
  --tabbar-h: 0px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f6f9;
  --panel: #ffffff;
  --panel-2: #eef3f7;
  --line: #d6dee6;
  --text: #0f1b26;
  --muted: #5b6b7a;
  --accent: #0a84d6;
  --accent-ink: #ffffff;
  --shadow: 0 6px 20px rgba(15,27,38,.12);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #f3f6f9; --panel: #ffffff; --panel-2: #eef3f7; --line: #d6dee6;
    --text: #0f1b26; --muted: #5b6b7a; --accent: #0a84d6; --accent-ink: #ffffff;
    --shadow: 0 6px 20px rgba(15,27,38,.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar {
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: relative; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; font-weight: 700; letter-spacing: .2px; }
.loc { flex: 1; min-width: 0; }
.loc-btn {
  max-width: 100%; display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
}
.loc-btn #locName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-pin { color: var(--accent); font-size: 10px; }
.caret { color: var(--muted); font-size: 11px; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); display: inline-flex; font-size: 22px; line-height: 1; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }

.tabs { display: flex; gap: 4px; }
.tabs button {
  display: flex; align-items: center; gap: 6px; background: none; border: 0;
  padding: 8px 12px; border-radius: 10px; color: var(--muted); font-weight: 600;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); background: var(--panel-2); }

@media (max-width: 760px) {
  :root { --tabbar-h: calc(60px + env(safe-area-inset-bottom)); }
  .brand span { display: none; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel); border-top: 1px solid var(--line); justify-content: space-around; gap: 0;
  }
  .tabs button { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; background: none !important; }
  .tabs button svg { width: 22px; height: 22px; }
}

/* ---------- alert banner ---------- */
.alert-banner {
  background: var(--danger); color: #fff; padding: 8px 14px; font-weight: 600; font-size: 14px;
  display: flex; gap: 8px; align-items: center; cursor: pointer; z-index: 999;
}
.alert-banner.watch { background: #d98200; }
.alert-banner.advisory { background: #6a55c9; }

/* ---------- views ---------- */
main { flex: 1; position: relative; min-height: 0; padding-bottom: var(--tabbar-h); }
.view { display: none; position: absolute; inset: 0 0 var(--tabbar-h) 0; }
.view.active { display: block; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px 16px 40px; }
.empty { padding: 60px 16px; text-align: center; color: var(--muted); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card h3 { margin: 0; font-size: 16px; }
h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.wide { width: 100%; }
select, input[type=search] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; max-width: 100%;
}
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg button { background: none; border: 0; padding: 5px 10px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.seg.small button { font-size: 13px; padding: 4px 9px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
label.check, label.radio { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
label.check.inline { display: inline-flex; font-size: 14px; }
label.range { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding-top: 4px; }
label.range input { flex: 1; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- radar map ---------- */
#map { position: absolute; inset: 0; background: #0b1016; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; max-width: 70vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13.5px; max-height: 50vh; overflow: auto; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line) !important; }

.map-panel { position: absolute; top: 12px; right: 12px; z-index: 600; max-width: calc(100% - 24px); max-height: calc(100% - 24px); display: flex; flex-direction: column; }
.panel-toggle {
  display: flex; align-items: center; gap: 6px; margin-left: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-weight: 600; box-shadow: var(--shadow);
}
.panel-body {
  display: none; margin-top: 8px; width: 290px; max-width: 100%;
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 14px; box-shadow: var(--shadow);
}
.map-panel.open .panel-body { display: block; }
@media (max-width: 760px) { .map-panel.open ~ .map-bottom { display: none; } }
.panel-body h4:first-child { margin-top: 10px; }
.panel-body select { width: 100%; margin: 2px 0 4px; }
.site-row { display: flex; gap: 6px; padding-left: 24px; }
.site-row select { flex: 1; min-width: 0; }

.map-bottom { position: absolute; left: 12px; right: 12px; bottom: 16px; z-index: 500; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; pointer-events: none; }
.map-bottom > * { pointer-events: auto; }
.player {
  display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px 6px 6px; box-shadow: var(--shadow); width: min(420px, 100%);
}
.player button { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); border: 0; display: grid; place-items: center; flex: none; }
.player button svg { fill: currentColor; stroke: none; }
.player input { flex: 1; min-width: 0; accent-color: var(--accent); }
#frameTime { font-variant-numeric: tabular-nums; font-size: 13px; min-width: 72px; text-align: right; }
.player.hidden { display: none; }
.legend {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; box-shadow: var(--shadow); font-size: 11.5px;
  max-width: 100%;
}
.legend .bar { height: 8px; width: 220px; max-width: 100%; border-radius: 4px; margin: 3px 0 2px; }
.legend .ticks { display: flex; justify-content: space-between; color: var(--muted); }
.legend .row { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.map-status { position: absolute; top: 12px; left: 56px; z-index: 500; display: flex; flex-direction: column; gap: 6px; max-width: calc(100% - 200px); }
.map-status .pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-status .pill.err { border-color: var(--danger); color: var(--danger); }
.loc-marker { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.popup-alert h5 { margin: 0 0 4px; font-size: 14px; }
.popup-alert p { margin: 4px 0; white-space: pre-wrap; }
.popup-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.popup-actions button { background: var(--accent); color: var(--accent-ink); border: 0; padding: 5px 10px; border-radius: 8px; font-weight: 600; font-size: 12.5px; }

/* ---------- forecast ---------- */
.grid-now { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
.grid-now .card { margin-bottom: 14px; }
@media (max-width: 760px) { .grid-now { grid-template-columns: 1fr; gap: 0; } }
.current .big { display: flex; align-items: center; gap: 14px; }
.current .temp { font-size: 56px; font-weight: 300; line-height: 1; }
.current .cond { font-size: 18px; font-weight: 600; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px 14px; margin-top: 14px; }
.kv div { font-size: 13px; color: var(--muted); }
.kv b { display: block; color: var(--text); font-size: 15px; font-weight: 600; }
.alert-item { border-left: 4px solid var(--danger); padding: 6px 10px; margin: 6px 0; background: var(--panel-2); border-radius: 0 8px 8px 0; }
.alert-item.watch { border-color: var(--warn); }
.alert-item.advisory { border-color: #8a74ff; }
.alert-item summary { cursor: pointer; font-weight: 600; }
.alert-item p { white-space: pre-wrap; font-size: 13px; margin: 6px 0; }
.daily { display: flex; flex-direction: column; }
.day { display: grid; grid-template-columns: 92px 40px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.day:first-child { border-top: 0; }
.day .name { font-weight: 600; }
.day .icon { font-size: 22px; text-align: center; }
.day .short { color: var(--muted); font-size: 13.5px; }
.day .hilo { font-variant-numeric: tabular-nums; white-space: nowrap; }
.day .hilo .lo { color: var(--muted); margin-left: 6px; }
.day .pop { color: var(--accent); font-size: 12px; margin-left: 6px; }
.day .detail { grid-column: 1 / -1; font-size: 13.5px; color: var(--muted); display: none; }
.day.open .detail { display: block; }
.afd { white-space: pre-wrap; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 60vh; overflow: auto; background: var(--panel-2); padding: 12px; border-radius: 10px; }
details summary { cursor: pointer; color: var(--accent); }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; text-decoration: none; color: var(--text); font-size: 13.5px; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; height: 240px; }
.chart.tall { height: 340px; }
@media (max-width: 760px) { .chart.tall { height: 290px; } }
.chart svg { width: 100%; height: 100%; stroke: none; fill: none; display: block; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .now-line { stroke: var(--accent); stroke-dasharray: 3 3; stroke-width: 1; }
.chart .hover-line { stroke: var(--muted); stroke-width: 1; }
.chart .loading, .chart .err { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; text-align: center; padding: 10px; }
.chart .err { color: var(--danger); }
.tip {
  position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; z-index: 5; min-width: 150px; display: none; white-space: nowrap;
}
.tip .t { font-weight: 600; margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; user-select: none;
}
.chip .sw { width: 10px; height: 10px; border-radius: 50%; }
.chip.off { opacity: .45; }
.chip.off .sw { background: transparent !important; border: 1.5px solid var(--muted); }
.chip.fail { border-color: var(--danger); color: var(--danger); cursor: help; }
.chip.loading { opacity: .6; }
.chip small { color: var(--muted); font-weight: 400; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mtable { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 100%; }
.mtable th, .mtable td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.mtable th:first-child, .mtable td:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); z-index: 1; }
.mtable thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
.mtable .hi { color: #ff8a65; } .mtable .lo { color: #64b5f6; } .mtable .pr { color: var(--ok); font-size: 11.5px; display: block; }
.mtable tr.cons td { font-weight: 700; background: var(--panel-2); }
.mtable tr.cons td:first-child { background: var(--panel-2); }

.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.model-grid .m { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.model-grid .m b { display: block; }
.model-grid .m span { color: var(--muted); font-size: 12px; display: block; margin-bottom: 6px; }
.model-grid .m a { font-size: 12.5px; margin-right: 10px; }

/* ---------- trends ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; }
.pos { color: #ff8a65; } .neg { color: #64b5f6; } .wet { color: var(--ok); } .dry { color: var(--warn); }
.hist { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.hist div { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); }
.hist b { display: block; color: var(--text); font-size: 18px; }

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 16px; padding: 0;
  width: min(440px, calc(100vw - 24px)); max-height: 80vh; box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(0,0,0,.5); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); margin: 0; }
.sheet-head h3 { margin: 0; }
.sheet-body { padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; max-height: calc(80vh - 60px); }
.sheet-body input[type=search] { width: 100%; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:hover { background: var(--panel-2); }
.list li small { color: var(--muted); }
.list li button { background: none; border: 0; color: var(--muted); font-size: 18px; }
label.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px); transform: translateX(-50%) translateY(20px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 2000; max-width: calc(100vw - 32px); font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

[hidden] { display: none !important; }
@media (max-width: 760px) {
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 10px; padding: 0 16px 4px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
}

.sim-links { padding: 2px 0 6px 24px; line-height: 1.5; }
