:root {
  color-scheme: light;
  --fond: #f6f5f1;
  --surface: #fdfdfb;
  --surface-2: #efeee8;
  --ligne: #dddbd2;
  --texte: #17160f;
  --texte-2: #55534b;
  --texte-3: #85837a;
  --accent: #1f5f4a;
  --accent-texte: #ffffff;
  --accent-doux: #e3eee9;
  --recette: #2a78d6;
  --depense: #eb6834;
  --positif: #1d7a3a;
  --negatif: #b3261e;
  --alerte-fond: #fff4dc;
  --alerte-texte: #6b4a00;
  --rayon: 10px;
  --ombre: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .06);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fond: #121210;
    --surface: #1a1a19;
    --surface-2: #24241f;
    --ligne: #34332d;
    --texte: #f4f3ee;
    --texte-2: #c3c2b7;
    --texte-3: #8c8a80;
    --accent: #6fc3a2;
    --accent-texte: #0d2219;
    --accent-doux: #1d3029;
    --recette: #3987e5;
    --depense: #d95926;
    --positif: #6cc488;
    --negatif: #f2867d;
    --alerte-fond: #3a2e10;
    --alerte-texte: #f3d58c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fond: #121210; --surface: #1a1a19; --surface-2: #24241f; --ligne: #34332d;
  --texte: #f4f3ee; --texte-2: #c3c2b7; --texte-3: #8c8a80;
  --accent: #6fc3a2; --accent-texte: #0d2219; --accent-doux: #1d3029;
  --recette: #3987e5; --depense: #d95926; --positif: #6cc488; --negatif: #f2867d;
  --alerte-fond: #3a2e10; --alerte-texte: #f3d58c;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--fond); color: var(--texte); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
