/* Financeiro Brilhante — estilos. Mobile-first, claro/escuro automático. */
:root {
  --bg: #f4f6f1; --superficie: #ffffff; --superficie-2: #eef2e9; --borda: #d9e0d0; --texto: #1d2a1b; --texto-2: #566451;
  --primaria: #2f6b3a; --primaria-hover: #255530; --primaria-texto: #ffffff; --acento: #c9962b;
  --ok: #1f7a3d; --ok-bg: #dff3e4; --aviso: #8a5a00; --aviso-bg: #fdf0cf; --ruim: #a3261c; --ruim-bg: #fbe0dd; --neutro: #45524a; --neutro-bg: #e6eae2;
  --serie-1: #2f6b3a; --serie-2: #c9962b; --serie-3: #3a6ea5;
  --sombra: 0 1px 2px rgb(0 0 0 / 8%), 0 4px 14px rgb(0 0 0 / 6%); --raio: 10px; --menu-w: 260px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12170f; --superficie: #1a2117; --superficie-2: #222b1e; --borda: #313c2d; --texto: #e7eee3; --texto-2: #a5b39f;
    --primaria: #5bb06c; --primaria-hover: #70c481; --primaria-texto: #0d1a0f; --acento: #e0b04a;
    --ok: #7bd493; --ok-bg: #1b3a24; --aviso: #f0c35c; --aviso-bg: #3c3010; --ruim: #ff9b92; --ruim-bg: #4a1c18; --neutro: #b9c6b3; --neutro-bg: #2a3326;
    --serie-1: #5bb06c; --serie-2: #e0b04a; --serie-3: #6fa8dc;
    --sombra: 0 1px 2px rgb(0 0 0 / 40%);
  }
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--texto); }
body { min-height: 100vh; }
h1 { font-size: 1.45rem; margin: 0; } h2 { font-size: 1.2rem; margin: 0; } h3 { font-size: 1.05rem; margin: 1.1rem 0 .5rem; }
a { color: var(--primaria); }
small { color: var(--texto-2); }
pre { background: var(--superficie-2); padding: .75rem; border-radius: 8px; overflow: auto; font-size: .82rem; max-height: 40vh; }
:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }

/* ---------- Controles ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--superficie); border: 1px solid var(--borda); border-radius: 8px; padding: .5rem .85rem; cursor: pointer; min-height: 40px; }
button:hover:not(:disabled) { background: var(--superficie-2); }
button:disabled { opacity: .55; cursor: wait; }
button.primario { background: var(--primaria); border-color: var(--primaria); color: var(--primaria-texto); font-weight: 600; }
button.primario:hover:not(:disabled) { background: var(--primaria-hover); }
button.perigo { color: var(--ruim); border-color: var(--ruim); background: transparent; }
button.secundario { background: transparent; }
button.icone { min-width: 40px; padding: .35rem; font-size: 1.25rem; line-height: 1; }
button.cheio { width: 100%; }
input, select, textarea { width: 100%; background: var(--superficie); border: 1px solid var(--borda); border-radius: 8px; padding: .5rem .65rem; min-height: 40px; }
input[type="checkbox"] { width: 1.15rem; height: 1.15rem; min-height: 0; accent-color: var(--primaria); }
textarea { resize: vertical; }
label { display: grid; gap: .25rem; font-size: .92rem; }
label > span { font-weight: 600; }
label.check { display: flex; align-items: center; gap: .55rem; }
label.check > span { font-weight: 400; }
label.mini { font-size: .8rem; color: var(--texto-2); }
label.mini > input, label.mini > select { min-height: 36px; padding: .3rem .5rem; }
.erro-campo { color: var(--ruim); margin: .4rem 0; min-height: 0; }
.ok-campo { color: var(--ok); margin: .4rem 0; }
.centro { text-align: center; }

/* ---------- Layout autenticado ---------- */
#layout { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
#lateral { position: fixed; inset: 0 auto 0 0; width: min(var(--menu-w), 85vw); background: var(--superficie); border-right: 1px solid var(--borda);
  transform: translateX(-100%); transition: transform .2s; z-index: 30; overflow-y: auto; padding-bottom: 2rem; }
