/*
 * US Energy Data Platform — shared styles
 * Load via: <link rel="stylesheet" href="/charts/shared/styles.css">
 * Also add Google Fonts in <head>:
 *   <link href="https://fonts.googleapis.com/css2?family=Inter:wght@600;700&family=Lato:wght@300;400;700&display=swap" rel="stylesheet">
 *
 * ── Design decisions (JS-side constants to use in new charts) ──
 * Chart lines:   stroke-width 1.5px, stroke-linecap 'butt', stroke-linejoin 'round'
 * Bar color:     #c26b6b (muted red) — single color for all bars
 * Bar padding:   scaleBand().padding(0.35)
 * Bar labels:    entity font-weight '700', fill '#5b5b5b'; value font-size '12px', fill '#5b5b5b'
 * Axis domain:   x-axis stroke '#999', y-axis domain removed
 * Axis ticks:    font-size '12px', fill '#5b5b5b'
 * Grid:         #line-chart .tick line (stroke:#999) + .grid line (dasharray 4,4, opacity 0.3) → subtle gray dashes. Never override with local CSS.
 * Scatter grid: override inline to #e8e8e8 / opacity 1 / no dash
 * Play speed:    400ms
 * Tooltips:      use .tooltip-header / .tooltip-body / .tooltip-row / .tooltip-swatch / .tooltip-name / .tooltip-value
 *
 * ── Scatter chart design decisions ──
 * Dots:          fill '#B22234', stroke '#7a1520', stroke-width 0.5, opacity 0.8, radius 5
 * Hover dot:     radius 7, opacity 1
 * Selected dot:  opacity 0.9, radius 6 (when state picker active)
 * Faded dot:     opacity 0.07, radius 4 (non-selected states)
 * Grid:          stroke #e8e8e8, stroke-opacity 1, no dasharray — set inline to override shared default
 * Zero lines:    .zero-line — stroke #aaa, no dash
 * Labels:        .scatter-label — 10.5px, paint-order stroke halo (white 2.5px)
 * Label overlap: greedy left-to-right via getBBox(), pad 3px; hidden labels revealed on hover
 * State picker:  use .state-picker-wrapper / .state-picker-btn / .state-picker-panel (see below)
 */

* { box-sizing: border-box; }

body {
    font-family: 'Lato', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    margin: 0; padding: 0;
    background: #f0f0f0; color: #333; line-height: 1.6;
}

/* ── Outer card ── */
.container {
    max-width: min(1120px, var(--card-width)); margin: 40px auto;
    background: white; border: 1px solid #d9d9d9;
    border-radius: 4px; box-shadow: 0 1px 5px rgba(0,0,0,0.08);
    display: flex; flex-direction: column;
}

/* ── Embedded overrides ── */
/* Height of the plotting area. Was a flat 600px, which made the chart card
   873px tall on every screen — taller than the visible area of any laptop, so
   the frame filled the window and still needed a scroll to see the footer and
   timeline. Now it tracks the window: 400px is the chrome around the plot (site
   header, title, view tabs, timeline, footer bar) plus a little breathing room,
   so the whole card lands inside the viewport. Clamped so it never gets too
   cramped to read on a short window, and never exceeds the original 600px on a
   tall one — large displays look exactly as before. Embeds override both rules
   below and are unaffected; charts read clientHeight at draw time and the
   shared resize handler redraws them, so this needs no per-chart change. */
:root {
    --chart-height: clamp(320px, calc(100vh - 380px), 600px);
    /* The frame's width tracks its height so the card scales as a whole rather
       than just getting shorter. 1.867 is the original 1120:600 proportion, so a
       tall window renders exactly the 1120x600 card as before and a short one
       gets the same shape, smaller. Shortening height alone left the map — which
       holds a 1.6:1 aspect and so scales to whichever side binds — shrinking
       inside a frame that stayed full width, turning 159px of slack into 607px. */
    --card-width: clamp(1000px, calc(var(--chart-height) * 1.867 + 40px), 1120px);
}

