.fergar-gallery { --fergar-orange: #fa996c; }
.fergar-gallery__main { box-sizing: border-box; width: 100%; max-width: 640px; height: 480px; margin: 0 auto; padding: 15px; overflow: hidden; border: 1px solid #d9dee5; border-radius: 8px; background: #fff; }
.fergar-gallery__main-button { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
.fergar-gallery__main-image, #product .fergar-gallery .js-qv-product-cover { display: block; width: 100%; max-width: 100% !important; height: 100% !important; object-fit: cover; object-position: center 65%; box-shadow: none; }
.fergar-gallery__main-button:focus-visible, .fergar-gallery__thumbnail:focus-visible, .fergar-gallery__arrow:focus-visible, .fergar-gallery__modal-thumbnail:focus-visible, .fergar-gallery-modal__close:focus-visible { outline: 3px solid var(--fergar-orange); outline-offset: 3px; }
.fergar-gallery__thumbnails-wrap { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; max-width: 640px; gap: .75rem; align-items: center; margin: 1rem auto 0; }
.fergar-gallery__thumbnails-wrap--carousel { grid-template-columns: 2.5rem minmax(0, 1fr) 2.5rem; }
.fergar-gallery__viewport { overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none; scroll-snap-type: x mandatory; }
.fergar-gallery__viewport::-webkit-scrollbar { display: none; }
.fergar-gallery__thumbnails, .fergar-gallery-modal__thumbnails { display: flex; gap: .75rem; width: max-content; min-width: 100%; margin: 0; padding: 0; list-style: none; }
.fergar-gallery__thumbnails .thumb-container { flex: 0 0 152px; margin: 0; scroll-snap-align: start; }
.fergar-gallery__thumbnail, .fergar-gallery__modal-thumbnail { display: block; width: 100%; padding: 2px; overflow: hidden; border: 2px solid transparent; border-radius: 6px; background: #fff; cursor: pointer; }
.fergar-gallery__thumbnail img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.fergar-gallery__thumbnail.is-active, .fergar-gallery__modal-thumbnail.is-active { border-color: var(--fergar-orange); box-shadow: 0 0 0 3px rgba(250, 153, 108, .24); }
.fergar-gallery__arrow { width: 2.5rem; height: 2.5rem; padding: 0; border: 1px solid #d3dce6; border-radius: 50%; background: #fff; color: #282828; cursor: pointer; }
.fergar-gallery__arrow:hover { border-color: var(--fergar-orange); color: var(--fergar-orange); }
.fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__thumbnails { width: 100%; min-width: 0; flex-wrap: nowrap !important; }
.fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__thumbnails .thumb-container { flex: 0 0 calc((100% - 2.25rem) / 4) !important; width: calc((100% - 2.25rem) / 4) !important; }
.fergar-gallery-modal__close { position: absolute; z-index: 1; top: .5rem; right: .75rem; width: 2.5rem; height: 2.5rem; border-radius: 50%; background: #fff; opacity: 1; }
.fergar-gallery-modal__image { display: block; width: 100%; max-height: 75vh; object-fit: contain; }
.fergar-gallery-modal__thumbnails { justify-content: center; width: 100%; margin-top: 1rem; overflow-x: auto; padding: .25rem; }
.fergar-gallery-modal__thumbnails li { flex: 0 0 88px; }
.fergar-gallery-modal__thumbnails img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
/* The existing theme's product modal styles target its legacy thumbnail picker.
   Scope these rules to the custom gallery so the modal is always a real image lightbox. */
#product-modal.fergar-gallery-modal .modal-dialog { width: auto; max-width: min(92vw, 1100px); margin: 1.75rem auto; }
#product-modal.fergar-gallery-modal .modal-content { overflow: hidden; border: 1px solid #d9dee5; border-radius: 8px; background: #fff; box-shadow: 0 12px 36px rgba(0, 0, 0, .28); }
#product-modal.fergar-gallery-modal .modal-body { display: block !important; padding: 3.5rem 1rem 1rem !important; }
#product-modal.fergar-gallery-modal figure { display: block !important; width: 100% !important; margin: 0 !important; }
#product-modal.fergar-gallery-modal .js-modal-product-cover.fergar-gallery-modal__image { display: block !important; position: static !important; width: 100% !important; max-width: 100% !important; height: auto !important; max-height: calc(100vh - 180px) !important; margin: 0 auto !important; opacity: 1 !important; visibility: visible !important; object-fit: contain !important; }
#product-modal.fergar-gallery-modal .fergar-gallery-modal__close { top: .75rem; right: .75rem; border: 1px solid #d9dee5; color: #282828; line-height: 1; }
@media (min-width: 768px) {
  #product .fergar-gallery .fergar-gallery__thumbnails-wrap { display: grid !important; grid-template-columns: minmax(0, 1fr); flex: 0 1 640px; width: 640px; max-width: 100%; margin-right: auto; margin-left: auto; }
  #product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel { grid-template-columns: 2.5rem minmax(0, 1fr) 2.5rem; }
  #product .fergar-gallery .fergar-gallery__viewport { min-width: 0; max-width: 100%; }
  #product .fergar-gallery .fergar-gallery__thumbnails { display: flex !important; flex-direction: row !important; align-items: center; }
  #product .fergar-gallery .fergar-gallery__thumbnails .thumb-container { float: none !important; flex: 0 0 152px !important; width: 152px !important; }
  #product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__thumbnails .thumb-container { flex-basis: calc((100% - 2.25rem) / 4) !important; width: calc((100% - 2.25rem) / 4) !important; }
}
@media (max-width: 767px) { .fergar-gallery__main { height: calc((100vw - 30px) * .75); min-height: 250px; padding: 8px; } .fergar-gallery__thumbnails .thumb-container { flex-basis: 88px; } .fergar-gallery__thumbnails-wrap { grid-template-columns: minmax(0, 1fr); gap: .25rem; } .fergar-gallery__thumbnails-wrap--carousel { grid-template-columns: 2rem minmax(0, 1fr) 2rem; } .fergar-gallery__arrow { width: 2rem; height: 2rem; } }

/* The carousel deliberately does not use the theme's thumbnail grid. Its
   viewport has one stable width, so only four thumbnails can be visible. */
#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel { display: block !important; position: relative; width: 100% !important; max-width: 640px; overflow: hidden; }
#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__viewport { box-sizing: border-box; width: 100%; padding: 0 3rem; overflow-x: auto; }
#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__thumbnails { width: 100%; min-width: 0; }
#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__arrow { position: absolute; z-index: 1; top: 50%; transform: translateY(-50%); }
#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel [data-gallery-scroll="previous"] { left: .25rem; }
#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel [data-gallery-scroll="next"] { right: .25rem; }

/* Keep every product's thumbnail rail directly below the 640px cover.
   Sofa-specific layout rules are loaded earlier and otherwise stretch this
   component across the complete column on non-sofa product pages. */
#product .fergar-gallery .fergar-gallery__thumbnails-wrap {
  box-sizing: border-box;
  width: 640px !important;
  max-width: 100% !important;
  margin: 1rem auto 0 !important;
}

#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel {
  width: 640px !important;
  max-width: 100% !important;
  margin: 1rem auto 0 !important;
}

@media (max-width: 767px) { #product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__viewport { padding: 0 2.5rem; } }

/* Sofa photography is supplied in a 4:3 format.  On phones the sofa layout
   previously combined a short, wide frame with cover plus a 12% scale, so the
   actual product was cropped. Keep the entire image visible and centered. */
@media (max-width: 767px) {
  .fergar-sofa-product .fergar-gallery__main {
    width: 100%;
    max-width: 100%;
    height: calc((100vw - 28px) * .75) !important;
    aspect-ratio: 4 / 3;
  }

  #product .fergar-sofa-product .fergar-gallery__main-image,
  #product .fergar-sofa-product .fergar-gallery__main:hover .fergar-gallery__main-image {
    display: block;
    object-fit: contain !important;
    object-position: center;
    transform: none !important;
  }

  #product .fergar-sofa-product .fergar-gallery__arrow {
    top: calc((100vw - 28px) * .375);
  }
}

/* The sofa polish uses a grid for short thumbnail lists. Restore the
   horizontal rail only for galleries that actually expose carousel controls. */
#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel {
  display: block !important;
  overflow: hidden !important;
}

#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__viewport {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scroll-snap-type: x mandatory;
}

#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__thumbnails {
  display: flex !important;
  flex-wrap: nowrap !important;
  grid-template-columns: none !important;
  width: 100% !important;
  min-width: 0 !important;
}

