*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { background: #1a2e40; font-family: 'DM Sans', system-ui, sans-serif; }

/* ── Animations ───────────────────────────────── */
@keyframes loadFlow {
  0%   { transform: translateX(-300%); }
  100% { transform: translateX(700%); }
}
@keyframes pulseLive {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.45; transform: scale(0.75); }
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes dotPing {
  0%   { transform: scale(1); opacity: 0.4; }
  75%  { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}
@keyframes wxSpin {
  to { transform: rotate(360deg); }
}

.load-bar { animation: loadFlow 1.6s ease-in-out infinite; }
.live-dot { animation: pulseLive 2.5s ease-in-out infinite; }
.dot-ping { animation: dotPing 2s ease-out infinite; }
.fade-up  { animation: fadeSlideUp 0.55s ease forwards; }

/* ── Nav / header buttons ─────────────────────── */
.nav-btn {
  transition: color 0.18s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
.nav-btn:active { transform: scale(0.82); }

/* ── Number tabular ───────────────────────────── */
.tabular { font-variant-numeric: tabular-nums; }

/* ── Smooth data transitions ──────────────────── */
#cfs-value, #temp-value, #gauge-value { transition: opacity 0.25s ease; }

/* ── iOS safe area ────────────────────────────── */
.safe-nav { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }

/* ════════════════════════════════════════════════
   MOBILE — default
   ════════════════════════════════════════════════ */

/* Background: fixed behind card, constrained to mobile frame */
#hero-bg {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: 100vh;
  height: 100svh;
  z-index: 0;
  overflow: hidden;
  will-change: transform;
}

/* Bottom nav: visible on mobile */
#bottom-nav  { display: none; } /* hidden until content loads via JS */
#desktop-nav { display: none; }

/* Card spacer (how much of the bg shows above the card) */
#hero-spacer { height: 52vh; height: 52svh; }

/* Card width — full on mobile */
#main-card { border-radius: 40px 40px 0 0; }

/* Stats: right column stacks vertically on mobile */
#stats-right { flex-direction: column; gap: 10px; }

/* CFS font — smaller on mobile */
#cfs-value { font-size: clamp(52px, 14vw, 68px); }

/* Chart width matches card on mobile */
#chart-svg { width: 100%; }

/* Loading/error: full screen overlays */
#state-loading, #state-error {
  position: fixed;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: 100vh; height: 100svh;
  z-index: 20;
}

/* ════════════════════════════════════════════════
   DESKTOP — ≥ 900px
   ════════════════════════════════════════════════ */
@media (min-width: 900px) {

  body { overflow-x: hidden; }

  /* Background: full viewport width, no centering constraint */
  #hero-bg {
    max-width: none;
    left: 0;
    transform: none;
    /* Keep translateY set by JS, but base transform is none */
  }

  /* Outer wrapper: allow full width */
  #outer-wrapper {
    display: block;
    max-width: none;
  }

  /* App frame: full width */
  #app-frame {
    max-width: none !important;
    width: 100%;
  }

  /* Spacer: taller on desktop (more image visible) */
  #hero-spacer { height: 58vh; height: 58svh; }

  /* Card: constrained width, centered, floating on the image */
  #main-card {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    border-radius: 32px 32px 0 0;
    padding: 48px 64px 80px;
  }

  /* Top section: river name + chip in a row */
  #card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 32px;
  }

  /* CFS row: larger number on desktop */
  #cfs-value { font-size: 88px; }

  /* Stats row: horizontal on desktop */
  #stats-right {
    flex-direction: row;
    gap: 40px;
    align-items: flex-start;
  }

  /* Divider between stats on desktop */
  #stats-divider { height: 90px; }

  /* Wider chart */
  #chart-svg { width: 100%; }

  /* Footer row */
  #card-footer { margin-top: 28px; }

  /* Desktop header nav: visible */
  #desktop-nav { display: flex; }

  /* Bottom nav: hidden on desktop */
  #bottom-nav  { display: none !important; }

  /* Loading/error: full screen, no max-width */
  #state-loading, #state-error {
    max-width: none;
    left: 0;
    transform: none;
  }

  /* Hero spacer: extra top padding clears the 60px fixed header */
  #hero-spacer { padding-top: 60px; }

  /* Secondary text scale-up on desktop */
  #station-chip         { font-size: 14px !important; }
  #cfs-unit             { font-size: 20px !important; }
  #river-level-label    { font-size: 13px !important; }
  #gauge-value          { font-size: 40px !important; }
  #gauge-unit           { font-size: 16px !important; }
  #status-badge         { font-size: 13px !important; }
  #water-temp-label     { font-size: 13px !important; }
  #temp-value           { font-size: 40px !important; }
  #temp-advisory        { font-size: 13px !important; }
  #cfs-status           { font-size: 20px !important; }
  #card-quote           { font-size: 18px !important; margin-top: 28px; }
  #chart-label          { font-size: 14px !important; }
  #update-time          { font-size: 14px !important; }
  #chart-legend-week span { font-size: 13px !important; }
  #typical-legend-item span { font-size: 13px !important; }
  #weather-section-label { font-size: 14px !important; }
  #weather-location     { font-size: 14px !important; }
  #freshness-label      { font-size: 13px !important; }
  #usgs-link            { font-size: 13px !important; }

  /* Weather strip: larger on desktop, full width */
  #weather-strip { gap: 16px; }
  .wx-card {
    flex: 1;
    flex-shrink: 1;
    width: auto;
    padding: 32px 24px 24px;
    gap: 6px;
  }
  .wx-icon { font-size: 44px; margin-bottom: 12px; }
  .wx-name { font-size: 18px; }
  .wx-temp { font-size: 56px; }
  .wx-desc { font-size: 22px; }
  .wx-wind { font-size: 18px; }
  .wx-precip { font-size: 18px; }
}

