html, body { margin: 0; height: 100%; font-family: system-ui, sans-serif; overflow: hidden; }
#map { position: absolute; inset: 0; }
#status {
  position: absolute; bottom: 12px; left: 12px; z-index: 10;
  background: rgba(22, 27, 34, 0.9); color: #e6edf3;
  padding: 8px 14px; border-radius: 8px; font-size: 13px;
}
#status.stale { color: #f0a35e; }
#layers-toggle {
  position: absolute; top: 12px; left: 12px; z-index: 15;
  width: 40px; height: 40px; border-radius: 8px;
  background: rgba(22, 27, 34, 0.9); color: #e6edf3; border: none;
  font-size: 18px; line-height: 1; cursor: pointer;
}
#layers-backdrop {
  position: fixed; inset: 0; z-index: 13;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
#layers-backdrop.visible { opacity: 1; pointer-events: auto; }
#layers {
  position: fixed; top: 0; left: 0; z-index: 14;
  width: min(280px, 82vw); height: 100%; box-sizing: border-box;
  background: rgba(13, 17, 23, 0.97); color: #e6edf3;
  padding: 64px 16px 16px; font-size: 13px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto; box-shadow: 2px 0 12px rgba(0, 0, 0, 0.4);
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}
#layers.expanded { transform: translateX(0); }
#layers .panel-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #8a99a8; margin: 0 0 4px;
}
.layer-category + .layer-category { border-top: 1px solid rgba(255, 255, 255, 0.08); margin-top: 4px; padding-top: 4px; }
.layer-category-header {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: none; padding: 4px 0; margin: 0;
  font: inherit; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #8a99a8; cursor: pointer; text-align: left;
}
.layer-category-header:hover { color: #c8d4e0; }
.layer-category-header .chevron {
  display: inline-block; font-size: 10px; transition: transform 0.15s ease;
}
.layer-category.expanded .layer-category-header .chevron { transform: rotate(90deg); }
.layer-category-items {
  display: flex; flex-direction: column; gap: 6px;
  padding-left: 14px; margin-top: 2px;
  overflow: hidden; max-height: 0;
}
.layer-category.expanded .layer-category-items { max-height: 320px; }
#layers label {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  user-select: none;
}
#layers input[type="checkbox"] { accent-color: #6f93b8; cursor: pointer; }
#notify-btn {
  width: 100%; padding: 8px 10px; margin-top: 4px;
  background: #6f93b8; color: #0d1117; border: none; border-radius: 6px;
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
#notify-btn:hover { background: #82a4c7; }
#notify-status {
  font-size: 11px; color: #8a99a8; margin-top: 6px; min-height: 14px;
}
.station-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.5); cursor: pointer;
}
/* Diamond, not a circle -- rain-only stations measure something different
   from water-level stations, so the shape itself flags that at a glance,
   not just the (differently-scaled) color underneath it. */
