:root {
  color-scheme: light;
  --bg: #f4f4f5;
  --surface: #ffffff;
  --line: #e4e4e7;
  --text: #09090b;
  --muted: #71717a;
  --primary: #8a6d1c;
  --accent: #d4af37;
  --success: #15803d;
  --warning: #eab308;
  --danger: #b91c1c;
  --retirement: #f8fafc;
  --fi: #fef9c3;
  --barista: #dcfce7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

/* MA5 — Hygiene responsive : aucun controle de formulaire ne deborde son conteneur (garde-fou  */
/* anti-debordement horizontal, cf. docs/decisions/ux-mobile-ameliorations.md MA5).             */
input,
select,
textarea {
  max-width: 100%;
}

/* Champs en grille des cartes enfants : autoriser le retrecissement sous la largeur intrinseque */
/* (sinon les inputs `date`/`number` peuvent forcer un debordement dans une colonne etroite).    */
.child-card .field {
  min-width: 0;
}

.child-card .field input {
  min-width: 0;
  width: 100%;
}

.app-header {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 82px;
  padding: 18px clamp(16px, 4vw, 40px);
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* MA1 — Conteneur des actions secondaires. Desktop : les boutons s'affichent en ligne   */
/* (le bouton « ⋮ » est masque). Mobile (<= 600 px) : les boutons passent en menu         */
/* deroulant ouvert par le bouton « ⋮ » (cf. media query ci-dessous + events.js).         */
.header-tools {
  position: relative;
  display: flex;
  align-items: center;
}

.header-menu {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-menu-toggle {
  display: none;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  min-height: 38px;
  min-width: 40px;
  padding: 0 10px;
}

.eyebrow {
  color: var(--muted);
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  font-family: Outfit, sans-serif;
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 700;
}

h2 {
  font-size: 17px;
  font-weight: 600;
}

.tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 0 clamp(16px, 4vw, 40px);
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  cursor: pointer;
  min-height: 48px;
  padding: 0 14px;
  white-space: nowrap;
}

.tab.active {
  border-bottom-color: var(--primary);
  color: var(--primary);
  font-weight: 700;
}

.tab-small {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
}

.tab-small:hover {
  background: var(--bg);
  color: var(--text);
}

.tab-small.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.app-main {
  display: grid;
  gap: 18px;
  padding: 22px clamp(16px, 4vw, 40px) 40px;
}

.panel,
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.kpi-grid.compact {
  margin-top: 18px;
}

.kpi-card {
  display: grid;
  gap: 8px;
  min-height: 120px;
  padding: 16px;
}

.kpi-card span,
.kpi-card small,
.muted {
  color: var(--muted);
}

.kpi-card strong {
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

.kpi-card.success {
  border-top: 4px solid var(--success);
}

.kpi-card.warning {
  border-top: 4px solid var(--warning);
}

.kpi-card.danger {
  border-top: 4px solid var(--danger);
}

.kpi-card.neutral {
  border-top: 4px solid var(--accent);
}

.button {
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 6px;
  color: white;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
}

.button.secondary {
  background: white;
  color: var(--primary);
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.badge.success {
  background: #e7f4ed;
  color: var(--success);
}

.badge.neutral {
  background: #eef2f7;
  color: var(--muted);
}

.checks {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.check {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
}

.check span {
  font-size: 18px;
  font-weight: 800;
}

.check.success span {
  color: var(--success);
}

.check.danger span,
.negative {
  color: var(--danger);
}

.positive {
  color: var(--success);
}

.param-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) 280px;
}

.scenario-controls {
  display: grid;
  gap: 18px;
}

.scenario-controls-head {
  align-items: start;
  display: flex;
  gap: 18px;
  justify-content: space-between;
}

.section-note {
  color: var(--muted);
  margin: 6px 0 0;
}

.segmented-control {
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  gap: 2px;
  padding: 3px;
}

.segmented-control button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  min-height: 34px;
  padding: 0 14px;
}

.segmented-control button.active {
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
  color: var(--primary);
}

.feature-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.feature-card {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 132px;
  padding: 14px;
}

.feature-card.active {
  border-color: rgba(138, 109, 28, 0.5);
  box-shadow: inset 0 3px 0 var(--accent);
}

.feature-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.feature-title {
  font-weight: 750;
}

.feature-description,
.feature-summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.feature-summary {
  color: var(--text);
}

.feature-switch-input {
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.feature-switch {
  align-items: center;
  background: #cbd5e1;
  border-radius: 999px;
  display: inline-flex;
  height: 24px;
  padding: 2px;
  transition: background 0.15s ease-in-out;
  width: 44px;
}

.feature-switch span {
  background: white;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
  display: block;
  height: 20px;
  transition: transform 0.15s ease-in-out;
  width: 20px;
}

.feature-card.active .feature-switch {
  background: var(--primary);
}

.feature-card.active .feature-switch span {
  transform: translateX(20px);
}

.inactive-feature-panel {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.inactive-feature-panel p {
  color: var(--muted);
  margin: 6px 0;
}

.inactive-feature-panel small {
  color: var(--text);
  font-weight: 650;
}

.accordion {
  margin-bottom: 12px;
  padding: 0;
}

.accordion summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  font-size: 16px;
  font-weight: 700;
  justify-content: space-between;
  list-style: none;
  padding: 16px 18px;
}

.accordion-summary {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-left: 12px;
  text-align: right;
}

.accordion[open] summary {
  border-bottom: 1px solid var(--line);
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 18px;
}

.form-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 240px));
  padding: 0;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-weight: 650;
}

