:root {
  --green: #0f6e4f;
  --green-dark: #0b5138;
  --green-light: #e6f4ee;
  --amber: #b5760b;
  --red: #b3261e;
  --ink: #1b1f1d;
  --ink-soft: #4d5651;
  --line: #dbe3de;
  --bg: #f6f8f7;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 20, 0.08), 0 1px 2px rgba(15, 23, 20, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --green: #3fbf8c;
    --green-dark: #2f9c70;
    --green-light: #123326;
    --ink: #eef2f0;
    --ink-soft: #b3bdb7;
    --line: #2a332e;
    --bg: #121613;
    --card: #1b201d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 12px 32px;
}

/* Site-wide nav (every page) */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-nav .wordmark {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.site-nav ul {
  list-style: none;
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}
.site-nav a:not(.wordmark) {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
}
.site-nav a:not(.wordmark).current {
  color: var(--green-dark);
  background: var(--green-light);
}
.site-nav a.soon {
  color: var(--ink-soft);
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

/* Nav menu toggle (checkbox hack — no JS needed) */
.nav-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.nav-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: auto;
  border-radius: 8px;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.nav-toggle-btn:hover { background: var(--green-light); }
.nav-toggle-input:focus-visible + .nav-toggle-btn {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}

@media (max-width: 720px) {
  .site-nav { position: relative; }
  .nav-toggle-btn { display: inline-flex; }
  .site-nav ul {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 2px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }
  .nav-toggle-input:checked ~ ul { display: flex; }
  .site-nav ul li { width: 100%; }
  .site-nav ul li a:not(.wordmark) {
    display: block;
    width: 100%;
    padding: 10px 12px;
  }
}

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--green-dark), var(--green));
  color: #fff;
  padding: 18px 16px;
}
.brand { display: flex; align-items: center; gap: 12px; max-width: 1000px; margin: 0 auto; }
.brand-bolt { font-size: 30px; line-height: 1; }
.app-header h1 { margin: 0; font-size: 1.25rem; }
.tagline { margin: 2px 0 0; font-size: 0.85rem; color: rgba(255,255,255,0.9); }

/* Homepage hero (larger variant of .app-header) */
.home-hero { padding: 40px 16px; }
.home-brand { display: block; max-width: 640px; margin: 0 auto; text-align: center; }
.home-hero h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 8px; }
.home-hero .tagline { font-size: 1rem; }

/* Hub grid (homepage) */
.hub-section { margin-top: 24px; }
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.hub-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-decoration: none;
  color: var(--ink);
}
.hub-card.live { border-color: var(--green); border-width: 1.5px; }
.hub-card.disabled { opacity: 0.72; }
.hub-card .tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 9px;
}
.hub-card .tag.live { background: var(--green-light); color: var(--green-dark); }
.hub-card .tag.soon { background: var(--bg); color: var(--ink-soft); border: 1px solid var(--line); }
.hub-card h3 { margin: 0 0 4px; font-size: 1rem; }
.hub-card p { margin: 0; font-size: 0.85rem; color: var(--ink-soft); }

/* Controls */
.controls { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.control-row { display: flex; flex-wrap: wrap; gap: 8px; }
.search-row { align-items: stretch; }
.search-form { display: flex; flex: 1 1 240px; gap: 8px; }
.search-form input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
}

