/* Module Chiffrage — s'appuie sur les variables de couleur du CRM (:root de index.html). */
#ch-root { max-width: 1280px; margin: 0 auto; }
#ch-root h2 { font-family: 'Sora', sans-serif; font-size: 16px; font-weight: 700; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
#ch-root h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink3); margin: 0 0 8px; font-weight: 700; }
.ch-num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-gradient); color: #fff; font-size: 12px; font-weight: 800; flex: none; }
.ch-aide { color: var(--ink3); font-size: 12.5px; margin: -4px 0 12px; }
.ch-carte { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 14px; }
.ch-bandeau { background: var(--amber-soft); border: 1px solid var(--amber-line); color: #8a4a05; border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.ch-bandeau.rouge { background: var(--red-soft); border-color: var(--red-line); color: #9b1c1c; }

/* Étapes */
.ch-entete { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.ch-titre { font-family: 'Sora', sans-serif; font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.ch-sous { font-size: 13px; color: var(--ink3); }
.ch-etapes { display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.ch-etape { border: 0; background: none; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--ink2); font-size: 13px; display: flex; align-items: center; gap: 7px; white-space: nowrap; font-family: inherit; }
.ch-etape span { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--line); font-size: 11px; }
.ch-etape.actif { background: var(--ink); color: #fff; }
.ch-etape.actif span { background: var(--brand-gradient); color: #fff; }
.ch-pied { position: sticky; bottom: -32px; margin: 8px -24px -32px; padding: 12px 24px; background: rgba(251, 247, 249, .94); backdrop-filter: blur(6px); border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 5; flex-wrap: wrap; }
.ch-pied-total { font-family: 'Sora', sans-serif; font-weight: 800; font-size: 20px; }
.ch-pied-total small { font-family: 'Inter', sans-serif; font-weight: 500; font-size: 12px; color: var(--ink3); margin-left: 6px; }

/* Champs */
.ch-champs { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.ch-champs label, .ch-champ { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink2); font-weight: 600; }
.ch-champs label.large { grid-column: 1 / -1; }
#ch-root input:not([type=checkbox]):not([type=range]):not([type=file]), #ch-root select, #ch-root textarea, #ch-nuancier input {
  border: 1px solid var(--line2); border-radius: var(--radius-sm); padding: 8px 10px; background: #fff; min-height: 38px; width: 100%;
  font-family: 'Inter', sans-serif; font-size: 14px; color: var(--ink);
}
#ch-root textarea { resize: vertical; line-height: 1.45; }
#ch-root input:focus, #ch-root select:focus, #ch-root textarea:focus, #ch-nuancier input:focus { outline: 2px solid var(--brand-pink-line); border-color: var(--accent); }
#ch-root input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.ch-coche { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--ink); }

/* Chiffrage */
.ch-grille { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.ch-recap-col { position: sticky; top: 0; }
.ch-ligne { display: grid; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.ch-zone { grid-template-columns: 180px minmax(200px, 1fr) 90px 90px 110px; }
.ch-zone.ch-tete { border-top: 0; padding-top: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink3); font-weight: 700; }
.ch-nom { font-weight: 600; font-size: 13.5px; }
.ch-decor { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ch-btn-vig { border: 0; padding: 0; background: none; cursor: pointer; flex: none; border-radius: 8px; }
.ch-vig { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; display: block; border: 1px solid var(--line); background: var(--paper); }
.ch-vig.vide { display: grid; place-items: center; color: var(--ink3); font-size: 10px; font-weight: 700; border-style: dashed; overflow: hidden; text-align: center; line-height: 1.1; }
.ch-btn-vig:hover .ch-vig { outline: 2px solid var(--accent); }
.ch-decor-saisie { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
#ch-root .ch-decor-saisie input { text-transform: uppercase; font-weight: 700; letter-spacing: .02em; }
.ch-decor-nom { font-size: 12px; color: var(--ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-cnum { display: flex; flex-direction: column; gap: 2px; }
.ch-cnum span { display: none; font-size: 11px; color: var(--ink3); font-weight: 600; }
#ch-root .ch-cnum input { text-align: right; }
.ch-tot { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13.5px; }
.ch-tot small { display: block; font-weight: 500; color: var(--ink3); font-size: 11.5px; }
.ch-forfait { grid-template-columns: minmax(0, 1fr) 150px 110px; }
.ch-forfait .ch-cnum span, .ch-support .ch-cnum span { display: block; }
.ch-support { grid-template-columns: 170px minmax(0, 1fr) 80px 110px 110px; }

.ch-badge { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .03em; padding: 2px 7px; border-radius: 999px; background: var(--paper); color: var(--ink3); vertical-align: middle; white-space: nowrap; }
.ch-badge.rouge { background: var(--red-soft); color: var(--red); }
.ch-badge.orange { background: var(--amber-soft); color: #b35c00; }
.ch-badge.vert { background: var(--green-soft); color: var(--green); }

.ch-recap { padding: 18px; }
.ch-recap-total { background: var(--brand-dark); color: #fff; border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.ch-recap-total span { color: #d9c7cf; font-size: 12px; display: block; }
.ch-recap-total strong { font-family: 'Sora', sans-serif; font-size: 28px; font-weight: 800; letter-spacing: -.02em; background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; font-variant-numeric: tabular-nums; }
.ch-dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-size: 13px; }
.ch-dl dt { color: var(--ink3); }
.ch-dl dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.ch-temps { margin-top: 14px; padding: 11px 12px; border-radius: 10px; background: var(--brand-orange-soft); font-size: 13px; }
.ch-temps span { display: block; color: #b35c00; font-weight: 700; }
.ch-bloc { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.ch-controles { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--red); }
.ch-controles strong { color: var(--ink); }
.ch-table-cmd { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; font-variant-numeric: tabular-nums; }
.ch-table-cmd th, .ch-table-cmd td { padding: 4px; text-align: right; border-bottom: 1px solid var(--line); }
.ch-table-cmd th:first-child, .ch-table-cmd td:first-child { text-align: left; }
#ch-root .ch-interne { display: none; }
#ch-root.interne .ch-interne { display: block; }

/* Nuancier */
#ch-nuancier { width: min(1100px, 96vw); height: min(820px, 92vh); border: 0; border-radius: 18px; padding: 0; box-shadow: 0 24px 70px rgba(0, 0, 0, .25); }
#ch-nuancier[open] { display: flex; flex-direction: column; }
#ch-nuancier::backdrop { background: rgba(26, 25, 23, .45); backdrop-filter: blur(3px); }
.ch-nu-tete { display: flex; gap: 12px; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.ch-nu-tete h2 { margin: 0; font-family: 'Sora', sans-serif; font-size: 16px; white-space: nowrap; }
.ch-nu-tete input { flex: 1; }
.ch-filtres { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 20px; border-bottom: 1px solid var(--line); align-items: center; }
.ch-filtres .ch-coche { margin-left: auto; font-size: 12.5px; color: var(--ink2); }
.ch-puce { border: 1px solid var(--line2); background: #fff; border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 12.5px; font-family: inherit; }
.ch-puce.actif { background: var(--ink); color: #fff; border-color: var(--ink); }
.ch-grille-decors { flex: 1; overflow-y: auto; padding: 16px 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; align-content: start; }
.ch-tuile { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 6px; cursor: pointer; text-align: left; position: relative; display: flex; flex-direction: column; gap: 2px; font-family: inherit; }
.ch-tuile:hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--brand-pink-soft); }
.ch-tuile-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--paper); display: block; }
.ch-tuile-img.vide { display: grid; place-items: center; color: var(--ink3); font-weight: 700; }
.ch-tuile-ref { font-weight: 800; font-size: 13px; }
.ch-tuile-lib { font-size: 11.5px; color: var(--ink3); line-height: 1.3; }
.ch-tuile .ch-badge { position: absolute; top: 10px; left: 10px; }
.ch-pastille { position: absolute; top: 12px; right: 12px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; background: var(--amber); }

/* Visualisation */
.ch-aa { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ch-aa .ch-carte { margin: 0; }
.ch-aa .large { grid-column: 1 / -1; }
.ch-photo { width: 100%; max-height: 340px; object-fit: contain; border-radius: 10px; background: var(--paper); display: block; }
.ch-depot { border: 2px dashed var(--line2); border-radius: 12px; padding: 38px 16px; text-align: center; color: var(--ink3); cursor: pointer; background: var(--paper); }
.ch-depot:hover, .ch-depot.survol { border-color: var(--accent); background: var(--brand-pink-soft); }
.ch-aa-zones { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.ch-aa-zone { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.ch-aa-zone span { display: flex; flex-direction: column; font-size: 13.5px; }
.ch-aa-zone small { color: var(--ink3); }
.ch-aa-zone.exclue { opacity: .5; }
.ch-boutons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.ch-prep { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin-top: 12px; }
.ch-planche { background: var(--paper); border-radius: 10px; padding: 8px; min-height: 120px; color: var(--ink3); font-size: 13px; }
.ch-planche canvas { width: 100%; height: auto; display: block; border-radius: 6px; }
.ch-comp { position: relative; border-radius: 14px; overflow: hidden; background: #111; user-select: none; }
.ch-comp > img, .ch-comp-avant img { display: block; width: 100%; height: auto; max-height: 76vh; object-fit: contain; }
.ch-comp-avant { position: absolute; inset: 0; }
.ch-comp-poignee { position: absolute; top: 0; bottom: 0; width: 3px; background: #fff; transform: translateX(-50%); pointer-events: none; box-shadow: 0 0 8px rgba(0, 0, 0, .4); }
.ch-comp-poignee span { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; color: var(--ink); border-radius: 50%; width: 40px; height: 40px; display: grid; place-items: center; font-weight: 800; box-shadow: 0 2px 8px rgba(0, 0, 0, .3); }
.ch-comp input[type=range] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.ch-comp-et { position: absolute; top: 12px; background: rgba(38, 15, 18, .72); color: #fff; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; pointer-events: none; }
.ch-comp-et.g { left: 12px; } .ch-comp-et.d { right: 12px; }
.ch-comp:fullscreen { display: flex; align-items: center; border-radius: 0; }
.ch-comp:fullscreen > img, .ch-comp:fullscreen .ch-comp-avant img { max-height: 100vh; height: 100vh; }

/* Devis (aperçu au format Pennylane) */
.ch-doc { background: #fff; max-width: 880px; margin: 0 auto 14px; padding: 40px 46px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); color: #1f1418; }
.ch-doc-tete { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.ch-doc-logo { display: flex; align-items: center; gap: 10px; font-family: 'Sora', sans-serif; font-weight: 800; font-size: 22px; }
.ch-doc-logo img { width: 46px; height: 46px; object-fit: contain; }
.ch-doc-titre { text-align: right; }
.ch-doc-titre strong { font-family: 'Sora', sans-serif; font-size: 24px; display: block; }
.ch-doc-titre span { color: var(--ink3); font-size: 13px; display: block; }
.ch-doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 26px 0 18px; font-size: 13.5px; }
.ch-doc-parties div { background: var(--paper); border-radius: 10px; padding: 12px 14px; }
.ch-doc-parties h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink3); }
.ch-doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ch-doc-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink3); padding: 8px 6px; border-bottom: 2px solid var(--ink); }
.ch-doc-table td { padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ch-doc-table .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ch-doc-table small { display: block; color: var(--ink3); font-size: 12px; margin-top: 2px; }
.ch-doc-totaux { margin: 16px 0 0 auto; width: 300px; max-width: 100%; font-size: 13.5px; }
.ch-doc-totaux div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.ch-doc-ttc { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px !important; font-family: 'Sora', sans-serif; font-size: 18px; font-weight: 800; }
.ch-doc-note { font-size: 12px; color: var(--ink3); margin: 14px 0 0; line-height: 1.5; }
.ch-doc-signature { margin-top: 26px; font-size: 12.5px; color: var(--ink3); }
.ch-doc-signature div { height: 86px; border: 1px dashed var(--line2); border-radius: 10px; margin-top: 6px; }
.ch-doc-aa { margin-top: 26px; }
.ch-doc-aa-img { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ch-doc-aa-img figure { margin: 0; }
.ch-doc-aa-img img { width: 100%; border-radius: 8px; display: block; }
.ch-doc-aa-img figcaption { font-size: 12px; color: var(--ink3); text-align: center; margin-top: 4px; }
.ch-options-devis { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.ch-options-devis label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink2); min-width: 150px; }

/* Liste des chiffrages */
.ch-liste { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.ch-fiche { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: transform .15s, box-shadow .15s; }
.ch-fiche:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.ch-fiche-nom { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 15px; }
.ch-fiche-meta { font-size: 12.5px; color: var(--ink3); }
.ch-fiche-total { font-family: 'Sora', sans-serif; font-weight: 800; font-size: 19px; }
.ch-vide { grid-column: 1 / -1; text-align: center; padding: 50px 20px; color: var(--ink3); }

/* Téléphone / tablette */
@media (max-width: 1080px) {
  .ch-grille { grid-template-columns: 1fr; }
  .ch-recap-col { position: static; }
}
@media (max-width: 820px) {
  .ch-zone.ch-tete { display: none; }
  .ch-zone { grid-template-columns: 1fr 1fr; padding: 12px 0; }
  .ch-zone .ch-nom, .ch-zone .ch-decor, .ch-zone .ch-tot { grid-column: 1 / -1; }
  .ch-cnum span { display: block; }
  .ch-forfait { grid-template-columns: 1fr 110px; }
  .ch-forfait .ch-tot { grid-column: 1 / -1; }
  .ch-support { grid-template-columns: 1fr 1fr; }
  .ch-support .ch-coche, .ch-support select, .ch-support .ch-tot { grid-column: 1 / -1; }
  .ch-aa, .ch-prep { grid-template-columns: 1fr; }
  .ch-doc { padding: 22px 16px; }
  .ch-doc-parties { grid-template-columns: 1fr; }
  .ch-doc-table th:nth-child(3), .ch-doc-table td:nth-child(3), .ch-doc-table th:nth-child(5), .ch-doc-table td:nth-child(5) { display: none; }
  .ch-pied { margin: 8px -12px -32px; padding: 10px 12px; }
  .ch-etape { padding: 7px 9px; }
  .ch-nu-tete { flex-wrap: wrap; }
  .ch-nu-tete input { flex-basis: 100%; order: 3; }
  .ch-grille-decors { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); }
}

/* Impression du devis seul */
@media print {
  html, body { height: auto !important; overflow: visible !important; display: block !important; background: #fff !important; }
  body.ch-impression * { visibility: hidden !important; }
  body.ch-impression #ch-doc, body.ch-impression #ch-doc * { visibility: visible !important; }
  body.ch-impression .stage, body.ch-impression .view { position: static !important; overflow: visible !important; }
  body.ch-impression #ch-doc { position: absolute; left: 0; top: 0; width: 100%; max-width: none; border: 0; box-shadow: none; padding: 0; margin: 0; }
  @page { margin: 14mm; }
}

/* Rappel du calcul par paliers */
.ch-paliers { margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--panel); font-size: 13px; color: var(--ink); }
.ch-paliers summary { cursor: pointer; font-weight: 600; }
.ch-paliers p, .ch-paliers ul { margin: 8px 0; }
.ch-paliers ul { padding-left: 20px; }
.ch-formule { padding: 8px 10px; border-radius: 8px; background: rgba(232, 10, 97, .06); font-variant-numeric: tabular-nums; }