.field small {
  color: var(--muted);
  min-height: 18px;
}

.field-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-title {
  font-weight: 650;
  color: var(--text);
}

.tooltip-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  cursor: help;
  transition: color 0.15s ease-in-out;
}

.tooltip-trigger:hover,
.tooltip-trigger.open {
  color: var(--accent);
}

.tooltip-trigger .info-icon {
  width: 14px;
  height: 14px;
  stroke: var(--muted);
  stroke-width: 2.2;
  display: inline-block;
  vertical-align: middle;
  transition: stroke 0.15s ease-in-out;
}

.tooltip-trigger:hover .info-icon,
.tooltip-trigger.open .info-icon {
  stroke: var(--accent);
}

.tooltip-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: #0f172a;
  color: #f8fafc;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 240px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.15), 0 4px 6px -4px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.15s;
  z-index: 999;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.tooltip-trigger::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  border-width: 5px;
  border-style: solid;
  border-color: #0f172a transparent transparent transparent;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.15s;
  z-index: 999;
}

/* `.open` reproduit l'etat survol : pose au tap (tactile) via events.js, car le survol */
/* n'existe pas au doigt. Le survol reste actif sur desktop.                           */
.tooltip-trigger:hover::after,
.tooltip-trigger:hover::before,
.tooltip-trigger.open::after,
.tooltip-trigger.open::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.field input,
.field select,
.table-input {
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 10px;
  width: 100%;
}

input[type="range"] {
  accent-color: var(--primary);
}

.number-stack {
  display: grid;
  gap: 8px;
}

.allocation-section {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 14px;
  padding: 18px;
}

