:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --border: rgba(11,11,11,0.10);
  --bus: #2a78d6;
  --trol: #eb6834;
  --tram: #1baf7a;
  --stalled: #b3b1aa;
  --alert-bg: #d03b3b;
}
html, body {
  margin: 0; height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}
#map { position: absolute; inset: 0; }

/* Баннеры */
.banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1200;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  font-size: 13px; font-weight: 600; text-align: center;
  color: #fff; background: var(--alert-bg);
}
.banner.stale { background: #52514e; font-weight: 400; }
.hidden { display: none !important; }

/* Легенда */
.panel {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px;
  z-index: 1000;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  color: var(--text-primary); font-size: 12px;
}
body.has-alert .panel { top: calc(44px + env(safe-area-inset-top)); }
.legend-row { display: flex; align-items: center; gap: 7px; margin: 2px 0; }
.legend-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  border: 2px solid var(--surface-1); box-shadow: 0 0 0 1px var(--border);
}
.legend-count { margin-left: auto; padding-left: 10px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* Маркеры транспорта */
.veh-icon {
  background: transparent; border: none;
  /* плавное скольжение к новой GPS-позиции между обновлениями;
     top/left — для webview без 3D-transform (десктопный Telegram) */
  transition: transform 4s linear, top 4s linear, left 4s linear;
}
/* во время зума/анимации карты переход отключается, иначе маркеры «плывут» */
.leaflet-zoom-anim .veh-icon,
.map-moving .veh-icon { transition: none; }
.veh-marker { display: flex; align-items: center; gap: 3px; }
.veh-marker .dot {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 2px solid var(--surface-1);
  box-shadow: 0 0 0 1px rgba(11,11,11,0.15);
  box-sizing: border-box;
}
.veh-marker.moving .dot { width: 14px; height: 14px; }
.veh-marker .num {
  font-size: 10px; font-weight: 600; color: var(--text-primary);
  background: var(--surface-1); border-radius: 4px; padding: 0 3px;
  box-shadow: 0 0 0 1px var(--border); white-space: nowrap; line-height: 14px;
}
.veh-marker.stalled .num { color: var(--muted); }
.veh-marker.selected .dot { box-shadow: 0 0 0 3px rgba(42,120,214,0.45); }

/* Bottom sheet маршрута */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1100;
  background: var(--surface-1); border-top: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
  max-height: 45%; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-header {
  display: flex; align-items: center; padding: 10px 14px 6px;
}
.sheet-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.sheet-close {
  margin-left: auto; border: none; background: none; font-size: 16px;
  color: var(--text-secondary); padding: 4px 8px; cursor: pointer;
}
.sheet-tabs { display: flex; gap: 6px; padding: 0 14px 8px; }
.sheet-tabs button {
  flex: 1; padding: 6px; font-size: 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-1); color: var(--text-secondary);
}
.sheet-tabs button.active {
  color: var(--text-primary); font-weight: 600;
  border-color: var(--text-secondary);
}
.stop-list {
  overflow-y: auto; margin: 0; padding: 0 14px 12px 34px;
  font-size: 13px; color: var(--text-primary);
}
.stop-list li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.stop-list li:last-child { border-bottom: none; }

/* Toast */
.toast {
  position: absolute; bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 1300; background: rgba(11,11,11,0.85); color: #fff;
  font-size: 13px; padding: 8px 14px; border-radius: 8px;
  pointer-events: none; white-space: nowrap;
}

/* Кнопка меню */
#menu-btn {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 10px;
  z-index: 1000; width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary);
  font-size: 18px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
body.has-alert #menu-btn { top: calc(44px + env(safe-area-inset-top)); }

/* Тумблер неактивного транспорта */
#inactive-btn {
  position: absolute; top: calc(58px + env(safe-area-inset-top)); left: 10px;
  z-index: 1000; width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); font-size: 17px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
