/* Fiche produit : le feuillet blanc d'origine (bon, variante, prix), les onglets et les feuillets de couleur. Jetons dans app.css. */

.pv { min-width: 0; }
.pv--busy { opacity: .6; transition: opacity .15s; }
.pv-notices:empty { display: none; }
.pv-notices { display: flex; flex-direction: column; gap: 8px; margin-bottom: var(--gap); }
.pv h2 { margin: 0; color: var(--ink); }

/* ---------- Le feuillet blanc d'origine ---------- */

/* Papier à coins carrés, tenu par son seul filet : le bon, la grille des variantes, puis le bandeau des prix en travers. */
.pv-top { display: grid; grid-template-columns: minmax(0, 1fr); background: var(--surface); border: 1px solid var(--rule); }
.pv-slot-a { min-width: 0; }
.pv-slot-b, .pv-slot-c { min-width: 0; border-top: 1px solid var(--rule); }
.pv-slot-d { min-width: 0; border-top: 1px solid var(--rule); padding: 16px 20px 20px; }
.pv-slot-d:has(> [hidden]) { display: none; }
.pv-top .block { border: 0; border-radius: 0; background: none; padding: 16px 20px 20px; height: 100%; }
.pv-top .block + .block { margin-top: 0; }
.pv-top .block h2 { font-size: var(--fs-md); }

/* ---------- A. Le bon ---------- */

.slip { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 28px; padding: 20px; }

.slip-media { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.slip-media--empty {
  aspect-ratio: 1; align-items: center; justify-content: center;
  border: 1px dashed var(--rose); background: var(--missing-tint);
}
.slip-noimage { color: var(--missing); font-weight: 600; }
.slip-preview {
  aspect-ratio: 1; display: grid; place-items: center; overflow: hidden;
  background: var(--surface); border: 1px solid var(--rule);
}
.slip-preview-img { width: 100%; height: 100%; object-fit: contain; }
/* Deux rangées de vignettes entières, la suite défile. */
.slip-thumbs { display: flex; flex-wrap: wrap; gap: 6px; max-height: 106px; overflow-y: auto; padding: 2px; }
.slip-thumb {
  width: 48px; height: 48px; padding: 0; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface); cursor: zoom-in; overflow: hidden;
}
.slip-thumb img { width: 100%; height: 100%; object-fit: contain; }
.slip-thumb:hover, .slip-thumb.is-current { border-color: var(--ink); }

.slip-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.slip-top { display: flex; align-items: flex-start; gap: 24px; }
.slip-heading { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }

