/* Responsive : page produits (fenêtre étroite → large). Tout est scopé body.embed. */

/* ================= Page ================= */
body.embed #page-produits-v2{container:pv2 / inline-size;min-width:0}
body.embed #page-produits-v2 .pg-head{gap:clamp(8px,1.6cqw,16px) 16px;margin-bottom:clamp(10px,2cqw,16px)}
body.embed #page-produits-v2 .pg-head h1{font-size:clamp(19px,1.4vw + 12px,24px)}
body.embed #page-produits-v2 .pg-head .t{min-width:min(220px,100%)}
body.embed #page-produits-v2 .pg-head .pg-actions .btn,
body.embed #page-produits-v2 .filters-row .btn{min-height:38px}

/* ---- filtres : recherche pleine largeur, listes qui se partagent la ligne ---- */
body.embed #page-produits-v2 .filters-row{gap:8px 10px}
body.embed #page-produits-v2 #pv2-search{flex:1 1 260px;min-width:min(200px,100%)}
body.embed #page-produits-v2 .select-sm{flex:1 1 150px;max-width:260px;min-width:min(150px,100%);text-overflow:ellipsis}
body.embed #page-produits-v2 .filters-row .input{min-height:38px}
@container pv2 (max-width:720px){
  body.embed #page-produits-v2 #pv2-search{flex-basis:100%}
  body.embed #page-produits-v2 .select-sm{max-width:none;flex:1 1 140px}
}
@container pv2 (max-width:460px){
  body.embed #page-produits-v2 .select-sm{flex-basis:100%}
  body.embed #page-produits-v2 #btn-refresh-produits-v2{flex:1 1 100%}
  body.embed #page-produits-v2 .pg-actions{width:100%}
  body.embed #page-produits-v2 .pg-actions .btn{flex:1 1 auto}
}

/* ---- barre de sélection collante ---- */
body.embed #page-produits-v2 #pv2-selection-bar:not([hidden]){top:6px;padding:10px clamp(10px,2cqw,16px);gap:8px 12px}
body.embed #page-produits-v2 #pv2-selection-bar > div{display:flex;gap:8px;flex-wrap:wrap;margin-left:auto}
body.embed #page-produits-v2 #pv2-selection-bar .btn{min-height:36px}
@container pv2 (max-width:520px){
  body.embed #page-produits-v2 #pv2-selection-bar:not([hidden]){flex-direction:column;align-items:stretch}
  body.embed #page-produits-v2 #pv2-selection-bar > div{margin-left:0}
  body.embed #page-produits-v2 #pv2-selection-bar > div .btn{flex:1 1 auto}
}
@media (max-height:640px){
  body.embed #page-produits-v2 #pv2-selection-bar:not([hidden]){top:4px;padding-block:6px}
  body.embed #page-produits-v2 .toolbar-card{padding-block:10px}
}

/* ================= Grille de cartes ================= */
body.embed #page-produits-v2 #pv2-grid.grid{
  grid-template-columns:repeat(auto-fill,minmax(min(100%,clamp(210px,17cqw,290px)),1fr));
  gap:clamp(10px,1.6cqw,20px)}
@container pv2 (max-width:520px){
  body.embed #page-produits-v2 #pv2-grid.grid{grid-template-columns:repeat(auto-fill,minmax(min(100%,150px),1fr));gap:10px}
}
@container pv2 (max-width:340px){
  body.embed #page-produits-v2 #pv2-grid.grid{grid-template-columns:1fr}
}
body.embed #pv2-grid .product-card{container:pcard / inline-size;min-width:0}
body.embed #pv2-grid .product-thumb{height:auto;aspect-ratio:4/3;max-height:200px}
@media (max-height:640px){body.embed #pv2-grid .product-thumb{aspect-ratio:16/10}}
body.embed #pv2-grid .product-thumb img{width:100%;height:100%}
/* case de sélection : cible confortable */
body.embed #pv2-grid .product-select-check{width:26px;height:26px;top:8px;left:8px;opacity:1;
  background:var(--card);border-radius:6px;box-shadow:0 0 0 4px color-mix(in srgb,var(--card) 80%,transparent)}
body.embed #pv2-grid .product-body{min-width:0;padding:clamp(10px,4cqw,16px) clamp(10px,5cqw,16px) 8px}
body.embed #pv2-grid .product-body > *{min-width:0;overflow-wrap:anywhere}
body.embed #pv2-grid .product-title{font-size:clamp(13.5px,6cqw,15.5px)}
body.embed #pv2-grid .product-meta{display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
body.embed #pv2-grid .product-card .pc-price{font-size:clamp(16px,7cqw,19px)}
body.embed #pv2-grid .product-actions{display:flex;flex-wrap:wrap;margin-top:auto;padding:6px clamp(10px,5cqw,16px) clamp(10px,5cqw,16px)}
body.embed #pv2-grid .product-actions .btn{min-height:38px;min-width:38px;flex:1 1 auto;justify-content:center;padding-inline:10px;white-space:nowrap}
body.embed #pv2-grid .product-actions .btn-history-v2{flex:0 0 auto}
body.embed #pv2-grid .product-actions .btn-edit-v2{flex:1 1 90px}
body.embed #pv2-grid .product-actions .btn-insert-v2{flex:1 1 90px}
/* carte étroite : historique + modifier sur une ligne, insérer en dessous */
@container pcard (max-width:200px){
  body.embed #pv2-grid .product-actions .btn-insert-v2{flex-basis:100%}
}

