:root {
  color-scheme: dark;
  /* Тёмная приглушённая тема (Linear/Vercel-style, без неона) */
  --bg: #0e1116;           /* фон приложения */
  --panel: #161a22;        /* сайдбар/шторка, карточки */
  --panel-2: #1c212b;      /* вложенные поверхности */
  --line: #272d38;         /* границы */
  --line-2: #353c4a;       /* границы поярче */

  --text: #e8ecf3;         /* основной текст */
  --muted: #98a2b3;        /* вторичный текст */
  --muted-2: #6b7482;      /* третичный / плейсхолдеры */

  --primary: #cbd3e0;      /* светлый slate (интерактив на тёмном) */
  --accent: #33c07f;       /* приглушённый изумруд — «свободно / есть топливо» */
  --accent-ink: #52d197;   /* зелёный для текста на тёмном фоне */
  --accent-2: #6ea6ff;     /* стальной синий — выбор / интерактив */
  --amber: #e0a94b;        /* приглушённый янтарный — «есть очередь» */
  --amber-ink: #edc178;
  --red: #e0736b;          /* приглушённый терракот — «большая очередь» */
  --red-ink: #f0948d;
  --gray: #6b7482;         /* «нет топлива» */

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 12px 32px rgba(0, 0, 0, .5);
  --radius: 14px;
  --peek: 150px;           /* высота «выглядывающей» шторки на мобилке */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Табличные цифры для числовых данных — цены/очереди не «прыгают» */
.stat-value, .fuel-badge, .price-cell .pv, .queue-pill, .best-time b, .card-addr {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* Видимый фокус для клавиатуры */
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 8px; }
.chip:focus-visible, .card:focus-visible, .btn:focus-visible { outline-offset: 3px; }

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

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center; color: #06210f;
  background: var(--accent);
}
.brand-logo svg { width: 24px; height: 24px; }
.brand-text h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.brand-text p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }

.topbar-stats { display: flex; gap: 10px; }
.stat {
  min-width: 108px; padding: 10px 16px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.stat-value { font-size: 19px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Controls ---------- */
.controls {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 16px 32px; flex-wrap: wrap;
}
.fuel-filter { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 15px; border-radius: 999px; cursor: pointer; user-select: none;
  background: var(--panel); border: 1px solid var(--line-2);
  font-size: 13px; font-weight: 500; color: var(--muted);
  transition: all .18s ease;
}
.chip:hover { border-color: var(--primary); color: var(--text); }
.chip.active {
  background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 600;
}
.control-right { display: flex; align-items: center; gap: 18px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch input { display: none; }
.switch-track {
  width: 38px; height: 22px; border-radius: 999px; background: var(--line-2);
  position: relative; transition: background .2s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: .2s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.sort-select {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 8px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
  font-family: inherit;
}

/* ---------- Layout ---------- */
.layout {
  flex: 1; display: grid; grid-template-columns: 404px 1fr; gap: 16px;
  min-height: 0; padding: 4px 32px 32px;
}
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
.list-head { padding: 16px 20px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.list-head span { color: var(--text); font-weight: 600; }
.station-list { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Station card ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
  position: relative;
}
.card:hover { border-color: var(--line-2); box-shadow: var(--shadow); transform: translateY(-1px); }
.card:active { transform: translateY(0) scale(.992); }
.card.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; opacity: .9; }
.card-brand { font-weight: 600; font-size: 15px; color: var(--text); }
.card-addr { font-size: 12px; color: var(--muted); margin-left: auto; text-align: right; max-width: 165px; }
.fuel-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 13px; }
.fuel-badge {
  font-size: 11px; font-weight: 500; padding: 4px 8px; border-radius: 7px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  display: flex; gap: 5px; align-items: baseline;
}
.fuel-badge .price { color: var(--text); font-weight: 600; }
.fuel-badge.out { color: var(--muted-2); border-style: dashed; text-decoration: line-through; opacity: .7; }
.card-foot { display: flex; align-items: center; gap: 12px; }
.queue-pill {
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px; display: flex; align-items: center; gap: 6px;
}
.queue-pill i { width: 7px; height: 7px; border-radius: 50%; }
.q-green { background: rgba(21, 154, 99, .10); color: var(--accent-ink); }
.q-green i { background: var(--accent); }
.q-amber { background: rgba(192, 138, 46, .12); color: var(--amber-ink); }
.q-amber i { background: var(--amber); }
.q-red { background: rgba(194, 91, 82, .12); color: var(--red-ink); }
.q-red i { background: var(--red); }
.mini-load { display: flex; align-items: flex-end; gap: 2px; height: 26px; margin-left: auto; }
.mini-load span { width: 4px; border-radius: 2px 2px 0 0; background: var(--line-2); }
.mini-load span.now { background: var(--accent-2); }

/* ---------- Map ---------- */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
#map { position: absolute; inset: 0; background: #0b0e13; }
.legend {
  position: absolute; bottom: 16px; left: 16px; z-index: 500;
  background: rgba(18, 22, 30, .9); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 9px 14px; display: flex; gap: 16px; font-size: 12px; color: var(--muted);
  backdrop-filter: blur(6px); box-shadow: var(--shadow-sm);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--accent); } .dot-amber { background: var(--amber); }
.dot-red { background: var(--red); } .dot-gray { background: var(--gray); }

/* Маркер-«капля» */
.marker {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(15, 23, 42, .28); position: relative;
}
.marker::after {
  content: ""; position: absolute; inset: 7px; border-radius: 50%; background: rgba(255, 255, 255, .92);
}
.marker.sel { transform: rotate(-45deg) scale(1.22); z-index: 1000 !important; box-shadow: 0 4px 12px rgba(15, 23, 42, .35); }

/* ---------- Detail panel ---------- */
.detail-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 1400;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.detail-backdrop.show { opacity: 1; pointer-events: auto; }
.detail {
  position: fixed; top: 0; right: 0; height: 100%; width: 420px; max-width: 92vw; z-index: 1500;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -16px 0 40px rgba(15, 23, 42, .12);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  overflow-y: auto; padding: 0;
}
.detail.show { transform: translateX(0); }
.detail-hero { padding: 24px; border-bottom: 1px solid var(--line); position: relative; }
.detail-close {
  position: absolute; top: 18px; right: 18px; width: 34px; height: 34px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); cursor: pointer;
  display: grid; place-items: center; transition: color .15s, border-color .15s;
}
.detail-close:hover { border-color: var(--red); color: var(--red); }
.detail-brand { display: flex; align-items: center; gap: 12px; }
.detail-brand .brand-dot { width: 12px; height: 12px; }
.detail-brand h2 { margin: 0; font-size: 21px; font-weight: 700; color: var(--text); }
.detail-addr { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.detail-updated { font-size: 12px; color: var(--muted); margin-top: 12px; display: flex; align-items: center; gap: 6px; }
.detail-updated .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(21, 154, 99, .5); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(21, 154, 99, .4); } 70% { box-shadow: 0 0 0 7px rgba(21, 154, 99, 0); } 100% { box-shadow: 0 0 0 0 rgba(21, 154, 99, 0); } }

