:root {
  color-scheme: light;
  --page: #f3f3f1;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --borda: #e3e2dd;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7d7c76;
  --grid: #e6e5e0;
  --acento: #2a78d6;
  --acento-suave: rgba(42, 120, 214, .12);
  --bom: #1a7f4b;
  --ruim: #c8312f;
  --alerta: #a86b00;
  --sombra: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --anterior: #a9a8a1;
  --seq: #eef4fc,#b7d3f6,#6da7ec,#2a78d6,#104281;
}
:root[data-theme="dark"] {
  --alerta: #e0a43a;
  color-scheme: dark;
  --page: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --borda: #2c2c2a;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8d8c84;
  --grid: #2a2a28;
  --acento: #3987e5;
  --acento-suave: rgba(57, 135, 229, .16);
  --bom: #3fbf7f;
  --ruim: #f0706e;
  --sombra: 0 1px 2px rgba(0,0,0,.3);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --anterior: #5c5b56;
  --seq: #1f2733,#184f95,#2a78d6,#5598e7,#9ec5f4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.4 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- topo ---------- */
.topo {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--borda);
}
.marca { display: flex; align-items: center; gap: 12px; min-width: 0; max-width: 260px; flex: none; }
.marca > div:last-child { min-width: 0; }
.marca-nome { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marca-icone {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--acento); color: #fff;
}
.marca-nome { font-weight: 600; font-size: 15px; }
.marca-logo { width: 36px; height: 36px; flex: none; object-fit: contain; }
.marca-sub { color: var(--text-muted); font-size: 12px; }

