*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1a1d23;
  --surface:   #23272f;
  --border:    #2e3340;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --accent:    #4f8ef7;
  --sidebar-w: 280px;
  --header-h:  60px;
  --detail-h:  320px;
  --radius:    6px;
}

html, body {
  height: 100%;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  /* overflow: hidden removed — it clips position:fixed modals in Firefox */
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
}

#brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  white-space: nowrap;
  flex-shrink: 0;
}
#brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  line-height: 1.2;
}
#brand-sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

#window-picker {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.win-label {
  font-size: 11px;
  color: var(--muted);
  margin-right: 3px;
  white-space: nowrap;
}
.win-btn {
  padding: 5px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.win-btn:hover  { background: var(--border); color: var(--text); }
.win-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#date-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
#date-tabs::-webkit-scrollbar { display: none; }

.date-tab {
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.date-tab:hover  { background: var(--border); color: var(--text); }
.date-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Main ─────────────────────────────────────────────────────────────────── */
#main {
  display: flex;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h)); /* dvh: mobile browser URL bar collapse */
  overflow: hidden;
  transition: height 0.2s ease;
}
#main.detail-open {
  height: calc(100vh - var(--header-h) - var(--detail-h));
  height: calc(100dvh - var(--header-h) - var(--detail-h));
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#filter-bar {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#state-filter {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
}
#state-filter:focus { outline: none; border-color: var(--accent); }

#park-count { color: var(--muted); font-size: 12px; }

#park-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#sidebar-footer {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  text-align: center;
}
#sidebar-footer a { color: var(--muted); text-decoration: none; }
#sidebar-footer a:hover { color: var(--accent); }

.park-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.park-item:hover  { background: var(--border); }
.park-item.active { background: rgba(79,142,247,0.15); }

.park-rank { color: var(--muted); font-size: 11px; min-width: 22px; }

.park-name-wrap { flex: 1; min-width: 0; }
.park-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.park-wx { font-size: 11px; color: var(--muted); }

.score-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  color: #fff;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ── Map ──────────────────────────────────────────────────────────────────── */
#map { flex: 1; background: #e8e0d8; }

.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius) !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  overflow: hidden !important;
  padding: 0 !important;
  width: 200px !important;
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content {
  font-size: 13px;
  line-height: 1.6;
  margin: 0 !important;
  padding: 0 !important;
  width: 200px !important;
  max-width: 200px !important;
}

.popup-photo-link { display: block; line-height: 0; overflow: hidden; }
.popup-photo-link:hover .popup-photo { opacity: 0.88; }
.popup-photo {
  display: block;
  width: 200px !important;
  max-width: 200px !important;
  height: 110px !important;
  object-fit: cover;
  object-position: center;
  transition: opacity 0.15s;
}
.popup-body {
  padding: 8px 12px 10px;
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.popup-body strong { font-size: 13px; }
.popup-meta { font-size: 11px; color: var(--muted); }

/* Layer control — keep it clean against the light map */
.leaflet-control-layers {
  border: 1px solid #ccc !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
}
.leaflet-control-layers-toggle { width: 32px !important; height: 32px !important; }
.leaflet-control-layers-expanded { padding: 8px 12px !important; font-size: 13px !important; }

/* ── Detail panel ─────────────────────────────────────────────────────────── */
#detail {
  height: var(--detail-h);
  background: var(--surface);
  border-top: 2px solid var(--border);
  padding: 24px 20px 12px 16px;
  position: relative;
  display: flex;
  gap: 20px;
  align-items: stretch;
  overflow: hidden;
}
#detail.hidden { display: none; }

#detail-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
#detail-close:hover { color: var(--text); }

#detail-info { min-width: 160px; padding-top: 2px; align-self: flex-start; }
#detail-info h2 { font-size: 14px; font-weight: 700; margin-bottom: 6px; line-height: 1.3; }
#detail-meta { font-size: 11px; color: var(--muted); line-height: 1.8; }
.dnr-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.dnr-link:hover { text-decoration: underline; }

