:root {
  --bg: #050907;
  --surface: #09110e;
  --surface-2: #0e1814;
  --line: rgba(182, 224, 206, .14);
  --muted: #7e938a;
  --text: #edf8f3;
  --accent: #4df5a6;
  --accent-dim: #163d2d;
  --amber: #ffc45e;
  --danger: #ff4f65;
  --mono: "DM Mono", monospace;
  --sans: "Manrope", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100svh; background: radial-gradient(circle at 55% 0%, rgba(26, 80, 56, .13), transparent 38%), var(--bg); }
.topbar { height: 68px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 26px; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: .06em; font-size: 18px; }
.brand-light { color: var(--muted); font-weight: 400; margin-left: -3px; }
.brand-mark { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 18px rgba(77,245,166,.7); }
.demo-disclosure, .system-health { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; color: var(--muted); }
.demo-disclosure { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); padding: 8px 12px; }
.demo-disclosure span { width: 5px; height: 5px; border-radius: 50%; background: var(--amber); }
.system-health { justify-self: end; display: flex; gap: 10px; align-items: center; }
.system-health strong { color: var(--text); font-weight: 500; }
.health-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: breathe 1.8s ease-in-out infinite; }

.workspace { height: calc(100svh - 68px); display: grid; grid-template-columns: 300px minmax(520px, 1fr) 290px; }
.workflow, .incident-rail { padding: 28px 24px; background: rgba(7, 13, 11, .86); overflow-y: auto; }
.workflow { border-right: 1px solid var(--line); }
.incident-rail { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.eyebrow { color: var(--accent); font: 500 10px/1.2 var(--mono); letter-spacing: .15em; }
.workflow h1 { margin: 13px 0 8px; font-size: 30px; line-height: 1.05; letter-spacing: -.04em; }
.intro { margin: 0 0 26px; color: var(--muted); font-size: 13px; line-height: 1.6; }

.scenario-switcher { display: grid; border-top: 1px solid var(--line); margin-bottom: 27px; }
.scenario { border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; padding: 12px 0; color: var(--muted); cursor: pointer; transition: color .2s, padding .2s; }
.scenario span { display: inline-block; width: 28px; color: #4c6259; font: 10px var(--mono); }
.scenario:hover, .scenario.active { color: var(--text); padding-left: 5px; }
.scenario.active span { color: var(--accent); }

.config-flow { display: grid; gap: 4px; }
.flow-step { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 11px 0; opacity: .36; transition: opacity .3s; }
.flow-step.active, .flow-step.complete { opacity: 1; }
.step-index { width: 24px; height: 24px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; font: 10px var(--mono); }
.flow-step.active .step-index { color: #04110b; background: var(--accent); border-color: var(--accent); }
.flow-step.complete .step-index { border-color: var(--accent); color: var(--accent); }
.flow-step h2 { margin: 2px 0 4px; font-size: 13px; }
.flow-step p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.step-content { min-width: 0; }
.rule-options { display: grid; gap: 5px; margin: 10px 0; }
.rule { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 9px; text-align: left; font-size: 11px; cursor: pointer; }
.rule.active { color: var(--text); border-color: rgba(77,245,166,.6); background: rgba(77,245,166,.07); }
.delay-control { display: grid; grid-template-columns: 1fr auto; gap: 6px; color: var(--muted); font-size: 10px; }
.delay-control output { color: var(--text); font-family: var(--mono); }
input[type="range"] { grid-column: 1 / -1; accent-color: var(--accent); width: 100%; }
.sound-toggle { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 11px; cursor: pointer; }
.sound-toggle input { position: absolute; opacity: 0; }
.sound-toggle span { width: 29px; height: 16px; border-radius: 20px; border: 1px solid var(--line); position: relative; transition: .2s; }
.sound-toggle span::after { content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; left: 2px; top: 2px; background: var(--muted); transition: .2s; }
.sound-toggle input:checked + span { border-color: var(--accent); background: var(--accent-dim); }
.sound-toggle input:checked + span::after { transform: translateX(13px); background: var(--accent); }
.primary-action { width: 100%; border: 0; background: var(--accent); color: #04110b; padding: 14px; margin-top: 18px; font-size: 11px; font-weight: 700; letter-spacing: .08em; cursor: pointer; transition: transform .2s, filter .2s; }
.primary-action:not(:disabled):hover { transform: translateY(-2px); filter: brightness(1.08); }
.primary-action:disabled { opacity: .24; cursor: not-allowed; }
.text-action { width: 100%; border: 0; background: transparent; color: var(--muted); padding: 13px; font-size: 10px; cursor: pointer; }
.text-action:hover { color: var(--accent); }

.stage { min-width: 0; display: grid; grid-template-rows: 72px 1fr 62px; padding: 0 20px; }
.stage-head { display: flex; justify-content: space-between; align-items: center; }
.stage-head > div:first-child { display: grid; gap: 7px; }
.stage-head strong { font-size: 14px; font-weight: 500; }
.monitor-state { display: flex; align-items: center; gap: 7px; font: 10px var(--mono); color: var(--muted); }
.monitor-state i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.monitor-state.armed { color: var(--accent); }
.monitor-state.suspected { color: var(--amber); }
.monitor-state.alarm { color: var(--danger); }

.video-frame { position: relative; min-height: 0; overflow: hidden; background: #020403; border: 1px solid var(--line); isolation: isolate; }
.video-frame video { width: 100%; height: 100%; display: block; object-fit: cover; filter: saturate(.84) contrast(1.04); }
.video-fallback { position: absolute; inset: 0; z-index: -1; display: grid; place-items: center; color: var(--muted); font: 10px var(--mono); background: linear-gradient(120deg,#0c1712,#060907); }
.video-frame.video-error video { opacity: 0; }
.camera-meta { position: absolute; z-index: 8; left: 13px; right: 13px; bottom: 10px; display: flex; justify-content: space-between; color: rgba(236,248,243,.72); font: 9px var(--mono); letter-spacing: .08em; text-shadow: 0 1px 4px #000; }
.zone { position: absolute; z-index: 2; left: 14%; top: 48%; width: 60%; height: 43%; border: 1px solid rgba(77,245,166,.45); background: rgba(77,245,166,.025); pointer-events: none; }
.zone span { position: absolute; left: 7px; top: 6px; color: var(--accent); font: 9px var(--mono); }
.target-box, .secondary-box { position: absolute; z-index: 5; border: 1px solid var(--accent); background: rgba(77,245,166,.035); }
.target-box { left: 53%; top: 55%; width: 12%; height: 23%; cursor: pointer; padding: 0; transition: border-color .25s, box-shadow .25s, opacity .3s; }
.target-box:hover, .target-box.selected { box-shadow: 0 0 0 2px rgba(77,245,166,.25), 0 0 25px rgba(77,245,166,.18); }
.target-label, .secondary-box span { position: absolute; left: -1px; top: -24px; white-space: nowrap; color: #06110c; background: var(--accent); padding: 4px 6px; font: 10px var(--mono); }
.target-label b, .secondary-box b { font-weight: 500; opacity: .7; }
.secondary-box { left: 30%; top: 57%; width: 15%; height: 11%; border-color: rgba(110,210,255,.8); pointer-events: none; }
.secondary-box span { background: #6ed2ff; }
.corner { display: none; position: absolute; width: 7px; height: 7px; background: var(--accent); }
.target-box.selected .corner { display: block; }
.c1 { left:-4px;top:-4px}.c2{right:-4px;top:-4px}.c3{left:-4px;bottom:-4px}.c4{right:-4px;bottom:-4px}
.target-box.hidden-object { opacity: 0; }
.scanline { position: absolute; z-index: 3; inset: 0 0 auto; height: 1px; background: linear-gradient(90deg,transparent,var(--accent),transparent); opacity: .45; animation: scan 3.5s linear infinite; pointer-events: none; }
.alarm-wash { position: absolute; z-index: 6; inset: 0; opacity: 0; pointer-events: none; border: 0 solid var(--danger); }
.alarm-wash.active { animation: alarmPulse 1.05s ease-in-out infinite; }
.event-banner { position: absolute; z-index: 9; left: 28px; bottom: 35px; width: min(390px, calc(100% - 56px)); padding: 18px 20px; background: rgba(20, 5, 8, .93); border-left: 3px solid var(--danger); transform: translateY(24px); opacity: 0; pointer-events: none; transition: .35s cubic-bezier(.2,.8,.2,1); }
.event-banner.visible { transform: translateY(0); opacity: 1; }
.event-banner strong { display: block; margin: 4px 0; font-size: 22px; }
.event-banner p { margin: 0; color: #c8aeb2; font-size: 12px; }
.event-kicker { color: var(--danger); font: 9px var(--mono); letter-spacing: .15em; }

.transport { display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center; }
.transport-button { border: 0; background: transparent; color: var(--accent); font: 10px var(--mono); cursor: pointer; padding: 10px 0; }
.transport-button.subtle { color: var(--muted); }
.progress { height: 2px; background: var(--line); overflow: hidden; }
.progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .08s linear; }
#elapsed { color: var(--muted); font: 10px var(--mono); }

.rail-heading { display: grid; gap: 8px; padding-bottom: 23px; border-bottom: 1px solid var(--line); }
.rail-heading strong { font-size: 17px; }
.subject-panel { padding: 22px 0; border-bottom: 1px solid var(--line); }
.subject-top { display: flex; justify-content: space-between; color: var(--muted); font: 9px var(--mono); }
.subject-panel > strong { display: block; margin-top: 10px; font-size: 20px; }
.subject-panel p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.state-track { padding: 20px 0; display: grid; gap: 14px; border-bottom: 1px solid var(--line); }
.state-node { display: grid; grid-template-columns: 9px 1fr; gap: 10px; opacity: .3; transition: opacity .3s, transform .3s; }
.state-node > span { width: 7px; height: 7px; border-radius: 50%; margin-top: 4px; border: 1px solid var(--muted); }
.state-node strong, .state-node small { display: block; }
.state-node strong { font-size: 11px; }
.state-node small { color: var(--muted); font-size: 9px; margin-top: 2px; }
.state-node.active { opacity: 1; transform: translateX(4px); }
.state-node.active > span { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 12px rgba(77,245,166,.5); }
.state-node[data-state="suspected"].active > span { background: var(--amber); border-color: var(--amber); }
.state-node[data-state="alarm"].active > span { background: var(--danger); border-color: var(--danger); }
.event-log { padding-top: 20px; min-height: 0; flex: 1; overflow: hidden; }
.event-log-head { display: flex; justify-content: space-between; color: var(--muted); font: 9px var(--mono); }
.event-log-head button { border: 0; background: transparent; color: var(--muted); font: 9px var(--mono); cursor: pointer; }
.event-log ol { list-style: none; margin: 15px 0 0; padding: 0; display: grid; gap: 14px; max-height: 28vh; overflow-y: auto; }
.event-log li { display: grid; grid-template-columns: 42px 1fr; gap: 8px; font-size: 10px; color: var(--muted); animation: eventIn .3s ease-out; }
.event-log li time { font: 9px var(--mono); color: #52675e; }
.event-log li strong { color: var(--text); font-weight: 500; }
.event-log li.alert strong { color: var(--danger); }
.event-log li.empty { display: block; }
.evidence { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; opacity: .28; transition: opacity .35s; }
.evidence.visible { opacity: 1; }
.evidence-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 9px; }
.evidence-head span, .evidence-grid figcaption { color: var(--muted); font: 9px var(--mono); letter-spacing: .11em; }
.evidence-head strong { font-size: 10px; font-weight: 500; }
.evidence-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.evidence-grid figure { margin: 0; position: relative; background: #020403; border: 1px solid var(--line); overflow: hidden; }
.evidence-grid canvas { display: block; width: 100%; height: auto; filter: saturate(.8); }
.evidence-grid figcaption { position: absolute; left: 5px; bottom: 4px; padding: 2px 4px; background: rgba(0,0,0,.72); }
.privacy-note { padding-top: 16px; border-top: 1px solid var(--line); color: #53675f; font: 8px/1.5 var(--mono); text-transform: uppercase; letter-spacing: .08em; }

@keyframes breathe { 50% { opacity: .35; } }
@keyframes scan { from { top: 4%; } to { top: 96%; } }
@keyframes alarmPulse { 0%,100% { opacity: .08; border-width: 0; background: transparent; } 50% { opacity: .8; border-width: 6px; background: rgba(255,79,101,.08); } }
@keyframes eventIn { from { opacity: 0; transform: translateY(7px); } }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 270px minmax(470px,1fr); }
  .incident-rail { display: none; }
}
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  body { overflow-y: auto; }
  .topbar { grid-template-columns: 1fr auto; padding: 0 16px; }
  .demo-disclosure { display: none; }
  .system-health span:not(.health-dot) { display: none; }
  .workspace { height: auto; min-height: calc(100svh - 68px); grid-template-columns: 1fr; }
  .workflow { min-width: 0; border: 0; padding: 22px 18px 34px; }
  .workflow h1 { font-size: 27px; }
  .scenario-switcher { grid-template-columns: repeat(3,1fr); }
  .scenario { font-size: 10px; padding-right: 6px; }
  .scenario span { display: block; margin-bottom: 4px; }
  .stage { order: -1; height: auto; min-height: 0; padding: 0 10px; grid-template-rows: 62px auto 52px; }
  .video-frame { width: 100%; aspect-ratio: 16 / 9; }
  .video-frame video { object-fit: contain; }
  .rule, .scenario, .primary-action, .text-action { min-height: 44px; }
  .event-banner { left: 14px; bottom: 24px; width: calc(100% - 28px); padding: 14px 16px; }
  .event-banner strong { font-size: 17px; }
  .target-label, .secondary-box span { font-size: 8px; top: -20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
