:root {
  --bg: #0B1220;
  --panel: #0F1829;
  --card: #16213A;
  --card2: #1C2946;
  --line: rgba(255, 255, 255, .07);
  --text: #EAF1FF;
  --muted: #8C9CB9;
  --dim: #5F6F8E;
  --accent: #2D8CFF;
  --accent2: #5AA7FF;
  --green: #30D158;
  --orange: #FF9F0A;
  --red: #FF453A;
  --r: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 15px/1.35 var(--font); overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; color: var(--text); }
/* иконки интерфейса; SVG-слой Leaflet внутри #map не трогаем */
:is(.topbar, .map-ctrls, .sheet, .modal, .login) svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:is(.topbar, .map-ctrls, .sheet, .modal, .login) svg .fill { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- карта ---------- */
#map { position: fixed; inset: 0; background: #1a2336; }
.leaflet-container { font: inherit; background: #1a2336; }
.leaflet-control-attribution { background: rgba(11, 18, 32, .55) !important; color: #9fb0cc !important; font-size: 9px !important; border-radius: 6px 0 0 0; }
.leaflet-control-attribution a { color: #bcd !important; }
.leaflet-bottom { bottom: var(--sheet-h, 0px); transition: bottom .25s; }
.dark-tiles .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.7); }

/* ---------- верхняя панель ---------- */
.topbar {
  position: fixed; z-index: 500; top: 0; left: 0; right: 0;
  padding: calc(var(--safe-t) + 8px) 14px 22px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, rgba(11, 18, 32, .92) 0%, rgba(11, 18, 32, .6) 60%, rgba(11, 18, 32, 0) 100%);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { font-weight: 700; font-size: 19px; letter-spacing: .2px; display: flex; align-items: center; gap: 9px; }
.brand-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(45, 140, 255, .25); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  background: rgba(22, 33, 58, .88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); color: var(--text);
}
.icon-btn.ghost { background: var(--card); }
.icon-btn:active, .fab:active { transform: scale(.94); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.map-ctrls {
  position: fixed; z-index: 450; right: 12px;
  bottom: calc(var(--sheet-h, 0px) + 12px); transition: bottom .25s;
  display: flex; flex-direction: column; gap: 10px;
}
.fab {
  width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center;
  background: rgba(15, 24, 41, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); color: var(--text); box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}
.fab.on { color: var(--accent2); }

/* ---------- маркеры ---------- */
.pin { position: relative; width: 52px; height: 64px; }
.pin-body {
  position: absolute; left: 4px; top: 0; width: 44px; height: 44px; border-radius: 50%;
  background: var(--c); display: grid; place-items: center; box-shadow: 0 6px 16px rgba(0, 0, 0, .45);
  border: 3px solid #fff;
}
.pin-body::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; margin-left: -7px;
  border: 7px solid transparent; border-top: 9px solid #fff; border-bottom: 0;
}
.pin-ava { color: #fff; font-weight: 700; font-size: 17px; }
.pin-pulse {
  position: absolute; left: 50%; top: 50px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%;
  background: var(--c); opacity: .9;
}
.pin.fresh .pin-pulse::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--c);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse { from { transform: scale(.4); opacity: .9; } to { transform: scale(1.6); opacity: 0; } }
.pin-label {
  position: absolute; left: 50%; top: -30px; transform: translateX(-50%); white-space: nowrap;
  background: rgba(11, 18, 32, .9); color: #fff; font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .1);
}
.pin-label span { color: var(--muted); font-weight: 500; }
.pin.sel .pin-body { transform: scale(1.1); }

.stop-mark {
  width: 24px; height: 24px; border-radius: 8px; background: #fff; color: #0B1220; border: 2px solid var(--c);
  display: grid; place-items: center; font-size: 12px; font-weight: 800; box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.stop-mark.hl { background: var(--c); color: #fff; transform: scale(1.2); }
.end-mark { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 4px solid var(--c); box-shadow: 0 1px 6px rgba(0, 0, 0, .4); }

/* ---------- нижняя шторка ---------- */
.sheet {
  position: fixed; z-index: 600; left: 0; right: 0; bottom: 0;
  height: calc(100% - var(--safe-t) - 64px);
  background: var(--panel); border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .45); border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  transform: translateY(calc(100% - var(--peek, 300px)));
  transition: transform .32s cubic-bezier(.2, .8, .2, 1);
  will-change: transform; max-width: 720px; margin: 0 auto;
}
.sheet.dragging { transition: none; }
.sheet[data-state="full"] { transform: translateY(0); }
.sheet-drag { padding: 9px 0 4px; flex: none; touch-action: none; cursor: grab; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .22); margin: 0 auto; }
.sheet-body { flex: 1; overflow: hidden; padding: 0 14px calc(var(--safe-b) + 18px); overscroll-behavior: contain; }
.sheet[data-state="full"] .sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.drag-zone { touch-action: none; }

/* обзор */
.ov-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 12px; }
.ov-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.pill { font-size: 12.5px; padding: 6px 10px; border-radius: 20px; background: var(--card); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill b { color: var(--text); font-weight: 600; }

.mcard {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; margin-bottom: 10px; border-radius: var(--r);
  background: linear-gradient(180deg, var(--card2), var(--card)); border: 1px solid var(--line);
}
.mcard:active { transform: scale(.985); }
.ava {
  --c: var(--accent); flex: none; width: 48px; height: 48px; border-radius: 50%; position: relative;
  display: grid; place-items: center; font-weight: 700; font-size: 18px; color: #fff; background: var(--c);
  box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--c);
}
.ava.sm { width: 40px; height: 40px; font-size: 16px; }
.ava .dot { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--panel); background: var(--dim); }
.dot.stop { background: var(--green); }
.dot.move { background: var(--accent); }
.mcard-main { flex: 1; min-width: 0; }
.mcard-name { font-weight: 700; font-size: 16.5px; }
.mcard-addr { color: var(--text); opacity: .86; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.mcard-st { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.mcard-side { text-align: right; flex: none; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.batt { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--text); font-size: 13px; }
.batt-i { width: 22px; height: 11px; border: 1.6px solid currentColor; border-radius: 3px; position: relative; padding: 1px; opacity: .9; }
.batt-i::after { content: ""; position: absolute; right: -4px; top: 2.5px; width: 2px; height: 4px; background: currentColor; border-radius: 0 1px 1px 0; }
.batt-i i { display: block; height: 100%; border-radius: 1px; background: var(--green); }
.batt.low .batt-i i { background: var(--red); }
.batt.mid .batt-i i { background: var(--orange); }

.hint-card { padding: 14px; border-radius: var(--r); background: rgba(45, 140, 255, .1); border: 1px solid rgba(45, 140, 255, .25); font-size: 13.5px; color: #cfe2ff; margin-bottom: 10px; }
.hint-card b { color: #fff; }

/* карточка человека */
.mhead { display: flex; align-items: center; gap: 12px; padding: 4px 0 12px; }
.back { width: 36px; height: 36px; border-radius: 12px; background: var(--card); display: grid; place-items: center; flex: none; border: 1px solid var(--line); }
.mhead-main { flex: 1; min-width: 0; }
.mhead-name { font-size: 20px; font-weight: 700; line-height: 1.15; }
.mhead-st { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.mhead-st .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); display: inline-block; }
.clock { flex: none; text-align: right; }
.clock b { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock span { font-size: 11.5px; color: var(--muted); }

.addr { padding: 12px 14px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line); margin-bottom: 10px; display: flex; gap: 11px; align-items: center; }
.addr svg { color: var(--accent2); flex: none; }
.addr-t { font-weight: 600; font-size: 15px; }
.addr-s { color: var(--muted); font-size: 12.5px; margin-top: 1px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 15px; padding: 10px 6px 9px; text-align: center; min-width: 0; }
.tile-v { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tile-k { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.tile-i { height: 20px; display: grid; place-items: center; margin-bottom: 4px; color: var(--accent2); }
.tile-i svg { width: 19px; height: 19px; }
.tile.warn .tile-v { color: var(--orange); }
.tile.bad .tile-v { color: var(--red); }

.sec-title { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 2px 9px; }
.sec-title h3 { margin: 0; font-size: 17px; }
.sec-title span { font-size: 12px; color: var(--muted); }

.periods { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; margin: 0 -14px 12px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.periods::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 13px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-size: 13.5px; font-weight: 600; color: var(--muted); }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.custom { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.custom label { font-size: 11.5px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.custom input { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; min-width: 0; width: 100%; color-scheme: dark; font-size: 14px; }
.custom .btn { grid-column: 1 / -1; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.sum { background: linear-gradient(180deg, var(--card2), var(--card)); border: 1px solid var(--line); border-radius: 15px; padding: 11px 12px; }
.sum b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.sum span { font-size: 11.5px; color: var(--muted); }

.day-h { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 16px 2px 8px; }
.tl { list-style: none; margin: 0; padding: 0; }
.ev { display: flex; gap: 12px; padding: 11px 12px; border-radius: 15px; background: var(--card); border: 1px solid var(--line); margin-bottom: 8px; width: 100%; text-align: left; align-items: center; }
.ev.hl { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ev-i { flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.ev.stop .ev-i { background: rgba(48, 209, 88, .14); color: var(--green); }
.ev.trip .ev-i { background: rgba(45, 140, 255, .15); color: var(--accent2); }
.ev-i svg { width: 19px; height: 19px; }
.ev-m { flex: 1; min-width: 0; }
.ev-t { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-s { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.ev-r { flex: none; text-align: right; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ev-r span { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.now-tag { color: var(--green); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; font-size: 14px; }
.skeleton { height: 58px; border-radius: 15px; background: linear-gradient(90deg, var(--card) 0%, var(--card2) 50%, var(--card) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; margin-bottom: 8px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- кнопки, модалка, вход ---------- */
.btn { padding: 12px 16px; border-radius: 14px; background: var(--card2); border: 1px solid var(--line); font-weight: 600; font-size: 15px; text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.wide { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 13.5px; border-radius: 11px; }
.btn:active { opacity: .85; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.modal { position: fixed; inset: 0; z-index: 900; background: rgba(4, 8, 16, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: flex; align-items: flex-end; justify-content: center; }
.modal-card { width: 100%; max-width: 560px; max-height: calc(100% - var(--safe-t) - 20px); background: var(--panel); border-radius: 24px 24px 0 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); animation: up .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(40%); opacity: .4; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.modal-head h2 { margin: 0; font-size: 21px; }
.modal-body { overflow-y: auto; padding: 4px 16px calc(var(--safe-b) + 22px); -webkit-overflow-scrolling: touch; }
.set-sec { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.set-sec h4 { margin: 0 0 10px; font-size: 15px; }
.set-sec p { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.set-sec p b { color: var(--text); }
.set-sec ol { margin: 0 0 12px; padding-left: 20px; font-size: 13.5px; color: #c9d5ea; }
.set-sec ol li { margin-bottom: 7px; }
.field { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.field .ava { box-shadow: none; }
.field input { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.seg { display: flex; background: var(--panel); border-radius: 12px; padding: 3px; border: 1px solid var(--line); }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--card2); color: var(--text); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.switch input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: #2a3654; position: relative; flex: none; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(20px); }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin-bottom: 12px; padding: 9px 11px; border-radius: 12px; background: var(--panel); }
.status-line .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.opt { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.opt-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.opt ol { margin-bottom: 10px; }
.linkbox { font-size: 12px; word-break: break-all; color: var(--muted); background: var(--panel); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; font-family: ui-monospace, Menlo, monospace; }

.login { position: fixed; inset: 0; z-index: 1000; background: radial-gradient(120% 80% at 50% 0%, #16264a 0%, var(--bg) 60%); display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 12px 40px rgba(45, 140, 255, .35); }
.login h1 { margin: 16px 0 6px; font-size: 30px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login input { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; text-align: center; }
.login .small { margin-top: 14px; }

.toast { position: fixed; z-index: 1100; left: 50%; top: calc(var(--safe-t) + 64px); transform: translateX(-50%); background: rgba(22, 33, 58, .96); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; font-size: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4); max-width: calc(100% - 32px); text-align: center; }

@media (min-width: 760px) {
  .sheet { left: 16px; right: auto; width: 400px; bottom: 16px; height: auto; top: calc(var(--safe-t) + 72px); border-radius: 24px; transform: none !important; border: 1px solid var(--line); }
  .sheet-drag { display: none; }
  .sheet .sheet-body { overflow-y: auto; padding-top: 14px; }
  .map-ctrls { bottom: 24px !important; }
  .leaflet-bottom { bottom: 0 !important; }
}