.station-dot-rain { border-radius: 3px; transform: rotate(45deg); }
#banners {
  position: absolute; top: 12px; left: 56px; right: 56px; z-index: 10;
  display: flex; flex-direction: column; gap: 6px;
  max-width: 560px; margin: 0 auto;
  max-height: calc(100% - 24px); overflow-y: auto;
}
.banner {
  padding: 9px 14px; border-radius: 8px; font-size: 12.5px; line-height: 1.4;
  backdrop-filter: blur(8px);
}
.banner-time { display: block; margin-top: 2px; font-size: 11px; opacity: 0.8; }
.banner-warning {
  background: rgba(210, 153, 34, 0.92); color: #1a1300; border: 1px solid #d29922;
}
.banner-flood {
  background: rgba(218, 54, 51, 0.92); color: #fff; border: 1px solid #da3633;
}
.banner-placeholder {
  background: rgba(22, 27, 34, 0.85); color: #8a99a8; border: 1px solid #30363d;
  text-align: center;
}
.user-location-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: #58a6ff;
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(88, 166, 255, 0.35), 0 0 4px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
.demo-station-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(210, 153, 34, 0.25);
  border: 3px dashed #d29922;
  box-shadow: 0 0 0 4px rgba(210, 153, 34, 0.18);
  cursor: pointer;
}
.demo-viewer-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(88, 166, 255, 0.3);
  border: 3px dashed #58a6ff;
  box-shadow: 0 0 0 4px rgba(88, 166, 255, 0.18);
  cursor: pointer;
}
.demo-case-marker {
  width: 20px; height: 20px;
  background: rgba(163, 113, 247, 0.35);
  border: 3px dashed #a371f7;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  cursor: pointer;
}
.case-marker {
  width: 18px; height: 18px;
  background: #ff5630;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.popup-more-info {
  margin-top: 4px; padding: 3px 8px;
  background: #21262d; color: #6f93b8; border: 1px solid #30363d;
  border-radius: 5px; font: inherit; font-size: 11.5px; cursor: pointer;
}
.popup-more-info:hover { background: #30363d; }

/* Bottom-right, tucked just above the (compact) attribution control so
   neither one covers the other. */
#legend {
  position: absolute; bottom: 34px; right: 12px; z-index: 10;
  background: rgba(22, 27, 34, 0.9); color: #e6edf3;
  padding: 8px 12px; border-radius: 8px; font-size: 11px;
  max-height: 50vh; overflow-y: auto;
}
#legend .legend-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #8a99a8; margin: 8px 0 6px;
}
#legend .legend-title:first-child { margin-top: 0; }
#legend .legend-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
#legend .legend-row:last-child { margin-bottom: 0; }
#legend .legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
#legend .legend-dot-rain { border-radius: 2px; transform: rotate(45deg); }

/* Reuses .modal-backdrop for its click-outside-to-close behavior, but
   without the dimming -- the whole point of the station card floating
   beside the map (rather than a full modal) is that the map stays legible
   while it's open. */
#station-backdrop { background: transparent; }

/* Anchored to the right edge (not centered like .modal) so opening it reads
   as "more detail alongside the map" rather than a full-screen interrupt --
   the map stays visible through the semi-transparent backdrop, and
   openStationCard() flies the camera to keep the station itself out from
   under the card rather than physically resizing #map. */
