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

/* --- Conteneurs : la page réagit à la largeur de l'iframe, chaque carte à sa propre largeur --- */
body.embed #page-recherche{container:pg-panier / inline-size}
body.embed #page-recherche .split-side{container:pg-card / inline-size;min-width:0}

/* --- Grille : panier (large) + packs (colonne latérale collante) --- */
body.embed #page-recherche .split{
  display:grid;grid-template-columns:minmax(0,3fr) minmax(280px,2fr);
  gap:clamp(12px,2cqw,24px);align-items:start;
}
body.embed #page-recherche .split-side{flex:none!important;width:auto;margin-bottom:0;padding:clamp(14px,2.2cqw,22px)}
body.embed #page-recherche .split-side+.split-side{position:sticky;top:8px;max-height:calc(100vh - 16px);overflow:auto;overscroll-behavior:contain}
body.embed #page-recherche .split-side h3{overflow-wrap:anywhere}
@container pg-panier (max-width:860px){
  body.embed #page-recherche .split{grid-template-columns:minmax(0,1fr)}
  body.embed #page-recherche .split-side+.split-side{position:static;max-height:none;overflow:visible}
}

/* --- Liste du panier --- */
body.embed #page-recherche .cart-list{min-width:0}
body.embed #panier-pack-list{max-height:min(46vh,420px);overflow:auto;padding-right:2px}
body.embed #page-recherche .cart-item{min-width:0;flex-wrap:nowrap}
body.embed #page-recherche .cart-item .name{flex:1 1 0;min-width:0;overflow-wrap:anywhere;hyphens:auto}
body.embed #page-recherche .cart-item .name>div{overflow-wrap:anywhere}
body.embed #page-recherche .cart-item>span:first-child:not(.name):not(.cart-thumb-click){flex:none;width:16px;text-align:center;touch-action:none}
body.embed #page-recherche .cart-thumb-click{flex:none;display:inline-flex;align-items:center;justify-content:center;min-width:44px;min-height:44px}
body.embed #page-recherche .cart-thumb-click img{width:clamp(40px,7cqw,56px)!important;height:clamp(40px,7cqw,56px)!important}
body.embed #page-recherche .cart-item .btn,
body.embed #page-recherche .cart-item .icon-btn{flex:none;min-height:36px;min-width:36px;white-space:nowrap}
body.embed #page-recherche .cart-item .icon-btn{display:inline-flex;align-items:center;justify-content:center}
body.embed #page-recherche .qty-input{flex:none;width:clamp(56px,10cqw,72px);min-height:38px}
body.embed #panier-pack-list .cart-item{min-height:48px}

/* Suggestions : texte + boutons qui passent à la ligne */
body.embed #page-recherche .cart-suggestion{flex-wrap:wrap;min-width:0;row-gap:6px;margin-left:clamp(0px,4cqw,28px)}
body.embed #page-recherche .cart-suggestion>.muted{flex:1 1 200px;min-width:0;overflow-wrap:anywhere}
body.embed #page-recherche .cart-suggestion>span:last-child{display:inline-flex;gap:6px;flex:none;margin-left:auto}
body.embed #page-recherche .cart-suggestion .btn{min-height:36px}

/* Barre « ajouter produit / pièce » et enregistrement de pack : retour à la ligne propre */
body.embed #page-recherche .filters-row{flex-wrap:wrap}
body.embed #page-recherche .filters-row .btn{flex:1 1 auto;min-height:38px}
body.embed #page-recherche .filters-row .input{flex:1 1 200px}

/* --- Actions collantes (Insérer / Vider) --- */
/* le défilement se fait dans main.content : on retire son padding bas tant que cette page est ouverte, sinon la barre collante s'arrête au-dessus du bord */
body.embed .content:has(#page-recherche.active){padding-bottom:0}
body.embed #page-recherche.active{padding-bottom:clamp(16px,3vh,28px)}
body.embed #page-recherche .cart-actions{
  position:sticky;bottom:0;z-index:4;display:flex;flex-direction:column;gap:6px;
  margin:6px calc(-1*clamp(14px,2.2cqw,22px)) calc(-1*clamp(14px,2.2cqw,22px));
  padding:10px clamp(14px,2.2cqw,22px) clamp(12px,2cqw,18px);
  background:var(--card);border-top:1px solid var(--border);
  border-radius:0 0 var(--radius) var(--radius);
}
body.embed #page-recherche .cart-actions .btn{margin:0;min-height:44px}
body.embed #page-recherche .cart-actions #btn-clear-cart{min-height:38px}
body.embed #page-recherche #cart-progress,body.embed #page-recherche #panier-pack-progress{overflow-wrap:anywhere}

