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

/* Conteneurs : la page (colonnes) et la carte du tableau (cartes empilées) */
body.embed #page-liste{container:pl / inline-size}
body.embed #page-liste .table-card{container:pt / inline-size}

/* --- Mise en page générale (mobile d'abord : une colonne) --- */
body.embed #page-liste .split{display:flex;flex-direction:column;flex-wrap:nowrap;align-items:stretch;gap:clamp(12px,2cqw,20px)}
body.embed #page-liste .split-side,
body.embed #page-liste .split-main{flex:0 0 auto!important;width:100%;min-width:0;position:static;box-sizing:border-box}
body.embed #page-liste .split-side{padding:clamp(14px,2.4cqw,22px)}
body.embed #liste-text{height:clamp(150px,32vh,340px);min-height:150px;max-height:60vh;width:100%;box-sizing:border-box}
body.embed #page-liste #liste-suggest{max-height:min(160px,24vh)!important;overflow:auto}
body.embed #page-liste .steph{row-gap:2px}
body.embed #page-liste .full{min-height:44px}
body.embed #page-liste .split-side p.muted{overflow-wrap:anywhere}

/* --- Deux colonnes dès que la page est assez large --- */
@container pl (min-width:960px){
  body.embed #page-liste .split{flex-direction:row;align-items:flex-start}
  body.embed #page-liste .split-side{flex:0 0 clamp(300px,30cqw,420px)!important;width:auto;position:sticky;top:8px;max-height:calc(100vh - 16px);overflow:auto}
  body.embed #page-liste .split-main{flex:1 1 0!important;width:auto}
  body.embed #liste-text{height:clamp(200px,calc(100vh - 380px),520px);max-height:none}
}
/* hauteurs basses : le panneau de collage ne colle plus (il dépasserait la fenêtre) */
@media (max-height:640px){
  @container pl (min-width:960px){
    body.embed #page-liste .split-side{position:static;max-height:none}
  }
}

/* --- Tableau : aération réduite avant de passer en cartes --- */
@container pt (max-width:880px){
  body.embed #liste-table thead th{padding:10px}
  body.embed #liste-table td{padding:10px}
  body.embed #liste-table .liste-status{min-width:0}
  body.embed #liste-table td:nth-child(3){min-width:150px;max-width:240px;overflow-wrap:anywhere}
}

/* --- Sous 720 px de tableau : chaque ligne devient une carte empilée --- */
@container pt (max-width:719px){
  body.embed #liste-table,
  body.embed #liste-table tbody{display:block;min-width:0;width:100%}
  body.embed #liste-table thead{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
  body.embed #liste-table tr{display:block}

  /* lignes produit */
  body.embed #liste-table tr[data-idx]:not(.liste-room):not(.liste-section):not(.liste-note){
    display:grid;grid-template-columns:auto minmax(0,1fr) auto;
    grid-template-areas:"status status actions" "qty text text" "match match match";
    gap:8px 10px;align-items:center;padding:12px 14px;border-bottom:1px solid var(--border)}
  body.embed #liste-table tr[data-idx]:not(.liste-room):not(.liste-section):not(.liste-note) td{display:block;padding:0;border:0;min-width:0;max-width:none}
  body.embed #liste-table td:nth-child(1){grid-area:status}
  body.embed #liste-table td:nth-child(2){grid-area:qty}
  body.embed #liste-table td:nth-child(3){grid-area:text;overflow-wrap:anywhere}
  body.embed #liste-table td:nth-child(3)::before{content:"Écrit : ";font-weight:600;font-size:12px;color:var(--muted,var(--sub))}
  body.embed #liste-table td:nth-child(4){grid-area:match}
  body.embed #liste-table td:nth-child(6){grid-area:actions}
  body.embed #liste-table tr[data-idx] td:nth-child(5){display:none!important}
  body.embed #liste-table td:nth-child(2) .liste-qty{display:block;width:72px;min-height:36px}
  body.embed #liste-table .liste-actions{display:flex;justify-content:flex-end;border-bottom:0}
  body.embed #liste-table .liste-status{display:flex;align-items:center;flex-wrap:wrap;gap:6px}
  body.embed #liste-table .liste-status input{margin-right:2px;flex:none}
  body.embed #liste-table .liste-match{padding:6px;margin:-6px;min-height:44px}
  body.embed #liste-table .liste-thumb{width:40px!important;height:40px!important;min-width:40px;max-width:40px;max-height:40px}
  body.embed #liste-table .liste-thumb img{width:40px!important;height:40px!important;max-width:40px!important;max-height:40px!important}
  body.embed #liste-table .liste-add-bib{min-height:36px}
  /* le bouton « + BDD Produits » passe sur sa propre ligne, pleine largeur utile */
  body.embed #liste-table tr[data-idx] .liste-actions{flex-wrap:wrap}

  /* pièces / titres / notes : blocs simples (colspan ignoré en block) */
  body.embed #liste-table .liste-room,
  body.embed #liste-table .liste-section,
  body.embed #liste-table .liste-note{display:block}
  body.embed #liste-table .liste-room{position:sticky;top:0;z-index:2}
  body.embed #liste-table .liste-room td,
  body.embed #liste-table .liste-section td,
  body.embed #liste-table .liste-note td{display:block;position:static;width:100%;box-sizing:border-box}
  body.embed #liste-table .liste-room td{padding:16px 14px 8px;font-size:16px;background:var(--card)}
  body.embed #liste-table .liste-section td{display:flex;align-items:center;flex-wrap:wrap;gap:6px 10px}
  body.embed #liste-table .liste-sec2item{margin-left:auto;min-height:36px}
  body.embed #liste-table tbody>tr:first-child>td[colspan]{display:block}
}

/* Grands tableaux : liseré et hauteurs de ligne stables */
@container pt (min-width:720px){
  body.embed #liste-table td:nth-child(3){min-width:170px;max-width:clamp(200px,30cqw,380px);overflow-wrap:anywhere}
  body.embed #liste-table .liste-qty{min-height:36px;width:80px}
  body.embed #liste-table .liste-add-bib{min-height:36px}
}

/* --- Barre d'insertion collante --- */
body.embed #page-liste .split-main>.card:last-child{bottom:calc(env(safe-area-inset-bottom,0px) + 8px);padding:clamp(10px,1.6cqw,14px) clamp(12px,2cqw,20px);gap:10px 16px;margin-bottom:0}
@container pl (max-width:520px){
  body.embed #page-liste #btn-insert-liste{width:100%;margin-left:0;min-width:0}
  body.embed #page-liste .split-main>.card:last-child h3{flex-basis:100%}
}
@media (max-height:640px){
  body.embed #page-liste .split-main>.card:last-child{flex-wrap:nowrap;padding:8px 14px}
  body.embed #page-liste .split-main>.card:last-child h3{display:none}
  body.embed #page-liste #liste-insert-progress{position:absolute;bottom:100%;left:0;right:0;background:var(--card);padding:4px 14px}
}
