/* Gráficos (public/js/graficos.js). As duas cores das séries passaram na checagem
   de daltonismo (protan, deutan, tritan) e de contraste, no fundo claro e no escuro. */

:root {
  --serie-1: #1d4ed8;
  --serie-2: #ea580c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --serie-1: #3b82f6;
    --serie-2: #ea580c;
  }
}

.grafico { position: relative; margin: 0; min-width: 0; }
.grafico figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .15rem .6rem;
  margin-bottom: .75rem;
}
.graf-titulo { font-weight: 650; font-size: 1rem; color: var(--texto); }
.graf-subtitulo { font-size: .8rem; color: var(--texto-fraco); }
.graf-legenda {
  list-style: none;
  margin: -.25rem 0 .5rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1rem;
  font-size: .8rem;
  color: var(--texto-fraco);
}
.graf-legenda li { display: inline-flex; align-items: center; gap: .4rem; }
.graf-chave { width: 10px; height: 10px; border-radius: 3px; background: var(--serie-1); }
.graf-chave.s2 { background: var(--serie-2); }
.graf-vazio {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--texto-fraco);
  font-size: .9rem;
  border: 1px dashed var(--borda-forte);
  border-radius: 10px;
}

/* ------------------------------------------------- colunas (por período) */

.graf-area {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  gap: .5rem;
  height: 190px;
  padding-top: 1.1rem; /* espaço para o valor escrito no pico */
}
.graf-eixo { position: relative; font-size: .72rem; color: var(--texto-fraco); font-variant-numeric: tabular-nums; }
.graf-eixo span { position: absolute; right: 0; transform: translateY(50%); line-height: 1; white-space: nowrap; }
.graf-plot {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-bottom: 1px solid var(--borda-forte);
}
.graf-grade span { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--borda); }
.graf-slot {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 2px;
  border-radius: 4px 4px 0 0;
  outline-offset: 2px;
}
.graf-slot:hover, .graf-slot:focus-visible { background: color-mix(in srgb, var(--serie-1) 9%, transparent); }
.graf-coluna {
  position: relative;
  flex: 0 1 24px; /* no máximo 24 px: o resto da faixa fica de ar */
  min-width: 2px;
  background: var(--serie-1);
  border-radius: 4px 4px 0 0;
}
.graf-coluna.s2 { background: var(--serie-2); }
.graf-coluna .graf-valor {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 3px;
  font-size: .72rem;
  font-weight: 650;
  color: var(--texto);
  white-space: nowrap;
}
.graf-x {
  display: flex;
  gap: 2px;
  margin: .35rem 0 0 2.75rem; /* largura do eixo + o espaço entre eles */
  font-size: .72rem;
  color: var(--texto-fraco);
}
.graf-x span { flex: 1 1 0; min-width: 0; display: flex; justify-content: center; white-space: nowrap; }

/* -------------------------------------------- barras (por categoria) */

.graf-linhas { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.graf-linha {
  display: grid;
  grid-template-columns: minmax(5.5rem, 34%) minmax(0, 1fr);
  align-items: center;
  gap: .75rem;
  border-radius: 6px;
  outline-offset: 2px;
}
.graf-rotulo { font-size: .85rem; color: var(--texto); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graf-linha.outros .graf-rotulo { color: var(--texto-fraco); }
.graf-trilho { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.graf-barra {
  flex: none;
  height: 14px;
  width: calc(var(--p) * (100% - 4rem)); /* sobra lugar para o valor na ponta */
  min-width: 2px;
  background: var(--serie-1);
  border-radius: 0 4px 4px 0; /* reta na base, arredondada na ponta */
}
.graf-linha.outros .graf-barra { background: color-mix(in srgb, var(--serie-1) 45%, var(--cartao)); }
.graf-trilho .graf-valor { font-size: .8rem; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--texto); white-space: nowrap; }
.graf-linha:hover .graf-rotulo, .graf-linha:focus-visible .graf-rotulo { color: var(--serie-1); }

/* ----------------------------------------------------- dica e tabela */

.graf-dica {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  max-width: 16rem;
  padding: .4rem .6rem;
  font-size: .78rem;
  line-height: 1.35;
  color: #fff;
  background: #0f172a;
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, .25);
}
.graf-dica[hidden] { display: none; }
@media (prefers-color-scheme: dark) {
  .graf-dica { color: #0f172a; background: #e5e7eb; }
}
.graf-tabela { margin-top: .6rem; font-size: .85rem; }
.graf-tabela summary { cursor: pointer; color: var(--destaque); font-size: .8rem; width: max-content; }
.graf-tabela table { margin-top: .5rem; }

@media print {
  .graf-dica, .graf-tabela { display: none !important; }
  .grafico { break-inside: avoid; }
  .graf-coluna, .graf-barra, .graf-chave { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
