.chart-card {
    min-height: auto;
}

.chart-card__header {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.chart-card__header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    /* Let a wide header tool (e.g. the operator source switch) drop to
       its own line on a narrow screen instead of overflowing the card
       and dragging the whole page into a horizontal scroll. */
    flex-wrap: wrap;
    row-gap: var(--space-2);
}

.chart-card__header-extra {
    margin-left: auto;
    flex-shrink: 0;
}

.chart-card__title {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.chart-card__subtitle {
    font-size: 0.8125rem;
    letter-spacing: 0.01em;
}

.chart-card__plot {
    margin-top: var(--space-2);
}

/* Strip the inner card chrome so the plot is not double-bordered when
   mountResponsiveChart renders inside the wrapper card. */
.chart-card__plot .chart-card {
    border: 0;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

.chart-card__plot .card__label {
    display: none;
}

.chart-card__lede {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: var(--line-normal);
    text-align: justify;
    text-wrap: pretty;
}

.card__label + .chart-card__lede {
    margin-top: var(--space-1);
}

.chart-slot {
    position: relative;
    width: 100%;
    min-height: var(--chart-min-height);
}

.chart-shell {
    position: relative;
}

/* Keyboard scrub lands on the shell (role="application"). */
.chart-shell:focus-visible {
    outline: var(--focus-ring-width) solid var(--color-accent);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--radius-sm);
}

/* Visually hidden live region, kept in the a11y tree so updates speak. */
.chart-shell__live {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.chart-shell .chart {
    margin-top: 0;
}

.chart-tooltip {
    position: absolute;
    z-index: var(--z-tooltip);
    width: max-content;
    min-width: 200px;
    max-width: min(420px, 92vw);
    padding: var(--space-3);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    box-shadow: var(--shadow-tooltip);
    font-size: var(--font-size-control);
    line-height: var(--line-normal);
    pointer-events: none;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity var(--motion-fast) var(--motion-ease),
        visibility var(--motion-fast) var(--motion-ease);
}

.chart-tooltip.is-visible {
    opacity: 1;
    visibility: visible;
}

/* Docked readout for narrow touch screens, where a floating tooltip
   would cover the point it describes; JS toggles the shell class. */
.chart-readout {
    display: none;
}

.chart-shell--readout-docked .chart-readout {
    display: block;
    margin-bottom: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    font-size: var(--font-size-control);
    line-height: var(--line-normal);
    text-align: left;
}

.chart-tooltip__title {
    font-weight: var(--font-weight-medium);
    color: var(--color-text-strong);
}

.chart-tooltip__kv {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    margin-top: var(--space-2);
}

/* Never break a numeric value mid-value; the label column may wrap. */
.chart-tooltip__kv strong {
    white-space: nowrap;
}

.chart-tooltip__muted {
    margin-top: var(--space-2);
    font-size: var(--font-size-chart-axis);
    color: var(--color-text-muted);
    word-break: break-word;
}

.chart-tooltip__swatch {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: var(--space-2);
    border-radius: 2px;
    vertical-align: baseline;
}

.chart {
    width: 100%;
    height: auto;
    margin-top: var(--space-2);
    /* Vertical drag scrolls the page, horizontal drag scrubs the series
       (attachTouchInspect); without it the browser claims every gesture. */
    touch-action: pan-y;
}

.chart__grid,
.chart__zero {
    stroke: var(--color-divider);
    stroke-width: 1;
    fill: none;
}

.chart__zero {
    stroke: var(--color-border);
}

.chart__y-label,
.chart__x-label {
    font-family: var(--font-sans);
    font-size: var(--font-size-chart-axis);
    fill: var(--color-text-subtle);
}

.chart__y-title {
    font-family: var(--font-sans);
    font-size: var(--font-size-chart-axis);
    fill: var(--color-text-subtle);
    letter-spacing: var(--letter-uppercase);
    text-transform: uppercase;
}

.chart__line {
    fill: none;
    stroke: var(--color-accent);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart__area {
    fill: var(--color-accent);
    fill-opacity: 0.08;
    stroke: none;
}

.chart__dot {
    fill: var(--color-accent);
    stroke: var(--color-bg);
    stroke-width: 2;
}

.chart__cursor-line {
    stroke: var(--color-accent);
    stroke-opacity: 0.35;
    stroke-width: 1;
    pointer-events: none;
}

.chart__bar {
    fill: var(--color-accent);
    transition:
        fill var(--motion-fast) var(--motion-ease),
        opacity var(--motion-fast) var(--motion-ease);
}

.chart__bar--active {
    fill: var(--color-accent-soft);
}

.chart__bar--reassigned {
    fill: var(--color-accent);
}

.chart__bar--newly-mapped {
    fill: var(--color-success);
}

.chart__bar--unmapped {
    fill: var(--color-warning);
}

.chart__stack {
    transition: opacity var(--motion-fast) var(--motion-ease);
}

.chart-shell:has(.chart__stack--active) .chart__stack {
    opacity: 0.4;
}

.chart-shell:has(.chart__stack--active) .chart__stack--active {
    opacity: 1;
}

/* Invisible full-height hit target so a hover anywhere in a column
   surfaces its tooltip, not just inside the drawn segments. */
.chart__bar-capture {
    fill: transparent;
    pointer-events: all;
}

.chart__line--filled,
.chart__dot--filled {
    stroke: var(--color-accent);
    fill: var(--color-accent);
}

.chart__line--filled {
    fill: none;
}

.chart__line--unfilled,
.chart__dot--unfilled {
    stroke: var(--color-accent-soft);
    fill: var(--color-accent-soft);
}

.chart__line--unfilled {
    fill: none;
}

.chart__line--reassigned,
.chart__dot--reassigned {
    stroke: var(--color-accent);
    fill: var(--color-accent);
}

.chart__line--reassigned {
    fill: none;
}

.chart__line--newly-mapped,
.chart__dot--newly-mapped {
    stroke: var(--color-success);
    fill: var(--color-success);
}

.chart__line--newly-mapped {
    fill: none;
}

.chart__line--unmapped,
.chart__dot--unmapped {
    stroke: var(--color-warning);
    fill: var(--color-warning);
}

.chart__line--unmapped {
    fill: none;
}

.chart__line--total,
.chart__dot--total {
    stroke: var(--color-text-muted);
    fill: var(--color-text-muted);
}

.chart__line--total {
    fill: none;
    stroke-dasharray: 6 3;
}

/* Background ring on the active dot; placed after the colour modifiers
   so the ring stroke wins over the series stroke. */
.chart__marker {
    stroke: var(--color-bg);
    stroke-width: 2;
    pointer-events: none;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-2);
    font-size: var(--font-size-control);
    color: var(--color-text-strong);
}

.chart-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chart-legend__swatch {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-pill);
    flex-shrink: 0;
}

.chart-legend__swatch--filled {
    background: var(--color-accent);
}

.chart-legend__swatch--unfilled {
    background: var(--color-accent-soft);
}

.chart-legend__swatch--reassigned {
    background: var(--color-accent);
}

.chart-legend__swatch--newly-mapped {
    background: var(--color-success);
}

.chart-legend__swatch--unmapped {
    background: var(--color-warning);
}

.chart-legend__swatch--total {
    background: transparent;
    border: 1.5px dashed var(--color-text-muted);
}

button.chart-legend__item {
    border: 0;
    background: transparent;
    padding: 2px 4px;
    margin: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition:
        background var(--motion-fast) var(--motion-ease),
        opacity var(--motion-fast) var(--motion-ease);
}

button.chart-legend__item:hover {
    background: var(--color-divider);
}

button.chart-legend__item:focus-visible {
    background: var(--color-divider);
    outline: var(--focus-ring-width) solid var(--color-accent);
    outline-offset: var(--focus-ring-offset);
}

.chart-legend__item--off {
    opacity: 0.45;
}

.chart-legend__item--off .chart-legend__swatch {
    opacity: 0.55;
}

.chart-legend__item--off > span:last-child {
    text-decoration: line-through;
}

@media (pointer: coarse) {
    button.chart-legend__item {
        padding: var(--space-2) var(--space-2);
        min-height: 36px;
    }
}
