/* CRM financier — feuille de style unique, sans framework.
 *
 * Mise en page : barre laterale de navigation groupee (vue d ensemble, planifier, outils, donnees),
 * contenu sur une colonne de cartes ; sous 980px, la barre devient un bandeau defilant en haut.
 * Couleur : neutres legerement teintes de vert sapin, un seul accent bleu encre (inspire du billet
 * de 5 $), et trois couleurs d etat (vert, ambre, rouge) reservees au sens.
 * Typo : Bricolage Grotesque pour les titres et les grands chiffres, Atkinson Hyperlegible pour le
 * texte (concue pour la lisibilite, utile a qui lit en langue seconde), IBM Plex Mono pour les colonnes.
 */
:root {
  --fond: #f2f4f1;
  --surface: #ffffff;
  --surface-2: #eceff0;
  --bordure: #d6ddd8;
  --texte: #15201c;
  --texte-doux: #46564f;
  --texte-faible: #6f7f77;
  --accent: #1f4e8c;
  --accent-texte: #ffffff;
  --accent-fond: rgba(31, 78, 140, .1);
  --vert: #1d7f45;  --vert-fond: rgba(29, 127, 69, .1);
  --orange: #a35c00; --orange-fond: rgba(163, 92, 0, .1);
  --rouge: #c0362c; --rouge-fond: rgba(192, 54, 44, .1);
  --bleu: var(--accent); --bleu-fond: var(--accent-fond);
  --violet: #6b4fb3;
  --rayon: 12px;
  --ombre: 0 1px 2px rgba(21, 32, 28, .05), 0 6px 18px -10px rgba(21, 32, 28, .18);
  --titre: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --police: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #0f1513; --surface: #161d1a; --surface-2: #1d2622; --bordure: #2b3631;
    --texte: #e6ece8; --texte-doux: #a3b2aa; --texte-faible: #74847c;
    --accent: #7eaaf0; --accent-texte: #0c1a2e; --accent-fond: rgba(126, 170, 240, .14);
    --vert: #5bc48a; --vert-fond: rgba(91, 196, 138, .13);
    --orange: #e7a94a; --orange-fond: rgba(231, 169, 74, .13);
    --rouge: #f0817a; --rouge-fond: rgba(240, 129, 122, .13);
    --violet: #b3a1ee;
    --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 22px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #0f1513; --surface: #161d1a; --surface-2: #1d2622; --bordure: #2b3631;
  --texte: #e6ece8; --texte-doux: #a3b2aa; --texte-faible: #74847c;
  --accent: #7eaaf0; --accent-texte: #0c1a2e; --accent-fond: rgba(126, 170, 240, .14);
  --vert: #5bc48a; --vert-fond: rgba(91, 196, 138, .13);
  --orange: #e7a94a; --orange-fond: rgba(231, 169, 74, .13);
  --rouge: #f0817a; --rouge-fond: rgba(240, 129, 122, .13);
  --violet: #b3a1ee;
  --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 22px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--fond); color: var(--texte); font-family: var(--police);
  font-size: 15.5px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-family: var(--titre); font-weight: 650; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.08rem; }