.menu-aberto #lateral { transform: none; box-shadow: var(--sombra); }
#fundo-menu { display: none; position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 20; }
.menu-aberto #fundo-menu { display: block; }
.marca { display: flex; align-items: center; gap: .55rem; padding: 1rem; font-weight: 700; font-size: 1.05rem; color: var(--primaria); }
.marca-icone { font-size: 1.5rem; }
#menu details { border-top: 1px solid var(--borda); }
#menu summary { cursor: pointer; padding: .7rem 1rem; font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-2); list-style-position: inside; }
#menu ul { list-style: none; margin: 0; padding: 0 0 .4rem; }
#menu a { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem 1rem .5rem 1.6rem; color: var(--texto); text-decoration: none; min-height: 40px; }
#menu a:hover { background: var(--superficie-2); }
#menu a.ativo { background: var(--superficie-2); color: var(--primaria); font-weight: 700; box-shadow: inset 3px 0 0 var(--primaria); }
.contador { background: var(--aviso-bg); color: var(--aviso); border-radius: 999px; padding: 0 .5rem; font-size: .75rem; font-weight: 700; }
.contador:empty { display: none; }
.contador.critico { background: var(--ruim-bg); color: var(--ruim); }
#coluna { min-width: 0; display: flex; flex-direction: column; }
#topo { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .75rem; padding: .5rem 1rem; background: var(--superficie); border-bottom: 1px solid var(--borda); }
#topo .espaco { flex: 1; }
#topo .usuario { display: grid; text-align: right; line-height: 1.15; font-size: .9rem; }
#conteudo { padding: 1rem; max-width: 1280px; width: 100%; margin: 0 auto; outline: none; }
@media (min-width: 960px) {
  #layout { grid-template-columns: var(--menu-w) 1fr; }
  #lateral { position: sticky; top: 0; height: 100vh; transform: none; grid-column: 1; }
  #coluna { grid-column: 2; }
  #btn-menu { display: none; }
  #conteudo { padding: 1.5rem 2rem; }
}

