/* Presence Monitoring — sci-fi HUD layout. */

:root {
  --hud-cyan: #5be1ff;
  --hud-cyan-dim: rgba(91, 225, 255, 0.18);
  --hud-amber: #ffb24a;
  --hud-amber-dim: rgba(255, 178, 74, 0.2);
  --hud-red: #ff4d6e;
  --hud-red-dim: rgba(255, 77, 110, 0.2);
  --hud-green: #5cffb8;
  --hud-green-dim: rgba(92, 255, 184, 0.18);
  --hud-bg: #06080d;
  --hud-bg-alt: #0a0e16;
  --hud-grid: rgba(91, 225, 255, 0.07);
  --hud-edge: rgba(91, 225, 255, 0.4);
  --hud-mono: 'IBM Plex Mono', 'Roboto Mono', monospace;
  --hud-display: 'Orbitron', 'Outfit', sans-serif;
}

body {
  background: var(--hud-bg);
  color: #e7eef7;
  font-family: 'DM Sans', sans-serif;
  margin: 0;
}

.noise-overlay {
  position: fixed; inset: 0;
  background-image: radial-gradient(rgba(91,225,255,0.05) 1px, transparent 1px);
  background-size: 3px 3px;
  pointer-events: none; z-index: 0;
}
.bg-grid-overlay {
  position: fixed; inset: 0;
  background:
    linear-gradient(var(--hud-grid) 1px, transparent 1px) 0 0/40px 40px,
    linear-gradient(90deg, var(--hud-grid) 1px, transparent 1px) 0 0/40px 40px;
  pointer-events: none; z-index: 0;
}
.scanline-overlay {
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 3px, rgba(91,225,255,0.03) 4px);
  pointer-events: none; z-index: 1;
  animation: scanline 7s linear infinite;
}
@keyframes scanline {
  0% { transform: translateY(0); } 100% { transform: translateY(40px); }
}

.presence-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative; z-index: 5;
}

/* ── Header ──────────────────────────────────────────── */
.presence-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--hud-edge);
  background: linear-gradient(180deg, rgba(91,225,255,0.05), transparent);
  width: 100%;
  box-sizing: border-box;
}
.header-left   { display: flex; gap: 14px; align-items: center; flex: 0 0 auto; }
.header-center { display: flex; flex-direction: column; align-items: center; flex: 1 1 auto; min-width: 0; }
.header-right  { display: flex; gap: 14px; align-items: center; justify-content: flex-end; flex: 0 0 auto; margin-left: auto; flex-wrap: wrap; }

.hex-logo {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--hud-cyan), #1a4a78);
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%);
  filter: drop-shadow(0 0 8px var(--hud-cyan));
}
.hud-title { font-family: var(--hud-display); font-weight: 700; letter-spacing: 0.18em; font-size: 1.1rem; color: var(--hud-cyan); text-shadow: 0 0 10px var(--hud-cyan-dim); }
.hud-sub   { font-family: var(--hud-mono); font-size: 0.66rem; color: rgba(231,238,247,0.55); letter-spacing: 0.18em; }

.hud-clock { font-family: var(--hud-display); font-size: 1.6rem; color: var(--hud-cyan); letter-spacing: 0.12em; text-shadow: 0 0 10px var(--hud-cyan-dim); }
.hud-date  { font-family: var(--hud-mono); font-size: 0.7rem; color: rgba(231,238,247,0.55); letter-spacing: 0.1em; }

.hud-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border: 1px solid var(--hud-edge);
  border-radius: 999px; font-family: var(--hud-mono); font-size: 0.7rem;
  color: var(--hud-cyan); letter-spacing: 0.14em;
  background: rgba(91,225,255,0.06);
}
.hud-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--hud-cyan); box-shadow: 0 0 8px currentColor; }
.hud-pill.connected   { color: var(--hud-green); border-color: var(--hud-green); }
.hud-pill.connected   .hud-dot { background: var(--hud-green); }
.hud-pill.degraded    { color: var(--hud-amber); border-color: var(--hud-amber); }
.hud-pill.degraded    .hud-dot { background: var(--hud-amber); }
.hud-pill.disconnected { color: var(--hud-red); border-color: var(--hud-red); }
.hud-pill.disconnected .hud-dot { background: var(--hud-red); }

