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

:root {
  --bg: #0f1115;
  --surface: #171a20;
  --surface2: #222733;
  --text: #f3f6fb;
  --text-dim: #8a93a4;
  --accent: #69d2ff;
  --accent-strong: #00b8ff;
  --green: #7ee787;
  --orange: #ffa726;
  --red: #ef5350;
  --header-h: 52px;
  --filter-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #2e3644;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #3d4a5f;
}
* {
  scrollbar-width: thin;
  scrollbar-color: #2e3644 transparent;
}

/* --- Header --- */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 12px;
  padding-right: 12px;
  z-index: 1000;
  border-bottom: 1px solid var(--surface2);
}

#highway-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

#highway-name {
  background: var(--accent-strong);
  color: #000;
  font-weight: 700;
  font-size: 20px;
  padding: 4px 12px;
  border-radius: 6px;
  letter-spacing: 1px;
}

#highway-direction {
  font-size: 13px;
  color: var(--text-dim);
}

#header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#gps-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
#gps-status.gps-on { background: var(--green); }
#gps-status.gps-off { background: var(--red); }
#gps-status.gps-wait { background: var(--orange); }

#view-toggle {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid #394255;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  min-height: 44px;
  cursor: pointer;
}

/* --- Banners --- */
#stale-banner {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  left: 0;
  right: 0;
  background: var(--orange);
  color: #000;
  text-align: center;
  padding: 6px;
  font-size: 13px;
  font-weight: 600;
  z-index: 999;
}

#status-message {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top) + var(--filter-h));
  left: 0;
  right: 0;
  background: var(--surface2);
  color: var(--text);
  text-align: center;
  padding: 14px 16px;
  font-size: 15px;
  z-index: 998;
}

.hidden { display: none !important; }

/* --- Filter bar (collapsed) --- */
#filter-bar {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  left: 0;
  right: 0;
  height: var(--filter-h);
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  z-index: 997;
  border-bottom: 1px solid var(--surface2);
}

#filter-open-btn {
  min-height: 38px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid #364056;
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
#filter-open-btn .filter-bar-label {
  font-weight: 700;
  font-size: 13px;
}
#filter-open-btn #filter-summary {
  color: var(--text-dim);
  font-size: 12px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#filter-open-btn .filter-chevron {
  color: var(--text-dim);
  font-size: 10px;
}
#filter-open-btn.has-filters {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 1px rgba(0, 184, 255, 0.2);
}

.filter-presets {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.filter-presets::-webkit-scrollbar { display: none; }

.filter-preset {
  min-height: 36px;
  border-radius: 18px;
  border: 1px solid #364056;
  background: var(--surface2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  padding: 0 12px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
}
.filter-preset.active {
  border-color: var(--green);
  color: var(--green);
  background: rgba(126, 231, 135, 0.1);
}

/* --- Filter bottom sheet --- */
#filter-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1100;
}

#filter-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border: 1px solid #2b3242;
  border-bottom: none;
  padding: 10px 14px calc(14px + var(--safe-bottom));
  z-index: 1200;
  max-height: 70vh;
  overflow-y: auto;
}

.sheet-handle {
  width: 48px;
  height: 5px;
  border-radius: 99px;
  margin: 2px auto 12px;
  background: #3a4358;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-head h2 {
  font-size: 18px;
  font-weight: 700;
}
.sheet-text-btn {
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  padding: 0 8px;
}

.sheet-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.sheet-tab {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #364056;
  background: var(--surface2);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.sheet-tab.active {
  border-color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--accent-strong);
  color: var(--accent);
}

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

