/* МАЯК · map screen styles (filters / layers / clusters / scrubber / ruler) */

/* ─────────────────────────────────────────
   FILTER BAR — top of map
   ───────────────────────────────────────── */
.map-filters {
  position: absolute;
  top: 14px; left: 14px;
  right: 60px;                          /* clear the controls column on the right */
  display: flex; align-items: center; gap: 6px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-md);
  z-index: var(--z-panel);
  flex-wrap: wrap;
  width: max-content;
  max-width: calc(100% - 14px - 60px);
}
.map-filter-group {
  display: flex; align-items: center; gap: 2px;
  padding: 0 4px;
  position: relative;
}
.map-filter-group + .map-filter-group::before {
  content: ""; position: absolute; left: -1px; top: 4px; bottom: 4px;
  width: 1px; background: var(--line);
}
.map-filter-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 0 6px 0 2px;
}
.fchip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 9px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px; font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.fchip:hover { color: var(--fg); background: var(--bg-sub); }
.fchip.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent-line);
}
.fchip .mono-num {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: inherit;
  opacity: .7;
}

/* ─────────────────────────────────────────
   LAYERS POPOVER (anchored to map-controls)
   ───────────────────────────────────────── */
.map-controls .btn.icon.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent-line);
}
.layers-pop {
  position: absolute;
  right: 60px; top: 14px;
  width: 240px;
  padding: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-overlay);
}
.layers-pop h5 {
  margin: 0 0 8px;
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-family: var(--font-mono); font-weight: 500;
}
.layer-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 6px;
  border-radius: var(--r-2);
  cursor: pointer;
  transition: background var(--t-fast);
}
.layer-row:hover { background: var(--bg-sub); }
.layer-row input { accent-color: var(--accent); cursor: pointer; }
.layer-row-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.layer-row-name { font-size: 13px; color: var(--fg); font-weight: 500; }
.layer-row-sub { font-size: 11px; color: var(--muted-2); margin-top: 1px; }
.layer-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid var(--line-2);
}

/* ─────────────────────────────────────────
   GEOFENCES (SVG overlay)
   ───────────────────────────────────────── */
.gz-fill { opacity: 0.13; }
.gz-stroke { fill: none; stroke-width: 0.35; stroke-dasharray: 1 0.6; }
.gz-ops      .gz-fill { fill: var(--accent); } .gz-ops      .gz-stroke { stroke: var(--accent); }
.gz-watch    .gz-fill { fill: var(--warn); }    .gz-watch    .gz-stroke { stroke: var(--warn); }
.gz-restricted .gz-fill { fill: var(--danger); } .gz-restricted .gz-stroke { stroke: var(--danger); }
.gz-label {
  fill: var(--fg-2);
  font-family: var(--font-mono);
  font-size: 1.4px;
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 500;
}
.gz-label-bg {
  fill: var(--paper);
  opacity: .85;
}

/* ─────────────────────────────────────────
   HEATMAP
   ───────────────────────────────────────── */
.heatmap-blob {
  mix-blend-mode: multiply;
}
[data-theme="dark"] .heatmap-blob {
  mix-blend-mode: screen;
}

/* ─────────────────────────────────────────
   CLUSTER BUBBLES (zoom = out)
   ───────────────────────────────────────── */
.mk-cluster {
  position: absolute;
  transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper);
  border: 2px solid var(--accent);
  color: var(--fg);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  pointer-events: auto;
  transition: transform var(--t-fast);
}
.mk-cluster:hover { transform: translate(-50%, -50%) scale(1.08); }
.mk-cluster::after {
  content: "";
  position: absolute; inset: -6px;
  border: 1px dashed var(--accent);
  border-radius: 999px;
  opacity: .35;
}
.mk-cluster.has-alert { border-color: var(--danger); }
.mk-cluster.has-alert::after { border-color: var(--danger); opacity: .55; }

/* ─────────────────────────────────────────
   EVENT MARKERS along track
   ───────────────────────────────────────── */
.track-event {
  cursor: pointer;
}

/* ─────────────────────────────────────────
   TIME SCRUBBER (bottom)
   ───────────────────────────────────────── */