.station-card {
  position: fixed; top: 50%; right: 32px; z-index: 20;
  width: min(340px, 90vw); max-height: 80vh; overflow-y: auto; box-sizing: border-box;
  background: #161b22; color: #e6edf3; border: 1px solid #30363d;
  border-radius: 10px; padding: 20px 22px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  transform: translateY(-50%) translateX(12px); opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.station-card.visible { opacity: 1; pointer-events: auto; transform: translateY(-50%) translateX(0); }
.station-card h3 { margin: 0 0 2px; font-size: 16px; padding-right: 22px; }
.station-card .card-close {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none; color: #e6edf3; font-size: 20px; line-height: 1;
  cursor: pointer; padding: 0 2px;
}
.station-card .card-close:hover { color: #d29922; }
.station-card-sub { font-size: 12px; color: #8a99a8; margin: 0 0 10px; }
.station-card-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.station-card-section:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }
.station-card-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #8a99a8; margin: 0 0 4px;
}
.station-card-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 3px; }
.station-card-row span:first-child { color: #8a99a8; }
.station-card-meta { font-size: 11px; color: #8a99a8; margin-top: 2px; }
.station-card-offline { color: #8a99a8; font-size: 13px; font-style: italic; margin: 0; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 19;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-backdrop.visible { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed; top: 50%; left: 50%; z-index: 20;
  width: min(360px, 88vw); max-height: 84vh; overflow-y: auto;
  background: #161b22; color: #e6edf3; border: 1px solid #30363d;
  border-radius: 10px; padding: 20px 22px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%) scale(0.96); opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.modal.visible { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal-disclaimer {
  margin: 0 0 14px; font-size: 12.5px; color: #f0a35e; font-weight: 600;
}
.modal-features { margin: 0 0 16px; padding-left: 18px; font-size: 13px; line-height: 1.5; }
.modal-features li { margin-bottom: 6px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-actions button {
  flex: 1; padding: 9px 10px; border: none; border-radius: 6px;
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
#welcome-demo-btn { background: #6f93b8; color: #0d1117; }
#welcome-demo-btn:hover { background: #82a4c7; }
#welcome-dismiss-btn { background: #21262d; color: #e6edf3; border: 1px solid #30363d !important; }
#welcome-dismiss-btn:hover { background: #30363d; }
.about-title { font-size: 13px; font-weight: 600; margin: 4px 0 6px; }
.about-note { font-size: 12px; color: #8a99a8; line-height: 1.45; margin: 0 0 10px; }
.about-subtitle {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #8a99a8; margin: 4px 0 6px;
}
.demo-btn {
  display: block; width: 100%; padding: 7px 10px; margin-bottom: 6px;
  background: #21262d; color: #e6edf3; border: 1px solid #30363d;
  border-radius: 6px; font: inherit; font-size: 12px; text-align: left; cursor: pointer;
}
.demo-btn:hover { background: #30363d; }
.demo-hidden { display: none !important; }
.demo-panel {
  /* 56px, not 12px, so this doesn't sit on top of #status (also bottom-anchored,
     33px tall) on narrower widths where the panel spans nearly the full
     viewport -- the stale-feed scenario in particular needs #status visible
     underneath it, not covered by it. */
  position: fixed; bottom: 56px; left: 50%; transform: translateX(-50%);
  z-index: 17; width: min(420px, 90vw); max-height: 42vh; overflow-y: auto;
  background: #21262d; color: #e6edf3; border: 1px solid #d29922;
  border-radius: 10px; padding: 14px 16px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  display: none; font-size: 13.5px; line-height: 1.5;
}
.demo-panel.visible { display: block; }
.demo-panel-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  font-size: 13px; margin-bottom: 6px;
}
#demo-panel-close {
  background: none; border: none; color: #e6edf3; font-size: 20px; line-height: 1;
  cursor: pointer; padding: 0 2px; flex-shrink: 0;
}
#demo-panel-close:hover { color: #d29922; }
#demo-panel-note { font-size: 12px; color: #d29922; margin: 0; }
.demo-panel hr { border: none; border-top: 1px solid rgba(255, 255, 255, 0.15); margin: 10px 0; }
#demo-panel-advisory { margin: 0; }

@media (max-width: 640px) {
  #layers { font-size: 14px; }
  .layer-category-header, #layers label { padding: 7px 0; }
  #layers input[type="checkbox"] { width: 18px; height: 18px; }

  /* MapLibre's attribution shows in full until the viewer's first pan, then
     auto-collapses -- on a narrow screen that first-paint text is wide
     enough to reach across and sit on top of #status (also bottom-left).
     Cap its width so it wraps within its own bottom-right corner instead. */
  .maplibregl-ctrl-attrib-inner { max-width: 42vw; font-size: 9px; }
}

/* On laptop+ widths there's room for the drawer to push the map aside
   instead of overlaying it (a scrim over 2/3 of a wide screen reads as
   broken, not "focused"). #map's own left offset does the pushing --
   app.js calls map.resize() on its transitionend once the shift finishes,
   since MapLibre doesn't repaint a container-only resize on its own. */
@media (min-width: 900px) {
  #layers-backdrop { display: none; }
  #map, #banners, #status { transition: left 0.22s ease; }
  body.drawer-open #map { left: min(280px, 82vw); }
  body.drawer-open #banners { left: calc(56px + min(280px, 82vw)); }
  body.drawer-open #status { left: calc(12px + min(280px, 82vw)); }
  body.drawer-open .demo-panel { left: calc(50% + min(280px, 82vw) / 2); }
}
