:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f4f5f7);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111316);
  --muted: var(--tg-theme-hint-color, #6f7680);
  --accent: var(--tg-theme-button-color, #111316);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --separator: rgba(127, 127, 127, 0.22);
  --success: #138a4b;
  --warning: #b56b00;
  --danger: #c0392b;
  --unknown: #7a8088;
  --info: #2f80ed;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); }
button { font: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--info) 60%, transparent); outline-offset: 2px; }

.app-shell { position: relative; width: 100%; height: 100%; background: var(--bg); }
.map { position: absolute; inset: 0; }

.top-panel {
  position: absolute;
  z-index: 30;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  pointer-events: none;
}

.brand-row, .region-row, .filter-strip {
  pointer-events: auto;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  border: 1px solid var(--separator);
}

.brand-row {
  min-height: 56px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 9px;
  border-radius: 18px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 900;
  letter-spacing: -0.04em;
}
.brand-copy { min-width: 0; }
.brand-title { font-size: 14px; font-weight: 800; letter-spacing: 0.04em; }
.brand-subtitle { margin-top: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-actions { display: flex; gap: 6px; }

.icon-button, .map-action {
  border: 1px solid var(--separator);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  cursor: pointer;
}
.icon-button { width: 38px; height: 38px; border-radius: 12px; font-size: 20px; font-weight: 800; }
.icon-button:disabled, .map-action:disabled { opacity: .55; cursor: wait; }
.icon-button.is-spinning { animation: spin .8s linear infinite; }

.region-row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-radius: 16px;
}
.region-label { color: var(--muted); font-size: 12px; font-weight: 800; }
.region-select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--separator);
  border-radius: 11px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.filter-strip {
  margin-top: 8px;
  display: flex;
  gap: 7px;
  padding: 8px;
  border-radius: 16px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.filter-strip::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--separator);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
}
.filter-chip:active { transform: scale(.96); }
.filter-chip.is-active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.network-banner {
  position: absolute;
  z-index: 32;
  top: calc(max(10px, env(safe-area-inset-top)) + 158px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--warning);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.map-actions {
  position: absolute;
  z-index: 24;
  right: 12px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: grid;
  gap: 9px;
}
.map-action { width: 48px; height: 48px; border-radius: 16px; font-size: 24px; }

.loading-indicator, .toast {
  position: absolute;
  z-index: 60;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  color: var(--text);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.loading-indicator { top: calc(max(10px, env(safe-area-inset-top)) + 168px); }
.toast { bottom: calc(90px + env(safe-area-inset-bottom)); border-radius: 14px; }
.is-hidden { display: none !important; }

.empty-state {
  position: absolute;
  z-index: 25;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 36px));
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 18px;
  border: 1px solid var(--separator);
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  text-align: center;
}
.empty-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: var(--bg); font-size: 25px; }
.empty-state strong { font-size: 17px; }
.empty-state > span { color: var(--muted); font-size: 13px; line-height: 1.45; }
.empty-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.empty-actions > :only-child { grid-column: 1 / -1; }

.legend-dot[data-state="available"] { background: var(--success); }
.legend-dot[data-state="likely"] { background: var(--warning); }
.legend-dot[data-state="unavailable"] { background: var(--danger); }
.legend-dot[data-state="unknown"] { background: var(--unknown); }

.station-sheet {
  position: absolute;
  z-index: 50;
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  max-height: min(72vh, 660px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px 16px 18px;
  border: 1px solid var(--separator);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 98%, transparent);
  box-shadow: 0 -10px 34px rgba(0,0,0,.2);
  transform: translateY(calc(100% + 30px));
  opacity: 0;
  transition: transform .22s ease, opacity .18s ease;
  pointer-events: none;
}
.station-sheet.is-open { transform: translateY(0); opacity: 1; pointer-events: auto; }
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 10px; border-radius: 999px; background: var(--separator); }
.sheet-close { position: absolute; top: 11px; right: 12px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--bg); color: var(--text); font-size: 24px; cursor: pointer; }
.station-heading { padding-right: 38px; }
.station-brand { display: inline-block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.station-title { margin: 0 0 4px; font-size: 22px; line-height: 1.15; }
.station-address { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.station-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.meta-pill { padding: 7px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 700; }
.meta-pill[data-freshness="fresh"] { color: var(--success); }
.meta-pill[data-freshness="stale"] { color: var(--warning); }
.fuel-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.fuel-card { padding: 11px 8px; border: 1px solid var(--separator); border-radius: 16px; background: var(--bg); text-align: center; }
.fuel-name { font-weight: 900; font-size: 14px; }
.fuel-price { margin-top: 5px; font-size: 13px; font-weight: 900; line-height: 1.2; }
.fuel-status { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.2; }
.fuel-card[data-state="available"] .fuel-status { color: var(--success); }
.fuel-card[data-state="likely"] .fuel-status { color: var(--warning); }
.fuel-card[data-state="unavailable"] .fuel-status { color: var(--danger); }
.station-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 15px; }
.primary-action, .secondary-action { min-height: 46px; padding: 0 12px; border-radius: 14px; font-weight: 800; cursor: pointer; }
.primary-action { border: 0; background: var(--accent); color: var(--accent-text); }
.secondary-action { border: 1px solid var(--separator); background: var(--bg); color: var(--text); }
.primary-action:disabled, .secondary-action:disabled { opacity: .55; cursor: wait; }
.station-disclaimer { margin: 13px 2px 0; color: var(--muted); font-size: 11px; line-height: 1.4; }

.modal-backdrop { position: absolute; z-index: 70; inset: 0; background: rgba(0,0,0,.38); }
.legend-panel {
  position: absolute;
  z-index: 75;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100% - 32px));
  padding: 20px;
  border-radius: 22px;
  border: 1px solid var(--separator);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.legend-panel h2 { margin: 0 42px 16px 0; font-size: 20px; }