body.embedded { padding: 0; background: transparent; }
body.embedded .site-header { display: none; }
body.embedded .footer { display: none; }
body.embedded .container { max-width: 100%; margin: 0; border: none; border-radius: 0; box-shadow: none; height: 100vh; overflow: hidden; }
body.embedded h1 { cursor: pointer; }
body.embedded h1:hover { text-decoration: underline; }
body.embedded .chart-body { overflow: hidden; }
body.embedded .view-container { height: 100%; min-height: 0; }
body.embedded .marimekko-view { height: 100% !important; }

/* ── Header ── */
.chart-header { display: flex; flex-direction: column; gap: 10px; padding: 16px 20px 10px; border-bottom: 1px solid #e8e8e8; }
.chart-header-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
h1 { margin: 0 0 3px 0; color: #222; font-size: 22px; font-family: 'Inter', sans-serif; font-weight: 700; line-height: 1.2; }
.chart-logo { height: 22px; width: auto; opacity: 0.75; flex-shrink: 0; margin-top: 4px; }
/* House style: logo lives in the footer (bottom-left), not the header. */
.chart-header-top .chart-logo { display: none; }
.chart-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 20px 10px; }
.footer-logo { height: 13px; width: auto; opacity: 0.7; flex-shrink: 0; }
/* Funder credit sits beside the IFP mark. The two logos are set to the same
   height rather than the same width: trimmed of its canvas padding, the Arnold
   Ventures lockup is 3.39:1 against IFP's 3.46:1, so equal height gives them
   near-equal width and equal visual weight. A hairline rule keeps them reading
   as two marks rather than one lockup. */
.footer-logos { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.footer-logo-sep { width: 1px; height: 13px; background: #dcdcdc; flex-shrink: 0; }
/* 15px, not the 13px IFP uses. Arnold Ventures is a stacked two-line lockup, so
   at equal height its type sets about half the size of IFP's single line and
   reads as fine print. 15px brings the wordmark back to a comparable size while
   keeping it from outweighing the publisher's own mark, which 17px did. */
/* Opacity 0.55, not the 0.7 IFP uses. The IFP artwork is dark grey (luminance
   55/255) while the Arnold Ventures mark is pure black, so at matched opacity AV
   renders visibly heavier. On white, IFP composites to about 115; 0.55 puts AV at
   the same tone, so neither mark draws the eye first. */
.footer-logo-av { height: 15px; opacity: 0.55; }
.subtitle { color: #777; font-size: 13px; font-weight: 400; margin: 0; }

/* ── Source selector ── */
.source-selector { display: flex; align-items: center; gap: 6px; flex-shrink: 0; padding-top: 2px; }
/* font-family is explicit: without it this inherits DM Sans from the page
   stylesheet while the .source-select beside it is Lato, so the label rendered
   noticeably lighter than its own dropdown — and than the same label on charts
   that set Lato inline. */
.control-label { font-size: 12px; color: #888; white-space: nowrap; font-family: 'Lato', sans-serif; }
.source-select { padding: 5px 8px; font-size: 13px; font-family: 'Lato', sans-serif; border: 1px solid #d3d3d3; border-radius: 3px; background: white; color: #333; cursor: pointer; outline: none; }
.source-select:hover { border-color: #999; }
.source-select:focus { border-color: #3c4e66; box-shadow: 0 0 0 2px rgba(60,78,102,0.1); }

/* ── Chart body ── */
.chart-body { position: relative; flex: 1; display: flex; padding: 6px 0 0; }
.view-container { position: relative; height: var(--chart-height); flex: 1; min-width: 0; padding: 0 20px; }

/* ── State panel (full page, right side) ── */
.state-panel {
    width: 200px; flex-shrink: 0;
    border-left: 1px solid #e8e8e8;
    display: flex; flex-direction: column;
    height: var(--chart-height); overflow: hidden;
}
.state-panel.hidden { display: none; }
body.embedded .state-panel { display: none; }
.state-panel-title { font-size: 10px; font-weight: 700; color: #bbb; text-transform: uppercase; letter-spacing: 0.06em; padding: 12px 12px 6px; flex-shrink: 0; }
.state-panel-search-wrapper { padding: 0 8px 4px; flex-shrink: 0; }
.state-panel-list { flex: 1; overflow-y: auto; min-height: 0; }
.state-panel-clear { padding: 5px 12px; font-size: 11px; color: #bbb; cursor: pointer; border-bottom: 1px solid #f2f2f2; user-select: none; flex-shrink: 0; }
.state-panel-clear:hover { color: #d73027; background: #fafafa; }
.state-panel .state-checkbox-item { padding: 4px 10px; }
.state-panel .state-search { font-size: 11px; padding: 4px 7px; }

/* ── Map view ── */
.map-view { height: 100%; display: flex; flex-direction: column; }
.map-view.hidden { display: none; }
#map { width: 100%; flex: 1; min-height: 0; overflow: hidden; }
#map svg { width: 100%; height: 100%; display: block; }
.map-state { stroke: #d0d0d0; stroke-width: 0.8px; cursor: pointer; transition: stroke-width 0.2s; }
.map-state:hover { stroke: #333; stroke-width: 2px; }

/* ── Tooltip (OWID style) ── */
.tooltip {
    position: fixed;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    font-size: 13px; font-family: 'Lato', sans-serif;
    pointer-events: none; opacity: 0; transition: opacity 0.15s;
    z-index: 100; min-width: 160px; max-width: 260px;
}
.tooltip-header {
    background: #f7f7f7;
    padding: 6px 12px;
    font-weight: 700; font-size: 13px; color: #2d2d2d;
    border-bottom: 1px solid #e8e8e8;
    border-radius: 4px 4px 0 0;
}
.tooltip-body { padding: 6px 12px 8px; }
.tooltip-row { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.tooltip-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.tooltip-name { flex: 1; color: #555; }
.tooltip-value { font-weight: 600; color: #2d2d2d; font-variant-numeric: tabular-nums; margin-left: 12px; }
.tooltip-no-data { font-size: 11px; color: #aaa; margin-top: 5px; font-style: italic; }
.tooltip-divider { border: none; border-top: 1px solid #e8e8e8; margin: 4px 0; }
.value-increase { color: #1a9850; }
.value-decrease { color: #d73027; }

/* ── Legend ── */
.legend { padding: 6px 0 2px; border-top: 1px solid #e0e0e0; margin-top: 4px; }
.legend-title { font-size: 12px; color: #767676; margin-bottom: 6px; text-align: center; }
.legend-scale { display: flex; flex-direction: column; align-items: center; gap: 0; }
/* Edge-label strip legend (all map charts) */
.legend-strip { display: flex; width: 490px; }
.legend-strip-segment { flex: 1; height: 14px; border: 1px solid #fff; cursor: pointer; transition: opacity 0.15s; }
.legend-tick-row { width: 490px; position: relative; height: 18px; margin-top: 2px; }
.legend-tick-label { position: absolute; transform: translateX(-50%); font-size: 11px; color: #767676; white-space: nowrap; }

/* ── View tabs row (tabs + optional embedded state selector) ── */
.view-tabs-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.view-tabs { display: flex; gap: 2px; }
.embedded-state-selector { display: none; }
body.embedded .embedded-state-selector.visible { display: flex; align-items: center; }
.embedded-state-selector .state-multiselect { width: 170px; }

/* ── View tabs ── */
.view-tab {
    display: flex; align-items: center; gap: 5px; padding: 5px 10px;
    border: none; background: transparent; border-radius: 3px; cursor: pointer;
    font-size: 12px; font-family: 'Lato', sans-serif; color: #999; transition: all 0.15s;
}
.view-tab:hover { background: #efefef; color: #555; }
.view-tab.active { background: #e8edf3; color: #3c4e66; font-weight: 600; }
.view-tab svg { flex-shrink: 0; }

/* ── Line chart view ── */
/*
 * Canonical line chart grid/axis style — do NOT override these in individual charts.
 * Grid:    .grid line gets stroke:#999 (from #line-chart .tick line) + dasharray/opacity below → subtle gray dashes
 * X-axis:  domain line #999, tick marks #999 (size 4 in JS); y-axis domain removed, tickSize(0) in JS
 */
.chart-view { display: none; }
.chart-view.active { display: flex; flex-direction: column; height: 100%; }
#line-chart { width: 100%; flex: 1; min-height: 0; }
.line-label { font-size: 12px; font-weight: 500; }
/* House style: line charts show smooth lines with no persistent per-point markers.
   The hover read-out dot/crosshair is a separate element and is unaffected.
   (Connected scatterplots do not use .chart-dot, so their points remain visible.) */
.chart-dot { display: none; }
#line-chart .tick text { font-family: 'Lato', sans-serif; font-size: 12px; fill: #5b5b5b; }
#line-chart .domain { stroke: #999; }
#line-chart .tick line { stroke: #999; }
.grid line { stroke-dasharray: 4,4; shape-rendering: crispEdges; stroke-opacity: 0.3; }
.grid path { stroke-width: 0; }

/* ── Bar chart view ── */
.bar-view { display: none; }
.bar-view.active { display: flex; flex-direction: column; height: 100%; }
#bar-chart { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
#bar-chart svg { display: block; }
#bar-chart .tick text { font-family: 'Lato', sans-serif; font-size: 12px; fill: #5b5b5b; }
#bar-chart .domain { stroke: #999; }
#bar-chart .tick line { stroke: #999; }
#bar-chart .bar-grid .tick line { stroke: #f2f2f2; }
#bar-chart .bar-grid .domain { stroke: none; }

/* ── State selector (dropdown, used in embedded mode) ── */
.state-multiselect { position: relative; width: 100%; max-width: 320px; }
.state-multiselect-header {
    padding: 6px 10px; background: #f7f7f7; border: 1px solid #d3d3d3; border-radius: 3px;
    font-size: 12px; color: #5e5e5e; cursor: pointer; user-select: none;
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.state-multiselect-header:hover { background: #f2f2f2; }
.state-multiselect-header.expanded { border-radius: 3px 3px 0 0; }
.state-multiselect-header-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-multiselect-header-arrow { flex-shrink: 0; font-size: 9px; color: #aaa; transition: transform 0.15s; }
.state-multiselect-header.expanded .state-multiselect-header-arrow { transform: rotate(180deg); }
.state-multiselect-container {
    max-height: 240px; overflow-y: auto; border: 1px solid #d3d3d3; border-top: none;
    border-radius: 0 0 3px 3px; background: white; padding: 4px 0; display: none;
    position: absolute; width: 100%; z-index: 10; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.state-multiselect-container.expanded { display: block; }
/* Group headings inside the state/region picker ("Regions (EIA)", "Grid
   operators (RTOs)"). Fifteen charts each carried their own copy of this rule in
   a local <style>; defining it here covers the charts that gained region
   groupings later and had none. A quiet uppercase caption — it separates the
   list, it is not a row you can click. */
.state-group-header {
    font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; color: #9aa1ab;
    padding: 9px 12px 4px; margin-top: 3px;
    border-top: 1px solid #eee; pointer-events: none;
}

.state-checkbox-item { display: flex; align-items: center; padding: 5px 10px; cursor: pointer; font-size: 12px; color: #333; gap: 8px; user-select: none; }
.state-checkbox-item:hover { background: #f5f5f5; }
.state-checkbox-item.selected { color: #222; }
.state-item-tick { width: 14px; flex-shrink: 0; color: #3c4e66; font-size: 13px; font-weight: 700; }
.state-item-name { flex: 1; }
.state-clear-row { padding: 5px 10px; font-size: 11px; color: #999; cursor: pointer; border-bottom: 1px solid #f2f2f2; user-select: none; }
.state-clear-row:hover { color: #d73027; background: #fafafa; }
.state-search-wrapper { padding: 6px 8px 4px; border-bottom: 1px solid #f2f2f2; }
.state-search { width: 100%; padding: 5px 8px; font-size: 12px; font-family: 'Lato', sans-serif; border: 1px solid #d3d3d3; border-radius: 3px; outline: none; box-sizing: border-box; color: #333; }
.state-search:focus { border-color: #3c4e66; }

/* ── Table view ── */
.table-view { display: none; }
.table-view.active { display: flex; flex-direction: column; height: 100%; }

/* ── Marimekko distribution view ── */
.marimekko-view { display: none; }
.marimekko-view.active { display: flex; flex-direction: column; height: 100%; }
#marimekko-chart { width: 100%; flex: 1; min-height: 0; overflow: visible; }
#marimekko-chart svg { display: block; overflow: visible; }
#marimekko-chart .grid line { stroke: #999; }
#data-table { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.data-table-container { overflow-x: auto; overflow-y: auto; border: 1px solid #e0e0e0; border-radius: 2px; flex: 1; min-height: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; background: white; }
.data-table thead { background: #f7f7f7; position: sticky; top: 0; z-index: 10; }
.data-table th { padding: 8px 12px; text-align: left; font-weight: 600; color: #5e5e5e; border-bottom: 2px solid #d3d3d3; cursor: pointer; user-select: none; }
.data-table th:hover { background: #f2f2f2; }
.data-table th.sortable::after { content: ' ↕'; color: #ccc; font-size: 10px; }
.data-table th.sort-asc::after { content: ' ↑'; color: #5e5e5e; }
.data-table th.sort-desc::after { content: ' ↓'; color: #5e5e5e; }
.data-table td { padding: 6px 12px; border-bottom: 1px solid #e8e8e8; color: #333; }
.data-table tbody tr:hover { background: #f9f9f9; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .col-name { font-weight: 500; color: #222; }
.data-table .col-value { font-variant-numeric: tabular-nums; }
.change-positive { color: #1a9850; }
.change-negative { color: #d73027; }

/* ── Footer: timeline ── */
.chart-footer-bar { display: flex; align-items: center; padding: 0 20px; height: 44px; margin-top: 4px; margin-bottom: 2px; }
.timeline { display: flex; align-items: center; gap: 8px; flex: 1; }
.play-btn {
    width: 28px; height: 28px; border-radius: 50%; border: 1px solid #d3d3d3;
    background: white; cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 10px; color: #3c4e66; flex-shrink: 0; transition: all 0.15s; padding: 0;
}
.play-btn:hover { border-color: #3c4e66; background: #f0f4f8; }
.play-btn.playing { background: #3c4e66; color: white; border-color: #3c4e66; }
.timeline-year { font-size: 11px; color: #888; min-width: 28px; text-align: center; font-variant-numeric: tabular-nums; }
.timeline-year.current { color: #222; font-weight: 700; font-size: 13px; min-width: 34px; }
.year-slider-wrapper { flex: 1; }
.year-slider { width: 100%; height: 4px; border-radius: 2px; background: #e0e0e0; outline: none; -webkit-appearance: none; appearance: none; cursor: pointer; }
.year-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #3c4e66; cursor: pointer; border: 2px solid white; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.year-slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #3c4e66; cursor: pointer; border: 2px solid white; }

/* ── Dual-range slider (line chart view) ── */
.dual-range-wrapper { flex: 1; position: relative; height: 20px; display: flex; align-items: center; }
.dual-range-track-bg { position: absolute; left: 0; right: 0; height: 4px; border-radius: 2px; background: #e0e0e0; pointer-events: none; }
.dual-range-track-fill { position: absolute; height: 4px; border-radius: 2px; background: #3c4e66; pointer-events: none; }
.dual-range-wrapper input[type=range] { position: absolute; width: 100%; pointer-events: none; -webkit-appearance: none; appearance: none; background: transparent; margin: 0; padding: 0; height: 4px; }
.dual-range-wrapper input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: all; width: 14px; height: 14px; border-radius: 50%; background: #3c4e66; cursor: pointer; border: 2px solid white; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.dual-range-wrapper input[type=range]::-moz-range-thumb { pointer-events: all; width: 14px; height: 14px; border-radius: 50%; background: #3c4e66; cursor: pointer; border: 2px solid white; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.dual-range-wrapper input[type=range]::-webkit-slider-runnable-track { background: transparent; }
.dual-range-wrapper input[type=range]::-moz-range-track { background: transparent; }

/* ── Source attribution ── */
.source { padding: 5px 20px 4px; font-size: 11px; color: #aaa; font-weight: 300; line-height: 1.5; }
.source + .source { padding-top: 1px; }
.source:last-of-type { padding-bottom: 8px; }
.source span[style*="font-weight:600"], .source span[style*="font-weight: 600"] { color: #aaa; }
.source a { color: #aaa; text-decoration: none; }
.source a:hover { color: #555; text-decoration: underline; }

/* ── Download button & popover ── */
.download-bar {
    display: flex;
    gap: 6px;
}
.download-wrap {
    position: relative;
}
.download-btn,
.share-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    color: #6b7280;
    background: transparent;
    border: none;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.16);
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s, box-shadow 0.15s, background 0.15s;
    line-height: 1;
    font-family: 'Lato', sans-serif;
    font-size: 12.5px;
}
.download-btn:hover,
.share-btn:hover { color: #1f2937; box-shadow: 0 0 0 1px rgba(0,0,0,0.30); background: rgba(0,0,0,0.03); }
.download-btn svg,
.share-btn svg { flex-shrink: 0; }
.btn-label { white-space: nowrap; }

.share-popover {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.14);
    width: 240px;
    z-index: 500;
    overflow: hidden;
}
.share-popover.open { display: block; }

.copy-confirm {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: #3c4e66;
    color: #fff;
    font-family: 'Lato', sans-serif;
    font-size: 12px;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 600;
}
.copy-confirm.visible { display: block; }

.download-popover {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.14);
    width: 240px;
    z-index: 500;
    overflow: hidden;
}
.download-popover.open { display: block; }
.download-popover-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: #aaa;
    padding: 10px 14px 6px;
    border-bottom: 1px solid #f0f0f0;
    font-family: 'Lato', sans-serif;
}
.download-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid #f5f5f5;
}
.download-option:last-child { border-bottom: none; }
.download-option:hover { background: #f0f4f8; }
.download-option-icon {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: #e8edf3;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #3c4e66;
}
.download-option-text { flex: 1; }
.download-option-title {
    font-family: 'Lato', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #222;
    margin-bottom: 2px;
}
.download-option-desc {
    font-family: 'Lato', sans-serif;
    font-size: 11px;
    color: #888;
    line-height: 1.4;
}

/* PNG export — strip interactive controls */
.container.png-export .view-tabs-row { display: none !important; }
.container.png-export .chart-footer-bar { display: none !important; }
.container.png-export .state-panel { display: none !important; }
.container.png-export .download-bar { display: none !important; }
.container.png-export .chart-body { padding-top: 0; }
/* Breathing room so the logo (footer) and data-source line aren't flush against
   the image edge / clipped in the exported PNG. */
.container.png-export { padding: 10px 8px 20px; }
.container.png-export .chart-footer { padding-bottom: 4px; }

/* ── Scatter chart ── */
/* Grid: scatter charts need more visible grid — override shared .grid line inline in the chart */
.scatter-dot { cursor: pointer; transition: fill 250ms, opacity 150ms; }
.scatter-label {
    font-size: 10.5px;
    font-family: 'Lato', sans-serif;
    pointer-events: none;
    fill: #5b5b5b;
    paint-order: stroke;
    stroke: white;
    stroke-width: 2.5px;
    stroke-linejoin: round;
}
.axis-label { font-size: 12px; fill: #5b5b5b; font-family: 'Lato', sans-serif; }
.zero-line { stroke: #aaa; stroke-width: 1px; stroke-dasharray: none; }

/* ── State picker (scatter) ── */
.state-picker-wrapper { position: relative; }
.state-picker-btn {
    font-family: 'Lato', sans-serif;
    font-size: 13px;
    color: #333;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 5px 10px;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.4;
}
.state-picker-btn:hover { border-color: #999; }
.state-picker-btn.has-selection { border-color: #B22234; color: #B22234; }
.state-picker-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.13);
    z-index: 200;
    width: 210px;
}
.state-picker-panel.open { display: block; }
.state-picker-top { padding: 8px 8px 6px; border-bottom: 1px solid #f0f0f0; }
.state-picker-search {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 8px;
    font-size: 12px;
    font-family: 'Lato', sans-serif;
    border: 1px solid #ddd;
    border-radius: 4px;
    outline: none;
    margin-bottom: 6px;
}
.state-picker-actions { display: flex; gap: 10px; }
.state-picker-action {
    font-size: 12px;
    color: #888;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-family: 'Lato', sans-serif;
}
.state-picker-action:hover { color: #333; text-decoration: underline; }
.state-picker-list { max-height: 230px; overflow-y: auto; padding: 4px 0; }
.state-picker-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 13px;
    font-family: 'Lato', sans-serif;
    color: #333;
}
.state-picker-item:hover { background: #f5f5f5; }
.state-picker-item input[type="checkbox"] { cursor: pointer; accent-color: #B22234; flex-shrink: 0; }

/* ── Chart metadata ── */
.chart-metadata {
    max-width: 1120px;
    margin: 0 auto;
    padding: 36px 20px 48px;
    border-top: 1px solid #e8e8e8;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 48px;
    align-items: start;
}
.chart-metadata-main { min-width: 0; }
.chart-metadata-prose {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 400;
    color: #555;
    line-height: 1.7;
    max-width: 700px;
    margin: 0 0 12px 0;
}
.chart-metadata-prose:last-child { margin-bottom: 0; }
.chart-metadata-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-left: 24px;
    border-left: 1px solid #e8e8e8;
}
.chart-metadata-field dt {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #aaa;
    margin: 0 0 3px 0;
}
.chart-metadata-field dd {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: #444;
    margin: 0;
    line-height: 1.5;
}
.chart-metadata-field dd a { color: #1a5ea8; text-decoration: none; }
.chart-metadata-field dd a:hover { text-decoration: underline; }
.chart-metadata-section { margin-top: 4px; }
.chart-metadata-subheading {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin: 28px 0 10px 0;
}
.chart-metadata-subheading:first-child { margin-top: 0; }

/* ── Explore more section ── */
.chart-explore-more {
    max-width: 1120px;
    margin: 0 auto 56px;
    padding: 24px 20px 0;
    border-top: 1px solid #e8e8e8;
}
/* Topic banner */
.chart-explore-topic-banner {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 11px 16px;
    background: #f5f5f5;
    border-radius: 4px;
    margin-bottom: 20px;
    text-decoration: none;
    transition: background 0.12s;
}
.chart-explore-topic-banner:hover { background: #ececec; }
.chart-explore-topic-banner-label {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: #aaa;
    flex-shrink: 0;
}
.chart-explore-topic-banner-name {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    transition: color 0.12s;
}
.chart-explore-topic-banner:hover .chart-explore-topic-banner-name { color: #111; }
.chart-explore-topic-banner svg { color: #bbb; flex-shrink: 0; }

/* Related charts label */
.chart-explore-related-label {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #aaa;
    margin: 0 0 12px 0;
    letter-spacing: 0.04em;
}

.chart-explore-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.chart-explore-card {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 0.14s, box-shadow 0.14s;
}
.chart-explore-card:hover {
    border-color: #bbb;
    box-shadow: 0 2px 10px rgba(0,0,0,0.07);
}
.chart-explore-thumb {
    position: relative;
    width: 100%;
    height: 155px;
    overflow: hidden;
    background: #f5f5f5;
    flex-shrink: 0;
}
.chart-explore-thumb iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 960px;
    height: 500px;
    border: none;
    transform: scale(0.375);
    transform-origin: top left;
    pointer-events: none;
}
.chart-explore-thumb-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
}
.chart-explore-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    gap: 10px;
    border-top: 1px solid #efefef;
    background: #fff;
}
.chart-explore-card-title {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.35;
    color: #444;
}
.chart-explore-card:hover .chart-explore-card-title { color: #111; }
.chart-explore-card-footer svg { flex-shrink: 0; color: #ccc; }
.chart-explore-card:hover .chart-explore-card-footer svg { color: #aaa; }

/* ── Narrow screens ───────────────────────────────────────────────────────────
   The chart stylesheet had no media queries, and the map legend carries a fixed
   width: 490px — 100px wider than a phone — so 37 of 57 chart pages scrolled
   sideways, by up to 333px. max-width (not width) is deliberate: the legend
   keeps its 490px at every width where 490px fits, and only shrinks once the
   container is genuinely narrower, so nothing changes on a page that isn't
   already overflowing. The two flex-wrap rules are load-bearing — without them
   the tab row and source selector still push the page wide. */
@media (max-width: 640px) {
    .legend-strip,
    .legend-tick-row  { max-width: 100%; }
    .view-tabs-row    { flex-wrap: wrap; }
    .source-selector  { flex-wrap: wrap; max-width: 100%; }
    .source-select    { max-width: 100%; }
}

/* ── Small screens ─────────────────────────────────────────────────────────
   .chart-body is a flex ROW: the plot and the 200px state panel sit side by
   side. That is fine at desktop widths and ruinous on a phone — at 390px the
   panel took 200px and the plot was left with 148px, about a third of the
   screen. Below the breakpoint the row becomes a column, so the plot gets the
   full width and the panel sits under it at a capped height. Paired with
   window.fitMargin(), which shrinks the in-SVG label gutters at the same
   breakpoint. Desktop is untouched: everything here is inside the query. */
@media (max-width: 699px) {
    .chart-body      { flex-direction: column; }
    .view-container  { padding: 0 10px; }

    .state-panel {
        width: 100%;
        height: auto;
        max-height: 190px;
        border-left: none;
        border-top: 1px solid #e8e8e8;
        margin-top: 10px;
    }
    .state-panel-list { max-height: 132px; }

    /* Axis and series labels are sized for a 760px plot; at 360px they crowd. */
    .chart-body svg text { font-size: 11px; }
    .axis-label          { font-size: 11px; }

    /* The five view tabs do not fit one phone row — Marimekko was being cut
       off mid-word. Let them wrap onto a second line rather than truncate. */
    .view-tabs-row { flex-wrap: wrap; row-gap: 6px; }
    .view-tabs     { flex-wrap: wrap; row-gap: 4px; }
    .view-tab      { padding-left: 8px; padding-right: 8px; }

    /* Controls stack rather than overflow. */
    .chart-controls, .control-row { flex-wrap: wrap; }
    .chart-footer    { flex-wrap: wrap; gap: 8px; }
    .download-bar    { margin-left: auto; }
}
