:root {
  --brand: #1d5a37;
  --brand-ink: #ffffff;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1b1f1c;
  --muted: #5d655f;
  --border: #dde2dd;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.14);

  /* Status colors (always shown with an icon + label, never color alone) */
  --open: #0ca30c;
  --filling: #fab219;
  --full: #d03b3b;
  --unknown: #8a918c;
  --on-open: #ffffff;
  --on-filling: #1b1f1c;
  --on-full: #ffffff;
  --on-unknown: #ffffff;

  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141715;
    --surface: #1e2320;
    --text: #eef1ee;
    --muted: #a3aca5;
    --border: #333a35;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    --unknown: #7c847e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar & tabs ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand img { border-radius: 7px; box-shadow: 0 0 0 1.5px rgba(255,255,255,.5); }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
.permit select {
  appearance: none; border: 1.5px solid rgba(255,255,255,.55); background: rgba(255,255,255,.12);
  color: #fff; border-radius: 999px; padding: 6px 30px 6px 12px; font-size: 15px;
  background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
  background-position: right 14px center, right 9px center; background-size: 5px 5px; background-repeat: no-repeat;
}
.permit select option { color: #111; }

.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs button {
  flex: 1; border: 0; background: none; padding: 11px 0; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }
@media (prefers-color-scheme: dark) { .tabs button[aria-selected="true"] { border-bottom-color: #5fbf85; } }

.offline { background: #fff3cd; color: #5c4400; font-size: 14px; padding: 8px 16px; text-align: center; }

main { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; }

/* ---------- Map ---------- */
#map { position: absolute; inset: 0; background: #e8ebe7; }
.map-locate {
  position: absolute; right: 12px; top: 12px; z-index: 500;
  width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: var(--surface); color: var(--brand); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.map-locate.on { color: #1a73e8; }
@media (prefers-color-scheme: dark) { .map-locate { color: #7fd3a0; } }

.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500; margin: 0; padding: 7px 10px;
  list-style: none; display: flex; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); font-size: 13px;
}
.legend li { display: flex; align-items: center; gap: 4px; }

.dot {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  font-size: 11px; font-weight: 800; line-height: 1;
}
.dot-open { background: var(--open); color: var(--on-open); }
.dot-filling { background: var(--filling); color: var(--on-filling); }
.dot-full { background: var(--full); color: var(--on-full); }
.dot-unknown { background: var(--unknown); color: var(--on-unknown); }

.pin {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 18px; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
  transition: transform .15s;
}
.pin-open { background: var(--open); color: var(--on-open); }
.pin-filling { background: var(--filling); color: var(--on-filling); }
.pin-full { background: var(--full); color: var(--on-full); }
.pin-unknown { background: var(--unknown); color: var(--on-unknown); }
.pin-dim { opacity: .45; transform: scale(.8); }
#map .pin-unknown { transform: scale(.75); }
#map .pin-unknown.pin-dim { transform: scale(.65); }
.pin-selected, #map .pin-selected { transform: scale(1.2); }

/* The tap area is the pin itself, not the invisible square around it */
.leaflet-marker-icon.pin-wrap { display: grid; place-items: center; pointer-events: none; }
.pin-wrap .pin { pointer-events: auto; }
#map.zoom-mid .pin { width: 26px; height: 26px; font-size: 13px; border-width: 2px; }
#map.zoom-far .pin { width: 16px; height: 16px; font-size: 0; border-width: 2px; }
.leaflet-tooltip.pin-label {
  background: rgba(255,255,255,.92); border: 0; box-shadow: 0 1px 4px rgba(0,0,0,.25);
  padding: 1px 6px; font-size: 12px; font-weight: 600; color: #1b1f1c; border-radius: 6px;
}
.leaflet-tooltip.pin-label::before { display: none; }
#map.hide-labels .pin-label { display: none; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }

/* ---------- List ---------- */
#list-view { overflow-y: auto; padding: 12px 16px 24px; }
.loc-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.chip {
  flex: none; border: 1.5px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 7px 12px; font-size: 14px; font-weight: 600;
}
.lot-list, .picker-list { grid-template-columns: minmax(0, 1fr); } /* long names get "…" instead of widening the page */
.lot-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list-heading { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 0; }
.lot-card {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; min-height: 64px;
}
.lot-card .pin { width: 34px; height: 34px; font-size: 16px; flex: none; border-width: 0; box-shadow: none; }
.lot-card-main { flex: 1; min-width: 0; }
.lot-card-name { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lot-card-meta { display: block; font-size: 14px; color: var(--muted); }
.lot-card-dist { font-weight: 700; font-size: 15px; white-space: nowrap; }
.lot-card.dim { opacity: .6; }

/* ---------- Big action button ---------- */
.action {
  display: flex; gap: 10px; padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.big-btn {
  flex: 1; min-height: 72px; border: 0; border-radius: 18px; padding: 8px 16px;
  background: var(--brand); color: #fff; display: flex; flex-direction: column; justify-content: center;
  box-shadow: 0 3px 0 #123b24; transition: transform .06s, box-shadow .06s;
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #123b24; }
.big-btn.leaving { background: #b3541e; box-shadow: 0 3px 0 #7a3712; }
.big-btn:disabled { opacity: .7; }
.big-main { font-size: 24px; font-weight: 800; line-height: 1.1; }
.big-sub { font-size: 14px; opacity: .92; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.change-lot {
  flex: none; width: 72px; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 18px; font-size: 13px; font-weight: 650; line-height: 1.2; color: var(--muted);
}

/* ---------- Bottom sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
  max-height: 88dvh; overflow-y: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(20px + var(--safe-bottom));
  animation: up .18s ease-out;
}
@media (min-width: 640px) { .sheet { left: 50%; right: auto; width: 560px; transform: translateX(-50%); animation: none; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet h2 { font-size: 21px; margin: 2px 0 6px; line-height: 1.2; }
.close-btn { border: 0; background: var(--bg); width: 36px; height: 36px; border-radius: 50%; font-size: 20px; flex: none; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 6px;
  border-radius: 999px; font-weight: 700; font-size: 15px;
}
.status-pill .dot { width: 22px; height: 22px; font-size: 13px; background: rgba(255,255,255,.25); color: inherit; }
.status-open { background: var(--open); color: var(--on-open); }
.status-filling { background: var(--filling); color: var(--on-filling); }
.status-full { background: var(--full); color: var(--on-full); }
.status-unknown { background: var(--unknown); color: var(--on-unknown); }
.facts { margin: 12px 0; padding: 0; list-style: none; display: grid; gap: 4px; color: var(--muted); font-size: 15px; }
.facts strong { color: var(--text); font-weight: 600; }
.sheet h3 { font-size: 15px; margin: 18px 0 8px; }
.report-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.report-btn {
  border: 2px solid var(--border); background: var(--surface); border-radius: 12px;
  padding: 12px 4px; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.report-btn .dot { width: 26px; height: 26px; font-size: 15px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.secondary-btn {
  display: block; text-align: center; text-decoration: none; border: 0; border-radius: 12px; padding: 12px;
  font-weight: 700; background: var(--bg); color: var(--text);
}
.secondary-btn.primary { background: var(--brand); color: #fff; }
.picker-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.report-hint { margin: -4px 0 8px; }
.intro p { margin: 8px 0; }
.intro ol { padding-left: 20px; margin: 8px 0; }
.intro li { margin: 6px 0; }

/* ---------- Busiest-times chart ---------- */
.seg { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 3px; margin-bottom: 8px; }
.seg button { border: 0; background: none; padding: 5px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.chart-summary { font-weight: 650; margin: 0 0 4px; }
.chart-readout { font-size: 13px; color: var(--muted); min-height: 1.4em; margin: 0 0 2px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .axis-text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .threshold { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; }
.chart .bar-empty { fill: var(--border); }
.chart .bar-thin { opacity: .45; }
.chart .hit { fill: transparent; }
.chart .hit.active + .bar, .chart .bar.active { stroke: var(--text); stroke-width: 1.5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(100px + var(--safe-bottom)); z-index: 1100;
  margin: 0 auto; max-width: 480px; display: flex; align-items: center; gap: 12px;
  background: #1b1f1c; color: #fff; padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow);
  font-size: 15px;
}
.toast.error { background: #8c1f1f; }
.toast button { border: 0; background: none; color: #9be3b4; font-weight: 800; padding: 4px 6px; }

/* ---------- Where a status came from ---------- */
/* Each status color, as a variable the outlined/faded styles can reuse */
.pin-open, .dot-open, .status-open { --c: var(--open); --c-ink: var(--open); }
.pin-filling, .dot-filling, .status-filling { --c: var(--filling); --c-ink: var(--filling-ink); }
.pin-full, .dot-full, .status-full { --c: var(--full); --c-ink: var(--full); }
:root { --filling-ink: #8f6200; }
@media (prefers-color-scheme: dark) { :root { --filling-ink: var(--filling); } }

/* Older report (30 min–2 hr): same color, faded */
.pin.basis-recent, .dot.basis-recent, .status-pill.basis-recent { opacity: .55; }
/* No recent reports, guessed from past weeks: outlined instead of filled */
.pin.basis-typical, .dot.basis-typical, .status-pill.basis-typical {
  background: var(--surface); color: var(--c-ink); border: 3px solid var(--c);
}
.dot.basis-typical { border-width: 2px; }
.status-pill.basis-typical { border-width: 2px; padding: 3px 10px 3px 4px; }
.status-pill.basis-typical .dot { background: transparent; }
.basis-note { margin: 10px 0 0; font-size: 14px; color: var(--muted); }

.legend { max-width: calc(100% - 24px); }
.legend .legend-note { flex-basis: 100%; gap: 4px; color: var(--muted); font-size: 12px; }
.legend .legend-note .dot { width: 14px; height: 14px; font-size: 8px; margin-left: 4px; }
.legend .legend-note .dot:first-child { margin-left: 0; }

/* ---------- Show all / main lots ---------- */
.map-chip {
  position: absolute; left: 12px; top: 12px; z-index: 500;
  border: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600;
}
.map-chip u, .show-all-link u { text-decoration: none; color: var(--brand); }
@media (prefers-color-scheme: dark) { .map-chip u, .show-all-link u { color: #7fd3a0; } }
.show-all-link {
  width: 100%; border: 1.5px dashed var(--border); background: none; border-radius: var(--radius);
  padding: 12px; font-size: 14px; font-weight: 600; color: var(--muted);
}

/* ---------- "How full was it?" after parking ---------- */
.toast { flex-direction: column; align-items: stretch; gap: 10px; }
.toast-row { display: flex; align-items: center; gap: 12px; }
.toast-row span { flex: 1; }
.toast-ask { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.toast-ask > span { grid-column: 1 / -1; font-weight: 700; }
.toast-ask button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(255,255,255,.1); border-radius: 10px; padding: 10px 4px; color: #fff; font-size: 14px;
}
.toast-ask .dot { width: 24px; height: 24px; font-size: 14px; }

/* ---------- "Add to Home Screen" tip ---------- */
.install-tip {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); font-size: 14px; line-height: 1.3;
}
.install-tip img { border-radius: 8px; flex: none; }
.install-text { flex: 1; min-width: 0; }
.install-text svg { vertical-align: -3px; color: #1a73e8; }
.install-btn { flex: none; border: 0; border-radius: 999px; padding: 7px 14px; background: var(--brand); color: #fff; font-weight: 700; font-size: 14px; }
.install-close { flex: none; border: 0; background: none; width: 32px; height: 32px; font-size: 20px; color: var(--muted); }

/* ---------- About button, terms, and the one-time agree card ---------- */
.topbar-right { display: flex; align-items: center; gap: 6px; }
.about-btn {
  flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.12); color: #fff; display: grid; place-items: center;
}
.terms-line a, .sheet p a { color: var(--brand); font-weight: 600; }
@media (prefers-color-scheme: dark) { .terms-line a, .sheet p a { color: #7fd3a0; } }
.agree-points { list-style: none; margin: 8px 0 12px; padding: 0; display: grid; gap: 10px; }
.agree-points li { display: flex; gap: 10px; line-height: 1.4; }
.agree-icon { flex: none; color: var(--brand); padding-top: 1px; }
@media (prefers-color-scheme: dark) { .agree-icon { color: #7fd3a0; } }
.agree-btn { width: 100%; margin-top: 12px; padding: 14px; font-size: 16px; }
.link-btn { display: block; width: 100%; border: 0; background: none; padding: 12px; color: var(--muted); font-size: 15px; }
.about-id { word-break: break-all; margin-top: 4px; }
.about-id code { font-size: 12px; }

/* ---------- "A spot just opened" ---------- */
.pin { position: relative; }
.pin-badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 4px;
  border-radius: 999px; background: #fff; color: #087a08; border: 2px solid #0ca30c;
  font-size: 11px; font-weight: 800; line-height: 1;
}
.pin .pin-badge { position: absolute; top: -9px; right: -11px; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.pin-badge.taken { color: var(--muted); border-color: var(--unknown); }
#map.zoom-far .pin .pin-badge { top: -7px; right: -9px; min-width: 14px; height: 14px; padding: 0; font-size: 0; }
#map .pin-unknown .pin-badge, #map .pin.basis-recent .pin-badge { transform: scale(1.25); }
.lot-card .pin .pin-badge { display: none; } /* the card has its own line for it */
.lot-card-opened { display: block; font-size: 13px; font-weight: 700; color: #087a08; }
.opened-note {
  display: flex; align-items: center; gap: 8px; margin: 10px 0 0; padding: 8px 10px;
  background: rgba(12,163,12,.1); border-radius: 10px; font-weight: 600; font-size: 14px;
}
.legend .legend-note .legend-badge { min-width: 18px; height: 16px; font-size: 9px; border-width: 1.5px; margin-left: 4px; }
@media (prefers-color-scheme: dark) {
  .lot-card-opened { color: #6fdc6f; }
  .pin-badge { background: #1e2320; color: #6fdc6f; }
}

/* ---------- Feedback ---------- */
.feedback-btn { margin-top: 10px; }
.feedback-hint { margin: 6px 2px 0; }

/* ---------- Find my car ---------- */
.car-pin {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: #1b1f1c; color: #fff; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.change-lot.find-car { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text); }
.change-lot.find-car svg { width: 22px; height: 22px; }
.car-where { margin: 2px 0 0; color: var(--muted); font-size: 15px; }
