/* 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;

  --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;
  }
}

*,
*::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: center;
  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;
}

.app-title span {
  opacity: 0.75;
}

/* 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;
}

.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;
}

.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;
}

/* ~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%);
}

/* Wider screens: keep the list readable */

@media (min-width: 768px) {
  .cards {
    max-width: 720px;
    margin-inline: auto;
  }
}
