:root {
  --bg: #042237;
  --bg-2: #08283e;
  --panel: #07354d;
  --panel-2: #10364d;
  --line: #245771;
  --line-2: #35718e;
  --text: #edf6fc;
  --muted: #9fbacb;
  --gold: #e2b73c;
  --gold-2: #ffd34f;
  --ok: #3ddc84;
  --warn: #e2b73c;
  --off: #8a9aa6;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; }

/* Buttons & inputs */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px 14px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--line-2); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-outline { background: transparent; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #042237; font-weight: 600; }
.btn-gold:hover { background: var(--gold-2); }
.btn-gold-outline { border-color: var(--gold); color: var(--gold-2); }
.btn-block { width: 100%; }
.btn.on { background: var(--gold); color: #042237; border-color: var(--gold); }
.icon-btn { background: none; border: 0; font-size: 18px; color: var(--text); }
.input, .form input, .login-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}
.input:focus, input:focus, select:focus { outline: 2px solid var(--line-2); outline-offset: -1px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-logo { width: 220px; justify-self: center; margin-bottom: 8px; }
.login-error { color: #ff8a8a; min-height: 1em; margin: 0; font-size: 13px; }

/* Shell */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand { padding: 12px 24px; border-bottom: 1px solid var(--line); }
.brand img { width: 100%; max-width: 150px; display: block; margin: 0 auto; }
/* sem barra de rolagem: tudo é dimensionado para caber; em telas muito baixas ainda rola, sem barra */
.sidebar { overflow-y: auto; scrollbar-width: none; }
.sidebar::-webkit-scrollbar { display: none; }
.nav { display: grid; gap: 0; padding: 8px 10px; }
.nav a {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  user-select: none;
}
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: #ffffff14; color: var(--gold-2); }
.ico, .ico-sm { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico { width: 22px; height: 22px; }
.ico-sm { width: 16px; height: 16px; color: var(--gold); }

/* Telemetria */
.telemetry {
  margin: 4px 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff08;
  display: grid;
  gap: 6px;
}
.telemetry header { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.metric { display: grid; grid-template-columns: 74px 1fr 40px; align-items: center; column-gap: 8px; font-size: 13px; }
.metric strong { text-align: right; font-size: 12px; }
.metric small { grid-column: 1 / -1; color: var(--muted); font-size: 10.5px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric i { height: 4px; border-radius: 4px; background: #ffffff14; overflow: hidden; }
.metric b { display: block; height: 100%; width: 0; border-radius: 4px; background: #2dd4bf; transition: width .6s; }
#mCpu b { background: var(--gold); }
#mNet b { background: #34d399; }
#mDisk b, #mRec b { background: #22d3ee; }

.side-actions { margin-top: auto; padding: 10px 12px; display: flex; gap: 8px; }
.side-actions .btn { padding: 8px 14px; font-weight: 600; }
.side-actions .btn[data-view] { flex: 1; }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg-2); }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-wrap: wrap;
}
.nvr-select {
  display: grid;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  min-width: 280px;
}
.nvr-select small { color: var(--muted); font-size: 11px; letter-spacing: .08em; }
/* Seletor de NVR/Tela: dropdown próprio (escuro, no tema) */
.nvr-select.dropdown { position: relative; }
.dd-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  background: transparent; border: 0; color: var(--text); font: 600 16px/1.3 inherit; padding: 0; cursor: pointer; text-align: left; }
.dd-caret { color: var(--gold-2); transition: transform .2s; }
.nvr-select.open .dd-caret { transform: rotate(180deg); }
.dd-menu { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40; margin: 0; padding: 6px; list-style: none;
  background: var(--panel); border: 1px solid var(--gold); border-radius: 10px; box-shadow: 0 12px 32px #000a; max-height: 60vh; overflow: auto; }
.dd-menu li { padding: 9px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--text); }
.dd-menu li:hover { background: var(--bg); color: var(--gold-2); }
.dd-menu li.on { color: var(--gold); }
.dd-menu li.on::after { content: " ✓"; }
.dd-menu li.muted { color: var(--muted); font-weight: 400; cursor: default; }
.title { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; }
.title strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
.title span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.pager { display: flex; align-items: center; gap: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pager .btn { padding: 6px 12px; font-size: 18px; line-height: 1; }
.live-count { color: var(--ok); display: flex; align-items: center; gap: 6px; margin-right: 6px; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--off); }
.dot.on { background: var(--ok); }
.dot.wait { background: var(--warn); }

/* Grid */
.stage { flex: 1; min-height: 0; display: flex; }
/* A grade cobre toda a área; a imagem estica para preencher o quadro */
.grid-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  padding: 6px;
  background: var(--bg-2);
}
.grid {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 3px;
  padding: 3px;
  overflow: hidden;
  background: #021726;
  border: 2px solid var(--gold); /* moldura dourada */
  border-radius: 10px;
  box-shadow: 0 0 16px #e2b73c33;
}
.grid.empty { place-items: center; align-content: center; color: var(--muted); }
.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #020f19;
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: fill; display: block; }
.tile-name {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 5px 34px 12px 7px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px #000;
  background: linear-gradient(#000a, transparent);
}
.tile-expand {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px;
  padding: 0;
  font-size: 12px;
  border: 1px solid var(--gold); border-radius: 5px;
  background: #0429; color: var(--gold-2);
}
.badge {
  position: absolute; left: 4px; bottom: 24px; right: auto;
  background: #000b;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--gold-2);
  display: flex; align-items: center; gap: 6px;
}
.badge.live { color: var(--text); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.badge.off { color: var(--off); }
.quality {
  position: absolute; left: 4px; bottom: 4px;
  background: #000b;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--gold-2);
}
.quality:empty { display: none; }
.grid.organizing .tile { cursor: grab; outline: 2px dashed var(--gold); outline-offset: -4px; }
.tile.drag-over { outline: 3px solid var(--gold-2) !important; }
.tile.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: inset 0 0 0 4px var(--gold-2); } to { box-shadow: inset 0 0 0 0 transparent; } }

/* Right panel */
.cam-panel {
  width: 270px;
  background: var(--bg);
  border-left: 1px solid var(--line);
  padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
  min-height: 0;
}
.cam-panel-head { display: flex; justify-content: space-between; align-items: center; font-size: 17px; }
.cam-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.cam-list li { display: grid; grid-template-columns: 16px 1fr; gap: 2px 8px; padding: 10px 6px; border-radius: 6px; cursor: pointer; }
.cam-list li:hover { background: var(--panel); }
.cam-list li .dot { margin-top: 6px; }
.cam-list li strong { font-weight: 600; }
.cam-list li { grid-template-columns: 16px 1fr auto; }
.cam-list li small { grid-column: 2 / -1; color: var(--muted); }
.cam-list .rename { background: none; border: 0; color: var(--muted); padding: 0 4px; opacity: 0; font-size: 15px; }
.cam-list li:hover .rename { opacity: 1; }
.cam-list .rename:hover { color: var(--gold-2); }

/* Pages */
#view-devices, .view.page { overflow: auto; padding: 20px 24px; display: block; }
.page-head { display: flex; justify-content: space-between; align-items: center; }
.page-head h1 { margin: 0; font-size: 22px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin: 18px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.card h2, .section-title { font-size: 16px; margin: 0 0 8px; }
.section-title { margin-top: 24px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: ui-monospace, Menlo, monospace; word-break: break-all; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; }
.table td.empty { color: var(--muted); text-align: center; }
.soon { margin: auto; text-align: center; }
.soon img { width: 120px; opacity: .8; }

/* Câmera aberta: cobre a área do mosaico, com a mesma moldura */
.grid-wrap { position: relative; }
.viewer {
  position: absolute;
  inset: 6px;
  z-index: 3;
  background: #000;
  border: 2px solid var(--gold);
  border-radius: 10px;
  overflow: hidden;
}
/* preenche toda a área, como os quadros do mosaico */
.viewer video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block; }
.viewer video.loading { opacity: 0; }
/* Faixa de info da câmera aberta: logo + resolução/fluxo + canal/nome */
.viewer-info {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px 26px;
  background: linear-gradient(#000b, transparent);
  transition: opacity .3s;
}
.vi-logo { width: 42px; height: 42px; flex: none; opacity: .9; filter: drop-shadow(0 1px 3px #000); }
.vi-text { display: grid; gap: 2px; min-width: 0; }
.vi-meta {
  font-size: 14px; font-weight: 700; letter-spacing: .02em;
  color: var(--gold-2); text-shadow: 0 1px 3px #000;
  text-transform: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vi-meta:empty { display: none; }
.vi-name {
  font-size: 17px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.viewer .badge { left: 14px; bottom: 64px; top: auto; right: auto; }

/* Barra de controles translúcida: some quando o mouse sai ou fica parado */
.cam-controls {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px;
  border-radius: 14px;
  background: rgba(40, 96, 128, .55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.viewer:not(.controls-on) .viewer-info { opacity: 0; }
.viewer.controls-on .cam-controls { opacity: 1; transform: none; pointer-events: auto; }
.viewer.controls-on { cursor: default; }
.viewer:not(.controls-on) { cursor: none; }
.ctl {
  height: 36px;
  padding: 0 11px;
  border: 1px solid #ffffff1f;
  border-radius: 8px;
  background: rgba(10, 40, 60, .55);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
}
.ctl:hover { background: rgba(10, 40, 60, .85); }
.ctl:active, .ptz-group .ctl:active { background: var(--gold); color: #042237; }
select.ctl { width: 180px; padding-right: 6px; }
select.ctl option { background: var(--panel); }
.ptz-group { display: flex; gap: 6px; flex-wrap: wrap; }
.ptz-group [data-ptz^="left"], .ptz-group [data-ptz="up"], .ptz-group [data-ptz="down"], .ptz-group [data-ptz="right"] { width: 38px; padding: 0; font-size: 17px; }
.ctl-more { position: relative; }
.ctl-menu {
  position: absolute; bottom: 46px; left: 0;
  display: grid; min-width: 180px;
  padding: 6px;
  border-radius: 10px;
  background: rgba(10, 40, 60, .92);
  border: 1px solid #ffffff1f;
}
.ctl-menu button { background: none; border: 0; text-align: left; padding: 9px 10px; border-radius: 6px; color: var(--text); }
.ctl-menu button:hover { background: #ffffff14; }
.viewer:fullscreen { inset: 0; border: 0; border-radius: 0; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { border: 0; padding: 10px 16px; }
  .brand img { max-width: 130px; }
  .nav { display: flex; overflow-x: auto; padding: 6px 8px; width: 100%; }
  .nav a { padding: 8px 12px; white-space: nowrap; }
  .telemetry, .side-actions { display: none; }
  .nvr-select { min-width: 0; flex: 1; }
  .cam-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 5; }
  .grid-wrap { display: block; overflow: auto; }
  .grid { height: auto; grid-template-columns: 1fr 1fr !important; grid-template-rows: none !important; }
  .tile { aspect-ratio: 16 / 9; }
}

/* Tela cheia */
#view-screens:fullscreen { background: var(--bg-2); }

/* IA */
.nav-badge { margin-left: auto; min-width: 20px; padding: 1px 6px; border-radius: 10px; background: #e5484d; color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.ai-events { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.ai-event { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; }
.ai-event:hover { border-color: var(--gold); }
#phoneEvents .ai-event { cursor: zoom-in; }
.ai-event img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: #000; }
.ai-event figcaption { padding: 8px 10px; display: grid; gap: 2px; }
.ai-event small, .toast small { color: var(--muted); }
.toasts { position: fixed; top: 16px; right: 16px; z-index: 20; display: grid; gap: 10px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center;
  padding: 10px; border-radius: 12px;
  background: rgba(10, 40, 60, .95); border: 1px solid #e5484d; box-shadow: 0 8px 30px #0008;
  animation: toast-in .3s ease-out;
}
.toast img { width: 120px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: #000; }
.toast div { display: grid; gap: 4px; }
.toast span { display: flex; gap: 6px; margin-top: 4px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* Troca de senha */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: #000a; }
.modal-card {
  width: min(420px, 100%); display: grid; gap: 12px;
  padding: 24px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--gold); box-shadow: 0 12px 40px #000a;
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card p { margin: 0; }
.modal-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.modal-card input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); padding: 10px 12px; font: inherit;
}
.pw-rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.pw-rules li::before { content: "○ "; }
.pw-rules li.ok { color: #34d399; }
.pw-rules li.ok::before { content: "✓ "; }
.pw-rules li.missing { color: #ff8a8a; font-weight: 600; }
.pw-rules li.missing::before { content: "✕ "; }
#pwMsg { font-size: 14px; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Gravações */
.rec-date input { background: transparent; border: 0; color: var(--text); font: 600 15px/1.3 inherit; padding: 0; color-scheme: dark; }
.rec-stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 6px; background: var(--bg-2); }
.rec-player { position: relative; flex: 1; min-height: 0; background: #000; border: 2px solid var(--gold); border-radius: 10px; overflow: hidden; box-shadow: 0 0 16px #e2b73c33; }
.rec-player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.rec-player .quality { top: 10px; right: 10px; left: auto; bottom: auto; }
.rec-hint { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 16px; background: #000a; }
.timeline-wrap { padding: 4px 6px 0; }
.timeline { position: relative; height: 34px; border-radius: 8px; background: #021726; border: 1px solid var(--line); cursor: pointer; overflow: hidden; }
.tl-seg { position: absolute; top: 6px; bottom: 6px; background: #2dd4bf; border-radius: 2px; opacity: .85; }
.tl-seg.alarm { background: #e5484d; }
.tl-cursor { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--gold-2); box-shadow: 0 0 6px var(--gold); }
.tl-hover { position: absolute; top: 2px; transform: translateX(-50%); font-size: 11px; padding: 0 4px; border-radius: 4px; background: #000c; color: var(--text); pointer-events: none; }
.tl-hours { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 2px 0 0; }

/* Mapa */
.map-stage { flex: 1; min-height: 0; display: flex; }
.map-canvas { position: relative; flex: 1; min-width: 0; display: grid; place-items: center; padding: 6px; overflow: auto; }
.map-board { position: relative; border: 2px solid var(--gold); border-radius: 10px; overflow: hidden; box-shadow: 0 0 16px #e2b73c33; }
.map-board img { display: block; max-width: 100%; max-height: calc(100vh - 110px); user-select: none; -webkit-user-drag: none; }
.map-board.editing { outline: 2px dashed var(--gold-2); outline-offset: 4px; }
.map-pin {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 4px; border-radius: 14px;
  background: rgba(4, 34, 55, .85); border: 1px solid var(--gold); color: var(--text);
  font-size: 12px; white-space: nowrap; cursor: pointer;
}
.map-pin i { width: 14px; height: 14px; border-radius: 50%; background: var(--off); box-shadow: 0 0 0 3px #0006; }
.map-pin.on i { background: var(--ok); }
.map-pin:hover { background: rgba(4, 34, 55, 1); z-index: 2; }
.map-board.editing .map-pin { cursor: grab; }
.map-del { color: #ff8a8a; padding-left: 2px; }
#mapList li { cursor: grab; }

/* Menu "⋯" do quadro e configuração da câmera */
.tile-more {
  position: absolute; top: 4px; right: 32px;
  width: 24px; height: 24px; padding: 0;
  border: 1px solid var(--gold); border-radius: 5px;
  background: #0429; color: var(--gold-2); font-size: 14px; line-height: 1;
}
.tile-name { padding-right: 62px; }
.tile-menu {
  position: fixed; z-index: 25; width: 200px; display: grid; padding: 6px;
  border-radius: 10px; background: rgba(10, 40, 60, .96); border: 1px solid var(--line-2); box-shadow: 0 8px 24px #0008;
}
.tile-menu button { background: none; border: 0; text-align: left; padding: 9px 10px; border-radius: 6px; color: var(--text); }
.tile-menu button:hover { background: #ffffff14; }
.cam-card { width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.cam-card h3 { margin: 6px 0 0; font-size: 13px; color: var(--gold-2); letter-spacing: .04em; text-transform: uppercase; }
.cam-streams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cam-stream { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 10px; display: grid; gap: 8px; margin: 0; }
.cam-stream legend { padding: 0 4px; font-size: 12px; color: var(--muted); }
.cam-card select, .cam-card input[readonly] {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); padding: 7px 8px; font: inherit;
}
.cam-card label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.cam-card label.check input { width: auto; }
.cam-clock { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 600px) { .cam-streams { grid-template-columns: 1fr; } }
.input-sm { padding: 5px 8px; font-size: 13px; width: auto; }

/* Alarmes dos equipamentos */
.nvr-events-head { margin-top: 18px; }
.ai-event img.no-snap { object-fit: contain; padding: 18%; opacity: .5; }
.alert-toggles { display: grid; gap: 8px; }
.alert-toggles label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* Imagem e máscaras */
.cam-color { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 14px; }
.cam-color label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; }
.cam-color input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--gold); }
.cam-color output { grid-row: 1; grid-column: 2; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.cam-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px 14px; align-items: center; }
.mask-box { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #000; aspect-ratio: 16 / 9; }
.mask-box img, .mask-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mask-box img { object-fit: fill; }
.mask-box canvas { cursor: crosshair; touch-action: none; }

/* Janelas grandes: título e botões fixos, só o meio rola */
.cam-card { display: flex; flex-direction: column; gap: 0; padding: 0; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px 12px; border-bottom: 1px solid var(--line); }
.modal-body { flex: 1; min-height: 0; overflow: auto; display: grid; gap: 12px; padding: 16px 24px; }
.cam-card .modal-actions { padding: 12px 24px; border-top: 1px solid var(--line); }
.modal-x {
  flex: none; width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 16px; cursor: pointer;
}
.modal-x:hover { color: var(--gold); border-color: var(--gold); }
.modal-body { scrollbar-width: thin; scrollbar-color: var(--gold) transparent; }
.modal-body::-webkit-scrollbar { width: 8px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 8px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.cam-hz { color: var(--text) !important; font-weight: 600; }
.cam-hz select { border-color: var(--gold) !important; }

/* Avisos e confirmações do painel */
.dlg { z-index: 60; }
.dlg-card { width: min(420px, 100%); }
.dlg-card p { color: var(--text); line-height: 1.45; white-space: pre-line; }
.dlg-card input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); padding: 10px 12px; font: inherit; }
.btn-danger { background: #b4232a; border-color: #b4232a; color: #fff; }
.btn-danger:hover { background: #d02a32; }

/* Tabela de equipamentos sem rolagem lateral */
.table small.sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; white-space: normal; }
.table td.wrap { white-space: normal; }
.table td.actions { text-align: right; white-space: normal; }
.table td.actions .btn { margin: 2px 0 2px 4px; }

/* Ajustar várias câmeras */
.bulk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.bulk-color label > span.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
.bulk-color input[type=range]:disabled { opacity: .35; }
.bulk-cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 12px; max-height: 220px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.bulk-cams label.check { font-size: 13px !important; }
.cam-card h3 .btn { margin-left: 8px; text-transform: none; letter-spacing: 0; }
.bulk-progress { display: grid; gap: 6px; }
.bulk-progress .bar { height: 8px; border-radius: 8px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.bulk-progress .bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .4s; }
.bulk-color span.check input { width: auto; margin: 0; }

/* IA: abas */
.ai-tabs { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px; margin: 14px 0 18px; border-bottom: 1px solid var(--line); }
.ai-tabs button { flex: none; white-space: nowrap; }
.ai-tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 10px 14px; font: inherit; cursor: pointer; }
.ai-tabs button:hover { color: var(--text); }
.ai-tabs button.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.tab-tools .input { color-scheme: dark; }

/* Visitantes */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-cards-col { grid-template-columns: 1fr; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; }
.stat small { color: var(--muted); }
.stat strong { font-size: 28px; color: var(--gold); font-variant-numeric: tabular-nums; }
.bars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 4px; height: clamp(200px, 40vh, 460px); align-items: end; padding-top: 18px; }
.bars .bar { height: 100%; display: grid; grid-template-rows: auto 1fr auto; align-items: end; text-align: center; min-width: 0; }
.bars .bar i { display: block; width: 100%; min-height: 2px; background: linear-gradient(var(--gold), var(--gold-2)); border-radius: 4px 4px 0 0; align-self: end; }
.bars .bar span { font-size: 11px; color: var(--text); }
.bars .bar small { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* Uso de celular */

/* Rostos */
.face-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 8px; }
.face { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; }
.face:hover, .face.known { border-color: var(--gold); }
.face img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #000; }
.face figcaption { padding: 6px 8px; display: grid; gap: 2px; font-size: 13px; }
.face figcaption small { color: var(--muted); font-size: 11px; }
.face figcaption .btn { justify-self: start; margin-top: 4px; }

/* Placas */
.plate { display: inline-block; padding: 2px 8px; border-radius: 4px; background: #fff; color: #111; border-top: 5px solid #1f4fa8; font: 700 15px/1.2 ui-monospace, Menlo, monospace; letter-spacing: .06em; }
.plate-snap { width: 120px; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 6px; display: block; }
.alert-row td { background: #b4232a22; }
.watch-list { display: flex; flex-wrap: wrap; gap: 8px; }
.watch { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: 13px; }
/* o miolo da janela rola inteiro: nenhuma seção é espremida para caber */
.modal-body { grid-auto-rows: max-content; align-content: start; }
.bulk-cams { min-height: 120px; }

/* Montar tela personalizada */
.screen-card { width: min(860px, 100%); }
.screen-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.screen-pick > div { display: grid; gap: 8px; align-content: start; min-width: 0; }
.screen-pick h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.pick-list { list-style: none; margin: 0; padding: 4px; height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.pick-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 6px; font-size: 14px; }
.pick-list li small { color: var(--muted); font-size: 11px; }
#screenAvail li[data-add] { cursor: pointer; }
#screenAvail li[data-add]:hover { background: var(--panel); color: var(--gold-2); }
.pick-list.chosen { counter-reset: n; }
.pick-list.chosen li:not(.muted)::before { counter-increment: n; content: counter(n); color: var(--gold); font-weight: 700; min-width: 22px; }
.pick-list.chosen li > span:first-of-type { flex: 1; }
.pick-btns { display: flex; gap: 4px; }
.pick-btns button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.pick-btns button:hover { color: var(--gold); border-color: var(--gold); }
.modal-actions .spacer { flex: 1; }
.grid.empty .btn { margin-top: 12px; }
@media (max-width: 700px) { .screen-pick { grid-template-columns: 1fr; } .pick-list { height: 220px; } }

/* Orbi AI: visão geral e briga */
button.stat { text-align: left; font: inherit; color: inherit; cursor: pointer; }
button.stat:hover { border-color: var(--gold); }
.ai-status { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.ai-cam { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 8px; }
.ai-cam small { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips em { font-style: normal; font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--gold); color: var(--gold-2); }
.fight-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); gap: 16px; align-items: start; margin-bottom: 14px; }
.fight-head h2 { margin: 0 0 6px; }
.fight-cams { display: grid; gap: 8px; }
.ev-actions { display: flex; gap: 6px; margin-top: 6px; }
.ai-event.dismissed { opacity: .55; }
@media (max-width: 800px) { .fight-head { grid-template-columns: 1fr; } }
/* Grade 5×5 e 6×6: quadros pequenos, textos e botões menores */
.grid.dense { gap: 2px; }
.grid.dense .tile-name { font-size: 11px; padding: 3px 6px; }
.grid.dense .badge, .grid.dense .quality { font-size: 10px; padding: 1px 5px; }
.grid.dense .tile-more, .grid.dense .tile-expand { transform: scale(.75); transform-origin: top right; }
.tile .tile-name { cursor: grab; }
.tile.dragging { opacity: .4; }
.title.spacer { flex: 1; }
.panel-hint { color: var(--muted); font-size: 12px; margin: 4px 2px 8px; }
/* Mapa de calor */
.heat-wrap { background: #000; border: 2px solid var(--gold); border-radius: 12px; overflow: hidden; box-shadow: 0 0 16px #e2b73c33; max-width: min(100%, calc((100vh - 300px) * 16 / 9)); margin: 0 auto; }
.heat-wrap canvas { width: 100%; height: auto; display: block; }
/* Detecção de presença (áreas) */
.zone-wrap { position: relative; border: 2px solid var(--gold); border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 16/9; max-width: min(100%, calc((100vh - 340px) * 16 / 9)); margin: 0 auto; }
.zone-wrap img, .zone-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.zone-wrap img { object-fit: fill; }
.zone-wrap canvas { cursor: crosshair; }
/* Barra de rolagem fina e discreta na lista de câmeras */
.cam-list { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.cam-list::-webkit-scrollbar { width: 6px; }
.cam-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
.cam-list::-webkit-scrollbar-thumb:hover { background: var(--gold); }
.cam-list::-webkit-scrollbar-track { background: transparent; }
/* Rolagem fina e discreta em todo o painel (nada de barra cinza grossa) */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
*::-webkit-scrollbar-thumb:hover { background: var(--gold); }
*::-webkit-scrollbar-track { background: transparent; }
/* Visitantes: cartões coloridos, controles e gráfico */
/* Cards no padrão da Central de IA: card escuro, borda colorida à esquerda, número grande na cor do card */
.stat-cards-grad { gap: 12px; margin-bottom: 14px; }
.stat-cards-grad .stat {
  --accent: #60a5fa;
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 17%, var(--panel)), var(--panel) 70%);
  color: #fff;
  padding: 10px 15px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 12px;
}
.stat-cards-grad .stat small { color: #cdddeb; font-size: 12px; font-weight: 600; letter-spacing: .01em; }
.stat-cards-grad .stat strong { font-size: 26px; line-height: 1; justify-self: end; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-cards-grad button.stat { transition: filter .12s, border-color .12s; }
.stat-cards-grad button.stat:hover { filter: brightness(1.12); border-color: var(--accent); }
.stat-cards-grad .stat:nth-child(1) { --accent: #60a5fa; }  /* azul */
.stat-cards-grad .stat:nth-child(2) { --accent: #22d3ee; }  /* ciano */
.stat-cards-grad .stat:nth-child(3) { --accent: #34d399; }  /* verde */
.stat-cards-grad .stat:nth-child(4) { --accent: #a78bfa; }  /* roxo */
.stat-cards-grad .stat:nth-child(5) { --accent: #fbbf24; }  /* dourado */
.stat-cards-grad .stat:nth-child(6) { --accent: #f472b6; }  /* rosa */
.count-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.count-head h2 { margin: 0; }
.tab-tools label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.count-detail { margin-top: 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-size: 14px; }
.bars .bar.empty i { background: transparent; }
.bars .bar.on i { outline: 2px solid #fff; }
.bars.bars-blue .bar i { background: linear-gradient(#60a5fa, #2563eb); }
.bars.bars-teal .bar i { background: linear-gradient(#5eead4, #0d9488); }
.bars .bar { cursor: pointer; }
/* Zoom digital no viewer */
.viewer.zoomed #viewerVideo, .viewer.zoomed #viewerPreview { cursor: grab; }
.viewer-zoom { position: absolute; left: 12px; bottom: 64px; z-index: 5; padding: 6px 10px; border-radius: 10px;
  background: rgba(40,96,128,.65); backdrop-filter: blur(8px); border: 1px solid var(--gold); color: var(--gold-2);
  font: 600 13px/1 inherit; cursor: pointer; }
.viewer-zoom:hover { color: #fff; }

/* Uso de celular: no padrão da Presença (mídia limitada à tela + faixa de miniaturas) */
.phone-chips { display: inline-flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 14px; }
.phone-chips b { color: var(--gold-2); font-size: 18px; margin-left: 4px; }
.ai-tab[data-tab=phone] .phone-spot { position: relative; margin: 0 auto 12px; max-width: min(100%, calc((100vh - 330px) * 16 / 9));
  aspect-ratio: 16 / 9; background: #000; border: 2px solid var(--gold); border-radius: 12px; overflow: hidden; }
.ai-tab[data-tab=phone] .phone-spot img { width: 100%; height: 100%; object-fit: contain; display: block; cursor: zoom-in; }
.ai-tab[data-tab=phone] .phone-spot figcaption { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 14px; background: linear-gradient(transparent, #000c); color: #fff; }
.phone-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.phone-strip img { height: 80px; aspect-ratio: 16 / 10; object-fit: contain; background: #000; border-radius: 8px; border: 2px solid var(--line); cursor: pointer; flex: none; }
.phone-strip img.on { border-color: var(--gold); }
/* Editor de telas: grupos por equipamento */
.pick-list .pick-group { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: -4px;
  background: var(--panel); margin: 4px -4px 2px; padding: 6px 10px; border-radius: 0; border-bottom: 1px solid var(--line); }
.pick-list .pick-group strong { color: var(--gold-2); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.pick-list .pick-group:hover { background: var(--panel); color: inherit; }
#screenAvail li[data-add] { padding-left: 16px; }
.screen-pick h3 { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.screen-pick h3 .btn { text-transform: none; letter-spacing: 0; }
/* Barra de maior valor (pico) destacada em dourado */
.bars .bar.peak i { background: linear-gradient(var(--gold-2), var(--gold)) !important; box-shadow: 0 0 10px #e2b73c88; }
.bars .bar.peak span { color: var(--gold-2); font-weight: 700; }
/* Timelapse */
.tl-result { display: grid; gap: 10px; justify-items: start; max-width: min(100%, calc((100vh - 280px) * 16 / 9)); }
.tl-result video { width: 100%; border: 2px solid var(--gold); border-radius: 12px; background: #000; }
.inp-num { width: 60px; }
#zoneAbsOpts { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
/* Relatórios */
#view-reports .page-head { align-items: center; }
#view-reports .page-head select { color-scheme: dark; }
#repCards { margin-bottom: 8px; }
.table .dot { margin-right: 4px; }
.rep-tools { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
/* Cabeçalho de seção no seletor de câmeras (Equipamentos / Minhas telas) */
.dd-menu .dd-head { padding: 8px 12px 4px; color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; cursor: default; pointer-events: none; }
.dd-menu .dd-head:first-child { padding-top: 2px; }

/* ----- Escolher câmeras com IA ----- */
.aipick-card { width: min(900px, 94vw); }
.aipick-list { max-height: calc(100vh - 300px); overflow: auto; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.aipick-row { display: flex; align-items: center; gap: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); flex-wrap: wrap; }
.aipick-cam { min-width: 180px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.aipick-feats { display: flex; flex-wrap: wrap; gap: 6px 14px; flex: 1; }
.aipick-feat { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.aipick-feat input { accent-color: var(--gold); }
#aiPickSearch { width: 100%; }

/* ----- Uniforme (funcionários não contam) ----- */
.uni-box { padding: 8px 12px; margin: 6px 0 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.uni-head { margin: 0; }
.uni-list { display: flex; flex-wrap: wrap; gap: 8px; min-height: 22px; align-items: center; }
.uni-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.uni-chip i { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); }
.uni-chip button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 2px; }
.uni-chip button:hover { color: #fff; }
.uni-add { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.uni-add input[type=color] { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer; }

/* ----- Ver foto ampliada (lightbox) ----- */
.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(2,14,24,.86); display: flex; align-items: center; justify-content: center; padding: 24px; backdrop-filter: blur(2px); }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.6); object-fit: contain; }
.lb-x { position: absolute; top: 16px; right: 20px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: #fff; font-size: 18px; cursor: pointer; }
.lb-x:hover { background: var(--panel-2); }
img.zoomable, .plate-snap { cursor: zoom-in; }

/* ----- Tela da IA cabe sem rolar a página: prende a view e deixa o conteúdo se ajustar ----- */
#view-ai.view.page { overflow: hidden; display: flex; flex-direction: column; }
#view-ai > .page-head, #view-ai > .ai-tabs { flex: 0 0 auto; }   /* cabeçalho e abas não encolhem (senão a barra de abas some) */
#view-ai .ai-tab { flex: 1 1 auto; min-height: 0; overflow: auto; }         /* listas longas rolam só aqui dentro, não a página toda */
/* Visitantes: cards + gráfico numa tela só (o gráfico encolhe para caber) */
#view-ai .ai-tab[data-tab=count]:not(.hidden) { display: flex; flex-direction: column; overflow: hidden; }
.ai-tab[data-tab=count] > .card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.ai-tab[data-tab=count] .bars { flex: 1 1 auto; min-height: 92px; height: auto; }

/* Marcar pessoa cadastrada como funcionário (não conta como visitante) */
.emp-check { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); margin: 4px 0; cursor: pointer; }
.emp-check input { accent-color: var(--gold); }

.src-tag { font-style: normal; font-size: 10px; font-weight: 700; color: #9ec5ff; border: 1px solid #3a6ea5; border-radius: 4px; padding: 1px 4px; margin-left: 6px; vertical-align: middle; }