.legend-list { display: grid; gap: 12px; }
.legend-list > div { display: grid; grid-template-columns: 20px 1fr; column-gap: 10px; align-items: center; }
.legend-list small { grid-column: 2; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.legend-dot { width: 18px; height: 18px; border-radius: 50%; grid-row: 1 / span 2; }
.legend-note { margin: 16px 0 0; padding: 11px; border-radius: 14px; background: var(--bg); color: var(--muted); font-size: 12px; line-height: 1.4; }

.fatal-error {
  position: absolute;
  z-index: 100;
  inset: 20px;
  margin: auto;
  width: min(440px, calc(100% - 40px));
  height: fit-content;
  padding: 20px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow);
}
.fatal-error strong, .fatal-error span { display: block; }
.fatal-error span { margin: 8px 0 14px; color: var(--muted); line-height: 1.45; }
.fatal-error .primary-action { width: 100%; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .top-panel { width: 540px; right: auto; }
  .station-sheet { width: 430px; right: auto; left: 12px; }
  .empty-state { top: 50%; }
}

@media (max-height: 620px) {
  .station-sheet { max-height: 82vh; }
  .top-panel { top: max(6px, env(safe-area-inset-top)); }
  .brand-row { min-height: 50px; }
  .filter-strip { margin-top: 5px; }
}

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

/* MAP-NEXT-2: searchable regions + filtered station card list */
.region-row {
  grid-template-columns: auto minmax(0, .9fr) minmax(0, 1.1fr);
}
.region-search {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--separator);
  border-radius: 11px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}
.region-search::placeholder { color: var(--muted); font-weight: 600; }

.station-list-panel {
  position: absolute;
  z-index: 36;
  left: 10px;
  right: 72px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  padding: 10px;
  border: 1px solid var(--separator);
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}
.station-list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 2px 8px;
}
.station-list-header strong { font-size: 13px; }
.station-list-more { color: var(--muted); font-size: 11px; white-space: nowrap; }
.station-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.station-list::-webkit-scrollbar { display: none; }
.station-list-card {
  flex: 0 0 min(280px, 82vw);
  display: grid;
  gap: 4px;
  padding: 10px 11px;
  border: 1px solid var(--separator);
  border-left: 4px solid var(--unknown);
  border-radius: 15px;
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  scroll-snap-align: start;
}
.station-list-card[data-state="available"] { border-left-color: var(--success); }
.station-list-card[data-state="likely"] { border-left-color: var(--warning); }
.station-list-card[data-state="unavailable"] { border-left-color: var(--danger); }
.station-list-name { font-size: 13px; font-weight: 900; line-height: 1.2; }
.station-list-address { color: var(--muted); font-size: 11px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.station-list-facts { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; font-size: 12px; }
.station-list-times { color: var(--muted); font-size: 10px; line-height: 1.2; }
.app-shell.has-station-list .map-actions { bottom: calc(132px + env(safe-area-inset-bottom)); }

.selected-fuel-focus {
  margin: 0 0 12px;
  padding: 11px;
  border: 1px solid var(--separator);
  border-left: 4px solid var(--unknown);
  border-radius: 16px;
  background: var(--bg);
}
.selected-fuel-focus[data-state="available"] { border-left-color: var(--success); }
.selected-fuel-focus[data-state="likely"] { border-left-color: var(--warning); }
.selected-fuel-focus[data-state="unavailable"] { border-left-color: var(--danger); }
.selected-fuel-title { margin-bottom: 8px; font-size: 13px; font-weight: 900; }
.selected-fuel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.selected-fuel-grid span { display: grid; gap: 2px; }
.selected-fuel-grid small { color: var(--muted); font-size: 10px; }
.selected-fuel-grid b { font-size: 12px; }
.fuel-price-time { margin-top: 4px; color: var(--muted); font-size: 9px; line-height: 1.2; }

@media (min-width: 720px) {
  .station-list-panel { width: 520px; right: auto; }
}

@media (max-width: 560px) {
  .region-row { grid-template-columns: 1fr 1fr; }
  .region-label { grid-column: 1 / -1; }
  .station-list-panel { right: 64px; }
}

/* Бесплатный Yandex Tiles API: собственные маркеры поверх официальной подложки. */
.yandex-tiles-logo {
  display: none;
  position: absolute;
  z-index: 35;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(6px, env(safe-area-inset-bottom));
  width: 88px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
}
.yandex-tiles-logo img { display: block; width: 88px; height: 48px; }
html[data-map-provider="yandex_tiles"] .yandex-tiles-logo { display: block; }
html[data-map-provider="yandex_tiles"] .app-shell.has-station-list .yandex-tiles-logo {
  bottom: calc(132px + env(safe-area-inset-bottom));
}

.autobot-leaflet-marker-wrap,
.autobot-leaflet-cluster-wrap { background: transparent; border: 0; }
.autobot-leaflet-marker,
.autobot-leaflet-cluster {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border: 3px solid #fff;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  box-shadow: 0 3px 10px rgba(0,0,0,.32);
}
.autobot-leaflet-marker { background: var(--marker-color, var(--unknown)); }
.autobot-leaflet-cluster { background: #1769aa; font-size: 12px; }
.leaflet-control-zoom { margin-top: 160px !important; }
.leaflet-control-zoom a { color: #111 !important; }

@media (max-width: 560px) {
  .yandex-tiles-logo { transform: scale(.84); transform-origin: bottom left; }
}
