/* Gráficos SVG: cores só por classe (cs-0 … cs-7); sem estilos em linha */
.cs-0 {
  --series: var(--chart-1);
}
.cs-1 {
  --series: var(--chart-2);
}
.cs-2 {
  --series: var(--chart-3);
}
.cs-3 {
  --series: var(--chart-4);
}
.cs-4 {
  --series: var(--chart-5);
}
.cs-5 {
  --series: var(--chart-6);
}
.cs-6 {
  --series: var(--chart-7);
}
.cs-7 {
  --series: var(--chart-8);
}
.sw {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--series, var(--chart-8));
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.chart-title {
  margin: 0;
  font-size: 1rem;
}
.chart-desc {
  margin: 2px 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.chart-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.chart-foot {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.chart-wrap {
  min-width: 0;
}
.chart {
  position: relative;
  width: 100%;
  border-radius: 8px;
}
.chart:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chart-svg {
  display: block;
  max-width: 100%;
  overflow: visible;
}
.grid-line {
  stroke: var(--chart-grid);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}
.grid-base {
  stroke: var(--border-strong);
  stroke-width: 1;
}
.axis-label {
  fill: var(--chart-axis);
  font-size: 11px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
.line {
  stroke: var(--series);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.area {
  stroke: none;
}
.grad-top {
  stop-color: var(--series);
  stop-opacity: 0.3;
}
.grad-bottom {
  stop-color: var(--series);
  stop-opacity: 0;
}
.bar {
  fill: var(--series);
}
.bar-hl {
  fill: var(--text);
  opacity: 0;
}
.bar-hl.on {
  opacity: 0.06;
}
.crosshair {
  stroke: var(--text-faint);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0;
}
.crosshair.on {
  opacity: 1;
}
.dot {
  fill: var(--bg);
  stroke: var(--series);
  stroke-width: 2.25;
  opacity: 0;
}
.dot.on {
  opacity: 1;
}
.spark {
  display: block;
  overflow: visible;
}
.spark .line {
  stroke-width: 1.75;
}
.spark .dot {
  fill: var(--series);
  stroke: var(--bg);
  stroke-width: 1.5;
}
.chart-overlay {
  fill: transparent;
  pointer-events: all;
  cursor: crosshair;
}

.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 140px;
  max-width: 260px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 0.8125rem;
  pointer-events: none;
}
.tip-title {
  font-weight: 600;
  margin-bottom: 4px;
}
.tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tip-row .tip-name {
  flex: 1;
  color: var(--text-muted);
}
.tip-row strong {
  font-variant-numeric: tabular-nums;
}
.tip-total {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 140px;
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}
.chart-empty-icon {
  font-size: 1.25rem;
  color: var(--text-faint);
}

/* Legenda */
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8125rem;
  color: var(--text);
}
button.legend-item {
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-weight: 500;
}
button.legend-item.secondary:hover {
  background: var(--surface-2);
}
button.legend-item.off {
  color: var(--text-faint);
  text-decoration: line-through;
}
button.legend-item.off .sw {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--series);
}

/* Rosca */
.donut {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px 28px;
}
.donut .chart-wrap {
  flex: none;
}
.donut-chart {
  width: auto;
}
.donut-track {
  stroke: var(--surface-2);
}
.slice {
  stroke: var(--series);
  transition: stroke-width 0.12s;
}
.slice.on {
  stroke-width: 29;
}
.center-value {
  fill: var(--text);
  font-size: 22px;
  font-weight: 650;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
.center-label {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
}
.donut-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 260px;
  display: grid;
  gap: 2px;
  min-width: 0;
}
.donut-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto 3.8em;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.875rem;
}
.donut-row.on {
  background: var(--surface-2);
}
.donut-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.donut-val,
.donut-share {
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.donut-share {
  color: var(--text-muted);
}

/* Barras horizontais e funil */
.hbar,
.funnel {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.hbar-row {
  display: grid;
  grid-template-columns: minmax(80px, 34%) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  border-radius: 8px;
}
.hbar-row:hover,
.funnel-step:hover {
  background: var(--surface);
}
.hbar-row:focus-visible,
.funnel-step:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.hbar-label {
  min-width: 0;
  display: grid;
  line-height: 1.25;
}
.hbar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
}
.hbar-sub {
  color: var(--text-muted);
  font-size: 0.75rem;
}
.hbar-track {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}
.hbar-track svg {
  display: block;
  width: 100%;
  height: 100%;
}
.hbar-fill {
  fill: var(--series);
}
.hbar-val {
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: right;
  min-width: 3.5em;
}
.funnel-step {
  padding: 8px 10px;
  border-radius: 8px;
  display: grid;
  gap: 6px;
}
.funnel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}
.funnel-val {
  font-variant-numeric: tabular-nums;
}
.funnel-track {
  height: 14px;
  border-radius: 6px;
}
.funnel-conv {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Medidor */
.gauge {
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 6px;
  max-width: 320px;
}
.gauge-svg {
  width: 100%;
  max-width: 300px;
  height: auto;
  overflow: visible;
}
.gauge-track {
  stroke: var(--surface-2);
}
.gauge-fill {
  stroke: var(--level-ok);
}
.gauge-fill.lv-atencao {
  stroke: var(--level-atencao);
}
.gauge-fill.lv-estourado {
  stroke: var(--level-estourado);
}
.gauge-fill.lv-sem_teto {
  stroke: var(--level-sem_teto);
}
.gauge-tick {
  stroke: var(--text-faint);
  stroke-width: 1.5;
}
.gauge-marker {
  stroke: var(--text);
  stroke-width: 2.5;
  stroke-linecap: round;
}
.gauge-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--level-ok);
}
.gauge-state.lv-atencao {
  color: var(--level-atencao);
}
.gauge-state.lv-estourado {
  color: var(--level-estourado);
}
.gauge-state.lv-sem_teto {
  color: var(--text-muted);
}
.gauge-state .lv-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.6875rem;
  color: var(--bg);
  background: var(--level-ok);
}
.gauge-state.lv-atencao .lv-icon {
  background: var(--level-atencao);
}
.gauge-state.lv-estourado .lv-icon {
  background: var(--level-estourado);
}
.gauge-state.lv-sem_teto .lv-icon {
  background: var(--level-sem_teto);
}

/* Tabela alternativa */
.chart-data {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.chart-data summary {
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--accent);
  padding: 2px 0;
}
.chart-data[open] summary {
  margin-bottom: 8px;
}
.chart-table table {
  font-size: 0.8125rem;
}
.chart-table th,
.chart-table td {
  padding: 6px 10px;
}
.chart-table {
  max-height: 280px;
  overflow: auto;
}
@media (max-width: 520px) {
  .hbar-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .hbar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .donut {
    justify-content: center;
  }
}
@media (prefers-reduced-motion: reduce) {
  .slice {
    transition: none;
  }
}

.hbar-row {
  grid-template-columns: minmax(110px, 38%) minmax(0, 1fr) auto;
}
.donut-name {
  white-space: normal;
  overflow-wrap: anywhere;
}
