/* Impré'son — Bon de commande à l'écran (bon-ecran.html)
 * Le bon papier redessiné en page web : même mise en page que le PDF, cases cliquables.
 * La feuille est dessinée à 1123 px de large (A4 paysage) puis réduite à la largeur de l'écran
 * par bon-ecran.js (--echelle). À l'impression, elle remplit une page A4 paysage. */

.bon-ecran-page {
    --bleu-bon: #0b4f9c;
    --orange-bon: #ef7d00;
    --trait-bon: #94a3b8;
    max-width: 1220px;
    margin: 0 auto;
    padding: 1.25rem 16px 2.5rem;
}

/* ---------- Barre au-dessus du bon ---------- */
.bon-barre { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.bon-titre-page { font-size: 1.45rem; color: var(--bleu-fonce, #0a2540); font-weight: 800; margin-bottom: 0.25rem; }
.bon-aide { color: var(--texte-discret, #64748b); font-size: 0.92rem; max-width: 640px; }
.bon-barre-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.bon-btn-principal, .bon-btn-secondaire {
    display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0.6rem 1.2rem;
    border-radius: 10px; font: inherit; font-weight: 800; cursor: pointer; text-decoration: none;
}
.bon-btn-principal { background: var(--orange-action, #c2410c); color: #fff; border: none; box-shadow: 0 4px 12px rgba(194, 65, 12, 0.25); }
.bon-btn-principal:hover { background: var(--orange-action-survol, #9a3412); }
.bon-btn-secondaire { background: #fff; color: var(--bleu-fonce, #0a2540); border: 1px solid var(--bordure-subtile, #e2e8f0); }

.bon-astuce-rotation { display: none; margin: 0 0 0.8rem; padding: 0.6rem 0.8rem; border-radius: 8px; background: #eff6ff; color: #1e3a8a; font-size: 0.88rem; }
@media (max-width: 700px) and (orientation: portrait) { .bon-astuce-rotation { display: block; } }

.bon-erreurs { margin: 0 0 0.8rem; padding: 0.7rem 0.9rem; border-radius: 8px; background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; font-weight: 600; font-size: 0.92rem; }
.bon-pied { margin-top: 0.9rem; font-size: 0.85rem; color: var(--texte-discret, #64748b); }

/* ---------- Feuille (dessinée à 1123 px, réduite à l'écran) ---------- */
.feuille-cadre { position: relative; width: 100%; overflow: hidden; }
.feuille {
    --echelle: 1;
    width: 1123px; transform: scale(var(--echelle)); transform-origin: 0 0;
    background: #fff; color: #0f172a; border-radius: 6px; box-shadow: 0 6px 24px rgba(15, 23, 42, 0.12);
    padding: 18px 24px 20px; font-size: 11.5px; line-height: 1.3; font-family: inherit;
}
.feuille *, .feuille *::before, .feuille *::after { box-sizing: border-box; }
.bon-ecran-page [hidden] { display: none !important; }

.f-entete { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--bleu-bon); padding-bottom: 6px; margin-bottom: 10px; }
.f-logo img { display: block; width: 165px; height: auto; }
.f-titre { text-align: right; }
.f-titre strong { display: block; font-size: 26px; font-weight: 900; color: var(--bleu-bon); letter-spacing: 0.5px; }
.f-numero { display: block; font-size: 12px; font-weight: 700; color: #0f172a; margin-top: 2px; }

.f-ligne { display: grid; gap: 10px; margin-bottom: 10px; }
.f-ligne > *, .f-deux-colonnes > * { min-width: 0; }
.f-ligne-haut { grid-template-columns: 1fr 1fr 1fr; }
.f-ligne-milieu { grid-template-columns: 1.12fr 1fr; align-items: start; }
.f-ligne-bas { grid-template-columns: 1.12fr 1fr; margin-bottom: 0; }

.f-cadre { border: 1.5px solid var(--bleu-bon); border-radius: 6px; overflow: hidden; min-height: 104px; }
.f-cadre.f-orange { border-color: var(--orange-bon); }
.f-bandeau { background: var(--bleu-bon); color: #fff; font-size: 10.5px; font-weight: 800; text-transform: uppercase; padding: 4px 10px; margin: 0; letter-spacing: 0.2px; }
.f-orange .f-bandeau { background: var(--orange-bon); }
.f-corps { padding: 4px 10px 6px; }
.f-corps-centre { display: flex; flex-direction: column; justify-content: center; min-height: 80px; gap: 3px; }
.f-petit { display: block; font-size: 10.5px; color: #64748b; font-weight: 700; margin-bottom: 2px; }
.f-adresse { font-size: 10.5px; color: #475569; margin: 3px 0 0; white-space: pre-line; }

/* Lignes à remplir : un champ posé sur un trait, comme sur le papier */
.f-ligne-saisie { display: flex; align-items: center; gap: 6px; margin: 1px 0; flex-wrap: nowrap; }
.f-ligne-saisie > span { white-space: nowrap; font-weight: 600; }
.feuille input[type="text"], .feuille input[type="email"], .feuille input[type="date"] {
    flex: 1; min-width: 0; height: 19px; border: none; border-bottom: 1px solid var(--trait-bon); border-radius: 0;
    background: transparent; font: inherit; font-size: 12px; color: #0f172a; padding: 0 2px;
}
.feuille input[type="date"] { max-width: 150px; }
.feuille input:focus, .feuille textarea:focus, .feuille select:focus { outline: 2px solid #93c5fd; outline-offset: 1px; background: #eff6ff; }
.f-gain { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.f-gain > span { white-space: nowrap; font-weight: 600; }

/* Cases à cocher carrées (bleu du bon) : radios et cases ont la même allure que sur le papier */
.feuille input[type="checkbox"], .feuille input[type="radio"] {
    appearance: none; -webkit-appearance: none; flex: 0 0 auto;
    width: 14px; height: 14px; margin: 0; border: 1.5px solid var(--bleu-bon); border-radius: 3px; background: #fff;
    cursor: pointer; vertical-align: middle; print-color-adjust: exact; -webkit-print-color-adjust: exact;
}
.feuille input[type="checkbox"]:checked, .feuille input[type="radio"]:checked {
    background: var(--bleu-bon) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.f-case { display: inline-flex; align-items: center; gap: 5px; margin: 1px 9px 1px 0; cursor: pointer; white-space: nowrap; }
.f-case.f-fort, .f-fort { font-weight: 800; }
.f-cases-ligne { display: flex; align-items: center; flex-wrap: wrap; gap: 1px 4px; margin: 2px 0; }
.f-cases-ligne > span { margin-right: 6px; }
.f-cases-ligne.f-entre { justify-content: space-between; }
.f-orange-texte { color: var(--orange-bon) !important; }

/* Panneau fabrication */
.f-panneau { border: 1.5px solid #cbd5e1; border-radius: 8px; background: #f8fafc; padding: 7px; }
.f-matieres { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 7px; }
.f-matiere { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 5px; border-radius: 7px; font-weight: 800; font-size: 12px; cursor: pointer; }
.f-matiere-resine { background: #e0e7ff; border: 1.5px solid #a5b4fc; color: #1e3a8a; }
.f-matiere-silicone { background: #ffedd5; border: 1.5px solid #fdba74; color: var(--orange-bon); }
.f-matiere-silicone input[type="radio"] { border-color: var(--orange-bon); }
.f-matiere-silicone input[type="radio"]:checked { background-color: var(--orange-bon); }
.f-aspect { display: flex; align-items: center; justify-content: center; gap: 14px; border: 1.5px dashed #cbd5e1; border-radius: 7px; padding: 3px; margin-bottom: 7px; font-weight: 800; background: #fff; }
.f-deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.f-colonne-droite { display: flex; flex-direction: column; gap: 8px; }
.f-sous-cadre { border: 1.5px solid #cbd5e1; border-radius: 7px; background: #fff; padding: 5px 9px 6px; }
.f-sous-titre { font-size: 11px; font-weight: 800; color: var(--bleu-bon); text-transform: uppercase; margin: 0 0 3px; padding-bottom: 3px; border-bottom: 1px solid #e2e8f0; }
.f-creux { display: inline-flex; align-items: center; gap: 6px; border: 1.5px dashed var(--orange-bon); border-radius: 6px; padding: 3px 8px; margin-top: 4px; color: var(--orange-bon); font-weight: 800; }
.f-creux input[type="checkbox"] { border-color: var(--orange-bon); }
.f-note-centre { text-align: center; font-size: 10px; font-weight: 700; margin: 4px 0 0; }

/* Pastilles de couleur des protections : une colonne par couleur, une ligne D et une ligne G */
.f-pastilles { display: grid; grid-template-columns: 14px repeat(var(--nb, 7), 1fr); gap: 3px 4px; align-items: center; justify-items: center; margin: 3px 0 6px; }
.f-pastilles .f-cote { font-size: 10px; font-weight: 800; }
.f-pastilles .f-cote-d { color: #dc2626; }
.f-pastilles .f-cote-g { color: #2563eb; }
.f-pastille { display: inline-block; width: 18px; height: 18px; border-radius: 4px; background: var(--teinte, #fff); border: 1px solid rgba(15, 23, 42, 0.25); print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.f-pastille[data-couleur="blanc"], .f-pastille[data-couleur="translucide"] {
    background: repeating-conic-gradient(#e2e8f0 0 25%, #fff 0 50%) 0 0 / 8px 8px;
}
.f-pastille[data-couleur="bleu"] { --teinte: #2563eb; }
.f-pastille[data-couleur="rouge"] { --teinte: #dc2626; }
.f-pastille[data-couleur="orange"] { --teinte: #f97316; }
.f-pastille[data-couleur="violet"] { --teinte: #7c3aed; }
.f-pastille[data-couleur="fuschia"] { --teinte: #db2777; }
.f-pastille[data-couleur="vert"] { --teinte: #16a34a; }
.f-pastille[data-couleur="jaune"] { --teinte: #facc15; }
.f-pastille[data-couleur="rose"] { --teinte: #fbcfe8; }

/* Tableau des formes */
.f-colonne-formes { display: flex; flex-direction: column; gap: 8px; }
.f-tableau-formes { border: 1.5px solid #cbd5e1; border-radius: 7px; overflow: hidden; background: #fff; }
.f-tableau-formes table { width: 100%; border-collapse: collapse; }
.f-tableau-formes th { background: var(--bleu-bon); color: #fff; font-size: 9px; font-weight: 800; text-transform: uppercase; padding: 4px 3px; line-height: 1.15; text-align: center; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.f-tableau-formes th:first-child { text-align: left; padding-left: 8px; }
.f-tableau-formes td { border-top: 1px solid #e2e8f0; padding: 3px; text-align: center; height: 23px; }
.f-tableau-formes td:first-child { text-align: left; padding-left: 8px; font-weight: 600; }
.f-tableau-formes td.f-sans-helix { background: #f1f5f9; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.f-tableau-formes tr.f-forme-choisie td:first-child { color: var(--bleu-bon); font-weight: 800; }
.f-epaulement { border: 1.5px dashed var(--orange-bon); border-radius: 7px; background: #fff7ed; padding: 5px 10px; color: var(--orange-bon); font-weight: 700; }
.f-epaulement p { font-size: 10px; font-style: italic; margin: 0 0 2px; }
.f-epaulement input[type="radio"] { border-color: var(--orange-bon); }
.f-epaulement input[type="radio"]:checked { background-color: var(--orange-bon); }
.f-grille-tubes { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 6px; }
.f-grille-tubes .f-case { align-items: flex-start; }
.f-grille-tubes .f-case span { display: flex; flex-direction: column; line-height: 1.15; }
.f-grille-tubes small { font-size: 9px; color: #64748b; }
.f-tubes-options .f-sous-cadre > .f-case { display: flex; margin: 5px 0; white-space: normal; }

/* Ligne du bas */
.f-acoustique .f-cases-ligne { margin: 3px 0; }
.f-acoustique small { font-weight: 400; font-style: italic; color: #64748b; }
.f-acoustique .f-gain { max-width: 150px; }
.feuille select { height: 22px; font: inherit; font-size: 11.5px; border: 1px solid var(--trait-bon); border-radius: 4px; background: #fff; margin-right: 10px; }
.f-observations textarea {
    width: 100%; height: 96px; resize: none; border: none; font: inherit; font-size: 12px; color: #0f172a; padding: 0 2px;
    background: repeating-linear-gradient(#fff 0 23px, var(--trait-bon) 23px 24px); line-height: 24px;
    print-color-adjust: exact; -webkit-print-color-adjust: exact;
}

/* Zones grisées (sans objet avec les choix faits) et zones en erreur */
.feuille .f-inactif { opacity: 0.38; }
.feuille .f-erreur { outline: 2.5px solid #dc2626; outline-offset: 2px; border-radius: 6px; }

/* ---------- Plein écran : seul le bon (et ses menus) occupe l'écran, on enchaîne les commandes ---------- */
.bon-ecran-page:fullscreen { max-width: none; width: 100%; height: 100%; overflow-y: auto; background: var(--fond-clair, #f1f5f9);
    padding: 0.9rem max(16px, 2vw) 1.5rem; box-sizing: border-box; }
.bon-ecran-page:fullscreen .bon-hors-plein-ecran, .bon-ecran-page:fullscreen .bon-aide, .bon-ecran-page:fullscreen .bon-pied,
.bon-ecran-page:fullscreen .bon-astuce-rotation { display: none; }
.bon-ecran-page:fullscreen .bon-barre { margin-bottom: 0.6rem; align-items: center; }
.bon-ecran-page:fullscreen .bon-titre-page { font-size: 1.2rem; margin: 0; }
.bon-ecran-page:fullscreen .feuille-cadre { margin: 0 auto; }
.bon-ecran-page:fullscreen .bon-modeles { margin-bottom: 0.6rem; padding: 0.45rem 0.8rem; }

/* ---------- Modèles de commande ---------- */
.bon-modeles { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.9rem; padding: 0.65rem 0.9rem;
    border: 1px solid var(--bordure-subtile, #e2e8f0); border-radius: 12px; background: #fff; }
.bon-modeles-titre { font-weight: 800; color: var(--bleu-fonce, #0a2540); font-size: 0.95rem; }
.bon-modeles select { font: inherit; font-size: 0.92rem; padding: 0.45rem 0.6rem; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff;
    min-width: 0; max-width: 100%; flex: 0 1 280px; }
.bon-btn-petit { padding: 0.45rem 0.85rem !important; font-size: 0.9rem !important; }
.bon-lien-discret { background: none; border: none; color: #b91c1c; font: inherit; font-size: 0.88rem; font-weight: 600; text-decoration: underline; cursor: pointer; padding: 0.3rem; }
.bon-modeles-message { flex-basis: 100%; margin: 0; font-size: 0.88rem; font-weight: 600; color: #166534; }
.bon-modeles-message.erreur { color: #991b1b; }
.bon-modele-aide { font-size: 0.86rem; color: #475569; margin: 0; }
.bon-modele-libelle { font-weight: 700; font-size: 0.92rem; color: #0f172a; }
.bon-modele-nom { font: inherit; padding: 0.6rem 0.7rem; border-radius: 10px; border: 1.5px solid #cbd5e1; width: 100%; box-sizing: border-box; }
.bon-modele-nom:focus { outline: none; border-color: var(--bleu-bon, #1e4f9c); }
.bon-modele-puces { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.bon-modele-puce { font: inherit; font-size: 0.84rem; padding: 0.35rem 0.65rem; border-radius: 999px; border: 1px solid #bfdbfe; background: #eff6ff;
    color: #1e3a8a; cursor: pointer; text-align: left; }
.bon-modele-puce:hover { background: #dbeafe; }

/* ---------- Menu de fin ---------- */
.bon-menu { margin: auto; border: none; border-radius: 16px; padding: 0; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(15, 23, 42, 0.35); }
.bon-menu::backdrop { background: rgba(15, 23, 42, 0.55); }
.bon-menu-boite { padding: 1.3rem; display: flex; flex-direction: column; gap: 0.6rem; }
.bon-menu h2 { font-size: 1.15rem; color: var(--bleu-fonce, #0a2540); font-weight: 800; margin-bottom: 0.2rem; }
.bon-choix { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; text-align: left; width: 100%; padding: 0.8rem 0.95rem;
    border-radius: 12px; border: 1.5px solid var(--bordure-subtile, #e2e8f0); background: #fff; font: inherit; cursor: pointer; color: #0f172a; text-decoration: none; }
.bon-choix strong { font-size: 0.98rem; }
.bon-choix span { font-size: 0.84rem; color: var(--texte-discret, #64748b); }
.bon-choix:hover { border-color: #94a3b8; }
.bon-choix.principal { border-color: var(--orange-action, #c2410c); background: #fff7ed; }
.bon-choix.principal strong { color: var(--orange-action, #c2410c); }
.bon-choix:disabled { opacity: 0.6; cursor: wait; }
.bon-menu-message { padding: 0.6rem 0.75rem; border-radius: 8px; background: #fef2f2; color: #991b1b; font-weight: 600; font-size: 0.88rem; }
.bon-menu-fermer { align-self: center; background: none; border: none; color: #475569; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0.4rem; }
.bon-resultat-ok { color: #166534; font-weight: 800; font-size: 1.05rem; }
.bon-resultat p { font-size: 0.92rem; color: #334155; margin: 0 0 0.4rem; }
.bon-resultat .bon-choix { margin-top: 0.2rem; }

/* Étiquette d'envoi après validation (mêmes styles que la page Commande) */
.etiquette-conf-zone:empty { display: none; }
.etiquette-conf-zone { margin-top: 0.4rem; padding-top: 0.6rem; border-top: 1px dashed #fdba74; font-size: 0.9rem; }
.etiquette-conf-zone p { margin: 0 0 0.6rem; }
.etiquette-conf-attente { color: #64748b; font-style: italic; }
.etiquette-conf-erreur, .etiquette-conf-specimen { color: #991b1b; font-weight: 700; }
.etiquette-conf-aide { font-size: 0.83rem; color: #64748b; }
.etiquette-conf-boutons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.btn-conf { padding: 0.55rem 0.9rem; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.btn-conf.principal { background: var(--orange-action, #c2410c); border-color: var(--orange-action, #c2410c); color: #fff; }
.btn-telecharger-etiquette { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0.5rem 0 0.2rem; padding: 0.55rem 0.9rem;
    border-radius: 8px; background: var(--bleu-fonce, #0a2540); color: #fff; font-weight: 700; text-decoration: none; border: none; font: inherit; cursor: pointer; }
.btn-lien-recente { font: inherit; font-weight: 700; display: inline; color: #1d4ed8; background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline; }

/* ---------- Impression : la feuille seule, sur une page A4 paysage ---------- */
@media print {
    /* Paysage, sur le format de papier choisi dans la fenêtre d'impression (A4, A3, Letter…) */
    @page { size: landscape; margin: 6mm; }
    body { background: #fff !important; }
    /* Espace réservé aux onglets du téléphone (petits formats de papier) : jamais imprimé */
    html body::after { display: none !important; }
    body > *:not(main), .bon-barre, .bon-astuce-rotation, .bon-erreurs, .bon-pied, .bon-menu, .bon-modeles, #bulle-tchat-flottante { display: none !important; }
    html, body { height: auto !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important; }
    .bon-ecran-page { max-width: none; padding: 0 !important; margin: 0 !important; min-height: 0 !important; overflow: hidden; }
    /* Seule la feuille s'imprime : rien après elle ne peut créer une 2e page blanche */
    .bon-ecran-page > :not(.feuille-cadre) { display: none !important; }
    .feuille-cadre { height: auto !important; overflow: hidden; margin: 0 !important; break-inside: avoid; page-break-inside: avoid; }
    /* La feuille garde sa mise en page de 1123 px, réduite pour tenir sur une page A4 paysage */
    .feuille { --echelle: 1; transform: none; box-shadow: none; border-radius: 0; padding: 0; zoom: 0.88; break-after: avoid; page-break-after: avoid; }
    /* Navigateurs récents : la feuille remplit exactement la page, quel que soit le papier et les marges.
       Largeur : agrandie ou réduite pour occuper toute la largeur imprimable (100vw = largeur de la page
       à l'impression), sans dépasser la hauteur (735 px = hauteur naturelle du bon).
       Hauteur : la place restante est répartie dans les cadres (ils s'allongent), jamais de 2e page. */
    @supports (zoom: calc(100vw / 1123px)) {
        .feuille { zoom: min(calc(100vw / 1123px), calc(100vh / 735px));
            height: calc(max(calc(1123px * 100vh / 100vw), 735px) - 12px);
            display: flex; flex-direction: column; overflow: hidden; }
        .f-entete, .f-ligne-haut { flex: 0 0 auto; }
        .f-ligne-milieu { flex: 3 1 0; align-items: stretch; min-height: 0; }
        .f-ligne-bas { flex: 1 1 0; min-height: 0; }
        .f-ligne-haut .f-cadre { display: flex; flex-direction: column; }
        .f-ligne-haut .f-corps { flex: 1; }
        .f-panneau, .f-colonne-formes { display: flex; flex-direction: column; }
        .f-panneau > .f-deux-colonnes, .f-colonne-formes > .f-tubes-options { flex: 1; }
        .f-observations { display: flex; flex-direction: column; }
        .f-observations textarea { flex: 1; height: auto; min-height: 0; }
    }
    .feuille .f-inactif { opacity: 1; }
    .feuille .f-erreur { outline: none; }
    .feuille input::placeholder { color: transparent; }
    .feuille select { border: none; appearance: none; -webkit-appearance: none; }
}
