:root {
  --bg: #0d0d1a;
  --panel: #14142b;
  --panel-2: #1c1c38;
  --line: #2a2a4a;
  --text: #e8e8f2;
  --muted: #9a9ab8;
  --accent: #60a5fa;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ---- Header ---- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.tag {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}
.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* ---- Product chips + legend ---- */
#controls {
  flex: 0 0 auto;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px 10px;
}
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 44px;
  min-width: 52px;
  transition: background 0.15s, border-color 0.15s;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1220;
}
.chip small {
  display: block;
  font-size: 0.58rem;
  font-weight: 500;
  opacity: 0.85;
  text-align: center;
}
.legend {
  margin-top: 10px;
  padding: 0 2px;
  display: none;
}
.legend.show { display: block; }
.legend-bar {
  height: 8px;
  border-radius: 4px;
  position: relative;
}
.legend-scale {
  position: relative;
  height: 14px;
  margin-top: 2px;
  font-size: 0.6rem;
  color: var(--muted);
}
.legend-scale span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}
.legend-scale .edge-left { transform: none; left: 0; }
.legend-scale .edge-right { transform: none; right: 0; }

/* ---- Map area ---- */
#mapWrap { flex: 1 1 auto; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0a0f1e; }

#search {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 1000;
  display: flex;
  gap: 6px;
  max-width: 460px;
}
#search input {
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(20, 20, 43, 0.94);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 0.9rem;
  min-height: 44px;
  outline: none;
}
#search button {
  background: var(--accent);
  color: #0b1220;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0 16px;
  min-height: 44px;
  cursor: pointer;
}
#searchMsg {
  position: absolute;
  top: 50px;
  left: 0;
  font-size: 0.75rem;
  color: var(--bad);
  background: rgba(20, 20, 43, 0.94);
  border-radius: 8px;
  padding: 6px 10px;
  display: none;
}
#searchMsg.show { display: block; }

/* ---- Bottom panel ---- */
#panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 62dvh;
  overflow-y: auto;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.45);
  transition: transform 0.22s ease;
  touch-action: pan-y;
}
#panel.closed { transform: translateY(calc(100% - 34px)); }
#panel.closed #panelBody { visibility: hidden; }
#panelToggle {
  position: sticky;
  top: 0;
  float: right;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  margin: -4px 0 4px 8px;
}
#panel.closed #panelToggle { transform: rotate(180deg); }

.panel-loading, .panel-error {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 6px 0 12px;
}
.panel-error { color: var(--bad); }

.loc h2 {
  margin: 0 0 2px;
  font-size: 1.05rem;
}
.coord { color: var(--muted); font-size: 0.7rem; }

.riskrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 12px;
  flex-wrap: wrap;
}
.badge {
  font-weight: 800;
  font-size: 0.9rem;
  padding: 7px 14px;
  border-radius: 999px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
}
.conf { font-size: 0.75rem; color: var(--muted); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.metric {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}
.metric .name { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.metric .value { font-size: 0.95rem; font-weight: 700; margin-top: 3px; }
.metric .mean { font-size: 0.6rem; color: var(--muted); margin-top: 2px; }
.metric.hot .value { color: #fb923c; }

.tsline {
  font-size: 0.7rem;
  color: var(--muted);
  margin: 10px 0 2px;
}
.warnlist { margin: 6px 0 4px; padding-left: 16px; }
.warnlist li { font-size: 0.75rem; color: var(--muted); margin-bottom: 3px; }

.btn {
  display: block;
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 10px;
  min-height: 44px;
  cursor: pointer;
  margin: 10px 0 6px;
}
.btn:disabled { opacity: 0.55; cursor: default; }

.nowcast-area { display: none; }
.nowcast-area.show { display: block; }
.nowcast-head {
  font-size: 0.8rem;
  font-weight: 700;
  margin: 10px 0 6px;
  color: var(--text);
}
.nc-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.nc-chip {
  min-height: 44px;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  text-align: center;
}
.nc-chip .t { font-size: 0.58rem; color: var(--muted); }
.nc-chip .lvl { font-size: 0.68rem; font-weight: 700; }
.nc-note { font-size: 0.7rem; color: var(--muted); margin-top: 6px; }

/* ---- AllertaMeteo ---- */
.alert-block {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.alert-block header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--panel-2);
}
.alert-chip {
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 3px 9px;
  color: #0b1220;
}
.alert-day { padding: 8px 12px; border-top: 1px solid var(--line); }
.alert-day .day-name {
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-day .dlabel {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 5px;
}
.alert-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.7rem;
  padding: 2px 0;
  color: var(--muted);
}

footer.src {
  margin-top: 14px;
  font-size: 0.6rem;
  color: #6b6b8f;
  line-height: 1.5;
}

.map-marker {
  width: 16px;
  height: 16px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--bad);
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.35);
}
.map-marker span {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: #fff;
}

.leaflet-container {
  background: #0a0f1e;
  font-family: inherit;
}
.leaflet-control-attribution {
  background: rgba(13, 13, 26, 0.75) !important;
  color: var(--muted) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

@media (min-width: 900px) {
  #panel {
    left: auto;
    width: 420px;
    max-height: calc(100dvh - 240px);
    border-radius: var(--radius) 0 0 var(--radius);
  }
}
