/* ============================================================
   ServoSpy — Cockpit Clarity Design System v3
   Full UX/UI audit implementation
   ============================================================ */

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

:root {
  /* Base palette */
  --bg: #0a0a12;
  --bg-raised: #0f0f1c;
  --surface: #151524;
  --surface-2: #1c1c34;
  --surface-3: #24243e;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(0, 212, 170, 0.4);

  /* Text */
  --text: #eaeaf2;
  --text-secondary: #a8a8c0;
  --text-tertiary: #7a7a98;

  /* Accent */
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.15);
  --accent-glow: rgba(0, 212, 170, 0.25);

  /* Markup colours */
  --green: #00c853;
  --green-bg: rgba(0, 200, 83, 0.12);
  --green-border: rgba(0, 200, 83, 0.35);
  --yellow: #ffd600;
  --yellow-bg: rgba(255, 214, 0, 0.12);
  --yellow-border: rgba(255, 214, 0, 0.3);
  --red: #ff1744;
  --red-bg: rgba(255, 23, 68, 0.10);
  --red-border: rgba(255, 23, 68, 0.3);

  /* Shared */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --font-display: 'Bricolage Grotesque', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'DM Mono', 'SF Mono', Consolas, monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --header-h: 160px;
  --bottom-bar-h: 56px;
}


/* ---- Skip Link ---- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 10000;
  padding: 12px 20px;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: var(--radius);
  text-decoration: none;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 12px;
}

/* ---- Grain Texture Overlay ---- */
.grain {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px 200px;
}

/* ---- Base ---- */
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(0, 212, 170, 0.05) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(0, 212, 170, 0.02) 0%, transparent 50%);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

/* ============================================================
   Global Focus-Visible Styles
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Override for specific components that style their own focus */
#location-input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ============================================================
   Search Header
   ============================================================ */
#search-bar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(10, 10, 18, 0.85);
  backdrop-filter: blur(24px) saturate(1.5);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top, 0) 0 0;
}

.search-inner {
  padding: 10px 16px;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- Brand ---- */
.brand {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1;
  color: var(--text);
  margin: 0;
  margin-right: auto;
  flex-shrink: 0;
}

.brand-accent {
  color: var(--accent);
}

/* ---- Fuel Toggle (Segmented Control) ---- */
.fuel-toggle {
  position: relative;
  display: flex;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 3px;
  border: 1px solid var(--border);
}

.fuel-btn {
  position: relative;
  z-index: 1;
  padding: 7px 12px;
  min-height: 34px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: calc(var(--radius) - 3px);
  transition: color 0.25s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fuel-btn.active {
  color: var(--bg);
}

.fuel-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--accent);
  border-radius: calc(var(--radius) - 3px);
  transition: transform 0.35s var(--ease-spring);
  box-shadow: 0 2px 8px rgba(0, 212, 170, 0.25);
}

.fuel-toggle[data-active="DL"] .fuel-slider {
  transform: translateX(100%);
}

/* ---- Search Input ---- */
.typeahead-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  transition: color 0.2s;
}

.typeahead-wrap:focus-within .search-icon {
  color: var(--accent);
}

.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-2);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.clear-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.clear-btn.hidden {
  display: none !important;
}

#location-input {
  width: 100%;
  padding: 13px 52px 13px 42px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
  transition: border-color 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out), background 0.25s;
  -webkit-appearance: none;
  min-height: 48px;
}

#location-input::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
}

#location-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--bg-raised);
}

.search-helper {
  display: block;
  font-size: 0.68rem;
  color: var(--text-tertiary);
  margin-top: 6px;
  padding-left: 2px;
}

#search-bar.search-active .search-helper {
  display: none;
}

/* ---- Typeahead Dropdown ---- */
#suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  max-height: min(280px, 40vh);
  overflow-y: auto;
  z-index: 1001;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: dropdown-in 0.2s var(--ease-out);
  overscroll-behavior: contain;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#suggestions li {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

#suggestions li:last-child {
  border-bottom: none;
}

