:root {
  --bg: #ffffff;
  --text: #15171a;
  --hint: #6b7280;
  --card: #f1f3f5;
  --sep: rgba(0, 0, 0, 0.08);
  --accent: #2481cc;
  --accent-text: #ffffff;
  --sale: #e53935;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  --top-h: 100px;
  --sheet-h: 40vh;
  --panel-w: 400px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17212b; --text: #f5f5f5; --hint: #8b9aa8; --card: #232e3c; --sep: rgba(255, 255, 255, 0.08);
    --accent: #5aa7e6; --accent-text: #ffffff; --sale: #ff6b6b; --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17212b; --text: #f5f5f5; --hint: #8b9aa8; --card: #232e3c; --sep: rgba(255, 255, 255, 0.08);
  --accent: #5aa7e6; --accent-text: #ffffff; --sale: #ff6b6b; --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- карта ---------- */
#map { position: fixed; left: 0; right: 0; top: 0; bottom: var(--sheet-h); background: var(--card); transition: bottom 0.22s ease; }
.leaflet-container { font: inherit; background: var(--card); }
.dark-tiles .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.6); }
.leaflet-control-attribution { font-size: 10px; background: rgba(255, 255, 255, 0.75) !important; }
[data-theme="dark"] .leaflet-control-attribution { background: rgba(23, 33, 43, 0.8) !important; color: var(--hint); }
[data-theme="dark"] .leaflet-control-attribution a { color: var(--accent); }
.leaflet-tooltip.shop-tip {
  background: var(--bg); color: var(--text); border: 0; box-shadow: var(--shadow); border-radius: 8px; padding: 4px 8px; font-size: 13px;
}
.leaflet-tooltip.shop-tip::before { display: none; }

/* ---------- верх: город, поиск, сети ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  padding: calc(8px + env(safe-area-inset-top)) 10px 4px;
  background: var(--bg); box-shadow: 0 1px 0 var(--sep), 0 4px 14px rgba(0, 0, 0, 0.06);
}
.bar { display: flex; gap: 8px; }
.city { position: relative; flex: 0 0 auto; }
.city select {
  appearance: none; -webkit-appearance: none; height: 42px; max-width: 132px; padding: 0 28px 0 12px;
  border: 0; border-radius: 12px; background: var(--card); color: var(--text); font: inherit; font-weight: 600;
  box-shadow: 0 1px 0 var(--sep);
}
.city::after { content: "▾"; position: absolute; right: 11px; top: 11px; color: var(--hint); pointer-events: none; }
.search { position: relative; flex: 1 1 auto; min-width: 0; }
.search svg { position: absolute; left: 11px; top: 12px; width: 18px; height: 18px; fill: none; stroke: var(--hint); stroke-width: 2.2; stroke-linecap: round; }
.search input {
  width: 100%; height: 42px; padding: 0 36px 0 36px; border: 0; border-radius: 12px; background: var(--card);
  color: var(--text); font: inherit; outline: none; box-shadow: 0 1px 0 var(--sep);
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { box-shadow: 0 0 0 2px var(--accent); }
.clear { position: absolute; right: 4px; top: 5px; width: 32px; height: 32px; border: 0; background: none; color: var(--hint); font-size: 22px; line-height: 1; }

.chips { display: flex; gap: 6px; padding: 8px 0 6px; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 0; border-radius: 17px; background: var(--card); color: var(--text); font-size: 13.5px; white-space: nowrap;
  box-shadow: 0 1px 0 var(--sep); transition: background 0.15s, color 0.15s;
}
.chip.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip .n { color: inherit; opacity: 0.65; font-variant-numeric: tabular-nums; font-weight: 400; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, #999); flex: 0 0 auto; box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.9); }

/* ---------- слайдер: лента листается пальцем, стрелки и тень по краям показывают, что дальше есть ещё ---------- */
.rail { position: relative; }
.track {
  overflow-x: auto; scrollbar-width: none;
  overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; touch-action: pan-x;
}
.track::-webkit-scrollbar { display: none; }
.rail::before, .rail::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 60px; z-index: 1; pointer-events: none; opacity: 0; transition: opacity 0.18s;
}
.rail::before { left: 0; background: linear-gradient(to right, var(--bg) 55%, transparent); }
.rail::after { right: 0; background: linear-gradient(to left, var(--bg) 55%, transparent); }
.rail.can-l::before, .rail.can-r::after { opacity: 1; }
.arrow {
  position: absolute; top: 50%; z-index: 2; width: 30px; height: 30px; margin-top: -15px; padding: 0;
  border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-text); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity 0.18s;
}
.arrow svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.arrow.l { left: 0; }
.arrow.r { right: 0; }
.rail.can-l .arrow.l, .rail.can-r .arrow.r { opacity: 1; pointer-events: auto; }
.rail.hint .arrow.r { animation: nudge 0.9s ease-in-out 4; }
@keyframes nudge { 50% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .rail.hint .arrow.r { animation: none; } }

