/* Poção Mágica · Painel — design-tokens.json v1.0.0 (2026-10-20)
   Regras: azul só marca/ação · magenta só IA · vermelho só desvio > 5% contra, ruptura e erro
   · sem gradiente, emoji ou borda-esquerda colorida · texto mínimo 12px · valores em reais em Plus Jakarta tabular. */
:root {
  /* brand */
  --primary: #2D4BE0; --primary-hover: #2238B8; --primary-soft: #E9EDFC;
  /* ai */
  --ai: #B0257E; --ai-soft: #FCE8F4;
  /* neutral */
  --ink: #0B1F38; --text-secondary: #4A5260; --text-meta: #63686F;
  --border-strong: #C9C2B6; --border: #DDD7CE; --canvas: #F4F1EC; --canvas-strong: #ECE8E1; --surface: #FFFFFF;
  --on-dark-muted: #AEB8C8; --on-dark-body: #D5DBE5;
  /* status */
  --above: #1E7A4F; --above-soft: #E3F2EA; --warning: #9A5600; --warning-soft: #FBEFD9; --below: #B42318; --below-soft: #FBE6E3;
  --preview: #5A3FA8; --preview-soft: #EEEAF8; --closed: #0B1F38; --closed-soft: #E6E9EF;
  --discussing: #0E6B70; --discussing-soft: #E0F1F1; --muted-soft: #EEECE8;
  /* tipografia, raio, sombra */
  --sans: 'Plus Jakarta Sans', system-ui, sans-serif; --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-pill: 999px;
  --shadow-float: 0 1px 2px rgba(11,31,56,.08), 0 4px 12px rgba(11,31,56,.06);
  --shadow-modal: 0 12px 40px rgba(11,31,56,.18);
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 400 14px/21px var(--sans);
  font-feature-settings: "tnum", "lnum"; -webkit-font-smoothing: antialiased; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 24px 48px; }
main.largo { max-width: 1440px; }
h1 { font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 20px; line-height: 26px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 12px; }
.cartao h2 { font-size: 16px; line-height: 22px; font-weight: 600; letter-spacing: 0; }
.sub { color: var(--text-secondary); margin: 0 0 24px; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 13px; line-height: 18px; font-weight: 500; }
code { background: var(--canvas-strong); padding: 1px 6px; border-radius: 4px; }
small { color: var(--text-meta); font-size: 12px; font-weight: 500; }

/* ---------- topbar (60px, tinta) ---------- */
.topo { display: flex; flex-wrap: wrap; align-items: stretch; justify-content: space-between; gap: 0 24px;
  min-height: 60px; padding: 0 24px; background: var(--ink); position: sticky; top: 0; z-index: 5; }
