/* =========================================================
   Grand-Livre DSRCAD - feuille de style unique
   Pas de framework, pas de build : tout est ici.
   ========================================================= */

:root {
  --fond: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --bord: #e0dbcd;
  --texte: #1c2620;
  --texte-doux: #5c6b61;
  --texte-faible: #8a8676;
  --accent: #2f6f5e;
  --accent-fond: #e4efe9;
  --accent-texte: #1d4a3d;
  --alerte: #9a6a2c;
  --alerte-fond: #f6ead6;
  --danger: #a33a2b;
  --danger-fond: #f7e3df;
  --ok: #2f6f5e;
  --rayon: 10px;
  --ombre: 0 1px 2px rgba(28, 38, 32, .07);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #141815;
    --surface: #1d2320;
    --surface-2: #232a26;
    --bord: #323a34;
    --texte: #e8e5da;
    --texte-doux: #aeb8b0;
    --texte-faible: #7c8478;
    --accent: #6fbfa3;
    --accent-fond: #22302a;
    --accent-texte: #9fdcc5;
    --alerte: #d9a85e;
    --alerte-fond: #342a1a;
    --danger: #e08577;
    --danger-fond: #34211e;
    --ok: #6fbfa3;
    --ombre: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent-texte); }
.nombre { font-variant-numeric: tabular-nums; }

/* ---------------- Marque ---------------- */
.marque { display: flex; align-items: center; gap: 10px; }
.marque-sigle {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 8px; font-weight: 700; font-size: 13px; letter-spacing: .02em;
}
.marque div { display: flex; flex-direction: column; line-height: 1.2; }
.marque strong { font-size: 14px; }
.marque span:not(.marque-sigle) { font-size: 11.5px; color: var(--texte-faible); letter-spacing: .06em; text-transform: uppercase; }

