/* Bibliothèque 7G — onglet Calcul matière (l'ancien Coût matière 7G, 29/09/2026).
   Chargé APRÈS styles.css : les couleurs, l'en-tête et la connexion viennent de la bibliothèque ;
   tout ce qui suit est rangé sous .cm pour ne rien changer aux onglets Produits et Contacts. */
@font-face { font-family: "Lexend Exa"; src: url(/polices/lexend-exa.woff2) format("woff2"); font-weight: 500; font-display: swap; }
:root {
  --accent-ink: #FFFFFF; --orange-doux: #FBEBD3; --rouge-doux: #FBE1E2; --violet: #6F45B8; --violet-doux: #ECE4F8;
  --radius: 14px; --f-chiffres: "Lexend Exa", "Lexend", "Segoe UI", system-ui, sans-serif;
}
[data-theme="dark"] { --accent-ink: #0A1724; --orange-doux: #3A2A12; --rouge-doux: #3B1A1D; --violet: #B79BEA; --violet-doux: #2A2140; }
/* l'en-tête est collant : un champ qui prend le focus ne doit pas passer dessous */
html { scroll-padding-top: 84px; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.entete #voir-catalogue { min-height: 36px; }

/* ---------- champs et boutons ---------- */
.cm input[type=text], .cm input[type=number], .cm input[type=search], .cm select, .cm textarea {
  width: 100%; height: 38px; min-height: 0; padding: 0 11px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s; font-size: 14px; }
.cm textarea { height: auto; min-height: 80px; padding: 9px 11px; resize: vertical; }
.cm input:focus, .cm select:focus, .cm textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-doux); }
.cm input:disabled, .cm textarea:disabled { background: var(--surface2); color: var(--ink-soft); }
.cm input[type=number] { font-variant-numeric: tabular-nums; }
.cm .btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; min-height: 0; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.cm .btn:hover { filter: brightness(1.08); }
.cm .btn:disabled { opacity: .5; cursor: default; filter: none; }
.cm .btn.sec { background: var(--surface); color: var(--ink); border-color: var(--line-2); font-weight: 500; }
.cm .btn.sec:hover { border-color: var(--accent); filter: none; }
.cm .btn.danger { background: transparent; color: var(--rouge); border-color: transparent; font-weight: 500; }
.cm .btn.danger:hover { border-color: var(--rouge); filter: none; }
.cm .btn.plein { width: 100%; }
.cm .btn.vert { background: var(--vert); color: #fff; }
.cm .btn.violet { background: var(--violet); color: #fff; }
.cm .btn.petit { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.cm .seg { display: flex; gap: 3px; padding: 3px; border-radius: 11px; background: var(--surface2); border: 1px solid var(--line); }
.cm .seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 7px 10px; font-size: 13px; color: var(--muted); cursor: pointer; }
.cm .seg button[aria-checked=true] { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: var(--shadow-sm); }
[data-theme="dark"] .cm .seg button[aria-checked=true] { background: var(--accent-doux); }

/* ---------- mise en page ---------- */
.cm .page { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; max-width: 1400px; margin: 0 auto; padding: 20px 20px 110px; }
.cm .page-simple { display: grid; gap: 16px; align-content: start; max-width: 1000px; margin: 0 auto; padding: 20px 20px 110px; }
.cm .page-simple { grid-template-columns: minmax(0, 1fr); }
.cm .page-simple > * { min-width: 0; }
.cm .recherche input { height: 46px; padding-left: 42px; font-size: 15px; border-radius: 12px; box-shadow: var(--shadow-sm); }
.cm .colonne { display: grid; gap: 18px; align-content: start; min-width: 0; }
.cm .carte { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.cm .carte > h2 { margin: 0 0 14px; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cm .carte > h2 svg { color: var(--accent); }
.cm .carte > h2 .espace { flex: 1; }
.cm .carte > h2 #dos-titre { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--ink); }
.cm .grille { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.cm .grille.deux { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cm .plein-large { grid-column: 1 / -1; }
.cm .champ { display: grid; gap: 5px; font-size: 12.5px; color: var(--ink-soft); min-width: 0; }
.cm .champ small { color: var(--muted); font-size: 11.5px; }
.cm .aide { font-size: 12.5px; color: var(--muted); margin: 0; text-align: left; }
.cm .erreur { text-align: left; }
.cm .trace { margin: 12px 0 0; font-size: 11.5px; color: var(--muted); }
.cm .retour { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 500; font-size: 13px; margin: 0 0 10px -4px; text-decoration: none; }
.cm .retour svg { width: 16px; height: 16px; }
.cm .titre-page { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.cm .titre-page h1 { margin: 0 0 4px; font-size: 21px; font-weight: 600; }
.cm .filtres { margin: 0; }

/* ---------- dossiers ---------- */
.cm .dossier .vignette { font-size: 11px; }
.cm .dossier .fin { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cm .dossier .somme { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13px; }
.cm .statut { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: var(--surface2); color: var(--ink-soft); }
.cm .statut::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.cm .statut.st-envoye { background: var(--accent-doux); color: var(--accent); }
.cm .statut.st-valide { background: var(--vert-doux); color: var(--vert); }
.cm .statut.st-abandonne { background: var(--rouge-doux); color: var(--rouge); }
.cm .seg.statuts { margin-bottom: 14px; }
.cm .seg.statuts button[data-statut=envoye][aria-checked=true] { color: var(--accent); }
.cm .seg.statuts button[data-statut=valide][aria-checked=true] { color: var(--vert); }
.cm .seg.statuts button[data-statut=abandonne][aria-checked=true] { color: var(--rouge); }
.cm .n-bloc { margin-top: 14px; }
.cm .affaires { display: grid; gap: 4px; margin-top: 8px; max-height: 340px; overflow: auto; }
.cm .affaires button { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; cursor: pointer; color: var(--ink); }
.cm .affaires button:hover { border-color: var(--accent); }
.cm .affaires b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm .affaires small { grid-column: 1; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm .affaires em { grid-row: 1 / 3; grid-column: 2; align-self: center; font-style: normal; font-size: 11px; color: var(--muted); }
.cm .affaire-choisie { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); background: color-mix(in srgb, var(--accent-doux) 55%, var(--surface)); margin-bottom: 14px; }
.cm .affaire-choisie > svg { color: var(--accent); }
.cm .affaire-choisie div { flex: 1; min-width: 0; }
.cm .affaire-choisie b { display: block; }
.cm .affaire-choisie small { color: var(--ink-soft); font-size: 12.5px; }
.cm #n-choisie { margin: 12px 0 0; }
.cm .calculs-dossier { display: grid; gap: 8px; }
.cm .calc-ligne { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.cm .calc-ligne > a { color: var(--ink); text-decoration: none; min-width: 0; }
.cm .calc-ligne > a:hover b { color: var(--accent); }
.cm .calc-ligne b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm .calc-ligne small { display: block; color: var(--muted); font-size: 12px; }
.cm .calc-ligne .m { font: 500 17px/1 var(--f-chiffres); color: var(--accent); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.cm .calc-ligne .outils { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.cm .vide { padding: 22px; text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 12px; }
.cm .bandeau-lecture { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--orange-doux); color: var(--orange); font-size: 13px; font-weight: 500; }
.cm .lecture #carte-ajout, .cm .lecture #vider, .cm .lecture .suppr, .cm .lecture #f-note { display: none !important; }

/* recherche d'article */
.cm .cherche { position: relative; }
.cm .cherche svg { position: absolute; left: 11px; top: 11px; color: var(--muted); width: 16px; height: 16px; }
.cm .cherche input { padding-left: 34px; }
.cm .propositions { position: absolute; z-index: 20; left: 0; right: 0; top: 42px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 320px; overflow: auto; padding: 4px; }
.cm .propositions button { display: flex; justify-content: space-between; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.cm .propositions button:hover, .cm .propositions button.sel { background: var(--accent-doux); }
.cm .propositions small { color: var(--muted); display: block; font-size: 11.5px; }
.cm .propositions .prix { font-weight: 600; white-space: nowrap; }
.cm .propositions .vide { border: 0; }

.cm .cases { display: flex; flex-wrap: wrap; gap: 8px; }
.cm .case { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-size: 13px; user-select: none; }
.cm .case input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.cm .case b { color: var(--accent); font-weight: 600; }
.cm .case.coche { border-color: var(--accent); background: var(--accent-doux); }
.cm .case.tube.coche { border-color: var(--vert); background: var(--vert-doux); }
.cm .bloc-tube { border: 1px solid color-mix(in srgb, var(--vert) 35%, var(--line)); background: color-mix(in srgb, var(--vert-doux) 55%, var(--surface)); border-radius: 12px; padding: 12px; }
.cm .bloc-finitions { border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line)); background: color-mix(in srgb, var(--accent-doux) 45%, var(--surface)); border-radius: 12px; padding: 12px; }
.cm .bloc-finitions > span, .cm .bloc-tube > span { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 8px; }

/* aperçu de la ligne avant ajout */
.cm .apercu-ligne { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px;
  background: var(--surface2); border: 1px dashed var(--line-2); }
.cm .apercu-ligne .calc { color: var(--ink-soft); font-size: 13px; }
.cm .apercu-ligne .montant { font: 500 20px/1 var(--f-chiffres); color: var(--accent); font-variant-numeric: tabular-nums; }

/* faisabilité */
.cm details.carte > summary { list-style: none; cursor: pointer; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.cm details.carte > summary::-webkit-details-marker { display: none; }
.cm details.carte > summary svg { color: var(--accent); }
.cm details.carte > summary::after { content: "Afficher"; margin-left: auto; font-size: 12px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--accent); }
.cm details.carte[open] > summary::after { content: "Masquer"; }
.cm details.carte[open] > summary { margin-bottom: 14px; }
.cm .verdict { margin-top: 12px; border-radius: 12px; padding: 12px 14px; }
.cm .verdict.ok { background: var(--vert-doux); border: 1px solid color-mix(in srgb, var(--vert) 40%, transparent); }
.cm .verdict.ko { background: var(--orange-doux); border: 1px solid color-mix(in srgb, var(--orange) 45%, transparent); }
.cm .verdict b.titre { display: block; margin-bottom: 8px; }
.cm .verdict.ok b.titre { color: var(--vert); } .cm .verdict.ko b.titre { color: var(--orange); }
.cm .verdict .l { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid color-mix(in srgb, var(--ink) 10%, transparent); font-size: 13px; }
.cm .verdict .l:last-of-type { border-bottom: 0; }
.cm .verdict .l span { color: var(--ink-soft); }
.cm .verdict .rouge { color: var(--rouge); } .cm .verdict .vert { color: var(--vert); }
.cm .verdict .btn { margin-top: 10px; }

/* récapitulatif */
.cm .tableau { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.cm table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cm th { text-align: left; font-weight: 500; font-size: 11.5px; color: var(--muted); background: var(--surface2); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.cm td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.cm tr:last-child td { border-bottom: 0; }
.cm td.num, .cm th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cm td .fam { display: block; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.cm td .des { font-weight: 500; }
.cm td .det { color: var(--ink-soft); font-size: 12.5px; }
.cm td.total { font-weight: 600; color: var(--accent); }
.cm tr.libre td { background: color-mix(in srgb, var(--vert-doux) 45%, transparent); }
.cm tr.faisabilite td { background: color-mix(in srgb, var(--orange-doux) 55%, transparent); }
.cm td.vide { border: 0; border-radius: 0; }
.cm table .badge, .cm .legende .badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 600; vertical-align: 1px; }
.cm .legende .badge { margin-left: 0; }
.cm .badge.tube, .cm .badge.libre { background: var(--vert-doux); color: var(--vert); }
.cm .badge.faisabilite { background: var(--orange-doux); color: var(--orange); }
.cm .badge.prestation { background: var(--violet-doux); color: var(--violet); }
.cm .suppr { border: 0; background: none; color: var(--muted); cursor: pointer; width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; }
.cm .suppr:hover { color: var(--rouge); background: var(--rouge-doux); }
.cm .total-barre { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 14px; padding: 16px 18px; border-radius: 14px;
  background: linear-gradient(135deg, #17568A, #0C3D63 60%, #0A3252); color: #fff; }
.cm .total-barre small { display: block; opacity: .75; font-size: 12px; }
.cm .total-barre b { font: 500 28px/1 var(--f-chiffres); font-variant-numeric: tabular-nums; }
.cm .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 0; border-top: 0; align-items: center; }
.cm .actions .espace { flex: 1; }
.cm .etat-calcul { font-size: 12.5px; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 400; }
.cm .etat-calcul.alerte { color: var(--rouge); font-weight: 500; }

/* colonne de droite */
.cm .outil-res { font: 500 26px/1.1 var(--f-chiffres); color: var(--accent); text-align: center; padding: 10px 0 2px; font-variant-numeric: tabular-nums; }
.cm .outil-res small { font: 400 13px var(--f); color: var(--muted); }
.cm .liste-calculs { display: grid; gap: 4px; max-height: 420px; overflow: auto; }
.cm .liste-calculs a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; width: 100%; text-align: left; border: 1px solid transparent; border-radius: 10px; padding: 8px 10px; color: var(--ink); text-decoration: none; }
.cm .liste-calculs a:hover { background: var(--surface2); }
.cm .liste-calculs a.actif { border-color: var(--accent); background: var(--accent-doux); }
.cm .liste-calculs b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm .liste-calculs small { grid-column: 1; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm .liste-calculs .m { grid-row: 1 / 3; grid-column: 2; align-self: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.cm .legende { display: grid; gap: 7px; font-size: 12.5px; color: var(--ink-soft); }

/* catalogue (direction) */
.cm .cat-grille { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; }
.cm .cat-familles { display: grid; gap: 3px; align-content: start; max-height: 70vh; overflow: auto; }
.cm .cat-familles button { text-align: left; border: 1px solid transparent; background: none; border-radius: 9px; padding: 7px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.cm .cat-familles button:hover { background: var(--surface2); }
.cm .cat-familles button.actif { border-color: var(--accent); background: var(--accent-doux); }
.cm .cat-familles em { font-style: normal; color: var(--muted); font-size: 12px; }
.cm .cat-table input, .cm .cat-table select { height: 34px; }
.cm .cat-table td { padding: 5px 8px; }
.cm .cat-table td.p { width: 130px; }
.cm .cat-ligne { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cm .cat-histo { align-items: flex-end; margin: 12px 0 16px; }
.cm .cat-histo .champ { flex: 1; min-width: 220px; max-width: 460px; }

/* fenêtre de confirmation */
.voile { position: fixed; inset: 0; background: rgba(6,20,32,.45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.dialogue { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.dialogue p { margin: 0 0 16px; }
.dialogue .actions { display: flex; gap: 8px; justify-content: flex-end; margin: 0; padding: 0; border: 0; }

/* impression (PDF) : seule la fiche imprimable apparaît */
.impression { display: none; }
@media print {
  @page { size: A4; margin: 10mm 12mm 16mm; }
  html, body { background: #fff !important; color: #111 !important; }
  body > *:not(.impression) { display: none !important; }
  .impression { display: block; font: 10pt/1.4 Calibri, "Segoe UI", Arial, sans-serif; color: #111; padding-bottom: 12mm; }
  .impression img.entete { width: 100%; height: auto; display: block; margin-bottom: 7mm; }
  .impression h1 { font-size: 15pt; color: #0C3D63; margin: 0 0 1mm; text-transform: uppercase; letter-spacing: .03em; }
  .impression h2 { font-size: 12pt; color: #0C3D63; margin: 0 0 1mm; }
  .impression .infos { color: #444; margin-bottom: 5mm; }
  .impression .desc { border-left: 3px solid #0C3D63; background: #F2F6FA; padding: 3mm 4mm; margin-bottom: 5mm; white-space: pre-wrap; }
  .impression table { width: 100%; border-collapse: collapse; font-size: 9pt; }
  .impression th { background: #0C3D63; color: #fff; padding: 2mm 3mm; border: 0; text-align: left; font-weight: 600; }
  .impression td { border-bottom: .5pt solid #CCD6E0; padding: 2mm 3mm; background: none !important; }
  .impression .num { text-align: right; white-space: nowrap; }
  .impression tr { break-inside: avoid; }
  .impression tr.libre td { background: #F0FAF4 !important; }
  .impression tr.faisabilite td { background: #FFF8EA !important; }
  .impression .tot { margin-top: 5mm; display: flex; justify-content: space-between; align-items: center; padding: 4mm 5mm; background: #0C3D63; color: #fff; border-radius: 2mm; break-inside: avoid; }
  .impression .tot b { font-size: 15pt; }
  .impression .tot.leger { background: #F2F6FA; color: #0C3D63; }
  .impression .notes { margin-top: 4mm; font-size: 8pt; color: #555; }
  .impression .calcul-imp { break-before: page; }
  .impression .calcul-imp.premier { break-before: auto; }
  .impression .pied { position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 6.5pt; color: #595959; background: #fff; padding-top: 2mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* petits écrans */
@media (max-width: 1100px) { .cm .page { grid-template-columns: 1fr; } }
@media (max-width: 700px) {
  .cm .page, .cm .page-simple { padding: 14px 16px 100px; gap: 14px; }
  .cm .grille, .cm .grille.deux { grid-template-columns: 1fr; }
  .cm .carte { padding: 16px; }
  .cm .cat-grille { grid-template-columns: 1fr; }
  .cm .total-barre b { font-size: 24px; }
  .cm .seg button { padding: 7px 6px; font-size: 12.5px; }
  .entete #voir-catalogue .txt { display: none; }
  .entete #voir-catalogue { width: 38px; padding: 0; }
}
/* un champ sous 16 px fait zoomer l'iPhone */
@media (max-width: 820px) { .cm input, .cm select, .cm textarea { font-size: 16px; } }
/* espacement sous les onglets d'ajout */
.cm [data-bloc] { margin-top: 14px; }
