/* CRM prospection — lots 3 et 4 : bons de commande, document imprimable, page publique de signature, réglages.
   Complète app.css (classes .paper, .sigbox, .stamp, .chips… réutilisées) ; feuille d'impression en fin de fichier. */

/* Page d'un bon : document à gauche, panneau d'actions à droite (une colonne sur mobile) */
.bon-layout{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:16px;align-items:start}
.bon-panel{display:flex;flex-direction:column;gap:12px;min-width:0}
.bon-card{display:flex;flex-direction:column;gap:8px}
.bon-card .card-h{margin-bottom:2px}
.bon-acts{display:flex;flex-wrap:wrap;gap:6px}
.bon-line{display:flex;justify-content:space-between;gap:8px;align-items:center;flex-wrap:wrap;padding:4px 0;border-bottom:1px solid var(--line)}
.bon-line:last-child{border-bottom:0}
.bon-el{display:grid;grid-template-columns:110px minmax(0,1fr) auto;gap:6px;align-items:center}
.bon-hash{word-break:break-all;font-size:.72rem}
.bon-warn{margin:6px 0 0;padding-left:18px}
.bon-log summary{cursor:pointer;color:var(--accent-2)}
.bon-log table td{padding:4px 6px;vertical-align:top}
.chips .chip b{font-family:var(--f-mono);font-weight:500;margin-left:4px;opacity:.8}

/* Éditeur */
.bon-ed{display:grid;grid-template-columns:minmax(0,1fr) 280px;gap:18px;align-items:start}
.bon-ed-main{display:flex;flex-direction:column;gap:16px;min-width:0}
.bon-ed-main section{display:flex;flex-direction:column;gap:10px}
.bon-ed-recap{position:sticky;top:0;background:var(--surface-2);border:1px solid var(--line);border-radius:8px;padding:12px;display:flex;flex-direction:column;gap:8px}
.bon-ed-recap table td{padding:5px 4px;background:transparent}
.bon-pres{display:flex;flex-direction:column;border:1px solid var(--line);border-radius:8px;max-height:220px;overflow:auto}
.bon-pres button{text-align:left;border:0;border-bottom:1px solid var(--line);background:var(--surface);padding:8px 10px;cursor:pointer}
.bon-pres button:hover{background:var(--surface-2)}
.bon-pres .tiny{padding:8px 10px}
.bon-issues{display:flex;flex-direction:column;gap:6px}
.bon-issue{display:flex;gap:8px;align-items:center;flex-wrap:wrap;text-align:left;border:1px solid var(--line);border-radius:7px;background:var(--surface);padding:7px 10px;cursor:pointer;color:var(--fg)}
.bon-issue.on{border-color:var(--accent);background:var(--accent-soft)}
.bon-issue .bd-chk{border-color:currentColor}
.bon-lines{display:flex;flex-direction:column;gap:8px}
.bon-lrow{display:grid;grid-template-columns:minmax(0,1.6fr) minmax(0,1fr) minmax(0,.9fr) 70px auto;gap:8px;align-items:end;padding:8px;border:1px solid var(--line);border-radius:8px}
.bon-lrow .f input + input{margin-top:4px}

/* Réglages */
.reg-row{display:flex;justify-content:space-between;gap:12px;align-items:center;flex-wrap:wrap;padding:8px 0;border-bottom:1px solid var(--line)}
.reg-row:last-child{border-bottom:0}
.reg-row > div:first-child{flex:1;min-width:220px}
.reg-row input,.reg-row select{min-width:200px}

