/*
 * Produits complémentaires — maquette Figma « Produits complémentaires / Section ».
 * Habillage par site : surcharger les variables --pc-* (couleurs, polices, rayons, espacements).
 * La coche reste verte (--fd-rec-checkbox), pas la couleur de marque.
 */
#fd-recommanded-complements[hidden] {
  display: none !important;
}

#fd-recommanded-complements {
  --pc-brand-primary: #183157;
  --pc-background-surface: #fff;
  --pc-background-selected: #f5f7fc;
  --pc-background-promo: #fff2f3;
  --pc-background-placeholder: #f1f2f4;
  --pc-border-default: #dfdfdf;
  --pc-border-strong: #8c9097;
  --pc-border-active: #183157;
  --pc-text-primary: #1c2123;
  --pc-text-secondary: #6c757d;
  --pc-text-price: #212529;
  --pc-text-promo: #cc2028;
  --pc-radius-sm: 4px;
  --pc-radius-md: 8px;
  --pc-spacing-2xs: 4px;
  --pc-spacing-xs: 8px;
  --pc-spacing-sm: 12px;
  --pc-spacing-lg: 20px;
  --pc-font-title: Karla, sans-serif;
  --pc-font-text: Karla, sans-serif;
  --pc-font-price: Lato, sans-serif;
  --fd-rec-checkbox: #00AB52;

  display: flex;
  flex-direction: column;
  gap: var(--pc-spacing-sm);
  box-sizing: border-box;
  width: 100%;
  min-width: min(312px, 100%);
  padding: var(--pc-spacing-lg);
  background: var(--pc-background-surface);
  color: var(--pc-text-primary);
  font-family: var(--pc-font-text);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  text-align: left;
  padding-top: 8px;

  @media (max-width: 525px) {
    padding: var(--pc-spacing-lg) 0;
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  /* Le thème cible p, a, h3, label, button, sup… Les classes du module
     restent prioritaires (un ID + une classe bat un ID + une balise). */
  p,
  ul,
  ol,
  li,
  h1, h2, h3, h4, h5, h6,
  label,
  button,
  input,
  select,
  a,
  strong,
  b,
  em,
  i,
  small,
  sup,
  img {
    margin: 0;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-decoration: inherit;
    text-transform: inherit;
    opacity: 1;
  }

  a:hover,
  a:focus,
  a:active {
    color: inherit;
    text-decoration: inherit;
    opacity: 1;
  }

  ul,
  ol {
    padding: 0;
    list-style: none;
  }

  strong,
  b {
    font-weight: 700;
  }

  em,
  i {
    font-style: italic;
  }

  sup {
    position: static;
    top: auto;
    bottom: auto;
    line-height: inherit;
    vertical-align: baseline;
  }

  button,
  input,
  select {
    appearance: none;
    -webkit-appearance: none;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  button {
    cursor: pointer;
  }

  img {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
    border: 0;
  }

  /* —— HTML libre au-dessus du titre (optionnel) ——
     Espace bas de 12px : fourni par le gap de la section (pas de marge
     supplémentaire pour ne pas doubler l’espacement). */
  .fd-rec-header-html {
    margin: 0;
    min-width: 0;
    font: normal normal 400 13px/18px var(--pc-font-text);
    color: var(--pc-text-primary);
    word-break: break-word;

    > :first-child {
      margin-top: 0;
    }

    > :last-child {
      margin-bottom: 0;
    }

    img {
      max-width: 100%;
      height: auto;
    }

    a {
      color: inherit;
      text-decoration: underline;
    }
  }

  /* —— En-tête —— */
  .fd-rec-header {
    display: flex;
    flex-direction: column;
    gap: var(--pc-spacing-2xs);
    word-break: break-word;
  }

  .fd-rec-title {
    margin: 0;
    font: normal normal 500 16px/22px var(--pc-font-title);
    letter-spacing: 0;
    color: var(--pc-text-primary);
  }

  .fd-rec-subtitle {
    margin: 0;
    font: normal normal 400 13px/18px var(--pc-font-text);
    letter-spacing: 0;
    color: var(--pc-text-secondary);
    word-break: break-word;
  }

  /* Sous-titre du bloc et sous-texte des options : HTML saisi en BO (gras, italique, police…) */
  .fd-rec-subtitle,
  .fd-rec-subtext {
    p {
      margin: 0;
    }

    strong,
    b {
      font-weight: 700;
    }

    em,
    i {
      font-style: italic;
    }

    a {
      color: inherit;
      text-decoration: underline;
    }

    a:hover,
    a:focus {
      color: var(--pc-text-primary);
    }

    img {
      max-width: 100%;
      height: auto;
      vertical-align: middle;
    }
  }

  /* —— Mention bas de bloc (CGV) —— */
  .fd-rec-footer {
    margin: 0;
    font: normal normal 400 12px/16px var(--pc-font-text);
    letter-spacing: 0;
    color: var(--pc-text-secondary);
    text-align: center;
    word-break: break-word;
  }

  .fd-rec-footer p {
    margin: 0;
  }

  .fd-rec-footer a {
    color: inherit;
    text-decoration: underline;
  }

  /* —— Liste d’options (dynamique : 2, 3 ou plus) —— */
  .fd-rec-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--pc-spacing-sm);
  }

  .fd-rec-item {
    margin: 0;
  }

  .fd-rec-item__row {
    display: block;
  }

  /* Carte option */
  .fd-rec-label {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    text-align: left;
    font-weight: 400;
    background: var(--pc-background-surface);
    border: 1px solid var(--pc-border-default);
    border-radius: var(--pc-radius-md);
    transition:
      background-color 0.15s ease,
      border-color 0.15s ease;

    &:hover {
      border-color: var(--pc-border-active);
    }

    &:has(.fd-rec-input:checked) {
      border-color: var(--pc-border-active);
      background-color: var(--pc-background-selected);
    }
  }

  .fd-rec-label__main {
    display: flex;
    align-items: center;
    gap: var(--pc-spacing-sm);
    min-width: 0;
    padding: var(--pc-spacing-sm);
  }

  /* Case à cocher (checkbox ou radio en sélection unique) */
  .fd-rec-input {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: var(--pc-background-surface) no-repeat center / 18px 18px;
    background-origin: border-box;
    border: 1.5px solid var(--pc-border-strong);
    border-radius: var(--pc-radius-sm);
    cursor: pointer;
    transition:
      background-color 0.15s ease,
      border-color 0.15s ease;

    &[type="radio"] {
      border-radius: 50%;
    }

    /* Survol de la carte : bordure de la case = bordure de carte au survol (le vert reste réservé à l'état coché) */
    .fd-rec-label:hover &:not(:checked) {
      border-color: var(--pc-border-active);
    }

    &:checked {
      background-color: var(--fd-rec-checkbox);
      background-image: url("../img/coche.svg");
      border-color: var(--fd-rec-checkbox);
    }

    &:focus {
      outline: none;
    }

    &:focus-visible {
      outline: 2px solid var(--pc-brand-primary);
      outline-offset: 2px;
    }
  }

  /* Visuel 68×68 */
  .fd-rec-media {
    position: relative;
    flex: 0 0 68px;
    width: 68px;
    height: 68px;
    overflow: hidden;
    background: var(--pc-background-placeholder);
    border: 1px solid var(--pc-border-default);
    border-radius: var(--pc-radius-md);

    &:has(img) {
      background: var(--pc-background-surface);
    }

    img {
      display: block;
      width: 100%;
      height: 100%;
      max-width: none;
      object-fit: cover;
    }
  }

  /* Infos */
  .fd-rec-infos {
    display: flex;
    flex-direction: column;
    gap: var(--pc-spacing-2xs);
    flex: 1 1 0;
    min-width: 0;
  }

  .fd-rec-name {
    font: normal normal 500 14px/19px var(--pc-font-text);
    letter-spacing: 0;
    color: var(--pc-text-primary);
    text-decoration: none;
    word-break: break-word;

    &:hover,
    &:focus {
      color: var(--pc-text-primary);
      text-decoration: underline;
    }
  }

  .fd-rec-subtext {
    display: block;
    font: normal normal 400 12px/16px var(--pc-font-text);
    letter-spacing: 0;
    color: var(--pc-text-secondary);
    word-break: break-word;
  }

  /* Déclinaison : libellé + <select> natif */
  .fd-rec-decl {
    display: flex;
    align-items: center;
    gap: var(--pc-spacing-xs);
    min-width: 0;
    padding-top: var(--pc-spacing-2xs);
  }

  .fd-rec-decl__label {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 45%;
    overflow: hidden;
    font: normal normal 400 12px/16px var(--pc-font-text);
    color: var(--pc-text-secondary);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .fd-rec-url-decl,
  .fd-rec-combination {
    display: block;
    flex: 0 1 140px;
    width: 140px;
    min-width: 0;
    max-width: 100%;
    height: 28px;
    margin: 0;
    padding: 0 28px 0 var(--pc-spacing-sm);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: var(--pc-background-surface) url("../img/chevron.svg") no-repeat right var(--pc-spacing-xs) center / 12px 12px;
    border: 1px solid var(--pc-border-default);
    border-radius: var(--pc-radius-md);
    box-shadow: none;
    color: var(--pc-text-primary);
    font: normal normal 400 12px/16px var(--pc-font-text);
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;

    &:hover {
      border-color: var(--pc-border-strong);
    }

    &:focus,
    &:focus-visible {
      outline: none;
      border-color: var(--pc-border-active);
    }
  }

  /* Ligne prix : prix à gauche, quantité à droite, passe à la ligne si besoin */
  .fd-rec-prices-container {
    display: flex;
    flex-wrap: nowrap; /* la quantité s'ouvre à droite sans passer à la ligne (évite un saut de carte) */
    align-items: center;
    justify-content: space-between;
    gap: var(--pc-spacing-xs);
    padding-top: var(--pc-spacing-2xs);
  }

  .fd-rec-prices {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: wrap;
    align-items: flex-start;
    column-gap: var(--pc-spacing-xs);
    row-gap: 0;
    white-space: nowrap;
  }

  .fd-rec-price-ttc {
    display: inline-flex;
    align-items: flex-start;
    gap: 2px;
    font: normal normal 700 18px/22px var(--pc-font-price);
    letter-spacing: 0;
    color: var(--pc-text-price);
  }

  .fd-rec-price-ht {
    display: inline-flex;
    align-items: flex-start;
    gap: 2px;
    padding-top: 5px;
    font: normal normal 400 11px/14px var(--pc-font-price);
    letter-spacing: 0;
    color: var(--pc-text-secondary);
  }

  .fd-rec-price-regular {
    display: flex;
    align-items: flex-start;
    gap: 2px;
    flex: 0 0 100%;
    font: normal normal 400 12px/15px var(--pc-font-price);
    letter-spacing: 0;
    color: var(--pc-text-promo);
    text-decoration: line-through;

    > * {
      text-decoration: line-through;
    }
  }

  .fd-rec-price-regular--hidden {
    display: none !important;
  }

  /* Exposants TTC / HT */
  .fd-rec-price-unit {
    position: static;
    top: auto;
    margin: 0;
    font: normal normal 400 9px/11px var(--pc-font-price);
    vertical-align: baseline;
  }

  /*
   * Sélecteur de quantité : animation d'origine (avant maquette).
   * Fermé = largeur 0 + opacité 0 (jamais display:none, pour garder la transition) ;
   * coché = 106px avec le léger rebond cubic-bezier. La hauteur 32px reste réservée → pas de saut vertical.
   */
  .fd-rec-qty {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    width: 0;
    height: 32px;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    background: var(--pc-background-surface);
    border: 1px solid var(--pc-border-default);
    border-radius: var(--pc-radius-md);
    cursor: default;
    transition:
      width ease-in 0.2s,
      opacity ease-in-out 0.2s,
      visibility 0s linear 0.2s;

    .fd-rec-label:has(.fd-rec-input:checked) & {
      width: 106px;
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
      transition:
        width cubic-bezier(0.18, 0.89, 0.15, 1.12) 0.3s,
        opacity ease-in-out 0.5s,
        visibility 0s;
    }
  }

  /* Sélecteur désactivé en BO : jamais affiché (pas d'animation) */
  .fd-rec-qty--off,
  .fd-rec-label:has(.fd-rec-input:checked) .fd-rec-qty--off {
    display: none !important;
  }

  .fd-rec-qty__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    margin: 0 1px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--pc-text-primary);
    font: normal normal 400 14px/18px var(--pc-font-price);
    cursor: pointer;
    user-select: none;

    &:hover {
      background: var(--pc-background-selected);
    }

    &:focus {
      outline: none;
    }

    &:focus-visible {
      outline: 2px solid var(--pc-brand-primary);
      outline-offset: -2px;
    }

    &[aria-disabled="true"] {
      color: var(--pc-border-strong);
      background: transparent;
      cursor: default;
    }
  }

  .fd-rec-qty__input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 28px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--pc-text-primary);
    font: normal normal 400 14px/18px var(--pc-font-price);
    text-align: center;
    -moz-appearance: textfield;
    appearance: textfield;

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }

    &:focus {
      outline: none;
    }
  }

  /* Bandeau promo collé en bas de la carte */
  .fd-rec-qty-discount {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: var(--pc-spacing-xs) var(--pc-spacing-sm);
    background: var(--pc-background-promo);
    border-radius: 0 0 7px 7px;
  }

  .fd-rec-qty-discount__offer {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    font: normal normal 500 12px/16px var(--pc-font-text);
    color: var(--pc-text-promo);
    text-align: center;
    word-break: break-word;
  }

  .fd-rec-qty-discount__percent,
  .fd-rec-qty-discount__sep,
  .fd-rec-qty-discount__save {
    color: inherit;
    font-weight: inherit;
  }

  /* « -5% par unité dès 2 quantités » en gras, « économisez … » en normal */
  .fd-rec-qty-discount__lead {
    color: inherit;
    font-weight: 700;
  }

  .fd-rec-qty-discount__save {
    font-weight: 400;
  }

  .fd-rec-qty-discount__sep {
    margin: 0 0.25em;
  }

  /* Priorité 3 : promotion manuelle (HTML libre saisi dans le BO), même habillage que l’offre */
  .fd-rec-qty-discount__manual {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    font: normal normal 500 12px/16px var(--pc-font-text);
    color: var(--pc-text-promo);
    text-align: center;
    word-break: break-word;

    & p {
      margin: 0;
    }

    & a {
      color: inherit;
      text-decoration: underline;
    }
  }

  /* Colonnes étroites (mobile, ou colonne d’achat réduite entre 992 et 1299 px) */
  @media (max-width: 525px), (min-width: 992px) and (max-width: 1299px) {
    .fd-rec-qty-discount__sep,
    .fd-rec-qty-discount__save {
      display: none;
    }

    /* Quantité sous les prix : la hauteur s'ouvre 0 → 32px (animation d'origine) */
    .fd-rec-prices-container {
      flex-direction: column;
      align-items: flex-start;
      justify-content: flex-start;
      row-gap: 0;
    }

    .fd-rec-qty {
      width: 106px;
      height: 0;
      margin-top: 0;
      border-width: 0;
      transition:
        height cubic-bezier(0.4, 0, 1, 1) 0.2s,
        margin-top cubic-bezier(0.4, 0, 1, 1) 0.2s,
        border-width 0s linear 0.2s,
        opacity ease-in-out 0.2s,
        visibility 0s linear 0.2s;

      .fd-rec-label:has(.fd-rec-input:checked) & {
        width: 106px;
        height: 32px;
        margin-top: 10px;
        border-width: 1px;
        transition:
          height cubic-bezier(0.4, 0, 1, 1) 0.2s,
          margin-top cubic-bezier(0.4, 0, 1, 1) 0.2s,
          border-width 0s,
          opacity ease-in-out 0.5s,
          visibility 0s;
      }
    }
  }

  @media (max-width: 359px) {
    .fd-rec-label__main {
      gap: var(--pc-spacing-xs);
      padding: var(--pc-spacing-xs);
    }

    .fd-rec-media {
      flex-basis: 56px;
      width: 56px;
      height: 56px;
    }
  }

  .fd-rec-qty-discount[hidden],
  .fd-rec-qty-discount__offer[hidden],
  .fd-rec-qty-discount__manual[hidden],
  .fd-rec-qty-discount__from[hidden],
  .fd-rec-qty-discount__sep[hidden],
  .fd-rec-qty-discount__save[hidden],
  .fd-rec-combination-wrap[hidden] {
    display: none !important;
  }
}

/* Injection dans la modal panier */
#blockcart-modal {
  .fd-rec-modal-complements {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px dashed rgba(0, 0, 0, 0.12);
  }

  .fd-rec-modal-complements__title {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: #6c868e;
  }

  .fd-rec-modal-complements__list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .fd-rec-modal-complements__item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .fd-rec-modal-complements__img {
    flex: 0 0 48px;
    width: 48px;
    height: 48px;

    img {
      display: block;
      width: 48px;
      height: 48px;
      max-width: none;
      object-fit: cover;
      border-radius: 4px;
    }
  }

  .fd-rec-modal-complements__info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
  }

  .fd-rec-modal-complements__name {
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.25;
  }

  .fd-rec-modal-complements__meta {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: #6c868e;
  }
}