.allocation-header {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.allocation-header h3 {
  font-size: 15px;
  margin: 0;
}

.allocation-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.allocation-grid {
  padding: 0;
}

.allocation-readout {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.allocation-metric {
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 4px;
  min-height: 86px;
  padding: 10px;
}

.allocation-metric span,
.allocation-metric small {
  color: var(--muted);
}

.allocation-metric strong {
  font-size: 17px;
}

.allocation-chart {
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: block;
  height: auto;
  max-height: 210px;
  width: 100%;
}

.allocation-line {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.summary-rail {
  align-self: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 14px;
  position: sticky;
  top: 14px;
}

/* MA2 — Conteneur des 3 KPI deterministes. Desktop : empiles (grille). Mobile : barre */
/* compacte horizontale (cf. media query <= 600 px + parametres-et-depenses.md §7).      */
.summary-rail__kpis {
  display: grid;
  gap: 8px;
}

/* MA4 — Resume de tete (survie / ruine) remonte pres de l'action. */
.mc-headline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mc-headline > div {
  display: flex;
  flex-direction: column;
}

.mc-headline span {
  color: var(--muted);
  font-size: 12px;
}

.mc-headline strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.mc-headline--success { border-left: 4px solid var(--success); }
.mc-headline--warning { border-left: 4px solid var(--warning); }
.mc-headline--danger { border-left: 4px solid var(--danger); }

.metric-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.metric-line span {
  color: var(--muted);
}

.summary-divider {
  border-top: 1px solid var(--line);
  margin: 4px 0;
}

.metric-line strong,
td,
th {
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* min-width:0 : indispensable pour qu'en contexte flex/grid le cadre RETRECISSE et que le         */
  /* defilement horizontal s'active ici (sinon un tableau large deborde la page au lieu de defiler). */
  min-width: 0;
}

.table-wrap-simple {
  overflow-x: visible;
}

table {
  border-collapse: collapse;
  min-width: 980px;
  width: 100%;
}

.expenses-table-simple {
  min-width: 0;
}

.expenses-table-simple td:first-child {
  display: grid;
  gap: 3px;
}

.expenses-table-simple td:first-child small {
  color: var(--muted);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
}

th {
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  text-transform: uppercase;
  z-index: 1;
}

.percent-input {
  align-items: center;
  display: flex;
  gap: 4px;
}

.percent-input .table-input {
  width: 70px;
}

/* Figer la première colonne (Age) */
table th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  border-right: 2px solid var(--line);
}

table td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  border-right: 2px solid var(--line);
}

.phase-fi td {
  background: var(--fi);
}

.phase-fi td:first-child {
  background: var(--fi);
}

.phase-barista td {
  background: var(--barista);
}

.phase-barista td:first-child {
  background: var(--barista);
}

.phase-retraite td {
  background: var(--retirement);
}

.phase-retraite td:first-child {
  background: var(--retirement);
}

.chart {
  display: block;
  height: auto;
  max-height: 360px;
  width: 100%;
}

.chart-axis,
.chart-axis-zero {
  stroke: #94a3b8;
  stroke-width: 1;
}

.chart-axis-zero {
  stroke-dasharray: 4 4;
}

.chart-band {
  fill: var(--accent);
  opacity: 0.12;
}

.chart-wealth {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-width: 4;
}

.chart-wealth-regime {
  stroke-dasharray: 10 5;
  stroke-width: 3;
}

.chart-threshold {
  fill: none;
  stroke: var(--danger);
  stroke-dasharray: 8 6;
  stroke-width: 2.5;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
}

.phase-band-fi {
  fill: #fff9c4;
  opacity: 0.75;
}

.phase-band-barista {
  fill: #bbf7d0;
  opacity: 0.68;
}

.phase-band-retirement {
  fill: #e3f2fd;
  opacity: 0.9;
}

.engines-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metrics-list {
  display: grid;
  gap: 12px;
}

.muted-box {
  background: #fafafa;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 16px;
  color: var(--muted);
}

.muted-box p {
  margin: 0 0 8px;
}

.muted-box p:last-child {
  margin-bottom: 0;
}

.highlight-gold {
  background: var(--fi);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 4px 0;
}

.intro-banner {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  background: var(--fi);
  border-bottom: 1px solid var(--accent);
  padding: 14px clamp(16px, 4vw, 40px);
}

.intro-banner__body {
  flex: 1;
}

.intro-banner__body p {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

.intro-banner__body p:last-child {
  margin-bottom: 0;
}

.intro-banner__title {
  font-weight: 600;
  font-size: 14px;
}

.intro-banner button {
  flex-shrink: 0;
  white-space: nowrap;
}

.app-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 16px clamp(16px, 4vw, 40px);
}

.disclaimer {
  margin: 0;
  max-width: 900px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

@media (max-width: 980px) {
  .intro-banner {
    flex-direction: column;
  }

  .kpi-grid,
  .checks,
  .param-layout,
  .form-grid,
  .allocation-readout,
  .feature-grid,
  .engines-layout {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .scenario-controls-head {
    display: grid;
  }

  .summary-rail {
    position: static;
    /* Mobile : remonter le bandeau (KPI + bouton « Lancer le balayage » Monte Carlo) */
    /* en tete de la page Parametres, sinon il tombe au milieu des accordeons.        */
    order: -1;
  }

  /* Onglets de navigation colles en haut : toujours atteignables au defilement. */
  .tabs {
    position: sticky;
    top: 0;
    z-index: 20;
  }

  /* En-tetes de tableau colles JUSTE SOUS la barre d'onglets (~48px de haut),  */
  /* sinon ils disparaitraient derriere elle au defilement vertical.            */
  th {
    top: 48px;
  }
}

/* ------------------------------------------------------------------ */
/* Palier « téléphone » (~600px et moins) — réglages fins mobile.      */
/* Quick wins UX : ces règles n'affectent AUCUN calcul, uniquement     */
/* l'affichage. Le palier 980px ci-dessus reste pour les tablettes.    */
/* ------------------------------------------------------------------ */
@media (max-width: 600px) {
  /* 1. Champs en 16px : empêche le zoom automatique d'iOS au focus    */
  /*    (tout champ < 16px fait sauter la page quand on tape).         */
  .field input,
  .field select,
  .table-input {
    font-size: 16px;
  }

  /* 2. Donner de l'air : titres et espacements resserrés, cartes KPI  */
  /*    qui ne réservent plus 120px chacune en pile verticale.         */
  h1 {
    font-size: 20px;
  }

  .app-main {
    gap: 14px;
    padding-top: 16px;
    padding-bottom: 28px;
  }

  .panel {
    padding: 14px;
  }

  .kpi-grid {
    gap: 10px;
  }

  .kpi-card {
    min-height: auto;
  }

  /* 3. Indiquer que la barre d'onglets défile : dégradé de bord droit */
  /*    + scrollbar masquée pour un défilement tactile propre.         */
  .tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  /* 4. Header compact : on récupère la hauteur perdue (82px) en haut   */
  /*    d'écran ; les actions s'étalent sur toute la largeur.          */
  .app-header {
    min-height: 0;
    padding: 14px 16px;
    gap: 10px;
  }

  /* MA1 — sur une seule rangee : selecteur de methode a gauche, bouton « ⋮ » a droite. */
  .header-actions {
    width: 100%;
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .header-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Les 3 actions secondaires basculent en menu deroulant (cache tant que non ouvert). */
  .header-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    min-width: 180px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 30;
    display: none;
  }

  .header-tools[data-open="true"] .header-menu {
    display: flex;
  }

  .header-menu .button {
    width: 100%;
    text-align: left;
  }

  /* MA2 — Cartes de fonctionnalites en liste compacte : on retire la description longue  */
  /* et la hauteur reservee, pour ne pas repousser KPI et sections plus bas.               */
  .feature-grid {
    gap: 8px;
  }

  .feature-card {
    min-height: auto;
    padding: 10px 12px;
    gap: 10px;
  }

  .feature-description {
    display: none;
  }

  /* MA2 — Bloc deterministe du resume en barre compacte horizontale (libelle au-dessus    */
  /* de la valeur). Le bloc Monte Carlo eventuel reste empile sous .summary-rail__kpis.     */
  .summary-rail {
    padding: 12px;
  }

  .summary-rail__kpis {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
  }

  .summary-rail__kpis .metric-line {
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0;
    justify-content: flex-start;
  }

  .summary-rail__kpis .metric-line span {
    font-size: 11px;
  }
}

/* ------------------------------------------------------------------ */
/* MA3 — Tableau Depenses (mode simple) en CARTES sur telephone.       */
/* Cf. docs/specs/ux/parametres-et-depenses.md §8.1. Presentation      */
/* pure : meme DOM et memes data-expense-* (edition au doigt intacte), */
/* seul l'affichage bascule de lignes de tableau a cartes empilees.    */
/* Le mode avance garde son tableau a defilement horizontal.           */
/* ------------------------------------------------------------------ */
@media (max-width: 600px) {
  .table-wrap-simple .expenses-table-simple,
  .table-wrap-simple .expenses-table-simple thead,
  .table-wrap-simple .expenses-table-simple tbody,
  .table-wrap-simple .expenses-table-simple tr {
    display: block;
    width: 100%;
  }

  /* En-tetes de colonnes inutiles en mode cartes. */
  .table-wrap-simple .expenses-table-simple thead {
    display: none;
  }

  /* Une ligne = une carte. */
  .table-wrap-simple .expenses-table-simple tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }

  /* Cellule titre (poste + frequence/periode) : pleine largeur, sans le traitement    */
  /* « colonne figee » herite des tableaux ; un filet souligne le titre.                */
  .table-wrap-simple .expenses-table-simple td:first-child {
    display: grid;
    gap: 3px;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 8px;
    margin-bottom: 6px;
  }

  /* Cellules valeur : libelle (data-label) a gauche, controle a droite. */
  .table-wrap-simple .expenses-table-simple td:not(:first-child) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 0;
    padding: 4px 0;
  }

  .table-wrap-simple .expenses-table-simple td:not(:first-child)::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
  }

  .table-wrap-simple .expenses-table-simple td .table-input {
    width: 130px;
    text-align: right;
  }
}

