:root {
  --bg: #eef0ec; --panel: #ffffff; --panel-2: #f6f7f4; --ink: #15181a; --muted: #555b60; --line: #dadcd6;
  --accent: #1d5fd0; --accent-btn: #1d5fd0; --accent-ink: #ffffff; --rec: #c62a1f; --ok: #11744f; --warn: #a14a06; --off: #8a9095;
  --chip: #e9ebe6; --video: #0b0d0e; --focus: #1d5fd0; --clip: #1d5fd0; --clip-bg: #dfe4ec;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d0f10; --panel: #15181a; --panel-2: #1b1f22; --ink: #e7e9ea; --muted: #9aa0a5; --line: #262b2e;
          --accent: #5b93f5; --accent-btn: #2b63d6; --accent-ink: #ffffff; --rec: #ff5b4f; --ok: #3fcf8e; --warn: #f2a33a; --off: #6c7378;
          --chip: #22272a; --clip: #4d8bff; --clip-bg: #1f2a3a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
input, select { font-size: 16px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent-btn); border-color: var(--accent-btn); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--rec); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.field { display: grid; gap: 5px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field input, .field select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.err { color: var(--rec); font-size: 13px; min-height: 1.2em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* ---------- auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 16px; }
.auth h1 { font-size: 18px; margin: 0; }
.auth .sub { color: var(--muted); font-size: 13px; margin-top: -10px; }
.auth a { color: var(--accent); }
.auth .links { font-size: 13px; text-align: center; }
.auth .ok { color: var(--ok); font-size: 13px; }
.auth .warn { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }
.auth .qr { background: #fff; padding: 10px; border-radius: 8px; width: 200px; height: 200px; justify-self: center; display: block; }
.auth .secret { font-family: var(--mono); font-size: 13px; word-break: break-all; background: var(--chip); padding: 8px 10px; border-radius: 6px; }
.auth ol { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; display: grid; gap: 4px; }

/* ---------- app shell */
header.top { display: flex; align-items: center; gap: 14px; padding: 0 18px; height: 54px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header.top h1 { font-size: 15px; margin: 0; white-space: nowrap; }
header.top .stats { display: flex; gap: 8px; flex-wrap: wrap; }
header.top .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.dot.recording { background: var(--ok); }
.dot.starting, .dot.retrying { background: var(--warn); }
.dot.offline { background: var(--rec); }
.dot.live { background: var(--rec); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.who { font-size: 13px; color: var(--muted); }

main.shell { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 54px); }
aside.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.filters { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.filters input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); width: 100%; }
.filters .row { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 10px; font-size: 12.5px; cursor: pointer; }
.seg button.on { background: var(--chip); font-weight: 600; }
#camList { overflow-y: auto; flex: 1; }
.cam { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.cam:hover { background: var(--panel-2); }
.cam.sel { background: color-mix(in srgb, var(--accent) 13%, transparent); }
.cam .t { font-size: 13px; line-height: 1.3; }
.cam .s { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.cam .h { font-size: 11.5px; color: var(--muted); font-family: var(--mono); text-align: right; }
.empty { padding: 30px 16px; color: var(--muted); text-align: center; }

section.view { overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
section.view > * { flex-shrink: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card > h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.camhead { display: flex; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }
.camhead h2 { font-size: 16px; margin: 0; flex: 1 1 280px; min-width: 0; }
.camhead h2 small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 36px; height: 20px; border-radius: 999px; background: var(--off); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(16px); }

.player { position: relative; background: var(--video); aspect-ratio: 16 / 9; max-height: 60vh; margin: 0 auto; width: 100%; }
.player video { width: 100%; height: 100%; object-fit: contain; display: block; }
.player .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #a7aeb3; font-size: 13px; text-align: center; padding: 20px; pointer-events: none; }
.player .badge { position: absolute; top: 12px; left: 12px; font-size: 11px; font-weight: 700; letter-spacing: .06em; padding: 3px 8px; border-radius: 4px; background: rgba(0,0,0,.65); color: #fff; }
.player .badge.live { background: var(--rec); }
.player .clock { position: absolute; top: 12px; right: 12px; font: 600 12.5px var(--mono); padding: 3px 8px; border-radius: 4px; background: rgba(0,0,0,.65); color: #fff; }

.timeline-wrap { padding: 14px 16px 16px; display: grid; gap: 10px; border-top: 1px solid var(--line); }
.timeline { position: relative; height: 34px; background: var(--clip-bg); border-radius: 6px; cursor: pointer; overflow: hidden; }
.timeline .c { position: absolute; top: 0; bottom: 0; background: var(--clip); opacity: .85; }
.timeline .now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--rec); }
.timeline .hover { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--ink); opacity: .5; pointer-events: none; }
.ticks { position: relative; height: 16px; font-size: 11px; color: var(--muted); }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.tl-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tl-controls input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 14px; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; background: var(--panel); padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.tabs button.on { background: var(--chip); color: var(--ink); }

.export { padding: 14px 16px; display: grid; gap: 12px; }
.export .grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.export .grid .field input { font-size: 14px; padding: 8px 10px; }
.rowi { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.rowi .grow { flex: 1 1 260px; min-width: 0; }
.rowi .name { font-size: 13px; overflow-wrap: anywhere; }
.rowi .info { font-size: 12px; color: var(--muted); font-family: var(--mono); overflow-wrap: anywhere; }
.status { font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.status.ready { color: var(--ok); } .status.error { color: var(--rec); } .status.queued, .status.working { color: var(--warn); }

table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tablewrap { overflow-x: auto; }
.invite { padding: 14px 16px; display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 10px; align-items: end; }
.linkbox { margin: 0 16px 14px; padding: 10px 12px; background: var(--chip); border-radius: 8px; font: 12.5px var(--mono); word-break: break-all; }

@media (max-width: 860px) {
  main.shell { grid-template-columns: 1fr; height: auto; }
  aside.list { border-right: 0; max-height: 45vh; }
  section.view { padding: 12px; }
  header.top { height: auto; padding: 10px 14px; flex-wrap: wrap; }
  .export .grid, .invite { grid-template-columns: 1fr; }
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.pad { padding: 0 16px; }
.tl-controls .spacer { min-width: 8px; }
.role { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--chip); }
.role.super, .role.admin { color: var(--accent); }
.dis { color: var(--rec); font-weight: 600; }

/* ---------- navigation */
#nav button { padding: 5px 12px; }

/* ---------- display wall */
main.shell.wide { grid-template-columns: 1fr; }
main.shell.wide aside.list { display: none; }
.wallview { display: flex; flex-direction: column; min-height: 0; height: 100%; background: var(--video); }
.walltools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.walltools select, .walltools input { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 14px; }
.walltools input { width: 180px; }
.wall { flex: 1; display: grid; gap: 4px; padding: 4px; min-height: 0; grid-auto-rows: 1fr; }
.wall.l2x2 { grid-template-columns: repeat(2, 1fr); }
.wall.l3x3, .wall.l1p5 { grid-template-columns: repeat(3, 1fr); }
.wall.l4x4 { grid-template-columns: repeat(4, 1fr); }
.wall.l1p5 .tile:first-child { grid-column: span 2; grid-row: span 2; }
.tile { position: relative; background: #000; overflow: hidden; min-height: 0; border-radius: 3px; }
.tile video, .tile img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile .lbl { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 5px; font-size: 12px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.75)); display: flex; align-items: center; gap: 6px; pointer-events: none; }
.tile .lbl span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .msg { position: absolute; inset: 0; display: grid; place-items: center; color: #8d959a; font-size: 12px; text-align: center; padding: 10px; pointer-events: none; }
.tile .acts { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .acts, .tile:focus-within .acts { opacity: 1; }
.tile .acts button { border: 0; border-radius: 6px; background: rgba(0,0,0,.7); color: #fff; font-size: 12px; padding: 4px 8px; cursor: pointer; }
.tile.empty { display: grid; place-items: center; border: 1px dashed #2b3134; background: #0e1112; }
.tile.empty button { background: transparent; border: 1px solid #3a4246; color: #b4bcc1; border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.wallview:fullscreen { height: 100vh; }
.wallview:fullscreen .walltools { display: none; }
dialog#picker { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, 92vw); max-height: 80vh; background: var(--panel); color: var(--ink); }
dialog#picker::backdrop { background: rgba(0,0,0,.55); }
.pickform { display: flex; flex-direction: column; max-height: 80vh; }
.pickhead { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
#pickFilter { margin: 10px 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
#pickList { overflow-y: auto; border-top: 1px solid var(--line); }
@media (max-width: 860px) {
  .wall.l3x3, .wall.l4x4, .wall.l1p5 { grid-template-columns: repeat(2, 1fr); }
  .wall.l1p5 .tile:first-child { grid-row: auto; }
  .wall { grid-auto-rows: minmax(120px, auto); }
  .tile { aspect-ratio: 16 / 9; }
}
h1.brand { letter-spacing: .14em; font-weight: 800; }
h1.brand small { letter-spacing: 0; font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 6px; }
.auth h1.brand small { display: block; margin: 4px 0 0; font-size: 13px; }

/* ---------- clipping */
.clipbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px 16px 0; }
kbd { font: 600 11px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; margin-left: 4px; color: var(--muted); }
.clipsum { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 16px; padding: 12px 14px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.clipsum.set { border-color: color-mix(in srgb, var(--warn) 60%, var(--line)); }
.clipsum .grow { flex: 1 1 260px; min-width: 0; }
.cliprange { font-weight: 600; font-variant-numeric: tabular-nums; }
.small { font-size: 12.5px; }
.fine { margin: 0 16px 8px; }
.fine summary { cursor: pointer; color: var(--muted); font-size: 12.5px; padding: 4px 0; }
.fine .export { padding: 10px 0 4px; }
.timeline .selr { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--warn) 45%, transparent); border-left: 2px solid var(--warn); border-right: 2px solid var(--warn); pointer-events: none; }
.timeline.dragging { cursor: ew-resize; }
.rowi.fresh { background: color-mix(in srgb, var(--ok) 12%, transparent); }
a.btn { color: var(--ink); text-decoration: none; display: inline-block; }
a.btn.primary { color: var(--accent-ink); }
