/* ══════════════════════════════════════════════════════════════════════════
   Charts.

   Every chart is inline SVG drawn by js/core/charts.js. Colours come from
   tokens, never from the drawing code, so a chart re-themes with the app
   without redrawing.
   ══════════════════════════════════════════════════════════════════════════ */

/* max-width, not width: a donut carries its own width/height attributes and
   would otherwise stretch to whatever column it lands in. Bar and line charts
   set an explicit pixel width inline and scroll inside .chart-scroll. */
.chart {
  max-width: 100%;
  display: block;
  overflow: visible;
}

.chart-wrap {
  position: relative;
  min-width: 0;
}

/* Charts that would squash below a usable width scroll instead. */
.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--s-2);
}

.chart text {
  font-family: var(--font);
  fill: var(--axis-text);
  font-size: 11px;
}

.chart .axis-line { stroke: var(--border); stroke-width: 1; }
.chart .grid-line { stroke: var(--grid-line); stroke-width: 1; }
.chart .grid-line.is-zero { stroke: var(--border-strong); }

.chart .bar {
  transition: opacity var(--t-fast) var(--ease);
  cursor: default;
}
.chart .bar:hover { opacity: 0.82; }

.chart .track { fill: var(--chart-track); }

.chart .slice {
  transition: transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
  transform-origin: center;
  cursor: default;
}
.chart .slice:hover { opacity: 0.85; }
.chart .slice.is-dim { opacity: 0.3; }

.chart .line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart .area { stroke: none; opacity: 0.14; }
.chart .point { stroke: var(--surface); stroke-width: 2; }

.chart .value-label {
  font-size: 10px;
  font-weight: 600;
  fill: var(--text-muted);
}

/* Centre text inside a donut. */
.chart .donut-total {
  font-size: 19px;
  font-weight: 600;
  fill: var(--text);
  letter-spacing: -0.02em;
}
.chart .donut-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  fill: var(--text-subtle);
}

/* ── legend ──────────────────────────────────────────────────────────────── */

.legend {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  min-width: 0;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast) var(--ease);
}
button.legend-item { cursor: pointer; }
button.legend-item:hover { background: var(--surface-hover); }

.legend-swatch {
  width: 10px;
  height: 10px;
  flex: none;
  background: var(--swatch, var(--text-subtle));
}

.legend-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.legend-value {
  font-variant-numeric: tabular-nums;
  font-weight: var(--fw-semi);
  color: var(--text);
  white-space: nowrap;
}

.legend-pct {
  font-variant-numeric: tabular-nums;
  color: var(--text-subtle);
  font-size: var(--fs-xs);
  min-width: 38px;
  text-align: right;
}

/* Chart beside its legend on a wide card, stacked on a narrow one.

   auto-fit rather than a media query on purpose: what matters is how wide the
   CARD is, not how wide the window is. A dashboard column can be 340px inside a
   1600px window, and a viewport media query would happily crush the legend to
   nothing there — which is exactly what it did. */
.chart-legend-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--s-5);
  align-items: center;
  justify-items: center;
}
.chart-legend-row > .legend { justify-self: stretch; width: 100%; }

/* ── tooltip ─────────────────────────────────────────────────────────────── */

.chart-tip {
  position: fixed;
  z-index: 150;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  padding: 6px var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease);
}
.chart-tip.is-visible { opacity: 1; }
.chart-tip b { font-variant-numeric: tabular-nums; }

/* ── ranked horizontal bars ──────────────────────────────────────────────── */

.rank-list { display: flex; flex-direction: column; gap: var(--s-3); }

.rank-row { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.rank-head {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  font-size: var(--fs-sm);
  min-width: 0;
}
.rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-variant-numeric: tabular-nums; font-weight: var(--fw-semi); white-space: nowrap; }
.rank-sub { color: var(--text-subtle); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }

.rank-track {
  height: 6px;
  border-radius: var(--r-sm);
  background: var(--chart-track);
  overflow: hidden;
}
.rank-fill {
  height: 100%;
  border-radius: var(--r-sm);
  background: var(--c-6);
  transition: width var(--t-slow) var(--ease);
}

/* ── sparkline ───────────────────────────────────────────────────────────── */

.spark { display: block; width: 100%; height: 34px; overflow: visible; }
.spark .line { fill: none; stroke: var(--c-6); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.spark .area { fill: var(--c-6); opacity: 0.12; stroke: none; }

/* ── heat strip (spend by weekday / by day) ──────────────────────────────── */

.heat {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.heat-cell {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  background: var(--chart-track);
  display: grid;
  place-items: center;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  color: var(--text-subtle);
  position: relative;
}
.heat-cell[data-level="0"] { background: var(--chart-track); }
.heat-cell[data-level="1"] { background: color-mix(in srgb, var(--c-6) 18%, var(--chart-track)); }
.heat-cell[data-level="2"] { background: color-mix(in srgb, var(--c-6) 38%, var(--chart-track)); }
.heat-cell[data-level="3"] { background: color-mix(in srgb, var(--c-6) 62%, var(--chart-track)); }
.heat-cell[data-level="4"] { background: var(--c-6); color: var(--on-accent); }

.heat-labels {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin-top: var(--s-2);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-align: center;
}

/* ── gauge (budget dial, tuner meter shares the tokens) ──────────────────── */

.gauge-wrap { display: flex; align-items: center; gap: var(--s-4); }
.gauge { flex: none; }
.gauge .track { stroke: var(--chart-track); fill: none; stroke-linecap: round; }
.gauge .fill  { fill: none; stroke-linecap: round; transition: stroke-dashoffset var(--t-slow) var(--ease); }