/* ════════════════════════════════════════════════
   MAP TAB PANEL
   ════════════════════════════════════════════════ */
#tab-map {
  position: fixed;
  left: 0; right: 0;
  top: 0;
  bottom: calc(62px + env(safe-area-inset-bottom, 0px)); /* clear mobile bottom nav */
  z-index: 150;
  background: #1a2e40;
  display: flex;
}

#map-leaflet {
  flex: 1;
  min-width: 0;
  height: 100%;
  position: relative;
  z-index: 1; /* creates stacking context — keeps all Leaflet z-indices contained here */
}

@media (min-width: 900px) {
  #tab-map {
    top: 60px; /* clear desktop header nav */
    bottom: 0;
  }
}

/* ── River Overview Toggle Button (mobile only) ── */
#ro-toggle {
  position: absolute;
  bottom: 20px;
  right: 16px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  background: #F3E9D9;
  border: none;
  border-radius: 99px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #1A1A1A;
  cursor: pointer;
}

@media (min-width: 900px) {
  #ro-toggle { display: none; }
}

/* ── River Overview Panel ─────────────────────── */
#river-overview {
  width: 85vw;
  max-width: 340px;
  flex-shrink: 0;
  background: #F3E9D9;
  overflow-y: auto;
  border-left: 1px solid rgba(0,0,0,0.08);
  height: 100%;
  /* mobile: slide in from right as an overlay */
  position: absolute;
  right: 0; top: 0; bottom: 0;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 900;
  box-shadow: -4px 0 24px rgba(0,0,0,0.18);
}

#river-overview.ro-open {
  transform: translateX(0);
}

@media (min-width: 900px) {
  #river-overview {
    position: static;
    width: 300px;
    transform: none;
    transition: none;
    box-shadow: none;
    display: block;
  }
  #river-overview.ro-open { transform: none; }
}

#ro-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 850;
  background: rgba(0,0,0,0.25);
}

@media (min-width: 900px) {
  #ro-backdrop { display: none !important; }
}

#river-overview-inner {
  padding: 16px 0 24px;
}

.ro-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 12px 16px;
}

.ro-header-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(26,26,26,0.35);
}

.ro-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.06);
  color: rgba(26,26,26,0.5);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.ro-close-btn:hover { background: rgba(0,0,0,0.12); }

@media (min-width: 900px) {
  .ro-close-btn { display: none; }
}

.ro-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.ro-row:hover { background: rgba(0,0,0,0.04); }
.ro-row.ro-active { background: rgba(29,110,179,0.10); }

.ro-row.ro-tributary { padding-left: 32px; }

