/*
 * --text, --accent, --accent-text e --radius NÃO estão mais aqui --
 * moveram pra tokens.css (item 25), que agora é a única fonte desses 4
 * nomes. A aparência de hoje é preservada pela classe .legacy-shell (no
 * <body> de index/wall/tutorial), que redeclara os valores antigos
 * exatos abaixo. --accent-dim fica aqui mesmo -- não colide, e seu valor
 * rgba já é literal (não referencia var(--accent)).
 */
:root {
  --bg: #1a2226;
  --bg-alt: #1f2a2f;
  --panel: #2b363b;
  --panel2: #344146;
  --border: #3f4c52;
  --muted: #9aa8ac;
  --accent-dim: rgba(242, 161, 52, .18);
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --shadow: 0 4px 18px rgba(0, 0, 0, .35);
}

/* Item pedido pelo cliente: modo claro, escolha do usuário (persistido em
   users.preferences.theme via PUT /api/auth/me/preferences, aplicado no
   boot -- ver applyTheme() em app.js). Mantém o mesmo âmbar de marca
   (--accent/--accent-text vêm do .legacy-shell, ver nota abaixo) --
   só o fundo/superfícies/texto neutro trocam. */
:root[data-theme="light"] {
  --bg: #f6f4ef;
  --bg-alt: #ffffff;
  --panel: #ffffff;
  --panel2: #f0ece3;
  --border: #ddd6c8;
  --muted: #766f60;
  --accent-dim: rgba(217, 134, 10, .13);
  --green: #1a7f37;
  --red: #cf222e;
  --yellow: #9a6700;
  --shadow: 0 2px 12px rgba(40, 35, 20, .1);
}
/* --text/--accent-text são redeclarados pelo .legacy-shell (ver tokens.css)
   direto no <body>, o que vence a herança de :root -- precisa de uma regra
   pelo menos tão específica quanto essa, mirando body, pra ganhar no claro. */
html[data-theme="light"] body.legacy-shell {
  --text: #2a2620;
  --accent-text: #1a2226;
}

