#map {
  position: fixed;
  inset: 0;
}

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 5;
  max-width: calc(100vw - 24px);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.6);
  animation: beacon 2s infinite;
}
@keyframes beacon {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(255, 77, 79, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
}

.stats { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.home-stat b { color: var(--danger); }

.conn { display: inline-flex; align-items: center; gap: 6px; }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.conn[data-state="open"] i { background: var(--ok); }
.conn[data-state="error"] i { background: var(--danger); }

/* ---------- legend ---------- */
.legend {
  position: fixed;
  left: 12px;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  width: 230px;
  padding: 10px 12px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 4;
}
.legend-toggle { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 0 0 6px; }
.legend[data-collapsed] ul, .legend[data-collapsed] .legend-note { display: none; }
.filters li label {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 2px; cursor: pointer; font-size: 13px;
}
.filters li input { accent-color: var(--accent); margin: 0; }
.filters li .sw { width: 18px; height: 18px; display: grid; place-items: center; }
.filters li .spd { margin-left: auto; color: var(--dim); font-size: 11px; }
.legend-note { margin: 8px 0 0; font-size: 11px; color: var(--dim); line-height: 1.35; }

/* ---------- side panel ---------- */
.panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 380px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 5;
  overflow: hidden;
}
.peek { display: none; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  padding: 12px 10px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px;
  border-radius: 10px; background: rgba(255, 255, 255, 0.08);
  font-size: 11px; line-height: 18px; font-variant-numeric: tabular-nums;
}

.tab-body { display: none; flex: 1; overflow-y: auto; }
.tab-body.active { display: block; }


.empty { padding: 40px 20px; text-align: center; color: var(--dim); }

/* ---------- narrow screens: map first, bottom sheet ---------- */
/* The sheet opens as a one-line "peek" with the most important target; tap → half, swipe
   up → full. The map is never half-covered unless the user asks for the list. */
@media (max-width: 760px) {
  .topbar { right: 12px; gap: 10px; padding: 6px 8px 6px 12px; flex-wrap: nowrap; }
  .topbar h1, .hide-narrow { display: none; }
  .stats { gap: 10px; white-space: nowrap; }
  .brand { gap: 6px; }
  .legend { display: none; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto;
    height: var(--sheet-h, 50vh);
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: height 0.22s ease;
    touch-action: none;
  }
  .panel[data-sheet="peek"] { --sheet-h: calc(72px + env(safe-area-inset-bottom, 0px)); }
  .panel[data-sheet="half"] { --sheet-h: 52vh; }
  .panel[data-sheet="full"] { --sheet-h: calc(100vh - 70px - env(safe-area-inset-top, 0px)); }
  .panel.dragging { transition: none; }
  .panel[data-sheet="peek"] .tabs, .panel[data-sheet="peek"] .tab-body { visibility: hidden; }
  .tab-body { touch-action: pan-y; }
  .peek { display: block; width: 100%; flex: none; padding: 6px 14px 10px; text-align: left; touch-action: none; }
  .grip { display: block; width: 40px; height: 4px; margin: 0 auto 8px; border-radius: 4px; background: var(--line-strong); }
  .peek-row { display: flex; align-items: center; gap: 10px; min-height: 40px; }
  .peek-ico { width: 26px; height: 26px; flex: none; color: var(--c, var(--muted)); }
  .peek-ico svg { width: 100%; height: 100%; }
  .peek-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
  .peek-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
  .peek-text small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .peek.hot b { color: var(--danger); }
  .peek-chev { color: var(--dim); transition: transform 0.2s; }
  .panel:not([data-sheet="peek"]) .peek-chev { transform: rotate(180deg); }
  .maplibregl-ctrl-bottom-right { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
}

.replay-badge {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent);
  color: #111;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.replay-badge b { font-variant-numeric: tabular-nums; margin-left: 4px; }