.chip-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.sheet-chip {
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid #364056;
  background: var(--surface2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.sheet-chip.active {
  border-color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--accent-strong);
  color: var(--accent);
}

.sheet-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.sheet-btn {
  min-height: 52px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.sheet-btn-ghost {
  background: transparent;
  border: 1px solid #42506b;
  color: var(--text);
}
.sheet-btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border: none;
  color: #00151f;
}

/* --- List View --- */
#list-view {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top) + var(--filter-h));
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 8px;
  padding-bottom: calc(8px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.station-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
  border: 1px solid var(--surface2);
  animation: cardIn .22s ease-out;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.station-card:first-child {
  border-color: var(--accent-strong);
  border-width: 1.5px;
}

.station-card:active {
  background: var(--surface2);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.station-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.station-name-block {
  flex: 1;
  min-width: 0;
  margin-right: 12px;
}

.station-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.badge-24h {
  font-size: 10px;
  background: var(--green);
  color: #000;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 700;
}

.station-ville {
  font-size: 12px;
  color: var(--text-dim);
}

.distance-block {
  text-align: right;
  flex-shrink: 0;
}

.station-distance {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-strong);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.eta-chip {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  margin-top: 2px;
}

/* Collapsed vs expanded card content */
.station-details {
  margin-top: 10px;
}

.services-row {
  display: flex;
  gap: 5px;
  margin-bottom: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.service-icon {
  font-size: 14px;
  background: var(--surface2);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.service-more {
  font-size: 11px;
  color: var(--accent);
  padding: 0 4px;
  font-weight: 600;
  cursor: pointer;
}

.prices-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.price-chip {
  background: var(--surface2);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
  border: 1px solid #2e3644;
  display: flex;
  align-items: center;
  gap: 3px;
}

.price-chip .fuel-label {
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 500;
}

.price-chip .fuel-price {
  font-weight: 700;
}

.price-chip.cheapest {
  background: rgba(126, 231, 135, 0.12);
  border-color: var(--green);
}

.price-chip.cheapest .fuel-price {
  color: var(--green);
}

.best-tag {
  font-size: 9px;
  font-weight: 700;
  color: #08140c;
  background: var(--green);
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 2px;
}

.price-updated {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* Expanded card: all services visible */
.station-card.expanded .services-row-full {
  display: flex;
}
.services-row-full {
  display: none;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.service-full-item {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.service-full-item .sfi-icon { font-size: 14px; }
.service-full-item .sfi-label { font-weight: 500; }

/* EV details (expanded) */
.ev-details {
  display: none;
  margin-top: 8px;
  padding: 8px;
  background: rgba(105, 210, 255, 0.06);
  border: 1px solid rgba(105, 210, 255, 0.2);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.station-card.expanded .ev-details { display: block; }
.ev-details-line {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.empty-msg {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
  font-size: 15px;
}

.ev-chip {
  background: rgba(105, 210, 255, 0.1);
  border-color: var(--accent);
}
.ev-chip .fuel-price {
  color: var(--accent);
}

/* --- Map View --- */
#map-view {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top) + var(--filter-h));
  left: 0;
  right: 0;
  bottom: 0;
}

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

#recenter-btn {
  position: absolute;
  right: 12px;
  bottom: calc(14px + var(--safe-bottom));
  min-height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  border: 1px solid #394255;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  z-index: 1001;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-radius: 10px !important;
}

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

.leaflet-popup-content {
  margin: 10px 14px !important;
  font-size: 14px;
  line-height: 1.5;
}

.popup-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}

.popup-distance {
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 6px;
}

.popup-prices {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}

/* User marker */
.user-marker {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 24px solid var(--accent);
  filter: drop-shadow(0 0 4px rgba(105, 210, 255, 0.6));
}

/* Next-station pulse on map */
@keyframes nextPulse {
  0% { filter: drop-shadow(0 0 0 rgba(105,210,255,0)); }
  50% { filter: drop-shadow(0 0 8px rgba(105,210,255,0.7)); }
  100% { filter: drop-shadow(0 0 0 rgba(105,210,255,0)); }
}
.next-station-marker { animation: nextPulse 2s infinite; }

/* Leaflet dark tiles */
.leaflet-tile {
  filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(1.1);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .station-card, .station-distance, #map, .next-station-marker {
    animation: none !important;
    transition: none !important;
  }
}
