/* Budget de la France — feuille de style unique.
   Les couleurs sont des jetons (custom properties) ; le thème sombre redéfinit les mêmes jetons. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6b6a65;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --btn: #2a78d6; /* fond de bouton actif, texte blanc ≥ 4,5:1 */
  /* Séries (palette validée : dataviz/validate_palette.js) */
  --s1: #2a78d6;  /* ressources / dépenses de l'État */
  --s2: #eb6834;  /* emprunt, deuxième série */
  --s3: #1baf7a;  /* versements à d'autres administrations */
  --neg: #e34948; /* diminutions (cascade) */
  --neutral: #898781;
  --on-fill: #ffffff;
  --warn-bg: #fff4e0;
  --warn-ink: #6b4300;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9d9b93;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #6da7ec;
    --accent-ink: #86b6ef;
    --btn: #256abf;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --neg: #e66767;
    --neutral: #898781;
    --warn-bg: #2e2412;
    --warn-ink: #f3cf8a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #9d9b93;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #6da7ec;
  --accent-ink: #86b6ef;
  --btn: #256abf;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --neg: #e66767;
  --neutral: #898781;
  --warn-bg: #2e2412;
  --warn-ink: #f3cf8a;
  --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 16px/1.55 var(--font);
  overflow-x: hidden;
}

a { color: var(--accent-ink); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4em; text-wrap: balance; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.8em; }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 24px; } }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 16px; top: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; }

/* En-tête */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--s1) url("/favicon.svg") center / cover; flex: none; }
.brand-year { color: var(--muted); margin-left: 4px; }
.theme-toggle { display: inline-flex; gap: 6px; align-items: center; background: transparent; color: var(--text-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 0.875rem; cursor: pointer; }
.theme-toggle:hover { background: var(--surface-2); }

.site-nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 0; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a { flex: none; padding: 10px 12px; color: var(--text-2); text-decoration: none; border-bottom: 2px solid transparent; font-size: 0.95rem; }
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding-top: 28px; padding-bottom: 48px; min-height: 60vh; }
main:focus, main:focus-visible { outline: none; }
.loading { color: var(--muted); }

.page-intro { max-width: 70ch; margin-bottom: 24px; }
.page-intro p { color: var(--text-2); font-size: 1.05rem; }

.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 20px; font-size: 0.95rem; }
.notice strong { color: inherit; }
.error { border-left: 4px solid var(--neg); padding: 12px 16px; background: var(--surface); }

/* Tuiles d'indicateurs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--text-2); font-size: 0.875rem; margin: 0 0 6px; }
.kpi-value { font-size: 1.75rem; font-weight: 600; line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
.kpi-sub { color: var(--muted); font-size: 0.8125rem; margin: 6px 0 0; }
.kpi--hero .kpi-value { font-size: clamp(2rem, 1.6rem + 1.5vw, 3rem); }
.kpi-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

/* Cartes et graphiques */
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 960px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 8px 16px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-sub { color: var(--text-2); margin: 4px 0 0; font-size: 0.95rem; max-width: 75ch; }
.card-foot { margin-top: 10px; font-size: 0.8125rem; color: var(--muted); }