/* ---------------- Connexion ---------------- */
.connexion {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
}
.connexion-carte {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: 14px;
  box-shadow: var(--ombre);
  padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.connexion-carte h1 { font-size: 20px; margin-top: 6px; }

/* ---------------- Mise en page ---------------- */
.application { display: flex; min-height: 100vh; }

.barre-laterale {
  width: 232px; flex: none;
  background: var(--surface);
  border-right: 1px solid var(--bord);
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
#navigation { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.groupe-nav {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--texte-faible); margin: 14px 0 4px 10px;
}
.lien-nav {
  display: block; padding: 8px 10px;
  border-radius: 8px; color: var(--texte-doux);
  text-decoration: none; font-size: 14px;
}
.lien-nav:hover { background: var(--surface-2); color: var(--texte); }
.lien-nav.actif { background: var(--accent-fond); color: var(--accent-texte); font-weight: 600; }

.pied-laterale { border-top: 1px solid var(--bord); padding-top: 14px; display: grid; gap: 10px; }
.utilisateur-actif { display: flex; align-items: center; gap: 10px; }
.utilisateur-actif div { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.utilisateur-actif strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.utilisateur-actif span { font-size: 11.5px; color: var(--texte-faible); }
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  background: var(--accent-fond); color: var(--accent-texte);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
}

.contenu { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.entete {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--bord);
  background: var(--surface);
}
.entete h1 { font-size: 20px; }
.entete p { margin: 2px 0 0; font-size: 13px; color: var(--texte-faible); }
.actions-page { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.bouton-menu { display: none; background: none; border: 0; font-size: 20px; color: var(--texte); cursor: pointer; }

.vue { padding: 24px 28px 64px; display: grid; gap: 20px; align-content: start; }
/* Sans min-width:0, un enfant de grille prend la largeur de son contenu :
   un tableau large pousserait alors toute la page en debordement horizontal. */
.vue > *, .grille > *, .carte { min-width: 0; }

/* Voile affiche derriere le menu mobile ouvert : le toucher referme le menu. */
.voile {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(0, 0, 0, .45);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.voile.visible { opacity: 1; pointer-events: auto; }
.fermer-menu { display: none; }

@media (max-width: 860px) {
  .barre-laterale {
    position: fixed; z-index: 30; left: 0; top: 0;
    width: min(280px, 82vw);
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--ombre);
  }
  .barre-laterale.ouverte { transform: translateX(0); }
  .bouton-menu { display: block; }

  /* Sur telephone, c'est le panneau entier qui defile, pas seulement la liste :
     sinon un en-tete de groupe peut rester visible avec ses liens hors champ.
     100dvh suit la hauteur reelle quand la barre d'adresse se replie. */
  .barre-laterale { height: 100vh; height: 100dvh; overflow-y: auto; gap: 14px; }
  #navigation { flex: 0 0 auto; overflow: visible; }
  .pied-laterale { margin-top: auto; }
  .groupe-nav { margin-top: 10px; }
  .entete, .vue { padding-left: 16px; padding-right: 16px; }

  /* Le menu ouvert recouvrait le bouton qui sert a le fermer :
     on ajoute une croix dans la barre, en plus du voile. */
  .fermer-menu {
    display: grid; place-items: center;
    position: absolute; top: 14px; right: 12px;
    width: 36px; height: 36px;
    border: 1px solid var(--bord); border-radius: 8px;
    background: var(--surface); color: var(--texte-doux);
    font-size: 18px; line-height: 1; cursor: pointer;
  }
  .marque { padding-right: 44px; }
}

/* ---------------- Confort tactile ---------------- */
@media (pointer: coarse), (max-width: 860px) {
  /* Cibles tactiles : au moins 40 px de haut (recommandation : 44). */
  .bouton, .bouton.petit, .lien-nav, a.bouton {
    min-height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .bouton.petit { padding: 8px 12px; font-size: 13px; }
  .bouton.discret { justify-content: flex-start; }
  td.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

  /* Sous 16 px, iOS zoome automatiquement en entrant dans un champ. */
  input, select, textarea { font-size: 16px; }

  /* Defilement fluide des tableaux larges. */
  .tableau-enveloppe { -webkit-overflow-scrolling: touch; }
}

/* ---------------- Boutons et formulaires ---------------- */
.bouton {
  font: inherit; font-size: 13.5px; font-weight: 500;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--bord); background: var(--surface);
  color: var(--texte); cursor: pointer;
}
.bouton:hover { background: var(--surface-2); }
.bouton.primaire { background: var(--accent); border-color: var(--accent); color: #fff; }
.bouton.primaire:hover { filter: brightness(1.08); }
.bouton.discret { background: none; border-color: transparent; color: var(--texte-faible); padding: 6px 8px; text-align: left; }
.bouton.discret:hover { color: var(--texte); background: var(--surface-2); }
.bouton.petit { padding: 4px 9px; font-size: 12.5px; }
.bouton.danger { color: var(--danger); border-color: var(--danger-fond); }
.bouton:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label { display: grid; gap: 5px; font-size: 12.5px; color: var(--texte-doux); font-weight: 500; }
textarea { min-height: 90px; resize: vertical; font-family: ui-monospace, monospace; font-size: 13px; }
input, select, textarea {
  font: inherit; font-size: 14px;
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte);
  width: 100%;
}
.formulaire { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.formulaire .large { grid-column: 1 / -1; }
.barre-filtres { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.barre-filtres label { flex: 1 1 150px; }

/* ---------------- Cartes ---------------- */
.carte {
  background: var(--surface); border: 1px solid var(--bord);
  border-radius: var(--rayon); box-shadow: var(--ombre);
  padding: 18px 20px;
}
.carte > h2 { font-size: 15px; margin-bottom: 4px; }
.carte > .sous-titre { font-size: 12.5px; color: var(--texte-faible); margin: 0 0 14px; }
.grille { display: grid; gap: 14px; }
.grille.colonnes-4 { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); align-items: start; }
.grille.colonnes-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

.tuile { display: grid; gap: 4px; }
.tuile .intitule { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--texte-faible); }
.tuile .valeur { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tuile .detail { font-size: 12.5px; color: var(--texte-faible); }
.tuile .valeur.positif { color: var(--ok); }
.tuile .valeur.negatif { color: var(--danger); }

/* ---------------- Tableaux ---------------- */
.tableau-enveloppe { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--texte-faible); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--bord); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--bord); vertical-align: middle; }
td:first-child { white-space: nowrap; }
.code-compte { color: var(--texte-faible); font-family: ui-monospace, monospace; font-size: 12px; margin-right: 4px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.montant, th.montant { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
.vide { padding: 28px 10px; text-align: center; color: var(--texte-faible); font-size: 13.5px; }

/* ---------------- Etiquettes et jauges ---------------- */
.etiquette {
  display: inline-block; font-size: 11.5px; font-weight: 500;
  padding: 2px 8px; border-radius: 20px;
  background: var(--surface-2); color: var(--texte-doux); border: 1px solid var(--bord);
}
.etiquette.ok, .etiquette.validee { background: var(--accent-fond); color: var(--accent-texte); border-color: transparent; }
.etiquette.attention, .etiquette.en-attente { background: var(--alerte-fond); color: var(--alerte); border-color: transparent; }
.etiquette.depasse, .etiquette.rejetee { background: var(--danger-fond); color: var(--danger); border-color: transparent; }

.jauge { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.jauge span { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.jauge.attention span { background: var(--alerte); }
.jauge.depasse span { background: var(--danger); }

/* ---------------- Graphique (barres en CSS) ---------------- */
.graphique { display: flex; align-items: stretch; gap: 10px; height: 160px; padding-top: 10px; }
.graphique .colonne { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.graphique .paire { flex: 1; min-height: 0; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.graphique .barre { width: 11px; border-radius: 3px 3px 0 0; min-height: 2px; }
.graphique .barre.produits { background: var(--accent); }
.graphique .barre.charges { background: var(--alerte); }
.graphique .mois { font-size: 10px; color: var(--texte-faible); white-space: nowrap; }
.legende { display: flex; gap: 14px; font-size: 12px; color: var(--texte-faible); margin-top: 10px; }
.legende i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* ---------------- Divers ---------------- */
.message { font-size: 13px; padding: 9px 12px; border-radius: 8px; margin: 0; }
.message.erreur { background: var(--danger-fond); color: var(--danger); }
.message.info { background: var(--accent-fond); color: var(--accent-texte); }

.notification {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--texte); color: var(--fond);
  padding: 10px 18px; border-radius: 24px; font-size: 13.5px;
  box-shadow: var(--ombre); z-index: 50; max-width: calc(100vw - 32px);
}
.notification.erreur { background: var(--danger); color: #fff; }

.chargement { color: var(--texte-faible); font-size: 13.5px; padding: 20px 0; }
.entete-section { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.liste-definitions { display: grid; gap: 8px; font-size: 13.5px; }
.liste-definitions div { display: flex; justify-content: space-between; gap: 12px; }
.liste-definitions dt { color: var(--texte-faible); }
.liste-definitions dd { margin: 0; font-variant-numeric: tabular-nums; }
details.bloc { border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px 16px; background: var(--surface); }
details.bloc summary { cursor: pointer; font-size: 14px; font-weight: 500; }
details.bloc[open] summary { margin-bottom: 12px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }


/* ---------------- Etats financiers ---------------- */
.entete-bloc {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--accent-texte); background: var(--accent-fond);
  font-weight: 700; padding: 8px 10px;
}
tr.ligne-groupe td { background: var(--surface-2); }
tr.ligne-total td { font-weight: 700; border-top: 1px solid var(--texte-faible); }
tr.ligne-resultat td {
  font-weight: 700; font-size: 15px;
  background: var(--accent-fond); color: var(--accent-texte);
  border-top: 2px solid var(--accent);
}
.ligne-total-bloc {
  display: flex; justify-content: space-between; gap: 12px;
  margin: 10px 0 0; padding-top: 10px;
  border-top: 2px solid var(--accent);
  font-weight: 700; font-variant-numeric: tabular-nums;
}

/* ---------------- Impression (Imprimer / PDF) ---------------- */
@media print {
  .barre-laterale, .actions-page, .bouton, #notification, .entete p { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  /* --texte-faible (#8a8676, un beige clair) sert d'intitules, de codes
     de compte, d'en-tetes de tableau et de legendes de graphique : lisible
     a l'ecran mais trop pale une fois imprime/exporte en PDF. On la fonce
     uniquement ici, sans toucher a l'affichage ecran. */
  :root { --texte-faible: #5b5647; }
  .application { display: block; }
  .contenu { display: block; }
  .entete { border: none; padding: 0 0 12px; background: none; }
  .vue { padding: 0; display: block; }
  .carte {
    box-shadow: none; border: 1px solid #bbb; break-inside: avoid;
    page-break-inside: avoid; margin-bottom: 14px; background: #fff;
  }
  .graphique { break-inside: avoid; }
  .tableau-enveloppe { overflow: visible; }
  /* Le bilan (ACTIF | PASSIF) est affiche en 2 colonnes a l'ecran ; a
     l'impression/export PDF la largeur de page fait chevaucher les deux
     tableaux (le second se superpose au premier). On empile les blocs
     verticalement pour l'impression : ACTIF, puis PASSIF en dessous. */
  .grille.colonnes-2, .grille.colonnes-4 { grid-template-columns: 1fr; }
  tr.ligne-resultat td, .entete-bloc { background: #eee !important; color: #000 !important; }
  a[href]:after { content: ''; }
}


/* ---------------------------------------------------------------
   Tableaux sur telephone : empilement en fiches.

   Un tableau a 7 colonnes qui defile horizontalement sur un ecran de
   375 px ne montre que sa premiere colonne - donc rien d'utile. Chaque
   ligne devient ici une fiche ou l'intitule de colonne (data-label,
   pose par composants.js) sert d'etiquette a gauche et la valeur
   s'aligne a droite.
   --------------------------------------------------------------- */
@media (max-width: 640px) {
  .tableau-empilable thead { display: none; }
  .tableau-empilable, .tableau-empilable tbody, .tableau-empilable tr, .tableau-empilable td {
    display: block; width: 100%;
  }
  .tableau-empilable tr {
    border: 1px solid var(--bord);
    border-radius: var(--rayon);
    padding: 6px 12px;
    margin-bottom: 10px;
    background: var(--surface);
  }
  .tableau-empilable tr:hover { background: var(--surface); }
  .tableau-empilable tr:last-child { margin-bottom: 0; }

  .tableau-empilable td {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; text-align: right;
    padding: 7px 0;
    border-bottom: 1px solid var(--bord);
    white-space: normal;
  }
  .tableau-empilable td:last-child { border-bottom: none; }

  /* Etiquette issue de l'en-tete de colonne. */
  .tableau-empilable td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    text-align: left;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--texte-faible); font-weight: 600;
  }
  /* Une colonne sans intitule (boutons d'action) occupe toute la largeur. */
  .tableau-empilable td[data-label=""]::before { content: none; }
  .tableau-empilable td[data-label=""] { justify-content: flex-end; }

  /* La premiere cellule fait office de titre de fiche : pas d'etiquette,
     aligne a gauche comme un titre, et un peu plus d'air en dessous. */
  .tableau-empilable td:first-child {
    justify-content: flex-start; text-align: left;
    font-weight: 600; font-size: 15px;
    padding-bottom: 9px;
    border-bottom: 1px solid var(--bord);
  }
  .tableau-empilable td:first-child::before { content: none; }
  .tableau-empilable .jauge { min-width: 90px; }
  .tableau-empilable .vide { display: block; }

  /* Les lignes de synthese des etats financiers gardent leur mise en forme. */
  .tableau-empilable tr.ligne-groupe td, .tableau-empilable tr.ligne-total td,
  .tableau-empilable tr.ligne-resultat td { justify-content: space-between; }
}


/* ---------------- Cascade SYSCOHADA ---------------- */
.repere-sig {
  font-family: ui-monospace, monospace; font-size: 11px; font-weight: 700;
  color: var(--accent-texte); background: var(--accent-fond);
  padding: 2px 5px; border-radius: 4px;
}
.repere-sig.discret { background: none; color: var(--texte-faible); font-weight: 500; }
.cascade-sig tr.ligne-compte td { padding-top: 3px; padding-bottom: 3px; font-size: 12.5px; border-bottom: none; }
.cascade-sig tr.ligne-total td { background: var(--surface-2); }
@media (max-width: 640px) {
  /* La cascade se lit en colonnes : on la garde telle quelle, avec defilement. */
  .cascade-sig, .cascade-sig tbody, .cascade-sig tr, .cascade-sig td { display: revert; }
  .cascade-sig thead { display: revert; }
  .cascade-sig td::before { content: none; }
  .cascade-sig td { text-align: left; }
  .cascade-sig td.montant { text-align: right; }
}