:root {
  --card: #ffffff;
  --ink: #10202b;
  --muted: #6b7c8a;
  --line: #e6ebf0;
  --accent: #ff8a00;
  --accent-ink: #1a1204;
  --ok: #12a150;
  --ok-bg: #e7f7ee;
  --bad: #e5484d;
  --bad-bg: #fdecec;
  --warn-ink: #b25e00;
  --warn-bg: #fff4e5;
  --a: #2f7ef0;
  --b: #12a150;
  --field: #f7f9fb;
  --field-focus: #ffffff;
  --soft: #f2f5f8;
  --hover: #eef4ff;
  --track: #e9eef3;
  --grip: #d3dbe2;
  --map-bg: #aad3df;
}

[data-theme="dark"] {
  --card: #141414;
  --ink: #ececec;
  --muted: #9a9a9a;
  --line: #2c2c2c;
  --accent: #ff9a1f;
  --accent-ink: #1a1204;
  --ok: #34d399;
  --ok-bg: #10281c;
  --bad: #f87171;
  --bad-bg: #2e1a1a;
  --warn-ink: #fbbf24;
  --warn-bg: #2b230e;
  --a: #60a5fa;
  --b: #34d399;
  --field: #1d1d1d;
  --field-focus: #232323;
  --soft: #202020;
  --hover: #262626;
  --track: #2a2a2a;
  --grip: #3c3c3c;
  --map-bg: #0a0a0a;
}

/* Тёмная карта: инвертируем светлые тайлы OSM — подписи остаются русскими. */
[data-theme="dark"] .leaflet-tile {
  filter: invert(100%) hue-rotate(180deg) brightness(90%) contrast(88%) saturate(60%);
}
[data-theme="dark"] .leaflet-control-zoom a {
  background: var(--card); color: var(--ink); border-color: var(--line);
}
[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(20,20,20,.7); color: var(--muted);
}
[data-theme="dark"] .leaflet-control-attribution a { color: var(--muted); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; color: var(--ink);
  /* без резинового скролла страницы — иначе на iOS шторка «уезжает» вместе с ней */
  overscroll-behavior: none; }
button, a, input, select { touch-action: manipulation; }
#map { position: fixed; inset: 0; background: var(--map-bg); z-index: 0; }

/* Панель */
.sheet {
  position: fixed; z-index: 500; left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.28);
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  /* dvh следует за реальной высотой экрана (адресная строка мобильных
     браузеров), vh — фолбэк для старых движков */
  max-height: 82vh; max-height: 82dvh;
  overflow-y: auto; overscroll-behavior: contain;
  transition: transform .28s ease;
  will-change: transform;
}
.sheet.collapsed { transform: translateY(calc(100% - 148px - env(safe-area-inset-bottom, 0px))); }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--grip); margin: 4px auto 10px; cursor: grab; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.theme-btn {
  margin-left: auto; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--line); border-radius: 50%; background: var(--soft);
  font-size: 17px; cursor: pointer; line-height: 1;
}
.logo { font-size: 30px; line-height: 1; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: -.2px; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* Поля адресов */
.field { position: relative; display: flex; align-items: center; margin-bottom: 10px; }
.dot { width: 11px; height: 11px; border-radius: 50%; margin-right: 10px; flex: none; box-shadow: 0 0 0 3px rgba(0,0,0,.05); }
.dot-a { background: var(--a); }
.dot-b { background: var(--b); }
.field input {
  flex: 1; padding: 13px 14px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.field input:focus {
  outline: none; border-color: var(--a); background: var(--field-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--a) 22%, transparent);
}
.geo-btn {
  position: absolute; right: 6px; width: 36px; height: 36px; flex: none;
  border: none; border-radius: 10px; background: transparent; font-size: 17px;
  cursor: pointer; line-height: 1;
}
.geo-btn:hover { background: var(--hover); }
.field input#from { padding-right: 46px; }

.suggest {
  position: absolute; z-index: 20; top: 50px; left: 21px; right: 0;
  list-style: none; margin: 0; padding: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15,23,32,.15); max-height: 220px; overflow-y: auto;
}
.suggest li { padding: 10px 12px; font-size: 13px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.suggest li:hover, .suggest li.active { background: var(--hover); }
.suggest li.sg-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .4px; cursor: default; }
.suggest li.sg-title:hover { background: none; }