/* ---------- кнопка «рядом со мной» ---------- */
.fab {
  position: fixed; right: 12px; bottom: calc(var(--sheet-h) + 26px); z-index: 1000; width: 46px; height: 46px;
  border: 0; border-radius: 50%; background: var(--bg); box-shadow: var(--shadow); display: grid; place-items: center;
  transition: bottom 0.22s ease;
}
.fab svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; }
.fab.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- нижняя шторка со списком ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--sheet-h); z-index: 1001; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.16);
  transition: height 0.22s ease; padding-bottom: env(safe-area-inset-bottom);
}
.handle { flex: 0 0 auto; height: 22px; border: 0; background: none; display: grid; place-items: center; }
.handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--sep); box-shadow: inset 0 0 0 10px rgba(127, 127, 127, 0.35); }
.head { flex: 0 0 auto; padding: 0 14px 8px; border-bottom: 1px solid var(--sep); }
.head h1 { margin: 0; font-size: 17px; line-height: 1.3; display: flex; align-items: center; gap: 8px; }
.head .sub { margin-top: 3px; color: var(--hint); font-size: 13px; }
.head .actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.head .actions a, .head .actions button {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 10px; border: 0;
  background: var(--card); color: var(--text); text-decoration: none; font-size: 14px;
}
.head .actions .primary { background: var(--accent); color: var(--accent-text); }
.back { border: 0; background: none; color: var(--accent); padding: 0 0 4px; font-size: 14px; }
.head .rail { margin-top: 8px; }
.cats { display: flex; gap: 6px; }
.cats .chip { height: 32px; font-size: 13px; }

.list { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.section { padding: 10px 14px 4px; color: var(--hint); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.offer, .shop {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center; width: 100%;
  padding: 9px 14px; border: 0; border-bottom: 1px solid var(--sep); background: none; text-align: left;
}
.offer:active, .shop:active { background: var(--card); }
.ph { width: 52px; height: 52px; border-radius: 10px; background: var(--card) center/cover no-repeat; display: grid; place-items: center; font-size: 24px; overflow: hidden; }
.ph img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.info { min-width: 0; }
.name { font-weight: 600; font-size: 14.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meta { display: block; margin-top: 2px; color: var(--hint); font-size: 12.5px; }
.meta .dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; vertical-align: 0; }
.info { display: block; }
.price { text-align: right; white-space: nowrap; }
.price b { display: block; font-size: 16px; }
.price s { display: block; color: var(--hint); font-size: 12.5px; }
.badge { display: inline-block; margin-top: 2px; padding: 1px 6px; border-radius: 6px; background: var(--sale); color: #fff; font-size: 12px; font-weight: 700; }
.badge.best { background: var(--card); color: var(--hint); font-weight: 600; }
.shop { grid-template-columns: 14px 1fr auto; }
.shop .dot { width: 12px; height: 12px; }
.shop .km { color: var(--hint); font-size: 13px; text-align: right; }
.more { display: block; width: calc(100% - 28px); margin: 12px 14px; height: 40px; border: 0; border-radius: 10px; background: var(--card); color: var(--accent); font-weight: 600; }
.empty { padding: 18px 16px; color: var(--hint); }
.empty b { color: var(--text); }
.note { padding: 14px 16px 22px; color: var(--hint); font-size: 12px; }
.note a { color: var(--hint); }

.toast {
  position: fixed; left: 50%; top: calc(var(--top-h) + 6px); transform: translateX(-50%); z-index: 1100; max-width: calc(100% - 32px);
  padding: 9px 14px; border-radius: 12px; background: rgba(20, 20, 20, 0.88); color: #fff; font-size: 14px; box-shadow: var(--shadow);
}

/* ---------- компьютер: список слева, карта справа ---------- */
@media (min-width: 860px) {
  .top { right: auto; width: var(--panel-w); box-shadow: none; border-right: 1px solid var(--sep); }
  #chains { flex-wrap: wrap; overflow: visible; } /* на компьютере все сети видны сразу, листать не надо */
  .chip { height: 32px; }
  #map { left: var(--panel-w); bottom: 0 !important; }
  .sheet { top: var(--top-h); right: auto; width: var(--panel-w); height: auto !important; border-radius: 0; box-shadow: none; border-right: 1px solid var(--sep); }
  .handle { display: none; }
  .head { padding-top: 10px; }
  .fab { bottom: 30px !important; right: 18px; }
  .toast { left: calc(var(--panel-w) + (100% - var(--panel-w)) / 2); }
}