.marca { display: flex; align-items: center; font-weight: 800; font-size: 16px; letter-spacing: -0.01em; color: #fff; text-decoration: none; }
.marca span { color: var(--on-dark-muted); font-weight: 600; margin-left: 6px; }
.topo nav { display: flex; flex-wrap: wrap; align-items: stretch; }
.topo nav a { display: flex; align-items: center; padding: 0 14px; color: var(--on-dark-body); text-decoration: none;
  font-weight: 600; border-bottom: 2px solid transparent; min-height: 44px; }
.topo nav a:hover { color: #fff; background: #1C3352; }
.topo nav a.ativo { color: #fff; background: #1C3352; border-bottom-color: #5B74F0; }
.topo nav.util a { font-weight: 500; color: var(--on-dark-muted); }
nav.sub { display: flex; gap: 4px; padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
nav.sub a { padding: 6px 12px; border-radius: var(--r-sm); color: var(--text-secondary); text-decoration: none; font-weight: 600; white-space: nowrap; }
nav.sub a:hover { background: var(--canvas); color: var(--ink); }
nav.sub a.ativo { background: var(--primary-soft); color: var(--primary); }

/* ---------- cards e grade ---------- */
.cartao { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px 20px; margin-bottom: 16px; }
.cab { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.cartao .cab { align-items: center; margin-bottom: 12px; }
.cab h1, .cab h2 { margin-bottom: 0; }
.cab .sub { margin-bottom: 0; }
.grade { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.grade .cartao { margin: 0; }
.dica { color: var(--text-secondary); margin: 0 0 12px; }
.vazio { color: var(--text-meta); margin: 0; }

/* ---------- KPI (label caps · valor 32/800 · comparação) ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpis > div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 20px; }
.kpis span:first-child, .rotulo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-secondary); }
.kpis strong { display: block; margin-top: 8px; font-size: 32px; line-height: 36px; font-weight: 800; letter-spacing: -0.03em; }
.kpis em { display: block; margin-top: 8px; font-style: normal; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--text-meta); }
.kpis em a { color: var(--primary); }
.trilho { position: relative; height: 4px; margin-top: 12px; border-radius: 2px; background: var(--canvas-strong); }
.trilho i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; background: var(--ink); }
.trilho b { position: absolute; top: -3px; width: 2px; height: 10px; background: var(--text-meta); }

/* ---------- badges (pill, fundo soft + texto value) ---------- */
.tag { display: inline-block; font-style: normal; font-size: 12px; line-height: 16px; font-weight: 600; padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--canvas-strong); color: var(--text-secondary); white-space: nowrap; letter-spacing: 0; text-transform: none; }
.tag.ok, .tag.above { background: var(--above-soft); color: var(--above); }
.tag.alerta, .tag.warning, .tag.defasado { background: var(--warning-soft); color: var(--warning); }
.tag.below, .tag.erro { background: var(--below-soft); color: var(--below); }
.tag.previa { background: var(--preview-soft); color: var(--preview); }
.tag.fechado { background: var(--closed-soft); color: var(--closed); }

/* ---------- conteúdo de agente de IA (magenta é só IA) ---------- */
.agente { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); padding: 16px 20px; margin-bottom: 16px; }
.agente-origem { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.agente-origem::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ai); }
.agente-origem .nome { color: var(--ai); }
.agente-bloco { background: var(--ai-soft); border-radius: var(--r-sm); padding: 12px 14px; }
.agente-bloco pre { margin: 0; white-space: pre-wrap; font-family: var(--mono); font-size: 12px; line-height: 18px; color: var(--ink); }
.relatorio-agente { line-height: 21px; }
.relatorio-agente table { margin: 12px 0; }

/* ---------- botões e campos (36px; 44px em toque) ---------- */
button, .botao { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 16px;
  font: 600 14px/1 var(--sans); border-radius: var(--r-sm); cursor: pointer; text-decoration: none;
  background: var(--primary); color: #fff; border: 1px solid var(--primary); }
button:hover, .botao:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
button.sec, .botao.sec { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
button.sec:hover, .botao.sec:hover { background: var(--canvas); border-color: var(--ink); color: var(--ink); }
button.ter, .botao.ter { background: transparent; color: var(--primary); border-color: transparent; }
button.ter:hover, .botao.ter:hover { background: var(--primary-soft); color: var(--primary); }
button:disabled, button:disabled:hover { background: var(--canvas-strong); border-color: var(--canvas-strong); color: var(--text-meta); cursor: not-allowed; }
input, select { font: 400 14px/1 var(--sans); color: var(--ink); background: var(--surface); height: 36px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
input[type=file] { height: auto; padding: 6px 0; border: 0; max-width: 100%; }
label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
form { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
form.calibra { display: grid; grid-template-columns: 1fr; gap: 8px; }
form.calibra label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; color: var(--ink); }
form.calibra input { width: 96px; text-align: right; }
form.linha input { width: 180px; }
.filtros { align-items: flex-end; }
.filtros label { display: grid; gap: 4px; }
.filtros select { min-width: 220px; max-width: 100%; }
@media (pointer: coarse) { button, .botao, input, select { height: 44px; } }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--primary); font-weight: 600; margin-bottom: 8px; min-height: 24px; }
ul.arquivos { margin: 12px 0 0; padding-left: 18px; font-family: var(--mono); font-size: 13px; line-height: 20px; }

/* ---------- avisos ---------- */
.aviso { border-radius: var(--r-md); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.aviso pre { margin: 0; white-space: pre-wrap; font-family: var(--mono); font-size: 12px; line-height: 18px; }
.aviso.ok { border-color: var(--above); background: var(--above-soft); color: var(--ink); }
.aviso.erro { border-color: var(--below); background: var(--below-soft); color: var(--below); }

/* ---------- tabelas (cabeçalho label-caps em canvas-strong, números à direita) ---------- */
.rolagem { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--canvas-strong); color: var(--text-secondary); font-size: 12px; line-height: 16px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; text-align: left; padding: 10px 12px; white-space: nowrap; }
td { height: 44px; padding: 0 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover td { background: var(--canvas); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.atencao { color: var(--warning); font-weight: 600; }
td.ruim { color: var(--below); font-weight: 600; }
td.above { color: var(--above); }
td.warning { color: var(--warning); }
td.below { color: var(--below); font-weight: 600; }
.forte { font-weight: 700; }
table.quebra td { white-space: normal; vertical-align: top; padding-top: 12px; padding-bottom: 12px; height: auto; min-width: 90px; }
table.lado th { width: 160px; background: transparent; }
pre.resumo { background: var(--canvas); border-radius: var(--r-sm); padding: 14px; overflow-x: auto; font-family: var(--mono); font-size: 12px; margin: 0; }

/* DRE: densidade compacta (146 linhas), primeira coluna fixa, subtotal em canvas peso 700 */
table.dre td { height: 32px; padding: 0 10px; }
table.dre th { padding: 8px 10px; }
table.dre td:first-child, table.dre th:first-child { position: sticky; left: 0; z-index: 1; min-width: 260px; white-space: normal; }
table.dre td:first-child { background: var(--surface); }
table.dre th:first-child { background: var(--canvas-strong); }
table.dre th.grupo { text-align: center; background: var(--surface); color: var(--ink); border-bottom: 1px solid var(--border-strong); }
table.dre tr.t-soma td, table.dre tr.t-soma td:first-child { background: var(--canvas); font-weight: 700; }
table.dre tr.t-pct td { color: var(--text-secondary); }
table.dre tr.t-titulo td { font-weight: 700; }
table.dre tr.n1 td:first-child { padding-left: 24px; }
table.dre tr.n2 td:first-child { padding-left: 38px; }
table.dre tr.n3 td:first-child { padding-left: 52px; }
table.dre tbody tr:hover td, table.dre tbody tr:hover td:first-child { background: var(--canvas-strong); }

/* ---------- login ---------- */
.tela-login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 380px; display: grid; gap: 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 32px; }
.login h1 { margin: 0; }
.login h1 span { color: var(--text-meta); font-weight: 600; }
.login .sub { margin: 0; }
.login label { display: grid; gap: 6px; }
.login button { width: 100%; }

footer { text-align: center; color: var(--text-meta); font-size: 12px; line-height: 16px; font-weight: 500; padding: 0 24px 32px; }

/* ---------- gráficos: real em tinta, orçado como traço; linhas sólida × tracejada ---------- */
.grafico { position: relative; width: 100%; min-height: 220px; }
.grafico svg { display: block; width: 100%; height: auto; overflow: visible; }
.serie-1 { fill: var(--ink); }
.serie-2 { fill: var(--text-meta); }
.graf-traco { stroke: var(--text-meta); stroke-width: 2; stroke-linecap: round; }
.graf-traco-halo { stroke: var(--surface); stroke-width: 6; stroke-linecap: round; }
.graf-linha { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.linha-1 { stroke: var(--ink); }
.linha-2 { stroke: var(--text-meta); stroke-dasharray: 6 4; }
.graf-ponto { stroke: var(--surface); stroke-width: 2; }
.graf-grade { stroke: var(--border); stroke-width: 1; }
.graf-zero { stroke: var(--border-strong); stroke-width: 1; }
.graf-guia { stroke: var(--border-strong); stroke-width: 1; }
.graf-eixo { fill: var(--text-meta); font: 500 12px var(--sans); font-variant-numeric: tabular-nums; }
.graf-alvo { fill: transparent; outline: none; }
.graf-alvo:focus-visible { stroke: var(--primary); stroke-width: 2; }
.graf-legenda { display: flex; gap: 16px; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 8px; }
.graf-legenda > span { display: inline-flex; align-items: center; gap: 6px; }
.graf-chip { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.graf-chip.serie-1 { background: var(--ink); }
.graf-chip.traco { height: 2px; border-radius: 1px; background: var(--text-meta); }
.graf-chip.tracejado { height: 0; border-radius: 0; background: none; border-top: 2px dashed var(--text-meta); }
.graf-dica { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 12px; font-size: 12px; line-height: 18px; box-shadow: var(--shadow-float); white-space: nowrap; z-index: 3; }
.graf-dica-tit { color: var(--text-meta); font-weight: 500; margin-bottom: 2px; }
.graf-dica-lin { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.graf-dica-lin strong { font-weight: 700; color: var(--ink); }
.graf-dica-lin span:last-child { color: var(--text-secondary); }

@media (max-width: 640px) {
  main { padding: 16px 16px 40px; }
  .topo { padding: 0 16px; }
  nav.sub { padding: 8px 16px; }
  .rolagem { margin: 0 -20px; }
  .kpis strong { font-size: 28px; line-height: 32px; }
}

/* ---------- agrupamento da DRE (grandes linhas · subgrupos · tudo) ---------- */
.agrupar { display: inline-flex; gap: 4px; padding: 3px; background: var(--canvas); border: 1px solid var(--border); border-radius: var(--r-sm); }
.agrupar button { height: 30px; padding: 0 12px; font-size: 13px; color: var(--text-secondary); }
.agrupar button[aria-pressed="true"] { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.cartao .cab h2 .tag { vertical-align: middle; margin-left: 8px; }
button.seta { width: 24px; height: 24px; padding: 0; margin: 0 6px 0 -4px; vertical-align: middle; background: transparent; border: 0;
  color: var(--text-secondary); border-radius: 4px; }
button.seta::before { content: ""; display: inline-block; width: 7px; height: 7px; border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 0.15s ease; }
button.seta[aria-expanded="true"]::before { transform: rotate(45deg); margin-top: -4px; }
button.seta:hover { background: var(--canvas-strong); color: var(--ink); border: 0; }
@media (pointer: coarse) { button.seta { width: 36px; height: 36px; } .agrupar button { height: 40px; } }
@media (prefers-reduced-motion: reduce) { button.seta::before { transition: none; } }
.seta-vazia { display: inline-block; width: 26px; }
@media (pointer: coarse) { .seta-vazia { width: 38px; } }

/* nota de unidade e leitura (meta 12px, logo abaixo do título) */
.nota { margin: -6px 0 12px; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--text-meta); }
.cab + .nota { margin-top: -4px; }

/* cabeçalho em forma de conta: operador + sigla, descrição discreta embaixo */
thead.formula th { vertical-align: bottom; padding-top: 12px; padding-bottom: 10px; }
thead.formula .op { color: var(--text-meta); font-weight: 500; letter-spacing: 0; margin-right: 2px; }
.th-desc { display: block; margin-top: 2px; font-size: 12px; line-height: 16px; font-weight: 500; letter-spacing: 0;
  text-transform: none; color: var(--text-meta); white-space: normal; }
thead.formula th.n .th-desc { margin-left: auto; max-width: 120px; }