.ro-line {
  position: absolute;
  left: 22px;
  top: 0; bottom: 0;
  width: 2px;
  background: rgba(29,110,179,0.18);
}
.ro-row.ro-tributary .ro-line { display: none; }

.ro-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  z-index: 1;
}

.ro-label {
  flex: 1;
  min-width: 0;
}
.ro-station-name {
  font-size: 12px;
  font-weight: 700;
  color: #1A1A1A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.ro-river-name {
  font-size: 10px;
  color: rgba(26,26,26,0.45);
  line-height: 1.3;
  margin-top: 1px;
}

.ro-stats {
  text-align: right;
  flex-shrink: 0;
}
.ro-cfs {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #1A1A1A;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.ro-gauge {
  font-size: 10px;
  color: rgba(26,26,26,0.45);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.ro-loading .ro-cfs {
  background: rgba(0,0,0,0.08);
  border-radius: 4px;
  color: transparent;
  min-width: 40px;
  display: inline-block;
}

.ro-divider {
  height: 1px;
  background: rgba(0,0,0,0.08);
  margin: 8px 16px;
}

/* ── Leaflet popup — match app design ─────────── */
.leaflet-popup-content-wrapper {
  background: #F3E9D9;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  font-family: 'DM Sans', system-ui, sans-serif;
  padding: 0;
  border: none;
}
.leaflet-popup-content {
  margin: 0;
}
.leaflet-popup-tip {
  background: #F3E9D9;
}
.leaflet-popup-close-button {
  color: rgba(26,26,26,0.35) !important;
  font-size: 18px !important;
  top: 8px !important;
  right: 10px !important;
}

.map-popup {
  padding: 16px 20px 18px;
  min-width: 190px;
}
.map-popup-name {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 15px;
  color: #C9A86A;
  line-height: 1.2;
  margin-bottom: 2px;
}
.map-popup-site {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(26,26,26,0.35);
  margin-bottom: 14px;
}
.map-popup-stats {
  display: flex;
  gap: 18px;
}
.map-popup-stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.map-popup-val {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #1A1A1A;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.map-popup-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(26,26,26,0.35);
}

/* ── Map legend ───────────────────────────────── */
.map-legend {
  background: rgba(243,233,217,0.94);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: 'DM Sans', system-ui, sans-serif;
  box-shadow: 0 4px 16px rgba(0,0,0,0.16);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(26,26,26,0.6);
}
.legend-item + .legend-item { margin-top: 5px; }
.legend-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.85);
}

/* ── Map tooltips ─────────────────────────────── */
.leaflet-tooltip.map-tooltip {
  background: #F3E9D9;
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: #1A1A1A;
  padding: 6px 10px;
  line-height: 1.4;
}
.leaflet-tooltip.map-tooltip strong { font-weight: 700; }
.leaflet-tooltip.map-tooltip::before { border-top-color: #F3E9D9; }

/* ════════════════════════════════════════════════
   WEATHER STRIP
   ════════════════════════════════════════════════ */
#weather-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}
#weather-strip::-webkit-scrollbar { display: none; }

.wx-card {
  flex-shrink: 0;
  width: 130px;
  background: rgba(243,233,217,0.65);
  border: 1px solid rgba(26,26,26,0.08);
  border-radius: 14px;
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.wx-icon {
  font-size: 26px;
  line-height: 1;
  margin-bottom: 6px;
}
.wx-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(26,26,26,0.38);
}
.wx-temp {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: #1A1A1A;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.wx-desc {
  font-size: 13px;
  font-weight: 500;
  color: rgba(26,26,26,0.5);
  line-height: 1.3;
}
.wx-wind {
  font-size: 12px;
  font-weight: 600;
  color: rgba(26,26,26,0.32);
  margin-top: 3px;
}
.wx-precip {
  font-size: 12px;
  font-weight: 700;
  color: #1D6EB3;
}

/* ── Weather loading spinner ──────────────────── */
.wx-spinner {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 1.5px solid rgba(26,26,26,0.15);
  border-top-color: rgba(26,26,26,0.38);
  border-radius: 50%;
  animation: wxSpin 0.7s linear infinite;
  vertical-align: middle;
  margin-left: 5px;
  flex-shrink: 0;
}
