/* ── Theme variables ──────────────────────────────────────────────────────── */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1a1a2e;
  --muted: #666677;
  --border: #d0d3da;
  --hairline: #f0f0f0;
  --accent: #c0392b;
  --accent-hover: #a93226;
  --control: #e8eaed;
  --badge-bg: #d5f5e3;
  --badge-text: #1a7a42;
  --divider: #ccc;
  --active-bg: #fff9e6;
  --overlay: rgba(255,255,255,0.88);
}
body.dark {
  --bg: #15171e;
  --panel: #1e2129;
  --text: #e6e7ee;
  --muted: #9fa1b3;
  --border: #3a3e4a;
  --hairline: #2c303a;
  --accent: #e05545;
  --accent-hover: #c0392b;
  --control: #2a2e38;
  --badge-bg: #1d3a2a;
  --badge-text: #7fd8a0;
  --divider: #4a4e5a;
  --active-bg: #363019;
  --overlay: rgba(21,23,30,0.88);
}

/* ── Reset & base ─────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', sans-serif; font-size: 13px;
  background: var(--bg); color: var(--text); overflow: hidden;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
#left-sidebar {
  position: absolute; top: 0; left: 0; width: 220px; bottom: 185px;
  background: var(--panel); padding: 14px 16px; overflow-y: auto;
  border-right: 1px solid var(--border); z-index: 999;
  transition: width 0.25s ease, padding 0.25s ease;
}
#left-toggle {
  position: absolute; top: 50%; left: 220px; transform: translateY(-50%);
  width: 16px; height: 52px; background: var(--accent); color: #fff;
  border: none; border-radius: 0 4px 4px 0; cursor: pointer; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; transition: left 0.25s ease;
}
#left-toggle:hover { background: var(--accent-hover); }
body.left-hidden #left-sidebar  { width: 0; padding: 0; overflow: hidden; }
body.left-hidden #left-toggle   { left: 0; }

#map {
  position: absolute; top: 0; left: 220px; right: 340px; bottom: 185px;
  transition: left 0.25s ease, right 0.25s ease;
}
body.left-hidden   #map { left: 0; }
body.sidebar-hidden #map { right: 0; }

#sidebar {
  position: absolute; top: 0; right: 0; width: 340px; bottom: 185px;
  background: var(--panel); padding: 14px 16px; overflow-y: auto;
  border-left: 1px solid var(--border);
  transition: width 0.25s ease, padding 0.25s ease;
}
body.sidebar-hidden #sidebar { width: 0; padding: 0; overflow: hidden; }

#sidebar-toggle {
  position: absolute; top: 50%; right: 340px; transform: translateY(-50%);
  width: 16px; height: 52px; background: var(--accent); color: #fff;
  border: none; border-radius: 4px 0 0 4px; cursor: pointer; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; transition: right 0.25s ease;
}
#sidebar-toggle:hover { background: var(--accent-hover); }
body.sidebar-hidden #sidebar-toggle { right: 0; }

#controls {
  position: absolute; bottom: 0; left: 0; right: 0; height: 185px;
  background: var(--panel); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 6px; padding: 8px 20px;
}

/* ── Left sidebar: parameter controls ────────────────────────────────────── */
.param-group { margin-bottom: 14px; }
.param-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 6px; }
.param-options { display: flex; flex-direction: column; gap: 5px; }
.param-options label { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13px; color: var(--text); }
.param-options input[type=radio] { accent-color: var(--accent); cursor: pointer; }
/* The sliders that replaced the max-day and resupply radio groups.  The rule
   below used to be scoped to #customSolve, where the pace sliders live. */
.param-group input[type="range"] { width: 100%; margin: 2px 0 0; accent-color: var(--accent); }
/* A parameter that cannot apply -- resupply under Supported -- is dimmed in
   place rather than removed, so the sidebar does not jump as styles change. */
.param-group.disabled { opacity: .45; }
.param-group.disabled input { cursor: not-allowed; }
.param-note { font-size: 10.5px; line-height: 1.45; color: var(--muted); margin-top: 6px; }
.param-note.warn { color: var(--accent); }
#presetInfo { margin-top: 16px; font-size: 11px; color: var(--muted); line-height: 2.0; }
#presetInfo .info-row { display: flex; justify-content: space-between; border-bottom: 1px solid var(--hairline); padding: 2px 0; }
#presetError { margin-top: 8px; font-size: 11px; color: var(--accent); display: none; }

