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

/* Conteneurs : la page (barre d'insertion) et chaque carte-tableau (passage en lignes empilées) */
body.embed #page-prestations{container:pd / inline-size;min-width:0}
body.embed #page-prestations .table-card{container:pt / inline-size;min-width:0}
body.embed #page-prestations>.card{min-width:0;box-sizing:border-box}

/* --- En-tête : filtres qui passent à la ligne --- */
body.embed #page-prestations .dv-head{padding:clamp(12px,2.2cqw,20px)}
body.embed #page-prestations .dv-lead{max-width:none;font-size:clamp(13px,1.4cqw,14px)}
body.embed #page-prestations .dv-head .filters-row{display:flex;flex-wrap:wrap;gap:8px 10px;align-items:center}
body.embed #page-prestations .dv-head .select-sm{flex:1 1 260px;min-width:0;width:auto;max-width:100%;min-height:40px;text-overflow:ellipsis}
body.embed #page-prestations .dv-head .btn{min-height:40px;flex:none}
body.embed #page-prestations #prest-scan-progress{overflow-wrap:anywhere}
@container pd (max-width:560px){
  body.embed #page-prestations .dv-head .btn{flex:1 1 100%}
  body.embed #page-prestations .dv-head #btn-scan-prestations{order:-1}
}

/* --- Tableaux : zones cliquables et champs --- */
body.embed #page-prestations .table input.input{min-height:36px;min-width:0;box-sizing:border-box}
body.embed #page-prestations .table .btn.small{min-height:36px}
body.embed #page-prestations .table .icon-btn{width:36px;height:36px;min-width:36px}
body.embed #page-prestations .table td{vertical-align:middle}
body.embed #page-prestations #prest-lines-table .prest-designation{min-width:0;width:100%}
body.embed #page-prestations #prest-lines-table .prest-type-mo{min-width:0;width:100%}
body.embed #page-prestations #prest-lines-table .prest-temps,
body.embed #page-prestations #prest-lines-table .prest-taux{width:100%;max-width:96px}
body.embed #page-prestations .table td.muted{overflow-wrap:anywhere}
body.embed #page-prestations .prest-toggle-sources{white-space:nowrap}
body.embed #page-prestations .prest-sources-row .cart-item{flex-wrap:wrap;min-width:0}
body.embed #page-prestations .prest-sources-row .cart-item>div{flex:1 1 200px!important;min-width:0;overflow-wrap:anywhere}
body.embed #page-prestations .prest-sources-row .cart-item .icon-btn{flex:none}

/* --- Tableau intermédiaire : aération réduite --- */
@container pt (max-width:980px){
  body.embed #prest-lines-table th,body.embed #prest-lines-table td{padding:9px 8px}
  body.embed #prest-lines-table td:nth-child(3){max-width:130px}
}

/* --- Lignes de prestation : sous 780 px, chaque ligne devient une carte --- */
@container pt (max-width:779px){
  body.embed #prest-lines-table,body.embed #prest-lines-table tbody,
  body.embed #prest-lines-table tr,body.embed #prest-lines-table td{display:block;width:100%;min-width:0;box-sizing:border-box}
  body.embed #prest-lines-table thead{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
  body.embed #prest-lines-table tr[data-idx]:not(.prest-sources-row){
    display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px 10px;align-items:end;
    padding:12px 14px;border-bottom:1px solid var(--border)}
  body.embed #prest-lines-table tr[data-idx]:not(.prest-sources-row) td{padding:0;border:0;max-width:none;width:auto;min-width:0}
  body.embed #prest-lines-table tr[data-idx]:not(.prest-sources-row):hover td{background:transparent}
  body.embed #prest-lines-table td:nth-child(1){grid-column:1/-1;font-size:14px}
  body.embed #prest-lines-table td:nth-child(2){grid-column:1/-1}
  body.embed #prest-lines-table td:nth-child(3){align-self:stretch;display:flex;flex-direction:column;justify-content:flex-end;gap:4px;max-width:none}
  body.embed #prest-lines-table td:nth-child(7){grid-column:1/-1}
  body.embed #prest-lines-table td[data-label]:not(:first-child)::before{content:attr(data-label);display:block;font-size:12px;font-weight:600;color:var(--sub);margin-bottom:4px;white-space:normal}
  body.embed #prest-lines-table td:nth-child(3)::before{margin-bottom:0}
  body.embed #prest-lines-table .prest-temps,body.embed #prest-lines-table .prest-taux{max-width:none}
  body.embed #prest-lines-table .prest-src-cell .btn{width:100%;justify-content:center}
  body.embed #prest-lines-table tr:not([data-idx]) td{padding:14px}
  body.embed #prest-lines-table tr.prest-sources-row{padding:0}
  body.embed #prest-lines-table tr.prest-sources-row[hidden]{display:none}
  body.embed #prest-lines-table tr.prest-sources-row td{padding:8px 10px;border-bottom:1px solid var(--border)}
}
@container pt (max-width:479px){
  body.embed #prest-lines-table tr[data-idx]:not(.prest-sources-row){grid-template-columns:repeat(2,minmax(0,1fr))}
  body.embed #prest-lines-table tr[data-idx]:not(.prest-sources-row) td:nth-child(3){grid-column:1/-1;flex-direction:row;align-items:baseline;justify-content:flex-start;gap:8px}
  body.embed #prest-lines-table tr[data-idx]:not(.prest-sources-row) td:nth-child(5){grid-column:1/-1}
}

