/* a4w_cartflow — rendus panneau, toast, modal. Prefixe a4w-cf- partout.
 *
 * Parti pris : ce panneau vit dans le theme du marchand. Il n'impose ni police
 * ni palette — il herite la typographie du theme et laisse ses boutons aux
 * classes btn/btn-primary. Les seules couleurs qu'il pose sont des neutres et
 * une couleur d'erreur, toutes exposees en variables pour qu'un theme enfant
 * puisse les reprendre sans toucher au module.
 */

#a4w-cf-host {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
}

#a4w-cf-host.a4w-cf-host--panel,
#a4w-cf-host.a4w-cf-host--modal {
  display: block;
  background: rgba(0, 0, 0, 0);
  transition: background 0.25s ease;
}

#a4w-cf-host.a4w-cf-host--panel.a4w-cf-host--open,
#a4w-cf-host.a4w-cf-host--modal.a4w-cf-host--open {
  background: rgba(0, 0, 0, 0.45);
}

#a4w-cf-host.a4w-cf-host--toast {
  display: block;
  background: none;
  pointer-events: none;
}

#a4w-cf-host.a4w-cf-host--toast .a4w-cf-toast {
  pointer-events: auto;
}

body.a4w-cf-locked {
  overflow: hidden;
}

/* Popup native : ceinture par-dessus la neutralisation JS.
 *
 * front.js met deja prestashop.blockcart.showModal a vide, et il est charge en
 * priorite 100 pour passer devant les 150 de ps_shoppingcart. Mais cette
 * neutralisation depend d'un ordre d'execution : un theme qui recreerait
 * l'objet `prestashop` apres notre script l'effacerait sans bruit. Cette regle,
 * elle, ne depend de rien. Elle ne s'applique que si le module est actif,
 * puisque la feuille n'est chargee que dans ce cas.
 */
#blockcart-modal {
  display: none !important;
}

/* --- Jetons ---------------------------------------------------------------
   Surchargeables depuis le theme enfant : redefinir ces variables suffit a
   reaccorder tout le panneau. */
.a4w-cf-panel,
.a4w-cf-modal__dialog,
.a4w-cf-toast {
  --a4w-cf-surface: #fff;
  --a4w-cf-muted: rgba(0, 0, 0, 0.56);
  --a4w-cf-rule: rgba(0, 0, 0, 0.10);
  --a4w-cf-field: rgba(0, 0, 0, 0.045);
  --a4w-cf-accent: currentColor;
  --a4w-cf-danger: #b3261e;
  --a4w-cf-success: #1e7d47;
  --a4w-cf-gutter: 1.25rem;
}

/* --- Panneau lateral --- */
.a4w-cf-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  width: min(420px, 100%);
  background: var(--a4w-cf-surface);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.18);
  transition: transform 0.28s ease;
}

.a4w-cf-panel--right { right: 0; transform: translateX(100%); }
.a4w-cf-panel--left  { left: 0;  transform: translateX(-100%); }

.a4w-cf-host--open .a4w-cf-panel { transform: translateX(0); }

.a4w-cf-panel__inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* Seul le corps defile : l'en-tete, le recap et les boutons restent visibles,
   comme sur la popup native. */
.a4w-cf-panel__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--a4w-cf-gutter);
}

.a4w-cf-panel__header,
.a4w-cf-panel__quickorder,
.a4w-cf-panel__footer,
.a4w-cf-panel .a4w-cf__totals {
  flex: 0 0 auto;
}

.a4w-cf-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem var(--a4w-cf-gutter);
  border-bottom: 1px solid var(--a4w-cf-rule);
}

.a4w-cf-panel__title {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.2;
  font-weight: 600;
}

.a4w-cf-panel__close,
.a4w-cf-modal__close {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.a4w-cf-panel__close:hover,
.a4w-cf-modal__close:hover { background: var(--a4w-cf-field); }

/* --- Lignes du panier --- */
.a4w-cf__lines {
  list-style: none;
  margin: 0;
  padding: 0;
}

.a4w-cf__line {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  grid-template-areas:
    "image name   remove"
    "image meta   meta"
    "image qty    total"
    "image error  error";
  column-gap: 0.875rem;
  row-gap: 0.25rem;
  align-items: start;
  padding: 1rem 0;
  border-bottom: 1px solid var(--a4w-cf-rule);
}

.a4w-cf__line:last-child { border-bottom: 0; }

.a4w-cf__line-image {
  grid-area: image;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--a4w-cf-rule);
  border-radius: 6px;
  background: var(--a4w-cf-field);
}

