/* =====================================================================
   Biblioteca visual, tokens e estilos base dos componentes
   Padrões recriados a partir da varredura do Tableau Public Viz of the Day.
   Código próprio. Paleta categórica e de estado validada (método dataviz,
   validador de daltonismo e contraste). Para trocar de marca, trocar só os
   tokens deste bloco e rodar o validador de novo.
   ===================================================================== */
:root {
  color-scheme: light;
  --plano: #f6f6f3;            /* fundo da página */
  --superficie: #fcfcfb;       /* fundo do cartão e do gráfico */
  --superficie-2: #f0efec;     /* faixa, cabeçalho de tabela */
  --tinta-1: #0b0b0b;          /* texto principal */
  --tinta-2: #52514e;          /* texto secundário */
  --tinta-3: #6f6d68;          /* eixos e rótulos discretos */
  --grade: #e1e0d9;            /* linhas de grade */
  --base: #c3c2b7;             /* linha de base e eixo */
  --borda: rgba(11, 11, 11, 0.10);
  --apagado: #d4d3cc;          /* marcas fora de destaque */

  --serie-1: #2a78d6; --serie-2: #eb6834; --serie-3: #1baf7a; --serie-4: #eda100;
  --serie-5: #e87ba4; --serie-6: #008300; --serie-7: #4a3aa7; --serie-8: #e34948;

  --seq-100: #cde2fb; --seq-200: #9ec5f4; --seq-300: #6da7ec; --seq-400: #3987e5;
  --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;
  --div-neg: #e34948; --div-meio: #f0efec; --div-pos: #2a78d6;

  --estado-bom: #0ca30c; --estado-atencao: #fab219; --estado-serio: #ec835a; --estado-critico: #d03b3b;
  --texto-alta: #006300; --texto-baixa: #b42323;

  --fonte: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --raio: 10px; --raio-marca: 4px;
  --sombra: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --dur: 600ms; --curva: cubic-bezier(.2,.7,.2,1);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plano: #0f0f0e; --superficie: #1a1a19; --superficie-2: #232321;
    --tinta-1: #ffffff; --tinta-2: #c3c2b7; --tinta-3: #9a988f;
    --grade: #2c2c2a; --base: #45453f; --borda: rgba(255,255,255,0.10); --apagado: #3a3a37;
    --serie-1: #3987e5; --serie-2: #d95926; --serie-3: #199e70; --serie-4: #c98500;
    --serie-5: #d55181; --serie-6: #008300; --serie-7: #9085e9; --serie-8: #e66767;
    --seq-100: #104281; --seq-200: #184f95; --seq-300: #1c5cab; --seq-400: #256abf;
    --seq-500: #3987e5; --seq-600: #6da7ec; --seq-700: #b7d3f6;
    --div-neg: #e66767; --div-meio: #383835; --div-pos: #3987e5;
    --texto-alta: #0ca30c; --texto-baixa: #e66767;
    --sombra: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plano: #0f0f0e; --superficie: #1a1a19; --superficie-2: #232321;
  --tinta-1: #ffffff; --tinta-2: #c3c2b7; --tinta-3: #9a988f;
  --grade: #2c2c2a; --base: #45453f; --borda: rgba(255,255,255,0.10); --apagado: #3a3a37;
  --serie-1: #3987e5; --serie-2: #d95926; --serie-3: #199e70; --serie-4: #c98500;
  --serie-5: #d55181; --serie-6: #008300; --serie-7: #9085e9; --serie-8: #e66767;
  --seq-100: #104281; --seq-200: #184f95; --seq-300: #1c5cab; --seq-400: #256abf;
  --seq-500: #3987e5; --seq-600: #6da7ec; --seq-700: #b7d3f6;
  --div-neg: #e66767; --div-meio: #383835; --div-pos: #3987e5;
  --texto-alta: #0ca30c; --texto-baixa: #e66767;
  --sombra: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
}

/* ---------- base ---------- */
.bv, .bv * { box-sizing: border-box; }
.bv { font-family: var(--fonte); color: var(--tinta-1); }
.bv svg { display: block; overflow: visible; max-width: 100%; }
.bv text { fill: var(--tinta-2); font-family: var(--fonte); font-size: 12px; }
.bv .eixo path, .bv .eixo line { stroke: var(--base); }
.bv .eixo text { fill: var(--tinta-3); font-variant-numeric: tabular-nums; }
.bv .grade line { stroke: var(--grade); stroke-width: 1; }
.bv .grade path { display: none; }
.bv .rotulo-valor { fill: var(--tinta-1); font-weight: 600; font-variant-numeric: tabular-nums; }
.bv .rotulo-forte { fill: var(--tinta-1); font-weight: 600; }
.bv .anotacao { fill: var(--tinta-2); font-size: 12px; }
.bv .rotulo-quadrante { font-weight: 600; paint-order: stroke; stroke: var(--superficie); stroke-width: 4px; pointer-events: none; }
.bv .linha-anotacao { stroke: var(--tinta-3); stroke-dasharray: 2 3; fill: none; }
.bv .marca { transition: opacity .25s, fill .25s, stroke .25s; }
.bv.tem-foco .marca:not(.foco) { opacity: .18; }

