/* Thèmes : toutes les couleurs passent par des variables, [data-theme] est posé sur <html>. */
:root,
[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-halo: rgba(79, 70, 229, .09);
  --surface: #ffffff;
  --surface-alt: #f5f6fb;
  --text: #171a2c;
  --text-muted: #5a6078;
  --heading: #171a2c;
  --border: #e6e8f2;
  --field-border: #d9dcea;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0fe;
  --hero: linear-gradient(135deg, #4f46e5, #2563eb);
  --hero-text: #ffffff;
  --focus: #4f46e5;
  --danger: #c0262d;
  --warn-bg: #fff5e8;
  --warn-border: #f5c88a;
  --warn-text: #7a3b00;
  --note-bg: #f5f6fb;
  --shadow: 0 1px 2px rgba(23, 26, 44, .04), 0 8px 24px rgba(23, 26, 44, .06);
  --chart-gain: #4f46e5;
  --chart-cost: #ea580c;
  --chart-grid: #eceef6;
  --chart-text: #5a6078;
  --chart-ring: #ffffff;
}

[data-theme="dark"] {
  --bg: #0c1020;
  --bg-halo: rgba(116, 121, 240, .14);
  --surface: #141b2e;
  --surface-alt: #1b2339;
  --text: #e8eaf6;
  --text-muted: #a2a9c2;
  --heading: #f2f3fb;
  --border: #262f4a;
  --field-border: #323c5c;
  --accent: #8d91f6;
  --accent-text: #0c1020;
  --accent-soft: #252c4d;
  --hero: linear-gradient(135deg, #4f46e5, #2563eb);
  --hero-text: #ffffff;
  --focus: #a5a8fa;
  --danger: #ff9b9b;
  --warn-bg: #3a2a12;
  --warn-border: #8a5a1f;
  --warn-text: #ffd9a3;
  --note-bg: #1b2339;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  --chart-gain: #7479f0;
  --chart-cost: #e06c1c;
  --chart-grid: #232c46;
  --chart-text: #a2a9c2;
  --chart-ring: #141b2e;
}

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

html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

/* Coquille : la page ne défile jamais, seule la zone centrale le peut. La pilule garde sa
   propre bande, et aucun contenu ne passe plus dessous. */
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  margin: 0;
  background: radial-gradient(900px 420px at 15% -10%, var(--bg-halo), transparent 70%), var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* Pilule de navigation : toujours visible, jamais masquée */
.pilule {
  flex: none;
  align-self: center;
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.pilule-lien {
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.pilule-lien:hover { background: var(--accent-soft); color: var(--text); }
.pilule-lien.actif { color: var(--accent-text); font-weight: 600; background: var(--accent); }
.pilule-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.pilule-bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--heading);
  cursor: pointer;
}
.pilule-bouton:hover { background: var(--accent-soft); }
/* Bascule FR | EN : la langue active en relief, comme un petit segment. */
.pilule-langue {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  height: 28px;
  padding: 2px;
  border-radius: 999px;
  background: var(--accent-soft);
  text-decoration: none;
}
.langue { padding: 3px 7px; border-radius: 999px; color: var(--text-muted); font-size: 11.5px; font-weight: 600; letter-spacing: .02em; }
.langue-active { background: var(--surface); color: var(--heading); box-shadow: 0 1px 2px rgba(23, 26, 44, .15); }
.pilule-langue:hover .langue:not(.langue-active) { color: var(--text); }
.visuellement-cache { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icone { width: 18px; height: 18px; }
.icone-soleil { display: none; }
[data-theme="dark"] .icone-lune { display: none; }
[data-theme="dark"] .icone-soleil { display: block; }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
.segmente input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Page */
.page { flex: 1; min-height: 0; width: 100%; overflow-y: auto; padding: 8px 16px 16px; }
.entete { margin-bottom: 16px; }
.marque { margin: 0; color: var(--text-muted); font-size: 14px; letter-spacing: .02em; }
h1 { margin: 0; color: var(--heading); font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.page-calcul .entete { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 20px; max-width: 1400px; margin: 0 auto 8px; }
.page-calcul h1 { font-size: 21px; }

.calculatrice {
  display: grid;
  grid-template-columns: minmax(0, 56fr) minmax(0, 44fr);
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}
.carte {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.panneau-tete { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.panneau-tete .groupe { font-size: 14px; }
.groupe { margin: 0 0 2px; color: var(--heading); font-size: 15px; font-weight: 650; letter-spacing: -.005em; line-height: 1.3; }
.panneau-tete .groupe { margin: 0; }

/* Sections de saisie : une carte numérotée par étape */
.formulaire { display: flex; flex-direction: column; gap: 16px; }
.section { padding: 8px 16px 2px; }
.sous-titre { margin: 0 0 4px; color: var(--text-muted); font-size: 12.5px; line-height: 1.35; }

/* Champs */
.champ { padding: 5px 0; border-top: 1px solid var(--border); }
.sous-titre + .champ, .groupe + .champ, .champ:first-child { border-top: 0; padding-top: 2px; }
.champ label { display: block; color: var(--text); font-size: 13.5px; line-height: 1.35; }
.ligne { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.valeur { display: flex; gap: 6px; }
.valeur .nombre { width: 84px; }
/* Montants en euros : la case laisse lire « e.g. 60 000 » comme « ex. 60 000 ». */
[data-roi-form="cout"] .valeur .nombre { width: 124px; }
.valeur select { width: 108px; }
.champ-date input { width: 170px; }
.facultatif { color: var(--text-muted); }
input[type="text"], input[type="date"], select {
  width: 100%;
  height: 32px;
  padding: 4px 9px;
  border: 1px solid var(--field-border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:hover:not(:disabled), input[type="date"]:hover, select:hover { border-color: var(--accent); }
input[type="text"]:focus, input[type="date"]:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
  cursor: pointer;
}
input::placeholder { color: var(--text-muted); opacity: .65; }
input[type="text"]:disabled { opacity: .55; cursor: not-allowed; }

.nombre { position: relative; }
.nombre input { padding-right: 24px; }
.fleches { position: absolute; top: 3px; right: 3px; bottom: 3px; display: flex; flex-direction: column; gap: 1px; width: 18px; }
.fleches button {
  flex: 1;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 7px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.fleches button:hover:not(:disabled) { background: var(--accent); color: var(--accent-text); }
.fleches button:disabled { opacity: .5; cursor: not-allowed; }

.curseur {
  --piste: linear-gradient(to right, var(--accent) var(--position, 0%), var(--border) var(--position, 0%));
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 20px;
  margin: 2px 0 0;
  background: transparent;
  cursor: pointer;
}
.curseur::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--piste); }
.curseur::-moz-range-track { height: 6px; border-radius: 3px; background: var(--piste); }
.curseur::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(23, 26, 44, .3);
  cursor: grab;
  transition: transform .12s;
}
.curseur:hover::-webkit-slider-thumb { transform: scale(1.12); }
.curseur::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(23, 26, 44, .3);
  cursor: grab;
}
.curseur:active::-webkit-slider-thumb { cursor: grabbing; }
.curseur:active::-moz-range-thumb { cursor: grabbing; }

.erreur-champ { margin: 2px 0 0; min-height: 0; color: var(--danger); font-size: 12px; line-height: 1.3; }
.erreur-champ:empty { display: none; }

/* Bascule Mois / Année */
.segmente { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-alt); }
.segmente label { position: relative; margin: 0; cursor: pointer; }
.segmente input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmente span { display: block; padding: 3px 12px; border-radius: 7px; color: var(--text-muted); font-size: 13px; font-weight: 500; transition: background .15s, color .15s; }
.segmente input:checked + span { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(23, 26, 44, .15); }

/* Résultat */
.resume { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: stretch; gap: 8px; margin-bottom: 8px; }
.kpi { display: flex; flex-direction: column; justify-content: center; min-width: 170px; max-width: 230px; padding: 10px 16px; border-radius: 12px; background: var(--hero); color: var(--hero-text); }
.kpi-valeur { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.kpi-legende { margin: 1px 0 0; font-size: 12px; line-height: 1.3; }
.kpi .kpi-legende { opacity: .9; }
.kpi-date { margin: 8px 0 0; padding-top: 7px; border-top: 1px solid rgba(255, 255, 255, .3); font-size: 12px; line-height: 1.35; }
.kpi-date strong { font-size: 13px; font-weight: 650; }
.chiffres { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 0; }
.chiffres > div { padding: 5px 12px; border-radius: 10px; background: var(--surface-alt); }
.chiffres dt, .chiffres .kpi-legende { margin: 0; color: var(--text-muted); font-size: 12px; line-height: 1.3; }
.chiffres dd { margin: 1px 0 0; font-size: 14px; font-weight: 600; line-height: 1.3; }
.graphique svg { display: block; width: 100%; height: auto; font-family: inherit; }
.graphique .repere { font-size: 13px; }
.alerte {
  margin: 0 0 8px;
  padding: 5px 10px;
  font-size: 13px;
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
}
.invite, .lecture { margin: 0 0 6px; color: var(--text-muted); font-size: 13px; line-height: 1.4; }
.lecture { color: var(--text); }

/* Une seule ligne sur ordinateur : la bande déborde un peu sur la marge du panneau. */
.avertissement {
  margin: 8px -8px 0;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--note-bg);
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: -.01em;
  text-align: center;
  line-height: 1.35;
}
.avertissement p { margin: 0; }

/* Vue Coût */
.entete .rappel { max-width: 560px; margin: 0; }
.rappel { margin: 0 0 8px; padding: 6px 10px; border-radius: 10px; background: var(--surface-alt); color: var(--text-muted); font-size: 12px; line-height: 1.35; }
.rappel p { margin: 0; display: inline; }
.rappel a { margin-left: 6px; white-space: nowrap; }
.rappel:empty { display: none; }
.rappel a, .invite a { color: var(--accent); }
.salaires { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 10px; }
.salaires .champ { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 2px 8px; padding: 0 0 6px; border: 0; }
.salaires label { font-size: 13px; white-space: nowrap; }
.salaires .erreur-champ { grid-column: 1 / -1; }
.salaires .reglage { display: block; }
.chiffres .kpi-valeur-2 { margin: 1px 0 0; color: var(--heading); font-size: 16px; font-weight: 650; letter-spacing: -.01em; line-height: 1.2; }

/* Pied de page et pages de texte */
.pied { flex: none; padding: 3px 16px 5px; font-size: 12px; }
.pied nav { display: flex; flex-wrap: wrap; gap: 2px 14px; justify-content: center; }
.pied a { color: var(--text-muted); text-decoration: none; }
.pied a:hover, .pied a:focus-visible { color: var(--accent); text-decoration: underline; }
.texte { max-width: 760px; margin: 0 auto; line-height: 1.65; font-size: 16px; }
.texte h2 { margin: 28px 0 6px; color: var(--heading); font-size: 20px; }
.texte p { margin: 0 0 12px; }
.texte a { color: var(--accent); }
.texte .avertissement { margin: 16px 0 8px; padding: 6px 10px; font-size: 12.5px; letter-spacing: 0; text-align: left; }

/* Écran large : tout tient dans la hauteur, le graphique prend la place restante. */
@media (min-width: 960px) {
  .page-calcul { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 6px; }
  .page-calcul .calculatrice { flex: 1; min-height: 0; width: 100%; align-items: stretch; }
  .page-calcul .entete { width: 100%; }
  .formulaire { min-height: 0; overflow-y: auto; }
  .panneau { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
  #resultat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .graphique { position: relative; flex: 1; min-height: 170px; }
  .graphique svg { position: absolute; inset: 0; height: 100%; }
}

/* Écran étroit : une colonne, seule la zone centrale défile. */
@media (max-width: 959px) {
  .calculatrice { grid-template-columns: minmax(0, 1fr); }
  .salaires { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .champ-date input { width: 100%; }
  .pilule-lien { padding: 5px 9px; }
}

@media print {
  body { display: block; height: auto; overflow: visible; }
  .page { overflow: visible; }
  .pilule, .pied { display: none; }
}

@media (max-width: 560px) {
  .ligne { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  /* Téléphone : la pilule tient dans 360 px avec la bascule FR | EN. */
  .pilule { gap: 2px; padding: 5px 6px; }
  .pilule-lien { padding: 5px 7px; }
  .pilule-sep { margin: 0 2px; }
  .langue { padding: 3px 5px; }
}