h3 { font-size: .97rem; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* ---------- Coque : barre laterale + contenu ---------- */
.coque { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.laterale {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  border-right: 1px solid var(--bordure); background: var(--surface);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
}
.marque { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.marque .sceau {
  width: 34px; height: 34px; border-radius: 9px; flex: none; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-texte); font-family: var(--titre); font-weight: 750; font-size: 1.05rem;
}
.marque strong { display: block; font-family: var(--titre); font-size: 1.02rem; letter-spacing: -.015em; }
.marque span { display: block; font-size: .74rem; color: var(--texte-faible); line-height: 1.3; }

nav.onglets { display: flex; flex-direction: column; gap: 2px; }
nav.onglets .groupe {
  margin: 12px 8px 4px; font-size: .68rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--texte-faible);
}
nav.onglets .groupe:first-child { margin-top: 0; }
nav.onglets button {
  background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  color: var(--texte-doux); font-size: .9rem; font-weight: 500; white-space: nowrap;
}
nav.onglets button:hover { background: var(--surface-2); color: var(--texte); }
nav.onglets button[aria-current="page"] { background: var(--accent-fond); color: var(--accent); font-weight: 700; }
.pied-lateral { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; }
.theme { display: flex; gap: 4px; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.theme button { flex: 1; border: 0; background: none; padding: 5px 0; border-radius: 7px; font-size: .74rem;
  color: var(--texte-doux); cursor: pointer; }
.theme button[aria-pressed="true"] { background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }

.enveloppe { max-width: 1180px; width: 100%; margin: 0 auto; padding: 0 28px 80px; }
.entete-vue { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 26px 0 4px; }
.entete-vue p { margin: 4px 0 0; color: var(--texte-doux); font-size: .92rem; max-width: 62ch; }

@media (max-width: 980px) {
  .coque { display: block; }
  .laterale {
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; height: auto; flex-direction: row;
    align-items: center; padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--bordure);
  }
  .marque span, .pied-lateral, nav.onglets .groupe { display: none; }
  nav.onglets { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  nav.onglets::-webkit-scrollbar { display: none; }
  .enveloppe { padding: 0 16px 80px; }
}

section.vue { display: none; padding-top: 18px; }
section.vue.active { display: block; animation: apparait .22s ease; }
@keyframes apparait { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grille { display: grid; gap: 14px; align-items: start; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .g3, .g4, .g-2-1 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grille { grid-template-columns: 1fr !important; } }

/* ---------- Cartes ---------- */
.carte {
  background: var(--surface); border: 1px solid var(--bordure);
  border-radius: var(--rayon); padding: 18px; box-shadow: var(--ombre); min-width: 0;
}
.carte > header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.carte h2, .carte h3 { display: flex; align-items: center; gap: 8px; }
.sous { color: var(--texte-faible); font-size: .8rem; font-weight: 400; }

.kpi { box-shadow: none; }
.kpi .valeur { font-family: var(--titre); font-size: 1.9rem; font-weight: 650; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi .etiquette { color: var(--texte-doux); font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.kpi .note { color: var(--texte-faible); font-size: .8rem; }

/* ---------- Badges & feux ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; letter-spacing: .02em; border: 1px solid transparent; }
.badge.vert { background: var(--vert-fond); color: var(--vert); }
.badge.orange { background: var(--orange-fond); color: var(--orange); }
.badge.rouge { background: var(--rouge-fond); color: var(--rouge); }
.badge.bleu { background: var(--accent-fond); color: var(--accent); }
.badge.neutre { background: var(--surface-2); color: var(--texte-doux); border-color: var(--bordure); }
.point { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.feu { display: flex; align-items: center; gap: 14px; }
.feu .lampe { width: 52px; height: 52px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 1.4rem; }
.feu.vert .lampe { background: var(--vert-fond); box-shadow: inset 0 0 0 2px var(--vert); }
.feu.orange .lampe { background: var(--orange-fond); box-shadow: inset 0 0 0 2px var(--orange); }
.feu.rouge .lampe { background: var(--rouge-fond); box-shadow: inset 0 0 0 2px var(--rouge); }

/* ---------- Conseiller ---------- */
.conseiller { border-color: color-mix(in srgb, var(--accent) 30%, var(--bordure)); }
.conseiller .texte { font-size: 1.02rem; line-height: 1.65; white-space: pre-wrap; max-width: 75ch; }
.zone-question { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.zone-question input { flex: 1 1 320px; }
.suggestions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.suggestions button { font-size: .8rem; padding: 5px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--bordure); color: var(--texte-doux); cursor: pointer; }
.suggestions button:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Bienvenue ---------- */
.bienvenue { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center;
  background: var(--accent-fond); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--rayon); padding: 16px 18px; margin-bottom: 14px; }
.bienvenue p { margin: 4px 0 0; color: var(--texte-doux); font-size: .9rem; }
.bienvenue .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Recommandations ---------- */
.reco { border-left: 3px solid var(--bordure); padding: 12px 14px; background: var(--surface-2);
  border-radius: 0 10px 10px 0; margin-bottom: 10px; }
.reco.critique { border-left-color: var(--rouge); }
.reco.important { border-left-color: var(--orange); }
.reco.utile { border-left-color: var(--accent); }
.reco h3 { font-size: .95rem; margin-bottom: 5px; }
.reco p { margin: 4px 0; font-size: .88rem; color: var(--texte-doux); }
.reco .action { color: var(--texte); }
.reco .impact { color: var(--texte-faible); font-size: .82rem; }

/* ---------- Tableaux ---------- */
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th { text-align: left; color: var(--texte-faible); font-weight: 700; font-size: .7rem;
  text-transform: uppercase; letter-spacing: .07em; padding: 8px 10px; border-bottom: 1px solid var(--bordure); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid color-mix(in srgb, var(--bordure) 60%, transparent); vertical-align: middle;
  font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: .82rem; }
.table-defilante { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

/* ---------- Formulaires ---------- */
input, select, textarea {
  background: var(--surface); border: 1px solid var(--bordure); border-radius: 8px;
  padding: 8px 11px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fond); }
label { display: block; font-size: .76rem; color: var(--texte-doux); margin-bottom: 4px; font-weight: 700; }
.champ { margin-bottom: 10px; }
.bouton { background: var(--accent); color: var(--accent-texte); border: 0; border-radius: 8px; padding: 9px 16px;
  font-weight: 700; cursor: pointer; font-size: .88rem; transition: filter .15s; white-space: nowrap; }
.bouton:hover { filter: brightness(1.08); }
.bouton:disabled { opacity: .5; cursor: not-allowed; }
.bouton.fantome { background: var(--surface); border: 1px solid var(--bordure); color: var(--texte); }
.bouton.fantome:hover { border-color: var(--accent); color: var(--accent); }
.bouton.danger { background: var(--rouge-fond); color: var(--rouge); border: 1px solid color-mix(in srgb, var(--rouge) 30%, transparent); }
.bouton.mini { padding: 4px 9px; font-size: .76rem; }
.ligne-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; align-items: end; }

/* ---------- Barres & jauges ---------- */
.barre-fond { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.barre-remplie { height: 100%; border-radius: 99px; transition: width .5s cubic-bezier(.4, 0, .2, 1); }
.empilee { display: flex; height: 26px; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.empilee > span { display: grid; place-items: center; font-size: .7rem; font-weight: 700; color: var(--surface);
  transition: flex-basis .5s; overflow: hidden; }
.legende { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: .78rem; color: var(--texte-doux); }
.legende i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 5px; }

svg.graphe { width: 100%; height: auto; display: block; overflow: visible; }
svg.graphe text { fill: var(--texte-faible); }

.liste-nue { list-style: none; padding: 0; margin: 0; }
.liste-nue li { padding: 8px 0; border-bottom: 1px solid color-mix(in srgb, var(--bordure) 55%, transparent);
  display: flex; justify-content: space-between; gap: 12px; align-items: center; font-size: .88rem; }
.liste-nue li:last-child { border-bottom: 0; }
.coches { list-style: none; padding: 0; margin: 8px 0 0; }
.coches li { position: relative; padding: 5px 0 5px 24px; font-size: .87rem; color: var(--texte-doux); }
.coches li::before { content: "→"; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }

.avertissement { font-size: .75rem; color: var(--texte-faible); border-top: 1px solid var(--bordure);
  margin-top: 14px; padding-top: 10px; line-height: 1.5; }
.chargement { color: var(--texte-faible); font-size: .86rem; display: flex; align-items: center; gap: 8px; }
.chargement::before { content: ""; width: 12px; height: 12px; border: 2px solid var(--bordure);
  border-top-color: var(--accent); border-radius: 50%; animation: tourne .7s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }
.vide { color: var(--texte-faible); font-size: .87rem; text-align: center; padding: 22px; }
.num-vert { color: var(--vert); } .num-rouge { color: var(--rouge); } .num-orange { color: var(--orange); }
.notif { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); z-index: 99;
  background: var(--texte); color: var(--fond); padding: 10px 18px; border-radius: 10px;
  box-shadow: var(--ombre); font-size: .87rem; animation: apparait .2s; }

/* ---------- Guide ---------- */
.guide { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 18px; align-items: start; }
.guide .sommaire { position: sticky; top: 18px; }
.guide .sommaire a { display: block; padding: 5px 0; color: var(--texte-doux); text-decoration: none; font-size: .88rem; }
.guide .sommaire a:hover { color: var(--accent); }
.etapes { list-style: none; counter-reset: etape; padding: 0; margin: 0; display: grid; gap: 12px; }
.etapes li { counter-increment: etape; display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; }
.etapes li::before { content: counter(etape); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-fond); color: var(--accent); font-family: var(--titre); font-weight: 700; }
.etapes h3 { margin: 4px 0 2px; }
.etapes p, .guide p { margin: 4px 0; color: var(--texte-doux); font-size: .92rem; max-width: 70ch; }
.onglets-guide { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.onglets-guide button { text-align: left; background: var(--surface-2); border: 1px solid var(--bordure); border-radius: 10px;
  padding: 12px; cursor: pointer; }
.onglets-guide button:hover { border-color: var(--accent); }
.onglets-guide strong { display: block; font-family: var(--titre); margin-bottom: 3px; }
.onglets-guide span { color: var(--texte-doux); font-size: .84rem; }
dl.glossaire { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: .9rem; }
dl.glossaire dt { font-weight: 700; font-family: var(--mono); font-size: .84rem; }
dl.glossaire dd { margin: 0; color: var(--texte-doux); }
details.faq { border-bottom: 1px solid var(--bordure); padding: 10px 0; }
details.faq summary { cursor: pointer; font-weight: 700; }
details.faq p { margin: 8px 0 2px; }
@media (max-width: 980px) { .guide { grid-template-columns: 1fr; } .guide .sommaire { display: none; } }
@media (max-width: 520px) { dl.glossaire { grid-template-columns: 1fr; } dl.glossaire dd { margin-bottom: 6px; } }

.conseiller p { margin: 6px 0; }
.conseiller .texte { margin-top: 4px; }
.carte > .graphe { margin-bottom: 4px; }
@media (max-width: 640px) { .marque > div { display: none; } }

/* ---------- Icones ---------- */
nav.onglets button { display: flex; align-items: center; gap: 10px; }
nav.onglets button svg { width: 17px; height: 17px; flex: none; stroke-width: 1.8; }
.onglets-guide strong { display: flex; align-items: center; gap: 8px; }
.onglets-guide strong svg { width: 18px; height: 18px; color: var(--accent); }
@media (max-width: 980px) { nav.onglets button svg { display: none; } }

/* ---------- Illustration d accueil ---------- */
.bienvenue { grid-template-columns: 200px minmax(0, 1fr); grid-template-areas: "ill texte" "ill actions"; gap: 6px 22px; }
.bienvenue > div:first-child { grid-area: texte; align-self: end; }
.bienvenue .actions { grid-area: actions; align-self: start; margin-top: 8px; }
.illustration { grid-area: ill; width: 100%; max-width: 200px; height: auto; display: block; }
@media (max-width: 760px) { .bienvenue { grid-template-columns: 1fr; grid-template-areas: "texte" "actions"; } .illustration { display: none; } }
.ico { width: 17px; height: 17px; flex: none; }

/* Etat final = etat de repos : chaque animation part d un « from » et finit sur le dessin complet,
   donc avec les animations desactivees tout reste visible. */
.ill-barres rect { transform-box: fill-box; transform-origin: bottom; animation: monte .7s cubic-bezier(.2, .8, .2, 1) both;
  animation-delay: calc(var(--i) * 90ms); }
.ill-courbe { stroke-dasharray: 1; animation: trace 1.3s .5s ease-out both; }
.ill-point { animation: pop .4s 1.7s ease-out both; }
.ill-piece { animation: tombe .6s 1.1s cubic-bezier(.3, 1.4, .5, 1) both; }
@keyframes monte { from { transform: scaleY(0); } }
@keyframes trace { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0); transform-box: fill-box; transform-origin: center; } }
@keyframes tombe { from { transform: translateY(-40px); opacity: 0; } }

/* ---------- Graphiques animes ---------- */
.trace { stroke-dasharray: 1; animation: trace 1.1s ease-out both; }
.barre-svg { transform-box: fill-box; transform-origin: bottom; animation: monte .6s cubic-bezier(.2, .8, .2, 1) both; }
.jauge-arc { animation: jauge 1.1s cubic-bezier(.4, 0, .2, 1) both; }
@keyframes jauge { from { stroke-dashoffset: var(--depart); } }
.kpi { transition: transform .15s ease, box-shadow .15s ease; }
.kpi:hover { transform: translateY(-2px); box-shadow: var(--ombre); }

/* ---------- Conditions et rappels ---------- */
.conditions { max-width: 78ch; }
.conditions h3 { margin: 18px 0 4px; }
.conditions p { margin: 0; color: var(--texte-doux); font-size: .93rem; }
.rappel { margin: 12px 0 0; font-size: .78rem; color: var(--texte-faible); }
dialog.accord { border: 1px solid var(--bordure); border-radius: 16px; background: var(--surface); color: var(--texte);
  padding: 24px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45); }
dialog.accord::backdrop { background: rgba(10, 16, 14, .55); backdrop-filter: blur(3px); }
dialog.accord h2 { font-size: 1.3rem; margin-bottom: 6px; }
dialog.accord .coches li { color: var(--texte); }
.case { display: flex; gap: 10px; align-items: center; font-size: .92rem; color: var(--texte); font-weight: 700; margin: 14px 0; cursor: pointer; }
.case input { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.conditions-modale { max-height: 40vh; overflow-y: auto; border: 1px solid var(--bordure); border-radius: 10px; padding: 4px 14px 14px; margin-top: 8px; }
.conditions-modale header { display: none; }
.conditions-modale h3 { margin: 12px 0 2px; font-size: .9rem; }
.conditions-modale p { margin: 0; font-size: .85rem; color: var(--texte-doux); }