/* ------------------------------------------------------------------ */
/* MA4 — Monte Carlo en deux niveaux sur telephone : l'action          */
/* « Lancer la simulation » reste COLLEE en tete (sous la barre        */
/* d'onglets) pendant le defilement. Cf. docs/specs/ux/monte-carlo.md  */
/* §2bis. Presentation pure — aucune regle de calcul.                  */
/* ------------------------------------------------------------------ */
@media (max-width: 600px) {
  .monte-carlo-panel .mc-action-bar {
    position: sticky;
    top: 48px; /* juste sous la barre d'onglets collee (~48px) */
    z-index: 15;
    margin: -14px -14px 12px; /* le panel a 14px de padding en mobile : barre bord a bord */
    padding: 12px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    gap: 8px;
  }

  /* En-tetes des tableaux de resultats colles SOUS la barre d'action (48px onglets +    */
  /* ~48px barre d'action), pour ne pas disparaitre derriere elle au defilement.          */
  .monte-carlo-panel .table-wrap th {
    top: 96px;
  }

  /* Tableaux de resultats MC (survie, percentiles, balayage) : peu de colonnes -> on les fait   */
  /* TENIR dans la largeur (le texte passe a la ligne) au lieu de forcer 980px + defilement.      */
  .monte-carlo-panel .table-wrap table {
    min-width: 0;
  }
}

