/* ==============================================================
   Schéma Documents Commerciaux — CERPEG  v2
   Design moderne, sobre et lisible pour lycéens
   Auteur : Fabienne MAURI — Lycée Henri Brulle, Libourne
   ============================================================== */

:root {
  --bg:      #F0F4F8;
  --white:   #FFFFFF;
  --surface: #F8FAFC;
  --border:  #C8D5E0;
  --border-l:#DDE6EF;
  --text:    #0D1B2A;
  --muted:   #4A6072;
  --subtle:  #8A9BAB;

  /* Client — bleu */
  --cl:   #1848B8;
  --cl-l: #EBF2FF;
  --cl-m: #85ADEF;
  --cl-d: #0F2E78;

  /* Fournisseur — vert */
  --fo:   #0B7A52;
  --fo-l: #E6F7F0;
  --fo-m: #6ECFAA;
  --fo-d: #054030;

  /* Écriture comptable — violet */
  --ec:   #6B21D8;
  --ec-l: #F0EAFF;
  --ec-m: #C4A8F5;

  /* Comptabilité — bleu marine */
  --cpt:   #1B2D6B;
  --cpt-l: #EAF0FF;
  --cpt-m: #8FAAE8;

  /* Oui — écriture à passer */
  --yes:   #6B21D8;
  --yes-l: #F0EAFF;
  --yes-b: #C4A8F5;

  /* Non — pas d'écriture */
  --no:   #607080;
  --no-l: #EEF2F6;
  --no-b: #B8C8D4;

  /* Couleurs par document */
  --dv:  #8B5200; --dv-l: #FFF8EA;
  --bc:  #1848B8; --bc-l: #EBF2FF;
  --bl:  #0B7A52; --bl-l: #E6F7F0;
  --fa:  #B83A00; --fa-l: #FFF2EB;
  --av:  #A8143C; --av-l: #FFEEF3;
  --re:  #5C1CB0; --re-l: #F3EEFF;
  --pa:  #2C3E50; --pa-l: #F4F7FA;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

body {
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 1.8rem 1.8rem 0;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.page { max-width: 1060px; margin: 0 auto; flex: 1; }

/* ══════════════════════════════
   HEADER
   ══════════════════════════════ */
.pg-hd {
  background: var(--cl); color: #fff;
  border-radius: 14px; padding: 22px 28px;
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 18px;
}
.pg-hd-ic {
  width: 52px; height: 52px;
  background: rgba(255,255,255,.18); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pg-hd-ic i { font-size: 24px; }
.pg-hd h1 { font-size: 1.3rem; font-weight: 900; }
.pg-hd p  { font-size: 0.83rem; opacity: .75; margin-top: 5px; }

/* ══════════════════════════════
   BANNIÈRE RÔLE (MOI = CLIENT / FOURNISSEUR)
   ══════════════════════════════ */
.moi-banner {
  display: flex; align-items: center; gap: 18px;
  border-radius: 14px; padding: 20px 26px;
  margin-bottom: 18px; border: 2px solid;
}
.moi-banner i { font-size: 34px; flex-shrink: 0; }
.moi-banner .bn-text { flex: 1; }
.moi-banner strong {
  font-size: 1.15rem; font-weight: 900; display: block; letter-spacing: -.01em;
}
.moi-banner small {
  display: block; font-size: 0.85rem; font-weight: 600;
  opacity: .75; margin-top: 6px;
}
.moi-banner .role-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.72rem; font-weight: 900; letter-spacing: .07em; text-transform: uppercase;
  padding: 6px 16px; border-radius: 30px; white-space: nowrap; flex-shrink: 0;
}
.moi-banner.cl { background: var(--cl-l); color: var(--cl-d); border-color: var(--cl-m); }
.moi-banner.fo { background: var(--fo-l); color: var(--fo-d); border-color: var(--fo-m); }
.moi-banner.cl .role-tag { background: var(--cl); color: #fff; }
.moi-banner.fo .role-tag { background: var(--fo); color: #fff; }

/* ══════════════════════════════
   LÉGENDE
   ══════════════════════════════ */
.legend {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 8px 22px; padding: 13px 20px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 20px;
  font-size: 0.85rem;
}
.li { display: flex; align-items: center; gap: 9px; color: var(--muted); font-weight: 700; }
.ldot { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; border: 1px solid rgba(0,0,0,.14); }
.lsep { width: 1px; height: 18px; background: var(--border); }

/* ══════════════════════════════
   EN-TÊTES COLONNES
   ══════════════════════════════ */
.cg {
  display: grid; grid-template-columns: 1fr 136px 1fr;
  margin-bottom: 10px;
}
.ch-wrap { position: relative; display: flex; flex-direction: column; }
.ch-wrap .ch { width: 100%; flex: 1; }
.ch {
  padding: 14px 20px; font-size: 0.8rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .07em;
  display: flex; align-items: center; gap: 8px;
  border-radius: 12px 12px 0 0;
}
.ch.cl  { background: var(--cl); color: #fff; }
.ch.mid {
  background: #1B2D3E; color: #C8D8E8;
  justify-content: center; text-align: center;
  flex-direction: column; gap: 3px;
  font-size: 0.68rem; border-radius: 0;
}
.ch.fo  { background: var(--fo); color: #fff; justify-content: flex-end; }

.moi-badge-hd {
  font-size: 0.66rem; font-weight: 900; letter-spacing: .05em;
  padding: 2px 9px; border-radius: 4px;
  background: rgba(255,255,255,.22); white-space: nowrap; flex-shrink: 0;
}
.moi-hd { font-size: 0.83rem !important; }
.eux-hd { opacity: .60; font-size: 0.76rem !important; }

/* Tooltip sur les en-têtes */
.ch-tip {
  display: none; position: absolute; top: calc(100% + 6px); left: 0;
  background: #1B2D3E; color: #DDE8F4;
  font-size: 0.8rem; font-weight: 600; line-height: 1.6;
  padding: 10px 16px; border-radius: 8px; white-space: nowrap;
  z-index: 200; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  pointer-events: none;
}
.ch-tip.ch-tip-r { left: auto; right: 0; }
.ch-tip::before {
  content: ''; position: absolute; bottom: 100%; left: 18px;
  border: 7px solid transparent; border-bottom-color: #1B2D3E;
}
.ch-tip.ch-tip-r::before { left: auto; right: 18px; }
.ch-wrap:hover .ch-tip { display: block; }

/* ══════════════════════════════
   PHASES (étapes)
   ══════════════════════════════ */
.phase {
  display: flex; align-items: center; gap: 10px;
  margin: 24px 0 10px;
  font-size: 0.8rem; font-weight: 900;
  text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
}
.phase i { font-size: 16px; }
.phase::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ══════════════════════════════
   ACCORDÉON — conteneur
   ══════════════════════════════ */
.acc {
  background: var(--white); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; margin-bottom: 8px;
  transition: box-shadow .2s, transform .15s;
}
.acc:hover { box-shadow: 0 6px 24px rgba(0,0,0,.09); transform: translateY(-1px); }
.acc.open  { box-shadow: 0 6px 24px rgba(0,0,0,.11); }

/* ── Ligne d'en-tête de l'accordéon ── */
.ah {
  display: grid; grid-template-columns: 1fr 136px 1fr;
  cursor: pointer; user-select: none;
}
.ac { display: flex; align-items: center; gap: 13px; padding: 17px 20px; transition: background .12s; }
.ac.r { justify-content: flex-end; }

/* Fond selon émetteur */
.emis-cl .ac.l { background: var(--cl-l); }
.emis-cl .ac.r { background: var(--surface); }
.emis-fo .ac.l { background: var(--surface); }
.emis-fo .ac.r { background: var(--fo-l); }
.acc:hover .ac  { filter: brightness(.97); }

/* Accent MOI — bordure épaisse côté "ma colonne" */
.moi-cl .ac.l { border-left: 5px solid var(--cl); }
.moi-fo .ac.r { border-right: 5px solid var(--fo); }

/* ── Icônes document ── */
.di {
  width: 48px; height: 48px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.di i { font-size: 22px; }
.di.dv { background: var(--dv-l); color: var(--dv); }
.di.bc { background: var(--bc-l); color: var(--bc); }
.di.bl { background: var(--bl-l); color: var(--bl); }
.di.fa { background: var(--fa-l); color: var(--fa); }
.di.av { background: var(--av-l); color: var(--av); }
.di.re { background: var(--re-l); color: var(--re); }
.di.pa { background: var(--pa-l); color: var(--pa); border: 1px solid var(--border); }

.dn { font-size: 1rem; font-weight: 800; line-height: 1.25; }
.ds { font-size: 0.77rem; color: var(--muted); margin-top: 3px; font-weight: 600; }

/* ── Badges "MOI J'émets" / "Ils émettent" ── */
.eb {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.7rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 11px; border-radius: 6px;
  white-space: nowrap; flex-shrink: 0;
}
.eb.c { background: var(--cl-m); color: var(--cl-d); }
.eb.f { background: var(--fo-m); color: var(--fo-d); }
.eb.moi {
  background: #fff !important; border: 2px solid;
  font-size: 0.72rem; font-weight: 900;
}
.eb.moi.c { color: var(--cl); border-color: var(--cl); }
.eb.moi.f { color: var(--fo); border-color: var(--fo); }
.eb.eux {
  opacity: .48; font-style: italic; font-weight: 600;
  background: transparent !important; border: 1px dashed rgba(0,0,0,.22);
  font-size: 0.67rem; padding: 2px 8px;
}

/* ══════════════════════════════
   COLONNE CENTRALE (flèche + écriture)
   ══════════════════════════════ */
.am {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 9px; padding: 12px 10px;
  background: #E8EFF6;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
.arr { width: 100%; height: 22px; display: block; overflow: visible; }

/* ── Pill écriture comptable ── */
.pill {
  display: flex; align-items: center; gap: 5px; justify-content: center;
  font-size: 0.73rem; font-weight: 800;
  padding: 6px 10px; border-radius: 20px;
  width: 100%; white-space: nowrap; border: 1.5px solid;
}
.pill.yes { background: var(--yes-l); color: var(--yes); border-color: var(--yes-b); }
.pill.no  { background: var(--no-l);  color: var(--no);  border-color: var(--no-b); }
.pill i   { font-size: 13px; }

/* Chevron accordéon */
.chev { font-size: 15px; color: var(--subtle); transition: transform .22s; }
.acc.open .chev { transform: rotate(180deg); }

/* ══════════════════════════════
   PANNEAU DE DÉTAIL (développé)
   ══════════════════════════════ */
.ab {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .28s cubic-bezier(.4,0,.2,1);
}
.acc.open .ab { grid-template-rows: 1fr; }
.abi { overflow: hidden; }

.dg {
  display: grid; grid-template-columns: 1fr 136px 1fr;
  border-top: 1px solid var(--border-l);
}
.dc { padding: 1.1rem 1.4rem; }
.emis-cl .dc.l { background: var(--cl-l); }
.emis-cl .dc.r { background: var(--white); }
.emis-fo .dc.l { background: var(--white); }
.emis-fo .dc.r { background: var(--fo-l); }

/* Accent MOI dans le détail */
.moi-cl .dc.l { border-left: 5px solid var(--cl); }
.moi-fo .dc.r { border-right: 5px solid var(--fo); }

.dm {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; padding: 12px 10px;
  background: #E8EFF6;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}

/* ── Sections dans le détail ── */
.sec { margin-bottom: 14px; }
.sec:last-child { margin-bottom: 0; }

/* Section comptable — bleu marine */
.sec-cpt { background: var(--cpt-l); border-radius: 8px; padding: 8px 10px; margin-bottom: 14px; border-left: 3px solid var(--cpt); }
.sec-cpt:last-child { margin-bottom: 0; }
.sec-cpt .st { color: var(--cpt); border-bottom-color: var(--cpt-m); }
.sec-cpt .items li { color: var(--cpt); }
.sec-cpt .items li i { color: var(--cpt); }

.st {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.71rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em; color: var(--subtle);
  margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border-l);
}
.st i { font-size: 12px; }

.estrip {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 0 0 10px; margin-bottom: 12px;
  border-bottom: 1px solid rgba(0,0,0,.08);
}
.estrip.c { color: var(--cl); }
.estrip.f { color: var(--fo); }

/* ── Liste d'éléments ── */
.items { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.items li {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 0.86rem; font-weight: 500; color: var(--muted);
  padding: 6px 8px; border-radius: 6px; line-height: 1.5;
  transition: background .1s;
}
.items li:hover { background: var(--bg); color: var(--text); }
.items li i { font-size: 15px; flex-shrink: 0; margin-top: 1px; color: var(--subtle); }
.items li strong { color: var(--text); font-weight: 700; }

/* ── Badge compte ── */
.abadge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Courier New', monospace;
  font-size: 0.76rem; font-weight: 700;
  padding: 5px 13px; border-radius: 7px; margin-top: 10px; border: 1px solid;
}
.abadge.dr { background: var(--fo-l); color: var(--fo-d); border-color: var(--fo-m); }
.abadge.cr { background: var(--cl-l); color: var(--cl-d); border-color: var(--cl-m); }

/* ── Formule ── */
.formula {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.83rem; font-weight: 700; color: var(--re);
  background: var(--re-l); border-radius: 8px;
  padding: 8px 14px; margin-top: 10px; border: 1px solid var(--ec-m);
}
.formula i { font-size: 16px; }

/* ══════════════════════════════
   NOTE EN BAS DE PAGE
   ══════════════════════════════ */
.note {
  margin-top: 1.6rem; padding: 1.1rem 1.6rem;
  background: var(--white); border: 1px solid var(--border);
  border-left: 4px solid var(--fa); border-radius: 12px;
  font-size: 0.83rem; color: var(--muted); line-height: 1.85;
}
.note strong { color: var(--text); }

/* ══════════════════════════════
   FOOTER
   ══════════════════════════════ */
footer {
  text-align: center;
  font-size: 0.74rem; color: var(--subtle);
  padding: 0 24px 20px;
  background: transparent;
}

/* ══════════════════════════════
   ANIMATION DES FLÈCHES
   ══════════════════════════════ */

/* Flux animé sur la ligne de la flèche */
@keyframes flowAnim {
  from { stroke-dashoffset: 20; }
  to   { stroke-dashoffset: 0; }
}

/* Toutes les lignes dans les SVG .arr */
.arr line {
  stroke-dasharray: 9 6;
  animation: flowAnim 0.75s linear infinite;
}

/* Étiquette de contexte au-dessus/dessous de la flèche */
.arr-label {
  font-size: 0.62rem; font-weight: 800;
  letter-spacing: .05em; text-transform: uppercase;
  white-space: nowrap; opacity: .85;
  line-height: 1;
}

/* Pointe de flèche : légère pulsation */
@keyframes tipPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .55; }
}
.arr polyline {
  animation: tipPulse 0.75s ease-in-out infinite;
}

/* ══════════════════════════════
   TOOLTIP EFFET DE COMMERCE
   ══════════════════════════════ */
.ec-tip {
  position: relative; cursor: help;
  border-bottom: 1px dashed var(--muted);
}
.ec-tip .ec-tip-box {
  display: none;
  position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%);
  background: #1B2D3E; color: #DDE8F4;
  font-size: 0.8rem; font-weight: 500; line-height: 1.6;
  padding: 10px 14px; border-radius: 8px;
  width: 320px; z-index: 300;
  box-shadow: 0 6px 20px rgba(0,0,0,.28);
  pointer-events: none; white-space: normal;
}
.ec-tip .ec-tip-box::after {
  content: ''; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: #1B2D3E;
}
.ec-tip:hover .ec-tip-box { display: block; }

/* ══════════════════════════════
   BOUTON IMPRIMER
   ══════════════════════════════ */
.btn-print {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  background: var(--fo);
  color: #fff;
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: .04em;
  border: none;
  border-radius: 40px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0,0,0,.22);
  transition: background .15s, transform .12s, box-shadow .15s;
}
.btn-print:hover {
  background: var(--fo-d);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.btn-print i { font-size: 18px; }

/* ══════════════════════════════
   IMPRESSION — 1 PAGE STRICTE
   ══════════════════════════════ */
@media print {
  @page {
    size: A4 portrait;
    margin: 14mm 28mm;   /* 14 mm haut/bas, 28 mm gauche/droite */
  }

  /* ── Forcer l'impression des fonds et couleurs ── */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ── Masquer les éléments interactifs ── */
  .btn-print,
  footer,
  .chev,
  .ch-tip,
  .ec-tip-box { display: none !important; }

  /* ── Accordéons tous déployés à l'impression ── */
  .ab  { display: grid !important; grid-template-rows: 1fr !important; }
  .abi { overflow: visible !important; }

  /* ── Reset html/body ── */
  html, body {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ── Conteneur principal : zoom calculé par JS ── */
  .page {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    zoom: var(--print-zoom, 0.55);
  }

  /* ── Header ── */
  .pg-hd {
    border-radius: 8px !important;
    padding: 12px 18px !important;
    margin-bottom: 8px !important;
  }
  .pg-hd h1 { font-size: 1.1rem !important; }
  .pg-hd p  { font-size: 0.75rem !important; margin-top: 2px !important; }
  .pg-hd-ic { width: 38px !important; height: 38px !important; }

  /* ── Bannière rôle ── */
  .moi-banner {
    border-radius: 8px !important;
    padding: 10px 16px !important;
    margin-bottom: 10px !important;
  }

  /* ── Légende ── */
  .legend {
    padding: 5px 12px !important;
    margin-bottom: 8px !important;
    gap: 6px 16px !important;
    font-size: 0.8rem !important;
  }

  /* ── En-têtes colonnes ── */
  .cg { margin-bottom: 4px !important; }
  .ch { padding: 8px 14px !important; }

  /* ── Phases ── */
  .phase { margin: 8px 0 3px !important; }

  /* ── Accordéons ── */
  .acc, .acc:hover {
    box-shadow: none !important;
    transform: none !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    margin-bottom: 3px !important;
  }

  /* ── Cellules de la ligne d'en-tête accordéon ── */
  .ac { padding: 7px 12px !important; }
  .di { width: 34px !important; height: 34px !important; }
  .di i { font-size: 17px !important; }
  .dn { font-size: 0.9rem !important; }
  .ds { font-size: 0.72rem !important; }

  /* ── Colonne centrale (flèches) ── */
  .am { gap: 4px !important; padding: 6px 4px !important; }

  /* ── Panneau de détail ── */
  .dc  { padding: 0.45rem 0.8rem !important; }
  .dm  { padding: 5px 4px !important; gap: 6px !important; }
  .sec { margin-bottom: 6px !important; }
  .sec:last-child { margin-bottom: 0 !important; }

  /* ── Listes ── */
  .items { gap: 0 !important; }
  .items li {
    padding: 2px 5px !important;
    font-size: 0.82rem !important;
    line-height: 1.35 !important;
  }

  /* ── Section comptable ── */
  .sec-cpt {
    padding: 4px 7px !important;
    margin-bottom: 5px !important;
  }

  /* ── Titres de section ── */
  .st { margin-bottom: 4px !important; padding-bottom: 3px !important; }

  /* ── Badges ── */
  .abadge { padding: 3px 9px !important; margin-top: 5px !important; }

  /* ── Arrêter les animations SVG ── */
  .arr line, .arr polyline {
    animation: none !important;
    stroke-dasharray: 6 4 !important;
    stroke-dashoffset: 0 !important;
  }

  /* ── Hover désactivé ── */
  .items li:hover { background: transparent !important; }
  .acc:hover .ac  { filter: none !important; }

  /* ── Éviter les coupures de page ── */
  .acc, .phase, .cg, .legend, .moi-banner, .pg-hd { break-inside: avoid; }
}
