/* Argus — surveillance ops console.
   Dark, dense, monospace timestamps, semantic green/amber/red only.
   No decorative motion outside the REC pulse and NO-SIGNAL CRT flicker. */
:root {
  --bg: #0a0e13;
  --bg-tile: #050709;
  --bg-tile-fail: #000;
  --fg: #d6dde5;
  --muted: #6b7785;
  --border: #1c232c;
  --accent: #4ade80;
  --warn: #f59e0b;
  --err: #ef4444;
  --rec: #ef4444;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  font: 13px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  height: 100%; overflow: hidden;
}

header {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .9rem; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #0d131a 0%, #0a0e13 100%);
}
header img { width: 22px; height: 22px; }
h1 {
  margin: 0; font-size: .95rem; letter-spacing: .12em;
  text-transform: uppercase; font-weight: 600; color: var(--accent);
}
.ph {
  font-size: .62rem; letter-spacing: .12em; color: var(--muted);
  padding: .15rem .4rem; border: 1px solid var(--border); border-radius: 3px;
}
.header-right { margin-left: auto; }
.live-clock {
  font-size: .8rem; color: var(--muted);
  letter-spacing: .04em; font-variant-numeric: tabular-nums;
}

.status {
  font-size: .72rem; color: var(--muted);
  padding: .35rem .9rem; border-bottom: 1px solid var(--border);
  background: #070a0e;
}
.status .ok { color: var(--accent); }
.status .warn { color: var(--warn); }

main {
  display: grid; gap: 6px;
  padding: 6px;
  height: calc(100vh - 70px);
}
main.layout-grid {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
main.layout-focus {
  grid-template-columns: 1fr;
  grid-template-rows: 3fr 1fr;
}
.strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  min-height: 0;
}

.tile {
  position: relative; overflow: hidden;
  background: var(--bg-tile); border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  outline: 1px solid transparent;
  transition: outline-color 140ms ease, box-shadow 140ms ease;
  min-height: 0; min-width: 0;
}
.tile:hover { outline-color: var(--accent); }
.tile:focus-visible { outline-color: var(--accent); outline-width: 2px; }
.tile.focused {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 1px rgba(74, 222, 128, .35), 0 0 18px rgba(74, 222, 128, .18);
}
.tile.unmuted {
  outline-color: var(--accent);
}
.tile.rewound {
  outline: 2px solid var(--warn);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, .35), 0 0 16px rgba(245, 158, 11, .18);
}
.tile.rewound.focused {
  /* When a rewound camera is also focused, prefer the rewound (amber)
     outline — that's the more important signal (you're not watching live). */
  outline: 2px solid var(--warn);
}

.tile video.feed {
  width: 100%; height: 100%; object-fit: cover;
  display: block; background: #000;
}
.tile video.feed.failed { display: none; }

.tile-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(0,0,0,.55) 0%, rgba(0,0,0,0) 22%,
      rgba(0,0,0,0) 78%, rgba(0,0,0,.65) 100%);
}
.ovl-top, .ovl-bot {
  display: flex; align-items: center; gap: .55rem;
  padding: .4rem .55rem;
  font-size: .68rem; letter-spacing: .04em;
  color: #f4f7fb;
  text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
.cam-id { font-weight: 700; color: var(--accent); }
.cam-label { text-transform: uppercase; }
.cam-loc { color: #cbd5e1; }
.cam-ts { margin-left: auto; font-variant-numeric: tabular-nums; }

.signal-bars { display: inline-flex; gap: 2px; align-items: flex-end; }
.signal-bars i {
  display: inline-block; width: 3px; background: var(--accent); border-radius: 1px;
}
.signal-bars i:nth-child(1) { height: 4px; }
.signal-bars i:nth-child(2) { height: 7px; }
.signal-bars i:nth-child(3) { height: 10px; }
.signal-bars i:nth-child(4) { height: 13px; }

/* Phase 3: AUD badge (shown only on tile.unmuted). The element is
   always present in the DOM (empty when muted) so layout doesn't jump
   when audio toggles. */
.audio-state {
  margin-left: auto;
  font-weight: 700; color: var(--accent);
  letter-spacing: .14em;
  padding: 0 .3rem; min-width: 1.6rem;
  border: 1px solid transparent; border-radius: 2px;
}
.tile.unmuted .audio-state {
  border-color: var(--accent);
  background: rgba(74, 222, 128, .12);
}
/* If AUD is shown, the signal-bars should drop the auto-right-shove
   to keep both visible. Match by reverting margin on signal-bars when
   AUD is non-empty (it's the previous sibling). */
.audio-state:not(:empty) + .signal-bars { margin-left: 0; }

.rec-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-weight: 700; color: var(--rec);
}
.rec-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--rec);
  animation: rec-pulse 1.4s infinite ease-in-out;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(239, 68, 68, .7); }
  50%      { opacity: .4; box-shadow: 0 0 0 4px rgba(239, 68, 68, 0); }
}

