/*
 * Chart component
 *
 * Inline SVG charts carried in article markdown as raw HTML (the same
 * passthrough as asides and marginalia). Each chart is a
 * <figure class="chart"> holding a figcaption (title line plus a one-line
 * caption), an optional legend, the SVG, and a <details> table of the
 * figures for readers who want the numbers. The SVG scales to the reading
 * column via its viewBox; text inside it is sized in viewBox pixels.
 *
 * First used by the KiwiSaver election article, where the SVG is generated
 * by the kiwisuper project's draft builder and baked into the article
 * (status.md, "KiwiSaver article: charts baked in as SVG"). Series colours
 * are tokens in variables.css so the charts follow the theme.
 */

.article-body .chart {
    margin: var(--space-md) 0 var(--space-lg);
    font-family: var(--font-sans);
}

.article-body .chart figcaption {
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--color-ink);
}

.article-body .chart figcaption strong {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--color-primary-dark);
}

.article-body .chart svg {
    width: 100%;
    height: auto;
    display: block;
    font-family: var(--font-sans);
}

.article-body .chart figcaption + svg,
.article-body .chart svg + figcaption {
    margin-top: var(--space-sm);
}

/* Marks inside the SVG */
.article-body .chart .grid {
    stroke: var(--color-border);
    stroke-width: 1;
}

.article-body .chart .axis {
    fill: var(--color-ink-muted);
    font-size: 15px;
}

.article-body .chart .val {
    fill: var(--color-ink);
    font-size: 16px;
    font-weight: 600;
}

.article-body .chart .inside {
    fill: var(--chart-label-on-bar);
    font-size: 15px;
    font-weight: 600;
}

.article-body .chart .equal {
    stroke: var(--color-ink-muted);
    stroke-width: 2;
    stroke-dasharray: 6 4;
}

.article-body .chart rect:hover {
    opacity: 0.85;
}

/* Series: the class names are shared by the SVG marks and the legend
   swatches, so one rule colours both. */
.article-body .chart .s-rest { fill: var(--chart-series-1); background: var(--chart-series-1); }
.article-body .chart .s-health { fill: var(--chart-series-2); background: var(--chart-series-2); }
.article-body .chart .s-super { fill: var(--chart-series-3); background: var(--chart-series-3); }
.article-body .chart .s-nz { fill: var(--chart-nz); stroke: var(--chart-nz-stroke); stroke-width: 1; background: var(--chart-nz); }
.article-body .chart .s-aus,
.article-body .chart .s-aus-h,
.article-body .chart .s-aus-pen { fill: var(--chart-aus-green); background: var(--chart-aus-green); }
.article-body .chart .s-aus-tax { fill: var(--chart-aus-gold); background: var(--chart-aus-gold); }

/* Legend and the caption's small print */
.article-body .chart .small {
    font-size: 0.8rem;
    color: var(--color-ink-muted);
}

.article-body .chart .legend {
    display: flex;
    gap: var(--space-sm);
    margin: var(--space-xs) 0;
    font-size: 0.8rem;
}

.article-body .chart .key {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.article-body .chart .sw {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* "Show as table" */
.article-body .chart details {
    margin-top: var(--space-xs);
}

.article-body .chart summary {
    cursor: pointer;
}

.article-body .chart table {
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-top: var(--space-xs);
}

.article-body .chart th,
.article-body .chart td {
    border-bottom: 1px solid var(--color-border);
    padding: 0.2rem 0.6rem;
    text-align: right;
}

.article-body .chart th:first-child,
.article-body .chart td:first-child {
    text-align: left;
}
