/* ── Veturilo Hunter ──────────────────────────────────────────
   Темна тема, скляні поверхні, акцент — кислотний лайм (гроші)
   і малиновий (бренд Veturilo). */

:root {
  --bg:        #0b0e14;
  --surface:   #141924;
  --surface-2: #1b2231;
  --line:      rgba(255,255,255,.09);
  --line-soft: rgba(255,255,255,.055);

  --text:      #eef2f8;
  --text-dim:  #98a3b6;
  --text-mute: #67718a;

  --accent:    #ff2d6f;   /* бренд */
  --accent-2:  #ff6a3d;
  --money:     #3ddc97;   /* прибуток */
  --money-dim: rgba(61,220,151,.14);
  --warn:      #ffb84d;
  --elec:      #6ea8ff;

  --radius:    18px;
  --radius-sm: 13px;

  --shadow:    0 14px 40px rgba(0,0,0,.45);
  --ease:      cubic-bezier(.22,1,.36,1);
  --spring:    cubic-bezier(.34,1.4,.5,1);

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* висота вікна — JS перезаписує (Telegram viewport / iOS URL bar) */
  --app-h: 100dvh;
}

@media (prefers-color-scheme: light) {
  /* застосунок навмисно завжди темний: карта вночі читається краще,
     а Telegram Mini App і так частіше відкривають у темі. */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { position: fixed; inset: 0; width: 100%; }

button, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }

/* ── карта ─────────────────────────────────────────────────── */

