/* Where to Park@SG — mobile-first layout */

:root {
  --color-primary: #0b5cad;
  --color-on-primary: #ffffff;
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-text: #1b1f24;
  --color-muted: #5f6b7a;
  --color-border: #dde3ea;

  --color-ok: #1e8e3e;
  --color-low: #d97706;
  --color-full: #c5221f;
  --color-unknown: #80868b;
  --color-user: #1a73e8;
  --color-link: #0b5cad;

  --header-height: 52px;
  --tab-bar-height: 60px;
  --ad-unit-height: 50px; /* 320 x 50 mobile banner */
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #121418;
    --color-surface: #1c1f25;
    --color-text: #e8eaed;
    --color-muted: #9aa0a6;
    --color-border: #2e333b;
    --color-link: #8ab4f8; /* the primary blue is too dark to read on the dark background */
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  /* Named areas: a hidden ad slot leaves its row empty (0px) instead of shifting main into it */
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: 'header' 'ad' 'main' 'tabs';
  height: 100dvh;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  overscroll-behavior: none; /* no rubber-band / pull-to-refresh gap at scroll limits */
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

/* Header */

.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--header-height);
  padding: env(safe-area-inset-top) 16px 0;
  color: var(--color-on-primary);
  background: var(--color-primary);
}

.app-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  white-space: nowrap;
}

.app-title span {
  opacity: 0.75;
}

/* Vehicle toggle: one segmented control for both views */

.vehicle-toggle {
  display: flex;
  flex-shrink: 0;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.16);
}

.vehicle-toggle__button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--color-on-primary);
  opacity: 0.8;
  cursor: pointer;
}

.vehicle-toggle__button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.vehicle-toggle__button[aria-pressed="true"] {
  background: var(--color-on-primary);
  color: var(--color-primary);
  opacity: 1;
}

.vehicle-toggle__button:focus-visible {
  outline: 2px solid var(--color-on-primary);
  outline-offset: 2px;
}

/* Ad slot: fixed height, so the map and list don't jump when an ad loads */

.ad-slot {
  grid-area: ad;
  display: grid;
  place-items: center;
  height: calc(var(--ad-unit-height) + 9px); /* 4px padding top and bottom + 1px border */
  padding: 4px 16px;
  overflow: hidden;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.ad-slot__unit {
  width: 320px;
  height: var(--ad-unit-height);
}

.ad-slot__placeholder {
  display: grid;
  place-items: center;
  width: 320px;
  max-width: 100%;
  height: var(--ad-unit-height);
  border: 2px dashed var(--color-low);
  border-radius: 4px;
  color: var(--color-muted);
  font-size: 0.8125rem;
}

/* Panels */

.app-main {
  grid-area: main;
  position: relative;
  min-height: 0; /* let the grid row shrink so panels can scroll */
}

.panel {
  position: absolute;
  inset: 0;
}

.panel--list {
  overflow-y: auto;
  padding: 12px 16px;
}

.map {
  width: 100%;
  height: 100%;
}

/* Tab bar */

.tab-bar {
  grid-area: tabs;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--color-muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.tab svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.tab[aria-selected="true"] {
  color: var(--color-primary);
  font-weight: 600;
}

.tab:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -4px;
}

/* List cards */

.cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* long names ellipsize instead of widening the list */
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.card__body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.card__name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card__lots {
  display: grid;
  justify-items: end;
  color: var(--color-muted);
  font-size: 0.875rem;
}

.card__lots strong {
  color: var(--color-text);
  font-size: 1.25rem;
}

.card__lots small {
  white-space: nowrap; /* "of 359 lots" stays on one line next to a long carpark name */
}

.list-heading {
  max-width: 720px;
  margin: 0 auto 8px;
  color: var(--color-muted);
  font-size: 0.8125rem;
}

.list-heading__updated {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
}

.card__distance {
  color: var(--color-text);
  font-weight: 600;
}

.card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-muted);
  font-size: 0.8125rem;
}

/* Marker after the last card: when it nears the visible area, listView.js adds more cards */
.cards-end {
  height: 1px;
}

/* Up to ~2,300 cards: let the browser skip layout/paint for the ones off-screen */
.cards > li {
  content-visibility: auto;
  contain-intrinsic-size: auto 72px;
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.75rem;
}