body.has-alert #inactive-btn { top: calc(92px + env(safe-area-inset-top)); }
#inactive-btn.off { opacity: 0.55; }

/* Призраки: транспорт без связи */
.veh-marker.ghost { opacity: 0.45; }
.legend-dot.ghost-dot {
  background: transparent; border: 2px dashed var(--muted);
  box-shadow: none;
}

/* Боковое меню */
.drawer {
  position: absolute; top: 0; left: 0; bottom: 0; z-index: 1500;
  width: min(320px, 85vw);
  background: var(--surface-1); border-right: 1px solid var(--border);
  box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  overflow-y: auto;
}
#drawer-backdrop {
  position: absolute; inset: 0; z-index: 1400;
  background: rgba(0,0,0,0.3);
}
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; font-size: 15px; font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}
.drawer-group { border-bottom: 1px solid var(--border); }
.drawer-group-title {
  display: block; width: 100%; text-align: left;
  padding: 12px 14px; font-size: 14px; font-weight: 600;
  border: none; background: none; color: var(--text-primary); cursor: pointer;
}
.drawer-group-body { padding: 0 6px 10px; }
#stop-search {
  width: calc(100% - 16px); margin: 0 8px 8px; padding: 7px 10px;
  font-size: 13px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-1); color: var(--text-primary);
  box-sizing: border-box;
}
.drawer-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; font-size: 13px; color: var(--text-primary);
  cursor: pointer; border-radius: 6px;
}
.drawer-item:hover { background: rgba(11,11,11,0.04); }
.drawer-item .routes-chips {
  margin-left: auto; color: var(--muted); font-size: 11px;
  max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.drawer-section {
  padding: 8px 10px 3px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
}
.drawer-subsection {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 10px; font-size: 13px; font-weight: 600;
  border: none; background: none; color: var(--text-primary);
  cursor: pointer; text-align: left;
}
.drawer-subsection .cnt { font-weight: 400; color: var(--muted); font-size: 12px; }
.drawer-subsection .chev { margin-left: auto; color: var(--muted); }
#route-search {
  width: calc(100% - 16px); margin: 0 8px 8px; padding: 7px 10px;
  font-size: 13px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-1); color: var(--text-primary);
  box-sizing: border-box;
}

/* Панель остановки */
.sheet-sub {
  padding: 0 14px 6px; font-size: 12px; color: var(--text-secondary);
}
.passage-list {
  overflow-y: auto; padding: 0 14px 12px; font-size: 13px;
}
.passage-route {
  border-bottom: 1px solid var(--border); padding: 8px 0;
}
.passage-route:last-child { border-bottom: none; }
.passage-route-head {
  display: flex; align-items: center; gap: 8px; font-weight: 600;
  color: var(--text-primary);
}
.passage-route-head .dir {
  font-weight: 400; font-size: 12px; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.passage-route-head .cnt {
  margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted);
}
.passage-times {
  margin-top: 4px; color: var(--text-secondary);
  font-variant-numeric: tabular-nums; line-height: 1.6;
}
.passage-empty { padding: 14px; color: var(--muted); font-size: 13px; }

/* Планировщик */
#plan-from, #plan-to {
  width: calc(100% - 16px); margin: 4px 8px; padding: 7px 10px;
  font-size: 13px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-1); color: var(--text-primary);
  box-sizing: border-box;
}
#plan-from-list, #plan-to-list { max-height: 150px; overflow-y: auto; }
.plan-btn {
  display: block; width: calc(100% - 16px); margin: 8px;
  padding: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
  border: none; border-radius: 6px;
  background: var(--bus); color: #fff;
}
.plan-btn:disabled { background: var(--stalled); cursor: default; }
.plan-option { cursor: pointer; }
.plan-option:hover { background: rgba(11,11,11,0.03); }
.plan-times { margin-top: 3px; font-size: 12px; color: var(--text-secondary); }
.plan-times b { color: var(--text-primary); }
