:root {
  --bg: #0e1013; --panel: #171a1f; --line: #262a31; --text: #e6e8eb; --muted: #8b929c;
  --accent: #3b82f6; --motion: #f59e0b; --human: #ef4444; --ok: #22c55e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, select, input { font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; }
button { cursor: pointer; }
button:hover { border-color: #3a404a; }
button.on, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

header { display: flex; align-items: center; gap: 20px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; }
.brand span { color: var(--accent); }
nav { display: flex; gap: 6px; }
nav b { background: var(--motion); color: #000; border-radius: 9px; padding: 0 6px; font-size: 12px; margin-left: 4px; }
nav b:empty, nav b[data-zero] { display: none; }
#nvrStatus { margin-left: auto; display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
#nvrStatus i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--human); margin-right: 5px; }
#nvrStatus i.on { background: var(--ok); }

.warn { background: #3a2a05; color: #fcd34d; padding: 8px 16px; border-bottom: 1px solid #5c430a; }
.view { padding: 12px 16px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.pager { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

.grid { display: grid; gap: 6px; grid-template-columns: repeat(var(--cols, 3), 1fr); }
.tile { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 6px; overflow: hidden;
  border: 2px solid transparent; cursor: pointer; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .label { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 5px;
  background: linear-gradient(transparent, rgba(0,0,0,.75)); font-size: 12px; display: flex; gap: 6px; }
.tile .label .nvr { color: var(--muted); margin-left: auto; }
.tile .msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.tile.motion { border-color: var(--motion); }
.tile.human { border-color: var(--human); }
.tile .tag { position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 600; padding: 1px 6px;
  border-radius: 4px; display: none; }
.tile.motion .tag { display: block; background: var(--motion); color: #000; }
.tile.human .tag { display: block; background: var(--human); color: #fff; }
/* movimento agora: espaço vazio, câmera que já parou, câmera que acabou de entrar */
.slot { aspect-ratio: 16/9; border-radius: 6px; border: 1px dashed var(--line); background: #0b0d10; }
.tile.ended video { opacity: .45; }
.tile.ended .tag { display: block; background: #2a2f37; color: var(--muted); }
.tile.ended .tag:empty::before { content: 'PAROU'; }
.tile.fresh { animation: fresh 1s ease-in-out 3; }
@keyframes fresh { 50% { box-shadow: 0 0 0 3px var(--accent); } }

#focus { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 10; }
.focus-box { width: min(1280px, 96vw); background: var(--panel); border-radius: 10px; padding: 12px; }
.focus-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
#fClock { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
#fClock.live { color: var(--ok); }
#fClock.rec { color: var(--motion); }
.focus-video { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 6px; overflow: hidden; }
.focus-video video { width: 100%; height: 100%; object-fit: contain; }
#fStatus { position: absolute; top: 10px; left: 10px; font-size: 12px; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 8px; }
.controls .spacer { flex: 1; }
.controls .live { color: var(--human); font-weight: 600; }
.controls .live.on { background: var(--human); border-color: var(--human); color: #fff; }
.range { display: flex; gap: 4px; }
#timeline { width: 100%; display: block; background: #0b0d10; border-radius: 6px; cursor: pointer; }
.legend { font-size: 12px; margin-top: 6px; display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 12px; height: 8px; border-radius: 2px; }
.lg-rec { background: #1e3a5f; } .lg-motion { background: var(--motion); } .lg-human { background: var(--human); }

#sResults .row { display: grid; grid-template-columns: 220px 70px 1fr; gap: 10px; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--line); }
#sResults .row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sResults .row .n { color: var(--muted); font-size: 12px; text-align: right; }
#sResults canvas { width: 100%; height: 22px; background: #0b0d10; border-radius: 4px; cursor: pointer; display: block; }
#sResults .axis { display: grid; grid-template-columns: 220px 70px 1fr; gap: 10px; font-size: 11px; color: var(--muted); }
#sResults .axis div:last-child { display: flex; justify-content: space-between; }

.spacer { flex: 1; }

/* login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-box .brand { font-size: 20px; text-align: center; margin-bottom: 4px; }
.login-box label, .form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-box input { padding: 8px 10px; }
.erro { color: #fca5a5; margin: 0; font-size: 13px; }
.ok { color: #86efac; margin: 0; font-size: 13px; }

/* cabeçalho: usuário */
#userBox { display: flex; align-items: center; gap: 10px; font-size: 13px; }
#userBox a { color: var(--text); text-decoration: none; }
#userBox a:hover { text-decoration: underline; }
.tile .msg.noaccess { background: #0b0d10; }
button:disabled { opacity: .4; cursor: not-allowed; }

/* administração */
.admin { max-width: 1200px; margin: 0 auto; padding: 12px 16px 40px; }
.admin h2 { font-size: 16px; margin: 18px 0 10px; }
.admin table { width: 100%; border-collapse: collapse; }
@media (max-width: 800px) { .admin #userList table, .admin #nvrList table, .admin #tab-logs table { display: block; overflow-x: auto; white-space: nowrap; } }
.admin th, .admin td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
.admin th { color: var(--muted); font-weight: 500; }
.admin tr.click { cursor: pointer; }
.admin tr.click:hover td { background: #1b1f25; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 9px; background: #262a31; margin: 0 4px 2px 0; }
.pill.master { background: var(--accent); color: #fff; }
.pill.off { background: #3a1d1d; color: #fca5a5; }
.pill.on { background: #173a24; color: #86efac; }
.form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 14px; }
.form .row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form .checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.form .checks label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.form .actions { display: flex; gap: 8px; align-items: center; }
.camgrid { max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.camgrid table th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.camgrid td.c, .camgrid th.c { text-align: center; width: 92px; }
.camgrid tr.nvrhead td { background: #1b1f25; font-weight: 600; }
.note { font-size: 12px; color: var(--muted); }

@media (max-width: 700px) {
  header { flex-wrap: wrap; gap: 10px; }
  .grid { --cols: 2 !important; }
  #sResults .row, #sResults .axis { grid-template-columns: 110px 40px 1fr; }
}