.badge--ok { background: var(--color-ok); }
.badge--low { background: var(--color-low); }
.badge--full { background: var(--color-full); }
.badge--unknown { background: var(--color-unknown); }

.empty {
  padding: 48px 16px;
  color: var(--color-muted);
  text-align: center;
}

.empty__title {
  color: var(--color-text);
  font-size: 1.125rem;
  font-weight: 600;
}

/* Map markers */

.marker {
  display: grid;
  place-items: center;
  width: 36px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 12px;
  color: #fff;
  font: 700 0.75rem var(--font);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.35);
}

.marker--ok { background: var(--color-ok); }
.marker--low { background: var(--color-low); }
.marker--full { background: var(--color-full); }
.marker--unknown { background: var(--color-unknown); }

/* Carpark popup. Leaflet popups are always white, so use fixed light-theme colours. */

.popup {
  min-width: 200px;
  font-family: var(--font);
}

.popup p {
  margin: 0;
}

.popup__name {
  padding-right: 8px; /* clear the close button */
  color: #1b1f24;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.3;
}

.popup .popup__id {
  margin-top: 2px;
  color: #5f6b7a;
  font-size: 0.8125rem;
}

.popup__lots {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #dde3ea;
}

.popup__count {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.popup__count--ok { color: var(--color-ok); }
.popup__count--low { color: var(--color-low); }
.popup__count--full { color: var(--color-full); }
.popup__count--unknown { color: var(--color-unknown); }

.popup__total {
  color: #5f6b7a;
  font-size: 0.875rem;
}

.popup__lots .badge {
  align-self: center;
  margin-left: auto;
}

/* Locate-me map control (matches Leaflet's zoom buttons) */

.locate-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: #fff;
  color: #333;
  cursor: pointer;
}

.locate-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.locate-button[data-state="ready"] { color: var(--color-user); }
.locate-button[data-state="denied"],
.locate-button[data-state="unavailable"] { color: #aaa; }
.locate-button[data-state="locating"] svg { animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  50% { opacity: 0.3; }
}

/* Toast: short status messages above the tab bar */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + 16px);
  z-index: 1100; /* above Leaflet controls (1000) */
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: rgb(32 33 36 / 0.92);
  color: #fff;
  font-size: 0.875rem;
  text-align: center;
  transform: translateX(-50%);
}

/* Links above the list: About and Privacy */

/* List tab layout: the heading (left) and the links (right) share the first row; the cards span
   the full width below. #list uses display: contents, so the heading listView.js renders inside
   it takes part in this grid. */
.list-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  align-items: start;
  max-width: 720px;
  margin: 0 auto;
}

.list-body {
  display: contents;
}

.list-body > * {
  grid-column: 1 / -1;
}

.list-body > .list-heading {
  grid-column: 1;
  grid-row: 1;
  max-width: none;
  margin: 0 0 8px;
}

.list-links {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column; /* Privacy under About this app */
  align-items: flex-end;
  gap: 2px;
  margin-bottom: 8px;
  color: var(--color-muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.list-links a,
.doc-main a {
  color: var(--color-link);
}

/* Content pages (about/, privacy/): normal scrolling page instead of the app's full-screen grid */

body.doc {
  display: block;
  height: auto;
  min-height: 100dvh;
}

.doc .app-title {
  color: inherit;
  text-decoration: none;
}

.doc-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 48px;
  line-height: 1.6;
}

.doc-main h1 {
  margin: 8px 0 4px;
  font-size: 1.5rem;
  line-height: 1.3;
}

.doc-main h2 {
  margin: 28px 0 8px;
  font-size: 1.125rem;
}

.doc-main ul {
  padding-left: 20px;
}

.doc-main li + li {
  margin-top: 6px;
}

.doc-legend {
  list-style: none;
  padding-left: 0 !important;
}

.doc-legend .badge {
  display: inline-block;
  min-width: 84px;
  margin-right: 8px;
  text-align: center;
}

.doc-updated,
.doc-note {
  color: var(--color-muted);
  font-size: 0.875rem;
}

.doc-back {
  margin-top: 32px;
}

/* Wider screens: .list-layout keeps the list readable (max 720px, centred). Don't give .cards
   auto margins: inside that grid they'd shrink the cards to fit their content. */
