/* #region zone:finance.style.charts — โดนัท เส้น แท่ง legend tooltip และตารางสำรองของกราฟ */
.cat-0 {
  fill: var(--cat-0);
  background: var(--cat-0);
}
.cat-1 {
  fill: var(--cat-1);
  background: var(--cat-1);
}
.cat-2 {
  fill: var(--cat-2);
  background: var(--cat-2);
}
.cat-3 {
  fill: var(--cat-3);
  background: var(--cat-3);
}
.cat-4 {
  fill: var(--cat-4);
  background: var(--cat-4);
}
.cat-5 {
  fill: var(--cat-5);
  background: var(--cat-5);
}
.cat-other {
  fill: var(--cat-other);
  background: var(--cat-other);
}

.donut {
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(0, 1fr);
  align-items: center;
  gap: var(--sp-6);
}
.donut-figure {
  position: relative;
  margin: 0;
  aspect-ratio: 1;
}
.donut-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
/* 2px surface gap between slices; the hovered/focused slice lifts, the rest recede. */
.slice {
  stroke: var(--panel);
  stroke-width: 2;
  stroke-linejoin: round;
  cursor: pointer;
  outline: none;
  transition: opacity var(--dur-fast, 120ms) ease;
}
.donut-svg:hover .slice:not(:hover),
.donut-svg:focus-within .slice:not(:focus) {
  opacity: 0.45;
}
.slice:focus-visible {
  stroke: var(--text);
}
.donut-center {
  position: absolute;
  /* Stay inside the ring hole (inner radius 62 of 100): text over a slice has no readable background. */
  inset: 22%;
  overflow-wrap: anywhere;
  /* A real surface under the text: axe reads the SVG slice colour as the background of anything drawn over
     the chart box, even where the hole is empty. The disc is smaller than the hole (56% of 62%). */
  background: var(--panel);
  border-radius: 50%;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
  gap: 2px;
}
.donut-center small {
  color: var(--muted);
  font-size: var(--t-caption);
}
.donut-center b {
  font-size: var(--t-section);
}
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--sp-1);
  min-width: 0;
}
.legend li {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto 48px;
  align-items: center;
  gap: var(--sp-2);
  min-height: 32px;
  border-bottom: 1px solid var(--line);
}
.legend li:last-child {
  border-bottom: 0;
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
}
.legend-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.legend b {
  font-weight: 600;
  text-align: right;
}
.legend small {
  color: var(--muted);
  text-align: right;
  font-size: var(--t-caption);
}
.chart-empty {
  color: var(--muted);
  padding: var(--sp-4) 0;
}

.chart-table-toggle summary {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 var(--sp-2);
  margin-left: -8px;
  color: var(--accent-text);
  font-weight: 600;
  font-size: var(--t-label);
  cursor: pointer;
  border-radius: var(--r-control);
}
.chart-table-toggle summary:hover {
  background: var(--hover);
}
.chart-table-toggle[open] summary {
  margin-bottom: var(--sp-2);
}