#map {
  position: absolute;
  inset: 0;
  height: var(--app-h);
  background: #0b0e14;
  z-index: 0;
}
.leaflet-container { background: #0b0e14; font: inherit; outline: none; }
.leaflet-control-attribution {
  background: rgba(11,14,20,.7) !important;
  color: var(--text-mute) !important;
  font-size: 9px !important;
  padding: 1px 6px !important;
  backdrop-filter: blur(6px);
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-control-zoom { display: none; }
.leaflet-tile-pane { filter: saturate(.75) contrast(1.02); }

/* ── маркери ───────────────────────────────────────────────── */

.mk { will-change: transform; }

.mk-bike {
  width: 34px; height: 34px;
  border-radius: 50% 50% 50% 6px;
  transform: rotate(-45deg);
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  box-shadow: 0 5px 14px rgba(255,45,111,.42), 0 0 0 2px rgba(11,14,20,.85);
  animation: drop .45s var(--spring) backwards;
}
.mk-bike.is-elec { background: linear-gradient(150deg, #4f7ffd, #6ea8ff);
  box-shadow: 0 5px 14px rgba(110,168,255,.42), 0 0 0 2px rgba(11,14,20,.85); }
.mk-bike span {
  transform: rotate(45deg);
  font-size: 11px; font-weight: 800; color: #fff; letter-spacing: -.02em;
}
.mk-bike.is-active { animation: pop .5s var(--spring); z-index: 900; }

@keyframes drop {
  from { opacity: 0; transform: rotate(-45deg) translate(6px,-16px) scale(.5); }
  to   { opacity: 1; transform: rotate(-45deg) translate(0,0) scale(1); }
}
@keyframes pop {
  0%   { transform: rotate(-45deg) scale(1); }
  45%  { transform: rotate(-45deg) scale(1.32); }
  100% { transform: rotate(-45deg) scale(1); }
}

.mk-station {
  width: 15px; height: 15px; border-radius: 5px;
  background: rgba(61,220,151,.9);
  border: 2px solid rgba(11,14,20,.9);
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  transition: transform .25s var(--spring);
}
.mk-station.is-target { transform: scale(1.5); background: var(--money); }

.mk-me { position: relative; width: 22px; height: 22px; }
.mk-me i {
  position: absolute; inset: 4px;
  border-radius: 50%;
  background: #4f9bff;
  border: 2.5px solid #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
}
.mk-me::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 50%; background: rgba(79,155,255,.45);
  animation: ping 2.4s cubic-bezier(0,.5,.4,1) infinite;
}
@keyframes ping {
  0%   { transform: scale(.6); opacity: .75; }
  70%  { transform: scale(2.8); opacity: 0; }
  100% { transform: scale(2.8); opacity: 0; }
}

.route-line { animation: dash 1.6s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -24; } }

/* ── верхня панель ─────────────────────────────────────────── */

.topbar {
  position: absolute; z-index: 400;
  top: calc(var(--safe-top) + 10px); left: 12px; right: 12px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  animation: fadeDown .5s var(--ease) both;
}
@keyframes fadeDown { from { opacity: 0; transform: translateY(-10px); } }

.brand {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 13px 7px 10px;
  border-radius: 999px;
  background: rgba(20,25,36,.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(255,45,111,.6);
  animation: beat 2.6s ease-out infinite;
}
@keyframes beat {
  0%   { box-shadow: 0 0 0 0 rgba(255,45,111,.55); }
  60%  { box-shadow: 0 0 0 9px rgba(255,45,111,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,45,111,0); }
}
.brand-text { font-size: 13.5px; font-weight: 700; letter-spacing: -.01em; }

.icon-btn {
  pointer-events: auto;
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text);
  background: rgba(20,25,36,.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  transition: transform .18s var(--spring), background .2s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.is-busy svg { animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-pill {
  position: absolute; z-index: 400;
  top: calc(var(--safe-top) + 58px); left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: rgba(20,25,36,.85);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: fadeDown .35s var(--ease) both;
}
.status-pill.is-warn { color: var(--warn); border-color: rgba(255,184,77,.3); }

/* ── FAB ───────────────────────────────────────────────────── */

.fabs {
  position: absolute; z-index: 400;
  right: 12px;
  display: flex; flex-direction: column; gap: 10px;
  transition: bottom .28s var(--ease), opacity .2s linear;
  bottom: 0; /* JS */
}
.fab {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 16px;
  color: var(--text);
  background: rgba(20,25,36,.8);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: var(--shadow);
  transition: transform .18s var(--spring), color .2s, background .2s;
}
.fab:active { transform: scale(.9); }
.fab.is-on { color: #fff; background: linear-gradient(150deg, var(--accent), var(--accent-2)); border-color: transparent; }
.fab.is-busy svg { animation: spin .9s linear infinite; }
.fab-ghost { width: 40px; height: 40px; border-radius: 14px; margin-left: 3px; color: var(--text-dim); }

/* ── ручний пін ────────────────────────────────────────────── */

.pin-mode { position: absolute; inset: 0; z-index: 600; pointer-events: none; }
.pin-crosshair {
  position: absolute; left: 50%; top: 38%;
  transform: translate(-50%, -100%);
  animation: pinIn .4s var(--spring) both;
}
@keyframes pinIn { from { opacity: 0; transform: translate(-50%,-140%) scale(.6); } }
.pin-crosshair-shape {
  width: 30px; height: 30px;
  border-radius: 50% 50% 50% 6px;
  transform: rotate(-45deg);
  background: linear-gradient(150deg, #fff, #d8dfec);
  box-shadow: 0 6px 18px rgba(0,0,0,.55);
  animation: hover 1.9s ease-in-out infinite;
}
@keyframes hover {
  0%,100% { transform: rotate(-45deg) translateY(0); }
  50%     { transform: rotate(-45deg) translateY(-5px); }
}
.pin-crosshair-shadow {
  width: 14px; height: 5px; margin: 6px auto 0;
  border-radius: 50%; background: rgba(0,0,0,.45); filter: blur(2px);
}
.pin-actions {
  pointer-events: auto;
  position: absolute; left: 12px; right: 12px;
  bottom: calc(var(--safe-bottom) + 20px);
  display: flex; gap: 10px;
  animation: fadeUp .35s var(--ease) both;
}
.pin-actions .btn { flex: 1; }

/* ── кнопки ────────────────────────────────────────────────── */

.btn {
  padding: 13px 18px;
  border-radius: 14px;
  font-size: 15px; font-weight: 650;
  transition: transform .16s var(--spring), opacity .2s;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(255,45,111,.32);
}
.btn-ghost {
  color: var(--text);
  background: rgba(27,34,49,.9);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ── шторка ────────────────────────────────────────────────── */

.sheet {
  position: absolute; z-index: 500;
  left: 0; right: 0; bottom: 0;
  height: 88%;
  max-height: calc(var(--app-h) - var(--safe-top) - 56px);
  display: flex; flex-direction: column;
  border-radius: 22px 22px 0 0;
  background: linear-gradient(180deg, rgba(23,29,42,.97), rgba(15,19,28,.99));
  border-top: 1px solid var(--line);
  box-shadow: 0 -18px 50px rgba(0,0,0,.5);
  backdrop-filter: blur(24px) saturate(1.5);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  transform: translateY(100%);
  will-change: transform;
  touch-action: none;
}
.sheet.is-animating { transition: transform .42s var(--ease); }

.sheet-grab { padding: 8px 16px 12px; flex: none; cursor: grab; user-select: none; }
.sheet-grab:active { cursor: grabbing; }
.grabber {
  width: 38px; height: 4.5px; margin: 0 auto 11px;
  border-radius: 3px; background: rgba(255,255,255,.22);
}
.sheet-head { display: flex; align-items: flex-start; gap: 12px; }
.sheet-head-main { flex: 1; min-width: 0; }
.sheet-head h1 {
  margin: 0; font-size: 18px; font-weight: 750; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sheet-head p {
  margin: 3px 0 0; font-size: 12.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.chip-btn {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 620; color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  transition: transform .16s var(--spring), color .2s, background .2s;
}
.chip-btn:active { transform: scale(.94); }
.chip-btn.is-on { color: #fff; background: rgba(255,45,111,.18); border-color: rgba(255,45,111,.4); }
.badge {
  min-width: 17px; height: 17px; padding: 0 4px;
  display: grid; place-items: center;
  border-radius: 999px; background: var(--accent);
  font-size: 10.5px; font-weight: 800; color: #fff;
}

.sheet-body {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 12px calc(var(--safe-bottom) + 20px);
  touch-action: pan-y;
}

/* ── фільтри ───────────────────────────────────────────────── */

.filters {
  margin: 4px 4px 14px;
  padding: 14px 14px 6px;
  border-radius: var(--radius);
  background: rgba(255,255,255,.035);
  border: 1px solid var(--line-soft);
  animation: expand .32s var(--ease) both;
}
@keyframes expand { from { opacity: 0; transform: translateY(-8px); } }

.field { display: block; margin-bottom: 12px; }
.field-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: var(--text-dim); margin-bottom: 8px;
}
.field-label b { color: var(--text); font-size: 13.5px; font-variant-numeric: tabular-nums; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--fill,40%), rgba(255,255,255,.13) var(--fill,40%));
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  transition: transform .15s var(--spring);
}
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.22); }
input[type=range]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 0;
}

.toggles { display: flex; flex-direction: column; }
.toggle {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line-soft);
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui {
  flex: none; position: relative;
  width: 44px; height: 26px; border-radius: 999px;
  background: rgba(255,255,255,.13);
  transition: background .25s var(--ease);
}
.toggle-ui::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.35);
  transition: transform .28s var(--spring);
}
.toggle input:checked + .toggle-ui { background: var(--accent); }
.toggle input:checked + .toggle-ui::after { transform: translateX(18px); }
.toggle-text { font-size: 14px; font-weight: 560; }
.toggle-text small { display: block; font-size: 11.5px; font-weight: 400; color: var(--text-mute); margin-top: 1px; }

/* ── список ────────────────────────────────────────────────── */

.list { display: flex; flex-direction: column; gap: 10px; padding: 2px 2px 4px; }

.card {
  position: relative;
  padding: 13px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  overflow: hidden;
  animation: cardIn .42s var(--ease) both;
  transition: transform .18s var(--spring), border-color .2s, background .2s;
}
.card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--money); opacity: .8;
}
.card.is-loss::before { background: var(--text-mute); }
.card.is-elec::before { background: var(--elec); }
.card:active { transform: scale(.985); }
.card.is-active { border-color: rgba(255,45,111,.5); background: var(--surface-2); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
}

