/* SPEAR shared styles: tokens, controls, map objects */
:root {
  --bg: #0b1016;
  --panel: #111820;
  --panel-2: #17202b;
  --panel-3: #1e2935;
  --line: #263342;
  --text: #e6edf3;
  --muted: #8d9db1;
  --faint: #5b6b7e;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-ink: #04202e;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 12px; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: #253241; border-color: #33465a; }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
button.primary:hover, .btn.primary:hover { background: #5ccbfa; }
button.danger, .btn.danger { background: transparent; border-color: #7f1d1d; color: #fca5a5; }
button.danger:hover { background: #3b1111; }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; }
button.ghost:hover, .btn.ghost:hover { background: var(--panel-3); }
button.small { padding: 4px 8px; font-size: 12px; }
button.icon { padding: 6px; width: 32px; height: 32px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.field > span { font-weight: 600; letter-spacing: .02em; }
label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; font-size: 12px; color: var(--muted); }
.seg button.on { background: var(--panel-3); color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 3px 9px 3px 7px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer; user-select: none;
}
.chip .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.off { opacity: .42; text-decoration: line-through; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

.pill { display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--panel-3); letter-spacing: .02em; }
.pill.open { background: #3f1d1d; color: #fca5a5; }
.pill.resolved { background: #0f2e1c; color: #86efac; }
.pill.critical { background: #7f1d1d; color: #fff; }
.pill.high { background: #5a3410; color: #fdba74; }
.pill.low { background: #1e293b; color: #94a3b8; }
.pill.live { background: #7f1d1d; color: #fff; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* ---------- connection dot ---------- */
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); flex: none; }
.conn.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.conn.wait { background: var(--warn); animation: blink 1s infinite; }
.conn.down { background: var(--danger); }
@keyframes blink { 50% { opacity: .35; } }

/* ---------- toasts ---------- */
.toasts { position: fixed; z-index: 50; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: var(--shadow);
  cursor: pointer; animation: toast-in .18s ease-out;
}
.toast.alert { border-left-color: var(--danger); }
.toast.error { border-left-color: var(--danger); background: #2a1215; }
.toast b { display: block; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .9); display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 4px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; z-index: 40; background: rgba(3, 7, 12, .7); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); width: min(640px, 100%); padding: 20px; }
.modal h2 { margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- map objects ---------- */
.maplibregl-map { font: inherit; }
.maplibregl-ctrl-attrib { font-size: 10px; background: rgba(11, 16, 22, .7) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted); }
.maplibregl-ctrl-group { background: var(--panel-2) !important; border: 1px solid var(--line); }
.maplibregl-ctrl-group button { background: transparent; border: 0; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1); }

.m-unit { position: relative; width: 34px; height: 34px; cursor: pointer; }
.m-unit .ring {
  position: absolute; inset: 3px; border-radius: 50%;
  background: var(--c, #38bdf8); border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}
.m-unit .head {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0;
  transform: rotate(var(--rot, 0deg));
}
.m-unit .head::before {
  content: ""; position: absolute; left: -6px; top: -25px;
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 9px solid var(--c, #38bdf8);
  filter: drop-shadow(0 0 1px #fff);
}
.m-unit.nohead .head { display: none; }
.m-unit .lbl, .m-poi .lbl, .m-cam .lbl {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 1px;
  font-size: 11px; font-weight: 650; white-space: nowrap; color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000; pointer-events: none;
}
.m-unit.stale { opacity: .5; }
.m-unit.stale .ring { background: #64748b; }
.m-unit.me .ring { border-color: var(--accent); }
.labels-off .lbl { display: none; }

.m-poi { position: relative; width: 34px; height: 42px; cursor: pointer; }
.m-poi .pin {
  position: absolute; left: 2px; top: 0; width: 30px; height: 30px;
  background: var(--c, #64748b); border: 2px solid #fff;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .55);
}
.m-poi .ico { position: absolute; left: 2px; top: 0; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.m-poi.resolved { opacity: .55; filter: grayscale(.8); }
.m-poi.resolved .ico::after { content: "✓"; position: absolute; right: -6px; top: -6px; font-size: 11px; background: var(--ok); color: #03170a; border-radius: 50%; width: 15px; height: 15px; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.m-poi .badge { position: absolute; right: -4px; top: -6px; background: #fff; color: #000; font-size: 10px; font-weight: 800; border-radius: 8px; padding: 0 4px; line-height: 15px; }
.m-poi.critical .pin, .m-poi.pulse .pin { animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .75); } 70% { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
.m-poi.selected .pin, .m-unit.selected .ring, .m-cam.selected .box { outline: 3px solid var(--accent); outline-offset: 2px; }

.m-cam { position: relative; width: 32px; height: 32px; cursor: pointer; }
.m-cam .box { position: absolute; inset: 2px; border-radius: 8px; background: #111827; border: 2px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; box-shadow: 0 2px 6px rgba(0, 0, 0, .5); }
.m-cam .live { position: absolute; right: -3px; top: -3px; width: 11px; height: 11px; border-radius: 50%; background: var(--danger); border: 2px solid #fff; animation: blink 1.2s infinite; }

.m-me { width: 18px; height: 18px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(59, 130, 246, .25); }

.video-box { position: relative; background: #000; border-radius: var(--radius-sm); overflow: hidden; aspect-ratio: 16/9; }
.video-box video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.video-box .state { position: absolute; left: 8px; top: 8px; font-size: 11px; background: rgba(0, 0, 0, .6); padding: 2px 8px; border-radius: 999px; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); cursor: zoom-in; background: var(--panel-3); display: block; }

.empty { color: var(--faint); padding: 18px 8px; text-align: center; font-size: 13px; }