.filter-row { align-items: end; }
.filter {
  display: flex;
  flex-direction: column;
  font-size: 0.72rem;
  color: var(--ink-soft);
  gap: 3px;
  flex: 1 1 100px;
}
.filter select {
  padding: 9px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-secondary { background: var(--green-light); color: var(--green-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.icon { font-size: 1rem; }

.status-line {
  margin: 12px 2px 6px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  min-height: 1.2em;
}

/* View toggle (mobile) */
.view-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.view-btn {
  flex: 1;
  padding: 9px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.9rem;
}
.view-btn.active { background: var(--green); color: #fff; border-color: var(--green); }

.view-panel { display: none; }
.view-panel.active { display: block; }

#map {
  height: 52vh;
  min-height: 320px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* Station list */
.station-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.station-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  scroll-margin-top: 12px;
}
.station-card.highlight { outline: 2px solid var(--green); }
.station-top { display: flex; justify-content: space-between; gap: 10px; }
.station-name { font-weight: 700; font-size: 1rem; margin: 0 0 2px; }
.station-addr { font-size: 0.83rem; color: var(--ink-soft); margin: 0; }
.station-distance {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--green-dark);
  background: var(--green-light);
  padding: 4px 9px;
  border-radius: 999px;
  height: fit-content;
}

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.badge {
  font-size: 0.75rem;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.badge.status-operational { color: var(--green-dark); border-color: var(--green); background: var(--green-light); }
.badge.status-unknown { color: var(--ink-soft); }
.badge.status-down { color: var(--red); border-color: var(--red); background: rgba(179,38,30,0.08); }

.station-meta { font-size: 0.8rem; color: var(--ink-soft); margin: 4px 0 10px; }

.station-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.station-actions a.btn { text-decoration: none; font-size: 0.85rem; padding: 9px 13px; }

.empty-state, .error-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--ink-soft);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.error-state { color: var(--red); }

.leaflet-popup-content { font-size: 0.85rem; }
.leaflet-popup-content b { display: block; margin-bottom: 3px; }

.app-footer {
  max-width: 1000px;
  margin: 24px auto 0;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  font-size: 0.72rem;
  color: var(--ink-soft);
  line-height: 1.5;
}
.app-footer a { color: var(--ink-soft); }

/* Cost & Savings calculator */
.calc-section { margin-top: 20px; }
.calc-section h2 { margin: 0 0 6px; font-size: 1.15rem; }
.calc-intro {
  margin: 0 0 18px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  max-width: 640px;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.calc-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.calc-field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}
.calc-field input[type="number"],
.calc-field select {
  padding: 10px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
}
.calc-help {
  font-size: 0.74rem;
  color: var(--ink-soft);
  line-height: 1.35;
}
.calc-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-top: 6px;
  cursor: pointer;
}
.calc-checkbox input { margin-top: 2px; }

.calc-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.calc-result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}
.calc-result-card h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.calc-figure {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
}
.calc-sub {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.calc-result-card.highlight {
  border-color: var(--green);
  border-width: 1.5px;
  background: var(--green-light);
}
.calc-result-card.highlight h3 { color: var(--green-dark); }
.calc-result-card.highlight .calc-figure { color: var(--green-dark); }
.calc-result-card.highlight .calc-sub { color: var(--green-dark); }

.calc-note {
  margin: 14px 2px 0;
  font-size: 0.82rem;
  color: var(--amber);
}

/* Guide pages (OZEV grants, road tax, etc.) */
.guide-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin: 14px 2px 0;
  padding: 10px 16px;
  font-size: 0.88rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.guide-breadcrumb a { color: var(--green-dark); text-decoration: none; font-weight: 700; }
.guide-breadcrumb a:hover { text-decoration: underline; }
.guide-breadcrumb .breadcrumb-sep { margin: 0 8px; color: var(--ink-soft); font-weight: 400; }
.guide-breadcrumb .breadcrumb-current { color: var(--ink); font-weight: 700; }
.guide-section { margin-top: 10px; max-width: 680px; }
.guide-section h2 { margin: 24px 0 8px; font-size: 1.05rem; }
.guide-body {
  margin: 0 0 12px;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink);
}
.guide-list {
  margin: 0 0 12px;
  padding-left: 20px;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink);
}
.guide-list li { margin-bottom: 6px; }
.guide-note {
  margin: 18px 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.guide-glance {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 16px 0 20px;
}
.guide-glance-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  text-align: center;
}
.guide-glance-figure {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--green-dark);
}
.guide-glance-label {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.guide-cta {
  text-decoration: none;
  margin-top: 8px;
}

.guide-table-wrap {
  overflow-x: auto;
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.guide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: var(--card);
}
.guide-table th, .guide-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: normal;
}
.guide-table td.nowrap, .guide-table th.nowrap { white-space: nowrap; }
.guide-table th {
  color: var(--ink-soft);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg);
}
.guide-table tr:last-child td { border-bottom: none; }
.guide-table tr.highlight-row td { background: var(--green-light); }
.guide-table tr.highlight-row td:first-child { font-weight: 700; color: var(--green-dark); }
.guide-table td a { color: inherit; text-decoration: underline; }

/* Tablet / desktop: side-by-side map + list, no view toggle */
@media (min-width: 860px) {
  .view-toggle { display: none; }
  .view-panel { display: block !important; }
  #mapView { float: left; width: 58%; position: sticky; top: 12px; }
  #listView { float: right; width: 40%; }
  #map { height: 74vh; }
  .station-list { max-height: 74vh; overflow-y: auto; padding-right: 4px; }
  main::after { content: ""; display: table; clear: both; }
}