.card-top { display: flex; align-items: flex-start; gap: 10px; }
.card-rank {
  flex: none; width: 24px; height: 24px; margin-top: 1px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  font-size: 12px; font-weight: 800; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.card-rank.is-top { background: linear-gradient(140deg, var(--accent), var(--accent-2)); color: #fff; }
.card-id { flex: 1; min-width: 0; }
.card-id h3 {
  margin: 0; font-size: 15.5px; font-weight: 700; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
}
.tag {
  padding: 2px 7px; border-radius: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  background: rgba(255,255,255,.07); color: var(--text-dim);
}
.tag.is-elec { background: rgba(110,168,255,.16); color: var(--elec); }
/* заряд і запас ходу — це дані, а не підпис: без капсу й з табличними цифрами */
.tag.is-batt { text-transform: none; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.tag.is-zone { background: var(--money-dim); color: var(--money); }
.tag.is-warn { background: rgba(255,184,77,.15); color: var(--warn); }

.card-net {
  flex: none; text-align: right;
  font-size: 17px; font-weight: 800; letter-spacing: -.02em;
  color: var(--money); font-variant-numeric: tabular-nums;
}
.card-net.is-loss { color: var(--text-mute); }
.card-net small { display: block; font-size: 10.5px; font-weight: 600; color: var(--text-mute); letter-spacing: 0; }

.card-legs {
  display: flex; align-items: center; gap: 8px;
  margin: 11px 0 0; padding-top: 11px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px; color: var(--text-dim);
}
.leg { display: flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.leg b { color: var(--text); font-weight: 650; }
.leg-arrow { color: var(--text-mute); flex: none; }
.leg-total { margin-left: auto; color: var(--text-mute); }

.card-dest {
  margin-top: 9px;
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-dim);
}
.card-dest svg { flex: none; color: var(--money); }
.card-dest b { color: var(--text); font-weight: 620;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-dest span { flex: none; color: var(--text-mute); }

/* дії розкриваються лише на обраній картці — так у списку видно більше варіантів */
/* запасна станція: підказка на випадок, якщо основну заб'ють,
   доки їдеш — показуємо тільки на розгорнутій картці */
.card-alt {
  max-height: 0; opacity: 0; overflow: hidden;
  margin-top: 0; padding-left: 21px;
  font-size: 11.5px; color: var(--text-mute);
  transition: max-height .34s var(--ease), opacity .22s var(--ease), margin-top .34s var(--ease);
}
.card.is-active .card-alt { max-height: 34px; opacity: 1; margin-top: 5px; }

.card-actions {
  display: flex; gap: 8px;
  max-height: 0; margin-top: 0; opacity: 0;
  overflow: hidden;
  transition: max-height .34s var(--ease), opacity .22s var(--ease), margin-top .34s var(--ease);
}
.card.is-active .card-actions { max-height: 64px; margin-top: 11px; opacity: 1; }
.act {
  flex: 1;
  padding: 9px 10px;
  border-radius: 11px;
  font-size: 13px; font-weight: 620;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line-soft);
  color: var(--text);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .16s var(--spring), background .2s;
}
.act:active { transform: scale(.95); background: rgba(255,255,255,.1); }
.act-go { background: rgba(255,45,111,.16); border-color: rgba(255,45,111,.3); }

/* ── порожньо / скелетони ──────────────────────────────────── */

.empty { padding: 34px 20px 26px; text-align: center; animation: fadeUp .4s var(--ease) both; }
.empty-emoji { font-size: 40px; margin-bottom: 10px; animation: hover 3s ease-in-out infinite; }
.empty p { margin: 0 0 16px; color: var(--text-dim); font-size: 14px; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } }

.skeleton {
  height: 104px; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 240% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.sheet-foot {
  margin-top: 16px; padding: 0 4px;
  font-size: 11px; color: var(--text-mute);
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
}

/* ── тост ──────────────────────────────────────────────────── */

.toast {
  position: absolute; z-index: 900;
  left: 50%; bottom: calc(var(--safe-bottom) + 26px);
  transform: translate(-50%, 12px);
  max-width: min(88vw, 380px);
  padding: 11px 18px; border-radius: 14px;
  font-size: 13.5px; font-weight: 560; text-align: center;
  background: rgba(28,35,50,.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  transition: opacity .28s var(--ease), transform .28s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ── доступність ───────────────────────────────────────────── */

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