:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --borda: #e3e2de;
  --grid: #e9e8e4;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --series-1: #2a78d6;
  --series-1-fraco: #2a78d61f;
  --negativo: #e34948;
  --foco: #2a78d6;
  --sombra: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 8px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --borda: #2c2c2a;
    --grid: #2a2a28;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --series-1: #3987e5;
    --series-1-fraco: #3987e52a;
    --negativo: #e66767;
    --foco: #3987e5;
    --sombra: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface-1: #1a1a19;
  --borda: #2c2c2a;
  --grid: #2a2a28;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --series-1: #3987e5;
  --series-1-fraco: #3987e52a;
  --negativo: #e66767;
  --foco: #3987e5;
  --sombra: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

.topo { padding: 28px 0 8px; }
.topo h1 { margin: 0; font-size: clamp(22px, 3.2vw, 30px); letter-spacing: -.02em; font-weight: 700; text-wrap: balance; }
.sub { margin: 4px 0 0; color: var(--text-secondary); }

.filtros {
  display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end;
  margin: 20px 0 6px; padding: 14px; background: var(--surface-1);
  border: 1px solid var(--borda); border-radius: 12px; box-shadow: var(--sombra);
}
.filtros label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-secondary); flex: 1 1 130px; min-width: 0; }
.filtros label:first-child { flex-basis: 200px; }
select, button { font: inherit; color: var(--text-primary); }
select {
  appearance: none; width: 100%; padding: 8px 30px 8px 10px; border-radius: 8px;
  border: 1px solid var(--borda); background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237a7974' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
  font-size: 14px; font-weight: 500;
}
select:disabled { opacity: .5; }
select:focus-visible, button:focus-visible, .ranking li:focus-visible { outline: 2px solid var(--foco); outline-offset: 2px; }
.btn-sec { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--borda); background: transparent; cursor: pointer; font-size: 14px; font-weight: 500; }
.btn-sec:hover { background: var(--bg); }
.btn-link { border: 0; background: none; color: var(--text-secondary); cursor: pointer; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; padding: 4px; }

.resumo { margin: 6px 2px 14px; color: var(--text-muted); font-size: 13px; min-height: 20px; }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface-1); border: 1px solid var(--borda); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; box-shadow: var(--sombra); min-width: 0; }
.kpi-rot { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.kpi strong { font-size: clamp(24px, 3.4vw, 32px); font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-top: 4px; }
.kpi-det { font-size: 12px; color: var(--text-muted); }

.painel { background: var(--surface-1); border: 1px solid var(--borda); border-radius: 12px; padding: 16px; margin-top: 12px; box-shadow: var(--sombra); min-width: 0; }
.painel-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.painel h2 { margin: 0; font-size: 15px; font-weight: 600; }
.dica { font-size: 12px; color: var(--text-muted); }

.grafico { width: 100%; height: 260px; position: relative; }
.grafico svg { display: block; width: 100%; height: 100%; overflow: visible; }
.grafico .eixo { fill: var(--text-muted); font-size: 11px; }
.grafico .grade { stroke: var(--grid); stroke-width: 1; }
.grafico .barra { fill: var(--series-1); }
.grafico .alvo { fill: transparent; cursor: default; }
.grafico .alvo:hover + .barra, .grafico .barra.ativa { opacity: .8; }
.grafico .rotulo { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
.vazio { display: grid; place-items: center; height: 100%; color: var(--text-muted); font-size: 14px; }

.tabela { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabela th, .tabela td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; }
.tabela td:last-child, .tabela th:last-child { text-align: right; }
.tabela th { color: var(--text-secondary); font-weight: 600; font-size: 12px; }

.duas-colunas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ranking { list-style: none; margin: 0; padding: 0; max-height: 560px; overflow-y: auto; }
.ranking li {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; align-items: center; gap: 2px 8px;
  padding: 6px 6px; border-radius: 8px; cursor: pointer;
}
.ranking li:hover { background: var(--series-1-fraco); }
.ranking .pos { color: var(--text-muted); font-size: 12px; text-align: right; }
.ranking .nome { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .nome small { color: var(--text-muted); font-weight: 400; margin-left: 4px; }
.ranking .val { font-weight: 600; font-size: 14px; }
.ranking .val small { color: var(--text-muted); font-weight: 400; margin-left: 6px; font-size: 12px; }
.ranking .trilho { grid-column: 2 / 4; height: 6px; border-radius: 0 3px 3px 0; background: transparent; }
.ranking .trilho span { display: block; height: 100%; background: var(--series-1); border-radius: 0 3px 3px 0; min-width: 2px; }
.ranking .neg .trilho span { background: var(--negativo); }
.ranking .vazio-lista { cursor: default; color: var(--text-muted); display: block; padding: 20px 6px; }

.nota { margin: 24px 0 40px; color: var(--text-secondary); font-size: 14px; }
.nota h2 { font-size: 15px; color: var(--text-primary); margin: 0 0 6px; }
.nota ul { padding-left: 20px; margin: 6px 0; }
.nota a { color: var(--series-1); }
.fonte { font-size: 13px; color: var(--text-muted); }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--text-primary); color: var(--surface-1);
  padding: 6px 10px; border-radius: 8px; font-size: 13px; line-height: 1.35; box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  white-space: nowrap;
}
.tooltip b { font-weight: 700; }

.carregando { opacity: .55; transition: opacity .15s; }

@media (max-width: 760px) {
  .kpis { grid-template-columns: 1fr; }
  .duas-colunas { grid-template-columns: 1fr; }
  .filtros label { flex: 1 1 calc(50% - 12px); }
  .grafico { height: 220px; }
}
