:root {
  --bg: #0b0f14; --panel: #121820; --panel2: #18202a; --line: #232d39; --line2: #2e3a48;
  --text: #e6edf3; --dim: #8b98a7; --faint: #5d6b7a;
  --amber: #f5a524; --red: #ef4444; --red-bg: #3a1216; --orange: #f97316; --green: #22c55e; --blue: #3b82f6;
  --p5: #ef4444; --p4: #f97316; --p3: #f5a524; --p2: #3b82f6; --p1: #64748b;
  --r: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }
a { color: var(--amber); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; } h3 { font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.mono { font-family: var(--mono); font-size: 12px; }
.dim { color: var(--dim); } .faint { color: var(--faint); }
.row { display: flex; gap: 8px; align-items: center; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; gap: 8px; }
.sp { justify-content: space-between; }

/* shell */
.shell { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.top { display: flex; align-items: center; gap: 14px; padding: 0 14px; height: 48px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; letter-spacing: .08em; }
.brand img { width: 22px; height: 22px; }
.nav { display: flex; gap: 2px; overflow-x: auto; }
.nav a { color: var(--dim); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a.on { color: var(--text); background: var(--panel2); }
.nav .badge { margin-left: 6px; }
.top .right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.conn.ok { background: var(--green); }
main { overflow: hidden; min-height: 0; }
.page { height: 100%; overflow: auto; padding: 16px; }

/* controls */
.btn { background: var(--panel2); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 12px; }
.btn:hover { border-color: var(--dim); }
.btn.pri { background: var(--amber); border-color: var(--amber); color: #111; font-weight: 600; }
.btn.danger { background: var(--red-bg); border-color: #7f1d1d; color: #fecaca; }
.btn.ok { background: #0f2a1a; border-color: #166534; color: #bbf7d0; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 8px; min-width: 0; }
textarea { width: 100%; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); }
label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: end; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.stack > * + * { margin-top: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line2); color: var(--dim); white-space: nowrap; }
.badge.red { background: var(--red-bg); border-color: #7f1d1d; color: #fecaca; }
.badge.green { background: #0f2a1a; border-color: #166534; color: #bbf7d0; }
.badge.amber { background: #33240a; border-color: #854d0e; color: #fde68a; }
.badge.blue { background: #0f1f3a; border-color: #1e40af; color: #bfdbfe; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.online { background: var(--green); } .dot.offline { background: var(--red); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--dim); font-size: 12px; }
.empty { color: var(--faint); padding: 30px; text-align: center; }
.secret { background: #1f1a0b; border: 1px dashed #854d0e; border-radius: 6px; padding: 10px; word-break: break-all; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.err { border-color: #7f1d1d; background: var(--red-bg); }

/* queue */
.queue { display: grid; grid-template-columns: 380px 1fr; height: 100%; }
.qlist { border-right: 1px solid var(--line); overflow: auto; background: var(--panel); }
.qhead { position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 12px; }
.qitem { display: grid; grid-template-columns: 4px 64px 1fr; gap: 10px; padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.qitem:hover { background: var(--panel2); }
.qitem.sel { background: #1c2632; }
.qitem .bar { border-radius: 0 3px 3px 0; }
.qitem .thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 4px; background: #000; }
.qitem .t1 { display: flex; gap: 6px; align-items: center; font-weight: 600; }
.qitem .t2 { color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qitem.new .t1::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.age { font-variant-numeric: tabular-nums; margin-left: auto; font-size: 12px; color: var(--dim); font-weight: 400; }
.age.late { color: var(--red); font-weight: 600; }
.p5 { background: var(--p5); } .p4 { background: var(--p4); } .p3 { background: var(--p3); } .p2 { background: var(--p2); } .p1 { background: var(--p1); }
.detail { overflow: auto; padding: 16px; }
.dgrid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 14px; }
.media { background: #000; border-radius: var(--r); overflow: hidden; aspect-ratio: 16/9; position: relative; }
.media img, .media video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.media .ov { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button { background: none; border: 1px solid transparent; color: var(--dim); padding: 4px 10px; border-radius: 6px; }
.tabs button.on { background: var(--panel2); border-color: var(--line2); color: var(--text); }
.actions { position: sticky; bottom: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.log { font-size: 12px; }
.log div { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.instructions { white-space: pre-wrap; background: #1f1a0b; border: 1px solid #3f3210; border-radius: 6px; padding: 10px; }
.contact { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.minicams { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.minicams button { padding: 0; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; background: #000; text-align: left; }
.minicams button.on { border-color: var(--amber); }
.minicams img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.minicams span { display: block; font-size: 11px; padding: 3px 6px; background: var(--panel2); }
.frames .fstrip { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 8px; scrollbar-width: thin; }
.fstrip button { flex: 0 0 104px; padding: 0; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; background: #000; text-align: left; }
.fstrip button.on { border-color: var(--amber); }
.fstrip img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.fstrip span { display: flex; align-items: center; gap: 4px; font: 11px var(--mono); padding: 2px 5px; background: var(--panel2); }
.fstrip .hit { width: 7px; height: 7px; border-radius: 50%; background: var(--red); flex: none; }
.following { color: var(--red); animation: blink 1.6s infinite; }

/* wall */
.wall { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.tile { background: #000; border-radius: 6px; overflow: hidden; position: relative; aspect-ratio: 16/9; border: 1px solid var(--line); }
.tile.alarm { outline: 3px solid var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { outline-color: transparent; } }
.tile video, .tile img { width: 100%; height: 100%; object-fit: contain; }
.tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; background: linear-gradient(transparent, rgba(0,0,0,.85)); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.tile .off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); }
.fage { position: absolute; left: 8px; top: 8px; padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.7); font-size: 11px; color: #ddd; font-family: ui-monospace, monospace; }
.fage.stale { background: var(--red-bg); color: #fecaca; border: 1px solid #7f1d1d; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }

@media (max-width: 900px) {
  .queue { grid-template-columns: 1fr; }
  .queue.has-sel .qlist { display: none; }
  .queue:not(.has-sel) .detail { display: none; }
  .dgrid { grid-template-columns: 1fr; }
  .top { gap: 8px; padding: 0 8px; } .brand span { display: none; }
  .wall { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  .hide-m { display: none !important; }
}
@media (min-width: 901px) { .show-m { display: none !important; } }