#suggestions li:hover,
#suggestions li.active {
  background: var(--surface-2);
}

#suggestions li.active {
  background: var(--accent-dim);
}

#suggestions li.no-results {
  color: var(--text-tertiary);
  font-size: 0.85rem;
  cursor: default;
  justify-content: center;
}

#suggestions li.suggestion-header {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  padding: 8px 16px 4px;
  cursor: default;
  min-height: auto;
  border-bottom: none;
}

#suggestions li.suggestion-header:hover {
  background: transparent;
}

#suggestions li .suburb-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text);
}

#suggestions li .suburb-name .match {
  color: var(--accent);
  font-weight: 700;
}

#suggestions li .suburb-postcode {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-tertiary);
  font-weight: 400;
  flex-shrink: 0;
}

/* ============================================================
   Landing — cheap fuel data loads immediately
   ============================================================ */
#landing {
  padding: 16px 16px 24px;
  animation: landing-in 0.6s var(--ease-out) both;
}

@keyframes landing-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

#landing.landing-exiting {
  animation: landing-exit 0.35s var(--ease-out) forwards;
  pointer-events: none;
}

@keyframes landing-exit {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-24px); }
}

#landing.landing-entering {
  animation: landing-in 0.5s var(--ease-out) both;
}

/* ---- Location Prompt ---- */
.location-prompt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid rgba(0, 212, 170, 0.2);
  border-radius: var(--radius);
}

.location-prompt.hidden {
  display: none !important;
}

.location-prompt svg {
  color: var(--accent);
  flex-shrink: 0;
}

.location-prompt-text {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.location-prompt-btn {
  padding: 8px 20px;
  min-height: 36px;
  border: none;
  border-radius: 100px;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.location-prompt-btn:hover {
  background: #00e8ba;
  box-shadow: 0 4px 12px rgba(0, 212, 170, 0.3);
}

.location-prompt-btn:active {
  transform: scale(0.96);
}

/* ---- Landing Header ---- */
.landing-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.landing-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
  flex: 1 1 auto;
}

/* ---- Radius Selector (segmented control) ---- */
.radius-selector {
  position: relative;
  display: flex;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 3px;
  border: 1px solid var(--border);
}

.radius-selector.hidden {
  display: none !important;
}

.radius-pill {
  position: relative;
  z-index: 1;
  padding: 8px 14px;
  min-height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: calc(var(--radius) - 3px);
  transition: color 0.25s var(--ease-out), background 0.25s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.radius-pill.active {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 2px 8px rgba(0, 212, 170, 0.25);
}

.radius-pill:not(.active):hover {
  color: var(--text);
  background: var(--surface-2);
}

/* ---- See All Link ---- */
.see-all-link {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  transition: opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.see-all-link.hidden {
  display: none !important;
}

.see-all-link:hover {
  opacity: 0.75;
}

/* ---- Landing Cards ---- */
.landing-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100px;
}

/* Landing card accents — use price-based color from border-left only */
.station-card.landing-card-gold,
.station-card.landing-card-silver,
.station-card.landing-card-bronze {
  border-color: var(--border);
  background: var(--surface);
}

/* Landing card readability overrides (top 3 featured cards) */
.landing-cards .station-card {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.landing-cards .station-rank {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  opacity: 0.8;
}

.landing-cards .best-tag {
  font-size: 0.82rem;
  font-weight: 700;
  color: #2ecc71;
}

/* Price tag row */
.landing-cards .card-price-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 8px;
}

.landing-cards .card-price-hero.price-tag {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 2rem;
  font-weight: 800;
  background: #f5f5f5;
  color: #333;
  padding: 6px 14px;
  border-radius: 8px;
  display: inline-flex;
  align-items: baseline;
  line-height: 1;
  margin: 0;
}

.landing-cards .price-dollar {
  color: #1b7a4a;
  margin-right: 1px;
}

.landing-cards .price-value {
  color: #333;
}

.landing-cards .price-tier {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.landing-cards .price-tier-cheap {
  color: #2ecc71;
}

.landing-cards .price-tier-average {
  color: #f39c12;
}

.landing-cards .price-tier-expensive {
  color: #e74c3c;
}

.landing-cards .station-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.landing-cards .station-address {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.landing-cards .card-hero-drive {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.landing-cards .card-hero-dist {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.landing-cards .card-directions {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
}

/* ---- Search Toggle (always visible in header-top) ---- */
.search-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.search-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Hide toggle when search is active (form already visible) */
#search-bar.search-active .search-toggle {
  display: none;
}

/* ---- Search-active header state ---- */
#search-bar.search-active {
  border-bottom-color: rgba(0, 212, 170, 0.15);
  box-shadow: 0 1px 24px rgba(0, 212, 170, 0.06);
}

#search-bar.search-active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.4;
  animation: search-line-in 0.5s var(--ease-out) both;
}

@keyframes search-line-in {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* ---- Results entrance ---- */
#colour-legend,
#view-toggle,
#map-container,
#list-container {
  transition: opacity 0.35s var(--ease-out), transform 0.35s var(--ease-out);
}

.results-entering #colour-legend,
.results-entering #view-toggle {
  animation: results-bar-in 0.4s var(--ease-out) both;
}

.results-entering #map-container {
  animation: results-map-in 0.5s var(--ease-out) 0.1s both;
}

.results-entering #list-container {
  animation: results-list-in 0.5s var(--ease-out) 0.15s both;
}