/* ------------------------------------------------------------------ */
/* M1 — Tableau de projection en mode compact sur telephone.          */
/* Cf. docs/specs/ux/projection.md §9. On masque les colonnes non     */
/* essentielles par sous-vue (classe `proj-<sousvue>` posee sur le    */
/* <table> dans src/ui/views/projection.js). Les positions ci-dessous */
/* DOIVENT refleter l'ordre des colonnes de projection.js.            */
/* Repli « tableau complet » : ecran large ou telephone en paysage    */
/* (> 600 px). Le detail complet au tap viendra en phase M2.          */
/* Presentation pure — aucune regle de calcul.                        */
/* ------------------------------------------------------------------ */
@media (max-width: 600px) {
  /* Le tableau compact tient dans la largeur (annule le min-width 980px). */
  table[class^="proj-"] {
    min-width: 0;
  }

  /* Synthese Globale — garder Age(1), Phase(3), Patrimoine fin(9), Ratio FI(10). */
  .proj-summary :is(th, td):is(
    :nth-child(2), :nth-child(4), :nth-child(5),
    :nth-child(6), :nth-child(7), :nth-child(8)
  ) {
    display: none;
  }

  /* Revenus & IR — garder Age(1), Revenu net(5), Base IR apres PER(12), Impot IR(13). */
  .proj-revenues :is(th, td):is(
    :nth-child(2), :nth-child(3), :nth-child(4), :nth-child(6),
    :nth-child(7), :nth-child(8), :nth-child(9), :nth-child(10), :nth-child(11)
  ) {
    display: none;
  }

  /* Details Freelance — garder Age(1), CA(4), Total Net Freelance(10). */
  .proj-freelance :is(th, td):is(
    :nth-child(2), :nth-child(3), :nth-child(5),
    :nth-child(6), :nth-child(7), :nth-child(8), :nth-child(9)
  ) {
    display: none;
  }

  /* Logement & Immo — garder Age(1), Cout Logement Total(9). */
  .proj-housing :is(th, td):is(
    :nth-child(2), :nth-child(3), :nth-child(4), :nth-child(5),
    :nth-child(6), :nth-child(7), :nth-child(8)
  ) {
    display: none;
  }

  /* Retraite & Agirc — garder Age(1), Vos trimestres(4), Pension Foyer Nette(10). */
  .proj-retirement :is(th, td):is(
    :nth-child(2), :nth-child(3), :nth-child(5),
    :nth-child(6), :nth-child(7), :nth-child(8), :nth-child(9)
  ) {
    display: none;
  }

  /* Enveloppes — garder Age(1), PEA(4), CTO(5), PER(6). */
  .proj-envelopes :is(th, td):is(
    :nth-child(2), :nth-child(3), :nth-child(7), :nth-child(8), :nth-child(9),
    :nth-child(10), :nth-child(11), :nth-child(12), :nth-child(13)
  ) {
    display: none;
  }

  /* Details Depenses — colonnes de postes dynamiques : garder Age(1) et Total (dernier). */
  .proj-expenses :is(th, td):not(:first-child):not(:last-child) {
    display: none;
  }

  /* ---- M2 — detail d'une ligne au tap (cf. ux/projection.md §9, accordeon). ---- */
  /* Affordance : lignes cliquables + chevron sur la colonne Age, inverse a l'ouverture. */
  table[class^="proj-"] tbody tr:not(.proj-row-detail) {
    cursor: pointer;
  }

  table[class^="proj-"] tbody tr:not(.proj-row-detail) td:first-child::after {
    content: " ⌄";
    color: var(--muted);
  }

  .proj-row-open td:first-child::after {
    content: " ⌃";
  }

  /* La ligne de detail occupe toute la largeur : on annule le figeage de 1re colonne. */
  .proj-row-detail td {
    position: static;
    background: #fafafa;
    padding: 10px 12px;
    border-bottom: 2px solid var(--line);
  }

  .proj-detail-list {
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 14px;
  }

  .proj-detail-list > div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 4px;
  }

  .proj-detail-list dt {
    color: var(--muted);
    font-size: 12px;
  }

  .proj-detail-list dd {
    margin: 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
  }
}

