/* Signal Radar dashboard — desktop-first workstation. Dark primary + light theme. */
:root, [data-theme="dark"] {
  --bg: #0a0e14; --bg2: #0c1118; --panel: #10151e; --card: #161c27; --card2: #1b222e;
  --line: #242c3a; --line2: #161c27; --text: #e6edf3; --text2: #9aa7b5; --text3: #5b6675;
  --accent: #2dd4bf; --accent-ink: #04201c;
  --t0: #a855f7; --t1: #3b82f6; --t2: #22c55e; --t3: #64748b; --t4: #ef4444;
  --heat-cold: #475569; --heat-warm: #f59e0b; --heat-hot: #f97316; --heat-crit: #ff5630;
  --shadow: 0 4px 14px rgba(0,0,0,.4);
}
[data-theme="light"] {
  --bg: #eef1f6; --bg2: #e6eaf1; --panel: #ffffff; --card: #ffffff; --card2: #f3f5f9;
  --line: #dbe2ec; --line2: #e2e7ef; --text: #0f172a; --text2: #475569; --text3: #94a3b8;
  --accent: #0d9488; --accent-ink: #ffffff; --shadow: 0 4px 14px rgba(15,23,42,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "IBM Plex Sans", system-ui, sans-serif; -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }
button { font-family: inherit; cursor: pointer; }
.leaflet-container { background: var(--bg); }

#app { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }

/* guest banner */
.guest-banner {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 800;
  background: rgba(45,212,191,.12); border: 1px solid rgba(45,212,191,.4); color: var(--accent);
  font: 600 11px/1 "IBM Plex Mono", monospace; padding: 7px 14px; border-radius: 999px; letter-spacing: .3px;
  display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow);
}

/* top bar */
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); z-index: 100; }
.logo-mark { width: 26px; height: 26px; display: grid; place-items: center; background: rgba(45,212,191,.13); border: 1px solid var(--accent); border-radius: 7px; color: var(--accent); font-weight: 700; font-size: 14px; }
.brand { font-weight: 600; font-size: 14px; }
.area-switch { display: flex; align-items: center; gap: 7px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; font-size: 13px; }
.area-switch select { background: transparent; border: 0; color: var(--text); font-family: inherit; font-size: 13px; outline: none; }
.search { flex: 1; max-width: 360px; display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; }
.search input { flex: 1; background: transparent; border: 0; color: var(--text); font-family: inherit; font-size: 13px; outline: none; }
.spacer { flex: 1; }
.status-pill { display: flex; align-items: center; gap: 7px; font: 500 11px/1 "IBM Plex Mono", monospace; color: var(--text2); background: var(--card); border: 1px solid var(--line); padding: 6px 10px; border-radius: 999px; }
.status-pill .d { width: 7px; height: 7px; border-radius: 50%; background: var(--t2); box-shadow: 0 0 7px var(--t2); }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text2); font-size: 14px; }
.icon-btn:hover { color: var(--text); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #1f8f82); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 12px; border: 0; }

/* account menu */
.menu { position: absolute; top: 50px; right: 12px; width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 7px; z-index: 300; }
.menu .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 13px; }
.menu .row:hover { background: var(--card); }
.menu .seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.menu .seg button { border: 0; background: transparent; color: var(--text2); border-radius: 5px; padding: 4px 9px; font-size: 11.5px; font-weight: 600; }
.menu .seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.menu .item { width: 100%; text-align: left; border: 0; background: transparent; color: var(--text); padding: 9px 10px; border-radius: 8px; font-size: 13px; }
.menu .item:hover { background: var(--card); }

/* body grid: rail + content */
.body { display: grid; grid-template-columns: 52px 1fr; min-height: 0; }
.rail { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0; border-right: 1px solid var(--line); background: var(--panel); }
.rail button { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; border: 0; background: transparent; color: var(--text3); font-size: 16px; }
.rail button[aria-current="true"] { background: var(--card); color: var(--accent); }
.rail button:hover { color: var(--text); }

/* views */
.body > main { height: 100%; min-height: 0; }
.view { position: relative; height: 100%; min-height: 0; overflow: hidden; }
.view.hidden { display: none; }