/* cartão de componente */
.bv-cartao { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio);
  box-shadow: var(--sombra); padding: 20px 22px; }
.bv-cartao h3 { margin: 0 0 4px; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.bv-cartao .sub { margin: 0 0 14px; font-size: 13px; color: var(--tinta-2); }
.bv-cartao .fonte { margin: 12px 0 0; font-size: 11.5px; color: var(--tinta-3); }

/* legenda */
.bv-legenda { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 10px; font-size: 12.5px; color: var(--tinta-2); }
.bv-legenda button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 2px 0; }
.bv-legenda button[aria-pressed="false"] { opacity: .4; }
.bv-legenda i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* dica ao passar o mouse */
.bv-dica { position: fixed; z-index: 9999; pointer-events: none; min-width: 140px; max-width: 280px;
  background: var(--superficie); color: var(--tinta-1); border: 1px solid var(--borda); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: 9px 11px; font: 12.5px/1.45 var(--fonte);
  opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; }
.bv-dica.on { opacity: 1; transform: none; }
.bv-dica b { font-weight: 650; }
.bv-dica .linha-dica { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.bv-dica .linha-dica span:first-child { color: var(--tinta-2); display: inline-flex; align-items: center; gap: 6px; }
.bv-dica i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* filtros em linha (botões segmentados) */
.bv-filtros { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.bv-filtros button { font: 500 12.5px var(--fonte); color: var(--tinta-2); background: var(--superficie-2);
  border: 1px solid var(--borda); border-radius: 999px; padding: 5px 12px; cursor: pointer; transition: all .2s; }
.bv-filtros button:hover { color: var(--tinta-1); }
.bv-filtros button[aria-pressed="true"] { background: var(--tinta-1); color: var(--superficie); border-color: transparent; }

/* indicadores (cartões de número) */
.bv-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.bv-kpi { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px 18px 12px; box-shadow: var(--sombra); }
.bv-kpi .rot { font-size: 12.5px; color: var(--tinta-2); margin: 0 0 6px; }
.bv-kpi .val { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.bv-kpi .var { font-size: 12.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.bv-kpi .var.alta { color: var(--texto-alta); } .bv-kpi .var.baixa { color: var(--texto-baixa); } .bv-kpi .var.neutra { color: var(--tinta-3); }
.bv-kpi svg { margin-top: 8px; }

/* tabela com barras embutidas */
.bv-tabela { width: 100%; border-collapse: collapse; font-size: 13px; }
.bv-tabela th { text-align: left; font-weight: 600; color: var(--tinta-2); font-size: 12px; padding: 8px 10px;
  border-bottom: 1px solid var(--base); cursor: pointer; user-select: none; white-space: nowrap; }
.bv-tabela th.num, .bv-tabela td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bv-tabela td { padding: 8px 10px; border-bottom: 1px solid var(--grade); vertical-align: middle; }
.bv-tabela tr:hover td { background: var(--superficie-2); }
.bv-tabela .barra-cel { position: relative; height: 10px; background: var(--superficie-2); border-radius: 3px; min-width: 80px; }
.bv-tabela .barra-cel span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--serie-1); border-radius: 3px; transition: width var(--dur) var(--curva); }

/* medidor por faixa (bala) */
.bv-bala-linha { display: grid; grid-template-columns: minmax(120px, 34%) 1fr 64px; gap: 12px; align-items: center; margin: 8px 0; font-size: 13px; }

/* entrada animada ao rolar */
.bv-revela { opacity: 0; transform: translateY(14px); transition: opacity .7s var(--curva), transform .7s var(--curva); }
.bv-revela.visivel { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .bv-revela { opacity: 1; transform: none; transition: none; }
  .bv *, .bv-dica { transition: none !important; animation: none !important; }
}

/* tabela alternativa acessível (visualização em tabela de cada gráfico) */
.bv-ver-tabela { font: 500 12px var(--fonte); color: var(--tinta-2); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; margin-top: 10px; }
.bv-tabela-alt { margin-top: 10px; max-height: 260px; overflow: auto; }