/* ── Left sidebar: resupply plan ─────────────────────────────────────────── */
#resupplyPlan { margin-top: 14px; display: none; }
#resupplyPlan .rs-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent); margin-bottom: 6px;
}
.rs-stop {
  display: flex; gap: 6px; align-items: baseline;
  font-size: 11px; line-height: 1.5; padding: 3px 4px;
  border-radius: 3px; border-left: 3px solid transparent; cursor: pointer;
}
.rs-stop:hover  { background: var(--bg); }
.rs-stop.active { background: var(--active-bg); border-left: 3px solid #FFD700; }
.rs-stop .rs-day  { color: var(--accent); font-weight: 700; white-space: nowrap; }
.rs-stop .rs-name { flex: 1; color: var(--text); }
.rs-park {
  color: var(--badge-text); background: var(--badge-bg); border-radius: 8px;
  font-size: 9px; padding: 0 6px; white-space: nowrap; vertical-align: middle;
}
#resupplyPlan .rs-note { margin-top: 6px; font-size: 10px; color: var(--muted); line-height: 1.5; }

/* ── Right sidebar: day stats ─────────────────────────────────────────────── */
.day-header  { font-size: 17px; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.day-route   { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.sec-title   { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin: 12px 0 6px; }
.stat-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; margin-bottom: 4px; }
.stat-lbl    { color: var(--muted); font-size: 11px; }
.stat-val    { color: var(--text); font-size: 13px; font-weight: 600; }
.prog-bg     { background: var(--control); border-radius: 4px; height: 13px; margin-bottom: 3px; }
.prog-fill   { height: 13px; border-radius: 4px; background: linear-gradient(90deg, #27ae60, #1a7a42); transition: width .35s; }
.prog-lbl    { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.badge       { background: var(--badge-bg); color: var(--badge-text); padding: 4px 10px; border-radius: 12px; font-size: 12px; text-align: center; margin-top: 8px; display: none; }
.legend      { line-height: 2.0; font-size: 12px; }
.leg-line    { display: inline-block; width: 18px; height: 3px; border-radius: 1px; vertical-align: middle; margin-right: 5px; }
.itin-step:hover { background: var(--bg); }

/* ── Bottom controls ──────────────────────────────────────────────────────── */
.slider-row  { display: flex; align-items: center; gap: 7px; width: 100%; max-width: 960px; }
.slider-wrap { position: relative; flex: 1; display: flex; align-items: center; }
#daySlider   { width: 100%; accent-color: var(--accent); cursor: pointer; }

/* Resupply-day tick marks under the day slider track.  Horizontal position
   accounts for the ~14px thumb: the track's usable span is (100% - 14px)
   offset 7px, mirroring how the thumb center travels. */
#dayTicks    { position: absolute; left: 0; right: 0; top: 50%; height: 0; }
.day-tick {
  position: absolute; top: 6px; width: 7px; height: 7px;
  background: var(--accent); border: 1px solid var(--panel); border-radius: 1px;
  transform: translateX(-50%) rotate(45deg); cursor: pointer;
}
.day-tick:hover   { background: #FFD700; }
.day-tick.in-park { background: #1a7a42; }
.btn {
  background: var(--control); border: 1px solid var(--accent); color: var(--text);
  padding: 4px 11px; border-radius: 4px; cursor: pointer; font-size: 12px; white-space: nowrap;
}
.btn:hover   { background: var(--accent); color: #fff; }
.day-lbl     { color: var(--accent); font-weight: 700; font-size: 13px; min-width: 90px; text-align: center; }
.toggle-row  { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.toggle-row label { display: flex; align-items: center; gap: 4px; cursor: pointer; font-size: 11px; color: var(--muted); }
.toggle-row input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }
.opacity-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
#mapwarpOpacity, #hillshadeOpacity, #basemapOpacity {
  width: 110px; accent-color: var(--accent); cursor: pointer;
}
#basemapSel  { background: var(--panel); color: var(--text); }

/* ── Map icon tweaks ──────────────────────────────────────────────────────── */
.nps-icon            { filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 6px #fff); }
.grayscale-layer     { filter: grayscale(100%); }
body.zoom-small-icons .nps-icon { transform: scale(0.6); }

/* ── Dark-mode styling for Leaflet chrome ─────────────────────────────────── */
body.dark .leaflet-container { background: #15171e; }
body.dark .leaflet-popup-content-wrapper,
body.dark .leaflet-popup-tip { background: #1e2129; color: #e6e7ee; }
body.dark .leaflet-control-attribution { background: rgba(30,33,41,0.75); color: #9fa1b3; }
body.dark .leaflet-control-attribution a { color: #8ab4f8; }
body.dark .leaflet-bar a { background: #1e2129; color: #e6e7ee; border-bottom-color: #3a3e4a; }

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--overlay); z-index: 9999;
  align-items: center; justify-content: center; flex-direction: column; gap: 12px;
}
#loading.visible { display: flex; }
.spinner {
  width: 36px; height: 36px; border: 4px solid var(--control);
  border-top: 4px solid var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
#loading p { font-size: 13px; color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hiking pace controls (Custom Solve) ──────────────────────────────────
   A pace is not a display preference: changing it changes which traversal
   directions are cheap, so the circuit is re-solved around it.  The controls
   say "Build itinerary", never "apply", and every value snaps to a grid so a
   pace is reproducible and shareable rather than a point in a continuum. */
.pace-tiers {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 6px 0 10px;
}
.pace-tiers button {
  font: inherit; font-size: 11px; padding: 4px 6px; cursor: pointer;
  background: var(--control); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
}
.pace-tiers button:hover { border-color: var(--accent); }
.pace-tiers button.on {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.pace-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; color: var(--muted); margin-top: 8px;
}
.pace-row output { color: var(--text); font-variant-numeric: tabular-nums; }
#customSolve input[type="range"] { width: 100%; margin: 2px 0 0; accent-color: var(--accent); }
/* Day N was driven to, not walked to, so its row breaks from the one above. */
.day-shuttle { color: var(--muted); font-size: 10.5px; font-style: italic; padding: 2px 0 2px 6px; }
.pace-note {
  font-size: 10.5px; line-height: 1.45; color: var(--muted);
  margin: 10px 0 8px; min-height: 2.6em;
}
.pace-note.dirty { color: var(--accent); }

/* Start / finish pickers.  A native <datalist> gives substring type-ahead over
   107 trailheads without shipping a combobox library, and degrades to a plain
   text field where it is unsupported. */
.endpoint-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
}
.endpoint-row label {
  flex: 0 0 42px;
  font-size: 11px;
  color: var(--muted);
}
.endpoint-row input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11px;
  padding: 3px 5px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.endpoint-row input.bad {
  border-color: #c2410c;
}
