/* Where to Pump@WA — mobile-first layout */

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

  --color-cheap: #1e8e3e;
  --color-mid: #d97706;
  --color-dear: #c5221f;
  --color-user: #1a73e8;

  --header-height: 52px;
  --filters-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 auto 1fr auto;
  grid-template-areas: 'header' 'filters' '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;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

/* Filters: fuel type and today / tomorrow */

.filters {
  grid-area: filters;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--filters-height);
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.filters__fuel select {
  height: 36px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%235f6b7a'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E")
    no-repeat right 8px center / 20px;
  color: var(--color-text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  appearance: none;
  cursor: pointer;
}

.segmented {
  display: flex;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg);
}

.segmented button {
  height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--color-muted);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 600;
}

.filters__fuel select:focus-visible,
.segmented button:focus-visible {
  outline: 2px solid var(--color-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-mid);
  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__price {
  flex-shrink: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.card__price--cheap { color: var(--color-cheap); }
.card__price--mid { color: var(--color-mid); }
.card__price--dear { color: var(--color-dear); }

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

.list-notice {
  max-width: 720px;
  margin: 0 auto 8px;
  padding: 8px 12px;
  border: 1px solid var(--color-mid);
  border-radius: 8px;
  color: var(--color-text);
  font-size: 0.8125rem;
}

.list-credit {
  margin: 16px 0 4px;
  color: var(--color-muted);
  font-size: 0.75rem;
  text-align: center;
}

.list-credit a {
  color: inherit;
}

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

/* Hundreds of cards: let the browser skip layout/paint for the ones off-screen */
.cards > li {
  content-visibility: auto;
  contain-intrinsic-size: auto 72px;
}

.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: a zero-size anchor on the station, with the price label centred over it, so the
   label can grow with its text */

.marker-anchor {
  width: 0;
  height: 0;
}

.marker {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  min-width: 36px;
  height: 24px;
  padding: 0 7px;
  border: 2px solid #fff;
  border-radius: 12px;
  color: #fff;
  font: 700 0.75rem var(--font);
  white-space: nowrap;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.35);
  transform: translate(-50%, -50%);
}

.marker--cheap { background: var(--color-cheap); }
.marker--mid { background: var(--color-mid); }
.marker--dear { background: var(--color-dear); }

/* Station 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__address {
  margin-top: 2px;
  color: #5f6b7a;
  font-size: 0.8125rem;
}

.popup__price {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #dde3ea;
}

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

.popup__count--cheap { color: var(--color-cheap); }
.popup__count--mid { color: var(--color-mid); }
.popup__count--dear { color: var(--color-dear); }

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