:root {
  color-scheme: light dark;
  --page: #f4f6f3;
  --surface: #fbfcfa;
  --surface-raised: #ffffff;
  --surface-soft: #edf1ed;
  --text: #17201b;
  --muted: #66716a;
  --border: #d9dfda;
  --accent: #176b4d;
  --accent-strong: #10553c;
  --accent-soft: #dceee5;
  --available: #16845b;
  --unknown: #7c8794;
  --unavailable: #d6544d;
  --warning: #a86413;
  --shadow: 0 18px 45px rgb(43 61 50 / 0.12);
  --sheet-peek: 4.25rem;
  --mobile-header: 4rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #121713;
    --surface: #171d18;
    --surface-raised: #1c241e;
    --surface-soft: #232c25;
    --text: #edf3ee;
    --muted: #9ba79f;
    --border: #303b33;
    --accent: #55b98b;
    --accent-strong: #70cba0;
    --accent-soft: #1b3d2e;
    --available: #55b98b;
    --unknown: #8f9aa5;
    --unavailable: #ef7770;
    --warning: #e5a84f;
    --shadow: 0 18px 45px rgb(0 0 0 / 0.34);
  }
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
summary { font: inherit; }

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
summary:focus-visible,
input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: wait; opacity: 0.65; }

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 390px) minmax(0, 1fr);
  grid-template-areas: "sidebar map";
  width: 100%;
  min-height: 100dvh;
  height: 100dvh;
}

.mobile-header,
.sheet-handle,
.sheet-backdrop { display: none; }

.sidebar {
  grid-area: sidebar;
  min-height: 0;
  overflow: hidden;
  position: relative;
  z-index: 20;
  border-right: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 10px 0 32px rgb(42 55 47 / 0.06);
}

.sidebar__body {
  height: 100%;
  overflow-y: auto;
  padding: 28px 24px 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.desktop-header { margin-bottom: 24px; }

.brand-kicker {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.desktop-header h1 {
  margin: 0;
  font-size: clamp(30px, 3vw, 39px);
  line-height: 1;
  letter-spacing: -0.045em;
  font-weight: 760;
}

.subtitle {
  max-width: 34ch;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.freshness-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  min-height: 74px;
  padding: 13px 12px 13px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-raised);
  box-shadow: 0 8px 24px rgb(41 57 47 / 0.07);
}

.freshness-card__indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--unknown);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--unknown) 14%, transparent);
}

.freshness-card.fresh .freshness-card__indicator {
  background: var(--available);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--available) 14%, transparent);
}

.freshness-card.stale .freshness-card__indicator,
.freshness-card.error .freshness-card__indicator {
  background: var(--unavailable);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--unavailable) 14%, transparent);
}

.freshness-card.syncing .freshness-card__indicator {
  background: var(--warning);
  animation: status-pulse 1.25s ease-in-out infinite;
}

