/* =====================================================================
   Finances perso — charte graphique « Sapin et laiton »
   Voir CHARTE.md. Pour changer l'apparence : modifiez uniquement les variables ci-dessous.
   ===================================================================== */
:root {
  /* Couleurs */
  --sauge: #E9EEE8;        /* fond de page */
  --papier: #F9FAF7;       /* panneaux, champs */
  --encre: #1D2A25;        /* texte principal */
  --encre-2: #5E6B65;      /* texte secondaire */
  --trait: #D5DDD5;        /* bordures, séparateurs */
  --sapin: #24493D;        /* barre latérale, boutons principaux */
  --sapin-clair: #DCE7E0;  /* survols, fonds d'information */
  --mousse: #4F7D69;       /* barres de graphiques, montants positifs */
  --laiton: #B8873A;       /* accent rare : logo, page active, chiffre clé */
  --brique: #A23E2E;       /* alertes, dépassements, dettes */
  --brique-fond: #F6E4DF;
  --sur-sapin: #E9EEE8;    /* texte sur fond sapin */

  /* Typographie */
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;

  /* Formes */
  --r-panneau: 14px;
  --r-champ: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --sauge: #121815; --papier: #1A221E; --encre: #E4EAE5; --encre-2: #9AA7A0; --trait: #2B3630;
    --sapin: #0D1411; --sapin-clair: #22302A; --mousse: #7DB39A; --laiton: #D6A85A;
    --brique: #E08A7B; --brique-fond: #3A2522; --sur-sapin: #DCE4DE;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.55 var(--sans); background: var(--sauge); color: var(--encre); }
a { color: var(--sapin); text-decoration-thickness: 1px; text-underline-offset: 2px; }
@media (prefers-color-scheme: dark) { a { color: var(--mousse); } }
:focus-visible { outline: 2px solid var(--laiton); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Typographie : titres et chiffres en serif, texte courant en sans */
h1, h2, h3, .t-val, .phrase, .phrase-soc { font-family: var(--serif); font-variant-numeric: lining-nums tabular-nums; }
h1 { font-size: 2rem; font-weight: 600; line-height: 1.15; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 0 0 .9rem; }
h2.section { font-size: 1.05rem; color: var(--encre-2); margin: 1.6rem 0 .7rem; font-weight: 600; }
h3.petit { font-size: .95rem; margin: 1rem 0 .4rem; }
.muted { color: var(--encre-2); margin: 0; }
.petit { font-size: .85rem; }
.num, td, .b-montant { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- structure */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.app > *, .grille2 > *, .tuiles > * { min-width: 0; }
.cote { background: var(--sapin); color: var(--sur-sapin); padding: 1.4rem .9rem 1.2rem; display: flex; flex-direction: column; gap: 1.4rem; position: sticky; top: 0; height: 100vh; }
.marque { display: flex; align-items: center; gap: .6rem; font-family: var(--serif); font-size: 1.2rem; font-weight: 600; padding: 0 .5rem; color: #fff; }
.marque svg { width: 30px; height: 30px; flex: none; }
#menu { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
#menu a { position: relative; padding: .5rem .7rem .5rem .9rem; border-radius: var(--r-champ); text-decoration: none; color: var(--sur-sapin); opacity: .82; }
#menu a:hover { opacity: 1; background: rgba(255, 255, 255, .06); }
#menu a.actif { opacity: 1; background: rgba(255, 255, 255, .1); font-weight: 600; }
#menu a.actif::before { content: ""; position: absolute; left: 0; top: 22%; bottom: 22%; width: 3px; border-radius: 2px; background: var(--laiton); }
#menu hr { border: 0; border-top: 1px solid rgba(255, 255, 255, .12); margin: .6rem .7rem; }
.cote .btn.lien { color: var(--sur-sapin); opacity: .7; }
.colonne { min-width: 0; }
.contenu { padding: 2rem 2.4rem 4rem; max-width: 1180px; width: 100%; }
.bandeau { background: var(--sapin-clair); color: var(--encre); padding: .55rem 2.4rem; font-size: .88rem; border-bottom: 1px solid var(--trait); }
.entete { margin-bottom: 1.4rem; }
.entete.ligne { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.entete .muted { max-width: 70ch; }

/* ---------------------------------------------------------------- panneaux */
.carte { background: var(--papier); border: 1px solid var(--trait); border-radius: var(--r-panneau); padding: 1.25rem 1.4rem; margin-bottom: 1.1rem; overflow-x: auto; }
.grille2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; margin-bottom: 1.1rem; }
.grille2 > .carte { margin-bottom: 0; }
.encart { background: var(--sapin-clair); border-radius: var(--r-champ); padding: .85rem 1.1rem; margin: 0 0 1.1rem; }
.encart.alerte { background: var(--brique-fond); border-left: 3px solid var(--brique); }
.encart.alerte div + div { margin-top: .25rem; }
.bandeau + .contenu .encart:first-child { margin-top: 0; }

/* La phrase d'ouverture : l'élément signature de la charte */
.phrase { margin: 0 0 1.6rem; max-width: 46rem; }
.phrase p { margin: 0 0 .35rem; font-size: 1.45rem; line-height: 1.35; }
.phrase strong { font-weight: 600; border-bottom: 2px solid var(--laiton); }
.phrase .muted { font-family: var(--sans); font-size: .92rem; margin-top: .5rem; }
.phrase-net { font-size: 1.9rem !important; font-weight: 600; }

/* Tuiles de chiffres */
.tuiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: .8rem; }
.tuile { background: var(--papier); border: 1px solid var(--trait); border-radius: var(--r-panneau); padding: .95rem 1.05rem; }
.t-label { color: var(--encre-2); font-size: .84rem; }
.t-val { font-size: 1.55rem; font-weight: 600; margin: .1rem 0; }
.t-sous { color: var(--encre-2); font-size: .8rem; }
.tuile.alerte { border-color: var(--brique); background: var(--brique-fond); }
.tuile.alerte .t-val, .txt-alerte { color: var(--brique); }

/* Barres horizontales */
.barres { display: flex; flex-direction: column; gap: 4px; }
.barre-ligne { display: grid; grid-template-columns: 160px 1fr 84px; gap: .7rem; align-items: center; padding: 3px 4px; border-radius: 6px; }
.barre-ligne:hover { background: var(--sapin-clair); }
.b-label { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-piste { height: 10px; }
.b-val { display: block; height: 100%; background: var(--mousse); border-radius: 0 4px 4px 0; min-width: 2px; }
.barre-ligne.dette .b-val { background: var(--brique); }
.b-montant { text-align: right; font-size: .9rem; }

/* Objectifs */
.objectif { padding: .6rem 0; border-bottom: 1px solid var(--trait); }
.objectif:last-child { border-bottom: 0; }
.o-tete { display: flex; justify-content: space-between; gap: .6rem; font-size: .93rem; }
.progress { height: 6px; background: var(--sauge); border-radius: 3px; margin: .4rem 0; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--mousse); border-radius: 3px; }

/* Courbes */
.courbe { position: relative; }
.courbe svg { width: 100%; height: 150px; display: block; }
.courbe .ligne { fill: none; stroke: var(--sapin); stroke-width: 2; vector-effect: non-scaling-stroke; }
@media (prefers-color-scheme: dark) { .courbe .ligne { stroke: var(--mousse); } }
.courbe .zero { stroke: var(--brique); stroke-dasharray: 4 4; stroke-width: 1; vector-effect: non-scaling-stroke; }
.courbe .curseur { stroke: var(--encre-2); stroke-width: 1; vector-effect: non-scaling-stroke; }
.courbe .point { fill: var(--laiton); stroke: var(--papier); stroke-width: 2; }
.bulle { position: absolute; top: -8px; background: var(--encre); color: var(--papier); font-size: .8rem; padding: 3px 9px; border-radius: 6px; pointer-events: none; white-space: nowrap; }

/* ---------------------------------------------------------------- tableaux */
.tableau-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .85rem; text-align: left; border-bottom: 1px solid var(--trait); white-space: nowrap; }
th { font-size: .8rem; color: var(--encre-2); font-weight: 600; }
.num { text-align: right; }
.donnees th[data-tri] { cursor: pointer; user-select: none; }
.donnees th[data-tri]:hover { color: var(--encre); }
.donnees tbody tr { cursor: pointer; }
.donnees tbody tr:hover { background: var(--sapin-clair); }
.donnees.fixe tbody tr, .ops tbody tr { cursor: default; }
tr.inactif td { color: var(--encre-2); text-decoration: line-through; }
tfoot td, tr.total td { font-weight: 600; border-bottom: 0; }
tr.total td { border-top: 1px solid var(--encre-2); }
.mini th, .mini td { padding: .45rem .35rem; font-size: .9rem; }
td.lib { white-space: normal; min-width: 220px; }
.ops td { vertical-align: top; }
.positif { color: var(--mousse); }
.vide { padding: 1.6rem; }
.tag { font-size: .78rem; padding: 1px 7px; border-radius: 999px; }
.tag.alerte, .badge.a_verifier { background: var(--brique-fond); color: var(--brique); }
.badge { font-size: .76rem; padding: 2px 9px; border-radius: 999px; background: var(--sauge); color: var(--encre-2); white-space: nowrap; }
.badge.a_payer { background: var(--sapin-clair); color: var(--sapin); }
.badge.payee { background: var(--sauge); color: var(--encre); }
@media (prefers-color-scheme: dark) { .badge.a_payer { color: var(--mousse); } }
code { background: var(--sauge); padding: 1px 6px; border-radius: 4px; font-size: .85em; word-break: break-all; }
.ligne-fac { display: grid; grid-template-columns: 1fr auto 90px; gap: .6rem; font-size: .88rem; padding: .35rem 0; border-top: 1px solid var(--trait); }
details.carte summary { cursor: pointer; font-family: var(--serif); font-weight: 600; }
details.carte[open] summary { margin-bottom: .7rem; }

/* Sociétés */
.soc-tete { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.phrase-soc { font-size: 1.2rem; margin: 0 0 1rem; }
.phrase-soc strong { border-bottom: 2px solid var(--laiton); }
.societe .muted.petit { margin-top: .6rem; max-width: 80ch; }

/* ---------------------------------------------------------------- formulaires */
.btn { font: inherit; font-size: .92rem; border: 1px solid var(--trait); background: var(--papier); color: var(--encre); padding: .5rem 1.05rem; border-radius: var(--r-champ); cursor: pointer; }
.btn:hover { border-color: var(--encre-2); }
.btn.primaire { background: var(--sapin); border-color: var(--sapin); color: #fff; }
.btn.primaire:hover { filter: brightness(1.15); }
@media (prefers-color-scheme: dark) { .btn.primaire { background: var(--mousse); border-color: var(--mousse); color: #0D1411; } }
.btn.danger { color: var(--brique); border-color: var(--brique); background: transparent; }
.btn.lien { border: 0; background: none; color: var(--encre-2); padding: .3rem .5rem; text-align: left; text-decoration: underline; text-underline-offset: 2px; }
.btn.petit { padding: .25rem .65rem; font-size: .82rem; }
.btn:disabled { opacity: .6; cursor: wait; }
label.btn { display: inline-block; }
.boutons { display: flex; gap: .5rem; flex-wrap: wrap; }
.champ { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.champ span { font-size: .85rem; color: var(--encre-2); }
input, select, textarea { font: inherit; padding: .5rem .65rem; border: 1px solid var(--trait); border-radius: var(--r-champ); background: var(--papier); color: var(--encre); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sapin); outline-offset: -1px; }
.case { display: flex; gap: .5rem; align-items: center; margin: .6rem 0; }
.case input, .filtres input[type=checkbox] { width: auto; min-width: 0; accent-color: var(--sapin); }
.err { color: var(--brique); min-height: 1.2em; margin: .4rem 0 0; }
.filtres { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: .7rem; }
.filtres input, .filtres select { width: auto; min-width: 160px; }
.filtres .case { margin: 0; font-size: .85rem; color: var(--encre-2); }
select.cat { padding: .25rem .45rem; font-size: .85rem; min-width: 155px; }
select.cat.ia { border-style: dashed; border-color: var(--laiton); }
.depot { border: 1.5px dashed var(--trait); border-radius: var(--r-panneau); padding: 1.2rem; text-align: center; color: var(--encre-2); margin-bottom: 1.1rem; background: var(--papier); }
.depot.survol { border-color: var(--sapin); background: var(--sapin-clair); }

dialog { border: 1px solid var(--trait); border-radius: 16px; padding: 1.5rem 1.6rem; width: min(640px, 94vw); background: var(--papier); color: var(--encre); }
dialog::backdrop { background: rgba(13, 20, 17, .5); }
.champs { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; max-height: 62vh; overflow-y: auto; padding-right: 2px; }
.champs .champ:has(textarea), .champs .case { grid-column: 1 / -1; }
.actions { display: flex; gap: .5rem; margin-top: 1.1rem; }
.espace { flex: 1; }
#toast { position: fixed; bottom: 1.3rem; left: 50%; transform: translateX(-50%); background: var(--sapin); color: #fff; padding: .65rem 1.2rem; border-radius: 10px; z-index: 50; max-width: 90vw; font-size: .9rem; }
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: ouvrir .16s ease-out; }
  @keyframes ouvrir { from { opacity: 0; transform: translateY(6px); } }
}

/* ---------------------------------------------------------------- connexion */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--sapin); padding: 1rem; }
.login .carte { width: min(380px, 94vw); padding: 2rem 1.8rem; }
.login .marque { color: var(--encre); padding: 0; margin-bottom: 1.4rem; font-size: 1.4rem; }
.login .btn.primaire { width: 100%; padding: .65rem; }

/* ---------------------------------------------------------------- mobile */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .cote { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .9rem; }
  #menu { flex-direction: row; flex-wrap: wrap; flex-basis: 100%; order: 3; }
  #menu hr { display: none; }
  #menu a { padding: .35rem .6rem; }
  #menu a.actif::before { display: none; }
  .cote .btn.lien { margin-left: auto; }
  .contenu { padding: 1.2rem 1rem 3rem; }
  .bandeau { padding: .5rem 1rem; }
  .grille2, .champs { grid-template-columns: 1fr; }
  .tuiles { grid-template-columns: 1fr 1fr; }
  .t-val { font-size: 1.25rem; }
  .phrase p { font-size: 1.2rem; }
  .phrase-net { font-size: 1.5rem !important; }
  .entete.ligne { flex-direction: column; }
  .barre-ligne { grid-template-columns: 110px 1fr 74px; }
  h1 { font-size: 1.6rem; }
}