/* Phase 3: REWOUND badge replaces the REC dot when a camera is in
   playback. Amber so the operator can't miss they're not watching live. */
.playback-state {
  display: inline-flex; align-items: center; gap: .25rem;
  font-weight: 700; color: var(--warn);
  letter-spacing: .04em;
  padding: 0 .35rem;
  border: 1px solid var(--warn); border-radius: 2px;
  background: rgba(245, 158, 11, .12);
}
.playback-state:empty {
  display: none;
}
.pb-icon { font-size: .82rem; line-height: 1; }

/* Strip thumbnails sit smaller; trim overlay padding for legibility. */
.strip .tile .ovl-top, .strip .tile .ovl-bot {
  padding: .25rem .4rem; font-size: .62rem;
}
.strip .tile .signal-bars i:nth-child(1) { height: 3px; }
.strip .tile .signal-bars i:nth-child(2) { height: 5px; }
.strip .tile .signal-bars i:nth-child(3) { height: 7px; }
.strip .tile .signal-bars i:nth-child(4) { height: 9px; }

/* "No signal" fallback — visible only when .tile.no-signal */
.no-signal-overlay {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg-tile-fail);
  pointer-events: none; overflow: hidden;
}
.tile.no-signal .no-signal-overlay { display: flex; }
.tile.no-signal .rec-badge { color: var(--muted); }
.tile.no-signal .rec-dot {
  background: var(--muted); animation: none; box-shadow: none;
}
.tile.no-signal .signal-bars i { background: var(--muted); opacity: .25; }
.tile.no-signal .cam-id { color: var(--muted); }
.tile.no-signal .audio-state,
.tile.no-signal .playback-state { display: none; }

.ns-grid {
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.04) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.04) 0 1px, transparent 1px 3px),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.05) 0%, transparent 70%);
  animation: ns-flicker 4s infinite steps(20, end);
}
@keyframes ns-flicker {
  0%, 100% { opacity: .9; }
  10%      { opacity: .55; }
  30%      { opacity: 1; }
  50%      { opacity: .7; }
  70%      { opacity: .95; }
}
.ns-text {
  position: relative; font-size: 1rem; font-weight: 700;
  letter-spacing: .25em; color: var(--err);
  text-shadow: 0 0 6px rgba(239, 68, 68, .5);
  padding: .25rem .6rem;
}
.ns-sub {
  position: relative; font-size: .68rem; color: var(--muted);
  letter-spacing: .12em; margin-top: .3rem;
}
.strip .tile .ns-text { font-size: .76rem; letter-spacing: .18em; }
.strip .tile .ns-sub  { font-size: .56rem; }

/* ----- Phase 4: snapshot tray ----------------------------------------
   Floating bottom-right toasts confirming each capture. Auto-dismiss
   after 8 s (scheduled by bridge.js::snapshot); manual ×-dismiss too.
   The tray sits outside #grid so layout transitions don't disturb it. */
