/*
 * BN Smart Product Catalog — Related/Upsell cards.
 * Deeply normalizes the card body while leaving section headings, product
 * links, wishlist, quick view, swatches and WooCommerce purchase behavior intact.
 */

/* Metadata is generated on every single-product loop but shown only here. */
.single-product .bnspc-native-loop-brand,
.single-product .bnspc-native-loop-stock {
  display: none;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) {
  --bnspc-card-border: #dfe4ea;
  --bnspc-card-radius: 15px;
  --bnspc-card-text: #17191e;
  --bnspc-card-muted: #667085;
  --bnspc-card-soft: #f2f4f7;
  --bnspc-card-green: #067647;
  --bnspc-card-red: #d71920;
  --bnspc-card-orange: #f79009;
  overflow: visible;
}

/*
 * Flatsome/Flickity moves product columns inside .flickity-slider. Target the
 * product column itself instead of only direct children of .row; otherwise the
 * theme's default 15–20px column padding remains and cards look far apart.
 */
.single-product :is(
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .row {
  margin-left: -6px !important;
  margin-right: -6px !important;
}

.single-product :is(
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.product-small.col, li.product, .bnspc-loop-item) {
  box-sizing: border-box;
  padding-left: 6px !important;
  padding-right: 6px !important;
}

/* Strong fallback for the actual Flickity DOM used by Flatsome. */
.single-product :is(
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .flickity-slider > :is(.product-small.col, li.product, .bnspc-loop-item) {
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding-left: 6px !important;
  padding-right: 6px !important;
}

/* Equal-height items for normal rows and Flatsome/Flickity rows. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.row, .products, .flickity-slider) {
  align-items: stretch;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.product-small, li.product) {
  display: flex;
  height: auto;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.product-small, li.product) > .col-inner,
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .bnspc-loop-inner {
  display: flex;
  width: 100%;
  height: 100%;
}

/* Main card shell. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.product-small.box, .product-small .box, li.product .box, .bnspc-loop-card) {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  min-height: 448px;
  overflow: hidden;
  border: 1px solid var(--bnspc-card-border);
  border-radius: var(--bnspc-card-radius);
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .025);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

@media (hover: hover) {
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) :is(.product-small.box, .product-small .box, li.product .box, .bnspc-loop-card):hover {
    transform: translateY(-2px);
    border-color: #d2d8e0;
    box-shadow: 0 10px 28px rgba(16, 24, 40, .08);
  }
}

/* Fixed square media area so every title starts at the same height. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.box-image, .bnspc-loop-image) {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  height: auto !important;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--bnspc-card-radius) var(--bnspc-card-radius) 0 0;
  background: #fff;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.box-image, .bnspc-loop-image) > div,
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.box-image, .bnspc-loop-image) a,
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.box-image, .bnspc-loop-image) .image-zoom,
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.box-image, .bnspc-loop-image) .image-fade_in_back {
  width: 100%;
  height: 100%;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.box-image, .bnspc-loop-image) img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  margin: 0 auto;
  padding: 10px;
  object-fit: contain;
  object-position: center;
}

/* Content body. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.box-text, .bnspc-loop-content) {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  min-height: 215px;
  padding: 14px 15px 16px !important;
  text-align: left !important;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.title-wrapper, .bnspc-loop-title) {
  flex: 0 0 auto;
  min-height: 46px;
  margin: 0 0 8px;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .name.product-title {
  display: -webkit-box;
  min-height: 43px;
  margin: 0;
  overflow: hidden;
  color: var(--bnspc-card-text);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .name.product-title a {
  color: inherit;
}

/* Native price-wrapper becomes a predictable vertical metadata stack. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.price-wrapper, .bnspc-loop-meta) {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-width: 0;
}

/* Brand pill. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .bnspc-native-loop-brand {
  display: block;
  max-width: 100%;
  margin: 0 0 7px;
  padding: 4px 8px;
  overflow: hidden;
  border-radius: 7px;
  background: var(--bnspc-card-soft);
  color: var(--bnspc-card-muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .bnspc-native-loop-brand {
  display: inline-flex;
  width: auto;
  color: #596579;
}

/* Reviews remain native, only spacing and color are normalized. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .star-rating {
  flex: 0 0 auto;
  margin: 2px 0 8px;
  color: var(--bnspc-card-orange) !important;
  font-size: 14px;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .star-rating::before,
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .star-rating span::before {
  color: var(--bnspc-card-orange) !important;
}

/* Keep price directly below the rating; fixed heights still align stock rows. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .price {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  color: #111318;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .price del {
  display: block;
  margin: 0 0 1px;
  color: #8a9099;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  opacity: 1;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .price ins {
  display: block;
  color: #111318;
  font-weight: 700;
  text-decoration: none;
}

/* Stock line. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .bnspc-native-loop-stock {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
  color: var(--bnspc-card-green);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .bnspc-native-loop-stock-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: currentColor;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .bnspc-native-loop-stock.is-outofstock {
  color: #c4322b;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .bnspc-native-loop-stock.is-onbackorder {
  color: #b54708;
}

/* Keep sale badges inside the card instead of hanging outside the left edge. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .badge-container {
  top: 12px !important;
  left: 12px !important;
  margin: 0 !important;
  z-index: 8;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .badge {
  width: auto;
  height: auto;
}

.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) .badge-inner {
  min-width: 0;
  min-height: 0;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--bnspc-card-red) !important;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
}

/* Style existing wishlist controls when the site/plugin already provides them. */
.single-product :is(
  .related.products,
  .related-products-wrapper,
  .up-sells.upsells.products,
  .upsells.products,
  .upsells-wrapper
) :is(.wishlist-button, .add-to-wishlist-button, .yith-wcwl-add-to-wishlist a) {
  border-radius: 999px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 4px 14px rgba(16, 24, 40, .12);
}

/* Mobile: retain the site's own column/slider logic, only resize the cards. */
@media (max-width: 849px) {
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) :is(.product-small.box, .product-small .box, li.product .box, .bnspc-loop-card) {
    min-height: 365px;
    border-radius: 12px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) :is(.box-image, .bnspc-loop-image) {
    border-radius: 12px 12px 0 0;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) :is(.box-image, .bnspc-loop-image) img {
    padding: 7px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) :is(.box-text, .bnspc-loop-content) {
    min-height: 178px;
    padding: 10px 9px 12px !important;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) :is(.title-wrapper, .bnspc-loop-title) {
    min-height: 40px;
    margin-bottom: 6px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .name.product-title {
    min-height: 38px;
    font-size: 12.5px;
    line-height: 1.5;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-native-loop-brand {
    margin-bottom: 5px;
    padding: 3px 6px;
    border-radius: 6px;
    font-size: 9px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .star-rating {
    margin-bottom: 6px;
    font-size: 12px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .price {
    min-height: 38px;
    font-size: 13px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .price del {
    font-size: 10px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-native-loop-stock {
    gap: 5px;
    margin-top: 6px;
    font-size: 10px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-native-loop-stock-dot {
    width: 7px;
    height: 7px;
    flex-basis: 7px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .badge-container {
    top: 8px !important;
    left: 8px !important;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .badge-inner {
    padding: 5px 7px;
    font-size: 9px;
  }
}

/*
 * Mobile product loops: present native Related/Upsell items as a static
 * two-column row instead of a horizontal Flickity carousel. Desktop keeps the
 * theme's original slider behavior. The JS normalizer adds
 * `.bnspc-mobile-grid` to the native product container.
 */
@media (max-width: 767px) {
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    overflow: visible !important;
  }

  /* Flickity DOM: turn the viewport/slider back into normal document flow. */
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid.flickity-enabled {
    display: block !important;
    height: auto !important;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid > .flickity-viewport {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    touch-action: pan-y !important;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid > .flickity-viewport > .flickity-slider {
    position: static !important;
    left: auto !important;
    width: 100% !important;
    height: auto !important;
    transform: none !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 12px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid > .flickity-viewport > .flickity-slider > :is(
    .product-small.col,
    li.product,
    .bnspc-loop-item
  ) {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
  }

  /* Native non-Flickity rows receive the same 2-column layout. */
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid:not(.flickity-enabled) {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 12px;
  }

  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid:not(.flickity-enabled) > :is(
    .product-small.col,
    li.product,
    .bnspc-loop-item
  ) {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Slider navigation is unnecessary in the mobile grid. */
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid :is(
    .flickity-button,
    .flickity-prev-next-button,
    .flickity-page-dots
  ),
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid > :is(
    .flickity-button,
    .flickity-prev-next-button,
    .flickity-page-dots
  ) {
    display: none !important;
  }

  /* Let CSS Grid equalize cards naturally without forcing an oversized row. */
  .single-product :is(
    .related.products,
    .related-products-wrapper,
    .up-sells.upsells.products,
    .upsells.products,
    .upsells-wrapper
  ) .bnspc-mobile-grid :is(
    .product-small.box,
    .product-small .box,
    li.product .box,
    .bnspc-loop-card
  ) {
    min-height: 0;
    height: 100%;
  }
}