.discret { color: var(--texte-2); }
.petit { font-size: .85rem; }
.chiffre { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cache { display: none !important; }

/* Boutons et champs */
button, .bouton {
  font: inherit; cursor: pointer; border: 1px solid var(--ligne); background: var(--surface); color: var(--texte);
  padding: .55em 1em; border-radius: 8px; display: inline-flex; align-items: center; gap: .45em; text-decoration: none; min-height: 40px;
}
button:hover, .bouton:hover { background: var(--surface-2); }
button.principal, .bouton.principal { background: var(--accent); color: var(--accent-texte); border-color: transparent; font-weight: 600; }
button.principal:hover { filter: brightness(1.08); }
button.danger { color: var(--negatif); }
button.lien { border: 0; background: none; padding: .2em; color: var(--accent); min-height: 0; text-decoration: underline; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: .85rem; color: var(--texte-2); margin-bottom: .25em; font-weight: 500; }
input, select, textarea {
  font: inherit; width: 100%; padding: .55em .7em; border: 1px solid var(--ligne); border-radius: 8px; background: var(--surface); color: var(--texte); min-height: 40px;
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.champ { margin-bottom: .9rem; }
.aide { font-size: .8rem; color: var(--texte-3); margin-top: .25em; }
.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grille-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.case { display: flex; gap: .6em; align-items: flex-start; font-size: .95rem; color: var(--texte); }
.case input { margin-top: .25em; }

/* Écran de connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.connexion .carte { width: 100%; max-width: 420px; }
.marque { display: flex; align-items: center; gap: .6em; font-weight: 700; font-size: 1.1rem; }
.marque svg { flex: none; }
.marque .logo { height: 30px; width: auto; display: block; }
.onglets { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 9px; margin: 1.2rem 0; }
.onglets button { flex: 1; border: 0; background: none; min-height: 36px; justify-content: center; }
.onglets button[aria-selected="true"] { background: var(--surface); box-shadow: var(--ombre); font-weight: 600; }

.carte { background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 1.3rem; box-shadow: var(--ombre); }
.message { padding: .7em .9em; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.message.erreur { background: color-mix(in srgb, var(--negatif) 12%, transparent); color: var(--negatif); }
.message.info { background: var(--accent-doux); color: var(--texte); }
.bandeau-demo { background: var(--alerte-fond); color: var(--alerte-texte); font-size: .85rem; padding: .5em 16px; text-align: center; }

/* Structure principale */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--ligne); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.nav .marque { padding: 4px 10px 18px; }
.nav a { display: flex; align-items: center; gap: .7em; padding: .6em .75em; border-radius: 8px; color: var(--texte-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--texte); }
.nav a[aria-current="page"] { background: var(--accent-doux); color: var(--texte); }
.nav .bas { margin-top: auto; font-size: .82rem; color: var(--texte-3); padding: 10px; word-break: break-all; }
.contenu { padding: 24px 32px 64px; max-width: 1180px; width: 100%; min-width: 0; }
.entete { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 1.4rem; }
.entete h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.exercice select { width: auto; font-weight: 600; }

/* Tuiles */
.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 1.4rem; }
.tuile { background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 14px 16px; }
.tuile .titre { font-size: .82rem; color: var(--texte-2); display: flex; align-items: center; gap: .45em; }
.tuile .valeur { font-size: 1.45rem; font-weight: 650; margin-top: .2em; font-variant-numeric: tabular-nums; }
.tuile .sous { font-size: .78rem; color: var(--texte-3); margin-top: .15em; }
.tuile.vedette { background: var(--accent-doux); border-color: transparent; }
.pastille { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

.panneaux { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.panneau { background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 16px 18px; min-width: 0; }
.panneau h2 { font-size: 1rem; }

/* Graphique */
.graphique { position: relative; }
.graphique svg { display: block; width: 100%; height: auto; overflow: visible; }
.graphique .axe { fill: var(--texte-3); font-size: 11px; }
.graphique .grille { stroke: var(--ligne); stroke-width: 1; }
.legende { display: flex; gap: 16px; font-size: .82rem; color: var(--texte-2); margin-bottom: 8px; flex-wrap: wrap; }
.legende span { display: inline-flex; align-items: center; gap: .4em; }
.infobulle { position: absolute; pointer-events: none; background: var(--texte); color: var(--fond); font-size: .8rem; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; z-index: 5; }
.infobulle .l { display: flex; align-items: center; gap: .4em; }
.barres-h .ligne-cat { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin-bottom: 10px; font-size: .85rem; }
.barres-h .piste { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.barres-h .rempli { height: 100%; background: var(--depense); border-radius: 0 4px 4px 0; }

/* Tableaux */
.filtres { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filtres input, .filtres select { width: auto; min-width: 140px; }
.filtres input[type="search"] { flex: 1; min-width: 180px; }
.tableau-conteneur { overflow-x: auto; background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--ligne); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-3); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr.cliquable { cursor: pointer; }
tbody tr.cliquable:hover { background: var(--surface-2); }
td.montant, th.montant { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.recette-txt { color: var(--positif); }
.etiquette { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--texte-2); white-space: nowrap; }
.etiquette.alerte { background: var(--alerte-fond); color: var(--alerte-texte); }
tfoot td { font-weight: 650; background: var(--surface-2); }
.vide { text-align: center; padding: 48px 16px; color: var(--texte-2); }

/* Formules et quota */
.quota { background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 12px 16px; margin-bottom: 1.2rem; display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; font-size: .9rem; }
.quota .piste { grid-column: 1 / -1; grid-row: 2; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.quota .rempli { height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }
.formules { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 1rem 0; max-width: 820px; }
.formule { background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 20px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.formule.mise-en-avant { border: 2px solid var(--accent); }
.formule.actuelle { background: var(--accent-doux); border-color: transparent; }
.formule h2 { margin: 0; }
.formule .prix { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.formule .prix span { font-size: .9rem; font-weight: 500; color: var(--texte-2); }
.atouts { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 6px; font-size: .92rem; }
.atouts li { padding-left: 1.5em; position: relative; }
.atouts li::before { content: ""; position: absolute; left: 4px; top: .2em; width: .35em; height: .7em; border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(45deg); }
@media (max-width: 860px) { .formules { grid-template-columns: 1fr; } .quota { grid-template-columns: 1fr; } .quota .piste { grid-row: auto; } }

/* Zone de dépôt */
.depot { border: 2px dashed var(--ligne); border-radius: var(--rayon); padding: 22px; text-align: center; color: var(--texte-2); margin-bottom: 16px; background: var(--surface); }
.depot.survol { border-color: var(--accent); background: var(--accent-doux); }

/* Fenêtre modale */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--texte); box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: contents; }
.modale-tete { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--ligne); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modale-tete h2 { margin: 0; }
.modale-corps { padding: 18px 20px; display: grid; grid-template-columns: 1fr 280px; gap: 20px; }
.modale-corps.simple { grid-template-columns: 1fr; }
.modale-pied { display: flex; justify-content: space-between; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--ligne); position: sticky; bottom: 0; background: var(--surface); }
.bascule { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 9px; margin-bottom: 1rem; }
.bascule label { flex: 1; margin: 0; text-align: center; padding: .45em; border-radius: 6px; cursor: pointer; font-size: .95rem; color: var(--texte-2); }
.bascule input { position: absolute; opacity: 0; }
.bascule label:has(input:checked) { background: var(--surface); color: var(--texte); font-weight: 600; box-shadow: var(--ombre); }
.bascule label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.justif { border: 1px solid var(--ligne); border-radius: var(--rayon); background: var(--surface-2); min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 12px; text-align: center; }
.justif img { max-width: 100%; max-height: 420px; border-radius: 6px; }
.justif iframe { width: 100%; height: 380px; border: 0; border-radius: 6px; background: white; }
.progression { width: 100%; height: 6px; background: var(--ligne); border-radius: 3px; overflow: hidden; }
.progression div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.calcul { font-size: .85rem; color: var(--texte-2); background: var(--surface-2); padding: .6em .8em; border-radius: 8px; margin-bottom: .9rem; }

/* Bilan */
.bilan h2 { margin-top: 1.4rem; }
.bilan .panneau h2 { margin-top: 0; }
.resultat { font-size: 1.1rem; }
.note { font-size: .85rem; color: var(--texte-2); border-left: 3px solid var(--ligne); padding-left: 12px; margin: 1rem 0; }

/* Mobile */
.nav-mobile { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .nav { display: none; }
  .nav-mobile { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--ligne); z-index: 10; padding-bottom: env(safe-area-inset-bottom); }
  .nav-mobile a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: .68rem; color: var(--texte-2); text-decoration: none; }
  .nav-mobile a[aria-current="page"] { color: var(--accent); font-weight: 600; }
  .contenu { padding: 16px 16px 90px; }
  .panneaux { grid-template-columns: 1fr; }
  .modale-corps { grid-template-columns: 1fr; }
  .justif { min-height: 140px; order: -1; }
  .justif img { max-height: 240px; }
  .modale-pied [data-fermer] { display: none; }
  .modale-pied { padding: 12px 16px; }
  .modale-pied > div:empty { display: none; }
  .modale-pied .actions { flex-wrap: nowrap; margin-left: auto; }
  .modale-pied button { padding: .55em .8em; }
  .grille-3 { grid-template-columns: 1fr 1fr; }
  .masquer-mobile, .depot { display: none; }
}
@media (max-width: 480px) { .grille-2, .grille-3 { grid-template-columns: 1fr; } }

/* Impression du bilan */
@media print {
  .nav, .nav-mobile, .bandeau-demo, .actions, .filtres, .ne-pas-imprimer { display: none !important; }
  .app { display: block; }
  .contenu { padding: 0; max-width: none; }
  body { background: white; color: black; }
  .panneau, .tableau-conteneur, .tuile { border-color: #ccc; box-shadow: none; }
}
