:root {
  --bg: #14171c;
  --surface: #1e2229;
  --surface-alt: #262b33;
  --border: #333944;
  --text: #e8eaed;
  --muted: #9aa1ac;
  --green: #3ecf7e;
  --red: #e5534b;
  --neutral: #9aa1ac;
  --accent: #4a9eff;
  --star: #f5c518;
}

* {
  box-sizing: border-box;
}

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

body {
  padding-bottom: 2rem;
}

h1, h2 {
  font-weight: 600;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 0.75rem 0;
  color: var(--text);
}

.controls {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.control-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.fuel-buttons, .radius-buttons {
  display: flex;
  gap: 0.25rem;
}

button.fuel-btn, button.radius-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
}

button.fuel-btn.active, button.radius-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06111f;
  font-weight: 600;
}

select {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
  max-width: 100%;
}

main#app {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.error-banner {
  background: #3a1f1d;
  border: 1px solid var(--red);
  color: #ffb3ae;
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td.station-name {
  white-space: normal;
  min-width: 10rem;
}

tr.stale {
  opacity: 0.5;
}

tr.abandoned {
  opacity: 0.28;
}

.abandoned-marker {
  color: var(--muted);
  font-size: 0.85em;
  margin-left: 0.15rem;
}

th.sortable {
  padding: 0;
}

.sort-btn {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  width: 100%;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  padding: 0.5rem 0.6rem;
}

.sort-btn:hover {
  color: var(--text);
}

.sort-arrow {
  font-size: 0.85em;
}

tr.station-row {
  cursor: pointer;
}

tr.station-row:hover {
  background: var(--surface-alt);
}

th.star-col, td.star-cell {
  width: 2rem;
  text-align: center;
  padding-left: 0.4rem;
  padding-right: 0.2rem;
}

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
  padding: 0.1rem 0.3rem;
}

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

.outside-hint {
  color: var(--muted);
  font-size: 0.8em;
  font-style: italic;
  margin-left: 0.35rem;
}

tr.pinned-divider td {
  padding: 0;
  height: 0;
  border: none;
  border-top: 2px solid var(--border);
}

.table-search {
  margin-bottom: 0.75rem;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#station-search {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 1.8rem 0.4rem 0.6rem;
  font-size: 0.9rem;
  width: 100%;
  max-width: 260px;
}

.search-clear {
  position: absolute;
  right: 0.4rem;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
}

.search-clear:hover {
  color: var(--text);
}

.favorite-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.favorite-chip {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.favorite-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06111f;
  font-weight: 600;
}

#trend-heading {
  scroll-margin-top: 4.5rem;
}

.delta-green {
  color: var(--green);
}

.delta-red {
  color: var(--red);
}

.delta-neutral {
  color: var(--neutral);
}

.empty-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.sparse-note {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  margin: -0.25rem 0 0.75rem 0;
}

#map {
  height: 420px;
  width: 100%;
  border-radius: 8px;
  background: var(--surface-alt);
}

.chart-wrap {
  position: relative;
  height: 320px;
  width: 100%;
}

.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
}

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

.leaflet-popup-content b {
  color: var(--text);
}

.popup-trend-btn {
  display: block;
  margin-top: 0.4rem;
  background: var(--accent);
  color: #06111f;
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 420px) {
  main#app {
    padding: 0.5rem;
  }

  .panel {
    padding: 0.6rem;
  }

  #map {
    height: 320px;
  }

  .chart-wrap {
    height: 260px;
  }

  th, td {
    padding: 0.4rem 0.4rem;
    font-size: 0.82rem;
  }
}
