:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e5e7eb;
  --panel-bg: #f9fafb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --fg: #f3f4f6;
    --muted: #9ca3af;
    --accent: #60a5fa;
    --border: #374151;
    --panel-bg: #1f2937;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

body {
  display: flex;
  flex-direction: column;
}

#panel {
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  /* Cap the panel itself so the map below always keeps most of the screen on a phone,
     even when the reachable-stops list is long -- the panel scrolls internally instead. */
  max-height: 45vh;
  overflow-y: auto;
  flex-shrink: 0;
}

#search-panel[hidden],
#route-panel[hidden] {
  display: none;
}

#search-panel {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  /* flex-end, not center: labeled inputs (label text + field) are taller than a bare button,
     so centering left buttons floating above the fields' baseline -- this lines button bottoms
     up with input bottoms instead. */
  align-items: flex-end;
  gap: 10px;
}

#route-panel {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--muted);
  gap: 2px;
}

input,
select {
  font-size: 0.95rem;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

/* The min/max minutes step arrows were nearly invisible against the input background and
   weren't adding much -- typing a value directly is the primary interaction, so drop them. */
input[type="number"] {
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

button {
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  width: 34px;
  height: 34px;
}

/* Neutral/outline by default (unlocked -- nothing to draw attention to), filled with the
   accent color when active (locked -- deliberately engaged, worth noticing at a glance). */
#origin-lock-btn {
  background: var(--panel-bg);
  color: var(--muted);
  border-color: var(--border);
}
#origin-lock-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

#sync-btn.spinning svg {
  animation: sync-spin 1s linear infinite;
}

@keyframes sync-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  flex-basis: 100%;
}

#map {
  flex: 1;
  min-height: 0;
}

#stops-panel {
  flex-basis: 100%;
}

#stops-panel summary {
  font-size: 0.9rem;
  margin: 4px 0;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}

#stops-panel summary:hover {
  color: var(--fg);
}

#stops-list {
  margin: 0;
  padding-left: 20px;
  font-size: 0.85rem;
}

#stops-list li {
  margin-bottom: 2px;
  cursor: pointer;
}

#stops-list li:hover {
  text-decoration: underline;
}

#stops-list .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

/* --- stop marker popup (mainly for touchscreens -- see app.js's supportsHover) --- */

.stop-popup {
  font-size: 0.85rem;
  line-height: 1.4;
}

.popup-directions-btn {
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

/* --- origin search / autocomplete --- */

#origin-search-wrap {
  position: relative;
}

#origin-search-results {
  /* position: fixed (set from JS via the input's getBoundingClientRect) so the dropdown
     escapes #panel's overflow-y:auto clipping instead of being scroll-clipped inside it. */
  position: fixed;
  z-index: 3000;
  margin: 2px 0 0;
  padding: 4px 0;
  list-style: none;
  min-width: 220px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#origin-search-results li {
  padding: 6px 10px;
  font-size: 0.9rem;
  cursor: pointer;
}

#origin-search-results li:hover {
  background: var(--panel-bg);
}

/* --- near/far legend --- */

#legend[hidden] {
  display: none;
}

#legend {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-basis: 100%;
  font-size: 0.75rem;
  color: var(--muted);
}

#legend-bar {
  flex: 1;
  max-width: 220px;
  height: 8px;
  border-radius: 4px;
  /* Blue -> violet -> red, deliberately *avoiding* the green hue range: for red-green color
     blindness (the most common form), green and red read as similar muddy tones, which would
     wreck a blue->green->red ramp right at the "far" end where the distinction matters most. */
  background: linear-gradient(to right, hsl(240, 80%, 55%), hsl(300, 80%, 55%), hsl(0, 80%, 55%));
}

/* --- route detail panel (replaces the old modal: map + legs are both visible at once) --- */

#route-back {
  align-self: flex-start;
  padding: 4px 10px;
  font-size: 0.85rem;
}

#route-title {
  margin: 4px 0 0;
  font-size: 1.05rem;
}

#route-summary {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

#route-legs {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* small labeled dot at board/alight points along the route line on the map */
.transfer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid #111827;
}

.leg {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.leg:first-child {
  border-top: none;
}

.leg-badge {
  flex-shrink: 0;
  min-width: 52px;
  text-align: center;
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  height: fit-content;
}

.leg-badge.mode-walk { background: var(--muted); }
.leg-badge.mode-bus { background: #16a34a; }
.leg-badge.mode-tram { background: #ea580c; }
.leg-badge.mode-subway,
.leg-badge.mode-rail { background: #7c3aed; }

.leg-detail .leg-time {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--fg);
}

.leg-detail .leg-route {
  font-weight: 600;
}

.leg-detail .leg-meta {
  color: var(--muted);
  font-size: 0.8rem;
}
