.error-message {
    color: #a00;
}

.dof-chart {
    position: relative;
    width: 100%;
    box-sizing: border-box;
    /* min-height: 90vh; */
    /* padding-inline: 12px; */
}

.dof-chart[data-chart-type="bar-vertical"],
.dof-chart[data-chart-type="bar-horizontal"],
.dof-chart[data-chart-type="line-single"],
.dof-chart[data-chart-type="line-multi"] {
    height: auto;
}

/* ECharts needs an explicit height on the div it mounts into. */
.dof-bar-inner,
.dof-line-inner {
    min-width: 250px;
    height: clamp(400px, 30vh, 600px);
}

/* bar-horizontal.js sets its own height from the category count. */
.dof-bar-inner--horizontal {
    height: auto;
}

/* Room for the legend below the plot. */
.dof-line-inner--multi {
    height: clamp(440px, 34vh, 660px);
}

.dof-chart-title {
    text-align: center;
    text-wrap: balance;
}
.dof-chart-subtitle {
    text-align: center;
    color: #555;
    margin-bottom: 12px;
    text-wrap: balance;
}
.dof-chart-source {
    text-align: center;
    text-wrap: balance;
    font-size: 0.78em;
    color: #888;
    margin-top: 8px;
}

/* Download-data button, bottom right under the chart.
   A flow-level row rather than an absolutely positioned corner: the source note
   above it is centred and can wrap to two lines, and an overlay would land on
   top of it on narrow screens. */
.dof-chart-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.dof-chart-download {
    font: inherit;
    font-size: 0.78em;
    line-height: 1.4;
    /* --dof-accent: the chart's colour, set per button by shared.js. */
    color: var(--dof-accent, #1c4647);
    background: transparent;
    border: 1px solid var(--dof-accent, #1c4647);
    border-radius: 3px;
    padding: 4px 10px;
    cursor: pointer;
    transition:
        color 0.2s ease,
        border-color 0.15s ease,
        background-color 0.15s ease;
}

.dof-chart-download:hover,
.dof-chart-download:focus-visible {
    color: #ffffff;
    border-color: var(--dof-accent, #1c4647);
    background: var(--dof-accent, #1c4647);
}

/* Nothing to click on paper. */
@media print {
    .dof-chart-actions {
        display: none;
    }
}

/* Loading spinner */
.dof-chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.dof-chart-loading::after {
    content: "";
    width: 36px;
    height: 36px;
    border: 4px solid #ddd;
    border-top-color: #1a73e8;
    border-radius: 50%;
    animation: dof-spin 0.75s linear infinite;
}

@keyframes dof-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error box */
.dof-chart-error {
    border: 2px solid #c62828;
    color: #c62828;
    background: #fff5f5;
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Responsive */
@media (max-width: 768px) {
    .dof-chart {
        min-height: 50vh;
    }
}

@media (max-width: 480px) {
    .dof-bar-inner,
    .dof-line-inner {
        height: 350px;
    }
    .dof-bar-inner--horizontal {
        height: auto;
    }
    .dof-line-inner--multi {
        height: 420px;
    }
}

/* Data table for screen readers (renderDataTable in shared.js): in the
   accessibility tree, off screen visually. */
.dof-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Admin standalone view (admin/views/view-chart.php). */
.dof-chart--standalone .dof-bar-inner,
.dof-chart--standalone .dof-line-inner {
    height: calc(100vh - 220px);
    min-height: 360px;
}
.dof-chart--standalone .dof-bar-inner--horizontal {
    height: auto;
    min-height: 0;
}

@media (prefers-reduced-motion: reduce) {
    .dof-chart-loading::after {
        animation: none;
    }
    .dof-chart-download {
        transition: none;
    }
}

/* Canvas for the structured types (donut, sunburst, sankey, scatter, flow,
   matrix, iceberg, tracker, fragmentation, revenue-pie). Renderers that size
   by content (sankey, matrix) set an inline height instead. */
.dof-chart-canvas {
    min-width: 250px;
    height: clamp(420px, 60vh, 620px);
}
.dof-chart-canvas--round {
    height: clamp(420px, 64vh, 680px);
}
.dof-chart-canvas--tall {
    height: clamp(480px, 72vh, 760px);
}

/* Sankey keeps its columns readable and scrolls sideways on small screens. */
.dof-chart-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.dof-chart-canvas--wide {
    min-width: 700px;
}

@media (max-width: 480px) {
    .dof-chart-canvas,
    .dof-chart-canvas--round {
        height: 380px;
    }
    .dof-chart-canvas--tall {
        height: 460px;
    }
}

.dof-chart--standalone .dof-chart-canvas:not([style*="height"]) {
    height: calc(100vh - 220px);
    min-height: 420px;
}