.snapshot-tray {
  position: fixed; right: 12px; bottom: 12px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
  pointer-events: none;
  max-width: 320px;
}
.snap-card {
  pointer-events: auto;
  width: 280px;
  background: #0d131a;
  border: 1px solid var(--accent);
  border-radius: 4px;
  box-shadow:
    0 6px 28px rgba(0, 0, 0, .55),
    0 0 0 1px rgba(74, 222, 128, .25);
  overflow: hidden;
  animation: snap-in 240ms cubic-bezier(.2, .7, .3, 1);
}
@keyframes snap-in {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.snap-thumb {
  width: 100%; aspect-ratio: 16 / 9; object-fit: cover;
  display: block; background: #000;
}
.snap-meta {
  display: flex; align-items: center; gap: .45rem;
  padding: .4rem .55rem;
  font-size: .68rem; letter-spacing: .03em;
}
.snap-icon { color: var(--accent); font-size: .8rem; line-height: 1; }
.snap-label {
  flex: 1; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.snap-x {
  background: transparent; border: 0;
  color: var(--muted); font: inherit;
  font-size: 1rem; line-height: 1;
  cursor: pointer; padding: 0 .35rem;
}
.snap-x:hover { color: var(--accent); }

/* ----- Phase 5: AI alert tray ---------------------------------------- */
.alert-tray {
  position: fixed; top: 70px; right: 12px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 90;
  max-width: 360px;
  pointer-events: none;
}
.alert-card {
  pointer-events: auto;
  width: 340px;
  background: #0d131a;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .04);
  overflow: hidden;
  position: relative;
  animation: alert-in 280ms cubic-bezier(.2, .7, .3, 1);
}
@keyframes alert-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.alert-card.sev-high {
  border-color: var(--err);
  animation:
    alert-in 280ms cubic-bezier(.2, .7, .3, 1),
    alert-attention 1.4s 3 ease-out 280ms;
}
.alert-card.sev-med  { border-color: var(--warn); }
.alert-card.sev-low  { border-color: var(--muted); }
@keyframes alert-attention {
  0%, 100% { box-shadow: 0 8px 32px rgba(0, 0, 0, .6), 0 0 0 1px rgba(239, 68, 68, .25); }
  50%      { box-shadow: 0 8px 32px rgba(0, 0, 0, .6), 0 0 0 4px rgba(239, 68, 68, .55); }
}
.alert-stripe {
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--err);
}
.alert-card.sev-med .alert-stripe { background: var(--warn); }
.alert-card.sev-low .alert-stripe { background: var(--muted); }
.alert-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .4rem .65rem .25rem .85rem;
  font-size: .62rem; letter-spacing: .12em;
}
.alert-kind { color: var(--err); font-weight: 700; }
.alert-card.sev-med .alert-kind { color: var(--warn); }
.alert-card.sev-low .alert-kind { color: var(--muted); }
.alert-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.alert-body { padding: .15rem .65rem .35rem .85rem; }
.alert-body strong { font-size: .78rem; color: var(--fg); font-weight: 600; }
.alert-summary { font-size: .72rem; color: var(--muted); margin-top: .25rem; line-height: 1.4; }
.alert-actions {
  display: flex; gap: .35rem;
  padding: .35rem .65rem .55rem .85rem;
  flex-wrap: wrap;
}
.alert-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  font: inherit;
  font-size: .65rem;
  letter-spacing: .04em;
  padding: .28rem .6rem;
  border-radius: 2px;
  cursor: pointer;
}
.alert-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.alert-actions button.ghost { color: var(--muted); }
.alert-actions button.ghost:hover { color: var(--warn); border-color: var(--warn); }

/* Status-line .err helper (alert count) */
.status .err { color: var(--err); font-weight: 700; }

/* Per-tile alert pip — small dot in the top overlay strip */
.alert-pip { display: inline-block; margin-left: .25rem; min-width: 0.8rem; font-weight: 700; }
.alert-pip.active.sev-high {
  color: var(--err);
  animation: pip-pulse 1.2s infinite ease-in-out;
}
.alert-pip.active.sev-med { color: var(--warn); }
.alert-pip.active.sev-low { color: var(--muted); }
@keyframes pip-pulse {
  0%, 100% { opacity: 1; text-shadow: 0 0 4px rgba(239, 68, 68, .8); }
  50%      { opacity: .5; text-shadow: 0 0 0 rgba(239, 68, 68, 0); }
}

/* ----- Phase 5: bounding-box overlays -------------------------------- */
.analytics-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 2;
}
.box-wrap {
  position: absolute;
  pointer-events: none;
}
.box {
  position: absolute; inset: 0;
  border: 1px solid var(--accent);
  border-radius: 1px;
  opacity: .85;
}
.box.box-vehicle { border-color: var(--warn); }
.box.box-plate   { border-color: #60a5fa; }
.box.box-zone    { border: 1px dashed var(--warn); }
.box.alert-active.sev-high {
  border-color: var(--err);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, .4), inset 0 0 6px rgba(239, 68, 68, .25);
  animation: box-pulse 1.2s infinite ease-in-out;
}
.box.alert-active.sev-med {
  border-color: var(--warn);
  animation: box-pulse 1.4s infinite ease-in-out;
}
.box.alert-active.sev-low {
  border-color: var(--muted);
}
@keyframes box-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .45; }
}
.box-label {
  position: absolute;
  bottom: 100%; left: 0;
  font-size: .58rem;
  letter-spacing: .04em;
  color: var(--accent);
  background: rgba(0, 0, 0, .72);
  padding: 1px 4px;
  white-space: nowrap;
  pointer-events: none;
  font-family: ui-monospace, Menlo, monospace;
  border-bottom: 1px solid currentColor;
}
.box-wrap.kind-vehicle .box-label,
.box-wrap.kind-zone    .box-label { color: var(--warn); }
.box-wrap.kind-plate   .box-label { color: #60a5fa; }
.strip .tile .box-label { font-size: .48rem; padding: 0 3px; }