.line-chart,
.cash-flow-chart {
  position: relative;
  width: 100%;
  min-width: 0;
}
.line-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: hidden;
  margin-top: var(--sp-2);
}
.chart-grid line {
  stroke: var(--line);
  stroke-width: 1;
}
.chart-grid text,
.chart-month {
  fill: var(--muted);
  font-size: var(--u-text-xs);
}
.series-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.series-line.s-accent {
  stroke: var(--accent);
}
.series-line.s-base {
  stroke: var(--muted);
  stroke-dasharray: 6 5;
}
.series-line.s-pay {
  stroke: var(--series-pay);
}
.series-band {
  fill: var(--acc-soft);
  stroke: none;
}
.chart-point {
  outline: none;
  cursor: pointer;
}
.chart-point .hit {
  fill: transparent;
  stroke: none;
}
.chart-point .dot {
  fill: var(--panel);
  stroke-width: 2;
  opacity: 0;
  transition: opacity var(--dur-fast, 120ms) ease;
}
.chart-point .dot.s-accent {
  stroke: var(--accent);
}
.chart-point .dot.s-base {
  stroke: var(--muted);
}
.chart-point .dot.s-pay {
  stroke: var(--series-pay);
}
.chart-point .dot.is-end,
.chart-point:hover .dot,
.chart-point:focus .dot {
  opacity: 1;
}
.chart-point:focus-visible .hit {
  stroke: var(--accent);
  stroke-width: 1;
}
/* The halo keeps the label legible even if a future change lets it meet a gridline. */
.chart-last-value {
  fill: var(--text);
  font-size: 14px;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 4px;
  stroke-linejoin: round;
  font-variant-numeric: tabular-nums;
}
.legend-line {
  display: inline-block;
  width: 22px;
  height: 0;
  border-top: 2px solid var(--accent);
  flex: none;
}
.legend-line.s-base {
  border-top-style: dashed;
  border-top-color: var(--muted);
}
.legend-line.s-pay {
  border-top-color: var(--series-pay);
}
.legend-band {
  display: inline-block;
  width: 22px;
  height: 10px;
  border-radius: 3px;
  background: var(--acc-soft);
  border: 1px solid var(--acc-ring);
  flex: none;
}
.chart-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  margin: 0;
  padding: 0;
  font-size: var(--t-body);
  font-weight: 600;
}
.chart-legend li {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 32px;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex: none;
}
.legend-swatch.up {
  background: var(--up);
}
.legend-swatch.down {
  background: var(--money-neg);
}
.chart-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.chart-topline > b {
  font-size: var(--t-body);
  font-weight: 600;
}
.chart-topline .chart-legend {
  margin: 0;
}
.status-positive {
  color: var(--accent-text);
}
.status-negative {
  color: var(--down);
}
.cash-bar {
  outline: none;
  cursor: pointer;
}
.cash-bar rect {
  fill: var(--up);
}
.cash-bar.is-negative rect {
  fill: var(--money-neg);
}
.cash-bar.is-zero rect {
  fill: var(--muted);
}
.cash-flow-chart {
  overflow: hidden;
}
.cash-chart {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: var(--sp-2);
  margin-top: var(--sp-3);
}
.cash-chart.no-axis {
  grid-template-columns: minmax(0, 1fr);
}
.cash-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 220px;
  margin: var(--sp-4) 0;
  font-size: var(--t-caption);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cash-axis-label {
  font-size: var(--t-caption);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 0;
  white-space: nowrap;
}
.cash-plot {
  display: block;
  width: 100%;
  height: 220px;
  margin: var(--sp-4) 0;
  overflow: visible;
}
.cash-plot line {
  vector-effect: non-scaling-stroke;
}
.cash-cols {
  grid-column: 2;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--sp-2);
  text-align: center;
}
.cash-chart.no-axis .cash-cols {
  grid-column: 1;
}
.cash-cols li {
  display: grid;
  gap: var(--sp-1);
  justify-items: center;
  min-width: 0;
}
.cash-value {
  font-size: var(--t-body);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
/* Three signed six-digit amounts must fit a phone column: one step smaller on narrow screens. */
@media (max-width: 420px) {
  .cash-value {
    font-size: var(--t-label);
  }
}
.cash-status,
.cash-cols .chart-month {
  font-size: var(--t-caption);
  color: var(--muted);
}
.cash-bar:hover rect,
.cash-bar:focus rect {
  opacity: 0.82;
}
.zero-line {
  stroke: var(--text);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.chart-tip {
  position: fixed;
  z-index: var(--z-chart-tip);
  max-width: min(320px, calc(100vw - 16px));
  padding: var(--sp-2) var(--sp-3);
  border-radius: 10px;
  background: var(--tip-bg);
  color: var(--tip-fg);
  font-size: var(--t-label);
  line-height: 1.5;
  pointer-events: none;
  box-shadow: var(--pop-shadow);
}

/* Two dashboard cards share the desktop column here: the 16px legend needs its own row. */
@media (min-width: 901px) and (max-width: 1199px) {
  :root:not(.fin-v3) .donut {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
  }
  :root:not(.fin-v3) .donut-figure {
    width: 200px;
  }
  :root:not(.fin-v3) .legend {
    width: 100%;
  }
}
@media (max-width: 600px) {
  .donut {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .donut-figure {
    width: min(220px, 70vw);
  }
  .legend {
    width: 100%;
  }
  /* Net-worth SVG text is in viewBox units (720 wide): scale it up so it still renders ≥ 11px on a phone. */
  .line-chart .chart-grid text,
  .line-chart .chart-month {
    font-size: var(--u-text-xl);
  }
  .chart-last-value {
    font-size: 22px;
  }
}
/* #endregion */