.hud-stat {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 10px;
  border-left: 1px solid rgba(91,225,255,0.18);
}
.hud-stat-label { font-family: var(--hud-mono); font-size: 0.62rem; letter-spacing: 0.16em; color: rgba(231,238,247,0.55); }
.hud-stat-val   { font-family: var(--hud-display); font-size: 1.4rem; color: var(--hud-cyan); text-shadow: 0 0 8px var(--hud-cyan-dim); }
.hud-stat.alert .hud-stat-val { color: var(--hud-red); text-shadow: 0 0 8px var(--hud-red-dim); }

.btn-icon {
  background: transparent; border: 1px solid var(--hud-edge);
  color: var(--hud-cyan); padding: 6px; border-radius: 6px; cursor: pointer;
}

/* ── Main grid ───────────────────────────────────────── */
.presence-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  gap: 16px;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}
.panel {
  background: linear-gradient(180deg, rgba(91,225,255,0.04), transparent 60%), var(--hud-bg-alt);
  border: 1px solid var(--hud-edge);
  border-radius: 10px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.panel:before, .panel:after {
  content: ''; position: absolute; width: 14px; height: 14px;
  border: 2px solid var(--hud-cyan);
}
.panel:before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.panel:after  { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.panel-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px;
  border-bottom: 1px dashed rgba(91,225,255,0.2);
  padding-bottom: 6px;
}
.panel-title { font-family: var(--hud-display); font-size: 0.8rem; letter-spacing: 0.18em; color: var(--hud-cyan); }
.panel-title.alert { color: var(--hud-red); }
.panel-meta  { font-family: var(--hud-mono); font-size: 0.7rem; color: rgba(231,238,247,0.55); }
.panel-body { flex: 1; overflow-y: auto; min-height: 0; padding-right: 4px; }

/* panel toolbar (filter chips above the body) */
.panel-toolbar {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 4px 0 8px 0;
  border-bottom: 1px dashed rgba(91,225,255,0.12);
  margin-bottom: 8px;
  position: relative;
}
.hud-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  background: rgba(91,225,255,0.06);
  border: 1px solid var(--hud-edge);
  border-radius: 999px;
  font-family: var(--hud-mono); font-size: 0.7rem;
  color: var(--hud-cyan); letter-spacing: 0.08em;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.hud-chip:hover { background: rgba(91,225,255,0.12); }
.hud-chip[aria-expanded="true"] { background: rgba(91,225,255,0.16); border-color: var(--hud-cyan); }
.hud-chip.has-filter {
  border-color: var(--hud-cyan);
  background: rgba(91,225,255,0.14);
  color: #fff;
}
.hud-chip-caret { font-size: 0.6rem; opacity: 0.7; }

.hud-popover {
  position: absolute; left: 0; right: 0; top: 100%;
  z-index: 20;
  background: var(--hud-bg-alt);
  border: 1px solid var(--hud-cyan);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.55);
  padding: 8px;
  max-height: 320px; overflow-y: auto;
  font-family: var(--hud-mono); font-size: 0.74rem;
  color: var(--hud-cyan);
}
.hud-popover[hidden] { display: none; }
.hud-popover-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 4px; cursor: pointer;
}
.hud-popover-row:hover { background: rgba(91,225,255,0.08); }
.hud-popover-row.divider {
  border-top: 1px dashed rgba(91,225,255,0.18);
  margin-top: 6px; padding-top: 8px;
  color: rgba(231,238,247,0.55); font-size: 0.66rem; letter-spacing: 0.1em;
  text-transform: uppercase; cursor: default;
}
.hud-popover-row input[type="checkbox"] {
  appearance: none;
  width: 12px; height: 12px;
  border: 1px solid var(--hud-edge);
  border-radius: 2px; background: transparent; cursor: pointer; position: relative;
}
.hud-popover-row input[type="checkbox"]:checked {
  background: var(--hud-cyan);
  border-color: var(--hud-cyan);
}
.hud-popover-row input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute; left: 1px; top: -3px;
  font-size: 11px; color: var(--hud-bg-alt);
  font-weight: 700; line-height: 1;
}
.hud-popover-row .row-name { color: #e7eef7; flex: 1; }
.hud-popover-row .row-count {
  color: rgba(231,238,247,0.5); font-size: 0.66rem;
}

/* tag list cards */
.tag-card {
  border: 1px solid rgba(91,225,255,0.15);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: rgba(91,225,255,0.03);
  position: relative;
  transition: border-color .2s, transform .1s;
}
.tag-card:hover { border-color: var(--hud-cyan); }
.tag-card .tag-name { font-weight: 700; font-size: 0.95rem; }
.tag-card .tag-mac  { font-family: var(--hud-mono); font-size: 0.7rem; color: rgba(231,238,247,0.5); }
.tag-card .tag-meta { display: flex; justify-content: space-between; margin-top: 4px; font-size: 0.74rem; color: rgba(231,238,247,0.7); font-family: var(--hud-mono); }
.tag-card.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 2px var(--hud-cyan), 0 0 16px var(--hud-cyan-dim); }
  100% { box-shadow: none; }
}