.scrubber {
  position: absolute;
  left: 14px;
  bottom: 14px;
  /* desktop wide: stretch to fill the gap between footer and marker card */
  width: clamp(320px, calc(100% - 28px - 480px), 640px);
  height: 88px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-md);
  z-index: 110;                          /* above marker-card on narrow shells */
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 8px 12px 6px;
}
.scrubber-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px;
}
.scrubber-head .callsign { font-weight: 600; color: var(--fg); }
.scrubber-head .now { color: var(--accent); font-family: var(--font-mono); }
.scrubber-actions { display: inline-flex; gap: 4px; }
.scrubber-actions .btn.icon { width: 24px; height: 24px; }

.scrubber-track {
  position: relative;
  height: 30px;
  margin: 0 2px;
}
.scrubber-rail {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 4px;
  background: var(--bg-sub);
  border-radius: 999px;
  transform: translateY(-50%);
  overflow: hidden;
}
.scrubber-rail-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg,
    color-mix(in oklch, var(--accent) 35%, transparent),
    color-mix(in oklch, var(--accent) 75%, transparent));
}
.scrubber-event {
  position: absolute;
  top: 50%; transform: translate(-50%, -50%);
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--muted-2);
  border: 1px solid var(--paper);
}
.scrubber-event.wake { background: var(--accent); }
.scrubber-event.stop { background: var(--warn); border-radius: 999px; }
.scrubber-event.session { background: var(--ok); }
.scrubber-event.geofence { background: var(--danger); transform: translate(-50%, -50%) rotate(45deg); }

.scrubber-handle {
  position: absolute;
  top: 50%; transform: translate(-50%, -50%);
  width: 16px; height: 24px;
  background: var(--accent);
  border-radius: 4px;
  cursor: grab;
  box-shadow: 0 1px 4px rgba(15, 20, 30, .25);
  display: flex; align-items: center; justify-content: center;
}
.scrubber-handle::after {
  content: ""; width: 2px; height: 12px;
  background: var(--accent-fg); border-radius: 1px;
  opacity: .55;
}
.scrubber-handle-label {
  position: absolute;
  bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  white-space: nowrap;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: var(--r-1);
  pointer-events: none;
}
.scrubber-input {
  position: absolute; inset: 0;
  -webkit-appearance: none; appearance: none;
  background: transparent; cursor: grab;
  margin: 0;
}
.scrubber-input::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 28px; background: transparent; cursor: grab;
}

.scrubber-ticks {
  display: flex; justify-content: space-between;
  font-family: var(--font-mono); font-size: 10px;
  color: var(--muted-2);
  padding: 0 1px;
}

/* ghost beacon at scrubbed-time position */
.mk-ghost {
  position: absolute;
  width: 22px; height: 22px;
  border-radius: 999px;
  border: 2px dashed var(--accent);
  background: var(--paper);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: .9;
}
.mk-ghost::after {
  content: ""; position: absolute; inset: 4px;
  background: var(--accent);
  border-radius: 999px;
  opacity: .7;
}

/* ─────────────────────────────────────────
   MAP FOOTER · scale bar + counters
   ───────────────────────────────────────── */
.map-footer {
  position: absolute;
  left: 14px; bottom: 14px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: var(--z-panel);
}
.scale-bar {
  display: inline-flex; align-items: flex-end; gap: 6px;
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 4px 8px;
  width: max-content;
}
.scale-bar-line {
  position: relative;
  height: 8px;
  border-left: 1.5px solid var(--fg-2);
  border-right: 1.5px solid var(--fg-2);
  border-bottom: 1.5px solid var(--fg-2);
}

.map-counters {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  font-size: 11.5px;
  width: max-content;
  max-width: 100%;
}
.map-counters .cnt {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 0 6px;
  border-right: 1px solid var(--line);
}
.map-counters .cnt:last-child { border-right: 0; }
.map-counters .cnt b { font-family: var(--font-mono); font-weight: 600; }

/* ─────────────────────────────────────────
   ZOOM PILL (in map-controls)
   ───────────────────────────────────────── */
.zoom-pill {
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--muted);
  text-align: center;
  padding: 2px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
  background: var(--bg-sub);
}

/* ─────────────────────────────────────────
   RULER
   ───────────────────────────────────────── */
.map-widget.ruler-on { cursor: crosshair; }
.ruler-pin {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--accent);
  border: 2px solid var(--paper);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(15, 20, 30, .35);
  pointer-events: none;
}
.ruler-line { stroke: var(--accent); stroke-width: 0.5; stroke-dasharray: 1.4 0.8; fill: none; }
.ruler-label {
  position: absolute;
  transform: translate(-50%, -120%);
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-mono); font-size: 11px;
  padding: 3px 7px;
  border-radius: var(--r-1);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

