:root {
  --bg: #05080d;
  --panel: rgba(9, 14, 22, 0.86);
  --panel-solid: #0b111b;
  --line: rgba(148, 163, 184, 0.16);
  --text: #e6edf6;
  --muted: #8a9bb0;
  --accent: #38bdf8;
  --accent-ink: #04121c;
  --r3: #f43f5e;
  --r2: #f59e0b;
  --r1: #facc15;
  --r0: #22c55e;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 12px;
}
body[data-brand="texmg"] { --accent: #2b9fd9; --accent-ink: #ffffff; }
body[data-brand="talos"] { --accent: #0fa98e; --accent-ink: #03110e; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
h2 { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0; }

#map { position: fixed; inset: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 10px 8px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand-logo { display: grid; place-items: center; flex: none; }
.brand-logo img { display: block; }
.brand-logo.chip { background: #fff; border-radius: 8px; padding: 6px 9px; }
.brand-logo.chip img { height: 20px; width: auto; }
.brand-logo.mark img { width: 34px; height: 34px; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand-text small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.modes { display: flex; gap: 4px; padding: 3px; margin-left: auto; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; }
.mode { border: 0; background: transparent; padding: 7px 12px; border-radius: 7px; color: var(--muted); font-weight: 500; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.mode.is-on { background: var(--accent); color: var(--accent-ink); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite; }
.mode:not(.is-on) .live-dot { animation: none; opacity: .6; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.5); } 70% { box-shadow: 0 0 0 7px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }
.updated { color: var(--muted); font: 12px var(--mono); white-space: nowrap; }

/* ---------- side panel ---------- */
.panel {
  position: fixed; z-index: 4; top: 80px; left: 12px; bottom: 12px; width: 384px;
  display: flex; flex-direction: column; gap: 14px;
  padding: 14px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  scrollbar-width: thin; scrollbar-color: rgba(148,163,184,.3) transparent;
}
.sheet-grip { display: none; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats[data-n="4"] { grid-template-columns: repeat(4, 1fr); }
.stats[data-n="4"] .stat b { font-size: 20px; }
.stats[data-n="4"] .stat span { font-size: 11px; }
.stat { background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.stat b { display: block; font: 600 24px/1.1 var(--mono); }
.stat span { color: var(--muted); font-size: 12px; }
.stat.hot b { color: var(--r3); }

.drill { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 10px; background: rgba(244,63,94,.07); border: 1px solid rgba(244,63,94,.25); }
.drill[hidden] { display: none; }
.drill-head { display: flex; align-items: center; gap: 12px; }
.play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 14px; flex: none; }
.drill-time { font: 600 15px var(--mono); }
.drill-storm { color: var(--muted); font-size: 12.5px; }
.drill-note { margin: 0; color: var(--muted); font-size: 12px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.playbook-btn {
  border: 0; border-radius: 10px; padding: 12px 14px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
}
.playbook-btn:disabled { background: rgba(255,255,255,.06); color: var(--muted); cursor: default; }

.sites-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.legend { color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.r3 { background: var(--r3); } .r2 { background: var(--r2); } .r1 { background: var(--r1); } .r0 { background: var(--r0); }

.sites { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.site { display: grid; grid-template-columns: 10px 1fr; gap: 4px 10px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.02); cursor: pointer; }
.site:hover, .site.is-focus { border-color: var(--accent); }
.site .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; }
.site-name { font-weight: 600; }
.site-name small { color: var(--muted); font-weight: 400; }
.site-why { grid-column: 2; color: var(--muted); font-size: 12.5px; }
.site-why b { color: var(--text); font-weight: 500; }
.chips { grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.chip { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: rgba(34,197,94,.1); color: #86efac; }
.chip.bad { background: rgba(244,63,94,.12); color: #fda4af; }
.site.clear .chips { display: none; }

.layers { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.layers h2 { grid-column: 1 / -1; }
.layers label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
.layers input { accent-color: var(--accent); }

.foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.foot p { margin: 0 0 8px; }
.foot a { color: var(--accent); font-weight: 600; text-decoration: none; }
.foot .fine { color: var(--muted); font-size: 11px; }

/* ---------- staff sign-in, tabs, circuits ---------- */
.staff { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border-radius: 10px; border: 1px dashed var(--line); color: var(--muted); font-size: 12.5px; }
.staff[hidden] { display: none; }
.staff-on { color: var(--text); display: flex; align-items: center; gap: 8px; min-width: 0; }
.staff-on i { width: 8px; height: 8px; border-radius: 50%; background: var(--r0); flex: none; box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.link-btn { border: 0; background: transparent; color: var(--accent); font-weight: 600; padding: 4px 0; white-space: nowrap; }
.tabs { display: flex; gap: 4px; padding: 3px; margin-bottom: 10px; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; }
.tabs[hidden] { display: none; }
.tab { flex: 1; border: 0; background: transparent; padding: 7px 8px; border-radius: 7px; color: var(--muted); font-weight: 500; font-size: 13px; }
.tab.is-on { background: rgba(255,255,255,.09); color: var(--text); }
.tab em { font-style: normal; color: var(--r3); font-weight: 600; margin-left: 4px; font-size: 11.5px; white-space: nowrap; }
.chip.mute { background: rgba(148,163,184,.12); color: #cbd5e1; }
.chip.mono { font-family: var(--mono); font-size: 10.5px; }
.site .dot.diamond { border-radius: 2px; transform: rotate(45deg) scale(.85); }
.coverage { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; color: var(--muted); }
.coverage summary { cursor: pointer; color: var(--text); font-weight: 500; }
.coverage h4 { margin: 10px 0 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.coverage ul { margin: 0; padding-left: 18px; }
.coverage p { margin: 8px 0 0; }
.muted { color: var(--muted); }
.login-card { gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
.field input { font: inherit; font-size: 16px; color: var(--text); background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-error { color: #fda4af; min-height: 1.2em; margin: 0; font-size: 13px; }
.pb-log.checklist li.todo { grid-template-columns: 1fr; opacity: 1; transform: none; }
.pb-log.checklist label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.pb-log.checklist input { accent-color: var(--accent); margin-top: 3px; }
.pb-log.checklist input:checked + span { color: var(--muted); text-decoration: line-through; }
.pb-actions { margin-top: 12px; }
.pb-actions[hidden] { display: none; }
.ghost-btn { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 8px; padding: 8px 12px; font-weight: 500; }

/* ---------- map popups / markers ---------- */
.maplibregl-popup-content { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; max-width: 280px; }
.maplibregl-popup-tip { border-top-color: var(--panel-solid) !important; border-bottom-color: var(--panel-solid) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; }
.pop-title { font-weight: 600; margin-bottom: 2px; }
.pop-sub { color: var(--muted); }
.maplibregl-ctrl-attrib { background: rgba(5,8,13,.6) !important; color: var(--muted); font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--muted); }
.maplibregl-ctrl-group { background: var(--panel-solid); border: 1px solid var(--line); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) opacity(.75); }

.storm-eye { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 700 13px var(--mono);
  background: radial-gradient(circle, rgba(244,63,94,.95) 0 30%, rgba(244,63,94,.25) 31% 60%, transparent 61%);
  animation: spin 3s linear infinite; }
.storm-eye span { animation: spin 3s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- playbook modal ---------- */
.modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(2,4,8,.6); backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.modal-card { width: min(560px, 100%); max-height: min(80vh, 720px); display: flex; flex-direction: column; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 17px; }
.close { border: 0; background: transparent; color: var(--muted); font-size: 16px; padding: 6px; }
.pb-sub { color: var(--muted); margin: 4px 0 12px; }
.pb-log { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; min-height: 0; flex: 1; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.pb-log li { display: grid; grid-template-columns: 20px 1fr; gap: 8px; opacity: 0; transform: translateY(4px); transition: opacity .25s, transform .25s; }
.pb-log li.in { opacity: 1; transform: none; }
.pb-log li .ic { text-align: center; }
.pb-log li.ok .ic { color: var(--r0); }
.pb-log li.warn .ic { color: var(--r2); }
.pb-log li.site-h { grid-template-columns: 1fr; font-weight: 600; margin-top: 8px; color: var(--text); }
.pb-log li .who { color: var(--muted); }
.pb-foot { color: var(--muted); font-size: 12px; margin: 14px 0 0; }

/* ---------- small screens: panel becomes a bottom sheet ---------- */
@media (max-width: 760px) {
  .topbar { top: 8px; left: 8px; right: 8px; flex-wrap: wrap; gap: 8px; padding: 8px; }
  .brand-text small { display: none; }
  .modes { order: 3; width: 100%; margin-left: 0; }
  .mode { flex: 1; justify-content: center; padding: 7px 6px; font-size: 13px; }
  .updated { margin-left: auto; font-size: 11px; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 46vh; border-radius: 16px 16px 0 0; padding: 6px 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); transition: max-height .25s; }
  .panel.is-open { max-height: 86vh; }
  .sheet-grip { display: grid; place-items: center; border: 0; background: transparent; padding: 6px 0 2px; position: sticky; top: -6px; z-index: 1; }
  .sheet-grip span { width: 44px; height: 5px; border-radius: 3px; background: rgba(148,163,184,.4); }
  .stat b { font-size: 20px; }
}

/* ---------- grouped layer panel ---------- */
.layer-panel { display: flex; flex-direction: column; gap: 8px; }
.lp-head { display: flex; align-items: center; gap: 8px; }
.lp-head h2 { margin-right: auto; }
.lp-count { font: 11px var(--mono); color: var(--muted); }
.lp-filter { font: inherit; font-size: 16px; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--text); }
@media (min-width: 761px) { .lp-filter { font-size: 13px; } }
.lp-filter:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.lp-player { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; background: rgba(196,181,253,.12); font-size: 12.5px; }
.lp-player[hidden] { display: none; }
.lp-groups { display: flex; flex-direction: column; gap: 6px; }
.lp-group { border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.02); }
.lp-group summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer; user-select: none; }
.lp-group summary::-webkit-details-marker { display: none; }
.lp-chev { width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; flex: none; margin-right: 2px; }
.lp-group[open] .lp-chev { transform: rotate(45deg); }
.lp-gname { font-weight: 600; font-size: 13px; }
.lp-group summary em { font-style: normal; font-size: 11px; color: var(--muted); margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.lp-note { margin: -2px 10px 6px 27px; font-size: 11px; color: var(--muted); }
.lp-group ul { list-style: none; margin: 0; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.lp-group li { padding: 5px 4px 5px 6px; border-radius: 7px; }
.lp-group li:hover { background: rgba(255,255,255,.035); }
.lp-group li label { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.lp-group li input { accent-color: var(--accent); margin: 0; flex: none; width: 15px; height: 15px; }
.lp-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--c); flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.lp-name { min-width: 0; }
.lp-group li small { display: block; margin: 1px 0 0 42px; font-size: 11px; color: #a5b4c8; }
.lp-group li small.muted { color: var(--muted); }
.lp-group li.locked label { cursor: default; color: var(--muted); }
.lp-group li.locked .lp-dot { opacity: .35; }
.lp-lock { font-size: 10px; }
.lp-switch { position: relative; width: 30px; height: 17px; flex: none; margin-left: 4px; }
.lp-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.lp-switch span { position: absolute; inset: 0; border-radius: 999px; background: rgba(148,163,184,.3); transition: background .15s; }
.lp-switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .15s; }
.lp-switch input:checked + span { background: var(--accent); }
.lp-switch input:checked + span::after { transform: translateX(13px); }
.lp-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.pop-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #fbbf24; margin-left: 4px; }
.pop-play { margin-top: 8px; border: 0; border-radius: 7px; padding: 6px 12px; background: #7c3aed; color: #fff; font-weight: 600; }

/* ---------- display styles (Talos) ---------- */
body[data-view="nvg"] #map canvas { filter: grayscale(1) brightness(1.35) sepia(1) hue-rotate(60deg) saturate(4.5) contrast(1.1); }
body[data-view="thermal"] #map canvas { filter: grayscale(1) contrast(1.6) brightness(1.1) sepia(1) hue-rotate(-40deg) saturate(7); }
body[data-view="crt"] #map canvas { filter: contrast(1.25) saturate(1.35) brightness(1.05); }
body[data-view="crt"] #map::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.22) 0 1px, transparent 1px 3px), radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.45)); }
body[data-view="nvg"] #map::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1; background: radial-gradient(ellipse at center, transparent 50%, rgba(0,20,0,.55)); }

/* ---------- Sites | Layers tabs ---------- */
.panel-tabs { display: flex; gap: 4px; padding: 3px; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; }
.ptab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 13px; }
.ptab.is-on { background: rgba(255,255,255,.09); color: var(--text); }
.ptab-n { font: 500 11px var(--mono); color: var(--accent); margin-left: 4px; }
[data-pane-body][hidden] { display: none !important; }