/* receiver list */
.recv-card {
  border: 1px solid rgba(91,225,255,0.15);
  border-radius: 6px; padding: 8px 10px; margin-bottom: 6px;
  background: rgba(91,225,255,0.03);
  display: grid; grid-template-columns: 1fr auto; gap: 6px;
  font-size: 0.78rem;
}
.recv-card .recv-id { font-family: var(--hud-mono); font-size: 0.78rem; color: var(--hud-cyan); }
.recv-card .recv-meta { font-size: 0.7rem; color: rgba(231,238,247,0.6); }
.recv-status { font-family: var(--hud-mono); font-size: 0.64rem; padding: 2px 8px; border-radius: 999px; height: fit-content; align-self: center; }
.recv-status.online   { background: var(--hud-green-dim); color: var(--hud-green); }
.recv-status.offline  { background: var(--hud-red-dim);   color: var(--hud-red); }
.recv-status.degraded { background: var(--hud-amber-dim); color: var(--hud-amber); }
.recv-status.unknown  { background: rgba(231,238,247,0.06); color: rgba(231,238,247,0.55); }

/* alerts list */
.alert-card {
  border-left: 3px solid var(--hud-red);
  background: var(--hud-red-dim);
  padding: 6px 10px; border-radius: 4px; margin-bottom: 5px;
  font-size: 0.78rem;
}
.alert-card .alert-kind { font-family: var(--hud-mono); font-weight: 700; color: var(--hud-red); }
.alert-card .alert-sum  { color: rgba(231,238,247,0.85); }
.alert-card.severity-high     { border-left-color: var(--hud-red); }
.alert-card.severity-medium   { border-left-color: var(--hud-amber); background: var(--hud-amber-dim); }
.alert-card.severity-medium .alert-kind { color: var(--hud-amber); }
.alert-card.severity-low,
.alert-card.severity-info     { border-left-color: var(--hud-cyan); background: var(--hud-cyan-dim); }
.alert-card.severity-low .alert-kind,
.alert-card.severity-info .alert-kind { color: var(--hud-cyan); }

/* ── Stage panel: room grid + radar rings ────────────── */
.panel-stage { padding: 0; overflow: hidden; }
.stage-glow {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 60%, rgba(91,225,255,0.18), transparent 60%);
  pointer-events: none;
}
.stage-rings {
  position: absolute; left: 50%; top: 56%; transform: translate(-50%, -50%);
  pointer-events: none;
}
.ring {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  border: 1px solid rgba(91,225,255,0.18);
  border-radius: 50%;
  animation: pulse 6s ease-in-out infinite;
}
.ring.r1 { width: 240px; height: 240px; }
.ring.r2 { width: 440px; height: 440px; animation-delay: 1s; }
.ring.r3 { width: 680px; height: 680px; animation-delay: 2s; }
@keyframes pulse {
  0%,100% { opacity: 0.18; }
  50%     { opacity: 0.45; }
}
.stage-header {
  position: relative; z-index: 2;
  padding: 14px 18px;
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 1px dashed rgba(91,225,255,0.15);
}
.stage-title { font-family: var(--hud-display); letter-spacing: 0.2em; color: var(--hud-cyan); font-size: 0.9rem; }
.stage-sub   { font-family: var(--hud-mono); font-size: 0.74rem; color: rgba(231,238,247,0.5); letter-spacing: 0.1em; }