#chart-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-x: auto; overflow-y: hidden; }
#chart-inner { flex: 1; min-width: 0; position: relative; }

/* ── Info button ──────────────────────────────────────────────────────────── */
#info-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
#info-btn:hover { color: var(--text); border-color: var(--accent); }

/* ── Info modal ───────────────────────────────────────────────────────────── */
#info-modal {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#info-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px;
  position: relative;
}

#info-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--border);
  border: none;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
#info-close:hover { background: var(--accent); color: #fff; }

.info-section { padding: 8px 0 16px; }
.info-section:first-child { padding-right: 36px; } /* keep title clear of close button */
.info-section h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.info-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 12px;
}
.info-section > p {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 10px;
}

hr.info-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

/* Factor list — grid keeps pill column fixed-width so text always left-aligns */
.factor-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}
.factor-list li,
.bonus-note {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}
.bonus-note { color: var(--muted); font-size: 12px; margin-top: 2px; }

.pill {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 3px 6px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  text-align: center;
  white-space: nowrap;
}

/* Color legend */
.color-legend { margin: 8px 0 8px; }
.color-bar {
  height: 10px;
  border-radius: 99px;
  background: linear-gradient(to right,
    rgb(215,48,39),
    rgb(240,130,50) 50%,
    rgb(254,224,139) 80%,
    rgb(166,217,106) 90%,
    rgb(26,152,80)
  );
  margin-bottom: 5px;
}
.color-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.info-footer {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  padding-bottom: 4px;
}
.info-footer a { color: var(--accent); text-decoration: none; }
.info-footer a:hover { text-decoration: underline; }

/* ── Sidebar toggle (header button, mobile only) ──────────────────────────── */
#sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
  line-height: 1;
}
#sidebar-toggle:hover { color: var(--accent); }

/* ── Sidebar backdrop ─────────────────────────────────────────────────────── */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1040; /* above Leaflet panes (≤700) and controls (1000) */
}
#sidebar-backdrop.visible { display: block; }

/* ── Detail drag handle ───────────────────────────────────────────────────── */
#detail-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#detail-handle::after {
  content: '';
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transition: background 0.15s;
}
#detail-handle:hover::after { background: var(--muted); }

/* ── Mobile breakpoint ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --header-h: 96px;   /* two rows: brand/buttons + trip picker/date tabs */
    --detail-h: 300px;
  }

  #sidebar-toggle { display: flex; align-items: center; }
  #brand-sub { display: none; }

  /* Header wraps to two rows: row 1 = ☰ brand ⓘ, row 2 = trip picker + date tabs */
  #header {
    flex-wrap: wrap;
    align-content: center;
    row-gap: 6px;
    padding: 8px 10px;
    gap: 8px;
  }
  #window-picker { order: 3; }
  #date-tabs     { order: 4; flex: 1; min-width: 0; }

  #sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: min(320px, 85vw);
    z-index: 1050; /* above Leaflet panes/controls and the backdrop */
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  #park-list {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }

  /* Detail panel: drop the meta sidebar, give the chart the full width and
     let it scroll horizontally — 7 days of tick labels can't fit on a phone */
  #detail { padding: 20px 10px 8px; gap: 0; }
  #detail-info { min-width: 0; padding-right: 24px; }
  #detail-info h2 { font-size: 13px; margin-bottom: 2px; }
  #detail-meta .detail-extra { display: none; }
  #detail { flex-direction: column; }
  #chart-inner { min-width: 560px; height: 100%; }

  #detail.collapsed {
    height: 24px;
    overflow: hidden;
  }
  #main.detail-open.detail-collapsed {
    height: calc(100vh - var(--header-h) - 24px);
    height: calc(100dvh - var(--header-h) - 24px);
  }
}

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  z-index: 1100; /* above Leaflet controls (1000), below info modal (1200) */
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}
#loading.fade-out {
  opacity: 0;
  pointer-events: none;
}
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden { display: none !important; }
