/* ===========================================================================
   European Index — styled in the colours of the European Union.
   Reflex blue (#003399) is the brand colour; gold (#FFCC00) is the accent.
   Green/red are reserved for semantic change indicators only.
   =========================================================================== */
:root {
    --eu-blue:        #003399;  /* EU flag field */
    --eu-blue-dark:   #00276f;  /* hover / pressed */
    --eu-blue-tint:   #eaf0fb;  /* light fill */
    --eu-blue-border: #b9cbe9;
    --eu-gold:        #ffcc00;  /* EU flag stars */
    --eu-gold-dark:   #caa200;
    --eu-gold-tint:   #fff7d6;
    --ink:            #14213d;  /* dark navy text */
    --muted:          #5b6680;
    --line:           #d7deea;
    --page:           #f5f8fd;
    --card:           #ffffff;
    --good:           #1a7f37;
    --bad:            #c5221f;
}

* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.5;
    margin: 0;
    color: var(--ink);
    background: var(--page);
}

/* Full-bleed blue header band; contents centred to the 900px column. */
header {
    display: flex;
    align-items: baseline;
    gap: 1.5rem;
    background: var(--eu-blue);
    border-bottom: 4px solid var(--eu-gold);
    padding: 1.1rem max(1rem, calc((100% - 900px) / 2));
}
header h1 { font-size: 1.25rem; margin: 0; }
header h1 a, header a { text-decoration: none; color: #fff; }
nav a {
    margin-right: 1.25rem;
    color: rgba(255, 255, 255, 0.9);
    border-bottom: 2px solid transparent;
    padding-bottom: 2px;
}
nav a:hover { color: #fff; border-bottom-color: var(--eu-gold); }

/* Content sits on a white card above the tinted page. */
main {
    max-width: 900px;
    margin: 1.5rem auto;
    padding: 1.25rem 1.5rem 1.75rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(20, 33, 61, 0.06);
}

footer {
    max-width: 900px;
    margin: 0 auto 2rem;
    padding: 0 1.5rem;
    border-top: 3px solid var(--eu-gold);
    padding-top: 1rem;
    font-size: 0.85rem;
    color: var(--muted);
}
footer .disclaimer {
    margin-top: 0.8rem;
    padding-top: 0.8rem;
    border-top: 1px dashed var(--line);
    color: var(--muted);
}

h2, h3 { color: var(--eu-blue); }
a { color: var(--eu-blue); }

.country-grid {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.5rem;
}
.country-grid a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    text-decoration: none;
    color: var(--ink);
    transition: background 0.12s, border-color 0.12s;
}
.country-grid a:hover { background: var(--eu-blue-tint); border-color: var(--eu-blue-border); }
.country-grid .flag { font-size: 1.4rem; }

table { border-collapse: collapse; width: 100%; margin-bottom: 1.5rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid #eef1f7; }
th { background: var(--eu-blue); color: #fff; }
th a { color: #fff; }

.caveat { cursor: help; }

.list-label { margin: 0.8rem 0 0.3rem; font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.tags { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tags li {
    padding: 0.2rem 0.6rem;
    background: var(--eu-blue-tint);
    border: 1px solid var(--eu-blue-border);
    border-radius: 999px;
    font-size: 0.85rem;
}

/* Election context card on the country page */
.election-card {
    border: 1px solid var(--eu-blue-border);
    border-left: 5px solid var(--eu-gold);
    background: var(--eu-blue-tint);
    border-radius: 8px;
    padding: 0.4rem 1rem 0.8rem;
    margin-bottom: 1.5rem;
}
.election-card h3 { margin: 0.6rem 0 0.4rem; }
.election-list { list-style: none; padding: 0; margin: 0 0 0.4rem; }
.election-list li { padding: 0.15rem 0; }
.muted { color: var(--muted); }

.score-badge {
    display: inline-block;
    padding: 0.5rem 0.9rem;
    background: var(--eu-blue-tint);
    border: 1px solid var(--eu-blue-border);
    border-radius: 8px;
}
.score-badge strong { color: var(--eu-blue); font-size: 1.1rem; }

/* Year-over-year / since-election change indicators (semantic colours) */
.chg { white-space: nowrap; font-size: 0.9rem; }
.chg.good { color: var(--good); }
.chg.bad  { color: var(--bad); }
.chg.flat { color: #999; }

/* Compare view — country picker */
.country-picker { border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 1rem; }
.country-picker legend { font-weight: 600; color: var(--eu-blue); padding: 0 0.4rem; }
.picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.4rem;
    margin-bottom: 0.8rem;
}
.picker-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}
.picker-item:hover { background: var(--eu-blue-tint); }
.picker-item.checked { background: var(--eu-blue-tint); border-color: var(--eu-blue); box-shadow: inset 0 0 0 1px var(--eu-blue); }
.picker-item .flag { font-size: 1.25rem; }
.picker-actions { display: flex; align-items: center; gap: 1rem; }
.picker-actions button {
    padding: 0.45rem 1.1rem;
    background: var(--eu-blue);
    color: #fff;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
}
.picker-actions button:hover { background: var(--eu-blue-dark); }
.btn-link { color: var(--eu-blue); text-decoration: none; }
.hint { color: var(--muted); }

/* Compare view — table */
.table-scroll { overflow-x: auto; }
.compare-table { border-collapse: collapse; min-width: 100%; }
.compare-table th, .compare-table td {
    padding: 0.55rem 0.8rem;
    border-bottom: 1px solid #eef1f7;
    text-align: right;
}
.compare-table thead th {
    text-align: center;
    background: var(--eu-blue);
    color: #fff;
    vertical-align: bottom;
}
.compare-table thead th a { text-decoration: none; color: #fff; }
.compare-table thead .flag { font-size: 1.6rem; }
.compare-table .metric-col {
    text-align: left;
    position: sticky;
    left: 0;
    background: #fff;
    color: var(--ink);
    font-weight: 600;
}
.compare-table thead .metric-col { background: var(--eu-blue); color: #fff; }
.compare-table tbody tr:nth-child(even) td { background: #fafbfe; }
.compare-table tbody tr:nth-child(even) .metric-col { background: #fafbfe; }
/* Best-in-comparison cell — EU gold highlight */
td.best { background: var(--eu-gold-tint) !important; font-weight: 700; color: var(--eu-blue); box-shadow: inset 0 0 0 2px var(--eu-gold); }

/* ===========================================================================
   Graph view — CSS-only table/chart switch + inline SVG line charts
   =========================================================================== */

/* The radios live next to the panels purely so `:checked ~` can reach them. */
.views .vs-radio { position: absolute; opacity: 0; pointer-events: none; }
.view-switch {
    display: inline-flex;
    margin-bottom: 0.8rem;
    border: 1px solid var(--eu-blue-border);
    border-radius: 999px;
    overflow: hidden;
}
.view-switch label {
    padding: 0.3rem 0.9rem;
    font-size: 0.85rem;
    color: var(--eu-blue);
    background: var(--card);
    cursor: pointer;
    user-select: none;
}
.view-switch label:hover { background: var(--eu-blue-tint); }
.vs-radio.is-table:checked ~ .view-chart,
.vs-radio.is-chart:checked ~ .view-table { display: none; }
.vs-radio.is-table:checked ~ .view-switch .lbl-table,
.vs-radio.is-chart:checked ~ .view-switch .lbl-chart {
    background: var(--eu-blue);
    color: #fff;
}
/* Keyboard focus must stay visible even though the radio itself is invisible. */
.vs-radio:focus-visible ~ .view-switch { outline: 2px solid var(--eu-gold-dark); outline-offset: 2px; }
.chart-card {
    margin: 0;
    padding: 0.6rem 0.7rem 0.4rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
}
.chart-card figcaption {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--eu-blue);
    margin-bottom: 0.3rem;
}
.chart-card figcaption .muted { font-weight: 400; margin-left: 0.35rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 9px; font-family: system-ui, sans-serif; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--card); stroke-width: 1; }
.chart .dot:hover { r: 4; }
.chart-empty { color: var(--muted); font-size: 0.85rem; padding: 1.2rem 0; text-align: center; }

.chart-legend {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 1.1rem;
    padding: 0.6rem 0 0.1rem;
    margin: 0;
    font-size: 0.85rem;
}
.chart-legend li { display: flex; align-items: center; gap: 0.4rem; }
.chart-legend .line-sample { width: 24px; height: 8px; flex: none; }
.chart-legend .swatch {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 0.25rem;
}

/* Interactive layer (chart.js): country chips, crosshair, hover tooltip.
   Everything here is progressive enhancement — without JS the static SVG and
   the plain .chart-legend below still render. */
.chart-controls { margin-bottom: 0.9rem; }
.chips-hint { margin: 0 0 0.5rem; }
.chart-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.7rem;
    font: inherit;
    font-size: 0.85rem;
    color: var(--muted);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
}
.chip:hover { border-color: var(--eu-blue-border); background: var(--eu-blue-tint); color: var(--ink); }
.chip .swatch {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--line);
}
.chip.on {
    color: var(--ink);
    font-weight: 600;
    background: var(--card);
    border-color: var(--c, var(--eu-blue));
    box-shadow: inset 0 0 0 1px var(--c, var(--eu-blue));
}
.chip.on .swatch { background: var(--c, var(--eu-blue)); }
.chip.loading { opacity: 0.5; cursor: progress; }

/* The wrapper positions the tooltip over the chart. */
.chart-wrap { position: relative; }
.chart .crosshair { stroke: var(--eu-blue-border); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
    position: absolute;
    top: 0.2rem;
    transform: translateX(0.5rem);
    min-width: 8rem;
    padding: 0.35rem 0.5rem;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid var(--eu-blue-border);
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(20, 33, 61, 0.12);
    font-size: 0.78rem;
    line-height: 1.5;
    pointer-events: none;
    z-index: 2;
}
.chart-tip.flip { transform: translateX(-100%) translateX(-0.5rem); }
.chart-tip strong { display: block; color: var(--eu-blue); }
.chart-tip .row { display: flex; align-items: center; gap: 0.35rem; white-space: nowrap; }
.chart-tip .line-sample { width: 20px; height: 8px; flex: none; }
.chart-tip .row b { margin-left: auto; padding-left: 0.6rem; }
.chart-tip .swatch { width: 0.55rem; height: 0.55rem; border-radius: 50%; display: inline-block; }

/* The big chart: one wide card per section, driven by the chips above it. */
.chart-big { padding: 0.8rem 1rem 0.6rem; }
.chart-big .chart-title { font-size: 1rem; font-weight: 600; color: var(--eu-blue); margin-bottom: 0.4rem; }
.chart-big .chart { min-height: 220px; }

/* Chip bars are grouped (Metrics / Countries) with a small label in front. */
.chip-group { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.5rem; }
.chip-group-label {
    flex: none;
    width: 4.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    padding-top: 0.3rem;
}
@media (max-width: 600px) {
    .chip-group { flex-direction: column; gap: 0.2rem; }
    .chip-group-label { width: auto; }
}

/* "Select all" / "Clear" next to the country chips. */
.chip-action {
    padding: 0.25rem 0.7rem;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--eu-blue);
    background: var(--eu-blue-tint);
    border: 1px solid var(--eu-blue-border);
    border-radius: 999px;
    cursor: pointer;
}
.chip-action:hover:not(:disabled) { background: var(--eu-blue); color: #fff; }
.chip-action:disabled { opacity: 0.45; cursor: default; }

/* A full 27-country tooltip must still fit on screen, so it tightens up. */
.chart-tip { max-height: 82vh; overflow: hidden; }
.chart-tip.compact { font-size: 0.72rem; line-height: 1.28; }
.chart-tip.compact .line-sample { width: 16px; }