/* --- Carte étroite (panier < 460 px) : ligne en deux rangées --- */
@container pg-card (max-width:460px){
  body.embed #page-recherche #cart-list .cart-item{
    display:grid;grid-template-columns:auto auto minmax(0,1fr) auto;align-items:center;column-gap:8px;row-gap:6px;
  }
  body.embed #page-recherche #cart-list .cart-item .name{grid-column:3 / 5;grid-row:1}
  body.embed #page-recherche #cart-list .cart-item>span:first-child:not(.name):not(.cart-thumb-click){grid-column:1;grid-row:1}
  body.embed #page-recherche #cart-list .cart-item .cart-thumb-click{grid-column:2;grid-row:1}
  body.embed #page-recherche #cart-list .cart-item .qty-input{grid-column:3;grid-row:2;justify-self:start;width:88px}
  body.embed #page-recherche #cart-list .cart-item .cart-remove{grid-column:4;grid-row:2}
  /* pièce (pas de vignette ni quantité) : nom + supprimer sur une ligne */
  body.embed #page-recherche #cart-list .cart-item:not(:has(.qty-input)){grid-template-columns:auto minmax(0,1fr) auto}
  body.embed #page-recherche #cart-list .cart-item:not(:has(.qty-input)) .name{grid-column:2;grid-row:1}
  body.embed #page-recherche #cart-list .cart-item:not(:has(.qty-input)) .cart-remove{grid-column:3;grid-row:1}
  body.embed #page-recherche .cart-suggestion{margin-left:0}
  body.embed #page-recherche .cart-suggestion>span:last-child{margin-left:0;width:100%}
  body.embed #page-recherche .cart-suggestion>span:last-child .cart-suggest-add{flex:1}
  body.embed #page-recherche .filters-row .btn{flex:1 1 100%}
}

/* --- Hauteurs basses --- */
@media (max-height:700px){
  body.embed #page-recherche .split-side{gap:8px}
  body.embed #page-recherche .cart-item{padding-block:6px;min-height:44px}
  body.embed #panier-pack-list{max-height:40vh}
  body.embed #page-recherche .cart-actions{padding-top:8px;padding-bottom:10px}
  body.embed #page-recherche .cart-actions{flex-direction:row;align-items:stretch;gap:8px}
  body.embed #page-recherche .cart-actions #btn-insert-cart{flex:1 1 auto;width:auto;min-height:40px}
  body.embed #page-recherche .cart-actions #btn-clear-cart{flex:0 1 auto;width:auto;min-height:40px;padding-inline:14px}
}

/* --- Fenêtres modales (ajout produit, nouvelle pièce, détail produit) --- */
body.embed #cart-add-modal,body.embed #cart-room-modal,body.embed #cart-item-modal{overflow:auto;padding:clamp(8px,2vw,16px)}
body.embed #cart-add-modal .modal,body.embed #cart-room-modal .modal,body.embed #cart-item-modal .modal{
  width:min(100%,var(--cart-modal-w,700px));max-width:100%;max-height:calc(100vh - 2*clamp(8px,2vw,16px));
  max-height:calc(100dvh - 2*clamp(8px,2vw,16px));overflow:auto;box-sizing:border-box;margin:0;
  padding:clamp(14px,3vw,24px);overscroll-behavior:contain;
}
body.embed #cart-add-modal .modal{--cart-modal-w:760px}
body.embed #cart-room-modal .modal{--cart-modal-w:440px}
body.embed #cart-item-modal .modal{--cart-modal-w:860px}
body.embed #cart-add-modal .modal,body.embed #cart-item-modal .modal{container:pg-modal / inline-size}
body.embed #cart-add-results{max-height:none!important;overflow:visible!important}
body.embed #cart-add-modal .cart-item,body.embed #cart-item-modal .cart-item{min-width:0;min-height:48px}
body.embed #cart-add-modal .cart-item .name,body.embed #cart-item-modal .cart-item .name{min-width:0;overflow-wrap:anywhere}
body.embed #cart-add-modal .cart-item{cursor:pointer}
body.embed #cart-add-search,body.embed #cart-room-name{width:100%;box-sizing:border-box;min-height:40px}
/* barre d'actions de modale toujours visible */
body.embed #cart-add-modal .modal-actions,body.embed #cart-room-modal .modal-actions,body.embed #cart-item-modal .modal-actions{
  position:sticky;bottom:calc(-1*clamp(14px,3vw,24px));z-index:2;background:var(--card);
  margin-inline:calc(-1*clamp(14px,3vw,24px));margin-bottom:calc(-1*clamp(14px,3vw,24px));
  padding:10px clamp(14px,3vw,24px);border-top:1px solid var(--border);flex-wrap:wrap;
}
body.embed #cart-add-modal .modal-actions .btn,body.embed #cart-room-modal .modal-actions .btn,body.embed #cart-item-modal .modal-actions .btn{min-height:40px}

/* Détail produit : 3 colonnes -> photo+infos / suggestions -> 1 colonne */
body.embed #cart-item-modal .cim-columns{
  display:grid;grid-template-columns:minmax(120px,180px) minmax(0,1fr) minmax(0,1fr);gap:clamp(12px,2.5cqw,20px);align-items:start;
}
body.embed #cart-item-modal .cim-photo{width:auto;min-width:0}
body.embed #cart-item-modal .cim-photo img{max-height:min(46vh,320px);aspect-ratio:1;object-fit:cover}
body.embed #cart-item-modal .cim-photo .placeholder{height:auto;aspect-ratio:1}
body.embed #cart-item-modal .cim-info,body.embed #cart-item-modal .cim-suggestions{overflow-wrap:anywhere}
@container pg-modal (max-width:700px){
  body.embed #cart-item-modal .cim-columns{grid-template-columns:minmax(110px,160px) minmax(0,1fr)}
  body.embed #cart-item-modal .cim-suggestions{grid-column:1 / -1}
}
@container pg-modal (max-width:420px){
  body.embed #cart-item-modal .cim-columns{grid-template-columns:minmax(0,1fr)}
  body.embed #cart-item-modal .cim-photo{max-width:200px}
}
@media (max-height:700px){
  body.embed #cart-item-modal .cim-photo img{max-height:34vh}
  body.embed #cart-add-modal .modal,body.embed #cart-item-modal .modal{padding-top:12px}
}