.a4w-cf__line-image img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.a4w-cf__line-name {
  grid-area: name;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.35;
  color: inherit;
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.a4w-cf__line-name:hover { text-decoration: underline; }

.a4w-cf__line-meta {
  grid-area: meta;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--a4w-cf-muted);
}

.a4w-cf__line-price { font-variant-numeric: tabular-nums; }

.a4w-cf__line-remove {
  grid-area: remove;
  justify-self: end;
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--a4w-cf-muted);
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
}

.a4w-cf__line-remove:hover:not(:disabled) {
  background: var(--a4w-cf-field);
  color: inherit;
}

.a4w-cf__line-remove:disabled { opacity: 0.45; cursor: default; }

/* Compteur : une pastille bordee, le nombre en chiffres a chasse fixe pour que
   les lignes ne dansent pas quand la quantite change. */
.a4w-cf__line-qty {
  grid-area: qty;
  align-self: center;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  /* Bordure, rayon et taille surchargeables par le thème (--a4w-cf-qty-*), pour aligner ce
     compteur sur les autres sélecteurs de quantité du site. */
  border: 1px solid var(--a4w-cf-qty-border, var(--a4w-cf-rule));
  border-radius: var(--a4w-cf-qty-radius, 999px);
  overflow: hidden;
}

.a4w-cf__qty-btn {
  width: var(--a4w-cf-qty-size, 2rem);
  height: var(--a4w-cf-qty-size, 2rem);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.a4w-cf__qty-btn:hover:not(:disabled) { background: var(--a4w-cf-field); }
.a4w-cf__qty-btn:disabled { opacity: 0.45; cursor: default; }

.a4w-cf__qty-value {
  min-width: 2.25rem;
  text-align: center;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

.a4w-cf__line-total {
  grid-area: total;
  align-self: center;
  justify-self: end;
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.a4w-cf__line-error {
  grid-area: error;
  color: var(--a4w-cf-danger);
  font-size: 0.8125rem;
  margin-top: 0.25rem;
}

/* Une region role="alert" mise en display:none sort de l'arbre
   d'accessibilite : on la masque visuellement en la laissant rendue.
   .a4w-cf__sr-only porte le meme traitement pour l'annonce de l'ajout, que le
   voyant percoit par le filet sur la ligne et le lecteur d'ecran par ce texte. */
.a4w-cf__sr-only,
.a4w-cf__line-error:empty,
.a4w-cf-qo__error:empty {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Le panneau ne reannonce pas l'ajout au-dessus de la liste : il designe la
   ligne concernee. Un filet a gauche, et un lavis qui s'efface. C'est le seul
   effet du panneau, tout le reste est immobile. */
.a4w-cf__line--added {
  position: relative;
  margin-left: calc(var(--a4w-cf-gutter) * -1);
  padding-left: calc(var(--a4w-cf-gutter) - 0.375rem);
  animation: a4w-cf-added 1.8s ease-out 1;
}

.a4w-cf__line--added::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.75rem;
  bottom: 0.75rem;
  width: 3px;
  border-radius: 3px;
  background: var(--a4w-cf-accent);
}

@keyframes a4w-cf-added {
  from { background: var(--a4w-cf-field); }
  to   { background: transparent; }
}

.a4w-cf__empty {
  margin: 0;
  padding: 3rem 0;
  text-align: center;
  color: var(--a4w-cf-muted);
}

/* --- Recap des totaux --- */
.a4w-cf__totals {
  padding: 0.875rem var(--a4w-cf-gutter);
  border-top: 1px solid var(--a4w-cf-rule);
  font-size: 0.9375rem;
}

.a4w-cf__summary {
  margin: 0 0 0.625rem;
  font-size: 0.8125rem;
  color: var(--a4w-cf-muted);
}

.a4w-cf__subtotal,
.a4w-cf__total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.1875rem 0;
}

.a4w-cf__subtotal-value,
.a4w-cf__total-value {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.a4w-cf__total--excl {
  margin-top: 0.375rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--a4w-cf-rule);
  font-weight: 600;
}

.a4w-cf__total--incl {
  font-size: 1.0625rem;
  font-weight: 700;
}

/* --- Pied : les deux boutons occupent toute la largeur du panneau ---
   Cote a cote quand ils tiennent, l'un sous l'autre sinon. « Commander · total » est plus
   long qu'un libelle seul : dans un panneau de 420 px, il ne tient plus a cote de « Voir le
   panier » sans se couper. Chaque bouton part de sa largeur naturelle, le second passe a la
   ligne quand la somme deborde, et chacun s'etire sur la place qui reste. L'ordre visuel
   reste celui du balisage, donc celui de la lecture et de la tabulation. */
.a4w-cf-panel__footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  padding: 0.875rem var(--a4w-cf-gutter) var(--a4w-cf-gutter);
}

.a4w-cf-panel__footer > .a4w-cf__hook { flex: 1 1 100%; }

.a4w-cf-panel__footer .btn {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* Tunnel delegue a un autre module : un seul bouton, pleine largeur. */
.a4w-cf-panel__footer--single .btn { flex-basis: 100%; }

/* Bouton d'achat avec son total : si la place manque, la seule coupure possible tombe apres
   le point median (espace insecable avant lui), jamais au milieu du montant. */
.a4w-cf__btn-total {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.a4w-cf-panel :focus-visible,
.a4w-cf-modal :focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* --- Modal --- */
.a4w-cf-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.a4w-cf-modal__dialog {
  background: var(--a4w-cf-surface);
  width: min(640px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  transform: scale(0.96);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.a4w-cf-host--open .a4w-cf-modal__dialog { transform: scale(1); opacity: 1; }

.a4w-cf-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem var(--a4w-cf-gutter);
  border-bottom: 1px solid var(--a4w-cf-rule);
}

.a4w-cf-modal__title {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.2;
  font-weight: 600;
}

.a4w-cf-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--a4w-cf-gutter);
}

.a4w-cf-modal__body .a4w-cf__totals {
  margin: 0 calc(var(--a4w-cf-gutter) * -1);
}

.a4w-cf-modal__footer {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.625rem;
  padding: 0.875rem var(--a4w-cf-gutter) var(--a4w-cf-gutter);
}

.a4w-cf-modal__footer > .a4w-cf__hook { flex-basis: 100%; }

/* Un lien .btn ne centre son texte que si le theme le fait ; ici, quoi qu'il en soit, le
   libelle et le total restent centres, y compris en pleine largeur sur mobile. */
.a4w-cf-modal__footer .btn { text-align: center; }

/* --- Toast --------------------------------------------------------------
   Meme vocabulaire que le panneau — vignette encadree, nom en evidence,
   action discrete — reduit a la seule ligne qui vient d'etre ajoutee. Il
   n'affiche aucun total : ce mode existe pour ne pas interrompre. */
.a4w-cf-toast {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  max-width: min(24rem, calc(100% - 2rem));
  background: var(--a4w-cf-surface);
  border: 1px solid var(--a4w-cf-rule);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
  padding: 0.875rem 1rem;
  transform: translateY(1rem);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.a4w-cf-host--open .a4w-cf-toast { transform: translateY(0); opacity: 1; }

.a4w-cf-toast__inner {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 0.625rem;
  align-items: start;
}

.a4w-cf-toast__mark {
  color: var(--a4w-cf-success);
  font-size: 1.125rem;
  line-height: 1.3;
}

.a4w-cf-toast__image {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--a4w-cf-rule);
  border-radius: 6px;
  background: var(--a4w-cf-field);
}

.a4w-cf-toast__image img { max-width: 100%; max-height: 100%; display: block; }

.a4w-cf-toast__body {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.a4w-cf-toast__name {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.a4w-cf-toast__label {
  font-size: 0.8125rem;
  color: var(--a4w-cf-muted);
}

.a4w-cf-toast__link {
  font-size: 0.8125rem;
  align-self: flex-start;
}

.a4w-cf-toast__close {
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--a4w-cf-muted);
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
}

.a4w-cf-toast__close:hover { background: var(--a4w-cf-field); color: inherit; }

.a4w-cf-toast :focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Repli d'erreur : meme boite, un filet rouge pour dire que ce n'est pas une
   confirmation. */
.a4w-cf-toast--error .a4w-cf-toast__inner {
  display: block;
  border-left: 3px solid var(--a4w-cf-danger);
  padding-left: 0.75rem;
}

/* --- Adaptation mobile : 768 px, en dur --- */
@media (max-width: 767px) {
  .a4w-cf-panel {
    --a4w-cf-gutter: 1rem;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 85vh;
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
  }

  .a4w-cf-panel--right,
  .a4w-cf-panel--left { transform: translateY(100%); }

  .a4w-cf-host--open .a4w-cf-panel { transform: translateY(0); }

  /* Poignee de glissement : la feuille se ferme au doigt, autant le dire. */
  .a4w-cf-panel__header::before {
    content: '';
    position: absolute;
    top: 0.5rem;
    left: 50%;
    width: 2.25rem;
    height: 4px;
    margin-left: -1.125rem;
    border-radius: 4px;
    background: var(--a4w-cf-rule);
  }

  .a4w-cf-panel__header {
    position: relative;
    padding-top: 1.375rem;
  }

  .a4w-cf__line { grid-template-columns: 56px minmax(0, 1fr) auto; }
  .a4w-cf__line-image { width: 56px; height: 56px; }

  .a4w-cf-modal { padding: 0; }

  .a4w-cf-modal__dialog {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  /* En plein ecran, deux boutons cote a cote deviennent etroits : on les
     empile, action principale en haut — column-reverse, puisqu'elle est la
     derniere du balisage. */
  .a4w-cf-modal__footer { flex-direction: column-reverse; }
  .a4w-cf-modal__footer .btn { width: 100%; }
  .a4w-cf-modal__footer > .a4w-cf__hook { order: 1; }

  .a4w-cf-toast {
    left: 0;
    right: 0;
    top: 0;
    bottom: auto;
    max-width: none;
    border-radius: 0;
    transform: translateY(-1rem);
  }
}

/* --- Animation vol-vers-panier --- */
.a4w-cf-fly {
  position: fixed;
  /* Au-dessus du conteneur des rendus (10000), sinon le vol passerait derriere
     le voile du panneau qu'il rejoint. */
  z-index: 10001;
  pointer-events: none;
  object-fit: cover;
  border-radius: 6px;
  transition: left 0.65s cubic-bezier(0.4, 0, 0.2, 1),
              top 0.65s cubic-bezier(0.55, 0, 1, 0.45),
              width 0.65s ease,
              height 0.65s ease,
              opacity 0.65s ease;
}

/* L'accessibilite prime sur l'effet : rien ne vole si le visiteur a demande
   a reduire les animations. Double garde, CSS et JS. */
@media (prefers-reduced-motion: reduce) {
  .a4w-cf-fly { display: none; }

  .a4w-cf-panel,
  .a4w-cf-modal__dialog,
  .a4w-cf-toast { transition: none; }

  .a4w-cf__line--added { animation: none; }
}

/* --- Accelerateur B2B : commande rapide --- */
.a4w-cf-panel__quickorder {
  padding: 0.875rem var(--a4w-cf-gutter);
  border-bottom: 1px solid var(--a4w-cf-rule);
}

.a4w-cf-qo__label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  color: var(--a4w-cf-muted);
}

.a4w-cf-qo__input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--a4w-cf-rule);
  border-radius: 6px;
  background: var(--a4w-cf-surface);
  color: inherit;
  font: inherit;
}

.a4w-cf-qo__results {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  max-height: 40vh;
  overflow-y: auto;
}

.a4w-cf-qo__item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.4rem 0.375rem;
  border-radius: 4px;
  cursor: pointer;
}