/* --- Produits sans type : sous 640 px, cartes --- */
body.embed #prest-uncategorized-table td:nth-child(2){overflow-wrap:anywhere}
@container pt (max-width:639px){
  body.embed #prest-uncategorized-table,body.embed #prest-uncategorized-table tbody,
  body.embed #prest-uncategorized-table td{display:block;min-width:0;width:100%;box-sizing:border-box}
  body.embed #prest-uncategorized-table thead{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
  body.embed #prest-uncategorized-table tr{
    display:grid;grid-template-columns:minmax(0,1fr) auto auto;
    grid-template-areas:"titre titre titre" "ref ref ref" "ligne assign ban";
    gap:6px 10px;align-items:center;padding:12px 14px;border-bottom:1px solid var(--border)}
  body.embed #prest-uncategorized-table td{padding:0;border:0;width:auto}
  body.embed #prest-uncategorized-table tr:hover td{background:transparent}
  body.embed #prest-uncategorized-table .prest-unc-titre{grid-area:titre;font-weight:500;overflow-wrap:anywhere}
  body.embed #prest-uncategorized-table .prest-unc-ref{grid-area:ref;overflow-wrap:anywhere}
  body.embed #prest-uncategorized-table td[data-label="Ligne"]{grid-area:ligne}
  body.embed #prest-uncategorized-table td[data-label="Ligne"]::before{content:"Ligne ";font-weight:600}
  body.embed #prest-uncategorized-table .prest-unc-assign{grid-area:assign}
  body.embed #prest-uncategorized-table .prest-unc-ban{grid-area:ban}
}

/* --- Lignes ignorées --- */
body.embed #prest-bans-list .cart-item{flex-wrap:wrap;min-width:0}
body.embed #prest-bans-list .cart-item .name{flex:1 1 220px;min-width:0;overflow-wrap:anywhere}
body.embed #prest-bans-list .btn{min-height:36px}

/* --- Bloc d'insertion : barre collante toujours accessible --- */
body.embed #page-prestations .dv-insert{
  position:sticky;bottom:10px;z-index:5;
  display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:10px 16px;
  padding:clamp(10px,1.8cqw,16px) clamp(12px,2.2cqw,20px);
  box-shadow:0 8px 24px rgba(20,30,40,.16);border:1px solid var(--line-strong,var(--border))}
body.embed #page-prestations .dv-insert #prest-summary{flex:1 1 220px;min-width:0;overflow-wrap:anywhere}
body.embed #page-prestations .dv-insert .btn.full{flex:0 1 auto;width:auto;min-width:min(100%,300px);margin-left:auto}
body.embed #page-prestations .dv-insert .dv-hint{flex:1 1 100%;font-size:12.5px}
@container pd (max-width:640px){
  body.embed #page-prestations .dv-insert .btn.full{flex:1 1 100%;width:100%;margin-left:0}
}
/* hauteurs basses : la barre ne colle plus (elle masquerait le contenu) */
@media (max-height:620px){
  body.embed #page-prestations .dv-insert{position:static;box-shadow:none}
}

/* --- Fenêtre modale « Affecter à un type » --- */
body.embed #prest-assign-modal{padding:12px;box-sizing:border-box;overflow:auto}
body.embed #prest-assign-modal .modal{width:min(560px,100%)!important;max-width:100%;max-height:calc(100vh - 24px);overflow:auto;box-sizing:border-box;padding:clamp(14px,3vw,24px)}
body.embed #prest-assign-modal #passign-source-text{overflow-wrap:anywhere}
body.embed #prest-assign-modal #passign-search{min-height:40px;box-sizing:border-box}
body.embed #prest-assign-modal #passign-results{max-height:min(260px,32vh)!important;overflow:auto}
body.embed #prest-assign-modal .filters-row{display:flex;flex-wrap:wrap;gap:8px}
body.embed #prest-assign-modal .filters-row .input{flex:1 1 140px;max-width:none!important;min-width:0;min-height:38px;box-sizing:border-box}
body.embed #prest-assign-modal #passign-new-designation{flex-basis:220px}
body.embed #prest-assign-modal .btn{min-height:38px}
body.embed #prest-assign-modal .modal-actions{flex-wrap:wrap}
@media (max-height:640px){
  body.embed #prest-assign-modal #passign-results{max-height:min(160px,26vh)!important}
}

body.embed #page-prestations .table-card{padding:0}
@media (max-height:760px){
  @container pd (max-width:640px){
    body.embed #page-prestations .dv-insert .dv-hint{display:none}
  }
}
@container pt (min-width:780px){
  body.embed #prest-lines-table td:nth-child(2){min-width:190px}
  body.embed #prest-lines-table td:nth-child(5){min-width:120px}
}