/* Securite : si l'ecran s'elargit (paysage / bureau) avec un detail ouvert, ne pas l'afficher. */
@media (min-width: 601px) {
  .proj-row-detail {
    display: none;
  }
}

/* FAQ Drawer backdrop */
.faq-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(9, 9, 11, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-in-out;
  z-index: 1000;
}

.faq-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* FAQ Drawer panel */
.faq-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 460px;
  max-width: 100%;
  height: 100vh;
  background: var(--surface);
  box-shadow: -4px 0 24px rgba(9, 9, 11, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1001;
}

.faq-drawer.open {
  transform: translateX(0);
}

.faq-drawer__header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 20px 24px;
}

.faq-drawer__header h2 {
  font-family: Outfit, sans-serif;
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.faq-drawer__close {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  padding: 4px;
  transition: color 0.15s;
}

.faq-drawer__close:hover {
  color: var(--text);
}

.faq-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* FAQ Items styling using details/summary */
.faq-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.faq-item:hover {
  border-color: rgba(138, 109, 28, 0.3);
}

.faq-item[open] {
  border-color: rgba(138, 109, 28, 0.5);
  box-shadow: 0 4px 12px rgba(138, 109, 28, 0.05);
}

.faq-item summary {
  align-items: center;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  font-weight: 600;
  justify-content: space-between;
  list-style: none;
  padding: 16px 20px;
  user-select: none;
}

/* Hide default marker in Chrome/Safari/Firefox */
.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-item summary::after {
  content: "+";
  font-family: monospace;
  font-size: 18px;
  color: var(--muted);
  transition: transform 0.15s;
}

.faq-item[open] summary::after {
  content: "−";
}

.faq-content {
  background: var(--bg);
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 16px 20px;
}

.faq-content p {
  margin: 0 0 12px;
}

.faq-content p:last-child {
  margin-bottom: 0;
}

.faq-content ul {
  margin: 0;
  padding-left: 20px;
}

.faq-content li {
  margin-bottom: 8px;
}

.faq-content li:last-child {
  margin-bottom: 0;
}

/* Highlight effect for target sections */
.faq-item.highlight {
  animation: faq-highlight-pulse 2s ease-in-out;
}

@keyframes faq-highlight-pulse {
  0% {
    background-color: var(--surface);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.2);
  }
  50% {
    background-color: rgba(212, 175, 55, 0.1);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.4);
  }
  100% {
    background-color: var(--surface);
    border-color: var(--line);
    box-shadow: none;
  }
}