.freshness-card__copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.freshness-card__copy strong {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.freshness-card__copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.refresh-link {
  min-width: 74px;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.control-section,
.station-section,
.source-details {
  padding-top: 23px;
}

.control-section h2,
.station-section h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.fuel-options {
  display: grid;
  grid-template-columns: 1.25fr repeat(2, 1fr);
  gap: 8px;
  margin-top: 11px;
}

.fuel-btn--quick {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.fuel-btn--quick.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #f6fbf8;
}

.fuel-btn,
.filter-btn {
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.fuel-btn:hover,
.filter-btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

.fuel-btn.active,
.filter-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #f6fbf8;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
}

.map-count,
.merged-note {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.filter-row {
  display: grid;
  grid-template-columns: 0.78fr 0.9fr 1.45fr 0.72fr;
  gap: 7px;
}

.filter-btn { padding-inline: 6px; }

.station-section { min-height: 260px; }

#stationList {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.station-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 11px;
  align-items: flex-start;
  padding: 11px 9px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.station-item:hover,
.station-item:focus-within { background: var(--surface-soft); }

.list-dot {
  width: 11px;
  height: 11px;
  margin-top: 5px;
  border: 2px solid var(--surface-raised);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border);
}

.list-dot.yes { background: var(--available); }
.list-dot.unknown { background: var(--unknown); }
.list-dot.no { background: var(--unavailable); }

.station-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.station-topline {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.station-topline strong {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-label {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 750;
}

.status-label.yes,
.popup-status.yes { color: var(--available); }
.status-label.unknown,
.popup-status.unknown { color: var(--unknown); }
.status-label.no,
.popup-status.no { color: var(--unavailable); }

.station-address,
.station-source {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.station-source { font-size: 11px; opacity: 0.82; }

#stationList .empty {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 22px 16px;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

#stationList .empty strong { color: var(--text); font-size: 14px; }
#stationList .empty span { font-size: 12px; line-height: 1.4; }

.source-details {
  margin-top: 12px;
  padding-bottom: 18px;
  border-top: 1px solid var(--border);
}

.source-details summary {
  padding-top: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
  cursor: pointer;
}

.source-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }

.chip span {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 12px;
}

.chip input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.source-help {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.meta { color: var(--muted); font-size: 11px; }

#map {
  grid-area: map;
  width: 100%;
  height: 100%;
  min-height: 0;
  z-index: 1;
  background: #d9dfd8;
}

.leaflet-control-zoom {
  overflow: hidden;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
  width: 42px !important;
  height: 42px !important;
  border-color: var(--border) !important;
  background: var(--surface-raised) !important;
  color: var(--text) !important;
  line-height: 42px !important;
}

.leaflet-top.leaflet-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-locate-btn {
  display: flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: 25px;
  line-height: 1;
  box-shadow: var(--shadow);
}

.map-locate-btn.loading,
.icon-btn.loading { animation: locate-spin 1s linear infinite; }

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

.leaflet-popup-content-wrapper {
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.station-popup {
  display: flex;
  min-width: 190px;
  flex-direction: column;
  gap: 5px;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

.station-popup strong { font-size: 15px; }
.station-popup span { color: var(--muted); line-height: 1.35; }
.station-popup small { color: var(--muted); }
.popup-status { margin-top: 3px; }

.geo-toast {
  position: fixed;
  top: 18px;
  left: calc(390px + (100vw - 390px) / 2);
  z-index: 900;
  max-width: min(86vw, 420px);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: none;
  transform: translateX(-50%);
}

.geo-toast.error { color: var(--unavailable); }

@keyframes status-pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.82); }
  50% { opacity: 1; transform: scale(1); }
}

@keyframes locate-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .layout {
    display: block;
    position: relative;
    overflow: hidden;
  }

  .mobile-header {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 500;
    height: calc(var(--mobile-header) + env(safe-area-inset-top, 0px));
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: env(safe-area-inset-top, 0px) 10px 0 16px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 93%, transparent);
    backdrop-filter: blur(14px);
  }

  .mobile-header__title {
    margin: 0;
    font-size: 17px;
    font-weight: 760;
    letter-spacing: -0.025em;
  }

  .mobile-header__status {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 10px;
  }

  .mobile-header__actions { display: flex; gap: 6px; }

  .icon-btn {
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border-radius: 12px;
    background: var(--surface-soft);
    color: var(--text);
    font-size: 22px;
  }

  #map {
    position: fixed;
    inset: 0;
    height: 100dvh;
    padding-top: calc(var(--mobile-header) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom, 0px));
  }

  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 600;
    background: rgb(9 15 11 / 0.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  .sheet-backdrop.visible { opacity: 1; pointer-events: auto; }

  .sidebar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 700;
    display: flex;
    max-height: calc(92dvh - env(safe-area-inset-top, 0px));
    flex-direction: column;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    background: var(--surface);
    box-shadow: 0 -14px 38px rgb(17 30 21 / 0.24);
    transform: translateY(calc(100% - var(--sheet-peek) - env(safe-area-inset-bottom, 0px)));
    transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .sidebar.open { transform: translateY(0); }
  .sidebar.open-full { max-height: calc(96dvh - env(safe-area-inset-top, 0px)); }

  .sheet-handle {
    display: flex;
    width: 100%;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 9px 16px 13px;
    border-radius: 20px 20px 0 0;
    background: transparent;
  }

  .sheet-handle__bar {
    width: 38px;
    height: 4px;
    margin-bottom: 8px;
    border-radius: 999px;
    background: var(--border);
  }

  .sheet-peek {
    width: 100%;
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar__body {
    height: auto;
    padding: 0 15px calc(22px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .desktop-header { display: none; }
  .freshness-card { margin-top: 4px; }

  .control-section,
  .station-section { padding-top: 20px; }

  .fuel-options {
    display: flex;
    width: calc(100% + 15px);
    margin-right: -15px;
    padding-right: 15px;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .fuel-options::-webkit-scrollbar { display: none; }

  .fuel-btn {
    min-width: max-content;
    padding-inline: 15px;
    scroll-snap-align: start;
  }

  .filter-row { gap: 6px; }
  .filter-btn { min-height: 44px; font-size: 12px; }

  .station-section { min-height: 320px; }
  .station-item { padding-block: 13px; }

  .leaflet-top.leaflet-left {
    top: auto;
    right: 12px;
    bottom: calc(12px + var(--sheet-peek) + env(safe-area-inset-bottom, 0px));
    left: auto;
    z-index: 450 !important;
  }

  .leaflet-top.leaflet-right {
    top: auto;
    right: 12px;
    bottom: calc(124px + var(--sheet-peek) + env(safe-area-inset-bottom, 0px));
    left: auto;
    z-index: 450 !important;
  }

  .leaflet-top.leaflet-left .leaflet-control,
  .leaflet-top.leaflet-right .leaflet-control {
    margin-right: 0 !important;
    margin-left: 0 !important;
  }

  .map-locate-btn { width: 50px; height: 50px; }

  .leaflet-control-zoom a {
    width: 48px !important;
    height: 48px !important;
    line-height: 48px !important;
  }

  .geo-toast {
    top: auto;
    bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom, 0px) + 70px);
    left: 50%;
  }
}

@media (max-width: 390px) {
  .filter-row { grid-template-columns: repeat(2, 1fr); }
  .freshness-card { grid-template-columns: auto minmax(0, 1fr); }
  .refresh-link { grid-column: 2; width: fit-content; }
}

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