:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel2: #1e242c;
  --line: #2a313b;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #3b82f6;
  --rec: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, select, input, .btn { font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
select, input { cursor: default; }
input { width: 100%; padding: 9px 10px; }
.btn { text-decoration: none; display: inline-block; }
.btn.disabled { opacity: .4; pointer-events: none; }
.ghost { background: transparent; }
.spacer { flex: 1; }
.label { color: var(--muted); font-size: 12px; margin-left: 8px; }
.hint { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ── login ── */
.login-page { display: flex; align-items: center; justify-content: center; }
.login-box { width: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-box label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login-box button { background: var(--accent); border-color: var(--accent); padding: 10px; font-weight: 600; }
.err { color: var(--rec); min-height: 1.2em; font-size: 13px; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; letter-spacing: .3px; }
.brand.big { font-size: 20px; justify-content: center; margin-bottom: 6px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec);
  box-shadow: 0 0 8px var(--rec); }

/* ── layout ── */
body:not(.login-page) { display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; }
.tabs button { background: transparent; border-color: transparent; }
.tabs button.active { background: var(--panel2); border-color: var(--line); }
.disk { color: var(--muted); font-size: 12px; }
.disk.low { color: var(--warn); }
.disk .d-short { display: none; }
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }
.seg-btns { display: inline-flex; }
.seg-btns button { border-radius: 0; margin-left: -1px; padding: 4px 9px; }
.seg-btns button:first-child { border-radius: 6px 0 0 6px; }
.seg-btns button:last-child { border-radius: 0 6px 6px 0; }
.seg-btns button.active { background: var(--accent); border-color: var(--accent); }

/* ── ao vivo ── */
#view-live { flex-direction: column; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; }
.grid { flex: 1; min-height: 0; display: grid; gap: 4px; padding: 0 4px 4px; }
.tile { position: relative; background: #000; border-radius: 4px; overflow: hidden; min-height: 0; }
.tile video-stream { display: block; width: 100%; height: 100%; }
.tile video { width: 100% !important; height: 100% !important; object-fit: contain; background: #000; }
.tile .cap { position: absolute; left: 0; right: 0; top: 0; padding: 5px 8px; font-size: 12px;
  display: flex; gap: 8px; align-items: center; background: linear-gradient(#000a, #0000);
  pointer-events: none; z-index: 2; }
.tile .cap .name { font-weight: 600; }
.tile .cap .sub { color: #cbd5e1; opacity: .8; }
.badge { margin-left: auto; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #0008; }
.badge.rec { color: #fff; background: var(--rec); }
.badge.err { color: #000; background: var(--warn); }
.badge.off { color: var(--muted); }
.tile .msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); }

/* ── gravações ── */
.side { width: 270px; padding: 12px; border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.side label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.side select { width: 100%; }
.side-title { color: var(--muted); font-size: 12px; margin-top: 4px; }
.seglist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; border: 1px solid var(--line);
  border-radius: 6px; }
.seglist li { padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex;
  justify-content: space-between; font-variant-numeric: tabular-nums; }
.seglist li:hover { background: var(--panel2); }
.seglist li.active { background: var(--accent); }
.seglist li.live { color: var(--rec); cursor: default; }
.seglist li.broken { color: var(--muted); text-decoration: line-through; cursor: default; }
.seglist li small { color: var(--muted); }
.seglist li.active small { color: #dbeafe; }
.player-area { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 10px; gap: 8px; }
.player-wrap { position: relative; flex: 1; min-height: 0; background: #000; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; }
#player { width: 100%; height: 100%; object-fit: contain; }
.clock { position: absolute; top: 8px; right: 10px; background: #000a; padding: 3px 8px; border-radius: 4px;
  font-variant-numeric: tabular-nums; font-size: 15px; pointer-events: none; }
.empty { position: absolute; color: var(--muted); pointer-events: none; }
.controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.timeline { position: relative; height: 62px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer; overflow: hidden; user-select: none; }
.ticks { position: absolute; inset: 0; }
.ticks .tk { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); }
.ticks .tk span { position: absolute; top: 2px; left: 3px; font-size: 10px; color: var(--muted); white-space: nowrap; }
.track { position: absolute; left: 0; right: 0; top: 22px; height: 30px; }
.track .sg { position: absolute; top: 0; bottom: 0; background: #2563eb; border-right: 1px solid #1d4ed8;
  min-width: 1px; }
.track .sg.live { background: var(--rec); opacity: .7; }
.track .sg.broken { background: #4b5563; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: #fbbf24; display: none;
  pointer-events: none; }
.hover-time { position: absolute; top: 2px; font-size: 11px; background: #000c; padding: 0 5px; border-radius: 3px;
  display: none; pointer-events: none; transform: translateX(-50%); }

@media (max-width: 800px) {
  #view-rec { flex-direction: column; }
  .side { width: auto; max-height: 40vh; }
  .hint { display: none; }
}

/* ── celular ── */
@media (max-width: 700px) {
  /* iOS dá zoom em campos com fonte < 16px */
  select, input { font-size: 16px; }

  /* cabeçalho compacto em uma linha, respeitando o notch */
  .topbar { gap: 8px; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .brand-text { display: none; }
  .tabs button { padding: 5px 9px; font-size: 13px; }
  .disk { font-size: 11px; white-space: nowrap; }
  .disk .d-long { display: none; }
  .disk .d-short { display: inline; }
  #logout { padding: 5px 8px; font-size: 13px; }

  /* ao vivo: sem barra de layout, uma câmera por linha em 16:9, rolando */
  #view-live .toolbar { display: none; }
  #view-live { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .grid { gap: 3px; padding: 3px; padding-bottom: max(3px, env(safe-area-inset-bottom)); flex: none; }
  .grid.stack { grid-auto-rows: auto; }
  .grid.stack .tile { aspect-ratio: 16 / 9; }
  .grid:not(.stack) { flex: 1; }

  /* gravações: player em cima, seleção e lista embaixo; a página rola */
  #view-rec { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .player-area { order: 1; flex: none; padding: 4px; gap: 6px; }
  .player-wrap { flex: none; aspect-ratio: 16 / 9; width: 100%; }
  .clock { font-size: 12px; top: 4px; right: 6px; }
  .controls { gap: 4px; }
  .controls button, .controls select, .controls .btn { padding: 5px 7px; font-size: 13px; }
  .controls .seg-btns button { padding: 4px 6px; font-size: 12px; }
  .lbl-speed, .lbl-zoom { display: none; }
  .controls .spacer { display: none; }
  .timeline { height: 52px; }
  .track { top: 18px; height: 28px; }
  .side { order: 2; max-height: none; border-right: none; border-top: 1px solid var(--line);
    padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom));
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .side-title, .seglist { grid-column: 1 / -1; }
  .seglist { max-height: 45vh; }
  .seglist li { padding: 9px 10px; }   /* alvo de toque maior */
}