/* Le numéro du bon : la référence fournisseur, imprimée en grand et copiable. */
.slip-number { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; line-height: 1; }
.slip-number-prefix { color: var(--muted); font-size: var(--fs-sm); }
.slip-number .copyable {
  font-family: var(--font); font-size: 34px; font-weight: 700; color: var(--ink); letter-spacing: -.01em;
  padding: 0; border-bottom-width: 2px; line-height: 1.05;
}
.slip-number .copyable[data-copied]::after { font-size: var(--fs-sm); font-weight: 500; letter-spacing: 0; }
.slip-name { font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; max-width: 40ch; }
.slip-supplier { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.slip-brand { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; }
.slip-brand-logo { height: 22px; width: auto; max-width: 88px; object-fit: contain; }
.slip-ids { display: flex; flex-wrap: wrap; gap: 2px 16px; }
.slip-id { white-space: nowrap; }

/* Le prix dès : la case du total, encadrée comme sur un bon. */
.slip-price {
  flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 168px;
  padding: 10px 14px 12px; border: 1px solid var(--ink); text-align: right;
}
.slip-price-label { color: var(--muted); font-size: var(--fs-sm); }
.slip-price-value { color: var(--ink); font-size: 30px; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.slip-price-note { color: var(--muted); font-size: var(--fs-xs); }
.slip-price[data-state="missing"] { border: 1px dashed var(--rose); background: var(--missing-tint); }
.slip-price[data-state="missing"] .slip-price-value { font-size: var(--fs-lg); }
.slip-price[data-state="inconsistent"] .slip-price-value { text-decoration: line-through 2px var(--rose); }

/* Les cases du bon : une grille imprimée à filet d'un pixel ; la donnée reçue remplit la case. */
.slip-form { display: flex; flex-direction: column; gap: 8px; }
.slip-form-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 16px; flex-wrap: wrap; }
.slip-count { color: var(--ink); font-weight: 650; font-size: var(--fs-md); }
.slip-count[data-tone="missing"] { color: var(--rose); }
.slip-legend { display: flex; gap: 14px; color: var(--muted); }
.slip-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.slip-legend-key { width: 18px; height: 12px; border: 1px solid var(--rule-strong); background: var(--surface); }
.slip-legend-key[data-state="missing"] { border: 1px dashed var(--rose); background: var(--missing-tint); }
.slip-legend-key[data-state="inconsistent"] { background: linear-gradient(var(--rose), var(--rose)) center / 100% 2px no-repeat var(--surface); }

.slip-cases {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0;
  border-top: 1px solid var(--rule-strong); border-left: 1px solid var(--rule-strong);
  counter-reset: slip-case;
}
.slip-case {
  counter-increment: slip-case; position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0; min-height: 58px;
  padding: 7px 10px 8px; border-right: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule-strong);
}
.slip-case dt { color: var(--muted); font-size: var(--fs-xs); line-height: 1.2; }
/* Le numéro imprimé de la case, devant son libellé : « 3 cases vides sur 16 » se lit contre lui. Décoratif pour les lecteurs d'écran. */
.slip-case dt::before {
  content: counter(slip-case, decimal-leading-zero);
  content: counter(slip-case, decimal-leading-zero) / "";
  display: inline-block; min-width: 2.2ch; margin-right: 5px;
  font-size: 10px; font-weight: 600; letter-spacing: .02em; font-variant-numeric: tabular-nums; color: var(--muted);
}
.slip-case dd {
  margin: 0; color: var(--ink); font-weight: 600; line-height: 1.3; min-width: 0;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; overflow-wrap: anywhere;
}
.slip-value-text { min-width: 0; }
.slip-case .copyable { font-family: var(--font); font-size: var(--fs-base); font-weight: 600; color: var(--ink); padding: 0; }
.slip-case a { color: var(--ink); }
.slip-case .slip-stock-key { display: inline-block; width: 14px; height: 10px; min-width: 0; padding: 0; border-radius: 2px; flex: none; border: 1px solid rgba(33, 61, 138, .18); }
.slip-star { width: 15px; height: 15px; }

/* Case vide : le filet passe en pointillé, la case se teinte et dit ce qui manque. */
.slip-case[data-state="missing"] { background: var(--missing-tint); }
.slip-case[data-state="missing"]::before {
  content: ""; position: absolute; inset: 3px; border: 1px dashed var(--rose); pointer-events: none;
}
.slip-missing { color: var(--missing); font-weight: 650; }
/* Case incohérente : la valeur reçue est barrée. */
.slip-case[data-state="inconsistent"] .slip-value-text { text-decoration: line-through 2px var(--rose); }
.slip-flag { color: var(--missing); font-size: var(--fs-xs); font-weight: 650; }

/* Le seul mouvement de la page : à l'ouverture d'une fiche, les cases se remplissent en cascade courte. */
.slip--fill .slip-case dd { animation: slip-fill .5s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 24ms + 80ms); }
@keyframes slip-fill {
  from { clip-path: inset(0 100% 0 0); opacity: .2; }
  to { clip-path: inset(0 0 0 0); opacity: 1; }
}