.room-grid {
  position: relative; z-index: 2;
  padding: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.room-tile {
  border: 1px solid rgba(91,225,255,0.25);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(91,225,255,0.04), rgba(91,225,255,0.01));
  /* Extra bottom padding reserves space for the absolutely-positioned
     sparkline so room-tags can't run into it. */
  padding: 12px 14px 46px 14px;
  position: relative;
  min-height: 140px;
  transition: border-color .25s, box-shadow .25s, transform .15s;
}
.room-tile.has-occupants {
  border-color: var(--hud-cyan);
  box-shadow: 0 0 12px var(--hud-cyan-dim);
}
.room-tile:hover { transform: translateY(-2px); }
.room-tile .room-name {
  font-family: var(--hud-display); letter-spacing: 0.1em; font-size: 0.95rem;
  color: var(--hud-cyan);
}
.room-tile .room-meta { font-family: var(--hud-mono); font-size: 0.66rem; color: rgba(231,238,247,0.45); margin-top: 2px; }
.room-tile .room-count {
  position: absolute; right: 12px; top: 10px;
  font-family: var(--hud-display); font-size: 1.6rem; color: var(--hud-cyan);
  text-shadow: 0 0 8px var(--hud-cyan-dim);
}
.room-tile .room-tags {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 8px;
}
.room-tile .room-tag {
  font-family: var(--hud-mono); font-size: 0.7rem;
  padding: 2px 6px; border: 1px solid rgba(91,225,255,0.4);
  border-radius: 4px; color: rgba(231,238,247,0.85);
  background: rgba(91,225,255,0.05);
}
.room-tile.empty .room-name  { color: rgba(231,238,247,0.4); }
.room-tile.empty .room-count { color: rgba(231,238,247,0.18); text-shadow: none; }

/* CSI motion sparkline pinned to the bottom ~1/4 of every tile. New samples
   land at the right edge; old samples slide off the left as the buffer fills.
   Absolute-positioned so it sits flush with the tile's bottom edge regardless
   of how many tag chips wrap above. */
.room-tile .room-csi-spark {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 8px;
  display: block;
  height: 32px;
}
.room-tile.empty .room-csi-spark { opacity: 0.45; }

.stage-footer {
  position: relative; z-index: 2;
  border-top: 1px dashed rgba(91,225,255,0.15);
  padding: 8px 18px; min-height: 60px; max-height: 110px; overflow-y: auto;
  font-family: var(--hud-mono); font-size: 0.72rem;
  color: rgba(231,238,247,0.7);
}
.event-row { display: flex; gap: 10px; align-items: baseline; padding: 2px 0; }
.event-row .event-time { color: rgba(231,238,247,0.4); width: 80px; }
.event-row .event-kind {
  width: 60px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--hud-cyan);
}
.event-row.lost  .event-kind { color: var(--hud-red); }
.event-row.alert .event-kind { color: var(--hud-amber); }