/* ================= Fenêtres ================= */
body.embed #produit-v2-modal,body.embed #bulk-edit-modal,body.embed #pack-modal{
  --mp:clamp(14px,2.4vw,24px);
  padding:clamp(8px,2vw,16px);
  overflow-y:auto}
body.embed #produit-v2-modal .modal,body.embed #bulk-edit-modal .modal,body.embed #pack-modal .modal{
  container:pmodal / inline-size;
  box-sizing:border-box;max-width:100%;
  max-height:calc(100vh - 2 * clamp(8px,2vw,16px));
  max-height:calc(100dvh - 2 * clamp(8px,2vw,16px));
  overflow:auto;overscroll-behavior:contain}
body.embed #produit-v2-modal .modal{width:min(760px,100%);padding:0}
body.embed #bulk-edit-modal .modal{width:min(560px,100%);padding:var(--mp)}
body.embed #pack-modal .modal{width:min(720px,100%);padding:var(--mp)}
body.embed #bulk-edit-modal .modal h3,body.embed #pack-modal .modal h3{margin:0 0 8px;font-size:clamp(16px,1.2vw + 10px,19px)}

/* ---- fenêtre produit ---- */
body.embed #produit-v2-modal #pv2-modal-title{padding:clamp(12px,2.4vw,18px) var(--mp);font-size:clamp(16px,1.2vw + 10px,18px);overflow-wrap:anywhere}
body.embed #produit-v2-form{padding:4px var(--mp) 0}
body.embed #produit-v2-form .input,body.embed #produit-v2-form .textarea,body.embed #produit-v2-form select{min-height:38px;max-width:100%}
body.embed #produit-v2-form .textarea{min-height:70px}
body.embed #produit-v2-form .modal-actions{margin-inline:calc(-1 * var(--mp));padding:12px var(--mp);gap:8px;justify-content:flex-end;box-shadow:0 -6px 12px -8px rgba(20,30,40,.18)}
body.embed #produit-v2-form .modal-actions .btn{min-height:38px}
body.embed #produit-v2-form .filters-row{gap:8px}
body.embed #produit-v2-form .filters-row .select-sm{flex:0 1 150px;min-width:110px}
body.embed #produit-v2-form .filters-row .input[style*="flex:1"]{flex:1 1 200px}
body.embed #produit-v2-form .pv2-ligne-extra-row{flex-wrap:nowrap}
body.embed #produit-v2-form .pv2-ligne-extra-row .pv2-le-label{flex:0 1 220px;min-width:0}
body.embed #produit-v2-form .pv2-ligne-extra-row .pv2-le-valeur{min-width:0}
body.embed #produit-v2-form .icon-btn{min-width:38px;min-height:38px}
/* la zone de défilement du tableau des compléments ne dépasse jamais la fenêtre */
body.embed #produit-v2-form div[style*="max-height:240px"]{max-height:min(300px,42vh) !important;max-height:min(300px,42dvh) !important;overscroll-behavior:contain}
body.embed #pv2-complements-table{min-width:640px}
body.embed #pv2-complements-table thead th{position:sticky;top:0;z-index:1;background:var(--card)}
body.embed #pv2-complements-table td{vertical-align:middle}
body.embed #pv2-complements-table td.comp-act{width:1%;white-space:nowrap;text-align:left}
body.embed #pv2-complements-table td:nth-child(n+5) .input{min-width:72px}
body.embed #pv2-complements-table td.comp-act .icon-btn{width:32px;height:32px}

