:root {
  --red: #e0322c;
  --ink: #1c1c22;
  --muted: #6b7280;
  --bg: #ffffff;
  --card: #ffffff;
  --border: #e6e8ec;
  --shadow: 0 6px 24px rgba(20, 22, 30, 0.18);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
.hidden { display: none !important; }

#map { position: fixed; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* Floating controls */
.fabs {
  position: fixed; top: calc(14px + var(--safe-t)); right: 14px; z-index: 5;
  display: flex; flex-direction: column; gap: 10px;
}
.fab {
  width: 44px; height: 44px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.92); color: var(--ink);
  box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer;
}
.fab.active { background: #2b7cff; color: #fff; }
.fab.busy { animation: fab-pulse 0.9s ease-in-out infinite; }
@keyframes fab-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* Top banners */
.banners {
  position: fixed; top: calc(10px + var(--safe-t)); left: 12px; right: 70px; z-index: 6;
  display: flex; flex-direction: column; gap: 8px;
}
.alert, .impact {
  border-radius: 14px; padding: 10px 14px; box-shadow: var(--shadow); cursor: pointer; color: #fff;
}
.alert { background: linear-gradient(180deg, #e53935, #c62828); }
.alert .ev { font-weight: 600; font-size: 15px; }
.alert .sub { font-size: 12px; opacity: 0.9; }
.impact { background: linear-gradient(180deg, #5c6bc0, #3949ab); }
.impact.winter { background: linear-gradient(180deg, #42a5f5, #1976d2); }
.impact.storm  { background: linear-gradient(180deg, #5c6bc0, #303f9f); }
.impact.flooding { background: linear-gradient(180deg, #26a69a, #00796b); }
.impact.heat   { background: linear-gradient(180deg, #ff7043, #e64a19); }
.impact.cold   { background: linear-gradient(180deg, #4fc3f7, #0277bd); }
.impact.wind   { background: linear-gradient(180deg, #78909c, #455a64); }
.impact .ev { font-weight: 600; font-size: 15px; }
.impact .sub { font-size: 12px; opacity: 0.92; }

/* Layers toggles */
.toggle { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--border); cursor: pointer; }
.toggle .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.toggle .dot.ring { background: #fff; }
.toggle .tlabel { flex: 1; font-size: 15px; }
.toggle .sw { width: 42px; height: 26px; border-radius: 999px; background: #c8ccd4; position: relative; flex: none; transition: background .15s; }
.toggle .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.toggle.on .sw { background: #34c759; }
.toggle.on .sw::after { transform: translateX(16px); }

/* User-location marker */
.me-marker { width: 18px; height: 18px; border-radius: 50%; background: #2b7cff; border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(43,124,255,0.25); }

/* Map popup (facilities) */
.maplibregl-popup-content { border-radius: 12px; padding: 10px 12px; }
.pop { font-size: 13px; line-height: 1.4; color: #1c1c22; }

/* List panel */
.panel {
  position: fixed; inset: 0; z-index: 3; background: var(--bg);
  padding-top: var(--safe-t); overflow-y: auto; padding-bottom: 120px;
}
.list-head { padding: 12px 16px 4px; }
.list-head h1 { margin: 0 0 8px; font-size: 26px; }
.segrow { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #eceef2; border-radius: 10px; padding: 3px; }
.seg button {
  border: none; background: transparent; padding: 6px 16px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.row { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.badge { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff; }
.badge svg { width: 20px; height: 20px; }
.row .body { min-width: 0; flex: 1; }
.row .type { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .loc { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: #9aa0aa; font-size: 12px; }
.row.cleared { opacity: 0.55; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* Bottom controls */
.bottom {
  position: fixed; left: 0; right: 0; bottom: calc(10px + var(--safe-b)); z-index: 7;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.status {
  background: rgba(255,255,255,0.92); color: var(--muted); font-size: 12px;
  padding: 5px 12px; border-radius: 999px; box-shadow: var(--shadow);
}
.status.err { color: var(--red); }
.switch {
  display: inline-flex; background: rgba(255,255,255,0.95); border-radius: 999px;
  padding: 4px; box-shadow: var(--shadow); pointer-events: auto;
}
.switch button {
  border: none; background: transparent; padding: 10px 26px; border-radius: 999px;
  font-size: 15px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.switch button.on { background: #2b7cff; color: #fff; }

/* Sheets */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 8; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--card); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 8px 20px calc(24px + var(--safe-b)); max-height: 82vh; overflow-y: auto;
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: #d0d3d9; margin: 6px auto 12px; }
.sheet h2 { font-size: 15px; color: var(--muted); margin: 16px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: #f6f7f9; color: var(--ink);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--red); color: #fff; border-color: var(--red); }
.done {
  margin-top: 20px; width: 100%; border: none; background: var(--red); color: #fff;
  font-size: 16px; font-weight: 600; padding: 14px; border-radius: 14px; cursor: pointer;
}
.note { font-size: 12px; color: var(--muted); margin: 12px 0 0; line-height: 1.4; }

/* Detail */
.d-head { display: flex; gap: 12px; align-items: center; margin: 6px 0 14px; }
.d-head .t { font-size: 20px; font-weight: 700; }
.d-head .s { font-weight: 600; }
.d-row { display: flex; padding: 6px 0; border-bottom: 1px solid var(--border); }
.d-row .k { color: var(--muted); width: 38%; }
.d-actions { display: flex; gap: 10px; margin-top: 16px; }
.d-actions a, .d-actions button {
  flex: 1; text-align: center; text-decoration: none; border: 1px solid var(--border);
  background: #f6f7f9; color: var(--ink); border-radius: 12px; padding: 12px; font-size: 15px; cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  :root { --ink: #f1f2f5; --muted: #a2a9b6; --bg: #14151a; --card: #1c1e25; --border: #2a2d36; }
  .fab, .status, .switch { background: rgba(30,32,40,0.92); }
  .seg { background: #262932; } .seg button.on { background: #3a3e49; }
  .chip { background: #262932; } .done { color: #fff; }
  .d-actions a, .d-actions button { background: #262932; }
}