/* ── Toasts ─────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 6px; }
.toast {
  background: rgba(255,77,110,0.92); color: #fff;
  padding: 10px 14px; border-radius: 6px; font-family: var(--hud-mono);
  letter-spacing: 0.1em; font-size: 0.74rem;
  box-shadow: 0 0 12px var(--hud-red-dim);
}

/* ── Header affordances (help / theme / portal switcher) ─────── */
.presence-header .btn-icon {
  background: transparent;
  border: 1px solid var(--hud-edge, rgba(255,255,255,0.15));
  color: var(--hud-fg, #cfe9ff);
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.presence-header .btn-icon:hover {
  background: rgba(0,212,255,0.08);
  border-color: rgba(0,212,255,0.45);
}
.presence-header .portal-switcher {
  position: relative;
  display: inline-flex;
}
.presence-header .portal-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: rgba(10,16,28,0.96);
  border: 1px solid rgba(0,212,255,0.35);
  border-radius: 8px;
  padding: 8px 0;
  z-index: 80;
  display: none;
  font-family: var(--hud-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), 0 0 14px rgba(0,212,255,0.15);
}
.presence-header .portal-menu.show { display: block; }
.presence-header .portal-menu a,
.presence-header .portal-menu .portal-menu-disabled {
  display: block;
  padding: 6px 14px;
  color: #cfe9ff;
  text-decoration: none;
}
.presence-header .portal-menu a:hover { background: rgba(0,212,255,0.1); }
.presence-header .portal-menu .portal-menu-disabled { color: rgba(207,233,255,0.35); cursor: not-allowed; }
.presence-header .portal-menu-section {
  padding: 6px 14px 2px;
  color: rgba(0,212,255,0.7);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.presence-header .portal-menu-divider {
  height: 1px;
  background: rgba(0,212,255,0.18);
  margin: 6px 0;
}

/* ── Help modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(2,6,12,0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  max-width: 600px;
  width: calc(100% - 32px);
  background: rgba(10,16,28,0.98);
  border: 1px solid rgba(0,212,255,0.45);
  border-radius: 8px;
  padding: 20px 22px;
  color: #cfe9ff;
  font-family: var(--hud-mono);
}
.hud-modal-title {
  font-family: 'Orbitron', var(--hud-mono);
  letter-spacing: 0.18em;
  font-size: 0.92rem;
  color: #00d4ff;
  margin-bottom: 14px;
}
.hud-modal-body {
  font-size: 0.84rem;
  line-height: 1.55;
  color: rgba(207,233,255,0.92);
  font-family: 'DM Sans', sans-serif;
}
.hud-modal-body p { margin: 8px 0; }
.hud-modal-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

/* ── Responsive layouts: keep operational panels accessible ─────
   Previously the right (receivers + alerts) and left (live tags)
   panels were `display: none` below 1100/800 px, which hid the
   exact data operators care about on tablets/phones. Stack them
   vertically below the stage instead so every panel scrolls into
   view. */
@media (max-width: 1100px) {
  .presence-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(280px, auto);
  }
  .panel-tags      { order: 2; max-height: 360px; }
  .panel-stage     { order: 1; }
  .panel-receivers { order: 3; max-height: 420px; }
  .header-center   { display: none; }
}
@media (max-width: 800px) {
  .presence-header { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .header-right    { flex-wrap: wrap; gap: 6px; }
  .hud-stat        { padding: 4px 8px; }
  .panel-tags, .panel-receivers { max-height: 320px; }
}

/* ── Tag-card click affordance (drilldown on the HUD) ─────────────── */
.tag-card[data-action="open-tag"] {
  cursor: pointer;
  transition: border-color 0.12s ease;
}
.tag-card[data-action="open-tag"]:hover,
.tag-card[data-action="open-tag"]:focus-visible {
  border-color: var(--hud-cyan);
  outline: none;
}

/* ── Alert ack button ─────────────────────────────────────────────── */
.alert-card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
}
.alert-ack {
  background: transparent;
  border: 1px solid currentColor;
  color: var(--hud-cyan);
  font-family: var(--hud-mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.alert-ack:hover { background: rgba(91,225,255,0.12); }
.alert-acked {
  font-family: var(--hud-mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  color: var(--hud-green);
  border: 1px dashed var(--hud-green);
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0.65;
}

/* ── Receiver group headers ───────────────────────────────────────── */
.recv-group-head {
  font-family: var(--hud-mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  color: rgba(231,238,247,0.55);
  text-transform: uppercase;
  padding: 8px 4px 4px 4px;
  border-top: 1px dashed rgba(91,225,255,0.18);
  margin-top: 6px;
}
.recv-group-head:first-child { border-top: none; margin-top: 0; padding-top: 2px; }

/* ── Tag detail modal ─────────────────────────────────────────────── */
.tag-detail-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 24px;
  margin-bottom: 14px;
}
.tag-detail-grid > div { display: flex; flex-direction: column; gap: 2px; }
.td-label {
  font-family: var(--hud-mono);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  color: rgba(231,238,247,0.55);
  text-transform: uppercase;
}
.td-val {
  font-size: 0.95rem;
  color: var(--hud-cyan);
}
.td-val.mono { font-family: var(--hud-mono); font-size: 0.85rem; }
.td-section-title {
  font-family: var(--hud-mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  color: rgba(231,238,247,0.65);
  text-transform: uppercase;
  margin: 8px 0 6px 0;
}
.td-history {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 220px; overflow-y: auto;
  border: 1px solid rgba(91,225,255,0.15);
  padding: 6px;
  border-radius: 4px;
}
.td-row {
  display: grid;
  grid-template-columns: 80px 90px 1fr 60px;
  gap: 8px;
  padding: 4px 6px;
  font-family: var(--hud-mono);
  font-size: 0.78rem;
  border-bottom: 1px dashed rgba(91,225,255,0.08);
}
.td-row:last-child { border-bottom: none; }
.td-row-kind { color: var(--hud-amber); }
.td-row-loc  { color: rgba(231,238,247,0.85); }
.td-row-rssi { color: rgba(231,238,247,0.6); text-align: right; }
.td-loading, .td-empty {
  padding: 12px;
  text-align: center;
  color: rgba(231,238,247,0.5);
  font-family: var(--hud-mono);
  font-size: 0.78rem;
}

/* ─── Stage view toggle (grid vs floorplan) ─────────────────────────── */

/* `display: grid` on .room-grid would otherwise override the HTML hidden
   attribute (which uses display: none). Force the hidden state to win. */
.room-grid[hidden],
.floorplan-stage[hidden] { display: none !important; }

/* ─── Floorplan view (alternative to room-grid) ─────────────────────── */

.stage-view-switch {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-left: auto;
}
.hud-chip.selected {
  background: rgba(91,225,255,0.22);
  border-color: var(--hud-cyan);
  color: #fff;
  box-shadow: 0 0 8px var(--hud-cyan-dim);
}

.floorplan-stage {
  position: relative; z-index: 2;
  padding: 18px;
  flex: 1;
  min-height: 0;
  display: flex; align-items: stretch; justify-content: stretch;
}
/* Shell = viewport. Pan/zoom transform is applied to the inner canvas;
   the shell stays put with overflow hidden so the canvas can move
   freely without bleeding past the panel edges. */
.fp-mon-shell {
  position: relative;
  flex: 1;
  background: #0a0d12;
  border: 1px solid rgba(91,225,255,0.25);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 18px rgba(91,225,255,0.08) inset;
  cursor: grab;
  touch-action: none; /* let pointer events drive pan; disable browser pan */
}
.fp-mon-shell.dragging { cursor: grabbing; }
/* Canvas holds the image and overlay together. transform-origin: 0 0
   matches the math in applyFpZoom() so cursor-anchored zoom stays exact. */
.fp-mon-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  /* aspect-ratio is set inline from the meta dims; the canvas keeps the
     image's intrinsic aspect so polygons drawn in normalized 0..1 land
     on the right pixels. */
  transform-origin: 0 0;
  transition: none;  /* immediate response while wheel/drag is active */
  will-change: transform;
}
.fp-mon-img {
  width: 100%; height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  /* Floorplans rendered at 150 DPI tend to be near-white; soften the
     contrast against the HUD palette so room outlines stay readable. */
  filter: brightness(0.86) contrast(1.05);
}
.fp-mon-svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  /* The SVG itself is transparent to pointer events so dragging the
     shell pans even when the cursor is over an empty polygon area.
     Individual <g class="fp-mon-tag"> children opt back in via inline
     pointer-events so tag clicks still work. */
  pointer-events: none;
}
.fp-mon-tag { pointer-events: auto; }

/* Floating zoom toolbar. Anchored to the bottom-right of the shell so
   it stays visible at any zoom and doesn't overlap the room labels. */
.fp-mon-toolbar {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex; gap: 6px;
  z-index: 5;
}
.fp-mon-toolbar .hud-chip {
  min-width: 36px; justify-content: center;
  font-size: 0.78rem; padding: 4px 10px;
}
.fp-mon-toolbar .hud-chip:focus-visible {
  outline: 2px solid var(--hud-cyan);
  outline-offset: 2px;
}

/* Tag detail popover (hover over a dot). Singleton element appended to
   the body so it isn't clipped by .fp-mon-shell's overflow:hidden. */
.fp-mon-tag-popover {
  position: fixed;
  z-index: 1000;
  min-width: 200px; max-width: 260px;
  background: rgba(10,13,18,0.95);
  border: 1px solid var(--hud-cyan);
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.55), 0 0 12px rgba(91,225,255,0.18);
  font-family: var(--hud-mono);
  font-size: 0.78rem;
  color: rgba(231,238,247,0.92);
  pointer-events: none;  /* never steals hover from the dot beneath */
}
.fp-mon-tag-popover .fp-pop-name {
  font-family: var(--hud-display);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--hud-cyan);
  margin-bottom: 2px;
}
.fp-mon-tag-popover .fp-pop-mac {
  font-size: 0.7rem;
  color: rgba(231,238,247,0.55);
  margin-bottom: 8px;
  word-break: break-all;
}
.fp-mon-tag-popover .fp-pop-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 2px 0;
}
.fp-mon-tag-popover .fp-pop-row span:first-child {
  color: rgba(231,238,247,0.5);
}

