:root {
  --bg: #f7f9fb;
  --panel: #ffffff;
  --accent: #0a7d4b;
  --accent-dark: #075f39;
  --text: #1c2733;
  --muted: #6a7785;
  --border: #e2e8f0;
  --avoid: #d64545;
  --caution: #d98a00;
  --good: #0a7d4b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

body {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
}

#map { flex: 1; }

h1 { font-size: 1.25rem; margin: 0 0 14px; }
h2 { font-size: 1rem; margin: 0 0 10px; }

.mode-toggle { display: flex; gap: 6px; margin-bottom: 12px; }
.mode-toggle button {
  flex: 1;
  padding: 8px;
  border: 1px solid #8f99a6;
  background: #a7b0bc;     /* grey for the unselected option */
  color: var(--text);      /* keep the label clearly readable */
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.mode-toggle button:hover { background: #97a1ae; }
.mode-toggle button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.mode-toggle button.active:hover { background: var(--accent-dark); }

.hint { font-size: 0.85rem; color: var(--muted); margin: 0 0 14px; }

.geo-field { position: relative; margin-bottom: 10px; }
.geo-field label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.geo-field input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--panel);
}
.suggest {
  position: absolute;
  z-index: 1000;
  left: 0;
  right: 0;
  top: 100%;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
}
.suggest li {
  padding: 8px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.suggest li:last-child { border-bottom: none; }
.suggest li:hover, .suggest li.active { background: var(--bg); }
.suggest .s-title { font-weight: 600; }
.suggest .s-sub { color: var(--muted); font-size: 0.75rem; }
.suggest .s-empty { color: var(--muted); cursor: default; }

label { display: block; font-size: 0.85rem; margin-bottom: 12px; }
select, input[type="number"] {
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--panel);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 0 12px;
  padding: 8px 12px;
}
legend { font-size: 0.8rem; color: var(--muted); padding: 0 4px; }
label.cb { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
label.cb input { width: auto; margin: 0; }
label.cb-standalone { font-size: 0.85rem; margin: 0 0 12px; }

.actions { display: flex; gap: 8px; margin-bottom: 14px; }
button {
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: #e2e8f0; color: var(--text); }
button.secondary:hover { background: #cbd5e1; }
button:disabled { opacity: 0.5; cursor: progress; }
.actions button { flex: 1; }

.status {
  font-size: 0.85rem;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 14px;
  background: #fff4e5;
  border: 1px solid #f5d9a8;
}
.status.error { background: #fdeaea; border-color: #f3c0c0; color: var(--avoid); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; margin: 0 0 12px; }
dt { color: var(--muted); font-size: 0.85rem; }
dd { margin: 0; text-align: right; font-weight: 600; font-size: 0.9rem; }

.muted-note { font-weight: 400; color: var(--muted); font-size: 0.78rem; }

#w-now {
  font-size: 0.86rem;
  margin: 0 0 8px;
  color: var(--text);
}
.w-depart {
  font-size: 0.86rem;
  margin: 0 0 10px;
  padding: 7px 10px;
  border-radius: 6px;
  border-left: 4px solid var(--border);
  background: var(--bg);
}
.w-depart.good { border-left-color: var(--good); }
.w-depart.caution { border-left-color: var(--caution); }
.w-depart.avoid { border-left-color: var(--avoid); }

#w-rec { font-size: 0.9rem; margin: 0 0 10px; }
#w-windows { list-style: none; padding: 0; margin: 0; }
#w-windows li {
  font-size: 0.82rem;
  padding: 7px 10px;
  border-radius: 6px;
  margin-bottom: 5px;
  border-left: 4px solid var(--border);
  background: var(--bg);
}
#w-windows li.good { border-left-color: var(--good); }
#w-windows li.caution { border-left-color: var(--caution); }
#w-windows li.avoid { border-left-color: var(--avoid); }
#w-windows .label { font-weight: 600; }
#w-windows .text { color: var(--muted); }

.row { display: flex; gap: 8px; }
.row button { flex: 1; }

.route-legend { display: flex; gap: 14px; font-size: 0.74rem; color: var(--muted); margin: 0 0 12px; }
.route-legend .seg {
  display: inline-block;
  width: 16px;
  height: 4px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
.route-legend .seg.cycle { background: var(--good); }
.route-legend .seg.road { background: var(--avoid); }

.share { display: flex; gap: 6px; margin-top: 10px; }
.share input {
  flex: 1;
  padding: 7px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.share button { padding: 7px 10px; font-size: 0.8rem; }

#saved-list { list-style: none; padding: 0; margin: 0; }
#saved-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
#saved-list li:last-child { border-bottom: none; }
#saved-list .meta { flex: 1; min-width: 0; }
#saved-list .name {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#saved-list .sub { font-size: 0.75rem; color: var(--muted); }
#saved-list button {
  padding: 5px 9px;
  font-size: 0.75rem;
  background: #e2e8f0;
  color: var(--text);
}
#saved-list button:hover { background: #cbd5e1; }
#saved-list button.del { background: #fdeaea; color: var(--avoid); }
#saved-list button.del:hover { background: #f8d4d4; }

.ele-stats { display: flex; gap: 16px; font-size: 0.78rem; color: var(--muted); margin-bottom: 8px; }
.ele-stats b { color: var(--text); font-size: 0.88rem; }
#ele-chart { position: relative; width: 100%; height: 130px; }
#ele-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.ele-tip {
  position: absolute;
  top: -4px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 0.72rem;
  padding: 3px 7px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
}

#t-best { font-weight: 600; font-size: 0.92rem; margin: 0 0 6px; }
.t-note { font-size: 0.84rem; color: var(--muted); margin: 0 0 10px; }
.t-strip {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 50px;
  padding: 2px;
  background: var(--bg);
  border-radius: 6px;
}
.t-strip .bar { flex: 1; min-height: 4px; border-radius: 2px 2px 0 0; background: var(--good); }
.t-strip .bar.low { background: var(--good); }
.t-strip .bar.moderate { background: var(--caution); }
.t-strip .bar.heavy { background: var(--avoid); }
.t-strip .bar.now { outline: 2px solid var(--text); outline-offset: 1px; }
.t-axis { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--muted); margin-top: 3px; }
.t-legend { display: flex; gap: 14px; font-size: 0.72rem; color: var(--muted); margin-top: 8px; }
.t-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.t-legend .dot.low { background: var(--good); }
.t-legend .dot.moderate { background: var(--caution); }
.t-legend .dot.heavy { background: var(--avoid); }

.t-live { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.t-live-head { font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
  margin-left: 4px;
}
.badge.clear { background: var(--good); }
.badge.moderate { background: var(--caution); }
.badge.congested { background: var(--avoid); }
.t-live-list { list-style: none; padding: 0; margin: 6px 0 0; }
.t-live-list li { font-size: 0.8rem; padding: 3px 0; }
.t-live-list li.incident { color: var(--avoid); }

.pk-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-bottom: 10px;
  font-size: 0.8rem;
}
.pk-filters label { margin: 0; font-size: 0.8rem; }
.pk-filters select {
  margin-left: 6px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  font-size: 0.8rem;
}
.pk-empty { font-size: 0.84rem; color: var(--muted); margin: 4px 0 0; }

.parking-list { list-style: none; padding: 0; margin: 0; }
/* With more than 5 spots, cap the height to ~5 rows and scroll the rest. */
.parking-list.scroll {
  max-height: 22rem;
  overflow-y: auto;
  overscroll-behavior: contain; /* don't chain-scroll the sidebar/page */
  padding-right: 4px;           /* breathing room beside the scrollbar */
}
.parking-list li {
  display: flex;
  gap: 10px;
  padding: 9px 6px;
  margin: 0 -6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 6px;
}
.parking-list li:hover { background: var(--bg); }
.parking-list .thumb { cursor: zoom-in; }
.parking-list .pk-locate { font-size: 0.72rem; color: var(--accent); margin-top: 3px; }
.parking-list .pk-name { display: flex; align-items: center; gap: 6px; }
.pk-source {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  border-radius: 8px;
  color: #fff;
  flex: none;
}
.pk-source.lta { background: var(--accent); }
.pk-source.osm { background: #6a7785; }
.pk-source.mapillary { background: var(--caution); } /* amber: lower-confidence CV */

.pk-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--muted);
  padding: 6px 0 2px;
}
.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 24px;
}
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; text-align: center; }
.lightbox img {
  max-width: 90vw;
  max-height: 82vh;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.lightbox figcaption { color: #fff; font-size: 0.85rem; margin-top: 10px; }
.parking-list li:last-child { border-bottom: none; }
.parking-list .thumb {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
}
.parking-list .pk-meta { min-width: 0; }
.parking-list .pk-name { font-weight: 600; font-size: 0.85rem; }
.parking-list .pk-sub { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.parking-list .pk-shelter { color: var(--good); font-weight: 600; }

.hidden { display: none !important; }

/* --- Responsive: phones & small tablets ---------------------------------- */
/* Desktop is a fixed sidebar beside a filling map. On narrow screens that
   cramps both, so stack them: a tappable map on top, controls scrolling below
   with the normal page (no inner sidebar scroll). */
@media (max-width: 640px) {
  body {
    flex-direction: column;
    height: auto;        /* let the page grow and scroll naturally */
    min-height: 100vh;
  }

  #map {
    order: -1;           /* map sits above the controls */
    flex: none;
    width: 100%;
    height: 45vh;
    min-height: 260px;
  }

  #sidebar {
    width: 100%;
    min-width: 0;        /* drop the 340px floor so it never overflows */
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-y: visible; /* scroll the page, not a nested box */
    padding: 16px;
  }

  h1 { font-size: 1.15rem; }

  /* Roomier tap targets. */
  .mode-toggle button { padding: 11px; }
  .actions button, .row button { padding: 12px 14px; }
  .geo-field input,
  select,
  input[type="number"],
  input[type="datetime-local"] { font-size: 16px; } /* iOS won't zoom at >=16px */

  /* Let the parking list grow with the page instead of scrolling inside a
     box (nested touch-scroll is awkward on mobile). */
  .parking-list.scroll {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}

/* Very small phones: trim padding a little more. */
@media (max-width: 380px) {
  #sidebar { padding: 12px; }
  .card { padding: 12px; }
}