/* Заезды по пути */
.dot-via { background: var(--accent); }
.via-del {
  position: absolute; right: 6px; width: 32px; height: 32px; flex: none;
  border: none; border-radius: 10px; background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer; line-height: 1;
}
.via-del:hover { background: var(--hover); }
.via-field input { padding-right: 42px; }
.via-add {
  display: block; margin: -2px 0 10px; padding: 4px 2px;
  border: none; background: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--a);
}
.via-add:hover { text-decoration: underline; }

/* Недавние маршруты */
.recent-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -2px 0 10px; }
.recent-chips button {
  padding: 7px 11px; font-size: 12px; font-weight: 600; cursor: pointer;
  background: var(--soft); border: 1px solid var(--line); border-radius: 999px; color: var(--ink);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.recent-chips button:hover { background: var(--hover); }

/* Профиль машины */
.section-toggle {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; margin: 4px 0 10px; font-size: 14px; font-weight: 600;
  background: var(--soft); border: none; border-radius: 12px; cursor: pointer; color: var(--ink);
}
.chev { color: var(--muted); }
.section-body { margin-bottom: 8px; }

.row { display: flex; gap: 10px; }
.row label { flex: 1; }
label { display: block; font-size: 12px; color: var(--muted); margin: 6px 0; }
input[type=number], select {
  width: 100%; padding: 11px 12px; font-size: 15px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; background: var(--field); margin-top: 4px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type=number]:focus, select:focus {
  outline: none; border-color: var(--a); background: var(--field-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--a) 22%, transparent);
}

/* Топливо */
.fuel-field { background: var(--field); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 6px 0 14px; }
.fuel-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.fuel-head b { font-size: 18px; color: var(--ink); }
input[type=range] { width: 100%; margin: 10px 0 6px; accent-color: var(--accent); }

