:root {
  --bg: #e9ecef;
  --surface: #f4f5f7;
  --raised: #dde1e6;
  --well: #14181d;
  --line: #cfd4da;
  --text: #1b2027;
  --muted: #5d6874;
  --critical: #c8323a;
  --high: #c2600c;
  --medium: #9a7400;
  --info: #2b63c4;
  --ok: #1d8a52;
  --focus: #2b63c4;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
code { font-family: var(--mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* header + nav */
.brand-nav { display: flex; align-items: center; gap: 28px; min-width: 0; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 4px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; background: var(--surface); }
.nav a.active { color: var(--text); background: var(--raised); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 18px 32px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.brand-logo { height: 22px; width: auto; }
.brand:hover { text-decoration: none; }
.view { max-width: 1400px; margin: 0 auto; padding: 28px 32px 64px; }

/* drop zone */
.drop { position: relative; border: 1px dashed var(--line); border-radius: 6px; padding: 44px 32px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--info); background: var(--surface); }
.drop-title { margin: 0 0 8px; font-size: 22px; font-weight: 600; letter-spacing: -0.015em; }
.drop-sub { margin: 0 auto 22px; max-width: 62ch; color: var(--muted); }
.btn { background: var(--text); color: #fff; border: 0; border-radius: 4px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
.btn:hover { background: #000; }
.btn.quiet { background: var(--surface); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.btn.quiet:hover { color: var(--text); border-color: var(--muted); }
.drop-progress[hidden] { display: none; }
.drop-progress { display: flex; align-items: center; gap: 12px; margin-top: 22px; }
.bar { flex: 1; height: 4px; background: var(--raised); border-radius: 2px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--info); transition: width .2s; }
.pct { font-family: var(--mono); font-size: 13px; color: var(--muted); min-width: 4ch; text-align: right; }

/* jobs table */
.jobs { margin-top: 40px; }
.jobs-head, .events-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--surface); }
td.name { font-weight: 500; }
td.mono, .mono { font-family: var(--mono); font-size: 13px; }
td.right { text-align: right; }
.empty { padding: 36px 0; color: var(--muted); text-align: center; }

/* status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; line-height: 1.6; border: 1px solid var(--line); color: var(--muted); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.done { color: var(--ok); }
.pill.running { color: var(--info); }
.pill.queued { color: var(--muted); }
.pill.failed { color: var(--critical); }
.pill.running::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pill.running::before { animation: none; } .bar span { transition: none; } }
.progress-cell { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.progress-cell .bar { width: 110px; }

/* job detail */
.crumbs { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.crumbs .sep { margin: 0 8px; }
.crumbs span:last-child { color: var(--text); }
.job-meta { display: flex; flex-wrap: wrap; gap: 8px 20px; color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.job-meta .mono { color: var(--text); }
.job-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px; align-items: start; }
.player { background: var(--well); border-radius: 6px; overflow: hidden; aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center; }
.player video { width: 100%; height: 100%; display: block; background: var(--well); }
.processing { text-align: center; color: var(--muted); padding: 24px; width: min(420px, 90%); }
.processing .bar { margin: 14px 0 8px; }
.processing strong { color: var(--text); font-weight: 600; }
.failed-box { padding: 24px; color: var(--critical); }
.failed-box pre { color: var(--muted); font-size: 12px; white-space: pre-wrap; max-height: 200px; overflow: auto; margin: 10px 0 0; }

/* timeline — the signature element */
.timeline-wrap { margin: 14px 0 26px; }
.timeline { position: relative; height: 34px; background: var(--raised); border-radius: 4px; cursor: pointer; overflow: hidden; }
.timeline .seg { position: absolute; top: 0; bottom: 0; opacity: .85; border-left: 1px solid rgba(0,0,0,.35); }
.timeline .seg:hover { opacity: 1; }
.timeline .seg.critical { background: var(--critical); }
.timeline .seg.high { background: var(--high); }
.timeline .seg.medium { background: var(--medium); }
.timeline .seg.info { background: var(--info); opacity: .45; }
.timeline .seg.lane-1 { top: 50%; }
.timeline .seg.lane-0.has-lower { bottom: 50%; }
.timeline .playhead { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); pointer-events: none; }
.timeline .playhead::after { content: ""; position: absolute; top: 0; left: -4px; border: 5px solid transparent; border-top-color: var(--text); border-bottom: 0; }
.ticks { position: relative; height: 18px; margin-top: 4px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.ticks span { position: absolute; transform: translateX(-50%); }
.ticks span::before { content: ""; position: absolute; left: 50%; top: -5px; width: 1px; height: 4px; background: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* events */
.event { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; background: var(--surface); cursor: pointer; }
.event:hover { border-color: var(--muted); }
.event.suppressed { opacity: .55; }
.event img { width: 96px; height: 54px; object-fit: cover; border-radius: 3px; background: var(--well); display: block; }
.event .no-img { width: 96px; height: 54px; border-radius: 3px; background: var(--well); }
.event-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; row-gap: 2px; }
.event-title strong { white-space: nowrap; }
.event-title strong { font-weight: 600; }
.event-title .when { margin-left: auto; font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; }
.sev-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; background: var(--muted); }
.sev-dot.critical { background: var(--critical); } .sev-dot.high { background: var(--high); } .sev-dot.medium { background: var(--medium); } .sev-dot.info { background: var(--info); }
.sev { font-size: 12.5px; font-weight: 500; }
.sev.critical { color: var(--critical); } .sev.high { color: var(--high); } .sev.medium { color: var(--medium); } .sev.info { color: var(--info); }
.event-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.api { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.api.ok { color: var(--ok); } .api.bad { color: var(--critical); } .api.pending { color: var(--muted); }

/* request log */
.req { border-top: 1px solid var(--line); padding: 10px 0; }
.req:first-child { border-top: 0; padding-top: 0; }
.req-line { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.req-line .at { font-family: var(--mono); font-size: 13px; color: var(--muted); min-width: 7ch; }
.req-line .ev { font-weight: 500; min-width: 12ch; }
.chip { font-family: var(--mono); font-size: 12px; padding: 1px 8px; border-radius: 4px; border: 1px solid currentColor; line-height: 1.6; }
.chip.ok { color: var(--ok); } .chip.bad { color: var(--critical); }
.req-line .lat { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.linkbtn { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 4px; font-size: 13px; }
.linkbtn:hover { color: var(--text); background: var(--raised); }
.req-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.req-body[hidden] { display: none; }
.req-h { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 8px; align-items: baseline; }
.req-h code { color: var(--text); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.req-body pre { margin: 0; padding: 10px 12px; background: var(--raised); border-radius: 4px; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow: auto; color: var(--text); }
@media (max-width: 960px) { .req-body { grid-template-columns: 1fr; } }

/* panels */
.panel { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.panel h3 { margin-bottom: 12px; }
.spark { display: block; width: 100%; height: 72px; }
.spark path { fill: none; stroke: var(--info); stroke-width: 1.5; }
.spark .area { fill: var(--info); opacity: .12; stroke: none; }
.spark-note { font-size: 13px; color: var(--muted); margin-top: 6px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details pre { margin: 8px 0 0; padding: 10px 12px; background: var(--raised); border-radius: 4px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 260px; overflow: auto; color: var(--text); }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: #fff !important; color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--critical); }

@media (max-width: 960px) {
  .top { padding: 14px 16px; flex-direction: column; align-items: flex-start; gap: 6px; }
  .view { padding: 20px 16px 48px; }
  .job-grid { grid-template-columns: 1fr; }
  .drop { padding: 32px 18px; }
  .hide-sm { display: none; }
}

/* live mode — video + metrics primary, catalog and events in a sidebar */
.live-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 32px; align-items: start; }
.side-col { display: flex; flex-direction: column; gap: 26px; position: sticky; top: 20px; max-height: calc(100vh - 40px); }
.side-block { display: flex; flex-direction: column; }
.scenarios-block { flex: 0 0 auto; }                       /* the catalog never shrinks or gets covered */
.events-block { flex: 0 1 auto; min-height: 0; }
.events-block .live-events { overflow-y: auto; scrollbar-width: thin; min-height: 0; max-height: 40vh; padding-right: 2px; }
.events-block .live-history { overflow-y: auto; scrollbar-width: thin; min-height: 0; max-height: 30vh; padding-right: 2px; }
.collapse-head { display: flex; align-items: baseline; gap: 10px; width: 100%; background: none; border: 0; padding: 0; margin-bottom: 12px; cursor: pointer; color: var(--text); font: inherit; text-align: left; }
.history-head { margin: 14px 0 10px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.history-head:hover, .collapse-head:hover h3 { color: var(--info); }
.run-group { margin-bottom: 12px; }
.run-title { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); padding: 2px 0 6px; }
.run-title strong { color: var(--text); font-weight: 500; }
.collapse-head .chev { align-self: center; width: 7px; height: 7px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform 0.15s; }
.collapse-head[aria-expanded="true"] .chev { transform: rotate(45deg); }
.scenarios { display: flex; flex-direction: column; gap: 6px; }
.scn { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 12px; position: relative; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 6px; cursor: pointer; text-align: left; color: var(--text); font: inherit; }
.scn:hover { background: var(--surface); border-color: var(--line); }
.scn.active { background: var(--raised); border-color: var(--line); }
.scn.active::before { content: ""; position: absolute; left: -12px; top: 14px; bottom: 14px; width: 3px; border-radius: 2px; background: var(--info); }
.scn img { width: 84px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 3px; display: block; background: var(--well); }
.scn .scn-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scn .scn-sub { font-size: 12px; color: var(--muted); font-family: var(--mono); margin-top: 2px; }
.scn .rm { width: 24px; height: 24px; border-radius: 50%; border: 0; background: transparent; font: inherit; color: var(--muted); font-size: 15px; line-height: 24px; text-align: center; cursor: pointer; visibility: hidden; }
.scn:hover .rm { visibility: visible; }
.scn .rm:hover { color: var(--text); background: var(--raised); }
.scn.add { grid-template-columns: 84px 1fr; border: 1px dashed var(--line); color: var(--muted); margin-top: 4px; }
.scn.add:hover, .scn.add.over { border-color: var(--info); color: var(--text); background: transparent; }
.scn.add .plus { width: 84px; aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center; font-size: 22px; border-radius: 3px; background: var(--raised); }
.scn.add .bar { width: 100%; margin-top: 6px; }
.stage { position: relative; background: var(--well); border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center; }
.stage img { width: 100%; height: 100%; object-fit: contain; display: block; }
.stage-empty { color: #9aa4b1; padding: 24px; text-align: center; max-width: 52ch; line-height: 1.6; }
.stage-empty span { color: #eef1f4; }
.stage .overlay { position: absolute; left: 12px; right: 12px; bottom: 10px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
.live-badge { display: inline-flex; align-items: center; gap: 7px; background: rgba(12, 16, 20, .78); color: #eef1f4; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.live-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--critical); animation: pulse 1.1s ease-in-out infinite; }
.live-badge.off::before { background: var(--muted); animation: none; }
.stage .clock { background: rgba(12, 16, 20, .78); font-family: var(--mono); font-size: 12.5px; padding: 4px 10px; border-radius: 999px; color: #eef1f4; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; min-width: 0; }
.tile .v { font-family: var(--mono); font-size: 30px; font-weight: 500; line-height: 1.1; letter-spacing: -0.02em; }
.tile .k { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tile.alert .v { color: var(--high); }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-controls { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.live-controls[hidden] { display: none; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; margin-left: 6px; }
.live-events .event { grid-template-columns: 1fr; cursor: default; }
.live-events .event:hover { border-color: var(--line); }
.loop-mark { color: var(--muted); font-size: 12.5px; text-align: center; padding: 6px 0 10px; }
.api.sending { color: var(--info); display: inline-flex; align-items: center; gap: 6px; }
.api.sending::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 0.9s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .live-badge::before, .api.sending::before { animation: none; } }
@media (max-width: 1100px) {
  .live-layout { grid-template-columns: 1fr; }
  .side-col { position: static; max-height: none; }
  .scenarios { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

/* live chart */
.chart-panel[hidden] { display: none; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 118px; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font: 11px var(--mono); }
.chart .lbl.k { font-family: var(--sans); font-size: 12px; }
.chart .line { fill: none; stroke: var(--info); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: var(--info); opacity: .12; }
.chart .strip-smoke { fill: var(--high); opacity: .85; }
.chart .strip-fire { fill: var(--critical); opacity: .85; }
.chart .strip-bg { fill: var(--raised); }
.chart .loopline { stroke: var(--muted); stroke-dasharray: 3 3; stroke-width: 1; }
.chart .dot { fill: var(--info); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--text); stroke-width: 1; opacity: .5; }
.chart .hit { position: absolute; inset: 0; cursor: crosshair; }
.chart .tip { position: absolute; top: 0; transform: translate(-50%, -100%); background: var(--raised); border: 1px solid var(--line); border-radius: 4px; padding: 6px 9px; font: 12px var(--mono); color: var(--text); pointer-events: none; white-space: nowrap; }
.api.suppressed { color: var(--muted); }
.timeline .seg.suppressed { opacity: .3; }

/* per-scenario rules */
.rules-panel .form { display: flex; flex-wrap: wrap; gap: 12px 22px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field input[type=number] { width: 92px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--text); font: 14px var(--mono); }
.field input[type=number]:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.field.check { flex-direction: row; align-items: center; gap: 8px; padding-bottom: 8px; }
.rules-panel .btn { padding: 8px 14px; }
.rules-panel .note { font-size: 13px; color: var(--muted); margin-top: 10px; }