/* ---------- Conteúdo ---------- */
.cabecalho { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .5rem; }
.descricao { color: var(--texto-2); margin: .25rem 0 1rem; max-width: 70ch; }
.filtros { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin: .75rem 0 1rem; }
.filtros > input, .filtros > select { width: auto; flex: 1 1 11rem; max-width: 22rem; }
.filtros > label.mini { flex: 0 1 9rem; }
.bloco { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem; margin: 1rem 0; box-shadow: var(--sombra); }
.bloco > h2:first-child, .bloco > h3:first-child { margin-top: 0; }
.vazio { color: var(--texto-2); padding: 1rem 0; }
.resumo { margin: .25rem 0 .75rem; }
.aviso-caixa { background: var(--aviso-bg); color: var(--aviso); border-radius: 8px; padding: .65rem .9rem; margin: .75rem 0; }
.aviso-caixa ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.acoes { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.botoes-linha { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.motivo { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dl.detalhes { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .6rem 1.2rem; margin: .5rem 0; }
dl.detalhes > * { margin: 0; } dl.detalhes dt { font-size: .78rem; color: var(--texto-2); text-transform: uppercase; letter-spacing: .03em; } dl.detalhes dd { font-weight: 600; }

/* Abas */
.abas { display: flex; gap: .25rem; border-bottom: 1px solid var(--borda); margin: .75rem 0 1rem; overflow-x: auto; }
.abas button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; white-space: nowrap; }
.abas button.ativa { border-bottom-color: var(--primaria); color: var(--primaria); font-weight: 700; }

/* ---------- Tabelas ---------- */
.tabela-rolagem { overflow-x: auto; border: 1px solid var(--borda); border-radius: var(--raio); background: var(--superficie); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: .55rem .75rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--borda); }
th { background: var(--superficie-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.clicavel { cursor: pointer; } tr.clicavel:hover td { background: var(--superficie-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { background: var(--superficie-2); font-weight: 600; }
.melhor { color: var(--ok); font-weight: 700; }
.col-acoes { white-space: nowrap; }
@media (max-width: 640px) {   /* tabelas viram cartões no celular */
  .tabela-rolagem { border: 0; background: transparent; overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { position: absolute; left: -9999px; }
  tr { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); margin-bottom: .75rem; padding: .35rem .25rem; box-shadow: var(--sombra); }
  td { border: 0; display: grid; grid-template-columns: 38% 1fr; gap: .5rem; padding: .3rem .6rem; text-align: left !important; white-space: normal !important; }
  td::before { content: attr(data-rotulo); font-size: .75rem; font-weight: 700; color: var(--texto-2); text-transform: uppercase; }
  td.col-acoes { grid-template-columns: 1fr; } td.col-acoes::before { display: none; }
  tfoot, tfoot tr, tfoot td { display: block; }
  tfoot td[colspan] { display: none; }
}

/* Selos */
.selo { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.selo.ok { background: var(--ok-bg); color: var(--ok); } .selo.aviso { background: var(--aviso-bg); color: var(--aviso); }
.selo.ruim { background: var(--ruim-bg); color: var(--ruim); } .selo.neutro { background: var(--neutro-bg); color: var(--neutro); }

/* KPIs e barras */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: .75rem; margin: .5rem 0 1rem; }
.kpi { background: var(--superficie); border: 1px solid var(--borda); border-left: 4px solid var(--primaria); border-radius: var(--raio); padding: .7rem .9rem; display: grid; gap: .15rem; box-shadow: var(--sombra); }
.kpi.neg { border-left-color: var(--ruim); } .kpi.aviso { border-left-color: var(--acento); }
.kpi-rotulo { font-size: .78rem; color: var(--texto-2); text-transform: uppercase; letter-spacing: .03em; }
.kpi-valor { font-size: 1.3rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi.neg .kpi-valor { color: var(--ruim); }
.barras { display: grid; gap: .35rem; margin: .5rem 0 1rem; }
.barra-linha { display: grid; grid-template-columns: minmax(5rem, 9rem) 1fr minmax(6rem, auto); gap: .6rem; align-items: center; font-size: .85rem; }
.barra-trilho { background: var(--superficie-2); border-radius: 999px; height: .75rem; overflow: hidden; display: block; }
.barra { display: block; height: 100%; background: var(--primaria); border-radius: 999px; } .barra.neg { background: var(--ruim); }
.barra-valor { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .barra-linha { grid-template-columns: 1fr auto; } .barra-trilho { grid-column: 1 / -1; order: 3; } }

/* ---------- Formulários ---------- */
.grade-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .8rem 1rem; }
.span2 { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--borda); border-radius: 8px; padding: .6rem .8rem; margin: 0; min-width: 0; }
legend { font-weight: 600; padding: 0 .35rem; }
.itens-linhas { display: grid; gap: .6rem; margin-bottom: .6rem; }
.item-linha { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)) auto; gap: .5rem; align-items: end; padding: .5rem; background: var(--superficie-2); border-radius: 8px; }
.item-linha .icone { align-self: end; }
small { display: block; }

/* Matriz de permissões */
.matriz details { border: 1px solid var(--borda); border-radius: 8px; margin: .4rem 0; background: var(--superficie); }
.matriz summary { padding: .6rem .8rem; cursor: pointer; font-weight: 700; }
.matriz table { font-size: .85rem; } .matriz th[scope="row"] { text-transform: none; font-size: .88rem; color: var(--texto); background: transparent; white-space: normal; }
@media (max-width: 640px) { .matriz table, .matriz tbody, .matriz tr, .matriz td, .matriz th { display: revert; } .matriz tr { border: 0; box-shadow: none; padding: 0; margin: 0; display: table-row; } .matriz table { display: table; } .matriz tbody { display: table-row-group; } .matriz td { display: table-cell; } .matriz td::before { content: none; } .matriz thead { position: static; } }

/* ---------- Modal e toasts ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgb(0 0 0 / 50%); display: flex; align-items: flex-start; justify-content: center; padding: 1rem; overflow-y: auto; z-index: 100; }
.modal { background: var(--superficie); border-radius: 12px; width: min(34rem, 100%); margin: auto; box-shadow: 0 10px 40px rgb(0 0 0 / 35%); }
.modal.larga { width: min(60rem, 100%); }
.modal > header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem 1rem; border-bottom: 1px solid var(--borda); }
.modal-corpo { padding: 1rem; max-height: calc(100vh - 7rem); overflow-y: auto; }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 200; max-width: min(24rem, calc(100vw - 2rem)); }
.toast { background: var(--primaria); color: var(--primaria-texto); padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--sombra); }
.toast.erro { background: var(--ruim); color: #fff; }

/* ---------- Telas públicas ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, var(--superficie-2), var(--bg)); }
.auth-caixa { width: min(26rem, 100%); background: var(--superficie); border: 1px solid var(--borda); border-radius: 14px; padding: 1.5rem; box-shadow: var(--sombra); }
.auth-caixa .marca { padding: 0 0 .75rem; justify-content: center; } .auth-caixa h1 { text-align: center; margin-bottom: 1rem; font-size: 1.25rem; }
.auth-caixa form { display: grid; gap: .9rem; } .auth-caixa .links { text-align: center; margin: 1rem 0 0; }
.captcha { min-height: 65px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { #lateral, #topo, .filtros, .acoes, button { display: none !important; } #layout { display: block; } }

/* Anexos */
.anexo-envio { align-items: center; }
.anexo-envio input[type="file"] { flex: 2 1 14rem; }
.removido { text-decoration: line-through; color: var(--texto-2); }

/* Gráfico de colunas */
.grafico-caixa { margin: .5rem 0 1rem; padding: .75rem; background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); }
.grafico { width: 100%; height: auto; max-height: 300px; display: block; }
.grafico .eixo { stroke: var(--borda); stroke-width: 1; }
.grafico .eixo-texto { fill: var(--texto-2); font-size: 11px; }
.legenda { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .82rem; color: var(--texto-2); margin-top: .35rem; }
.legenda i { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
