/* D2Graf: motor de gráficos da casa. Cores só por tokens --d2-* (os --d2-graf-* vêm de d2.css,
   com valores próprios em cada tema). Texto sempre em token de texto, nunca na cor da série.
   Contraste no claro: os tons 3, 4 e 5 ficam abaixo de 3:1 contra a superfície; o motor compensa
   com rótulo direto obrigatório nessas séries (ou o valor na legenda) e com a vista em tabela. */

.d2graf { margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; position: relative; }
.d2graf-cab { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.d2graf-titulo { flex: 1 1 auto; min-width: 0; font-size: var(--d2-fs-sm); font-weight: 600; color: var(--d2-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d2graf-ferramentas { margin-left: auto; display: inline-flex; gap: 2px; opacity: .72; transition: opacity var(--d2-mov-rapido); }
.d2graf:hover .d2graf-ferramentas, .d2graf:focus-within .d2graf-ferramentas { opacity: 1; }
.d2graf-ferramenta[aria-pressed="true"] { background: var(--d2-bg-ativo); color: var(--d2-text); }
.d2graf-corpo { position: relative; min-width: 0; }
.d2graf-plot { position: relative; min-width: 0; border-radius: var(--d2-radius-sm); }
.d2graf-plot:focus { outline: none; }
.d2graf-plot:focus-visible { outline: 2px solid var(--d2-foco); outline-offset: 4px; }
.d2graf-svg { display: block; overflow: visible; max-width: 100%; touch-action: pan-y; }
.d2graf.is-atualizando .d2graf-plot { opacity: .55; transition: opacity var(--d2-mov-normal); }
.d2graf-esqueleto { min-height: 160px; }
.d2graf.is-vazio .d2graf-plot { min-height: 140px; display: flex; align-items: center; justify-content: center; }

/* Fios: grade e eixo recessivos, 1 px */
.d2graf-grade { stroke: var(--d2-graf-grade); stroke-width: 1; shape-rendering: crispEdges; }
.d2graf-base { stroke: var(--d2-graf-eixo); stroke-width: 1; shape-rendering: crispEdges; }
.d2graf-marco { stroke: var(--d2-graf-eixo); stroke-width: 1; stroke-dasharray: 3 3; }
.d2graf-ponte { stroke: var(--d2-graf-eixo); stroke-width: 1; stroke-dasharray: 2 2; shape-rendering: crispEdges; }
.d2graf-cruz { stroke: var(--d2-text-faint); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }

/* Textos (sempre tokens de texto) */
.d2graf-rotulo { fill: var(--d2-text-muted); font-size: var(--d2-fs-xs); }
.d2graf-rotulo-item { fill: var(--d2-text); font-size: var(--d2-fs-sm); }
.d2graf-rotulo-direto { fill: var(--d2-text); font-size: var(--d2-fs-xs); font-weight: 600; pointer-events: none; }
.d2graf-rotulo-fraco { fill: var(--d2-text-muted); font-weight: 500; }
.d2graf-svg .d2graf-num, .d2graf-num { font-family: inherit; font-variant-numeric: tabular-nums; }
.d2graf-centro-valor { fill: var(--d2-text); font-size: var(--d2-fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.d2graf-centro-rotulo { fill: var(--d2-text-muted); font-size: var(--d2-fs-xs); }

/* Marcas: linha de 2 px com pontas redondas, marcador de 8 px com anel da superfície */
.d2graf-serie { transition: opacity var(--d2-mov-rapido); }
.d2graf-linha { fill: none; stroke: var(--cor); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.d2graf-linha.is-fraca { stroke-dasharray: 4 4; }
.d2graf-area { fill: var(--cor); fill-opacity: calc(var(--d2-graf-area-opacidade, .3) * .6); stroke: none; }
.d2graf-ponto { fill: var(--cor); stroke: var(--d2-bg-elevated); stroke-width: 2; }
.d2graf-ponto.is-ativo { pointer-events: none; }
.d2graf-barra { fill: var(--cor); }
.d2graf-fatia .d2graf-barra { stroke: var(--d2-bg-elevated); stroke-width: 2; stroke-linejoin: round; }
.d2graf-fatia { transition: opacity var(--d2-mov-rapido), transform var(--d2-mov-rapido) var(--d2-curva-entrada); transform-box: view-box; }
.d2graf-fatia.is-ativa .d2graf-barra { stroke-width: 0; }
.d2graf-fatia.is-clicavel, .d2graf-alvo.is-clicavel, .d2graf-semaforo-item.is-clicavel { cursor: pointer; }
.d2graf-alvo { fill: transparent; }
.d2graf-realce { fill: var(--d2-bg-hover); pointer-events: none; }
.d2graf-serie.is-apagada, .d2graf-fatia.is-apagada, .d2graf-rotulo-direto.is-apagada { opacity: .18; }

/* Mapa de calor: escala sequencial de um tom em cinco faixas; célula sem medida neutra */
.d2graf-celula { stroke: none; transition: opacity var(--d2-mov-rapido); }
.d2graf-celula.is-f0 { fill: var(--d2-bg-subtle); stroke: var(--d2-border); stroke-width: 1; stroke-dasharray: 2 2; }
.d2graf-celula.is-f1, .d2graf-faixa-passo.is-f1 { fill: var(--d2-graf-seq-1); background: var(--d2-graf-seq-1); }
.d2graf-celula.is-f2, .d2graf-faixa-passo.is-f2 { fill: var(--d2-graf-seq-2); background: var(--d2-graf-seq-2); }
.d2graf-celula.is-f3, .d2graf-faixa-passo.is-f3 { fill: var(--d2-graf-seq-3); background: var(--d2-graf-seq-3); }
.d2graf-celula.is-f4, .d2graf-faixa-passo.is-f4 { fill: var(--d2-graf-seq-4); background: var(--d2-graf-seq-4); }
.d2graf-celula.is-f5, .d2graf-faixa-passo.is-f5 { fill: var(--d2-graf-seq-5); background: var(--d2-graf-seq-5); }
.d2graf-celula.is-ativa { stroke: var(--d2-text); stroke-width: 2; stroke-dasharray: none; }
.d2graf-celula-texto { font-size: 10.5px; font-weight: 600; pointer-events: none; fill: var(--d2-text); }
.d2graf-celula-texto.is-f4, .d2graf-celula-texto.is-f5 { fill: var(--d2-bg-elevated); }
html[data-theme="escuro"] .d2graf-celula-texto.is-f3, html[data-theme="escuro"] .d2graf-celula-texto.is-f4, html[data-theme="escuro"] .d2graf-celula-texto.is-f5,
.d2-noite .d2graf-celula-texto.is-f3, .d2-noite .d2graf-celula-texto.is-f4, .d2-noite .d2graf-celula-texto.is-f5 { fill: var(--d2-bg); }
@media (prefers-color-scheme: dark) {
    html:not([data-theme]) .d2graf-celula-texto.is-f3, html:not([data-theme]) .d2graf-celula-texto.is-f4, html:not([data-theme]) .d2graf-celula-texto.is-f5 { fill: var(--d2-bg); }
}
.d2graf-escala { display: flex; align-items: center; gap: 2px; justify-content: flex-end; font-size: var(--d2-fs-xs); color: var(--d2-text-muted); }
.d2graf-escala-rotulo { padding: 0 6px; }
.d2graf-faixa-passo { width: 22px; height: 10px; border-radius: 2px; }

/* Textura de 45° e 135° (daltonismo e impressão): traço da superfície sobre a cor da série */
.d2graf-textura { display: none; pointer-events: none; }
.d2graf-textura-traco { stroke: var(--d2-bg-elevated); stroke-width: 1.6; stroke-opacity: .7; }
.d2graf.is-textura .d2graf-textura { display: inline; }
.d2graf.is-textura .d2graf-amostra:not(.is-linha) { background-image: repeating-linear-gradient(45deg, transparent 0 3px, var(--d2-bg-elevated) 3px 4.5px); }
@media print { .d2graf-textura { display: inline; } .d2graf-ferramentas { display: none; } }
@media (forced-colors: active) {
    .d2graf-textura { display: inline; }
    .d2graf-textura-traco { stroke: CanvasText; }
    .d2graf-linha, .d2graf-cruz { stroke: CanvasText; }
}

/* Legenda: amostra pequena + nome em token de texto; o item destaca a série */
.d2graf-legenda { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 6px; }
.d2graf-legenda-item {
    display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 2px 8px; border: 0; border-radius: var(--d2-radius-sm);
    background: transparent; color: var(--d2-text-muted); font: inherit; font-size: var(--d2-fs-xs); cursor: pointer;
    transition: background-color var(--d2-mov-rapido), color var(--d2-mov-rapido);
}
.d2graf-legenda-item:hover { background: var(--d2-bg-hover); color: var(--d2-text); }
.d2graf-legenda-item[aria-pressed="true"] { background: var(--d2-bg-ativo); color: var(--d2-text); }
.d2graf-amostra { width: 10px; height: 10px; border-radius: 3px; background: var(--cor); flex: none; }
.d2graf-amostra.is-linha { width: 14px; height: 3px; border-radius: 2px; }
.d2graf-legenda-valor { color: var(--d2-text); font-weight: 600; }

/* Dica da casa com linhas: valor em destaque, nome da série em segundo plano */
.d2graf-dica { white-space: normal; min-width: 96px; }
.d2graf-dica-titulo { font-weight: 600; margin-bottom: 3px; opacity: .85; }
.d2graf-dica-linha { display: flex; align-items: center; gap: 6px; line-height: 1.5; }
.d2graf-dica-traco { width: 12px; height: 3px; border-radius: 2px; background: var(--cor); flex: none; }
.d2graf-dica-traco.is-bloco { width: 8px; height: 8px; border-radius: 2px; }
.d2graf-dica-valor { font-variant-numeric: tabular-nums; font-weight: 700; }
.d2graf-dica-rotulo { opacity: .78; }

/* Vista em tabela */
.d2graf-tabela-rolagem { overflow: auto; max-height: 360px; border: 1px solid var(--d2-border); border-radius: var(--d2-radius-md); }
.d2graf-tabela { width: 100%; border-collapse: collapse; font-size: var(--d2-fs-sm); color: var(--d2-text); }
.d2graf-tabela th, .d2graf-tabela td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--d2-border); white-space: nowrap; }
.d2graf-tabela thead th { position: sticky; top: 0; background: var(--d2-bg-subtle); color: var(--d2-text-muted); font-weight: 600; font-size: var(--d2-fs-xs); }
.d2graf-tabela tbody th { font-weight: 500; }
.d2graf-tabela .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.d2graf-tabela tbody tr:last-child > * { border-bottom: 0; }
.d2graf-tabela tbody tr:hover > * { background: var(--d2-bg-hover); }

/* Pequenos múltiplos */
.d2graf-multiplos { display: grid; grid-template-columns: repeat(var(--colunas, 2), minmax(0, 1fr)); gap: 12px; }
.d2graf-painel { min-width: 0; padding: 8px 0 0; border-top: 1px solid var(--d2-graf-grade); }
.d2graf-painel-cab { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.d2graf-painel-titulo { flex: 1; min-width: 0; font-size: var(--d2-fs-xs); color: var(--d2-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d2graf-painel-valor { font-size: var(--d2-fs-sm); font-weight: 700; color: var(--d2-text); }
.d2graf-multiplos-escala { margin-top: 6px; text-align: right; font-size: var(--d2-fs-xs); color: var(--d2-text-faint); }

/* Semáforo: estado escrito e ícone próprio (nunca só a cor) */
.d2graf-semaforo { display: grid; grid-template-columns: repeat(var(--colunas, 2), minmax(0, 1fr)); gap: 8px; }
.d2graf-semaforo-item {
    --tom: var(--d2-neutro-cor); --tom-fundo: var(--d2-neutro-fundo);
    display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 52px; padding: 8px 12px;
    border: 1px solid var(--d2-border); border-left: 3px solid var(--tom); border-radius: var(--d2-radius-md); background: var(--d2-bg-elevated);
    transition: background-color var(--d2-mov-rapido), border-color var(--d2-mov-rapido);
}
.d2graf-semaforo-item.is-ok { --tom: var(--d2-ok-cor); --tom-fundo: var(--d2-ok-fundo); }
.d2graf-semaforo-item.is-aviso { --tom: var(--d2-aviso-cor); --tom-fundo: var(--d2-aviso-fundo); }
.d2graf-semaforo-item.is-serio { --tom: color-mix(in oklab, var(--d2-aviso-cor) 45%, var(--d2-erro-cor)); --tom-fundo: color-mix(in oklab, var(--d2-aviso-fundo) 50%, var(--d2-erro-fundo)); }
.d2graf-semaforo-item.is-critico { --tom: var(--d2-erro-cor); --tom-fundo: var(--d2-erro-fundo); }
.d2graf-semaforo-item.is-ativo, .d2graf-semaforo-item:hover { background: var(--d2-bg-hover); }
.d2graf-semaforo-icone { display: inline-flex; padding: 6px; border-radius: var(--d2-radius-pill); background: var(--tom-fundo); color: var(--tom); flex: none; }
.d2graf-semaforo-icone .d2-icone { width: 16px; height: 16px; }
.d2graf-semaforo-texto { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.d2graf-semaforo-rotulo { font-size: var(--d2-fs-sm); color: var(--d2-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d2graf-semaforo-estado { font-size: var(--d2-fs-xs); color: var(--d2-text-muted); }
.d2graf-semaforo-valor { font-size: var(--d2-fs-md); color: var(--d2-text); }

/* Manchete: número grande, variação com cor semântica de texto e faísca */
.d2graf-manchete { display: flex; flex-direction: column; gap: 6px; }
.d2graf-manchete-numeros { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.d2graf-manchete-valor { font-size: var(--d2-fs-3xl); font-weight: 700; line-height: 1.1; color: var(--d2-text); letter-spacing: -.01em; }
.d2graf-manchete-variacao { display: inline-flex; align-items: center; gap: 6px; font-size: var(--d2-fs-xs); }
.d2graf-manchete-comparacao { color: var(--d2-text-muted); }
.d2graf-variacao { display: inline-flex; align-items: center; gap: 2px; padding: 1px 7px 1px 4px; border-radius: var(--d2-radius-pill); font-weight: 700; background: var(--d2-neutro-fundo); color: var(--d2-neutro-cor); }
.d2graf-variacao .d2-icone { width: 14px; height: 14px; }
.d2graf-variacao.is-boa { background: var(--d2-ok-fundo); color: var(--d2-ok-cor); }
.d2graf-variacao.is-ruim { background: var(--d2-erro-fundo); color: var(--d2-erro-cor); }
.d2graf-faisca { margin-top: 2px; }
.d2graf.is-compacto .d2graf-manchete-valor { font-size: var(--d2-fs-2xl); }

/* Movimento de entrada (só sem prefers-reduced-motion; o motor também não marca as classes) */
/* A linha surge por opacidade (movimento da casa só por transform e opacity, até 320 ms). */
.d2graf-desenhar { animation: d2graf-surgir var(--d2-mov-lento) var(--d2-curva-entrada) both; animation-delay: var(--atraso, 0ms); }
.d2graf-crescer { transform-box: fill-box; transform-origin: 50% 100%; animation: d2graf-crescer var(--d2-mov-lento) var(--d2-curva-entrada) both; animation-delay: var(--atraso, 0ms); }
.d2graf-crescer-direita { transform-box: fill-box; transform-origin: 0 50%; animation: d2graf-crescer-x var(--d2-mov-lento) var(--d2-curva-entrada) both; animation-delay: var(--atraso, 0ms); }
.d2graf-surgir { animation: d2graf-surgir var(--d2-mov-lento) var(--d2-curva-entrada) both; animation-delay: var(--atraso, 0ms); }
@keyframes d2graf-crescer { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes d2graf-crescer-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes d2graf-surgir { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    .d2graf-desenhar, .d2graf-crescer, .d2graf-crescer-direita, .d2graf-surgir { animation: none !important; }
    .d2graf-serie, .d2graf-fatia, .d2graf-celula, .d2graf-ferramentas, .d2graf-legenda-item, .d2graf-semaforo-item { transition: none; }
}

/* Celular: alvos de 44 px nas ferramentas e na legenda */
@media (max-width: 759.98px) {
    .d2graf-ferramentas { opacity: 1; }
    .d2graf-legenda-item { min-height: var(--d2-alvo-toque, 44px); }
    .d2graf-manchete-valor { font-size: var(--d2-fs-2xl); }
    .d2graf-tabela th, .d2graf-tabela td { padding: 8px 10px; }
}
