/* Meteo dashboard — system fonts, CSS custom properties, light/dark. */
:root {
  --bg: #f3f5f8; --card: #ffffff; --card-2: #f7f9fb; --fg: #17202b; --muted: #5d6b7c;
  --line: #dde3ea; --accent: #2563eb; --accent-fg: #ffffff;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --c-temp: #e4572e; --c-temp-band: rgba(228,87,46,.18); --c-dew: #0e9aa7; --c-hum: #2b7de9; --c-hum2: #8b8fd6;
  --c-press: #7c3aed; --c-wind: #2f9e44; --c-gust: #f08c00; --c-dir: #8a94a3; --c-rain: #1971c2; --c-rain2: #e03e8c; --c-sun: #e8890c; --c-uv: #9333ea;
  --grid: rgba(23,32,43,.09); --axis: #5d6b7c; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.06);
  --radius: 12px; --gap: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --card: #171e26; --card-2: #1d2530; --fg: #e6ebf1; --muted: #93a1b2;
    --line: #28323e; --accent: #5b9dff; --accent-fg: #0b1220;
    --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --c-temp: #ff7a59; --c-temp-band: rgba(255,122,89,.20); --c-dew: #3cc9d6; --c-hum: #6aa8ff; --c-hum2: #a5a8ee;
    --c-press: #b794f6; --c-wind: #5fd07a; --c-gust: #ffb02e; --c-dir: #8693a4; --c-rain: #5aa9f0; --c-rain2: #f06fb0; --c-sun: #fbb03b; --c-uv: #c084fc;
    --grid: rgba(230,235,241,.09); --axis: #93a1b2; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --card: #171e26; --card-2: #1d2530; --fg: #e6ebf1; --muted: #93a1b2;
  --line: #28323e; --accent: #5b9dff; --accent-fg: #0b1220;
  --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
  --c-temp: #ff7a59; --c-temp-band: rgba(255,122,89,.20); --c-dew: #3cc9d6; --c-hum: #6aa8ff; --c-hum2: #a5a8ee;
  --c-press: #b794f6; --c-wind: #5fd07a; --c-gust: #ffb02e; --c-dir: #8693a4; --c-rain: #5aa9f0; --c-rain2: #f06fb0; --c-sun: #fbb03b; --c-uv: #c084fc;
  --grid: rgba(230,235,241,.09); --axis: #93a1b2; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.skip { position: absolute; left: -999px; top: 0; background: var(--card); padding: 8px 12px; z-index: 20; }
.skip:focus { left: 8px; top: 8px; }

/* header */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); }
/* installed app (standalone, viewport-fit=cover): keep clear of the notch / status bar / home indicator */
.topbar { padding-top: calc(8px + env(safe-area-inset-top)); padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right)); }
main { padding-bottom: calc(16px + env(safe-area-inset-bottom)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
@media (display-mode: standalone) { body { overscroll-behavior-y: none; } }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, #f5a623, #60a5fa); }
.badge { font-size: 11px; font-weight: 600; background: var(--warn); color: #000; border-radius: 6px; padding: 1px 6px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.nav a:hover { background: var(--card-2); color: var(--fg); }
.nav a.active { background: var(--accent); color: var(--accent-fg); }
.toolbar { display: flex; gap: 6px; align-items: center; }
.station-sel { max-width: 210px; text-overflow: ellipsis; font-weight: 600; }
.station-sel[hidden] { display: none; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; outline: none; }

/* buttons & inputs */
.btn { font: inherit; font-weight: 600; color: var(--fg); background: var(--card-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; min-height: 36px; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, .cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost { background: transparent; min-width: 44px; }
.btn.active, .btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
select, input[type="date"], input[type="text"] { font: inherit; color: var(--fg); background: var(--card-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; min-height: 36px; }
.seg { display: inline-flex; }
.seg .btn { border-radius: 0; margin-left: -1px; }
.seg .btn:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg .btn:last-child { border-radius: 0 8px 8px 0; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: var(--gap); }
.controls label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.spacer { flex: 1; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; font-weight: 700; }
.page-title { font-size: 20px; margin-bottom: 4px; }
.sub { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }

/* states */
.state { display: flex; align-items: center; gap: 10px; padding: 18px; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.state-error { color: var(--bad); border-color: var(--bad); }
.state-empty { justify-content: center; text-align: center; flex-direction: column; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- live ---------- */
.live-head { display: flex; align-items: center; gap: 10px; margin-bottom: var(--gap); flex-wrap: wrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.stale { background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 25%, transparent); }
.stale-text { color: var(--bad); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.tile .big { font-size: 40px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.tile .big small { font-size: 18px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.tile .row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tile .kv { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; padding: 2px 0; }
.tile .kv span:first-child { color: var(--muted); }
.tile .kv.hi span:last-child { font-weight: 600; }
.trend { font-size: 22px; font-weight: 700; }
.trend.up { color: var(--bad); } .trend.down { color: var(--accent); } .trend.flat { color: var(--muted); }
.trend.press-up { color: var(--ok); } .trend.press-down { color: var(--warn); }
.tile-wide { grid-column: span 2; }
.wind-body { display: flex; gap: 14px; align-items: center; }
.compass { width: 150px; height: 150px; flex: none; }
.compass .ring { fill: var(--card-2); stroke: var(--line); stroke-width: 1.5; }
.compass .tick { stroke: var(--muted); stroke-width: 1; }
.compass text { fill: var(--muted); font: 600 11px var(--font); text-anchor: middle; dominant-baseline: central; }
.compass text.n { fill: var(--bad); }
.compass .needle { fill: var(--c-wind); }
.compass .gust { fill: var(--c-gust); stroke: var(--card); stroke-width: 1.5; }
.forecast { display: flex; align-items: center; gap: 8px; }
.forecast svg { width: 44px; height: 44px; }
.spark-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); margin-top: var(--gap); }
.spark .head { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); font-size: 13px; }
.spark .head b { color: var(--fg); font-size: 15px; font-variant-numeric: tabular-nums; }
.spark .plot { height: 64px; margin-top: 6px; }
.spark .plot .u-legend { display: none; }

/* live: configurable widgets (station chip, edit mode, drag & drop) */
.live-stations { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; font-size: 13px; }
.live-st { display: inline-flex; align-items: center; gap: 6px; }
.dot-sm { width: 8px; height: 8px; }
.dot-sm.ok { box-shadow: none; } .dot-sm.stale { box-shadow: none; }
.widget { position: relative; }
.w-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.w-head h2 { margin-bottom: 0; min-width: 0; }
.spark .w-head h2 { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 13px; }
.w-station { display: inline-flex; align-items: center; gap: 5px; flex: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; background: var(--card-2); }
.spark-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.w-nodata { margin-top: 4px; }
.widget.w-empty .big, .widget.w-empty .kv, .widget.w-empty .row { opacity: .45; }
.edit-bar { display: grid; gap: 10px; margin-bottom: var(--gap); border-style: dashed; border-color: var(--accent); }
.edit-row { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.live-grid.editing .widget { outline: 2px dashed color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -2px; padding-top: 48px; }
.w-edit { position: absolute; top: 6px; left: 8px; right: 8px; display: flex; gap: 4px; align-items: center; }
.w-btn { font: inherit; font-size: 14px; min-width: 32px; min-height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--card-2);
  color: var(--fg); cursor: pointer; padding: 0 6px; }
.w-btn:hover { border-color: var(--accent); }
.w-handle { cursor: grab; touch-action: none; font-size: 18px; }
.w-remove { flex: none; color: var(--bad); }
.w-edit .w-btn { flex: none; }
.w-station-sel { min-height: 32px; padding: 2px 4px; font-size: 12px; flex: 1 1 0; min-width: 0; width: 0; }
.widget.dragging { opacity: .55; outline-style: solid !important; }
.widget.dragging .w-handle { cursor: grabbing; }

/* ---------- explore ---------- */
.range-label { font-weight: 700; font-size: 16px; min-width: 0; }
.charts { display: grid; gap: var(--gap); }
.chart-card { padding: 10px 12px 6px; position: relative; }
.chart-card h2 { margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.chart-card h2 .sub { text-transform: none; letter-spacing: 0; font-weight: 400; }
.chart-host { width: 100%; }
.chart-empty { position: absolute; inset: 40px 12px 30px; display: flex; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; text-align: center; }
.chart-loading { opacity: .45; transition: opacity .15s; }
.uplot { font-family: var(--font); }
.u-legend { font-size: 12px; color: var(--fg); }
.u-legend .u-value { font-variant-numeric: tabular-nums; }
.u-select { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.res-pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- compare ---------- */
.years { display: flex; flex-wrap: wrap; gap: 6px; }
.year-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 99px; cursor: pointer; background: var(--card-2); font-variant-numeric: tabular-nums; user-select: none; }
.year-chip input { margin: 0; accent-color: var(--accent); }
.year-chip .sw { width: 10px; height: 10px; border-radius: 50%; background: transparent; border: 1px solid var(--line); }
.year-chip.on { border-color: var(--accent); }
.compare-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--gap); align-items: start; }
.compare-layout .years { max-height: 520px; overflow: auto; }

/* ---------- climate ---------- */
.heat-wrap { overflow-x: auto; }
.heat { display: grid; grid-template-columns: 48px repeat(12, minmax(34px, 1fr)); gap: 2px; min-width: 520px; font-variant-numeric: tabular-nums; }
.heat .hd { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; font-weight: 600; }
.heat .yr { font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; }
.cell { border: 0; padding: 0; margin: 0; height: 26px; border-radius: 3px; font: 600 11px var(--font); color: #111; cursor: pointer; background: var(--card-2); }
.cell.empty { background: repeating-linear-gradient(45deg, var(--card-2), var(--card-2) 4px, var(--line) 4px, var(--line) 5px); cursor: default; }
.cell.dark-bg { color: #fff; }
.cell:hover:not(.empty) { outline: 2px solid var(--fg); outline-offset: -2px; }
.legend-bar { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.legend-bar .ramp { height: 12px; width: 240px; max-width: 50%; border-radius: 6px; border: 1px solid var(--line); }

/* tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0; background: var(--card); }
table.data tbody tr:hover { background: var(--card-2); }
table.data td.when, table.data th.when { text-align: left; color: var(--muted); }
table.data td.val { font-weight: 700; }
.note { color: var(--muted); font-size: 12px; margin-top: 6px; }
.stack { display: grid; gap: var(--gap); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .tiles, .spark-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare-layout { grid-template-columns: 1fr; }
  .compare-layout .years { max-height: none; }
}
@media (max-width: 700px) {
  main { padding: 12px max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .topbar { flex-wrap: wrap; padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); gap: 6px 10px; }
  .nav { order: 3; flex-basis: 100%; }
  .toolbar { margin-left: auto; }
  .tiles, .spark-grid { grid-template-columns: 1fr; }
  .tile-wide { grid-column: auto; }
  .tile .big { font-size: 36px; }
  .compass { width: 130px; height: 130px; }
  .controls { gap: 8px; }
  .range-label { flex-basis: 100%; order: 5; }
}

/* settings page */
.settings-card { max-width: 720px; }
.settings-grid { display: grid; gap: 10px; margin-bottom: 12px; }
.setting-row { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(140px, 1fr) minmax(110px, 1fr); gap: 8px 12px; align-items: center; }
.setting-row label { font-weight: 600; }
.setting-row .sub { font-variant-numeric: tabular-nums; }
@media (max-width: 700px) {
  .setting-row { grid-template-columns: 1fr 1fr; }
  .setting-row .sub { grid-column: 1 / -1; }
}

/* station selector / labels */
.station-tag { display: inline-block; margin-left: 10px; padding: 2px 10px; border-radius: 99px; background: var(--card-2); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px; font-weight: 600; vertical-align: middle; }
.station-list { display: grid; gap: 10px; }
.station-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card-2); }
.station-item.current { border-color: var(--accent); }
.station-item h3 { font-size: 15px; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: currentColor; }
.pill.bad { color: var(--bad); border-color: currentColor; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.station-item dl { margin: 8px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; font-size: 13px; font-variant-numeric: tabular-nums; }
.station-item dt { color: var(--muted); }
.station-item dd { margin: 0; }
[hidden] { display: none !important; }

/* alert banner (watchdog) under the header */
.alert-banner { padding: 5px 16px; background: color-mix(in srgb, var(--bad) 14%, var(--card)); border-bottom: 1px solid var(--bad);
  color: var(--fg); font-size: 13px; font-weight: 600; }
.alert-banner .alert-line { padding: 1px 0; }
@media (max-width: 700px) { .alert-banner { padding: 5px 12px; } }

/* login */
.user-box { display: inline-flex; align-items: center; gap: 4px; }
.user-name { font-weight: 600; color: var(--fg); text-decoration: none; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn { text-decoration: none; display: inline-flex; align-items: center; }
.login-card { max-width: 420px; }
.login-form { display: grid; gap: 6px; margin-top: 10px; }
.login-form label { font-weight: 600; margin-top: 6px; }
.login-form .btn { margin-top: 10px; justify-self: start; }
.login-form input { width: 100%; }
input[type="password"] { font: inherit; color: var(--fg); background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-height: 36px; }

/* settings: users */
.users-table td, .users-table th { text-align: left; padding: 6px 8px; font-size: 13px; vertical-align: middle; }
.users-table .actions { display: flex; flex-wrap: wrap; gap: 4px; }
.users-table .btn { min-height: 30px; padding: 3px 8px; font-size: 12px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.inline-form input[type="text"], .inline-form input[type="password"] { min-width: 0; flex: 1 1 150px; }

/* settings: Bresser / ProWeatherLive */
.pwl-opt { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 0; }
.pwl-opt label { font-weight: 600; }
.pwl-opt input[type=radio] { width: 18px; height: 18px; margin: 0; }

/* settings: alerts */
.alert-state { display: grid; gap: 10px; }
.alert-log-wrap { margin-top: 12px; }
.alert-log-wrap h3 { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
table.data.log td, table.data.log th { text-align: left; padding: 5px 8px; font-size: 13px; }
table.data.log td.ok-cell { font-weight: 700; }
table.data.log td.ok-cell.yes { color: var(--ok); } table.data.log td.ok-cell.no { color: var(--bad); }
dl.alert-dl { margin: 0 0 10px; display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; font-size: 13px; font-variant-numeric: tabular-nums; }
dl.alert-dl dt { color: var(--muted); } dl.alert-dl dd { margin: 0; }
