/* Community Weather Map — styles */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #1f2a37; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Header ---------- */
#header {
  background: #1f2a37;
  color: #fff;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  z-index: 1000;
  flex-wrap: wrap;
}
#header h1 { font-size: 15px; margin: 0; font-weight: 600; }
#header .spacer { flex: 1; }
.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #374151;
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #10b981; display: inline-block; }
.dot.warn { background: #f59e0b; }
.dot.error { background: #ef4444; }

.header-controls { display: flex; gap: 8px; align-items: center; }
.header-controls label { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.header-controls select {
  background: #374151; color: #fff; border: 1px solid #4b5563;
  padding: 3px 6px; border-radius: 4px; font-size: 12px;
}
.header-controls button {
  background: #2563eb; color: #fff; border: none;
  padding: 4px 10px; border-radius: 4px; font-size: 12px; cursor: pointer;
}
.header-controls button:hover { background: #1d4ed8; }
.header-controls button:disabled { background: #4b5563; cursor: not-allowed; }

/* ---------- Main layout ---------- */
#main { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; min-height: 0; }

#bubbles {
  width: 320px;
  background: #f9fafb;
  border-left: 1px solid #e5e7eb;
  display: flex; flex-direction: column;
  min-height: 0;
  transition: width 200ms ease;
  position: relative;
}
#bubblesHeader { padding: 12px 14px; border-bottom: 1px solid #e5e7eb; background: #fff; }
#bubblesHeader h2 { margin: 0; font-size: 13px; font-weight: 600; color: #374151; flex: 1; }
.bubblesHeader-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bubbles-toggle {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  color: #374151;
  width: 24px; height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.bubbles-toggle:hover { background: #e5e7eb; }

/* ---------- Collapsed panel state ---------- */
#bubblesCollapsed {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  gap: 8px;
}
#bubbles.collapsed { width: 44px; }
#bubbles.collapsed #bubblesHeader,
#bubbles.collapsed #bubblesList { display: none; }
#bubbles.collapsed #bubblesCollapsed { display: flex; }
.collapsed-count {
  background: #ef4444; color: #fff;
  min-width: 26px; height: 26px;
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  padding: 0 6px;
}
.collapsed-count.zero { background: #d1d5db; color: #6b7280; }
.collapsed-label {
  font-size: 10px;
  color: #6b7280;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* On narrow screens (phones), make the expanded panel overlay the map instead of pushing it */
@media (max-width: 700px) {
  #bubbles { position: absolute; right: 0; top: 0; bottom: 0; z-index: 800; box-shadow: -2px 0 8px rgba(0,0,0,0.12); }
  #bubbles.collapsed { box-shadow: -1px 0 4px rgba(0,0,0,0.08); }
}
.bubble-controls { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: #6b7280; }
.bubble-controls label { display: flex; align-items: center; gap: 3px; cursor: pointer; }

#bubblesList { flex: 1; overflow-y: auto; padding: 8px; }
.bubble-empty { color: #9ca3af; font-size: 13px; text-align: center; padding: 24px 12px; font-style: italic; }

.bubble {
  background: #fff;
  border-radius: 6px;
  border-left: 4px solid #9ca3af;
  padding: 9px 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  font-size: 13px;
  line-height: 1.4;
  animation: slideIn 250ms ease-out;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}
.bubble:hover { background: #f9fafb; transform: translateX(-2px); }
.bubble:active { transform: translateX(0); }
.bubble.warning  { border-left-color: #dc2626; }
.bubble.watch    { border-left-color: #f97316; }
.bubble.advisory { border-left-color: #eab308; }

.bubble .b-event { font-weight: 600; color: #1f2a37; }
.bubble .b-community { color: #374151; }
.bubble .b-meta { font-size: 11px; color: #6b7280; margin-top: 3px; display: flex; gap: 8px; align-items: center; }
.bubble .region-badge { display: inline-block; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 6px; color: #fff; font-size: 11px; font-weight: 600; text-align: center; line-height: 18px; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---------- Pin styling ---------- */
/* The pin is wrapped so we can stack a pulsing halo behind it when the
   community is under an active NWS alert. Halo color follows severity:
   yellow=advisory, orange=watch, red=warning. The wrapper carries a
   data-alert attribute set by JS each time alerts refresh. */
.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;   /* sit above the halo */
  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;
}
/* Severity colors match the bubble feed left-borders for visual consistency */
.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; }
}

/* ---------- Popup card ---------- */
.popup-card { font-size: 13px; line-height: 1.4; min-width: 240px; }
.popup-card h3 { margin: 0 0 6px 0; font-size: 14px; }
.popup-card .row { margin-bottom: 3px; }
.popup-card .label { color: #6b7280; display: inline-block; min-width: 80px; }
.popup-card .notes { margin-top: 6px; padding-top: 6px; border-top: 1px solid #e5e7eb; font-style: italic; color: #4b5563; }
.popup-card .section { margin-top: 6px; 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: 3px; }

/* Active-alerts section in pin popups. Shown only when the community has at
   least one active NWS alert; left-border color matches the highest-severity
   alert. Same severity palette as the bubble feed and pin halos. */
.popup-alerts {
  margin: 0 0 8px 0;
  padding: 6px 8px;
  background: #fef2f2;
  border-left: 4px solid #9ca3af;
  border-radius: 3px;
  font-size: 12px;
}
.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.35;
}
.popup-alerts .pa-event { font-weight: 600; color: #1f2a37; }
.popup-alerts .pa-until { color: #6b7280; font-size: 11px; white-space: nowrap; }

/* ---------- Zone-shading click popup ---------- */
/* Popup that fires when the user clicks a shaded county or forecast zone.
   Lists every active NWS alert affecting that UGC, sorted highest-severity
   first. Color tier matches pin halos, bubble feed, and popup-alerts. */
.popup-zone .zp-ugc {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.popup-zone .zp-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.popup-zone .zp-item {
  padding: 6px 8px;
  background: #f9fafb;
  border-left: 4px solid #9ca3af;
  border-radius: 3px;
  font-size: 12px;
  line-height: 1.35;
}
.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: 11.5px; }
.popup-zone .zp-meta { display: flex; gap: 10px; color: #6b7280; font-size: 11px; margin-top: 3px; }

/* Make shaded polygons feel clickable on hover. */
.leaflet-interactive.zone-shade { cursor: pointer; }
.leaflet-interactive.zone-shade:hover { fill-opacity: 0.45 !important; }

/* ---------- Legend ---------- */
#legend {
  position: absolute;
  bottom: 24px;
  left: 12px;
  background: rgba(255,255,255,0.95);
  padding: 10px 12px;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  font-size: 12px;
  z-index: 999;
  display: none;
}
#legend.visible { display: block; }
#legend h4 { margin: 0 0 6px 0; font-size: 12px; font-weight: 600; }
#legend .swatch { display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: middle; border-radius: 2px; }

/* ---------- Stale-data banner ---------- */
#banner {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  background: #fef3c7;
  color: #92400e;
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 13px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  z-index: 1000;
  display: none;
}
#banner.visible { display: block; }

/* ---------- Region filter chip in bubble ---------- */
.bubble .b-region { font-weight: 600; color: #4b5563; }

/* ---------- Product Type pills (AL / MC / IL) ---------- */
.product-pills {
  margin: 6px 0 4px 0;
  display: flex;
  gap: 4px;
}
.product-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: help;
}

/* ---------- Main phone row ---------- */
.popup-card .main-phone { margin-top: 4px; font-weight: 500; }
.popup-card .main-phone a { color: #2563eb; text-decoration: none; }
.popup-card .main-phone a:hover { text-decoration: underline; }

/* ---------- Tropical Cyclone storm marker (on the map) ---------- */
.storm-marker {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 1px 1px rgba(0,0,0,0.5);
}

/* Storm category badge inside popup heading */
.popup-card .storm-cat-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---------- Tropical Cyclones sidebar panel ---------- */
#storms {
  border-top: 1px solid #e5e7eb;
  background: #fff;
  padding: 12px 14px 8px;
}
#storms.hidden { display: none; }
.storms-header h2 { margin: 0 0 8px 0; font-size: 13px; font-weight: 600; color: #374151; }
#bubbles.collapsed #storms { display: none; }

.storm-card {
  background: #f9fafb;
  border-radius: 6px;
  border-left: 4px solid #6b7280;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 120ms ease;
}
.storm-card:hover { background: #f3f4f6; }
.storm-card-row { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.storm-cat {
  display: inline-block;
  min-width: 28px;
  padding: 2px 6px;
  border-radius: 10px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.storm-name { font-weight: 600; color: #1f2a37; }
.storm-meta { color: #6b7280; font-size: 11px; }
.storm-nearest { color: #4b5563; font-size: 11px; margin-top: 2px; }

/* ---------- Model toggle panel ---------- */
#modelTogglePanel {
  position: absolute;
  bottom: 24px;
  right: 12px;
  width: 200px;
  background: rgba(255,255,255,0.97);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  padding: 10px 12px;
  font-size: 12px;
  z-index: 999;
  display: none;
  max-height: 60vh;
  overflow-y: auto;
}
#modelTogglePanel.visible { display: block; }
.model-panel-header {
  font-weight: 600;
  font-size: 12px;
  color: #1f2a37;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e5e7eb;
}
.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: 6px;
  padding: 3px 0;
  cursor: pointer;
}
.model-toggle input { margin: 0; }
.model-swatch {
  display: inline-block;
  width: 16px; height: 3px;
  border-radius: 2px;
}
.model-label { font-size: 12px; color: #374151; }
.model-status {
  font-size: 11px;
  color: #6b7280;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #e5e7eb;
  line-height: 1.4;
}
.model-status.error { color: #b45309; }
.model-status:empty { display: none; }

/* On phones the model panel can crowd; shrink and move to bottom-left */
@media (max-width: 700px) {
  #modelTogglePanel {
    right: 8px; bottom: 8px;
    width: 170px; max-height: 50vh;
  }
}

/* ---------- Animation control (radar + satellite playback) ---------- */
#animControl {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 42, 55, 0.92);
  color: #fff;
  border-radius: 24px;
  padding: 6px 10px 6px 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  z-index: 999;
  font-size: 12px;
}
#animControl.hidden { display: none; }
.anim-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.anim-btn:hover { background: #1d4ed8; }
.anim-btn.playing { background: #dc2626; }
.anim-btn.playing:hover { background: #b91c1c; }
.anim-track { display: flex; flex-direction: column; gap: 3px; min-width: 110px; }
.anim-time { font-weight: 600; font-size: 12px; }
.anim-dots { display: flex; gap: 3px; }
.anim-dots .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #4b5563;
}
.anim-dots .dot.active { background: #fbbf24; }
.anim-dots .dot.latest { background: #10b981; }

@media (max-width: 700px) {
  #animControl { bottom: 12px; padding: 4px 8px 4px 4px; gap: 8px; }
  .anim-btn { width: 28px; height: 28px; font-size: 11px; }
  .anim-track { min-width: 90px; }
}

/* ---------- Power Outages overlay (visual-only, see outages.js) ---------- */
.outage-shade { cursor: pointer; }
.outage-shade:hover { fill-opacity: 0.6 !important; }

.outage-popup { font: 13px system-ui, sans-serif; min-width: 200px; }
.outage-popup .op-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: #1f2a37;
}
.outage-popup .op-row { margin: 2px 0; }
.outage-popup .op-label { color: #6b7280; }
.outage-popup .op-meta {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
}
.outage-popup .op-source {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #e5e7eb;
  font-style: italic;
}

/* ---------- Forecast section in community pin popups (forecast.js) ---------- */
.forecast-section { margin-top: 6px; }
.forecast-section .fc-loading {
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
  padding: 4px 0;
}
.forecast-section .fc-error {
  font-size: 12px;
  color: #b45309;
  padding: 4px 0;
}
.forecast-section .section-title {
  /* Matches the existing .section .section-title pattern so it visually
     groups with on-site / region sections in the popup. */
  font-weight: 600;
  font-size: 12px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 3px;
}
.fc-row {
  display: grid;
  grid-template-columns: 65px 50px 1fr;
  grid-template-areas:
    "name temp short"
    "name temp wind";
  font-size: 12px;
  line-height: 1.35;
  padding: 3px 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: 13px;
}
.fc-row .fc-short { grid-area: short; color: #374151; }
.fc-row .fc-wind {
  grid-area: wind;
  font-size: 11px;
  color: #6b7280;
}