@keyframes results-bar-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes results-map-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes results-list-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Results exit (returning to landing) ---- */
.results-exiting #colour-legend,
.results-exiting #view-toggle,
.results-exiting #map-container,
.results-exiting #list-container {
  animation: results-exit 0.3s var(--ease-out) forwards;
}

@keyframes results-exit {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}




.quick-chip {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 10px 18px;
  min-height: 44px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.quick-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 12px rgba(0, 212, 170, 0.08);
}

.quick-chip:active {
  transform: scale(0.96);
}


/* ============================================================
   Station Rank Number
   ============================================================ */
.station-rank {
  position: absolute;
  top: 10px;
  right: 12px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-tertiary);
  opacity: 0.5;
  line-height: 1;
}

/* ============================================================
   View Toggle Bar
   ============================================================ */
#view-toggle {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

#view-toggle.hidden {
  display: none !important;
}

.toggle-bar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toggle-group {
  position: relative;
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border);
}

.toggle-btn {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: calc(var(--radius-sm) - 3px);
  transition: color 0.25s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.toggle-btn svg {
  opacity: 0.7;
}

.toggle-btn.active {
  color: var(--text);
}

.toggle-btn.active svg {
  opacity: 1;
}

.toggle-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--surface-3);
  border-radius: calc(var(--radius-sm) - 3px);
  transition: transform 0.3s var(--ease-spring);
}

.toggle-group[data-active="list"] .toggle-slider {
  transform: translateX(100%);
}

/* ---- Sort Toggle ---- */
.sort-group {
  display: flex;
  gap: 4px;
}

.sort-btn {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 12px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.sort-btn.active {
  border-color: var(--accent);
  color: var(--bg);
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 212, 170, 0.25);
}

.sort-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.sort-btn:not(:disabled):hover {
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
}

#station-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ============================================================
   Map
   ============================================================ */
#map-container {
  height: calc(100dvh - var(--header-h, 160px) - 40px);
  min-height: 350px;
  position: relative;
}

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

/* ---- Locate Button ---- */
.locate-btn {
  position: absolute;
  bottom: 24px;
  right: 12px;
  transition-property: background, color, border-color, bottom;
  transition-duration: 0.2s;
  transition-timing-function: var(--ease-out);
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: all 0.2s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.locate-btn:hover {
  background: var(--surface-2);
  color: var(--accent);
  border-color: var(--accent);
}

.locate-btn.has-location {
  color: var(--accent);
}

/* Leaflet overrides */
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border);
  padding: 0;
}