/* MAP view: map + feed panel */
.map-wrap { display: grid; grid-template-columns: 1fr 380px; height: 100%; }
@media (max-width: 900px) { .map-wrap { grid-template-columns: 1fr; } }
#map { height: 100%; width: 100%; }
.feed { border-left: 1px solid var(--line); background: var(--bg2); display: flex; flex-direction: column; min-height: 0; }
.feed-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.feed-head .t { font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.tchip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text2); border-radius: 999px; padding: 5px 10px; font: 600 11px/1 "IBM Plex Mono", monospace; }
.tchip .d { width: 8px; height: 8px; border-radius: 50%; }
.tchip[aria-pressed="true"] { color: var(--text); border-color: var(--text3); }
.tchip[aria-pressed="false"] { opacity: .5; }
.sortbtn { margin-left: auto; font: 600 11px/1 "IBM Plex Mono", monospace; color: var(--text2); background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; }
.feed-list { overflow-y: auto; flex: 1; min-height: 0; }
.srow { padding: 12px 14px; border-bottom: 1px solid var(--line2); display: grid; gap: 7px; }
.srow:hover { background: var(--card); cursor: pointer; }
.srow .top { display: flex; align-items: center; gap: 8px; }
.badge { font: 600 9.5px/1 "IBM Plex Mono", monospace; padding: 3px 6px; border-radius: 4px; white-space: nowrap; }
.srow .title { font-size: 13px; font-weight: 500; line-height: 1.4; }
.srow .meta { display: flex; align-items: center; gap: 8px; font: 500 10.5px/1 "IBM Plex Mono", monospace; color: var(--text3); flex-wrap: wrap; }
.heatbar { width: 54px; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.heatbar > i { display: block; height: 100%; }
.heatval { font: 600 11px/1 "IBM Plex Mono", monospace; }
.approx { color: var(--heat-warm); }

/* slide-over detail */
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); z-index: 400; opacity: 0; pointer-events: none; transition: opacity .2s; }
.overlay.show { opacity: 1; pointer-events: auto; }
.slideover { position: absolute; top: 0; right: 0; height: 100%; width: 440px; max-width: 92vw; background: var(--panel); border-left: 1px solid var(--line); box-shadow: -24px 0 60px rgba(0,0,0,.4); z-index: 500; transform: translateX(100%); transition: transform .24s ease; display: flex; flex-direction: column; }
.slideover.show { transform: none; }
.so-head { padding: 16px; border-bottom: 1px solid var(--line); }
.so-body { padding: 16px; overflow-y: auto; flex: 1; }
.so-foot { padding: 14px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.btn { border-radius: 9px; padding: 11px 16px; font-weight: 600; font-size: 13px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border: 0; }
.btn.full { flex: 1; text-align: center; }
.timeline { margin: 14px 0; padding-left: 18px; border-left: 2px solid var(--line); display: grid; gap: 16px; }
.tl-node { position: relative; }
.tl-node::before { content: ""; position: absolute; left: -25px; top: 2px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--panel); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line2); font-size: 13px; }
.kv .k { color: var(--text2); }
.kv .v { font-family: "IBM Plex Mono", monospace; font-size: 12.5px; text-align: right; }
#detailMap { height: 150px; border-radius: 10px; border: 1px solid var(--line); margin-top: 12px; }

/* health view */
.health { padding: 22px; overflow-y: auto; height: 100%; }
.health h2 { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.hgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-top: 18px; }
.hcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.hcard .src { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.hcard .st { width: 9px; height: 9px; border-radius: 50%; }
.hcard .line { display: flex; justify-content: space-between; font: 500 12px/1.8 "IBM Plex Mono", monospace; color: var(--text2); }
.gated { opacity: .72; }

/* generic config panels (alerts / areas) */
.panel-view { padding: 22px; overflow-y: auto; height: 100%; max-width: 720px; }
.panel-view h2 { font-size: 18px; font-weight: 600; margin: 0 0 16px; }
.field { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
.field .lbl { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field .hint { font-size: 12px; color: var(--text2); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.toggle-chip { border: 1px solid var(--line); background: var(--bg2); color: var(--text2); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; }
.toggle-chip[aria-pressed="true"] { border-color: var(--accent); color: var(--text); }

/* AI assistant */
.ai-fab { position: absolute; right: 18px; bottom: 18px; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); border: 0; font-size: 20px; box-shadow: var(--shadow); z-index: 600; }
.ai-panel { position: absolute; right: 18px; bottom: 82px; width: 360px; max-width: 92vw; height: 460px; max-height: 70vh; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); z-index: 650; display: none; flex-direction: column; overflow: hidden; }
.ai-panel.show { display: flex; }
.ai-head { padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.ai-sugg { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.ai-sugg button { font-size: 11.5px; border: 1px solid var(--line); background: var(--card); color: var(--text2); border-radius: 999px; padding: 6px 10px; }
.ai-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.ai-input input { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; color: var(--text); font-family: inherit; font-size: 13px; outline: none; }

.empty { display: grid; place-items: center; height: 100%; color: var(--text3); font-size: 13px; text-align: center; padding: 30px; }
.shimmer { background: linear-gradient(90deg, var(--card) 25%, var(--card2) 37%, var(--card) 63%); background-size: 400% 100%; animation: sh 1.3s ease infinite; }
@keyframes sh { from { background-position: 100% 0; } to { background-position: 0 0; } }
/* animated glowing pins */
.sr-pin { background: transparent !important; border: 0 !important; overflow: visible; }
.pin-wrap { position: relative; width: 100%; height: 100%; }
.pin-dot { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .9); animation: pinglow 2.4s ease-in-out infinite; }
.pin-ping { position: absolute; inset: 0; border-radius: 50%; opacity: .6; animation: pinping 2.2s ease-out infinite; }
@keyframes pinping { 0% { transform: scale(.55); opacity: .65; } 80%, 100% { transform: scale(2.7); opacity: 0; } }
@keyframes pinglow { 0%, 100% { box-shadow: 0 0 4px var(--g, #2dd4bf), 0 0 2px var(--g, #2dd4bf); } 50% { box-shadow: 0 0 15px var(--g, #2dd4bf), 0 0 7px var(--g, #2dd4bf); } }
@media (prefers-reduced-motion: reduce) { .pin-dot, .pin-ping { animation: none !important; } }

/* search-as-you-move toggle */
.map-search-toggle {
  position: absolute; top: 12px; left: 12px; z-index: 500;
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 13px; box-shadow: var(--shadow); font-size: 12.5px; color: var(--text);
  cursor: pointer; user-select: none;
}
.map-search-toggle .sw { width: 32px; height: 18px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; flex-shrink: 0; }
.map-search-toggle .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.map-search-toggle[aria-pressed="true"] .sw { background: var(--accent); }
.map-search-toggle[aria-pressed="true"] .sw::after { transform: translateX(14px); }
.map-search-toggle .cnt { color: var(--text3); font-family: "IBM Plex Mono", monospace; font-size: 11px; }

.leaflet-popup-content-wrapper { background: var(--card); color: var(--text); }
.leaflet-popup-tip { background: var(--card); }