/* CTA */
.cta {
  width: 100%; padding: 15px; font-size: 16px; font-weight: 700; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .1s ease, box-shadow .15s ease, filter .15s ease;
}
.cta:hover { filter: brightness(1.05); }
.cta:active { transform: translateY(1px); box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent); }
.cta:disabled { opacity: .7; cursor: default; }
.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(0,0,0,.25); border-top-color: var(--accent-ink);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Результат */
#result { margin-top: 14px; }
.banner { border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; font-weight: 600; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner .big { font-size: 17px; }
.banner .small { font-weight: 500; font-size: 13px; opacity: .9; margin-top: 2px; }

.gauge { margin: 12px 0; }
.gauge-track { position: relative; height: 12px; border-radius: 6px; background: var(--track); overflow: hidden; }
.gauge-fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; }
.gauge-fill.ok { background: var(--ok); }
.gauge-fill.bad { background: var(--bad); }
.gauge-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.stat { flex: 1 1 45%; background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .v { font-size: 17px; font-weight: 700; }
.stat .k { font-size: 11px; color: var(--muted); }

.stops-title { font-size: 13px; font-weight: 700; margin: 14px 0 6px; }
.stop { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.stop-num { width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.stop-name { font-size: 14px; font-weight: 600; }
.stop-meta { font-size: 12px; color: var(--muted); }
.note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.seo-footer { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.seo-footer a { display: inline-block; font-size: 12px; color: var(--muted); margin: 0 12px 6px 0; }
.warn { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 8px; }
.warn.restriction { border: 1px solid var(--bad); font-size: 14px; line-height: 1.5; margin-bottom: 12px; }

/* Панель станции */
.station-sheet {
  position: fixed; z-index: 600; left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.35);
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 75vh; max-height: 75dvh;
  overflow-y: auto; overscroll-behavior: contain;
}
.ss-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.ss-title { flex: 1; min-width: 0; }
.ss-name { font-size: 18px; font-weight: 800; }
.ss-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ss-close {
  width: 34px; height: 34px; flex: none; border: none; border-radius: 50%;
  background: var(--soft); color: var(--muted); font-size: 15px; cursor: pointer;
}
.ss-status { border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-weight: 600; }
.ss-status .st-big { font-size: 17px; }
.ss-status .st-small { font-weight: 500; font-size: 12px; opacity: .85; margin-top: 2px; }
.ss-status.st-yes { background: var(--ok-bg); color: var(--ok); }
.ss-status.st-none { background: var(--bad-bg); color: var(--bad); }
.ss-status.st-queue, .ss-status.st-low { background: var(--warn-bg); color: var(--warn-ink); }
.ss-status.st-unknown { background: var(--soft); color: var(--muted); }
.ss-status.st-limit { background: #f3e8ff; color: #7c3aed; }
.ss-status.st-b2b { background: #e0f2fe; color: #0369a1; }
[data-theme="dark"] .ss-status.st-limit { background: #2a1f3d; color: #c084fc; }
[data-theme="dark"] .ss-status.st-b2b { background: #0c2a3a; color: #7dd3fc; }

.ss-ask { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.ss-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.ss-grid button {
  padding: 14px 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  background: var(--field); border: 1px solid var(--line); border-radius: 12px; color: var(--ink);
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.ss-grid button:hover { background: var(--hover); border-color: var(--grip); }
.ss-grid button:active { transform: scale(.98); }
.ss-grid button:disabled { opacity: .5; }
.ss-thanks { text-align: center; color: var(--ok); font-size: 13px; font-weight: 600; padding: 6px 0; }

.queue-ask { background: var(--warn-bg); border-radius: 12px; padding: 12px 14px; margin: 8px 0; }
.qa-title { font-size: 13px; font-weight: 700; color: var(--warn-ink); margin-bottom: 8px; }
.qa-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.qa-chips button {
  flex: 1 1 auto; padding: 10px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; color: var(--ink);
}

.ss-nav {
  display: block; text-align: center; margin: 10px 0 4px; padding: 13px;
  background: var(--soft); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); font-size: 14px; font-weight: 600; text-decoration: none;
  transition: background .15s ease;
}
.ss-nav:hover { background: var(--hover); }

.share-row {
  display: block; width: 100%; text-align: center; margin-top: 10px; padding: 12px;
  background: var(--soft); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer;
}
.share-row:hover { background: var(--hover); }

.ss-recent-title { font-size: 13px; font-weight: 700; margin: 12px 0 4px; }
.ss-recent .mark-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.ss-recent .mark-st { font-weight: 600; }
.ss-recent .mark-st.st-yes { color: var(--ok); }
.ss-recent .mark-st.st-none { color: var(--bad); }
.ss-recent .mark-st.st-queue, .ss-recent .mark-st.st-low { color: var(--warn-ink); }
.ss-recent .mark-st.st-limit { color: #a855f7; }
.ss-recent .mark-st.st-b2b { color: #0ea5e9; }
.ss-recent .mark-time { color: var(--muted); }
.ss-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

@media (min-width: 720px) {
  .station-sheet { left: 412px; right: auto; bottom: 16px; width: 360px; border-radius: 20px; }
}

/* Маркеры карты */
.num-marker { background: var(--accent); color: var(--accent-ink); border: 2px solid #fff;
  border-radius: 50%; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.pt-marker { border: 2px solid #fff; border-radius: 50%; width: 20px; height: 20px; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.st-cluster {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--a); color: #fff; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
[data-theme="dark"] .st-cluster { border-color: #2c2c2c; }
[data-theme="dark"] .leaflet-control-scale-line {
  background: rgba(20,20,20,.7); color: var(--muted); border-color: var(--line);
}
.pt-a { background: var(--a); }
.pt-b { background: var(--b); }
.pt-via { background: var(--accent); }
.poi-marker {
  width: 24px; height: 24px; border-radius: 50%; font-size: 13px; line-height: 1;
  background: var(--card); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

@media (min-width: 720px) {
  .sheet { left: 16px; right: auto; bottom: 16px; top: 16px; width: 380px; border-radius: 20px; max-height: none; }
  .sheet.collapsed { transform: none; }
  .grip { display: none; }
}