.leaflet-popup-tip {
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.leaflet-popup-content {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.5;
  min-width: 220px;
  max-width: calc(100vw - 40px);
}

/* Larger close button for accessibility */
.leaflet-popup-close-button {
  width: 32px !important;
  height: 32px !important;
  font-size: 20px !important;
  line-height: 32px !important;
  color: var(--text-tertiary) !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.leaflet-popup-close-button:hover {
  color: var(--text) !important;
}

.popup-card {
  padding: 14px 16px;
}

/* Hero: drive time is the most important thing */
.popup-hero {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.popup-hero-drive {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  min-width: 2ch;
}

.popup-hero-dist {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.popup-name {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 2px;
  color: var(--text);
  padding-right: 20px;
}

.popup-addr {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.popup-price-hero {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 500;
  text-align: center;
  padding: 4px 0 8px;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Directions link in popup */
.popup-directions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
  padding: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  transition: background 0.15s;
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 12px -16px -14px;
  padding: 10px 16px;
  min-height: 44px;
}

.popup-directions:hover {
  background: var(--accent-dim);
}

/* Marker cluster overrides — uniform soft blue to avoid confusion with markup colours */
.marker-cluster {
  background: rgba(100, 160, 220, 0.25) !important;
}

.marker-cluster div {
  background: #5b9bd5 !important;
  color: #fff !important;
  font-family: var(--font-mono) !important;
  font-weight: 600 !important;
  font-size: 12px !important;
  width: 32px !important;
  height: 32px !important;
  margin-left: 4px !important;
  margin-top: 4px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.marker-cluster-small {
  background: rgba(100, 160, 220, 0.25) !important;
}

.marker-cluster-medium {
  background: rgba(100, 160, 220, 0.3) !important;
}

.marker-cluster-medium div {
  background: #5b9bd5 !important;
}

.marker-cluster-large {
  background: rgba(100, 160, 220, 0.35) !important;
}

.marker-cluster-large div {
  background: #4a8bc2 !important;
  color: #fff !important;
}

/* User location indicator */
.user-location-marker {
  background: none !important;
  border: none !important;
}

.user-location-dot {
  width: 16px;
  height: 16px;
  background: #4285f4;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(66, 133, 244, 0.6);
  position: relative;
}

.user-location-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin-top: -20px;
  margin-left: -20px;
  background: rgba(66, 133, 244, 0.15);
  border-radius: 50%;
  animation: user-pulse 2s ease-out infinite;
}

@keyframes user-pulse {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(1.2); opacity: 0; }
}

.leaflet-container {
  background: var(--bg) !important;
  font-family: var(--font-body);
}

/* ============================================================
   List View
   ============================================================ */
#list-container {
  padding: 12px 16px 24px;
}

/* Station Card */
.station-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  transition: border-color 0.2s, transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
  animation: card-in 0.4s var(--ease-out) both;
  cursor: default;
  position: relative;
  content-visibility: auto;
  contain-intrinsic-size: auto 140px;
}

.station-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
  border-left-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  transform: translateY(-1px);
}

.station-card:active {
  transform: scale(0.995);
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Drive time row */
.card-hero {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.card-hero-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.card-hero-drive {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.card-hero-dist {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* Drive time loading placeholder */
.drive-loading {
  display: inline-block;
  min-width: 5ch;
  color: var(--text-tertiary);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.card-info {
  margin-bottom: 8px;
}

.station-name {
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: 2px;
}

.station-address {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

/* Markup badge */
/* Price hero on card */
.card-price-hero {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 4px 0 8px;
}

/* Directions button on card */
.card-directions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  transition: background 0.2s var(--ease-out), color 0.2s;
  min-height: 48px;
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 12px -20px -18px;
  background: rgba(0, 212, 170, 0.04);
}

.card-directions:hover {
  background: var(--accent-dim);
}

.card-directions:active {
  background: rgba(0, 212, 170, 0.2);
}

.card-directions svg {
  flex-shrink: 0;
}

/* Best deal indicator */
.station-card.best-deal {
  border-color: rgba(255, 255, 255, 0.08);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(0, 200, 83, 0.04) 100%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.station-card.best-deal:hover {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.best-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.best-tag::before {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
  animation: best-pulse 2s ease-in-out infinite;
}

@keyframes best-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* ---- Load More Button ---- */
.load-more-btn {
  display: block;
  width: 100%;
  padding: 14px 20px;
  min-height: 48px;
  margin-top: 4px;
  margin-bottom: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.load-more-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* ============================================================
   Loading
   ============================================================ */
#loading {
  padding: 48px 16px 24px;
}

.loading-content {
  text-align: center;
  margin-bottom: 32px;
}

.spinner {
  position: relative;
  width: 36px;
  height: 36px;
  margin: 0 auto 14px;
}

.spinner-ring {
  position: absolute;
  inset: 0;
  border: 2.5px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.spinner-ring-2 {
  inset: 5px;
  border-top-color: transparent;
  border-right-color: var(--accent);
  animation-duration: 1.4s;
  animation-direction: reverse;
  opacity: 0.4;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* Skeleton cards */
.skeleton-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px;
  max-width: 640px;
  margin: 0 auto;
}

.skeleton-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.sk-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sk-line {
  height: 12px;
  background: var(--surface-2);
  border-radius: 6px;
}

.sk-badge {
  width: 52px;
  height: 28px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.sk-w35 { width: 35%; }
.sk-w40 { width: 40%; }
.sk-w45 { width: 45%; }
.sk-w50 { width: 50%; }
.sk-w60 { width: 60%; }
.sk-w70 { width: 70%; }
.sk-w75 { width: 75%; }
.sk-w80 { width: 80%; }

/* ============================================================
   Error / Empty States
   ============================================================ */
#error, #empty {
  text-align: center;
  padding: 64px 24px;
  animation: state-in 0.4s var(--ease-out) both;
}

@keyframes state-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.state-illustration {
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

#error .state-illustration {
  color: var(--red);
}

.state-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.state-desc {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  max-width: 260px;
  margin: 0 auto;
}

.empty-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

/* ============================================================
   Footer
   ============================================================ */
footer {
  position: relative;
  margin-top: 16px;
}

footer::before {
  content: '';
  position: absolute;
  top: -40px;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(180deg, transparent 0%, var(--bg) 100%);
  pointer-events: none;
}

.footer-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 16px 36px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.footer-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}

.logo-mark-sm {
  width: 18px;
  height: 18px;
}

.logo-mark-sm .logo-dot {
  width: 5px;
  height: 5px;
}

.logo-mark-sm .logo-ring {
  border-width: 1.5px;
  animation: none;
  opacity: 0.2;
}

.footer-wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--text-tertiary);
  letter-spacing: -0.3px;
}

footer p {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  line-height: 1.6;
}

footer strong {
  color: var(--text-secondary);
  font-weight: 600;
}

.footer-note {
  margin-top: 2px;
}

.coverage {
  margin-top: 10px;
  font-weight: 600;
  font-size: 0.7rem !important;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.footer-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.footer-nav a {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-nav a:hover {
  color: var(--accent);
}

.footer-nav-sep {
  color: var(--text-tertiary);
  opacity: 0.4;
  font-size: 0.72rem;
}

/* ============================================================
   Utility
   ============================================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ============================================================
   Mobile — Fixed bottom toggle bar
   ============================================================ */
@media (max-width: 899px) {
  #view-toggle:not(.hidden) {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    border-top: 1px solid var(--border);
    border-bottom: none;
    background: rgba(10, 10, 18, 0.92);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Content padding to avoid overlap with bottom bar */
  #list-container {
    padding-bottom: 72px;
  }

  #map-container {
    height: calc(100dvh - var(--header-h, 160px) - var(--bottom-bar-h));
  }

  /* Push locate button above the fixed bottom bar */
  .locate-btn {
    bottom: 16px;
  }

  .toggle-bar-inner {
    flex-wrap: wrap;
  }

  /* Sort group inline with toggle on mobile */
  .sort-group {
    order: 2;
  }

  #station-count {
    order: 3;
    width: 100%;
    text-align: center;
    font-size: 0.68rem;
    padding-top: 2px;
  }
}


/* ---- Collapsible search (always — search toggle is in header-top) ---- */
#search-form {
  display: none;
}

#search-form.search-expanded {
  display: block;
  animation: landing-in 0.25s var(--ease-out) both;
  margin-top: 10px;
}

/* When search is active (results showing), always show the form */
#search-bar.search-active #search-form {
  display: block;
  margin-top: 10px;
}

/* Small mobile tweaks */
@media (max-width: 380px) {
  .brand {
    font-size: 1rem;
  }

  .fuel-btn {
    padding: 6px 8px;
    font-size: 0.7rem;
  }

  #location-input {
    font-size: 0.9rem;
    padding: 12px 48px 12px 38px;
  }

  .landing-title {
    font-size: 1.1rem;
  }

  .sort-group {
    gap: 2px;
  }

  .sort-btn {
    padding: 6px 8px;
    font-size: 0.68rem;
  }

  /* Compact popup for tiny screens */
  .leaflet-popup-content {
    min-width: 180px;
  }

  .popup-card {
    padding: 10px 12px;
  }

  .popup-price-hero {
    font-size: 1.6rem;
    padding: 2px 0 6px;
  }

  .popup-hero-drive {
    font-size: 1.15rem;
  }

  .popup-name {
    font-size: 0.78rem;
    padding-right: 16px;
  }

  .popup-addr {
    font-size: 0.68rem;
    margin-bottom: 6px;
  }

  .popup-directions {
    font-size: 0.72rem;
    padding: 8px 12px;
    margin: 8px -12px -10px;
    min-height: 40px;
  }

  /* Compact cards */
  .card-price-hero {
    font-size: 1.4rem;
  }

  .station-card {
    padding: 12px 12px 12px 16px;
  }

  /* Match negative margins to reduced card padding */
  .card-directions {
    margin: 12px -12px -12px;
    padding: 10px 12px;
  }

  .station-name {
    font-size: 0.82rem;
  }

  .station-address {
    font-size: 0.7rem;
  }

  .card-hero-drive {
    font-size: 0.85rem;
  }

  /* Landing cards stay readable on small screens */
  .landing-cards .card-price-hero {
    font-size: 1.7rem;
  }

  .landing-cards .station-name {
    font-size: 0.92rem;
  }

  .landing-cards .station-address {
    font-size: 0.78rem;
  }

  .landing-cards .card-hero-drive {
    font-size: 0.95rem;
  }
}

/* Very small screens (iPhone SE, Galaxy Fold) */
@media (max-width: 320px) {
  .brand h1 {
    font-size: 1.05rem;
  }

  .fuel-btn {
    padding: 8px 10px;
    font-size: 0.7rem;
  }

  .header-top {
    gap: 8px;
  }

  .popup-price-hero {
    font-size: 1.4rem;
  }

  .popup-hero {
    gap: 6px;
    margin-bottom: 6px;
    padding-bottom: 6px;
  }

  .popup-hero-drive {
    font-size: 1rem;
  }

  .card-price-hero {
    font-size: 1.25rem;
  }

  .search-helper {
    font-size: 0.68rem;
  }
}

/* Touch device hover prevention — reset all interactive hover states */
@media (hover: none) {
  .station-card:hover {
    border-color: var(--border);
    border-left-color: var(--border);
    box-shadow: none;
    transform: none;
  }

  .station-card.best-deal:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  }

  .quick-chip:hover {
    border-color: var(--border);
    color: var(--text-secondary);
    background: var(--surface);
    box-shadow: none;
  }

  .load-more-btn:hover {
    background: var(--surface);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .locate-btn:hover {
    background: var(--surface);
    color: var(--text-secondary);
    border-color: var(--border);
  }

  .card-directions:hover {
    background: rgba(0, 212, 170, 0.04);
  }

  .popup-directions:hover {
    background: transparent;
  }

}

/* ============================================================
   Reduced Motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .logo-ring,
  .spinner-ring,
  .best-tag::before {
    animation: none !important;
  }

  .station-card {
    animation: none !important;
  }
}