/* Selected state for the LIVE TAGS rail card. Mirrors the red dot on
   the floorplan so the user can see at a glance which tag is "pinned". */
.tag-card.selected {
  border-color: #ff3b3b;
  background: rgba(255,59,59,0.08);
  box-shadow: 0 0 8px rgba(255,59,59,0.35);
}

/* Unplaced-tags diagnostic. Always anchored bottom-left; hover/focus
   expands the detail panel listing each tag and the location it
   actually resolved to. */
.fp-mon-unplaced {
  position: absolute;
  left: 12px; bottom: 12px;
  z-index: 6;
  background: rgba(255,180,0,0.14);
  border: 1px solid var(--hud-amber);
  border-radius: 6px;
  font-family: var(--hud-mono);
  font-size: 0.74rem;
  color: var(--hud-amber);
  cursor: help;
  outline: none;
}
.fp-mon-unplaced .fp-up-summary {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
}
.fp-mon-unplaced .fp-up-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--hud-amber);
  color: #000;
  font-weight: 800; font-family: var(--hud-display);
}
.fp-mon-unplaced .fp-up-detail {
  display: none;
  padding: 8px 12px 10px 12px;
  border-top: 1px dashed rgba(255,180,0,0.35);
  max-height: 240px; overflow-y: auto;
  min-width: 240px; max-width: 320px;
  color: rgba(231,238,247,0.92);
}
.fp-mon-unplaced:hover .fp-up-detail,
.fp-mon-unplaced:focus .fp-up-detail,
.fp-mon-unplaced:focus-within .fp-up-detail { display: block; }
.fp-up-hint {
  font-size: 0.7rem; color: rgba(231,238,247,0.55);
  margin-bottom: 6px;
}
.fp-up-loc {
  font-family: var(--hud-display);
  font-size: 0.78rem;
  color: var(--hud-cyan);
  letter-spacing: 0.06em;
  margin-top: 6px;
  padding-bottom: 2px;
  border-bottom: 1px dashed rgba(91,225,255,0.18);
  display: flex; justify-content: space-between;
}
.fp-up-loc .fp-up-count {
  color: var(--hud-amber);
  font-family: var(--hud-mono);
  font-size: 0.7rem;
}
.fp-up-tag {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 2px 0;
  font-size: 0.74rem;
}
.fp-up-tag .mono { color: rgba(231,238,247,0.55); font-size: 0.7rem; }
.fp-mon-room.has-occupants polygon { filter: drop-shadow(0 0 8px var(--hud-cyan-dim)); }

