:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #0a7d3c;
  --accent-dark: #075c2c;
  --border: #e2e5e9;
  --cheap: #0a7d3c;
  --pricey: #b3261e;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --card: #1e2226;
    --text: #f1f3f5;
    --muted: #9aa4af;
    --border: #30353b;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.sidebar-top {
  padding: env(safe-area-inset-top, 0px) 16px 0;
}

.results {
  padding: 0 16px calc(24px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 900px) {
  .app-layout {
    display: grid;
    grid-template-columns: 420px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "top map" "results map";
    height: 100vh;
  }

  .sidebar-top {
    grid-area: top;
    padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 8px;
  }

  .results {
    grid-area: results;
    min-height: 0;
    overflow-y: auto;
    padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .map-panel {
    grid-area: map;
    height: 100%;
  }

  #map {
    height: 100% !important;
    margin: 0;
    border-radius: 0;
    border: none;
    border-left: 1px solid var(--border);
  }
}

.topbar {
  padding: 16px 0 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
}

.feed-status {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.feed-status a {
  color: var(--muted);
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-tab {
  flex: 1;
  padding: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}

.mode-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.ev-price-note {
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 14px;
}

.connections {
  font-size: 0.8rem;
  color: var(--muted);
}

.search-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.75rem;
  color: var(--muted);
}

.postcode-row {
  display: flex;
  gap: 6px;
}

input, select {
  font-size: 1rem;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

#locate-btn {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  font-size: 1.1rem;
  padding: 0 12px;
  cursor: pointer;
}

.search-btn {
  grid-column: 1 / -1;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.search-btn:active { background: var(--accent-dark); }

.error {
  background: #fdecea;
  color: var(--pricey);
  border: 1px solid #f5c2bf;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 0 0 14px;
}

#map {
  height: 420px;
  border-radius: 12px;
  margin: 0 16px 14px;
  border: 1px solid var(--border);
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.station-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.station-info {
  min-width: 0;
}

.station-brand {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.station-rank {
  font-size: 0.75rem;
  color: white;
  background: var(--accent);
  border-radius: 999px;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.station-address {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.station-distance {
  font-size: 0.8rem;
  color: var(--muted);
}

.station-price {
  text-align: right;
  flex: 0 0 auto;
}

.station-price .pence {
  font-size: 1.2rem;
  font-weight: 700;
}

.station-price.cheap .pence { color: var(--cheap); }
.station-price.pricey .pence { color: var(--pricey); }

.price-pin {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 12px;
  background: var(--card);
  border: 2px solid var(--accent);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.price-pin-logo {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: white;
  object-fit: contain;
  flex: 0 0 auto;
}

.price-pin::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  border-width: 7px 5px 0 5px;
  border-style: solid;
  border-color: var(--accent) transparent transparent transparent;
}

.price-pin.cheap {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.price-pin.pricey {
  border-color: var(--pricey);
}

.price-pin.pricey::after {
  border-color: var(--pricey) transparent transparent transparent;
}

.empty-state, .loading-state {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
}

.leaflet-popup-content-wrapper {
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
}

.leaflet-popup-tip {
  background: var(--card);
}

.popup-card {
  font-family: inherit;
  color: var(--text);
  min-width: 190px;
}

.popup-price {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

.popup-price-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.popup-breakdown-bar {
  display: flex;
  height: 7px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.popup-breakdown-legend {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.popup-breakdown-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}

.popup-brand {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.popup-brand img {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.popup-address {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.popup-hours {
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.popup-hours summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
}

.popup-hours summary::-webkit-details-marker {
  display: none;
}

.popup-hours summary::after {
  content: "\25BE";
  margin-left: auto;
  color: var(--muted);
  font-size: 0.7rem;
}

.popup-hours[open] summary::after {
  content: "\25B4";
}

.popup-hours-week {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.popup-hours-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
}

.popup-hours-row.today {
  color: var(--text);
  font-weight: 600;
}

.popup-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.popup-badge.open {
  background: #e3f5ea;
  color: var(--accent-dark);
}

.popup-badge.closed {
  background: #fdecea;
  color: var(--pricey);
}

.popup-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.popup-chip {
  font-size: 0.68rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.popup-distance {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.popup-changed {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Extra specificity needed to beat Leaflet's own ".leaflet-container a" link color rule */
.leaflet-container a.popup-directions {
  display: block;
  text-align: center;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px;
  border-radius: 8px;
  text-decoration: none;
}

.leaflet-container a.popup-directions:hover {
  background: var(--accent-dark);
  color: white;
}

.legal-page {
  max-width: 680px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0px) 16px calc(32px + env(safe-area-inset-bottom, 0px));
  line-height: 1.6;
}

.legal-page .back-link {
  display: inline-block;
  margin: 16px 0;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.legal-page .back-link:hover {
  text-decoration: underline;
}

.legal-page h1 {
  margin-bottom: 4px;
}

.legal-page .last-updated {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0;
}

.legal-page h2 {
  font-size: 1.1rem;
  margin-top: 28px;
}

.legal-page a {
  color: var(--accent);
}

.legal-page ul {
  padding-left: 20px;
}

.legal-page li {
  margin-bottom: 8px;
}

.site-footer {
  max-width: 680px;
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  color: var(--muted);
}

.site-footer a {
  color: var(--muted);
}

.location-page {
  max-width: 680px;
}

.location-page .topbar {
  text-align: center;
  padding-top: 8px;
}

.location-page .loc-results {
  margin: 12px 0 28px;
  padding-left: 0; /* overrides ".legal-page ul" - this is a card list, not a bullet list */
}

/* The cards are much wider here than in the app's narrow sidebar, so let the address
   wrap onto a second line instead of inheriting the sidebar's ellipsis truncation. */
.location-page .station-address {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.location-page .station-card {
  align-items: flex-start;
}

.location-page .loc-brand-logo {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.location-page .empty-note {
  color: var(--muted);
  font-style: italic;
}

.location-page .stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 20px;
}

.location-page .stat-chip {
  flex: 1 1 140px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}

.location-page .stat-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
}

.location-page .stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.location-page .cta-link {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  margin: 8px 0 24px;
}

.location-page .cta-link:hover {
  background: var(--accent-dark);
}

.location-page .footer-links {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.location-page .city-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.location-page .city-chip {
  display: inline-block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text);
}

.location-page .city-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.location-page .city-chip-grid {
  margin-top: 16px;
}

.location-page hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

.location-page .regional-list {
  padding-left: 20px;
  margin: 12px 0 24px;
}

.location-page .regional-list li {
  margin-bottom: 6px;
}

.location-page .movers-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (min-width: 640px) {
  .location-page .movers-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.location-page .movers-grid h3 {
  margin-top: 0;
}

.location-page .mover-arrow {
  font-size: 0.7rem;
}

.location-page .mover-arrow.cheap {
  color: var(--cheap);
}

.location-page .mover-arrow.pricey {
  color: var(--pricey);
}
