/* ===========================================================================
   Walk Tracker — dark, mobile-first theme
   The glowing path pops against dark CARTO tiles. Controls float over a
   full-screen map. Touch targets are >=44px and respect safe-area insets.
   =========================================================================== */

:root {
  --bg: #0d1117;
  --panel: rgba(22, 27, 34, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #2dd4bf;          /* teal/cyan — matches the glowing path */
  --accent-strong: #5eead4;
  --danger: #f87171;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  /* safe-area insets (notches / home indicators) */
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px);
  --sa-right: env(safe-area-inset-right, 0px);
}

/* Light theme — applied when <body> has the .light class. Overrides the
   dark defaults above; the glowing-path accent stays teal in both themes. */
body.light {
  --bg: #eef1f5;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-border: rgba(0, 0, 0, 0.1);
  --text: #1f2937;
  --text-dim: #6b7280;
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --danger: #dc2626;
  --shadow: 0 8px 30px rgba(31, 41, 55, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;       /* prevent pull-to-refresh while dragging map */
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--bg);
}

/* Keep Leaflet's default attribution legible on the dark theme */
.leaflet-control-attribution {
  background: rgba(13, 17, 23, 0.7) !important;
  color: var(--text-dim) !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
body.light .leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.82) !important;
}

/* --- Top bar: search + locate ------------------------------------------- */
.top-bar {
  position: absolute;
  top: calc(12px + var(--sa-top));
  left: calc(12px + var(--sa-left));
  right: calc(12px + var(--sa-right));
  z-index: 1000;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.search {
  position: relative;
  flex: 1;
}

#search-input {
  width: 100%;
  height: 48px;
  padding: 0 40px 0 16px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;            /* >=16px avoids iOS auto-zoom on focus */
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  outline: none;
}
#search-input::placeholder { color: var(--text-dim); }
#search-input:focus { border-color: var(--accent); }

.search-clear {
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  height: 48px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.search-results {
  list-style: none;
  margin: 8px 0 0;
  padding: 6px;
  max-height: 50vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.search-results li {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.3;
  cursor: pointer;
}
.search-results li:hover,
.search-results li[aria-selected="true"] { background: rgba(45, 212, 191, 0.12); }
.search-results li.empty { color: var(--text-dim); cursor: default; }

/* --- Buttons ------------------------------------------------------------ */
.icon-btn {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); }
.icon-btn.locating { color: var(--accent); }
.icon-btn.locating svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Theme toggle shows the icon for the mode you'd switch TO:
   dark mode shows the sun, light mode shows the moon. */
#theme-btn .icon-moon { display: none; }
#theme-btn .icon-sun { display: block; }
body.light #theme-btn .icon-sun { display: none; }
body.light #theme-btn .icon-moon { display: block; }

/* --- Bottom panel: distance + controls ---------------------------------- */
.bottom-panel {
  position: absolute;
  left: calc(12px + var(--sa-left));
  right: calc(12px + var(--sa-right));
  bottom: calc(12px + var(--sa-bottom));
  z-index: 1000;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.distance {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.dist-value {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}
.dist-secondary { color: var(--text); opacity: 0.85; font-size: 26px; }
.dist-sep { color: var(--text-dim); font-size: 26px; }

/* When km is the primary unit, swap the emphasis */
.distance.km-primary #dist-km { color: var(--accent-strong); font-size: 34px; opacity: 1; }
.distance.km-primary #dist-miles { color: var(--text); opacity: 0.85; font-size: 26px; }

.controls {
  display: flex;
  gap: 10px;
}
.ctrl-btn {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.ctrl-btn:active:not(:disabled) { transform: scale(0.98); }
.ctrl-btn:disabled { opacity: 0.4; cursor: default; }
.ctrl-danger:not(:disabled) { color: var(--danger); }

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

/* --- Toast -------------------------------------------------------------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(170px + var(--sa-bottom));
  transform: translateX(-50%);
  z-index: 1100;
  max-width: 86vw;
  padding: 12px 18px;
  background: rgba(22, 27, 34, 0.96);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.toast.show { opacity: 1; }

/* --- Glowing path & waypoint markers (Leaflet SVG overlay) -------------- */
/* The path is drawn as two stacked polylines inside mapProvider.js:
   a thick blurred "glow" stroke beneath a bright thin core. The blur is
   applied here so the SVG element gets a soft halo. */
.walk-glow {
  filter: drop-shadow(0 0 6px var(--accent)) drop-shadow(0 0 12px var(--accent));
}

.waypoint-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-strong);
  border: 2px solid #0d1117;
  box-shadow: 0 0 8px var(--accent), 0 0 14px var(--accent);
}
/* The very first waypoint gets a distinct ring so "start" is obvious */
.waypoint-marker.start {
  background: #0d1117;
  border-color: var(--accent-strong);
}

/* On wider screens, cap the panel widths so it doesn't stretch awkwardly */
@media (min-width: 640px) {
  .bottom-panel { left: auto; right: 16px; width: 320px; }
}