#product .fergar-gallery .fergar-gallery__thumbnails-wrap--carousel .fergar-gallery__thumbnails .thumb-container {
  flex: 0 0 calc((100% - 2.25rem) / 4) !important;
  width: calc((100% - 2.25rem) / 4) !important;
  min-width: 0 !important;
  scroll-snap-align: start;
}

/* This benefits strip is a direct child of a Bootstrap flex row. Explicitly
   occupy the row so it cannot shrink to the width of its text. */
.fergar-gallery .fergar-sofa-footer-benefits {
  box-sizing: border-box;
  flex: 0 0 100%;
  width: 100% !important;
}

/* Let the product copy use the full phone viewport. The desktop grid's
   intrinsic column width was causing the right side of paragraphs to clip. */
@media (max-width: 767px) {
  #product .fergar-sofa-product .product-container {
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  #product .fergar-sofa-product .product-container > [class*="col-"],
  #product .fergar-sofa-product .product-information {
    width: 100% !important;
    min-width: 0;
    max-width: 100% !important;
  }

  #product .fergar-sofa-product .fergar-sofa-benefits {
    box-sizing: border-box;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-right: auto;
    margin-left: auto;
  }

  #product .fergar-sofa-product .fergar-sofa-benefits > div {
    min-width: 0;
  }

  #product .fergar-sofa-product .fergar-sofa-configurator,
  #product .fergar-sofa-product .fergar-sofa-configurator__grid,
  #product .fergar-sofa-product .fergar-sofa-configurator__grid > * {
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0;
    max-width: 100% !important;
  }

  #product .fergar-sofa-product .fergar-sofa-configurator__grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #product .fergar-sofa-product .fergar-sofa-options {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #product .fergar-sofa-product .product-add-to-cart,
  #product .fergar-sofa-product .fergar-sofa-quote-action,
  #product .fergar-sofa-product .fergar-sofa-quote-action .add {
    position: static !important;
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    padding: 0 !important;
  }

  #product .fergar-sofa-product .fergar-sofa-quote-button {
    box-sizing: border-box;
    width: 100% !important;
    min-height: 46px !important;
    height: 46px !important;
    margin: 0 !important;
    padding: 8px 14px !important;
    font-size: 14px !important;
    white-space: nowrap;
  }

  /* CTA persistente: el negro acompaña la navegación; el naranja queda integrado. */
  body#product {
    padding-bottom: 76px;
  }

  #product .fergar-sofa-product .fergar-sofa-quote-button {
    position: fixed !important;
    right: 14px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 14px;
    z-index: 1060;
    width: auto !important;
    height: 50px !important;
    min-height: 50px !important;
    padding: 8px 14px !important;
    font-size: 14px !important;
    box-shadow: 0 5px 18px rgba(0, 0, 0, .26) !important;
  }

  #product .fergar-sofa-product .fergar-sofa-quote-button .material-icons {
    margin-right: 10px;
    font-size: 24px;
  }

  #product .fergar-sofa-product .fergar-sofa-mobile-quote {
    position: static !important;
    box-sizing: border-box;
    height: 42px !important;
    min-height: 42px !important;
    padding: 6px 14px !important;
    font-size: 14px !important;
    line-height: 1.2;
  }

  #product .fergar-sofa-product .fergar-sofa-mobile-quote .material-icons {
    margin-right: 7px;
    font-size: 18px;
  }

  #product .product-description .hover-wrap:has(img.garantia) {
    display: inline-flex !important;
    box-sizing: border-box;
    width: 50% !important;
    margin: 0 !important;
    padding: 0 8px !important;
    vertical-align: top;
    justify-content: center;
  }

  #product .product-description .hover-wrap:has(img.garantia) .hover-wrap-inner {
    display: flex !important;
    width: 100% !important;
    justify-content: center;
  }

  #product .product-description .hover-wrap:has(img.garantia) img {
    display: block;
    width: auto !important;
    max-width: 100% !important;
    height: auto !important;
  }

  /* Las garantías llegan en dos elementos de lista separados. */
  #product .product-description ul:has(img.garantia) {
    display: flex !important;
    flex-wrap: nowrap !important;
    box-sizing: border-box;
    width: 100% !important;
    margin: 16px 0 0 !important;
    padding: 0 !important;
    list-style: none !important;
  }

  #product .product-description ul:has(img.garantia) > li {
    display: flex !important;
    flex: 0 0 50% !important;
    box-sizing: border-box;
    width: 50% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 8px !important;
    justify-content: center;
  }

  #product .product-description ul:has(img.garantia) .img-with-aniamtion-wrap,
  #product .product-description ul:has(img.garantia) .inner,
  #product .product-description ul:has(img.garantia) .hover-wrap,
  #product .product-description ul:has(img.garantia) .hover-wrap-inner {
    display: flex !important;
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    justify-content: center;
  }

  #product .product-description p:has(> img[src*="tecnico-ace-Fergar"]) {
    min-height: 126px;
    margin: 16px 0 0 !important;
    background: center / contain no-repeat url('/img/cms/tecnico-ace-torresol.png');
  }

  #product .product-description img[src*="tecnico-ace-Fergar"] {
    display: none !important;
  }

  /* Los dos sellos son hermanos dentro de un único <li>. */
  #product .product-description ul:has(img.garantia) {
    display: block !important;
    width: 100% !important;
  }

  #product .product-description ul:has(img.garantia) > li {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
  }

  #product .product-description li:has(> .img-with-aniamtion-wrap img.garantia) {
    display: flex !important;
    flex-wrap: wrap;
    width: 100% !important;
  }

  #product .product-description li:has(> .img-with-aniamtion-wrap img.garantia) > .img-with-aniamtion-wrap {
    display: flex !important;
    flex: 0 0 50% !important;
    box-sizing: border-box;
    float: none !important;
    width: 50% !important;
    height: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 8px !important;
    justify-content: center;
  }

  #product .product-description li:has(> .img-with-aniamtion-wrap img.garantia) > .img-with-aniamtion-wrap .inner,
  #product .product-description li:has(> .img-with-aniamtion-wrap img.garantia) > .img-with-aniamtion-wrap .hover-wrap,
  #product .product-description li:has(> .img-with-aniamtion-wrap img.garantia) > .img-with-aniamtion-wrap .hover-wrap-inner {
    display: flex !important;
    box-sizing: border-box;
    width: 100% !important;
    height: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    justify-content: center;
  }

  #product .product-description li:has(> .img-with-aniamtion-wrap img.garantia) img.garantia {
    display: block !important;
    flex: none;
    width: 100px !important;
    max-width: 100% !important;
    height: auto !important;
  }
}