/* ─────────────────────────────────────────
   ZOOMED MAP SCALING
   ───────────────────────────────────────── */
.map-canvas {
  position: absolute; inset: 0;
  transform-origin: var(--map-origin-x, 50%) var(--map-origin-y, 50%);
  transform: scale(var(--map-scale, 1));
  transition: transform var(--t-med);
}

/* selected track */
.track-svg {
  position: absolute; inset: 0;
  pointer-events: none;
}
.track-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 0.55;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1.6 0.8;
  filter: drop-shadow(0 0 0.3px var(--accent));
  animation: track-flow 16s linear infinite;
}
@keyframes track-flow {
  to { stroke-dashoffset: -120; }
}
.track-line.dim { opacity: .35; }
.track-line.active {
  stroke-dasharray: none;
  stroke-width: 0.7;
  opacity: 1;
  animation: none;
}
.track-end {
  fill: var(--accent);
  stroke: var(--paper);
  stroke-width: 0.25;
}

/* ─────────────────────────────────────────
   STATEFUL TWEAKS — hide redundant chrome when scrubber up
   ───────────────────────────────────────── */
.map-widget[data-scrubber="on"] .map-coords { display: none; }
.map-widget[data-scrubber="on"] .map-footer { bottom: 116px; }

.map-widget[data-selected="on"] .map-filters {
  max-width: calc(100% - 14px - 60px - 480px);
}

/* ─────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────── */
@media (max-width: 1280px) {
  .scrubber { width: clamp(300px, calc(100% - 28px - 440px), 560px); }
}
@media (max-width: 1100px) {
  /* Narrow shells: marker card eats most of the right side; scrubber
     becomes self-contained and floats above the bottom of the card. */
  .scrubber { width: min(440px, calc(100% - 28px)); }
  .map-widget[data-selected="on"] .map-filters {
    max-width: calc(100% - 14px - 60px);
    right: 60px;
  }
  .map-counters { flex-wrap: wrap; max-width: 60vw; }
}
@media (max-width: 720px) {
  .map-filters { left: 8px; right: 8px; top: 8px; max-width: none; flex-wrap: wrap; }
  .map-widget[data-selected="on"] .map-filters { max-width: calc(100% - 16px); }
  .map-filter-group + .map-filter-group::before { display: none; }
  .scrubber { left: 8px; bottom: 8px; width: calc(100% - 16px); }
  .layers-pop { right: 8px; top: 56px; }
}

/* ─────────────────────────────────────────
   LEAFLET (реальная карта OSM) — задача 1
   ───────────────────────────────────────── */
.map-widget-leaflet { cursor: default; }
.map-leaflet {
  position: absolute; inset: 0;
  z-index: 0;                     /* локальный контекст наложения: панели leaflet
                                     не должны перекрывать marker-card/списки */
  background: var(--map-bg);
}
.map-leaflet .leaflet-container {
  background: var(--map-bg);
  font: inherit;
}

/* Тёмная тема для ВСЕХ leaflet-карт (главная карта + геозоны и пр.):
   растровые тайлы светлые — инвертируем только слой тайлов; маркеры, геозоны,
   треки лежат в других панах leaflet и остаются в своих цветах. */
:root[data-theme="dark"] .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9) saturate(0.85);
}
/* Фон контейнера и ещё НЕ загруженных тайлов — тёмный. Дефолт leaflet (#ddd)
   иначе виден как светло-серые квадраты на тёмной теме. */
:root[data-theme="dark"] .leaflet-container {
  background: #0b0e11;
}