.abas { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.aba {
  border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  padding: 8px 11px; border-radius: 8px;
  color: var(--text-secondary); font-weight: 500;
}
.aba:hover { background: var(--surface-2); color: var(--text-primary); }
.aba.ativa { background: var(--acento-suave); color: var(--acento); }

.acoes { display: flex; align-items: center; gap: 6px; }
.atualizado { color: var(--text-muted); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.icone-btn {
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--borda); background: var(--surface-1);
  color: var(--text-secondary); display: grid; place-items: center;
}
.icone-btn:hover { color: var(--text-primary); background: var(--surface-2); }
.icone-btn.girando svg { animation: gira .8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

/* ---------- filtros ---------- */
.filtros {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px 0;
  flex-wrap: wrap;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button, .seg button {
  border: 1px solid var(--borda); background: var(--surface-1);
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  color: var(--text-secondary); font-size: 13px;
}
.chips button:hover, .seg button:hover { color: var(--text-primary); }
.chips button.ativo, .seg button.ativo {
  background: var(--acento); border-color: var(--acento); color: #fff;
}
.campos { display: flex; gap: 12px; align-items: center; }
.campos label { color: var(--text-muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.campos input, .campos select {
  background: var(--surface-1); border: 1px solid var(--borda);
  border-radius: 8px; padding: 5px 8px; font-size: 13px;
}
.campos select { min-width: 160px; }

.erro {
  margin: 12px 24px 0; padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--ruim); color: var(--ruim); background: var(--surface-1);
}

/* ---------- conteúdo ---------- */
main { flex: 1; overflow: auto; padding: 14px 24px 24px; }
.painel { display: none; }
.painel.ativo { display: block; animation: entra .25s ease-out; }
@keyframes entra { from { opacity: 0; transform: translateY(4px); } }

.card {
  background: var(--surface-1);
  border: 1px solid var(--borda);
  border-radius: 14px;
  box-shadow: var(--sombra);
  padding: 16px 18px;
  min-width: 0;
  position: relative;
}
.card.carregando::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--acento-suave), transparent);
  background-size: 200% 100%;
  animation: brilho 1.1s linear infinite;
  pointer-events: none;
}
@keyframes brilho { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.card-topo { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-sub { margin: 2px 0 0; color: var(--text-muted); font-size: 12px; }

.kpis { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.kpi { display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.kpi-rotulo { color: var(--text-secondary); font-size: 13px; }
.kpi-valor { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi.destaque .kpi-valor { font-size: 30px; }
.kpi-delta {
  font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; align-items: center;
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-delta > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.kpi-extra { color: var(--text-muted); font-weight: 400; }
.kpi-delta .sobe, .kpi-delta .desce { font-weight: 600; display: inline-flex; align-items: center; gap: 2px; }
.kpi-delta .sobe { color: var(--bom); }
.kpi-delta .desce { color: var(--ruim); }
.kpi-spark { width: 100%; height: 34px; margin-top: 2px; }

.grade { display: grid; gap: 14px; margin-bottom: 14px; }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-1 { grid-template-columns: 1fr 1fr; }
.g-1 { grid-template-columns: 1fr; }

.grafico { width: 100%; height: 320px; }
.grafico.baixo { height: 260px; }
.grafico.alto { height: 380px; }

.seg { display: flex; gap: 4px; }

/* ---------- tabela ---------- */
.tabela { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tabela th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--text-muted);
  padding: 8px 10px; border-bottom: 1px solid var(--borda);
}
.tabela td { padding: 9px 10px; border-bottom: 1px solid var(--borda); }
.tabela tr:last-child td { border-bottom: 0; }
.tabela tbody tr:hover { background: var(--surface-2); }
.tabela .num { text-align: right; white-space: nowrap; }
.tabela .pos { color: var(--text-muted); width: 32px; }
.barra-col { width: 18%; }
.barra { height: 8px; border-radius: 4px; background: var(--acento); min-width: 2px; }

/* ---------- em breve ---------- */
.em-breve { max-width: 560px; margin: 60px auto; text-align: center; padding: 36px; }
.em-breve p { color: var(--text-secondary); }
.tag {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--acento-suave); color: var(--acento); font-size: 12px; font-weight: 600;
}

/* ---------- kpis com N colunas ---------- */
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.kpis-4 { grid-template-columns: repeat(4, 1fr); }
.kpis-5 { grid-template-columns: repeat(5, 1fr); }
.kpis .kpi-delta .sobe, .kpis .kpi-delta .desce { flex: none; }
.kpi-sub { white-space: normal; flex-wrap: wrap; row-gap: 0; }
.kpi-sub > span:last-child { overflow: visible; }
.kpi-rotulo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- caixas ---------- */
.secao-titulo { margin: 4px 2px 10px; }
.secao-titulo h2 { margin: 0; font-size: 15px; font-weight: 600; }
.caixas-grade {
  display: grid; gap: 14px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.caixa-card { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; }
.caixa-nome { color: var(--text-secondary); font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.caixa-saldo { font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.caixa-saldo.neg { color: var(--ruim); }
.caixa-mov { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.caixa-mov b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.pt { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.pt.e { background: var(--s1); }
.pt.s { background: var(--s2); }

/* ---------- selos / tabelas compactas ---------- */
.selo {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  white-space: nowrap; border: 1px solid currentColor; align-self: flex-start;
}
.selo.ruim { color: var(--ruim); }
.selo.alerta { color: var(--alerta); }
.selo.neutro { color: var(--text-muted); }
.tabela.compacta td { padding: 7px 8px; font-size: 13px; }
.tabela.compacta th { padding: 6px 8px; }
.tabela .trunc { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabela .nowrap { white-space: nowrap; }
.tabela .mudo, .mudo { color: var(--text-muted); font-size: 11px; }
.txt-saida { color: var(--text-secondary); }
.tabela-rolagem { max-height: 330px; overflow-y: auto; overflow-x: hidden; }
#tUltimos { table-layout: fixed; }
#tUltimos th:nth-child(1) { width: 88px; }
#tUltimos th:nth-child(2) { width: 22%; }
#tUltimos th:nth-child(3) { width: 22%; }
#tUltimos th:nth-child(5) { width: 108px; }
#tUltimos td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rodape-nota { color: var(--text-muted); font-size: 12px; margin: 4px 2px 0; }

/* ---------- vendedores / projeção / DRE ---------- */
.kpi-valor { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra-linha { display: flex; align-items: center; gap: 8px; }
.barra-linha .barra { flex: none; max-width: 70%; }
.selo.bom { color: var(--bom); }
.selo.info { color: var(--s1); }
.selo.proj { color: var(--s2); }
.sobe { color: var(--bom); font-weight: 600; }
.desce { color: var(--ruim); font-weight: 600; }
.barra-opcoes {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 16px; margin-bottom: 14px;
}
.barra-opcoes label { color: var(--text-muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.barra-opcoes select {
  background: var(--surface-1); border: 1px solid var(--borda); border-radius: 8px; padding: 4px 8px; font-size: 13px;
}
.chk { color: var(--text-secondary); font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.chk input { accent-color: var(--acento); }
.opcoes-nota { margin-left: auto; }
.lista-ind { list-style: none; margin: 0; padding: 0; }
.lista-ind li {
  display: flex; flex-direction: column; gap: 1px; padding: 8px 0;
  border-bottom: 1px solid var(--borda); font-size: 13px;
}
.lista-ind li:last-child { border-bottom: 0; }
.lista-ind span { color: var(--text-muted); font-size: 12px; }
.lista-ind b { font-weight: 600; font-variant-numeric: tabular-nums; }
.aviso {
  margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; font-size: 13px;
  border: 1px solid var(--alerta); color: var(--text-secondary); background: var(--surface-1);
}
.aviso b { color: var(--alerta); }
.aviso p { margin: 0 0 6px; }
.btn-acao {
  border: 0; border-radius: 8px; padding: 7px 14px; margin: 2px 0 8px; cursor: pointer;
  background: var(--acento); color: #fff; font-weight: 600; font-size: 13px;
}
.btn-acao:disabled { opacity: .6; cursor: default; }
.aviso-tabela { margin-top: 6px; max-width: 760px; }
.aviso-tabela td, .aviso-tabela th { padding: 4px 8px; }
.coluna { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.dre-grade { align-items: start; }
.tabela.dre td { padding: 6px 8px; font-size: 13px; }
.tabela.dre .num { white-space: nowrap; }
.dre-T td { font-weight: 650; border-top: 1px solid var(--borda); background: var(--surface-2); }
.dre-R td { font-weight: 700; font-size: 14px; background: var(--acento-suave); color: var(--text-primary); }
.dre-G td:first-child { padding-left: 22px; color: var(--text-secondary); }
.dre-C td { font-size: 12px; color: var(--text-muted); }
.dre-C td:first-child { padding-left: 40px; }
.dre-I td { font-size: 12px; font-style: italic; color: var(--text-muted); }

@media (max-width: 1250px) {
  .kpis-4, .kpis-5 { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .g-2-1, .g-1-1 { grid-template-columns: 1fr; }
}

/* ---------- celular / tablet estreito ---------- */
@media (max-width: 760px) {
  /* a página inteira rola: cabeçalho e filtros não ficam presos ocupando a tela */
  body { overflow: auto; height: auto; min-height: 100%; }
  main { overflow: visible; flex: none; }
  .topo { flex-wrap: wrap; gap: 10px 8px; padding: 10px 16px; }
  .marca { flex: 1; max-width: none; }
  .marca-logo { width: 30px; height: 30px; }
  .marca-nome { font-size: 14px; }
  .acoes { gap: 4px; }
  .atualizado { display: none; }
  .icone-btn { width: 32px; height: 32px; }
  .abas { order: 3; flex-basis: 100%; padding-bottom: 2px; }
  .aba { padding: 7px 10px; font-size: 13px; }

  .filtros { padding: 10px 16px 0; gap: 10px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%; padding-bottom: 2px; }
  .chips button { flex: none; }
  .campos { flex-wrap: wrap; width: 100%; gap: 8px; }
  .campos label { flex: 1 1 140px; }
  .campos input, .campos select { width: 100%; min-width: 0; }

  main { padding: 12px 16px 20px; }
  .erro { margin: 10px 16px 0; }

  .kpis, .kpis-3, .kpis-4, .kpis-5 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi.destaque { grid-column: span 2; }
  .card { padding: 14px; border-radius: 12px; }
  .kpi-valor, .kpi.destaque .kpi-valor { font-size: 19px; }
  .kpi-delta { white-space: normal; flex-wrap: wrap; row-gap: 0; }
  .kpi-delta > span:last-child { overflow: visible; }

  .grade { gap: 10px; margin-bottom: 10px; }
  .grafico { height: 280px; }
  .grafico.baixo { height: 240px; }
  .grafico.alto { height: 340px; }
  .card-topo { flex-wrap: wrap; }

  /* tabelas rolam na horizontal dentro do cartão */
  .tabela { display: block; overflow-x: auto; white-space: nowrap; }
  .tabela .trunc { max-width: 180px; }
  .tabela-rolagem { overflow-x: auto; }
  #tUltimos { display: table; table-layout: auto; }

  .barra-opcoes { gap: 10px 14px; }
  .opcoes-nota { margin-left: 0; flex-basis: 100%; }
  .caixas-grade { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .caixa-saldo { font-size: 18px; }
  .em-breve { margin: 20px auto; padding: 24px; }
}
@media (max-width: 380px) {
  .kpis, .kpis-3, .kpis-4, .kpis-5 { grid-template-columns: 1fr; }
  .kpi.destaque { grid-column: auto; }
}