.chart { width: 100%; height: 420px; }
.chart--tall { height: 560px; }
.chart--short { height: 320px; }
@media (max-width: 600px) {
  .chart { height: 360px; }
  .chart--tall { height: 520px; }
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 8px; padding: 0; list-style: none; font-size: 0.875rem; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

/* Contrôles */
.controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin: 0 0 16px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { font: inherit; font-size: 0.875rem; border: 0; background: transparent; color: var(--text-2); padding: 6px 12px; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--btn); color: #fff; }
.control-label { font-size: 0.875rem; color: var(--text-2); margin-right: 6px; }
.btn-link { font: inherit; font-size: 0.875rem; background: none; border: 0; color: var(--accent-ink); cursor: pointer; padding: 0; text-decoration: underline; }
input[type="search"] { font: inherit; font-size: 0.95rem; padding: 7px 10px; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 0; width: 260px; max-width: 100%; }

/* Tableaux */
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; font-size: 0.8125rem; white-space: nowrap; }
th[data-sort] { cursor: pointer; user-select: none; }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: 0.7em; }
th[aria-sort="descending"]::after { content: " ▼"; font-size: 0.7em; }
td.num, th.num { text-align: right; }
tr.row-total td { font-weight: 600; border-top: 2px solid var(--axis); }
tr.row-child td { background: var(--surface-2); font-size: 0.85rem; }
tr.row-child td:first-child { padding-left: 28px; }
.expander { font: inherit; background: none; border: 0; padding: 0 6px 0 0; color: var(--text-2); cursor: pointer; width: 20px; }
.share { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.share-bar { width: 80px; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; flex: none; }
.share-bar span { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
@media (max-width: 600px) { .share-bar { display: none; } .hide-sm { display: none; } }

/* Pour 100 € */
.per100 { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.per100 li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; font-size: 0.9rem; }
.per100 .bar { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.per100 .bar span { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.per100 .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Flux en listes (petits écrans) */
.flux-listes h3 { margin: 16px 0 8px; }

/* Méthodologie */
.prose { max-width: 75ch; }
.prose dt { font-weight: 600; margin-top: 12px; }
.prose dd { margin: 2px 0 0; color: var(--text-2); }
.sources-list { padding-left: 1.2em; }
.sources-list li { margin-bottom: 8px; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); margin-left: 6px; vertical-align: 1px; }

/* Pied de page */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 20px 0; font-size: 0.875rem; color: var(--text-2); }
.site-footer p { margin: 0 0 4px; }

@media print {
  .site-header { position: static; }
  .theme-toggle, .controls { display: none; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* Simulateur */
:root { --good-ink: #006300; --bad-ink: #b42323; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) { --good-ink: #0ca30c; --bad-ink: #e66767; } }
:root[data-theme="dark"] { --good-ink: #0ca30c; --bad-ink: #e66767; }

.sim-summary { position: sticky; top: var(--header-h, 96px); z-index: 4; background: var(--page); padding: 10px 0 12px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.sim-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.sim-kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.sim-kpi .kpi-label { margin-bottom: 2px; }
.sim-kpi .kpi-value { font-size: 1.35rem; }
.sim-kpi .kpi-sub { margin-top: 2px; }
.sim-actions { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 10px; font-size: 0.9rem; }
.btn { font: inherit; font-size: 0.875rem; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--axis); background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.delta-pos { color: var(--good-ink); font-weight: 600; }
.delta-neg { color: var(--bad-ink); font-weight: 600; }
.delta-nul { color: var(--muted); }
@media (max-width: 600px) {
  .sim-summary { position: static; }
  .sim-kpi .kpi-value { font-size: 1.15rem; }
}

.sim-list { list-style: none; margin: 0; padding: 0; }
.sim-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(120px, 1fr) 120px 110px 28px; gap: 6px 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.sim-row:last-child { border-bottom: 0; }
.sim-label { font-size: 0.925rem; min-width: 0; }
.sim-label small { display: block; color: var(--muted); font-size: 0.78rem; }
.sim-row input[type="range"] { width: 100%; accent-color: var(--btn); margin: 0; }
.sim-row input[type="number"] { font: inherit; font-size: 0.9rem; width: 100%; padding: 4px 6px; border: 1px solid var(--axis); border-radius: 6px; background: var(--surface); color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.sim-delta { font-size: 0.85rem; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sim-reset { font: inherit; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px; border-radius: 4px; }
.sim-reset:hover { color: var(--text); }
.sim-reset:disabled { visibility: hidden; }
.sim-row.is-changed .sim-label { font-weight: 600; }
@media (max-width: 720px) {
  .sim-row { grid-template-columns: minmax(0, 1fr) 120px 28px; }
  .sim-label { grid-column: 1 / -1; }
  .sim-row input[type="range"] { grid-column: 1 / -1; }
  .sim-delta { text-align: left; grid-column: 1; grid-row: 3; }
}
.sim-input { display: flex; align-items: center; gap: 4px; }
.sim-unit { font-size: 0.75rem; color: var(--muted); }
.cta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; }
.cta p { margin: 0; }
.btn:is(a) { display: inline-block; text-decoration: none; }
.sim-mini { display: none; }
@media (max-width: 600px) {
  .sim-mini { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--border); font-size: 0.9rem; font-weight: 600; text-align: center; box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08); }
  main:has(.sim-mini) { padding-bottom: 72px; }
}