/* divIcon-маркер маяка */
.leaflet-div-icon.lf-mk,
.leaflet-div-icon.lf-pel {
  background: transparent;
  border: 0;
}
.lf-mk-core {
  position: absolute; left: 50%; top: 50%;
  width: 12px; height: 12px;
  border-radius: 999px;
  border: 2px solid #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.lf-mk-sel .lf-mk-core { width: 14px; height: 14px; }
.lf-mk-ring {
  position: absolute; left: 50%; top: 50%;
  width: 22px; height: 22px;
  border-radius: 999px;
  border: 2px solid var(--accent);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, .22);
}
.lf-pel-core {
  position: absolute; left: 50%; top: 50%;
  width: 11px; height: 11px;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.lf-pel-sel .lf-pel-core { width: 13px; height: 13px; }
.lf-pel-ring {
  position: absolute; left: 50%; top: 50%;
  width: 24px; height: 24px;
  border-radius: 999px;
  border: 2px solid #a06bd6;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 3px rgba(160, 107, 214, .22);
}

/* мини-легенда (лево-низ) */
/* переключатель диапазона трека (верх-право, появляется при выборе) */
.map-track-range {
  position: absolute;
  right: 14px; top: 14px;
  z-index: 500;
  display: inline-flex; align-items: center; gap: 3px;
  padding: 4px 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-md);
}
.map-track-range .mtr-label {
  font-size: 11px; color: var(--muted); padding: 0 4px 0 2px;
}
.mtr-btn {
  border: 0; background: transparent; cursor: pointer;
  font-size: 11.5px; font-family: var(--font-mono);
  color: var(--muted); padding: 3px 7px; border-radius: var(--r-1);
  transition: background var(--t-fast), color var(--t-fast);
}
.mtr-btn:hover { background: var(--bg-sub); color: var(--text); }
.mtr-btn.active { background: var(--accent); color: #fff; }
@media (max-width: 640px) {
  .map-track-range { right: 8px; top: 8px; }
}

.map-legend {
  position: absolute;
  left: 14px; bottom: 14px;
  z-index: 500;
  display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 6px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-md);
  font-size: 11.5px;
  max-width: calc(100% - 28px);
}
.map-legend .cnt {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 0 6px;
  border-right: 1px solid var(--line);
}
.map-legend .cnt:last-child { border-right: 0; }
.map-legend .cnt b { font-family: var(--font-mono); font-weight: 600; }
.map-legend .dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; flex-shrink: 0; }

@media (max-width: 720px) {
  .map-legend { left: 8px; bottom: 8px; max-width: calc(100% - 16px); }
}

/* Регулятор прозрачности LBS-окружности */
.map-lbs-ctl {
  position: absolute;
  right: 14px; bottom: 14px;
  z-index: 500;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-md);
}
.map-lbs-ctl .mlbs-dot {
  width: 9px; height: 9px; border-radius: 999px; flex-shrink: 0;
  background: #f0a020; box-shadow: 0 0 0 3px rgba(240, 160, 32, 0.22);
}
.map-lbs-ctl .mlbs-label {
  font-size: 11px; color: var(--muted); font-family: var(--font-mono);
}
.map-lbs-ctl input[type="range"] { width: 92px; accent-color: #f0a020; cursor: pointer; }
@media (max-width: 720px) {
  .map-lbs-ctl { right: 8px; bottom: 8px; }
  .map-lbs-ctl input[type="range"] { width: 70px; }
}

/* ── скраббер трека (низ карты, только в режиме «Трек») ── */
.map-track-scrub {
  position: absolute;
  left: 14px; right: 14px; bottom: 14px;
  z-index: 500;
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-md);
}
.map-track-scrub .mts-range { flex: 1; min-width: 60px; accent-color: var(--accent); cursor: pointer; }
.map-track-scrub .mts-step {
  border: 0; background: var(--bg-sub); color: var(--text);
  width: 28px; height: 24px; border-radius: var(--r-1); cursor: pointer;
  font-size: 11px; line-height: 1; flex-shrink: 0;
}
.map-track-scrub .mts-step:hover:not(:disabled) { background: var(--accent); color: #fff; }
.map-track-scrub .mts-step:disabled { opacity: .4; cursor: default; }
.map-track-scrub .mts-time { font-size: 11.5px; color: var(--text); white-space: nowrap; }
.map-track-scrub .mts-count { font-size: 11px; color: var(--muted); white-space: nowrap; }
.map-track-scrub .mts-empty { font-size: 12px; color: var(--muted); }

/* при открытой карточке устройства — правые контролы уходят левее карточки,
   чтобы не перекрывать её (карточка: right:16px, width до 460px) */
@media (min-width: 721px) {
  .map-widget[data-selected="on"] .map-track-range,
  .map-widget[data-selected="on"] .map-lbs-ctl,
  .map-widget[data-selected="on"] .map-track-scrub { right: calc(460px + 30px); }
}
/* в режиме трека: LBS-регулятор поднимаем над скраббером, легенду скрываем */
.map-widget[data-track="on"] .map-lbs-ctl { bottom: 62px; }
.map-widget[data-track="on"] .map-legend { display: none; }
