/* Community Weather Map — MOBILE build
   ------------------------------------------------------------------
   Touch-first layout: full-bleed map, slim top bar, floating action
   buttons, a draggable bottom sheet for the alert feed, and a popover
   layer panel. Pin / popup / severity styling is carried over verbatim
   from the desktop build so the two stay visually consistent.

   Safe-area insets (env(safe-area-inset-*)) keep controls clear of the
   notch and the iOS home indicator. */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1f2a37;
  background: #e5e7eb;
}

#app { position: fixed; inset: 0; }

/* ---------- Top bar ---------- */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: calc(46px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0 12px;
  background: #1f2a37;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1200;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
#topbar .brand { font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }
#topbar .status-cluster { display: flex; align-items: center; gap: 6px; }
#topbar .pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.14);
  border-radius: 12px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

/* status dot — green ok, amber warn, red error */
.dot { width: 9px; height: 9px; border-radius: 50%; background: #10b981; display: inline-block; flex-shrink: 0; }
.dot.warn  { background: #f59e0b; }
.dot.error { background: #ef4444; }

/* ---------- Map ---------- */
#map {
  position: absolute;
  top: calc(46px + env(safe-area-inset-top));
  left: 0; right: 0; bottom: 0;
}
/* Leaflet zoom control gets in the way of the top bar / fabs on a phone —
   we ship our own controls, so hide the default and bump attribution up
   clear of the collapsed sheet. */
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  font-size: 9px;
  background: rgba(255,255,255,0.7);
}

/* ---------- Floating action buttons ---------- */
#fabs {
  position: absolute;
  right: 12px;
  /* Sit above the collapsed sheet handle (which is ~58px tall + safe area). */
  bottom: calc(74px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1100;
}
.fab {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #1f2a37;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 120ms ease, transform 80ms ease;
}
.fab:active { transform: scale(0.92); }
.fab .fab-icon { font-size: 22px; line-height: 1; }
.fab.active { background: #2563eb; color: #fff; }
.fab.hidden { display: none; }
/* "locating" pulse while we wait on the GPS fix */
.fab.locating .fab-icon { animation: fab-spin 1s linear infinite; }
@keyframes fab-spin { to { transform: rotate(360deg); } }

/* ---------- Layer panel (popover above the FABs) ---------- */
#layerPanel {
  position: absolute;
  right: 12px;
  bottom: calc(134px + env(safe-area-inset-bottom));
  width: 240px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  padding: 12px 14px;
  z-index: 1150;
  font-size: 14px;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#layerPanel.hidden { display: none; }
.lp-header { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.lp-group { margin-bottom: 12px; }
.lp-group:last-child { margin-bottom: 0; }
.lp-group-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #6b7280; margin-bottom: 4px;
}
.lp-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  font-size: 14px;
  cursor: pointer;
}
.lp-row input { width: 20px; height: 20px; margin: 0; accent-color: #2563eb; }

/* ---------- Bottom sheet ---------- */
#sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -3px 16px rgba(0,0,0,0.22);
  z-index: 1300;
  display: flex;
  flex-direction: column;
  /* Default (expanded) height; collapsed/full states override via classes.
     Transition only fires when we're NOT actively dragging. */
  /* Initial fallback only — JS (setSheetState) drives the real height in px so
     it tracks the visible viewport. max-height intentionally NOT set in vh. */
  height: 55vh;
  transition: height 220ms cubic-bezier(.22,.61,.36,1);
}
#sheet.dragging { transition: none; }
#sheet.collapsed { height: calc(58px + env(safe-area-inset-bottom)); }
#sheet.full { height: 88vh; }

#sheetHandle {
  flex-shrink: 0;
  padding: 8px 16px 10px 16px;
  cursor: grab;
  user-select: none;
  touch-action: none; /* we manage drag here; body list scrolls normally */
}
#sheetHandle .grabber {
  width: 40px; height: 5px;
  border-radius: 3px;
  background: #d1d5db;
  margin: 0 auto 8px auto;
}
.sheet-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 14px; color: #374151;
}
.sheet-title strong { font-size: 15px; color: #1f2a37; flex-shrink: 0; }
/* Label takes remaining space and ellipsizes so the row stays ONE line — keeps
   the collapsed handle at a fixed 58px even when the storm badge is present. */
.sheet-title-label { color: #6b7280; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.storm-badge {
  flex-shrink: 0;
  display: inline-flex; align-items: center;
  background: #fef3c7; color: #b45309;
  font-size: 12px; font-weight: 700;
  padding: 2px 9px; border-radius: 11px;
}
.storm-badge.hidden { display: none; }

#sheetBody {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}
#sheet.collapsed #sheetBody { display: none; }

/* ---------- Sheet controls ---------- */
.sheet-controls {
  flex-shrink: 0;
  padding: 4px 16px 12px 16px;
  border-bottom: 1px solid #eef0f3;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#scopeFilter {
  width: 100%;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  color: #1f2a37;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.sev-toggles {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: 13px; color: #4b5563;
}
.sev-toggles label { display: flex; align-items: center; gap: 6px; }
.sev-toggles input { width: 18px; height: 18px; margin: 0; accent-color: #2563eb; }
#nextThreatBtn {
  align-self: flex-start;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
#nextThreatBtn:active { background: #1d4ed8; }

/* ---------- Bubble feed ---------- */
#bubblesList { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 12px 16px 12px; }
.bubble-empty { color: #9ca3af; font-size: 14px; text-align: center; padding: 28px 12px; }
.bubble {
  background: #f9fafb;
  border-left: 4px solid #9ca3af;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.bubble:active { background: #eef0f3; }
.bubble.warning  { border-left-color: #dc2626; background: #fef2f2; }
.bubble.watch    { border-left-color: #f97316; background: #fff7ed; }
.bubble.advisory { border-left-color: #eab308; background: #fefce8; }
.bubble .b-event { font-weight: 700; font-size: 14px; color: #1f2a37; }
.bubble .b-community { font-size: 13px; color: #374151; margin-top: 2px; }
.bubble .b-meta { font-size: 12px; color: #6b7280; margin-top: 5px; display: flex; gap: 10px; align-items: center; }
.bubble .region-badge {
  display: inline-block; min-width: 20px; height: 20px; border-radius: 10px;
  padding: 0 7px; color: #fff; font-size: 12px; font-weight: 600;
  text-align: center; line-height: 20px;
}

/* ---------- Legend ---------- */
/* Anchored bottom-left (above the collapsed sheet) so the transient stale-data
   banner at the top can never overlap it. Hidden behind the sheet when it's
   expanded, which is fine — you're reading the feed then, not the map legend. */
#legend {
  position: absolute;
  bottom: calc(66px + env(safe-area-inset-bottom));
  left: 10px;
  background: rgba(255,255,255,0.95);
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  font-size: 12px;
  z-index: 1000;
  display: none;
}
#legend.visible { display: block; }
#legend h4 { margin: 0 0 5px 0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #6b7280; }
#legend div { display: flex; align-items: center; margin: 2px 0; }
#legend .swatch { display: inline-block; width: 13px; height: 13px; margin-right: 7px; border-radius: 2px; }

/* ---------- Power outages overlay (outages.js) ---------- */
.outage-shade { cursor: pointer; }
.outage-popup { font-size: 14px; line-height: 1.45; min-width: 190px; max-width: 78vw; }
.outage-popup .op-title { font-weight: 700; font-size: 15px; margin-bottom: 6px; color: #1f2a37; }
.outage-popup .op-row { margin: 3px 0; }
.outage-popup .op-label { color: #6b7280; }
.outage-popup .op-meta { font-size: 12px; color: #6b7280; margin-top: 4px; }
.outage-popup .op-source { margin-top: 6px; padding-top: 6px; border-top: 1px solid #e5e7eb; font-style: italic; }

/* ---------- Radar loop timeline ---------- */
/* Bottom-center, above the collapsed sheet, shown only while looping. The
   legend is hidden during playback so they never collide. */
#animControl {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(74px + env(safe-area-inset-bottom));
  background: rgba(31,42,55,0.92);
  color: #fff;
  border-radius: 20px;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  z-index: 1100;
  font-size: 12px;
  min-width: 130px;
}
#animControl.hidden { display: none; }
.anim-time { font-weight: 600; }
.anim-dots { display: flex; gap: 5px; }
.anim-dots .dot { width: 7px; height: 7px; border-radius: 50%; background: #6b7280; }
.anim-dots .dot.active { background: #fbbf24; }
.anim-dots .dot.latest { background: #10b981; }

/* ---------- Stale-data banner ---------- */
#banner {
  position: absolute;
  top: calc(54px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  background: #fef3c7;
  color: #92400e;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  z-index: 1250;
  display: none;
}
#banner.visible { display: block; }

/* ---------- "You are here" GPS marker ---------- */
.gps-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #2563eb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 4px rgba(37,99,235,0.25), 0 1px 4px rgba(0,0,0,0.4);
}

/* ===========================================================
   Pin styling (carried over from desktop for consistency)
   =========================================================== */
.community-pin-wrap { position: relative; width: 30px; height: 30px; }
.community-pin {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  color: #fff; font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 1px 1px rgba(0,0,0,0.4);
  position: relative; z-index: 1;
}
.community-pin-halo {
  position: absolute;
  top: -10px; left: -10px;
  width: 50px; height: 50px;
  border-radius: 50%;
  border: 3px solid transparent;
  pointer-events: none;
  opacity: 0; z-index: 0;
}
.community-pin-wrap[data-alert="advisory"] .community-pin-halo {
  border-color: #eab308; opacity: 1; animation: pin-halo-pulse 1.6s ease-in-out infinite;
}
.community-pin-wrap[data-alert="watch"] .community-pin-halo {
  border-color: #f97316; opacity: 1; animation: pin-halo-pulse 1.4s ease-in-out infinite;
}
.community-pin-wrap[data-alert="warning"] .community-pin-halo {
  border-color: #dc2626; opacity: 1; animation: pin-halo-pulse 1.1s ease-in-out infinite;
}
@keyframes pin-halo-pulse {
  0%   { transform: scale(0.85); opacity: 0.85; }
  50%  { transform: scale(1.20); opacity: 0.30; }
  100% { transform: scale(0.85); opacity: 0.85; }
}

/* ===========================================================
   Popups — sized for a phone, larger touch targets
   =========================================================== */
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-content-wrapper { border-radius: 12px; }
.popup-card { font-size: 14px; line-height: 1.45; min-width: 200px; max-width: 78vw; }
.popup-card h3 { margin: 0 0 6px 0; font-size: 16px; }
.popup-card .row { margin-bottom: 4px; }
.popup-card .label { color: #6b7280; display: inline-block; min-width: 76px; }
.popup-card .notes { margin-top: 6px; padding-top: 6px; border-top: 1px solid #e5e7eb; font-style: italic; color: #4b5563; }
.popup-card .section { margin-top: 8px; padding-top: 6px; border-top: 1px solid #e5e7eb; }
.popup-card .section-title { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }

.popup-alerts {
  margin: 0 0 8px 0; padding: 7px 9px;
  background: #fef2f2; border-left: 4px solid #9ca3af; border-radius: 4px; font-size: 13px;
}
.popup-alerts.advisory { background: #fefce8; border-left-color: #eab308; }
.popup-alerts.watch    { background: #fff7ed; border-left-color: #f97316; }
.popup-alerts.warning  { background: #fef2f2; border-left-color: #dc2626; }
.popup-alerts .pa-title { font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: 0.06em; color: #6b7280; margin-bottom: 3px; }
.popup-alerts .pa-item { display: flex; justify-content: space-between; gap: 8px; line-height: 1.4; }
.popup-alerts .pa-event { font-weight: 600; color: #1f2a37; }
.popup-alerts .pa-until { color: #6b7280; font-size: 12px; white-space: nowrap; }

/* Expandable alert full-text: tap an event title to reveal the NWS bulletin.
   Body is height-capped + scrolls so a long bulletin never blows out the popup. */
.alert-details { margin: 0; }
.alert-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 4px 0;            /* bigger tap target for touch */
}
.alert-summary::-webkit-details-marker { display: none; }
.alert-summary::before {
  content: '\25B8';          /* ▸ caret */
  color: #6b7280;
  font-size: 11px;
  line-height: 1.4;
  transition: transform 0.12s ease;
}
.alert-details[open] > .alert-summary::before { transform: rotate(90deg); }
.popup-card .alert-event { font-weight: 600; font-size: 15px; color: #1f2a37; }
.alert-fulltext {
  margin-top: 6px;
  max-height: 240px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid #e5e7eb;
  padding-top: 6px;
}
.alert-fulltext .aft-body {
  white-space: pre-wrap;     /* preserve NWS line breaks */
  font-size: 13px;
  line-height: 1.5;
  color: #374151;
}
.alert-fulltext .aft-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  margin: 8px 0 2px;
}
.alert-fulltext.empty { font-style: italic; color: #6b7280; font-size: 13px; }

/* "Listen Online" → county Broadcastify scanner feed (opens in a new tab) */
.popup-card .listen-online { margin-top: 8px; }
.popup-card .listen-online a {
  display: inline-flex; align-items: center; gap: 5px;
  color: #2563eb; text-decoration: none; font-weight: 600; font-size: 14px;
}
.popup-card .listen-online .lo-sub { color: #6b7280; font-weight: 400; font-size: 12px; }

/* zone-shading click popup */
.popup-zone .zp-ugc { font-size: 12px; color: #6b7280; margin-bottom: 8px; }
.popup-zone .zp-list { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; }
.popup-zone .zp-item { padding: 7px 9px; background: #f9fafb; border-left: 4px solid #9ca3af; border-radius: 4px; font-size: 13px; line-height: 1.4; }
.popup-zone .zp-item.zp-advisory { background: #fefce8; border-left-color: #eab308; }
.popup-zone .zp-item.zp-watch    { background: #fff7ed; border-left-color: #f97316; }
.popup-zone .zp-item.zp-warning  { background: #fef2f2; border-left-color: #dc2626; }
.popup-zone .zp-event { font-weight: 600; color: #1f2a37; }
.popup-zone .zp-headline { color: #4b5563; margin-top: 2px; font-size: 12px; }
.popup-zone .zp-meta { display: flex; gap: 10px; color: #6b7280; font-size: 12px; margin-top: 3px; }

.leaflet-interactive.zone-shade { cursor: pointer; }

/* product type pills */
.product-pills { margin: 6px 0 4px 0; display: flex; gap: 5px; }
.product-pill { display: inline-block; padding: 3px 9px; border-radius: 11px; color: #fff; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }

/* main phone row — tel: link is a primary mobile action, make it obvious */
.popup-card .main-phone { margin-top: 6px; font-weight: 500; }
.popup-card .main-phone a {
  color: #fff; background: #2563eb; text-decoration: none;
  padding: 7px 12px; border-radius: 8px; display: inline-block; font-weight: 600;
}

/* region badge inside popups */
.region-badge { display: inline-block; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 7px; color: #fff; font-size: 12px; font-weight: 600; text-align: center; line-height: 20px; }

/* ---------- Forecast section (forecast.js) ---------- */
.forecast-section { margin-top: 8px; }
.forecast-section .fc-loading { font-size: 13px; color: #6b7280; font-style: italic; padding: 4px 0; }
.forecast-section .fc-error { font-size: 13px; color: #b45309; padding: 4px 0; }
.forecast-section .section-title { font-weight: 600; font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 4px; }
.fc-row {
  display: grid;
  grid-template-columns: 64px 48px 1fr;
  grid-template-areas: "name temp short" "name temp wind";
  font-size: 13px; line-height: 1.4; padding: 4px 0; border-bottom: 1px dotted #e5e7eb;
}
.fc-row:last-child { border-bottom: none; }
.fc-row .fc-name { grid-area: name; font-weight: 600; color: #1f2a37; align-self: center; }
.fc-row .fc-temp { grid-area: temp; font-weight: 600; color: #dc2626; align-self: center; font-size: 14px; }
.fc-row .fc-short { grid-area: short; color: #374151; }
.fc-row .fc-wind { grid-area: wind; font-size: 12px; color: #6b7280; }

/* marker cluster sizing — a touch larger for fingers */
.marker-cluster div { font-size: 13px; font-weight: 700; }

/* ===========================================================
   Tropical cyclones (hurricanes.js)
   =========================================================== */
/* Storm position marker on the map */
.storm-marker {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
  color: #fff; font-size: 13px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 1px 1px rgba(0,0,0,0.5);
}
/* Category badge in the storm popup heading */
.popup-card .storm-cat-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 11px;
  color: #fff; font-size: 12px; font-weight: 700;
  margin-left: 6px; vertical-align: middle;
}

/* Tropical Cyclones section inside the bottom sheet */
#storms {
  flex-shrink: 0;
  padding: 10px 16px 12px 16px;
  border-bottom: 1px solid #eef0f3;
  background: #fffdf7;
}
#storms.hidden { display: none; }
.storms-header {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: #b45309; margin-bottom: 8px;
}
.storm-card {
  background: #fff;
  border: 1px solid #f1e4cf;
  border-left: 4px solid #6b7280;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.storm-card:last-child { margin-bottom: 0; }
.storm-card:active { background: #fafafa; }
.storm-card-row { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.storm-cat {
  display: inline-block; min-width: 30px; padding: 2px 7px;
  border-radius: 11px; color: #fff; font-size: 12px; font-weight: 700; text-align: center;
}
.storm-name { font-weight: 700; font-size: 15px; color: #1f2a37; }
.storm-meta { color: #4b5563; font-size: 13px; }
.storm-nearest { color: #6b7280; font-size: 12px; margin-top: 2px; }

/* Per-model selector inside the layer panel */
#modelTogglePanel { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid #eef0f3; }
#modelTogglePanel.visible { display: block; }
.model-group { margin-bottom: 10px; }
.model-group:last-child { margin-bottom: 0; }
.model-group-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #6b7280; margin-bottom: 4px;
}
.model-toggle { display: flex; align-items: center; gap: 8px; padding: 7px 0; cursor: pointer; }
.model-toggle input { width: 18px; height: 18px; margin: 0; accent-color: #2563eb; }
.model-swatch { display: inline-block; width: 16px; height: 3px; border-radius: 2px; }
.model-label { font-size: 13px; color: #374151; }
.model-status { font-size: 11px; color: #6b7280; margin-top: 6px; line-height: 1.4; }
.model-status.error { color: #b45309; }
.model-status:empty { display: none; }