/* Document (rendu par BONDOC, mêmes styles dans le CRM et sur la page publique) */
.bon-paper{position:relative;overflow:hidden;max-width:760px;line-height:1.35}
.bon-paper > *{position:relative;z-index:1}
.bon-paper.draft::before{content:"APERÇU — SANS VALEUR CONTRACTUELLE";position:absolute;z-index:0;top:38%;left:-15%;right:-15%;text-align:center;transform:rotate(-26deg);font:700 34px/1.2 var(--f-display);color:rgba(191,52,52,.14);pointer-events:none;letter-spacing:.04em}
.bd-head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start;border-bottom:2px solid #5a6b82;padding-bottom:10px}
.bd-title{font-family:var(--f-display);font-size:19px;font-weight:700}
.bd-sub{font-size:10.5px;color:#555}
.bd-num{text-align:right;min-width:150px}
.bd-label{font-weight:700;font-size:13px}
.bd-mono{font-family:var(--f-mono)}
.bd-info{font-size:10px;color:#666;margin-top:4px}
.bd-band{background:#0f3d6e;color:#fff;font-size:10px;padding:6px 8px;margin-top:8px;border-radius:2px}
.bd-zone{font-size:11px;margin-top:8px}
.bd-fields{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 16px;margin:12px 0}
.bd-fields > div{font-size:11px;border-bottom:1px dotted #bbb;padding:2px 0;overflow-wrap:anywhere}
.bd-fields span{color:#666}
.bd-p{font-size:11px;margin-bottom:8px}
.bd-grid{display:grid;grid-template-columns:minmax(0,1.15fr) minmax(0,1fr);gap:14px}
.bd-tbl{background:#f6f6f6;width:100%}
.bd-tbl td,.bd-tbl th{color:#1a1a1a}
.bd-lines{margin:0 0 10px}
.paper .bd-tbl th{text-transform:none;letter-spacing:0;white-space:normal;font-size:10.5px}
.bd-r{text-align:right;white-space:nowrap}
.bd-cap{font-size:10px;font-weight:700;margin-bottom:4px;text-transform:uppercase;letter-spacing:.02em}
.bd-note{font-size:10px;color:#666;margin-top:3px}
.bd-total{font-size:11px;margin-top:4px}
.bd-side{font-size:11px;display:flex;flex-direction:column;gap:6px}
.bd-box{border:1px solid #ccc;padding:6px;min-height:58px;overflow-wrap:anywhere}
.bd-dim{color:#666}
.bd-blank{color:#aaa}
.bd-todo{color:#a86b0b;font-style:italic}
.bd-att{font-size:10px;color:#444;margin-top:8px;border:1px solid #ddd;padding:6px}
.bd-cgv{font-size:9.5px;color:#555;margin-top:8px;columns:2;column-gap:16px}
.bd-sig3{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin-top:10px;font-size:10px}
.bd-sig3 > div{border:1px solid #ccc;padding:6px}
.bd-sig3 .sigbox{height:46px;margin-top:4px}
.bd-sign{font-family:"Brush Script MT","Segoe Script",cursive;font-size:15px;color:#1a3d8f}
.bd-chk{display:inline-block;width:11px;height:11px;border:1px solid #333;vertical-align:-1px;text-align:center;line-height:10px;font-size:10px}
.bd-foot{font-size:9.5px;color:#666;margin-top:8px;border-top:1px solid #ddd;padding-top:6px;overflow-wrap:anywhere}
.bd-signed{margin-top:8px;border:1px solid #1d7f4c;color:#14532d;background:#eef8f1;padding:6px 8px;font-size:10.5px}
.bd-hash{word-break:break-all;font-size:9.5px}
.bd-retract{margin-top:10px;font-size:10px;color:#333;border-top:1px dashed #bbb;padding-top:8px}
.bd-retract p,.retract-form p{margin:4px 0}
.retract-form{margin-top:10px;font-size:10.5px;border:1px solid #999;padding:10px}

/* Gabarits versions 2 et 3 : image du bon papier (1240 × 1754 px, A4) en fond, valeurs posées en pourcentages de la page ;
   tailles en unités de conteneur (cqw) : le texte suit la largeur de la page, à l'écran comme à l'impression */
.bon-paper.bon-v2{max-width:860px;padding:0;background:transparent;border:0;border-radius:0;box-shadow:none;overflow:visible;
  display:flex;flex-direction:column;gap:16px;line-height:1.2;--bp-ink:#16307a;--bp-font:"Patrick Hand","Comic Neue","Comic Sans MS",cursive}
.bon-v2.draft::before{content:none}
.bp-sheet{position:relative;width:100%;background:#fff;box-shadow:0 2px 10px rgba(0,0,0,.12);overflow:hidden}
.bp-p1{aspect-ratio:1240/1754;container-type:inline-size}
.bp-img{position:absolute;inset:0;width:100%;height:100%;display:block;user-select:none;-webkit-user-select:none;pointer-events:none}
/* Valeurs jamais rognées (overflow visible) : réduites au besoin après mesure dans la police réellement chargée (BONDOC.fit) */
.bp-f{position:absolute;z-index:2;color:var(--bp-ink);font-family:var(--bp-font);white-space:nowrap;overflow:visible;line-height:1.2}
.bp-f.r{text-align:right}
.bp-f.c{text-align:center}
.bp-dense{background:rgba(255,255,255,.92)}
.bp-num{letter-spacing:.02em}
.bp-num0{color:#8a8f99;font-family:var(--f-body);font-style:italic}
.bp-x{position:absolute;z-index:2;transform:translate(-50%,-52%);color:var(--bp-ink);font-family:var(--f-body);font-weight:700;line-height:1}
.bp-sig{position:absolute;z-index:2;display:flex;flex-direction:column;justify-content:center;align-items:flex-start;gap:.15em;padding:0 .6cqw;
  color:var(--bp-ink);font-family:var(--f-body);line-height:1.2}
.bp-sig > div{white-space:nowrap;max-width:100%}
.bp-sig .bp-sname{font-family:var(--bp-font);line-height:1.05}
.bp-sig .bp-hash{font-family:var(--f-mono)}
.bp-sig-client{border-left:.25cqw solid var(--bp-ink)}
.bp-sig-regie{align-items:center}
.bp-sig-regie .stamp{border:.18cqw solid #1d7f4c;color:#1d7f4c;padding:.3cqw .9cqw;transform:rotate(-4deg);font-weight:700;border-radius:.4cqw;font-family:var(--f-body)}
.bp-patch{position:absolute;z-index:2;display:flex;align-items:center;justify-content:center;color:var(--bp-ink);font-family:var(--bp-font);white-space:nowrap}
.bp-warns{position:absolute;z-index:4;top:0;left:0;right:0}
.bp-warn{background:#fff3cd;color:#7a4b00;border-bottom:1px solid #e0c36b;font-family:var(--f-body);font-size:max(11px,1.3cqw);padding:.6cqw 1.2cqw}
.bp-warn[hidden]{display:none}
.bp-draft{position:absolute;z-index:3;left:-25%;right:-25%;top:46%;text-align:center;white-space:nowrap;transform:rotate(-54deg);pointer-events:none;
  font:700 5.6cqw/1.2 var(--f-display);color:rgba(191,52,52,.2);letter-spacing:.04em}
/* Bouton « Agrandir » de la page 1 (petit écran seulement) : case à cocher masquée et son étiquette, sans script */
.bon-v2 .bp-zoom-cb{position:absolute;opacity:0;width:1px;height:1px;margin:0;pointer-events:none}
.bp-zoom,.bp-zoom-out{display:none}
.bp-scroll{position:relative;max-width:100%}
.bp-annex{padding:28px 32px;font-size:11.5px;line-height:1.4;color:#1a1a1a}
.bp-annex .bp-draft{font-size:34px;top:30%}
.bp-annex-h{font-size:12.5px;border-bottom:1px solid #ccc;padding-bottom:6px;margin-bottom:10px}
.bp-block{margin-bottom:12px;overflow-wrap:break-word}
.bp-block p{margin:3px 0}
.bp-annex .bd-retract{margin-top:12px;font-size:11px}
.bp-annex .retract-form{font-size:11px}

/* Page publique de signature */
.sg-wrap{max-width:900px;margin:0 auto;padding:20px 16px 60px;display:flex;flex-direction:column;gap:16px}
.sg-head{display:flex;align-items:center;gap:10px;justify-content:space-between;flex-wrap:wrap}
.sg-card{background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:18px;display:flex;flex-direction:column;gap:12px}
.sg-card h1{font-size:1.3rem}
.sg-msg{font-size:.92rem;min-height:1.2em}
.sg-msg.bad{color:var(--bad)} .sg-msg.ok{color:var(--ok)}
.sg-code{font-family:var(--f-mono);font-size:1.4rem;letter-spacing:.3em;max-width:220px;text-align:center}
.sg-check{display:flex;gap:10px;align-items:flex-start;font-size:.9rem}
.sg-check input{width:18px;height:18px;margin-top:2px;flex:none}
.sg-ok{border-color:var(--ok);background:var(--ok-soft)}

@media (max-width:1180px){.bon-layout{grid-template-columns:1fr}}
@media (max-width:860px){.bon-ed{grid-template-columns:1fr}.bon-ed-recap{position:static}.bon-lrow{grid-template-columns:1fr 1fr}}
/* Document sur petit écran seulement : l'impression garde la disposition du modèle papier */
@media screen and (max-width:860px){.bd-grid,.bd-fields{grid-template-columns:1fr}.bd-sig3{grid-template-columns:1fr}.bd-cgv{columns:1}
  /* Bon papier (versions 2 et 3) : page 1 agrandie à la demande (1000 px, défilement horizontal dans le cadre, la page elle-même ne défile pas) */
  .bon-v2 .bp-zoom{display:inline-flex;align-self:flex-start;align-items:center;border:1px solid var(--line);border-radius:7px;background:var(--surface);color:var(--fg);
    padding:8px 12px;font-family:var(--f-body);font-size:.88rem;cursor:pointer}
  .bon-v2 .bp-zoom-cb:focus-visible + .bp-zoom{outline:2px solid var(--accent);outline-offset:2px}
  .bon-v2 .bp-zoom-cb:checked + .bp-zoom .bp-zoom-in{display:none}
  .bon-v2 .bp-zoom-cb:checked + .bp-zoom .bp-zoom-out{display:inline}
  .bon-v2 .bp-zoom-cb:checked ~ .bp-scroll{overflow-x:auto;-webkit-overflow-scrolling:touch;box-shadow:0 2px 10px rgba(0,0,0,.12)}
  .bon-v2 .bp-zoom-cb:checked ~ .bp-scroll .bp-p1{width:1000px;max-width:none}
  .bp-annex{padding:18px 16px}}

/* Impression : seul le document est imprimé (technique « visibility », valable aussi dans une fenêtre) */
@media print{
  @page{size:A4;margin:10mm}
  html,body{background:#fff !important;height:auto}
  body *{visibility:hidden}
  .side,.top,.bon-panel,.toasts,.no-print{display:none !important}
  .paper,.paper *{visibility:visible}
  .app,.main,.content,.bon-layout,.bon-doc,.sg-wrap{display:block;padding:0;margin:0;gap:0}
  .paper{position:absolute;left:0;top:0;width:100%;max-width:none;margin:0;border:0;border-radius:0;box-shadow:none;padding:0;font-size:9pt;color:#000;
    -webkit-print-color-adjust:exact;print-color-adjust:exact}
  .paper .bd-title{font-size:15pt} .paper .bd-label{font-size:10pt}
  .paper .bd-fields > div,.paper .bd-side,.paper .bd-zone,.paper .bd-p,.paper .bd-total{font-size:8.5pt}
  .paper table td,.paper table th{font-size:8.5pt;padding:3pt 5pt}
  .paper .bd-cgv,.paper .bd-foot,.paper .bd-sig3,.paper .bd-att,.paper .bd-retract{font-size:7.5pt}
  .paper .retract-form{break-before:page;font-size:9pt}
  .paper .bd-sig3,.paper .bd-signed{break-inside:avoid}
  .bon-paper.draft::before{color:rgba(191,52,52,.18)}
  /* Bon papier (versions 2 et 3) : page 1 = une page A4 exacte, sans marge (page nommée « bonpapier »), annexe sur les pages suivantes, avec
     les marges de la page par défaut. Document dans le flux normal (position statique) : Chrome n'applique pas la page
     nommée à une boîte positionnée hors flux (elle sortirait réduite, avec des marges). Rien d'imprimé ne la précède :
     tout ce qui l'entoure est masqué (display:none) ci-dessus. */
  .bon-paper.bon-v2{position:static;display:block;max-width:none;gap:0}
  .bon-v2 .bp-scroll{overflow:visible;box-shadow:none;break-after:page}
  .bon-v2 .bp-scroll:last-child{break-after:auto}
  .bon-v2 .bp-sheet{box-shadow:none}
  .bon-v2 .bp-p1{page:bonpapier;width:210mm;height:297mm;aspect-ratio:auto;break-inside:avoid}
  .bon-v2 .bp-annex{width:auto;padding:4mm 6mm;font-size:9.5pt;break-inside:auto}
  .bon-v2 .bp-annex .bd-retract,.bon-v2 .bp-annex .retract-form{font-size:9pt}
  .bon-v2 .retract-form{break-before:auto;break-inside:avoid}
  .bon-v2 .bp-annex .bp-draft{font-size:30pt}
}
@page bonpapier{size:A4;margin:0}

/* Lot 4 : solde d'un bon, échéancier, tableaux compacts du panneau */
.fin-bal{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
.fin-bal > div{display:flex;flex-direction:column;gap:2px;background:var(--surface-2);border-radius:7px;padding:6px 8px}
.fin-mini td{padding:5px 4px;vertical-align:top;background:transparent}
.fin-sched{width:100%;margin-top:8px}
.fin-sched td{padding:4px}
.fin-sched input{min-width:0}