* { box-sizing: border-box; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
body {
  margin: 0;
  font-family: var(--font-sans, -apple-system, "Segoe UI", Roboto, system-ui, sans-serif);
  background: var(--bg);
  color: var(--text);
  font-size: 15.5px;
}
button {
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 500;
  transition: filter .15s ease, transform .05s ease;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost, a.ghost { background: var(--panel2); color: var(--text); }
button.ghost:hover, a.ghost:hover { background: #232f3d; filter: none; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 15px;
}
textarea { font-family: inherit; resize: vertical; width: 100%; }
/* Multi-select nativo (config em lote, rota de notificação) fica muito cru
   por padrão -- só o hint "Ctrl/Cmd+clique" dava conta de indicar o
   comportamento. Opção marcada ganha destaque de cor + linha lateral,
   linhas ganham respiro/hover -- sem trocar o <select multiple> nativo por
   um componente customizado (menor risco, mesmo comportamento de teclado
   e acessibilidade já esperado pelo usuário). */
select[multiple] { padding: 6px; }
select[multiple] option {
  padding: 9px 12px; margin: 2px 0; border-radius: 6px; cursor: pointer;
  border-left: 3px solid transparent;
}
select[multiple] option:checked {
  background: linear-gradient(0deg, var(--accent-dim), var(--accent-dim));
  color: var(--accent); border-left-color: var(--accent); font-weight: 600;
}
select[multiple] option:hover { background: var(--panel2); }

/* QR Code do setup de 2FA -- fundo branco fixo (não segue tema claro/
   escuro) porque QR precisa de contraste alto pra escanear bem, seja
   qual for o tema do app. */
.totp-qr { display: inline-block; background: #fff; padding: 12px; border-radius: 10px; margin: 6px 0; }
.totp-qr img { display: block; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input[type="checkbox"], input[type="radio"] {
  width: 15px; height: 15px; flex-shrink: 0; accent-color: var(--accent);
  margin: 0;
}
code {
  background: var(--panel2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13.5px; }
.error { color: var(--red); min-height: 18px; font-size: 14.5px; }

/* ---------- login ---------- */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
  background: radial-gradient(circle at 25% 20%, #3a464c, var(--bg) 55%);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  padding: 36px 32px;
  border-radius: 16px;
  display: flex; flex-direction: column; gap: 12px;
  width: 320px;
  align-items: center;
  animation: loginCardIn .45s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes loginCardIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.login-logo { width: 56px; height: 56px; }
.login-card h1 { font-size: 20px; margin: 0; letter-spacing: .2px; }
.login-sub { margin: -6px 0 10px; color: var(--muted); font-size: 14px; text-align: center; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 4px; padding: 10px; }
.login-privacy-link {
  width: auto !important; margin-top: 6px !important; padding: 4px !important;
  background: transparent !important; color: var(--muted); font-size: 13px;
  text-decoration: underline; text-underline-offset: 2px;
}
.login-privacy-link:hover { color: var(--text); }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }

/* menu superior: categorias -- clicar numa abre o submenu correspondente
   na barra lateral recolhível abaixo. */
.topcats {
  display: flex; align-items: center; gap: 2px;
  padding: 0 14px; height: 56px; flex-shrink: 0;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.topcats-brand { display: flex; align-items: center; gap: 9px; padding-right: 16px; margin-right: 6px; border-right: 1px solid var(--border); flex-shrink: 0; }
.topcats-brand img { width: 24px; height: 24px; }
.topcats-brand .brand-name { font-weight: 700; font-size: 15.5px; letter-spacing: .1px; white-space: nowrap; }
/* Só ícone por padrão -- o rótulo vira um tooltip flutuante que aparece no
   hover/foco (item pedido: menu superior compacto, o nome expande ao lado
   do ícone ao passar o mouse, dentro do próprio botão). No mobile (media
   query abaixo) isso é revertido: hover não existe em touch, então o texto
   volta a ficar visível embaixo do ícone. */
.topcat {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: transparent; color: var(--muted);
  padding: 11px; border-radius: 8px;
  font-size: 15px; font-weight: 500; white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s ease, color .15s ease;
}
.topcat svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; transition: opacity .15s ease, transform .15s ease; }
.topcat:hover { background: var(--panel2); color: var(--text); }
.topcat:hover svg { transform: translateY(-1px); }
.topcat.active { background: var(--accent-dim); color: var(--accent); }
.topcat.active svg { opacity: 1; }
.topcat.active::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px;
  height: 2px; border-radius: 2px; background: var(--accent);
}

.topcat > span, .topcat-util > span {
  display: inline-block;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width .2s ease, opacity .15s ease;
}
.topcat:hover > span, .topcat:focus-visible > span, .topcat.active > span,
.topcat-util:hover > span, .topcat-util:focus-visible > span {
  max-width: 160px;
  opacity: 1;
}

.topcats-account {
  display: flex; align-items: center; gap: 2px;
  margin-left: auto; padding-left: 14px; flex-shrink: 0;
}
.topcats-who { color: var(--muted); font-size: 14px; white-space: nowrap; margin-right: 8px; }
.topcats-clock {
  color: var(--text); font-size: 14px; font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums; margin-right: 12px; padding-right: 12px;
  border-right: 1px solid var(--border);
}
.topcat-util {
  position: relative;
  font-size: 14.5px; padding: 9px;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap; color: var(--muted); border-radius: 8px;
}
.topcat-util svg { width: 18px; height: 18px; opacity: .8; }
.topcat-util:hover { background: var(--panel2); color: var(--text); }

.app-body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 216px; flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: relative;
  transition: width .16s ease;
}
.sidebar.collapsed { width: 60px; }
.sidebar.no-submenu { display: none; }

#sidebar-resize-handle {
  position: absolute; top: 0; right: -3px; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 5;
}
#sidebar-resize-handle:hover, #sidebar-resize-handle.dragging { background: var(--accent-dim); }
.sidebar.collapsed #sidebar-resize-handle { display: none; }

.sidebar-collapse-btn {
  display: flex; align-items: center; justify-content: flex-end;
  width: 100%; height: 34px; flex-shrink: 0; padding: 0 12px;
  background: transparent; color: var(--muted);
  border-bottom: 1px solid var(--border-soft, var(--border));
}
.sidebar-collapse-btn:hover { color: var(--text); }
.sidebar-collapse-btn svg { width: 15px; height: 15px; transition: transform .16s ease; }
.sidebar.collapsed .sidebar-collapse-btn { justify-content: center; }
.sidebar.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

.tabs { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; overflow-y: auto; }
.tabs[hidden] { display: none; }
/* Bug encontrado (2026-08): estas regras eram `.tabs button` (descendente
   -- combina QUALQUER botão dentro de .tabs, não só os itens de navegação
   do topo do menu). O botão de editar dentro de cada linha da árvore
   (.lt-row-edit, vários níveis mais fundo dentro de .tabs) também é um
   <button>, então herdava width:100% -- com flex-shrink:0 ele nunca
   devolvia esse espaço, espremendo pra 0px os vizinhos que encolhem
   (.lt-nvr-name, .dot), fazendo nome e bolinha de status sumirem. `>`
   restringe pros filhos DIRETOS de .tabs (os botões reais de navegação),
   sem afetar nada aninhado mais fundo como a árvore de NVR/câmera. */
.tabs > button {
  display: flex; align-items: center; gap: 10px;
  background: transparent; color: var(--muted);
  padding: 10px 12px; border-radius: 8px;
  font-size: 15px; font-weight: 500;
  text-align: left; width: 100%;
}
.tabs > button svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .8; }
.tabs > button:hover { background: var(--panel2); color: var(--text); }
.tabs > button.active { background: var(--accent-dim); color: var(--accent); }
.tabs > button.active svg { opacity: 1; }
.sidebar.collapsed .tabs > button span { display: none; }
.sidebar.collapsed .tabs > button { justify-content: center; padding: 10px; }
.sidebar.collapsed .live-tree { display: none; }
.sidebar.collapsed .live-tree-search-wrap { display: none; }
.live-tree-search-wrap { padding: 8px 10px 0; }
.live-tree-search {
  width: 100%; padding: 7px 10px; font-size: 14px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 7px; color: var(--text);
}
.live-tree-search::placeholder { color: var(--muted); }
.live-tree { margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 14.5px; }
.live-tree-header {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 6px 12px 10px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted);
}
.live-tree-header strong { color: var(--text); font-weight: 700; letter-spacing: .02em; }
.live-tree-header-actions { display: flex; gap: 4px; flex-shrink: 0; width: 100%; }
.live-tree-header-actions button {
  font-size: 12.5px; padding: 5px 8px; display: flex; align-items: center; gap: 4px;
  background: var(--panel2); color: var(--muted); border-radius: 6px; flex: 1; justify-content: center;
}
.live-tree-header-actions button:hover { color: var(--text); background: #3a474d; }
.live-tree-header-actions button.active { color: var(--accent); background: var(--accent-dim); }
.lt-area-name { padding: 6px 12px 4px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.lt-nvr {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; cursor: pointer; border-radius: 6px; margin: 0 4px;
  user-select: none;
}
.lt-nvr:hover { background: var(--panel2); }
.lt-nvr:hover .lt-row-edit { opacity: 1; }
.lt-nvr-caret { width: 10px; font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.lt-nvr-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.lt-icon { width: 15px; height: 15px; flex-shrink: 0; opacity: .75; }
.lt-row-edit {
  flex-shrink: 0; opacity: 0; padding: 3px; font-size: 13.5px; line-height: 1;
  background: transparent; color: var(--muted); transition: opacity .1s ease;
}
.lt-row-edit:hover { color: var(--accent); }
.lt-cams { padding-left: 26px; }
.lt-cams.hidden { display: none; }
.lt-cam {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 4px; cursor: pointer; border-radius: 6px; margin: 0 4px;
  font-size: 14px; color: var(--muted);
}
.lt-cam:hover { background: var(--panel2); color: var(--text); }
.lt-cam:hover .lt-row-edit { opacity: 1; }
.lt-cam-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lt-cams-loading, .lt-cams-empty { padding: 6px 12px; font-size: 13.5px; }
.lt-hidden-by-filter { display: none !important; }
.badge {
  background: var(--red); color: #fff; border-radius: 10px;
  padding: 0 6px; font-size: 12.5px; margin-left: auto;
}
/* .badge-green já era usada na aba "Reconhecidos" mas nunca tinha sido
   definida -- caía sempre no vermelho padrão de .badge. badge-amber é nova,
   pra aba "Pausados" (redesign da Central de Alarmes via demo). */
.badge-green { background: var(--green); }
.badge-amber { background: var(--yellow); }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.page-title { font-size: 17.5px; font-weight: 600; }

main { flex: 1; overflow-y: auto; padding: 22px 26px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar-group { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.dropdown { position: relative; display: inline-flex; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); min-width: 200px; padding: 4px;
  display: flex; flex-direction: column; gap: 2px;
}
.dropdown-menu.hidden { display: none; }
.dropdown-item {
  text-align: left; width: 100%; padding: 9px 11px; border-radius: 6px;
  background: transparent; color: var(--text); white-space: nowrap; font-size: 15px;
}
.dropdown-item:hover { background: var(--panel2); }
.dropdown-menu.filter-menu { padding: 10px; gap: 10px; min-width: 220px; }
.dropdown-menu.filter-menu label {
  display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13.5px;
}
.dropdown-menu.filter-menu label.filter-check {
  flex-direction: row; align-items: center; gap: 8px; font-size: 14.5px;
}
.dropdown-menu.filter-menu select { width: 100%; }
.sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }

.tabs-inline {
  display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); padding-bottom: 10px;
}
.tab-inline {
  background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 8px;
  font-size: 14.5px; font-weight: 500;
  border: 1px solid transparent;
}
.tab-inline:hover { background: var(--panel2); color: var(--text); }
.tab-inline.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* ---------- live grid ---------- */
.live-body { display: flex; gap: 14px; align-items: flex-start; }
.live-body #grid { flex: 1; min-width: 0; }
.grid { display: grid; gap: 10px; }
.grid-1 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
.grid-9 { grid-template-columns: repeat(3, 1fr); }
.grid-16 { grid-template-columns: repeat(4, 1fr); }
.cell {
  position: relative; aspect-ratio: 16/9;
  background: #000; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer;
  transition: outline-color .15s ease;
}
.cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell.selected-target { outline: 2px solid var(--yellow); outline-offset: -2px; }
.cell.cell-drag-over { outline: 3px dashed var(--accent); outline-offset: -3px; }
.cell iframe { width: 100%; height: 100%; border: 0; pointer-events: none; }
.cell .label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  padding: 5px 10px; font-size: 13.5px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
  color: #f0f0f0;
}
.cell .label span { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cell .label span:first-child {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell .label span:last-child { flex-shrink: 0; }
.cell-target-btn {
  background: transparent; padding: 0 2px; font-size: 13.5px; opacity: .7; line-height: 1;
}
.cell-target-btn:hover { opacity: 1; }
.cell .empty { display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: #b8b8b8; gap: 4px; text-align: center; padding: 8px; }
.cell .offline-msg { gap: 6px; }
.cell .offline-msg .offline-icon { font-size: 24px; opacity: .5; filter: grayscale(1); }
.cell .offline-msg strong { color: #f0f0f0; font-size: 14.5px; }
.cell .offline-msg button { margin-top: 4px; font-size: 13.5px; padding: 5px 10px; }
.cell-loading-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; background: #000; color: #b8b8b8; font-size: 14px;
  pointer-events: none;
}
.cell-spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: cellSpin .8s linear infinite;
}
@keyframes cellSpin { to { transform: rotate(360deg); } }
.ptz-lock-badge { opacity: .9; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* Item pedido pelo cliente: controle PTZ direto na célula da grade ao
   vivo (canto superior esquerdo), sem precisar abrir o modal da câmera --
   só aparece no hover pra não poluir uma grade 4x4 cheia de células PTZ. */
.cell-ptz-overlay {
  position: absolute; top: 6px; left: 6px; z-index: 6;
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
  opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.cell:hover .cell-ptz-overlay { opacity: 1; pointer-events: auto; }
.cell-ptz-pad {
  display: grid; grid-template-columns: repeat(3, 20px); grid-template-rows: repeat(3, 20px); gap: 2px;
  background: rgba(0,0,0,.6); padding: 4px; border-radius: 8px;
}
.cell-ptz-pad button {
  padding: 0; font-size: 11.5px; line-height: 1; background: rgba(255,255,255,.1); color: #fff;
  border-radius: 4px; touch-action: none;
}
.cell-ptz-pad button:hover { background: var(--accent); color: var(--accent-text); }
.cell-ptz-pad .cell-ptz-center { background: transparent !important; cursor: default; opacity: .3; }
.cell-ptz-zoom { display: flex; gap: 2px; width: 100%; }
.cell-ptz-zoom button {
  padding: 3px 0; font-size: 11.5px; flex: 1; background: rgba(0,0,0,.6); color: #fff; border-radius: 6px;
  touch-action: none;
}
.cell-ptz-zoom button:hover { background: var(--accent); color: var(--accent-text); }

.recordings-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 70px 20px; color: var(--muted); text-align: center;
}
.recordings-empty-icon { font-size: 32px; opacity: .5; }
.dot.online { background: var(--green); box-shadow: 0 0 6px rgba(63,185,80,.7); }
.dot.offline { background: var(--muted); }
.dot.alarm { background: var(--red); box-shadow: 0 0 6px rgba(248,81,73,.8); }

@media (max-width: 960px) {
  .live-body { flex-direction: column; }
}

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.data-table th {
  color: var(--muted); font-weight: 600; font-size: 13px;
  text-transform: uppercase; letter-spacing: .4px;
}
.data-table tbody tr:hover { background: rgba(255, 255, 255, .025); }
.data-table th.sortable-th { cursor: pointer; user-select: none; white-space: nowrap; }
.data-table th.sortable-th:hover { color: var(--text); }
.data-table th .sort-arrow { color: var(--accent); }
.col-sticky-actions {
  position: sticky; right: 0; background: var(--panel);
  box-shadow: -6px 0 8px -6px rgba(0,0,0,.4);
}
.data-table tbody tr:hover .col-sticky-actions { background: #2f3a3f; }
.pill { padding: 2px 9px; border-radius: 10px; font-size: 13px; font-weight: 500; white-space: nowrap; display: inline-block; }
.pill.new, .pill.active { background: rgba(248, 81, 73, .18); color: #ff8b85; }
.pill.acknowledged, .pill.snoozed { background: rgba(210, 153, 34, .18); color: #f0b445; }
.pill.completed, .pill.acked { background: rgba(63, 185, 80, .18); color: #5fd873; }
.pill.tag { background: rgba(88, 166, 255, .18); color: #79c0ff; }

/* ---------- alarm panel (Painel de Alarmes) ---------- */
.ap-toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.ap-search-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ap-search-row #ap-search { flex: 1; min-width: 220px; }
.ap-search-row input[type="date"] { width: auto; }
.ap-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ap-tab {
  background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 8px 14px; font-size: 14.5px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.ap-tab:hover { color: var(--text); filter: none; }
.ap-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.ap-controls-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ap-viewmode { display: flex; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.ap-vm { background: transparent; color: var(--muted); border-radius: 0; padding: 6px 12px; font-size: 14px; }
.ap-vm:hover { filter: none; color: var(--text); }
.ap-vm.active { background: var(--accent); color: var(--accent-text); }
.ap-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.ap-chip {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 14px;
  color: var(--muted); padding: 4px 12px; font-size: 13.5px;
}
.ap-chip:hover { filter: none; color: var(--text); }
.ap-chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.ap-body { min-height: 100px; }
.ap-cluster-section { margin-bottom: 22px; }
.ap-cluster-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ap-cluster-header strong { font-size: 14.5px; }
.ap-cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.ap-card {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--muted);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer;
  transition: transform .12s ease; display: flex; flex-direction: column;
}
.ap-card:hover { transform: translateY(-2px); }
.ap-card.ap-status-active { border-left-color: var(--red); }
.ap-card.ap-status-snoozed { border-left-color: var(--yellow); opacity: .85; }
.ap-card.ap-status-acked { border-left-color: var(--green); opacity: .8; }
.ap-card.ap-status-completed { border-left-color: var(--muted); opacity: .7; }
.ap-card.ap-trashed { border-left-color: var(--muted); opacity: .6; }
.ap-card.ap-selected { outline: 2px solid var(--accent); }
.ap-card-thumb { aspect-ratio: 16/9; background: #000; position: relative; }
.ap-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ap-card-thumb .ap-no-img { display: flex; align-items: center; justify-content: center; height: 100%; color: #888; font-size: 22px; }
.ap-card-check {
  position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(11,16,24,.85); border: 2px solid var(--border); display: flex;
  align-items: center; justify-content: center; font-size: 12.5px;
}
.ap-card.ap-selected .ap-card-check { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.ap-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.ap-card-top { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.aid { font-family: var(--font-mono, monospace); }
.ap-card-top .ap-time { margin-left: auto; white-space: nowrap; }
/* Redesign da Central de Alarmes (pedido via demo): o título do card virou
   o EVENTO (o que aconteceu), não a usina -- usina/câmera desceram pra
   .ap-card-sub. Hierarquia da demo: evento -> local -> metadados. */
.ap-card-event { font-weight: 600; font-size: 15px; }
.ap-card-sub { font-size: 13.5px; color: var(--muted); }
.ap-card-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.ap-card-actions button { flex: 1; padding: 5px 4px; font-size: 13px; min-width: 90px; }
.pill.pinned { background: rgba(79, 140, 247, .18); color: #79b8ff; }
.pill.noisy { background: rgba(248, 81, 73, .12); color: #ff8b85; }

.ap-bulk-bar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px 14px; margin-top: 14px;
}
/* ---------- panels ---------- */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel {
  background: var(--panel); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 12px; padding: 18px; margin-bottom: 18px;
}
.panel h3 {
  margin: 0 0 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
}
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border); gap: 8px;
}
.list li:last-child { border-bottom: none; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 12px; padding: 18px;
}
.card .big { font-size: 26px; font-weight: 700; margin-top: 2px; }

.dash-kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.dash-kpi {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px 14px 19px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.dash-kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent);
}
.dash-kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--chrome, var(--accent)); }
.dash-kpi-value { font-size: 25px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.dash-kpi-label { font-size: 14px; color: var(--muted); }
.dash-kpi-sub { font-size: 13px; color: var(--muted); opacity: .8; }
.dash-kpi-alert::before { background: var(--red); }
.dash-kpi-alert .dash-kpi-value { color: var(--red); }

.dash-map-panel { margin-bottom: 20px; }
.dash-map-panel h3 { margin-bottom: 12px; }
/* Bug real da "faixa em cima do mapa expandido" (achado só depois de ver
   o print do cliente): nem .dash-map nem #dash-map-modal tinham
   `position` definido. O Leaflet monta seus painéis internos (tiles,
   marcadores, controles de zoom) com position:absolute e z-index de
   200 a 1000 -- isso só fica CONTIDO dentro do próprio mapa se o
   container do mapa estabelecer seu próprio contexto de empilhamento
   (position relative/absolute + z-index). Sem isso, esses z-index
   "vazam" pro contexto de empilhamento do ANCESTRAL mais próximo que
   tiver `position` -- que nesse caso claramente não continha o
   suficiente, e o mapinha do card do dashboard (z-index 1000 dos
   controles dele) vencia o z-index:50 do .modal e aparecia por cima
   do mapa expandido. `position:relative` + `z-index:0` isola cada
   mapa no seu próprio contexto, sem vazar pra lugar nenhum.  */
.dash-map { height: 230px; border-radius: var(--radius); overflow: hidden; background: var(--panel2); position: relative; z-index: 0; cursor: pointer; }
/* Bug encontrado: a versão expandida do mapa ficava presa no limite geral
   de `.modal-body` (width: min(90vw, 900px)) -- em telas largas isso
   deixava uma faixa do mapa cortada/não expandida, bem menor que "tela
   cheia" de verdade. modal-body-map sobrescreve pra ocupar quase a tela
   toda só nesse modal específico. */
.modal-body-map { width: min(96vw, 1400px) !important; height: 90vh; max-height: 90vh; }
/* #modal-content não é flex por padrão (outros modais só crescem com o
   conteúdo) -- vira coluna flex só quando é o modal do mapa, pra
   #dash-map-modal poder usar flex:1 e preencher a altura de verdade. */
.modal-body-map #modal-content { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.modal-map-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0; }
#dash-map-modal { flex: 1; min-height: 0; border-radius: var(--radius); overflow: hidden; margin-top: 12px; position: relative; z-index: 0; }
/* Popup do Leaflet usa fundo/texto fixos por padrão -- reveste com os
   tokens do app pra acompanhar tema claro/escuro em vez de ficar sempre
   branco (ilegível no tema escuro). */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--text);
}
.leaflet-popup-content { margin: 10px 12px; font-size: 14.5px; line-height: 1.5; }
.leaflet-popup-content .usina-popup button {
  font-size: 13.5px; padding: 5px 10px;
}
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--text); }
/* Bug encontrado: a "faixa" que o cliente via ao expandir o mapa era a
   barra de atribuição do Leaflet (fundo branco fixo, canto inferior) --
   nunca tinha sido revestida com os tokens do app, então ficava sempre
   um retângulo branco chamativo sobre o mapa escuro, parecendo uma parte
   "sem estilo"/"sem expandir" do mapa. Botões de zoom tinham o mesmo
   problema (fundo branco fixo do Leaflet). */
.leaflet-container .leaflet-control-attribution {
  background: var(--panel); color: var(--muted);
}
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-control-attribution a:hover, .leaflet-control-attribution a:focus { color: var(--text); }
.leaflet-bar a {
  background-color: var(--panel); color: var(--text); border-bottom-color: var(--border);
}
.leaflet-bar a:hover { background-color: var(--panel2); }
.usina-marker { background: transparent; border: none; }
/* Nome da usina permanente ao lado do marcador (não só no popup ao
   clicar) -- Leaflet tooltip tem fundo branco fixo por padrão, mesmo
   problema do popup, reveste com os tokens do app. */
.leaflet-tooltip.usina-label {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600; padding: 3px 8px; border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.leaflet-tooltip.usina-label::before { border-top-color: var(--border); }
.marker-cluster { background-clip: padding-box; }
.marker-cluster div {
  background: var(--panel); color: var(--text); border: 2px solid var(--accent);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13.5px;
}

.dash-extra-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.dash-extra-panel { margin-bottom: 0; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.dash-extra-panel:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--chrome, var(--accent)); }
.dash-extra-panel h3 { margin: 0 0 10px; font-size: 15px; border-bottom: 0; padding-bottom: 0; }
.dash-extra-panel .list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; }
.dash-extra-panel .list li { display: flex; justify-content: space-between; gap: 8px; font-size: 14.5px; }
.dash-extra-panel .list li span.muted { font-size: 13.5px; flex-shrink: 0; }
.dash-stat-big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dash-stat-big .unit { font-size: 15.5px; font-weight: 500; color: var(--muted); margin-left: 4px; }

/* Donut de NVRs/Câmeras online x offline -- sem lib de gráfico no projeto,
   conic-gradient puro CSS (mesmo espírito sem-dependência dos outros
   charts, que são divs com width/height em %). */
.donut-chart-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut-chart {
  width: 96px; height: 96px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.donut-chart-hole {
  width: 60px; height: 60px; border-radius: 50%; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.1;
}
.donut-chart-hole strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.donut-chart-hole span { font-size: 10.5px; }
.donut-legend { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.donut-legend-item { display: flex; align-items: center; gap: 7px; }
.donut-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.donut-legend-item strong { font-variant-numeric: tabular-nums; }

.dash-cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.dash-card { cursor: pointer; display: flex; flex-direction: column; gap: 10px; transition: border-color .15s; }
.dash-card:hover { border-color: var(--accent); }
.dash-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dash-card-top strong { font-size: 17px; }
.dash-card-stats { display: flex; gap: 14px; font-size: 14.5px; color: var(--muted); }
.dash-card-stats .dot { margin-right: 5px; }
.dash-card-alarm { font-size: 14.5px; color: var(--red); }
.dash-card-btn { align-self: flex-start; }

.cam-mgmt-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.cam-mgmt-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.cam-mgmt-thumb {
  width: 120px; aspect-ratio: 16/9; background: #000; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; border-radius: 6px; overflow: hidden;
}
.cam-mgmt-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-mgmt-thumb button { font-size: 13.5px; padding: 4px 8px; }
.cam-mgmt-thumb .muted { font-size: 12.5px; text-align: center; padding: 0 4px; }
.cam-mgmt-body { padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.cam-mgmt-body .name { font-weight: 600; display: flex; align-items: center; gap: 6px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(6, 9, 14, .78); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-body {
  background: var(--panel); border: 1px solid var(--border);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  border-radius: 14px; padding: 22px; width: min(90vw, 900px);
  max-height: 90vh; position: relative;
  display: flex; flex-direction: column;
}
.modal-close {
  position: absolute; top: 10px; right: 12px; background: var(--panel);
  font-size: 22px; color: var(--muted); padding: 2px 8px; border-radius: 50%;
  z-index: 2; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.modal-close:hover { color: var(--text); }
#modal-content { overflow-y: auto; padding-right: 4px; }
.modal-body iframe { width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 8px; }
.modal-body video { width: 100%; border-radius: 8px; background: #000; }
.modal-body h3 { margin-top: 0; padding-right: 34px; }

/* ---------- formulário de regra de evento (Automação) ---------- */
.evrule-form { display: flex; flex-direction: column; gap: 22px; }
.evrule-section { display: flex; flex-direction: column; gap: 12px; }
.evrule-section-title {
  font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.evrule-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.evrule-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.evrule-days { display: flex; gap: 6px; flex-wrap: wrap; }
.evrule-day-label {
  display: flex; align-items: center; gap: 4px; border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 9px; font-size: 14px; cursor: pointer; user-select: none;
}
.evrule-day-label:has(input:checked) { border-color: var(--accent); color: var(--accent); }
.evrule-actions-list { display: flex; flex-direction: column; gap: 10px; }
.evrule-action-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  display: flex; flex-direction: column; gap: 10px; background: rgba(255,255,255,.02);
}
.evrule-action-card-head { display: flex; align-items: center; gap: 8px; }
.evrule-action-card-head select { flex: 1; }
.evrule-action-fields { display: flex; flex-direction: column; gap: 8px; }
.evrule-action-webhook { width: 100%; padding: 12px 14px; font-size: 16px; min-height: 46px; }
.evrule-modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding-top: 16px; margin-top: 2px; border-top: 1px solid var(--border);
}
@media (max-width: 640px) {
  .evrule-row, .evrule-row-3 { grid-template-columns: 1fr; }
}

/* ---------- toasts ---------- */
.toast-container {
  position: fixed; top: 18px; right: 18px; z-index: 300;
  display: flex; flex-direction: column; gap: 10px; max-width: 360px;
}
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  box-shadow: var(--shadow); border-radius: 10px; padding: 12px 12px 12px 14px;
  font-size: 15px; display: flex; align-items: flex-start; gap: 8px;
  animation: toastIn .18s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
.toast.warning { border-left-color: var(--yellow); }
.toast-msg { flex: 1; word-break: break-word; }
.toast-close { background: transparent; color: var(--muted); padding: 0 2px; font-size: 17.5px; line-height: 1; flex-shrink: 0; }
.toast-close:hover { color: var(--text); }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

.ptz-panel { display: flex; gap: 20px; margin-top: 14px; align-items: flex-start; flex-wrap: wrap; }
.ptz-pad {
  display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px);
  gap: 4px; user-select: none;
}
.ptz-pad button { padding: 0; font-size: 18px; touch-action: none; }
.ptz-pad .ptz-center { background: var(--panel2) !important; cursor: default; opacity: .6; }
.ptz-zoom { display: flex; flex-direction: column; gap: 8px; min-width: 140px; }
.ptz-zoom button { touch-action: none; }
.ptz-zoom input[type="range"] { width: 100%; vertical-align: middle; margin-left: 6px; }

/* ---------- recordings / maps ---------- */
.calendar { display: flex; flex-direction: column; gap: 4px; }
.calendar .day {
  display: flex; justify-content: space-between; padding: 8px 12px;
  background: var(--panel2); border-radius: 7px; cursor: pointer;
  transition: outline-color .1s ease;
}
.calendar .day:hover { outline: 1px solid var(--accent); }

.rec-timeline {
  position: relative; height: 40px; background: var(--panel2);
  border-radius: 7px; margin: 10px 0 6px; border: 1px solid var(--border);
  cursor: pointer;
}
.rec-timeline .tl-hour {
  position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border);
}
/* Item 37 do plano de execução ("Playback"), parte 2: períodos com
   gravação disponível no NVR (via ISAPI), como faixa de fundo -- fica
   embaixo dos marcadores de incidente (ordem no DOM: coverage primeiro,
   sem precisar de z-index já que .rec-timeline é o contexto de
   empilhamento). */
.rec-timeline .tl-coverage {
  position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 35%, transparent);
  border-left: 1px solid color-mix(in srgb, var(--accent) 60%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--accent) 60%, transparent);
}
.rec-timeline .tl-hour-label {
  position: absolute; top: 100%; margin-top: 2px; font-size: 11.5px; color: var(--muted);
  transform: translateX(-50%);
}
.rec-timeline .tl-marker {
  position: absolute; top: 4px; bottom: 4px; width: 6px; margin-left: -3px;
  border-radius: 3px; cursor: pointer; background: var(--red);
  transition: transform .1s ease;
}
.rec-timeline .tl-marker:hover { transform: scaleY(1.15) scaleX(1.6); }

/* Item 38 do plano de execução ("Playback sincronizado") */
.sync-playback-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px;
}
.sync-playback-grid:empty { display: none; }
.sync-playback-grid .sync-cell iframe {
  width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 8px; background: #000; display: block;
}
.sync-playback-grid .sync-cell-label {
  font-size: 13.5px; color: var(--muted); margin: 4px 0; text-align: center;
}

.map-canvas {
  position: relative; width: 100%; max-width: 1100px; background: #000;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  min-height: 300px; background-size: contain; background-repeat: no-repeat;
  background-position: center; box-shadow: var(--shadow);
}
.marker {
  position: absolute; width: 26px; height: 26px; border-radius: 50%;
  transform: translate(-50%, -50%); cursor: pointer; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center; font-size: 14.5px;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.marker.online { background: var(--green); }
.marker.offline { background: var(--muted); }
.marker.alarm { background: var(--red); animation: markerBlink 1s infinite; }
.marker.child-map { background: var(--accent); border-radius: 8px; }
@keyframes markerBlink { 50% { opacity: .25; box-shadow: 0 0 14px 4px rgba(248,81,73,.7); } }
.map-breadcrumb { margin-bottom: 10px; font-size: 14.5px; color: var(--muted); }
.map-breadcrumb button { background: transparent; color: var(--accent); padding: 2px 4px; font-size: 14.5px; }
.map-palette { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.map-palette button { background: var(--panel2); color: var(--text); }
.rep-mini { font-size: 14.5px; }
.rep-mini div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); }

/* ---------- relatórios: dashboard ---------- */
.dashboard-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; line-height: 1.2; }
.stat-sub { font-size: 13.5px; color: var(--muted); margin-top: 3px; }

.chart-bars { display: flex; flex-direction: column; gap: 10px; }
.chart-bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 56px; align-items: center; gap: 10px; font-size: 14.5px; }
.chart-bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.chart-bar-track { background: var(--panel2); border-radius: 6px; height: 16px; overflow: hidden; }
.chart-bar-fill { height: 100%; border-radius: 6px; background: var(--accent); transition: width .4s ease; }
.chart-bar-fill.good { background: var(--green); }
.chart-bar-fill.warn { background: var(--yellow); }
.chart-bar-fill.bad { background: var(--red); }
.chart-bar-value { text-align: right; color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.chart-empty { color: var(--muted); font-size: 14.5px; }

.chart-trend { display: flex; align-items: flex-end; gap: 3px; height: 130px; }
.chart-trend-bar {
  flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 3px;
  position: relative; cursor: default; transition: filter .1s ease;
}
.chart-trend-bar:hover { filter: brightness(1.3); }
.chart-trend-bar .chart-trend-tip {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); padding: 4px 8px;
  border-radius: 6px; font-size: 12.5px; white-space: nowrap; margin-bottom: 6px; z-index: 5;
  box-shadow: var(--shadow);
}
.chart-trend-bar:hover .chart-trend-tip { display: block; }

/* Item pedido pelo cliente: espaçamento dos botões de exportação (PDF/
   Excel) embaixo de cada gráfico de relatório -- antes o .toolbar genérico
   só tinha margin-bottom, então colava direto no gráfico acima sem
   respiro, e ainda sobrava espaço indevido embaixo (dentro do padding do
   .panel). */
.panel > .toolbar:not(:first-child) {
  margin-top: 16px;
  margin-bottom: 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.reports-loading {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 14.5px; margin-left: 4px;
}
.reports-loading .cell-spinner { width: 14px; height: 14px; border-width: 2px; position: static; }
.reports-loading.hidden { display: none; }

@media (max-width: 860px) {
  .app { height: auto; min-height: 100vh; }
  .topcats { overflow-x: auto; height: auto; padding: 6px 10px; position: sticky; top: 0; z-index: 41; }
  .topcats-brand { display: none; }
  .topcat { flex-direction: column; gap: 3px; font-size: 11.5px; padding: 7px 9px; }
  .topcat svg { width: 16px; height: 16px; }
  /* Sem hover em touch -- volta o rótulo pra baixo do ícone, sempre visível
     (reverte o tooltip flutuante do desktop). */
  .topcat > span, .topcat-util > span {
    display: inline; max-width: none; overflow: visible; opacity: 1;
    font-size: 11.5px; color: inherit;
  }
  .topcats-account { gap: 10px; }
  .topcat-util { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 8px; }
  .topcats-who, .topcats-clock { display: none; }
  .app-body { flex-direction: column; }
  .sidebar { width: 100% !important; flex-direction: row; align-items: center; border-right: none; border-bottom: 1px solid var(--border); position: sticky; top: 48px; z-index: 40; }
  .sidebar-collapse-btn { display: none; }
  .tabs[hidden] { display: none !important; }
  .tabs { flex-direction: row; overflow-x: auto; padding: 6px; -webkit-overflow-scrolling: touch; }
  .tabs > button { flex-direction: column; gap: 4px; font-size: 12px; padding: 8px 10px; white-space: nowrap; }
  .tabs > button svg { width: 16px; height: 16px; }
  /* Bug encontrado (2026-08): a regra `.tabs { flex-direction: row }` acima
     foi escrita pensando nos grupos com botões simples de navegação (Sites/
     NVRs/Câmeras etc, viram uma tira horizontal rolável no celular) -- mas
     `.tabs[data-group="live"]` e `[data-group="midia"]` não têm botões,
     têm a busca + a árvore de NVR/câmera inteira. Virando uma linha
     horizontal, a árvore ficava espremida numa largura mínima, e como
     `.lt-nvr-name`/`.dot` encolhem (flex:1 ou sem flex-shrink:0, ao
     contrário do ícone/editar que são flex-shrink:0), o nome e a bolinha de
     status sumiam por falta de espaço -- só o ícone (tamanho fixo)
     continuava aparecendo. Restaura o fluxo vertical normal só pra esses
     dois grupos. */
  .tabs[data-group="live"], .tabs[data-group="midia"] {
    flex-direction: column; overflow-x: visible; flex: 1 1 auto; min-width: 0;
  }
  #sidebar-resize-handle { display: none; }
  .badge { margin-left: 0; }
  .main-wrap { height: auto; }
  main { overflow-y: visible; padding: 16px 14px; }
  .cols { grid-template-columns: 1fr; }
  .grid-9, .grid-16 { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
  .table-scroll table { min-width: 640px; }
  .toast-container { left: 12px; right: 12px; top: 12px; max-width: none; }
  .modal-body { width: min(94vw, 900px); padding: 16px; }
  .inline-form input:not([type="checkbox"]):not([type="radio"]),
  .inline-form select { flex: 1 1 180px; }
  /* .lt-row-edit (editar NVR/câmera direto da árvore) só aparecia no
     :hover da linha -- em touch isso nunca acontece de um jeito que dê
     pra tocar o botão, então ficava inacessível no celular. */
  .lt-row-edit { opacity: .55; }
}

/* ---------- phones ---------- */
@media (max-width: 600px) {
  body { font-size: 16px; }
  main { padding: 12px 10px; }
  .topbar { padding: 10px 12px; }
  .page-title { font-size: 16.5px; }
  .sidebar-brand .brand-name { font-size: 15.5px; }
  .tabs > button { font-size: 11.5px; padding: 7px 8px; }

  /* buttons/inputs: bigger touch targets */
  button { padding: 10px 14px; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select { min-height: 40px; }

  .toolbar { gap: 6px; }
  .toolbar > .sep { display: none; }
  .toolbar select, .toolbar input:not([type="checkbox"]):not([type="radio"]) { flex: 1 1 140px; }
  .toolbar button { flex: 1 1 auto; }

  /* live view: priority mobile target */
  #live-tv { display: none; }
  .grid-1, .grid-4, .grid-9, .grid-16 { grid-template-columns: 1fr; }
  .cell { aspect-ratio: 16/10; }
  .cell .label { font-size: 14px; padding: 7px 10px; }
  .cell-target-btn { padding: 4px 6px; font-size: 16.5px; }
  .live-body { gap: 10px; }

  .ptz-pad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); }
  .ptz-zoom { min-width: 0; flex: 1 1 100%; }

  .modal { align-items: flex-end; }
  .modal-body {
    width: 100%; max-width: none; max-height: 92vh;
    border-radius: 16px 16px 0 0; padding: 16px 14px;
  }

  .login-card { width: min(320px, 88vw); padding: 28px 20px; }

  .cards, .cam-mgmt-grid, .ap-cards-grid { grid-template-columns: 1fr; }
}