/* Floorplan motion: pulse the room polygon itself so the whole room glows
   cyan when CSI detects movement. Much more visible than the small dot,
   especially when the plan is zoomed out — and the entire polygon area
   becomes the visual cue. The polygon's configured fill colour is kept;
   only fill-opacity and the cyan drop-shadow are animated. */
.fp-mon-room.has-motion polygon {
  animation: fp-mon-room-motion-pulse 1.8s ease-in-out infinite;
}
@keyframes fp-mon-room-motion-pulse {
  0%, 100% {
    fill-opacity: 0.32;
    filter: drop-shadow(0 0 4px rgba(34,211,238,0.45));
  }
  50% {
    fill-opacity: 0.72;
    filter: drop-shadow(0 0 16px rgba(34,211,238,0.95));
  }
}
/* Hide the redundant motion dot once the polygon itself signals motion. */
.fp-mon-room.has-motion .fp-mon-motion-dot { display: none; }

/* Live count badge — small circle anchored above each occupied polygon. */
.fp-mon-badge circle { transition: r 0.2s ease, filter 0.2s ease; }
.fp-mon-badge text   { letter-spacing: 0.05em; }
.fp-mon-badge.changed circle {
  animation: fp-mon-badge-pulse 0.9s ease;
}
@keyframes fp-mon-badge-pulse {
  0%   { r: 14; filter: drop-shadow(0 0 0 rgba(91,225,255,0)); }
  35%  { r: 19; filter: drop-shadow(0 0 10px rgba(91,225,255,0.85)); }
  100% { r: 14; filter: drop-shadow(0 0 0 rgba(91,225,255,0)); }
}
.fp-mon-tag { cursor: pointer; }
.fp-mon-tag circle { transition: r 0.18s ease, filter 0.18s ease; }
.fp-mon-tag:hover circle { r: 11; }
/* Selected tag — strong red pulse to be unmissable on a busy plan. The
   animation runs continuously while .selected is set; the JS auto-clears
   the class after 30 seconds, so the pulse stops itself. */