.a4w-cf-qo__item:hover,
.a4w-cf-qo__item:focus,
.a4w-cf-qo__item--active { background: var(--a4w-cf-field); }

.a4w-cf-qo__ref { font-weight: 600; }

.a4w-cf-qo__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.a4w-cf-qo__price { font-variant-numeric: tabular-nums; }

.a4w-cf-qo__empty {
  padding: 0.4rem 0.375rem;
  color: var(--a4w-cf-muted);
}

.a4w-cf-qo__choose {
  font-size: 0.8em;
  color: var(--a4w-cf-muted);
  white-space: nowrap;
}

.a4w-cf-qo__error {
  color: var(--a4w-cf-danger);
  font-size: 0.85em;
  margin-top: 0.35rem;
}

/* Barre « livraison offerte » (2.4.0, refs#6713) — maquette Panier de la charte v2 de gumuchev2 :
   fond crème, filet, barre de 4 px à l'encre. Jetons du thème avec repli. */
.a4w-cf-ship {
  background: var(--light-bg, #FAF7F4);
  color: var(--text-color, #1D191B);
  font-size: 0.875rem;
  line-height: 1.5;
}

.a4w-cf-ship--drawer {
  padding: 1rem var(--a4w-cf-gutter, 1.25rem);
  border-bottom: 1px solid var(--border-color, #E4E3E4);
}

.a4w-cf-ship--page {
  margin-bottom: 1rem;
  padding: 14px 16px;
  border-radius: var(--border-radius, 3px);
}

.a4w-cf-ship__text {
  margin: 0;
}

.a4w-cf-ship__bar {
  height: 4px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--border-color, #E4E3E4);
}

.a4w-cf-ship__bar > span {
  display: block;
  height: 100%;
  background: var(--text-color, #1D191B);
}
