/* Modo escuro. Vale quando <html data-theme="dark"> (static/js/tema.js). Carregado por último: só redefine variáveis e
   substitui os fundos claros escritos direto nos outros CSS. O modo claro (padrão) não é afetado. */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1520;
  --surface: #172230;
  --surface-2: #1d2b3c;
  --border: #2d3d52;
  --text: #e4eaf2;
  --muted: #9aaabd;
  --navy: #b5d0ef;       /* nos temas claros é o azul-marinho dos títulos; aqui vira azul claro para ler sobre fundo escuro */
  --navy-2: #163a63;
  --blue: #5aa0ee;
  --green: #35b583;
  --warn: #e3a94a;
  --danger: #f2766f;
  --realce: #1f3550;     /* fundo de item selecionado/pairado */
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }

/* ---- fundos que precisam continuar escuros mesmo com --navy claro (barra do topo, menu lateral, cabeçalhos) ---- */
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .sb-logo,
html[data-theme="dark"] .sb-titulo { background: linear-gradient(90deg, #0b1d33, #12304f); }
html[data-theme="dark"] .sup-head,
html[data-theme="dark"] .sup-toast,
html[data-theme="dark"] .sup-notif,
html[data-theme="dark"] .fila-topo,
html[data-theme="dark"] .compare thead th,
html[data-theme="dark"] .bk-num { background: #12304f; color: #fff; }
html[data-theme="dark"] .compare thead th:first-child { background: transparent; }
html[data-theme="dark"] .compare thead th:nth-child(4) { background: #2a3b50; }
html[data-theme="dark"] .login-body { background: linear-gradient(180deg, #0b1d33 0, #12304f 260px, var(--bg) 260px); }
html[data-theme="dark"] .login-brand h1, html[data-theme="dark"] .login-brand p { color: #e4eaf2; }
html[data-theme="dark"] .kpi.ativo { outline-color: var(--blue); }

/* ---- campos de formulário ---- */
html[data-theme="dark"] select,
html[data-theme="dark"] input:not([type=checkbox]):not([type=radio]),
html[data-theme="dark"] textarea,
html[data-theme="dark"] .sb-busca { background: var(--surface-2); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: #70829a; }
html[data-theme="dark"] select:focus, html[data-theme="dark"] input:focus, html[data-theme="dark"] textarea:focus { outline-color: rgba(90,160,238,.5); }
html[data-theme="dark"] label { color: #c6d2e1; }
html[data-theme="dark"] .legend-inner p, html[data-theme="dark"] .legend-list, html[data-theme="dark"] .compare tbody th { color: #c6d2e1; }

/* ---- botões, selos e alertas ---- */
html[data-theme="dark"] .btn-primary { background: #2f6fbd; color: #fff; }
html[data-theme="dark"] .btn-primary:hover { background: #3a7dd0; }
html[data-theme="dark"] .btn-secondary { background: #25364b; color: var(--text); }
html[data-theme="dark"] .btn-secondary:hover { background: #2f445c; }
html[data-theme="dark"] .badge, html[data-theme="dark"] .bloq-concluiu, html[data-theme="dark"] .mr-contagem { background: #25364b; color: var(--text); }
html[data-theme="dark"] .badge-ok, html[data-theme="dark"] .bloq-liberado { background: #14392b; color: #6fdcae; }
html[data-theme="dark"] .badge-off { background: #243142; color: var(--muted); }
html[data-theme="dark"] .badge-warn, html[data-theme="dark"] .bloq-contagem { background: #3d3115; color: #f0c264; }
html[data-theme="dark"] .badge-info, html[data-theme="dark"] .sup-chip, html[data-theme="dark"] .bk-onde { background: #1b3552; color: #b5d0ef; }
html[data-theme="dark"] .bloq-bloqueado { background: #4a2020; color: #ff9d97; }
html[data-theme="dark"] .alert-success { background: #123226; color: #8fe3bb; }
html[data-theme="dark"] .alert-error { background: #3b1b1b; color: #ffaaa4; }
html[data-theme="dark"] .alert-warning { background: #382d12; color: #f0cc82; }
html[data-theme="dark"] .alert-info { background: #17304b; color: #b5d0ef; }
html[data-theme="dark"] .alerta-documento { background: #3b1b1b; border-color: #7a3030; color: #ffaaa4; }
html[data-theme="dark"] .assumir-bloqueio { background: #382d12; border-color: #6b5420; color: #f0cc82; }
html[data-theme="dark"] .grade-aviso.ok { color: #6fdcae; }

/* ---- cartões, painéis, listas e tabelas ---- */
html[data-theme="dark"] .card, html[data-theme="dark"] .panel, html[data-theme="dark"] .kpi,
html[data-theme="dark"] .hist-item, html[data-theme="dark"] .nov-item { box-shadow: 0 1px 3px rgba(0,0,0,.4); }
html[data-theme="dark"] .card:hover, html[data-theme="dark"] .kpi:hover { box-shadow: 0 8px 18px rgba(0,0,0,.5); }
html[data-theme="dark"] .card-icon { background: #1b3552; }
html[data-theme="dark"] .card-star:hover { background: #3a3015; }
html[data-theme="dark"] code, html[data-theme="dark"] .sql-pre { background: #0e1824; color: #d3deec; }
html[data-theme="dark"] .ac-list li:hover, html[data-theme="dark"] .legend-toggle:hover,
html[data-theme="dark"] .compare tr:hover td, html[data-theme="dark"] .compare tr:hover th,
html[data-theme="dark"] .grade-rolagem tbody tr:hover, html[data-theme="dark"] table.grade tbody tr:hover,
html[data-theme="dark"] .tbl tr:hover td, html[data-theme="dark"] .dic-tab:hover { background: var(--realce); }
html[data-theme="dark"] .header-info, html[data-theme="dark"] .compare tbody th, html[data-theme="dark"] .stat-bar,
html[data-theme="dark"] .ws-janela-topo, html[data-theme="dark"] .grade-rodape,
html[data-theme="dark"] .consulta-filtros-selecao, html[data-theme="dark"] .fila-resumo, html[data-theme="dark"] .bk-explica { background: #131e2c; }
html[data-theme="dark"] .legend-table thead th { background: #1d2b3c; }
html[data-theme="dark"] .row-diff td, html[data-theme="dark"] .row-diff th { background: #3a2f14 !important; }
html[data-theme="dark"] .compare tr.row-total td, html[data-theme="dark"] .compare tr.row-total th { background: #25344a !important; color: var(--text); border-top-color: #3b4f6b; }
html[data-theme="dark"] .compare .total-formula { color: var(--muted); }
html[data-theme="dark"] .compare .dif-vermelha { color: #ff8a83 !important; }
html[data-theme="dark"] .compare .dif-verde { color: #5fd4a2 !important; }
html[data-theme="dark"] .grade-rolagem tbody tr:nth-child(even), html[data-theme="dark"] table.grade tbody tr:nth-child(even) { background: #1a2636; }
html[data-theme="dark"] table.grade tbody tr.grade-atual { background: #1f3a5a; }
html[data-theme="dark"] table.tabela thead th, html[data-theme="dark"] table.tbl thead th, html[data-theme="dark"] table.conec-tabela thead th,
html[data-theme="dark"] table.bloq-tabela thead th, html[data-theme="dark"] table.mr-tabela thead th, html[data-theme="dark"] table.fila-tabela thead th,
html[data-theme="dark"] table.grade thead th, html[data-theme="dark"] .rec-tabela table thead th, html[data-theme="dark"] table.grade th,
html[data-theme="dark"] .grid-nf thead th, html[data-theme="dark"] .fila-tabela thead th {
  background: #223247; color: #d9e4f2; box-shadow: inset -1px 0 0 #3a4e68, inset 0 -1px 0 #3a4e68;
}
html[data-theme="dark"] .tbl td { border-bottom-color: #26364a; }
html[data-theme="dark"] .tbl-senior td { background: #131e2c; }
html[data-theme="dark"] .grid-nf td.destaque { background: #3b1b1b; }
html[data-theme="dark"] .consulta-caixa { background: #1a2838; border-color: #34475f; }
html[data-theme="dark"] .panel.bloco-assumido { background: #131e2c; border-color: #26364a; }
html[data-theme="dark"] .dic-barra, html[data-theme="dark"] .rec-barra { background: #25364b; }
html[data-theme="dark"] .dic-obs.salvo { box-shadow: 0 0 0 2px #14392b; }
html[data-theme="dark"] #rec canvas { background: #131e2c; }
html[data-theme="dark"] .grupo-lista a, html[data-theme="dark"] .atend-resumo button, html[data-theme="dark"] .sup-tabs button { background: var(--surface-2); color: var(--muted); }
html[data-theme="dark"] .grupo-lista a.on, html[data-theme="dark"] .atend-resumo button.on, html[data-theme="dark"] .sup-tabs button.on { background: #1b3552; color: var(--navy); }
html[data-theme="dark"] .nov-dialog, html[data-theme="dark"] .ws-janela { background: var(--surface); color: var(--text); }

/* ---- Monitor de agendamentos / fila de arquivos ---- */
html[data-theme="dark"] .mr-cartao, html[data-theme="dark"] .ws-janela-quadro { background: var(--surface); }
html[data-theme="dark"] .mr-linha-erro, html[data-theme="dark"] .mr-linha-alerta, html[data-theme="dark"] .fila-linha-erro, html[data-theme="dark"] .fila-linha-parcial { background: #2c1a1c; }
html[data-theme="dark"] .mr-linha-sistema, html[data-theme="dark"] .fila-linha-importando { background: #1a2636; }
html[data-theme="dark"] .mr-sinal-vermelho, html[data-theme="dark"] .mr-b-ruim, html[data-theme="dark"] .fila-b-erro { background: #4a2020; color: #ff9d97; }
html[data-theme="dark"] .mr-sinal-amarelo, html[data-theme="dark"] .fila-b-andamento { background: #3d3115; color: #f0c264; }
html[data-theme="dark"] .mr-txt-aviso, html[data-theme="dark"] .mr-aviso-texto { color: #f0c264; }
html[data-theme="dark"] .fila-b-espera { background: #25364b; color: #c6d2e1; }
html[data-theme="dark"] .fila-b-ok { background: #14392b; color: #6fdcae; }
html[data-theme="dark"] .fila-b-desc { background: #2a3340; color: #9aaabd; }
html[data-theme="dark"] .g-grade { stroke: #2d3d52; }
html[data-theme="dark"] .g-texto { fill: #9aaabd; }
html[data-theme="dark"] .dv { --dv-ink: #e4eaf2; --dv-ink-2: #b6c3d4; --dv-muted: #8a9bb0; --dv-grid: #2d3d52; --dv-axis: #44566e; --dv-surface: #172230; }

/* ---- suporte (painel, chat, atendimento) ---- */
html[data-theme="dark"] .sup-help, html[data-theme="dark"] .atend-desliza .colapsada { background: #15283d; }
html[data-theme="dark"] .atend-desliza .colapsada:hover { background: #1c3550; }
html[data-theme="dark"] .sup-item, html[data-theme="dark"] .sup-origem, html[data-theme="dark"] .sup-msg.outra, html[data-theme="dark"] .sup-foot,
html[data-theme="dark"] .atend-aux .chip-aux { background: var(--surface); }
html[data-theme="dark"] .sup-item:hover { background: var(--realce); }
html[data-theme="dark"] .sup-item.ativo { background: #1b3552; border-color: var(--blue); }
html[data-theme="dark"] .sup-msgs { background: #121c2a; }
html[data-theme="dark"] .sup-msg.minha { background: #1f3b5c; }
html[data-theme="dark"] .atend-cab, html[data-theme="dark"] .sup-chat-head { background: #131e2c; }
html[data-theme="dark"] .sup-star { color: #44566e; }
html[data-theme="dark"] .sup-star.on { color: #e0a526; }

/* ---- barra lateral: já é escura; só reforça o campo de busca e o trilho ---- */
html[data-theme="dark"] { --sb-bg: #070f1a; --sb-bg-2: #0f2036; --sb-painel-bg: #0b1828; }
html[data-theme="dark"] .trilha { background: var(--surface); }
html[data-theme="dark"] .trilha [aria-current] { color: var(--text); }

/* ---- imagens e anexos mantêm a cor original ---- */
html[data-theme="dark"] .sup-img, html[data-theme="dark"] .sup-thumb { filter: none; }

/* ---- controle de aparência (atalho no topo e opções da tela principal) ---- */
.tema-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; border-radius: 8px; width: 38px; height: 34px; font-size: 16px; cursor: pointer; margin: 0 2px; }
.tema-btn:hover { background: rgba(255,255,255,.22); }
.tema-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.tema-seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 8px 16px; cursor: pointer; border-right: 1px solid var(--border); }
.tema-seg button:last-child { border-right: 0; }
.tema-seg button:hover { background: var(--bg); }
.tema-seg button.on { background: var(--blue); color: #fff; font-weight: 600; }
.tema-linha { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; margin: 0 0 18px; font-size: 13px; color: var(--muted); }
html[data-theme="dark"] .atend-barra-titulo { background: #12304f; }

/* ---- cores escritas direto nas telas (style="...") e blocos <style> dos templates ---- */
html[data-theme="dark"] [style*="#fbe3e3"], html[data-theme="dark"] [style*="#fde8e6"] { background: #4a2020 !important; color: #ff9d97 !important; }
html[data-theme="dark"] [style*="#a12a2a"], html[data-theme="dark"] [style*="#b42318"] { color: #ff9d97 !important; }
html[data-theme="dark"] [style*="#fff6f6"] { background: #2c1a1c !important; }
html[data-theme="dark"] [style*="#1a7f37"] { color: #6fdcae !important; }
html[data-theme="dark"] .senha-requisitos { background: #131e2c; border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .senha-requisitos li.ok, html[data-theme="dark"] .senha-requisitos li.ok::before { color: #6fdcae; }
html[data-theme="dark"] .senha-requisitos li::before, html[data-theme="dark"] .senha-requisitos .nota { color: var(--muted); }
html[data-theme="dark"] .proc-overlay { background: rgba(0, 0, 0, .65); }
html[data-theme="dark"] .popup-consulta { background: var(--surface); color: var(--text); }
html[data-theme="dark"] .link-titulo { color: #7fb4f5; }
html[data-theme="dark"] .trilha a, html[data-theme="dark"] .card-go, html[data-theme="dark"] .sup-file, html[data-theme="dark"] .header-secao-titulo { color: #7fb4f5; }
html[data-theme="dark"] .alerta-btn .tri { stroke: rgba(255,255,255,.7); }
html[data-theme="dark"] hr { border-color: var(--border); }
html[data-theme="dark"] ::-webkit-scrollbar { width: 12px; height: 12px; }
html[data-theme="dark"] ::-webkit-scrollbar-track { background: #121c2a; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #35475f; border-radius: 6px; border: 2px solid #121c2a; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #4a6080; }

/* ---- barras de cabeçalho das seções: cinza neutro (o azul fica só para ações, como botões e links) ---- */
html[data-theme="dark"] .atend-barra-titulo,
html[data-theme="dark"] .sup-head,
html[data-theme="dark"] .sup-toast,
html[data-theme="dark"] .sup-notif,
html[data-theme="dark"] .fila-topo,
html[data-theme="dark"] .compare thead th,
html[data-theme="dark"] .bk-num { background: #2e3743; color: #e4eaf2; }
html[data-theme="dark"] .compare thead th:first-child { background: transparent; }
html[data-theme="dark"] .compare thead th:nth-child(4) { background: #3a4553; }
html[data-theme="dark"] .sup-icon { background: rgba(255,255,255,.1); }
html[data-theme="dark"] table.tabela thead th, html[data-theme="dark"] table.tbl thead th, html[data-theme="dark"] table.conec-tabela thead th,
html[data-theme="dark"] table.bloq-tabela thead th, html[data-theme="dark"] table.mr-tabela thead th, html[data-theme="dark"] table.fila-tabela thead th,
html[data-theme="dark"] table.grade thead th, html[data-theme="dark"] .rec-tabela table thead th, html[data-theme="dark"] table.grade th,
html[data-theme="dark"] .grid-nf thead th, html[data-theme="dark"] .fila-tabela thead th, html[data-theme="dark"] .legend-table thead th, html[data-theme="dark"] .ws-janela-topo {
  background: #2a323d; color: #dbe3ee; box-shadow: inset -1px 0 0 #3d4756, inset 0 -1px 0 #3d4756;
}
html[data-theme="dark"] .ws-janela-topo { box-shadow: none; }
html[data-theme="dark"] .atend-secao { background: #131b26; }
