:root {
  --bg: #0f1317; --panel: #171c22; --panel2: #1f262e; --line: #2c353f; --text: #e6eaee; --muted: #8b97a3;
  --accent: #4fb3ff; --accent-ink: #06202f; --ok: #50dc82; --err: #ff6b6b; --motion: #ff9f43; --rec: #2f6f9f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { display: flex; flex-direction: column; min-height: 100%; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 8px 0; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; white-space: nowrap; }
.spacer { flex: 1; }

button, .btn, select, input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
button, .btn { cursor: pointer; display: inline-block; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--err); }
button.mini, a.mini { padding: 2px 8px; font-size: 12px; border-radius: 5px; background: rgba(15,19,23,.7); border: 1px solid var(--line); color: var(--text); cursor: pointer; }
button.icon { border: 0; background: none; font-size: 16px; }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; vertical-align: -3px; accent-color: var(--accent); }
input[type=range] { padding: 0; flex: 1; accent-color: var(--accent); }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

header.top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { color: var(--text); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--accent); display: inline-block; position: relative; }
.logo::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--accent); }
header.top nav { display: flex; gap: 4px; }
header.top nav a { color: var(--muted); padding: 6px 12px; border-radius: 6px; }
header.top nav a.active { color: var(--text); background: var(--panel2); }
main { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 12px 14px; gap: 10px; }
.toolbar, .controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.controls.small { gap: 6px; font-size: 12px; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px 10px; }
.empty.small { padding: 18px 10px; }

/* live */
.grid { display: grid; gap: 6px; flex: 1; min-height: 0; align-content: start; background: var(--bg); }
.grid:fullscreen { padding: 6px; align-content: center; }
.tile { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; border: 1px solid var(--line); }
.grid.single .tile { max-height: calc(100vh - 120px); margin: 0 auto; width: 100%; max-width: calc((100vh - 120px) * 16 / 9); }
.player { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.player.zoomed, .stage.zoomed { cursor: grab; }
.player video, .player img.still, .stage video { width: 100%; height: 100%; object-fit: contain; display: block; transform-origin: center; background: #000; }
.player img.still { position: absolute; inset: 0; display: none; }
.tile-msg, .stage-msg { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; text-align: center; pointer-events: none; }
.tile-top { position: absolute; top: 6px; left: 8px; right: 8px; display: flex; align-items: center; gap: 6px; pointer-events: none; text-shadow: 0 1px 2px #000; }
.tile-name { font-weight: 600; }
.tile-actions { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .tile-actions, .tile:focus-within .tile-actions { opacity: 1; }
@media (hover: none) { .tile-actions { opacity: 1; } }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; pointer-events: auto; }
.dot.on { background: var(--ok); } .dot.rec { background: #ff4d4d; box-shadow: 0 0 0 2px rgba(255,77,77,.3); } .dot.off { background: #666; }
.badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; letter-spacing: .04em; }
.badge.motion { background: var(--motion); color: #2a1700; text-shadow: none; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); border-color: #2c6b45; } .pill.err { color: var(--err); border-color: #7a3535; }

/* review */
.review { display: flex; gap: 12px; flex: 1; min-height: 0; }
.review-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.stage { position: relative; background: #000; border-radius: 8px; overflow: hidden; flex: 1; min-height: 200px; border: 1px solid var(--line); touch-action: none; }
.stage video { position: absolute; inset: 0; }
.stage-msg { top: 50%; bottom: auto; transform: translateY(-50%); background: none; font-size: 14px; color: var(--muted); }
.time-label { font-variant-numeric: tabular-nums; font-weight: 600; }
button.play { min-width: 70px; }
fieldset > button { align-self: flex-start; }
.tl-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0; overflow: hidden; }
canvas.timeline { width: 100%; height: 74px; display: block; cursor: pointer; touch-action: none; }
.hint { color: var(--muted); font-size: 12px; }
aside.events { width: 300px; flex: none; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-height: 0; max-height: calc(100vh - 80px); }
.ev-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ev-head select { padding: 3px 6px; font-size: 12px; }
.ev-list { overflow-y: auto; flex: 1; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.ev { display: flex; gap: 8px; padding: 5px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: center; }
.ev:hover { background: var(--panel2); }
.ev.active { border-color: var(--motion); background: var(--panel2); }
.ev img, .ev .noimg { width: 96px; height: 54px; object-fit: cover; border-radius: 4px; background: #000; flex: none; }
.ev-time { font-weight: 600; font-variant-numeric: tabular-nums; }
button.more { margin: 6px; }
@media (max-width: 900px) { .review { flex-direction: column; } aside.events { width: auto; max-height: 50vh; } .stage { min-height: 0; flex: none; aspect-ratio: 16 / 9; } .hint { display: none; } }

/* pages, tables, forms */
.page, .settings { max-width: 1000px; width: 100%; margin: 0 auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 10px; }
.subnav { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.subnav a { color: var(--muted); padding: 8px 12px; border-bottom: 2px solid transparent; }
.subnav a.active { color: var(--text); border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.form { display: flex; flex-direction: column; gap: 12px; } .form.narrow { max-width: 380px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.label { color: var(--muted); font-size: 12px; }
.field input, .field select { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; } .row.tight { flex-wrap: nowrap; align-items: center; gap: 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 10px; margin: 0; min-width: 0; }
legend { color: var(--muted); padding: 0 6px; font-size: 12px; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.checks { display: flex; flex-direction: column; gap: 6px; padding-left: 4px; } .checks.inline { flex-direction: row; flex-wrap: wrap; gap: 12px; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.devices { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.devices p { margin: 0; } .devices td { padding: 5px 8px 5px 0; } .devices tr:last-child td { border-bottom: 0; }
ul.plain { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; } ul.plain code { word-break: break-all; } fieldset > p { margin: 0; }
pre.log { margin: 0; max-height: 220px; overflow: auto; font-size: 11px; color: var(--muted); white-space: pre-wrap; }
.mask-box { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 6px; overflow: hidden; max-width: 560px; user-select: none; touch-action: none; }
.mask-box img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.mask-grid { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(16, 1fr); grid-template-rows: repeat(9, 1fr); }
.mask-cell { border: 1px solid rgba(255,255,255,.12); cursor: pointer; }
.mask-cell.on { background: rgba(255, 80, 80, .5); }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow-y: auto; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: 100%; max-width: 480px; }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px; }
.clip-video { width: 100%; max-height: 70vh; background: #000; border-radius: 6px; }
.auth-admin { display: flex; flex-direction: column; gap: 12px; } .auth-admin.sep { border-top: 1px solid var(--line); padding-top: 14px; }
.auth-problem { margin: 0; padding: 9px 12px; border: 1px solid #7a3535; border-radius: 6px; color: var(--err); }
.google-btn { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 9px 12px; background: #fff; color: #1f1f1f; border: 1px solid #747775; border-radius: 6px; font-weight: 500; text-decoration: none; }
.google-btn:hover { background: #f2f2f2; } .google-btn svg { width: 18px; height: 18px; }
.auth { margin: 12vh auto 0; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
#toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 28px)); }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; padding: 9px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.ok { border-left-color: var(--ok); } .toast.err { border-left-color: var(--err); }
@media (max-width: 600px) { header.top { gap: 6px; padding: 6px 8px; flex-wrap: wrap; } .who { display: none; } main { padding: 8px; } .grid { grid-template-columns: 1fr !important; } }
ul.steps { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
fieldset p { margin: 0; }
summary { cursor: pointer; color: var(--accent); }
