:root {
  --brand: #2563eb;
  --bg: #0b1120;
  --panel: #111827;
  --panel2: #1f2937;
  --line: #273244;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --ok: #22c55e;
  --bad: #ef4444;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
button, input, select { font: inherit; color: inherit; }
input, select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: 9px 14px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block; }
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: #fca5a5; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.error { color: #fca5a5; min-height: 1.2em; margin: 0; }
.empty, .hint { color: var(--muted); }
.hint { font-size: 13px; margin: 8px 0 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; padding: 28px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-logo { width: 56px; height: 56px; margin: 0 auto; }
.login-card h1 { text-align: center; margin: 0 0 8px; font-size: 20px; }

/* Topo */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.active { background: var(--panel2); color: var(--text); box-shadow: inset 0 -2px 0 var(--brand); }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
main { padding: 16px; max-width: 1600px; margin: 0 auto; }

/* Barra de ferramentas */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel2); border: 0; padding: 7px 13px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--brand); color: #fff; }
.pager { display: flex; align-items: center; gap: 6px; margin-left: auto; color: var(--muted); font-size: 13px; }

/* Grade ao vivo */
.grid { display: grid; gap: 8px; }
.grid.g1 { grid-template-columns: 1fr; }
.grid.g4 { grid-template-columns: repeat(2, 1fr); }
.grid.g9 { grid-template-columns: repeat(3, 1fr); }
.grid.g16 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) {
  .topbar { gap: 8px; }
  .user { margin-left: auto; }
  .tabs { order: 3; flex-basis: 100%; }
  .grid.g4, .grid.g9, .grid.g16 { grid-template-columns: 1fr; }
  .user span { display: none; }
}
.tile { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; cursor: pointer; border: 1px solid var(--line); }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.tile .label { position: absolute; left: 0; right: 0; top: 0; padding: 6px 10px; font-size: 13px; background: linear-gradient(#000a, #0000); display: flex; align-items: center; gap: 6px; }
.tile .msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; pointer-events: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.on { background: var(--ok); }

/* Tela cheia */
.focus { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; }
.focus-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
.focus video { flex: 1; width: 100%; min-height: 0; object-fit: contain; }

/* Gravações */
.timeline-wrap { position: relative; }
.timeline { position: relative; height: 44px; background: var(--panel2); border-radius: 8px; cursor: pointer; overflow: hidden; }
.timeline .seg-rec { position: absolute; top: 0; bottom: 0; background: var(--brand); opacity: .85; }
.timeline .cursor { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; }
.timeline-hours { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }
.player video { width: 100%; max-height: 70vh; background: #000; border-radius: 8px; display: block; }
.player-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }

/* Admin */
.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-row input, .form-row select { flex: 1 1 160px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }
code.key { background: var(--panel2); padding: 3px 6px; border-radius: 6px; font-size: 12px; word-break: break-all; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); }
.badge.ok { color: #86efac; }
.badge.bad { color: #fca5a5; }
@media (max-width: 800px) {
  table, tbody, tr, td { display: block; width: 100%; }
  thead, tr:first-child:has(th) { display: none; }
  tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  td { border: 0; padding: 4px 0; }
}

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90vw; }