@container pmodal (max-width:560px){
  body.embed #produit-v2-form .form-grid,body.embed #pv2-attributs-fields{grid-template-columns:1fr}
  body.embed #produit-v2-form .modal-actions #btn-delete-produit-v2{margin-right:0}
  body.embed #produit-v2-form .modal-actions .btn{flex:1 1 calc(50% - 8px)}
  body.embed #produit-v2-form .modal-actions #btn-save-produit-v2{flex-basis:100%;order:-1}
  body.embed #produit-v2-form .pv2-ligne-extra-row{flex-wrap:wrap}
  body.embed #produit-v2-form .pv2-ligne-extra-row .pv2-le-label{flex:1 1 calc(100% - 50px)}
  body.embed #produit-v2-form .pv2-ligne-extra-row .pv2-le-valeur{flex:1 1 calc(100% - 50px)}
  body.embed #produit-v2-form .filters-row .select-sm{flex:1 1 100%;max-width:none}
}
/* tableau des compléments : lignes empilées (cartes) quand la fenêtre est étroite */
@container pmodal (max-width:640px){
  body.embed #produit-v2-form div[style*="max-height:240px"]{max-height:none !important;overflow:visible !important;border:0 !important}
  body.embed #pv2-complements-table{min-width:0;width:100%;display:block;border:0}
  body.embed #pv2-complements-table thead{display:none}
  body.embed #pv2-complements-table tbody{display:block}
  body.embed #pv2-complements-table tr{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:8px;position:relative;
    padding:10px 12px;margin-bottom:10px;border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--card)}
  body.embed #pv2-complements-table tr.pv2-base-row{background:var(--accent-soft);border-color:var(--accent)}
  body.embed #pv2-complements-table td{display:flex;flex-direction:column;gap:3px;padding:0;border:0;min-width:0;width:auto !important;overflow-wrap:anywhere}
  body.embed #pv2-complements-table td::before{content:attr(data-label);font-size:11.5px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--sub)}
  body.embed #pv2-complements-table td:nth-child(1),body.embed #pv2-complements-table td:nth-child(2){grid-column:1/-1}
  body.embed #pv2-complements-table td:nth-child(3),body.embed #pv2-complements-table td:nth-child(4){grid-column:span 3}
  body.embed #pv2-complements-table td:nth-child(5),body.embed #pv2-complements-table td:nth-child(6),body.embed #pv2-complements-table td:nth-child(7){grid-column:span 2}
  body.embed #pv2-complements-table td:nth-child(n) .input{min-width:0;width:100%}
  body.embed #pv2-complements-table tr.pv2-base-row td:nth-child(3):empty,body.embed #pv2-complements-table tr.pv2-base-row td:nth-child(4):empty{display:none}
  body.embed #pv2-complements-table td.comp-act{width:auto !important;flex-direction:row;justify-content:flex-end}
  body.embed #pv2-complements-table td.comp-act::before{content:none}
}
@container pmodal (max-width:400px){
  body.embed #pv2-complements-table td:nth-child(3),body.embed #pv2-complements-table td:nth-child(4){grid-column:1/-1}
  body.embed #pv2-complements-table td:nth-child(5){grid-column:span 6}
  body.embed #pv2-complements-table td:nth-child(6),body.embed #pv2-complements-table td:nth-child(7){grid-column:span 3}
}

/* ---- modification groupée ---- */
body.embed #bulk-edit-modal .form-grid{grid-template-columns:minmax(150px,220px) minmax(0,1fr);gap:10px 14px}
body.embed #bulk-edit-modal .form-grid label{min-height:38px;overflow-wrap:anywhere}
body.embed #bulk-edit-modal .input{min-height:38px}
body.embed #bulk-edit-modal .modal-actions,body.embed #pack-modal .modal-actions{position:sticky;bottom:calc(-1 * var(--mp));z-index:5;
  margin:16px calc(-1 * var(--mp)) calc(-1 * var(--mp));padding:12px var(--mp);background:var(--card);border-top:1px solid var(--border);flex-wrap:wrap}
body.embed #bulk-edit-modal .modal-actions .btn,body.embed #pack-modal .modal-actions .btn{min-height:38px}
@container pmodal (max-width:460px){
  body.embed #bulk-edit-modal .form-grid{grid-template-columns:1fr;gap:2px}
  body.embed #bulk-edit-modal .form-grid label{min-height:36px}
  body.embed #bulk-edit-modal .form-grid .input{margin-bottom:10px}
  body.embed #bulk-edit-modal .modal-actions .btn,body.embed #pack-modal .modal-actions .btn{flex:1 1 auto}
}

/* ---- packs ---- */
body.embed #pack-modal .modal.modal-lg{width:min(720px,100%);max-height:calc(100dvh - 2 * clamp(8px,2vw,16px))}
body.embed #pack-list .cart-item{display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px}
body.embed #pack-list .cart-item > div:first-child{flex:1 1 180px;min-width:0;overflow-wrap:anywhere}
body.embed #pack-list .pack-actions{display:flex;gap:6px;flex-wrap:wrap;margin-left:auto}
body.embed #pack-modal .btn.small{min-height:36px}
body.embed #pack-build-list{max-height:clamp(150px,40vh,360px) !important;max-height:clamp(150px,40dvh,360px) !important;overscroll-behavior:contain}
body.embed #pack-build-list .cart-item{display:flex;align-items:center;gap:10px;min-height:44px}
body.embed #pack-build-list .cart-item label{min-width:0;overflow-wrap:anywhere;cursor:pointer;padding-block:4px}
body.embed #pack-build-list .pack-build-qty{flex:0 0 72px;width:72px !important;min-height:36px}
body.embed #pack-build-list input[type=checkbox]{flex:none}
@container pmodal (max-width:460px){
  body.embed #pack-list .pack-actions{width:100%}
  body.embed #pack-list .pack-actions .btn{flex:1 1 auto}
}
@media (max-height:560px){
  body.embed #pack-build-list{max-height:clamp(110px,32dvh,220px) !important}
}

/* testeur final : un element [hidden] ne doit jamais etre rendu visible par un display:flex de ce fichier (ex: bouton Supprimer sur Nouveau produit) */
body.embed button[hidden],body.embed .btn[hidden],body.embed .modal-actions [hidden],body.embed .actions [hidden]{display:none!important}