.detail-section { padding: 22px 24px; border-bottom: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 14px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.price-cell {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.price-cell.out { opacity: .55; }
.price-cell .ft { font-size: 12px; color: var(--muted); font-weight: 500; }
.price-cell .pv { font-size: 20px; font-weight: 700; color: var(--text); }
.price-cell .pv small { font-size: 12px; color: var(--muted); font-weight: 500; }
.price-cell.out .pv { font-size: 14px; color: var(--muted-2); }

/* График загруженности */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; margin-top: 6px; }
.bar { flex: 1; border-radius: 4px 4px 0 0; background: var(--line-2); position: relative; transition: height .3s; min-height: 3px; }
.bar.now { background: var(--accent-2); }
.bar:hover::after {
  content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: rgba(3, 6, 10, .94); color: var(--text); border: 1px solid var(--line);
  font-size: 10px; padding: 3px 6px; border-radius: 6px; white-space: nowrap; margin-bottom: 4px; z-index: 2;
}
.chart-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted-2); margin-top: 6px; }
.best-time { margin-top: 14px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.best-time b { color: var(--accent-ink); }

.detail-actions { padding: 22px 24px; display: flex; gap: 10px; }
.btn {
  flex: 1; text-align: center; padding: 12px; border-radius: 10px; font-weight: 600; font-size: 14px;
  cursor: pointer; border: 1px solid var(--line-2); text-decoration: none; color: var(--text); background: var(--panel);
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.btn.primary { background: var(--accent); border-color: transparent; color: #06210f; }
.btn.primary:hover { background: var(--accent-ink); }
.btn:hover { transform: translateY(-1px); border-color: var(--primary); }
.btn:active { transform: translateY(0) scale(.98); }

/* Мобильные элементы — по умолчанию скрыты (создаются из JS) */
.sheet-handle { display: none; }
.fab { display: none; }
/* Быстрый тап без 300мс задержки */
a, button, .chip, .card, .btn, .fab, .sheet-handle, .sort-select { touch-action: manipulation; }

/* ============ Мобайл / webview: карта на весь экран + нижняя шторка ============ */
@media (max-width: 900px) {
  body { overflow: hidden; }              /* скролл — только внутри шторки/детали */
  .topbar-stats { display: none; }

  /* Верхняя плашка — плавающий оверлей поверх карты */
  .topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1200; gap: 12px; border-bottom: none;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 12px;
    background: linear-gradient(180deg, rgba(14, 17, 22, .95) 45%, rgba(14, 17, 22, 0));
    backdrop-filter: blur(2px);
  }
  .brand-logo { width: 40px; height: 40px; }
  .brand-logo svg { width: 22px; height: 22px; }
  .brand-text h1 { font-size: 17px; }
  .brand-text p { display: none; }

  /* Карта — фон на весь экран */
  .layout { display: block; padding: 0; }
  .map-wrap { position: fixed; inset: 0; z-index: 1; border: none; border-radius: 0; box-shadow: none; }
  .leaflet-control-zoom { display: none !important; }   /* pinch-zoom */
  .leaflet-control-attribution { font-size: 9px; margin: 0 2px 2px 0; }
  .legend { display: none; }

  /* ── Шторка со списком ── */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100;
    height: 92dvh; border-radius: 20px 20px 0 0;
    border: 1px solid var(--line); border-bottom: none;
    box-shadow: 0 -10px 44px rgba(0, 0, 0, .6);
    transform: translateY(calc(100% - var(--peek)));
    transition: transform .34s cubic-bezier(.2, .85, .25, 1);
    will-change: transform; touch-action: none;
  }
  .sidebar.mid  { transform: translateY(46%); }
  .sidebar.full { transform: translateY(0); }
  .sidebar.dragging { transition: none; }

  .sheet-handle {
    display: flex; justify-content: center; align-items: center;
    padding: 10px 0 8px; cursor: grab; touch-action: none; flex: none;
  }
  .sheet-handle::before { content: ""; width: 42px; height: 5px; border-radius: 3px; background: var(--line-2); }

  /* Фильтры — шапка шторки; чипы горизонтально прокручиваются */
  .sidebar > .controls { flex-direction: column; align-items: stretch; gap: 10px; padding: 0 14px 12px; flex: none; }
  .fuel-filter {
    flex-wrap: nowrap; overflow-x: auto; gap: 8px; padding-bottom: 2px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-x;
  }
  .fuel-filter::-webkit-scrollbar { display: none; }
  .chip { flex: none; min-height: 38px; display: flex; align-items: center; }
  /* Фикс переполнения: тумблер не растёт, селект ужимается и не вылезает за экран */
  .control-right { justify-content: space-between; align-items: center; gap: 12px; flex-wrap: nowrap; }
  .control-right .switch { flex: 0 0 auto; min-width: 0; min-height: 40px; }
  .control-right .sort-select { flex: 1 1 auto; min-width: 0; min-height: 40px; }

  .list-head { flex: none; }
  .station-list {
    flex: 1; overscroll-behavior: contain; touch-action: pan-y;
    padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 24px);
  }
  .sidebar:not(.full) .station-list { overflow-y: hidden; }   /* прокрутка списка — только в раскрытой шторке */
  .card { padding: 15px 16px; }

  /* ── Деталь — нижний лист ── */
  .detail {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%; max-width: none; height: 90dvh;
    border-left: none; border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
    transform: translateY(100%); box-shadow: 0 -12px 48px rgba(0, 0, 0, .65);
  }
  .detail.show { transform: translateY(0); }
  .detail-hero::before {
    content: ""; display: block; width: 42px; height: 5px; border-radius: 3px;
    background: var(--line-2); margin: -8px auto 16px;
  }
  .detail-actions {
    position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  }
  .btn { min-height: 48px; display: flex; align-items: center; justify-content: center; }

  /* ── FAB «моё местоположение» ── */
  .fab {
    position: fixed; right: 14px; z-index: 1150;
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--peek) + 14px);
    width: 50px; height: 50px; border-radius: 15px; display: grid; place-items: center;
    background: var(--panel); border: 1px solid var(--line-2); color: var(--text);
    box-shadow: var(--shadow); cursor: pointer;
    transition: opacity .2s ease, transform .2s ease;
  }
  .fab:active { transform: scale(.94); }
  .fab.loading { opacity: .6; pointer-events: none; }
  /* когда список раскрыт (mid/full) — прячем, чтобы не перекрывал карточки */
  .fab.hidden { opacity: 0; transform: scale(.85) translateY(10px); pointer-events: none; }
  .fab svg { width: 22px; height: 22px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 2px solid var(--panel); }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ---------- Блок «Информация» (данные из OSM) ---------- */
.info-grid { display: flex; flex-direction: column; gap: 10px; }
.info-row {
  display: grid; grid-template-columns: 84px 1fr; align-items: baseline;
  gap: 12px; font-size: 14px;
}
.info-row .info-k {
  font-size: 12px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
}
.info-row .info-v { color: var(--text); word-break: break-word; }
.info-row .info-v a { color: var(--accent-2); text-decoration: none; }
.info-row .info-v a:hover { text-decoration: underline; }

/* ---------- Кластеры маркеров: тепловая шкала в тон цветам очереди ---------- */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background: transparent; }
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  font-family: "Inter", system-ui, sans-serif; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
  border: 2px solid rgba(255, 255, 255, .18);
}
.marker-cluster-small div  { background: var(--accent); color: #06210f; }  /* мало — зелёный */
.marker-cluster-medium div { background: var(--amber);  color: #241a00; }  /* средне — янтарь */
.marker-cluster-large div  { background: var(--red);    color: #fff; }     /* много — красный */