.slip-extra { display: flex; flex-direction: column; gap: 8px; }
.slip-cats { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.slip-cats .label { margin-right: 4px; }
.chip--main { background: var(--accent-soft); border-color: var(--cyan); color: var(--ink); }
.chip-star { width: 15px; height: 15px; margin-left: -4px; }
.pv-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pv-dates { margin: 0; }
.swatch--none { background: var(--surface); border: 1px dashed var(--rule-strong); }

/* ---------- B. Sélecteur de variante ---------- */

/* Le défileur montre un nombre entier de rangées sous l'en-tête collant et s'arrête toujours sur le haut d'une rangée.
   --pv-hbar : hauteur de la barre horizontale éventuelle, mesurée au rendu (product-zones.js). */
.pv-grid-frame {
  --pv-head-h: 28px; --pv-row-h: 33px; --pv-rows: 7;
  max-height: calc(var(--pv-head-h) + var(--pv-rows) * var(--pv-row-h) + 2px + var(--pv-hbar, 0px));
  overflow: auto; border: 1px solid var(--rule);
  scroll-snap-type: y mandatory; scroll-padding-top: var(--pv-head-h);
}
.pv-grid { width: auto; min-width: 100%; }
.pv-grid th, .pv-grid td { padding: 3px 4px; white-space: nowrap; vertical-align: middle; }
.pv-grid thead th { text-align: center; padding: 4px 6px; height: var(--pv-head-h); }
.pv-grid tbody th, .pv-grid tbody td { height: var(--pv-row-h); }
.pv-grid tbody tr, .pv-grid tbody th { scroll-snap-align: start; }
.pv-grid thead th.sticky-col { text-align: left; }
.pv-grid .pv-rowhead { text-align: left; font-weight: 550; color: var(--ink); padding-right: 12px; z-index: 1; }
.pv-rowname { display: inline-flex; align-items: center; gap: 6px; }
.pv-cell-wrap { text-align: center; }
.pv-cell {
  display: block; width: 100%; min-width: 44px; height: 26px; padding: 0 4px; border-radius: 3px;
  border: 1px solid transparent; font-size: var(--fs-xs); font-weight: 600; color: var(--ink); cursor: pointer;
}
span.pv-cell { cursor: default; }
button.pv-cell:hover { border-color: var(--ink); }
.pv-cell--high { background: rgba(55, 188, 221, .7); }
.pv-cell--mid { background: rgba(55, 188, 221, .4); }
.pv-cell--low { background: rgba(55, 188, 221, .16); }
.pv-cell--none { background: var(--rose-pale); color: var(--rose-deep); }
.pv-cell--unknown { background: var(--surface-alt); color: var(--muted); }
/* Combinaison absente : la case reste vide, filet en pointillé, comme une case vide du bon. */
.pv-cell--empty { background: transparent; border: 1px dashed var(--rule-strong); }
.pv-key { display: inline-block; width: 18px; min-width: 0; height: 12px; vertical-align: middle; }
.pv-legend { margin: 8px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.pv-legend .pv-key-label { margin-right: 8px; }
.pv-chiprow { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-top: 8px; }
.pv-chiprow:first-child { margin-top: 0; }
.chip[disabled] { opacity: .45; cursor: not-allowed; }
.pv-variants .block-head .aside { display: inline-flex; }

.pv-vtable { display: flex; flex-direction: column; gap: 8px; }
.pv-vtable[hidden] { display: none; }
.pv-vtable-bar { display: flex; align-items: center; gap: 12px; }
.pv-vtable-bar .input { flex: 1; max-width: 280px; }
.pv-vtable-frame { overflow: visible; border: 1px solid var(--rule); }
.pv-vtable-frame td, .pv-vtable-frame th { white-space: nowrap; }
/* Le tableau est au-dessus des feuillets : les onglets sont alors en bas de l'écran, l'en-tête colle sous la barre du haut. */
.pv-vtable-frame .data-table thead th { top: var(--topbar-h); }
.th-sort { display: inline-flex; align-items: center; gap: 2px; background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-transform: inherit; }
.th-sort:hover { color: var(--ink); }
.th-sort-icon { width: 14px; height: 14px; opacity: 0; }
.th-sort:hover .th-sort-icon { opacity: .5; }
th[aria-sort="ascending"] .th-sort-icon, th[aria-sort="descending"] .th-sort-icon { opacity: 1; color: var(--ink); }
th[aria-sort="descending"] .th-sort-icon { transform: rotate(180deg); }
.pv-row { cursor: pointer; }
.pv-row:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

/* ---------- C. Prix et marquages ---------- */

/* Un bandeau en travers de la fiche : titre et anomalies, paliers de prix de gauche à droite, marquages ; un filet entre chaque groupe. */
.pv-top .pv-banner { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 0; padding: 14px 20px 16px; }
.pv-banner > * { min-width: 0; margin: 0; padding: 0 24px; border-left: 1px solid var(--rule); }
.pv-banner > :first-child { padding-left: 0; border-left: 0; }
.pv-banner-head { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.pv-banner-head h2 { white-space: nowrap; }
.pv-checks-link { text-decoration: none; }
.pv-checks-link:hover { text-decoration: underline; }
.pv-price-list { display: flex; flex-wrap: wrap; gap: 10px 28px; max-width: 100%; overflow-x: auto; }
.pv-price { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pv-tiers { border-collapse: collapse; font-size: var(--fs-sm); }
.pv-tiers th { text-align: left; color: var(--muted); font-size: var(--fs-xs); font-weight: 600; padding: 3px 14px 3px 0; white-space: nowrap; }
.pv-tiers td { padding: 3px 14px; border-left: 1px solid var(--rule); white-space: nowrap; }
.pv-tiers td:last-child { padding-right: 0; }
.pv-tiers tr + tr > * { border-top: 1px solid var(--rule); }
.pv-figures { gap: 8px 22px; }
.pv-banner > .pv-chips { align-self: center; }

/* ---------- Onglets des feuillets ---------- */

[data-sheet="markings"] { --sheet: var(--cyan); --sheet-on: var(--cyan-on); --sheet-deep: var(--cyan-deep); --sheet-pale: var(--cyan-pale); --sheet-tint: var(--cyan-tint); }
[data-sheet="sheet"] { --sheet: var(--blue); --sheet-on: var(--blue-on); --sheet-deep: var(--blue-deep); --sheet-pale: var(--blue-pale); --sheet-tint: var(--blue-tint); }
[data-sheet="checks"] { --sheet: var(--rose); --sheet-on: var(--rose-on); --sheet-deep: var(--rose-deep); --sheet-pale: var(--rose-pale); --sheet-tint: var(--rose-tint); }
[data-sheet="coverage"] { --sheet: var(--green); --sheet-on: var(--green-on); --sheet-deep: var(--green-deep); --sheet-pale: var(--green-pale); --sheet-tint: var(--green-tint); }
[data-sheet="raw"] { --sheet: var(--yellow); --sheet-on: var(--yellow-on); --sheet-deep: var(--yellow-deep); --sheet-pale: var(--yellow-pale); --sheet-tint: var(--yellow-tint); }

/* Collants en haut comme en bas : avant qu'on y arrive, les onglets dépassent du bas de l'écran comme ceux d'un carnet. */
.section-nav {
  position: sticky; top: var(--topbar-h); bottom: 0; z-index: 20;
  display: flex; align-items: flex-end; gap: 4px; overflow-x: auto; height: var(--nav-h);
  margin: 20px -20px 0; padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--rule-strong);
}
.sheet-tab {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; white-space: nowrap; text-decoration: none;
  background: var(--sheet-pale); color: var(--sheet-deep); font-weight: 600;
}
.sheet-tab:hover { background: color-mix(in srgb, var(--sheet) 22%, var(--surface)); }
.sheet-tab[aria-current="true"] { background: var(--sheet); color: var(--sheet-on); }
.sheet-tab:focus-visible { outline-offset: -4px; }
.sheet-tab[aria-current="true"]:is([data-sheet="sheet"], [data-sheet="checks"]):focus-visible { outline-color: #fff; }
.section-nav .count { padding: 0 7px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 700; line-height: 18px; background: var(--surface); color: var(--sheet-deep); }
.section-nav .count:empty { display: none; }
.section-nav .count[data-tone="error"] { color: var(--error-ink); }
.section-nav .count[data-tone="warning"] { color: var(--warning-ink); }
.section-nav .count[data-tone="ok"] { color: var(--ok-ink); }

/* ---------- Feuillets ---------- */

.sheets { display: flex; flex-direction: column; gap: 20px; margin-top: 20px; }
.sheet {
  --sheet-rule: color-mix(in srgb, var(--sheet) 35%, var(--surface));
  scroll-margin-top: calc(var(--topbar-h) + var(--nav-h) + 8px); background: var(--sheet-tint); border: 1px solid var(--sheet-rule); min-width: 0;
}
.sheet-head {
  position: relative; display: flex; align-items: baseline; gap: 12px; padding: 12px 18px 15px;
  background: var(--sheet); color: var(--sheet-on);
}
.sheet .sheet-head h2 { color: var(--sheet-on); font-size: var(--fs-lg); }
.sheet-count { margin-left: auto; font-size: var(--fs-sm); font-weight: 600; }
.sheet-count:empty { display: none; }
/* La souche perforée : une ligne de petits trous entre l'en-tête et le corps du feuillet. */
.sheet-head::after {
  content: ""; position: absolute; left: 6px; right: 6px; bottom: -3px; height: 6px;
  background: radial-gradient(circle, var(--sheet-tint) 1.6px, transparent 2.1px) 0 50% / 9px 6px repeat-x;
}
.sheet-body { padding: 18px; min-width: 0; }

/* Dans un feuillet, les blocs internes deviennent des zones du papier, pas des cartes : des filets d'un pixel posés sur le feuillet. */
.sheet-body > .block { background: none; border: 0; border-radius: 0; padding: 0; }
.sheet-body .data-table { background: transparent; }
.sheet-body .data-table .sticky-col { background: var(--sheet-tint); }
.sheet-body .data-table thead th, .sheet-body .data-table thead .sticky-col { background: var(--sheet-pale); color: var(--text); }
.sheet-body .data-table tbody tr:hover td { background: color-mix(in srgb, var(--sheet-pale) 55%, var(--sheet-tint)); }

/* ---------- Feuillet Fiche ---------- */

.pv-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--sheet-rule, var(--rule)); border-bottom: 1px solid var(--sheet-rule, var(--rule)); }
.pv-col { min-width: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.pv-col:first-child { padding-left: 0; }
.pv-col:last-child { padding-right: 0; }
.pv-col + .pv-col { border-left: 1px solid var(--sheet-rule, var(--rule)); }
.pv-col h3 { margin: 0; font-size: var(--fs-md); color: var(--ink); }
.pv-col h4 { margin: 6px 0 0; }
.pv-rich { overflow-wrap: anywhere; max-height: 420px; overflow-y: auto; max-width: 70ch; }
.pv-rich p, .pv-rich ul, .pv-rich ol { margin: 0 0 8px; }
.pv-plain { list-style: none; margin: 0; padding: 0; }
.pv-levels { margin: 6px 0 0; padding-left: 18px; font-size: var(--fs-sm); }
.pv-col code { font-family: var(--font-mono); font-size: var(--fs-xs); }
.pv-textile { font-size: var(--fs-sm); }

/* ---------- Chargement ---------- */

.pv-skeleton { display: flex; flex-direction: column; gap: var(--gap); }
.pv-skeleton-slip { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 28px; }
.pv-skeleton-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--gap); }

/* Sous 1200 px, les prix passent en bande au-dessus des variantes et le bon se resserre. */
@media (max-width: 1199px) {
  .pv-slot-c { order: 1; }
  .pv-slot-b { order: 2; }
  .pv-slot-d { order: 3; }
  .slip { grid-template-columns: 220px minmax(0, 1fr); gap: 20px; padding: 16px; }
  .slip-number .copyable { font-size: 28px; }
  .slip-name { font-size: 20px; }
  .slip-price-value { font-size: 24px; }
  .slip-top { gap: 16px; }
  .slip-case { padding: 6px 8px 7px; }
  .slip-thumb { width: 40px; height: 40px; }
  .slip-thumbs { max-height: 90px; }
  .pv-skeleton-slip { grid-template-columns: 220px minmax(0, 1fr); }
}

@media (max-width: 1100px) {
  .pv-cols { grid-template-columns: minmax(0, 1fr); }
  .pv-col, .pv-col:first-child, .pv-col:last-child { padding: 16px 0; }
  .pv-col + .pv-col { border-left: 0; border-top: 1px solid var(--sheet-rule, var(--rule)); }
  .pv-skeleton-row { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .slip { grid-template-columns: minmax(0, 1fr); }
  .slip-media { max-width: 320px; }
  .slip-cases { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .slip-top { flex-direction: column; }
  .slip-price { align-items: flex-start; text-align: left; }
}