.fp-mon-tag.selected circle {
  fill: #ff3b3b;
  stroke: #fff;
  animation: fp-mon-selected-pulse 1s ease-in-out infinite;
}
@keyframes fp-mon-selected-pulse {
  0%, 100% {
    r: 10;
    stroke-width: 2;
    filter: drop-shadow(0 0 4px rgba(255,59,59,0.6));
  }
  50% {
    r: 18;
    stroke-width: 4;
    filter: drop-shadow(0 0 18px rgba(255,59,59,1));
  }
}
/* Hover doesn't compete with the pulse — animation overrides the
   transition during its run, and we want the pulse to keep visual
   priority over the hover-grow effect on .fp-mon-tag:hover. */
.fp-mon-tag.selected:hover circle { animation-play-state: running; }
.fp-mon-tag.flash circle {
  animation: fp-mon-tag-pulse 1.2s ease;
}
@keyframes fp-mon-tag-pulse {
  0%   { r: 9; filter: drop-shadow(0 0 0 rgba(255,255,255,0)); }
  35%  { r: 13; filter: drop-shadow(0 0 8px rgba(255,255,255,0.9)); }
  100% { r: 9; filter: drop-shadow(0 0 0 rgba(255,255,255,0)); }
}

.fp-mon-loading, .fp-mon-error {
  font-family: var(--hud-mono);
  font-size: 0.82rem;
  color: rgba(231,238,247,0.6);
  padding: 40px 12px;
  text-align: center;
}
.fp-mon-error { color: var(--hud-amber); }
.fp-mon-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.fp-mon-empty[hidden] { display: none; }
.fp-mon-empty-card {
  background: rgba(10,13,18,0.85);
  border: 1px solid rgba(91,225,255,0.3);
  border-radius: 8px;
  padding: 14px 18px;
  font-family: var(--hud-mono);
  font-size: 0.82rem;
  color: rgba(231,238,247,0.85);
  text-align: center;
  pointer-events: auto;
}

/* ---- Motion indicator (CSI-driven; independent of tag presence) ---- */

/* Grid-mode: inline dot rendered before the room name. Sized to be obvious
   at a glance — the whole point is "you can see motion across the grid
   without focusing on any one tile." */
.motion-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 10px;
  border-radius: 50%;
  background: rgba(120,140,160,0.35);
  border: 2px solid rgba(120,140,160,0.55);
  vertical-align: middle;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.motion-dot.is-motion {
  background: #22d3ee;
  border-color: #67e8f9;
  box-shadow: 0 0 14px rgba(34,211,238,0.9), 0 0 28px rgba(34,211,238,0.5);
  animation: motion-pulse 1.2s ease-in-out infinite;
}

/* Floorplan-mode: SVG circle rendered inside each room <g>. Larger radius
   so it remains readable when the floorplan is zoomed out; the SVG uses
   vector-effect=non-scaling-stroke so the outline width stays constant. */
.fp-mon-motion-dot {
  r: 12;
  fill: rgba(120,140,160,0.35);
  stroke: rgba(120,140,160,0.6);
  stroke-width: 1.5;
  pointer-events: auto;
  transition: fill 0.2s, stroke 0.2s, opacity 0.2s;
}
.fp-mon-room.has-motion .fp-mon-motion-dot {
  fill: #22d3ee;
  stroke: #67e8f9;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px rgba(34,211,238,0.9));
  /* Pulse opacity (transform/scale on SVG <circle> is unreliable across browsers
     because transform-origin is in user space, not the element's box). */
  animation: motion-pulse-opacity 1.2s ease-in-out infinite;
}

@keyframes motion-pulse {
  /* HTML/grid dot: scale + opacity (transform on inline-block works fine) */
  0%, 100% { opacity: 0.65; transform: scale(1); }
  50%      { opacity: 1.0;  transform: scale(1.35); }
}

@keyframes motion-pulse-opacity {
  /* SVG dot: opacity-only pulse */
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1.0; }
}
