
.psm-relatedproducts {
  margin: 0;
  padding-top: 2rem;
  padding-bottom: 2rem;
  font-family: inherit;
  --psmrp-cols-desktop: 4;
  --psmrp-cols-tablet: 3;
  --psmrp-cols-mobile: 2;
  --psmrp-gap: 12px;
}
.psm-relatedproducts--bg {
  position: relative;
  isolation: isolate;
  /* Vertical padding comes from the base section rule (2rem); only the
     inline inset is background-specific. */
  padding-inline: 1.5rem;
}

#index .psm-relatedproducts .js-product.product {
  border: 1px solid #f4f4f4;
}

.psm-relatedproducts--bg::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--psmrp-bleed-left, calc(50% - 50vw));
  width: var(--psmrp-bleed-width, 100vw);
  background: var(--psmrp-bg, transparent);
  z-index: -1;
}

/* Break out of any centered parent container to span the full viewport.
   The classic 50%/50vw trick: symmetric physical margins, RTL-safe. */
.psm-relatedproducts--w-full {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  padding-inline: 1.5rem;
}

/* In full-width mode the OUTER box (and the background band) stays
   edge-to-edge, but when a Max width is set the inner content — header and
   products — is centered at that width. No max width set → full usable
   width, as before. */
.psm-relatedproducts--w-full > .psm-relatedproducts__header,
.psm-relatedproducts--w-full > .psm-relatedproducts__viewport,
.psm-relatedproducts--w-full > .psm-relatedproducts__rows {
  max-width: var(--psmrp-maxw, none);
  margin-inline: auto;
}

/* Center the block at a fixed maximum width (BO "Max width" setting;
   falls back to a Bootstrap-xxl-like container). */
.psm-relatedproducts--w-container {
  max-width: var(--psmrp-maxw, 1320px);
  margin-inline: auto;
}

.psm-relatedproducts__header {
  margin-bottom: 1rem;
}

/* BO "Center title and subtitle" switch. */
.psm-relatedproducts--center-header .psm-relatedproducts__header {
  text-align: center;
}

.psm-relatedproducts__title {
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
}

/* ----- Card rhythm inside our blocks -----
   Themes force tall product cards (.card{min-height:480px}) and stretch the
   info area (.product-miniature__infos__top{height:100%} +
   __bottom{margin-top:auto}), which opens a large empty gap between the
   product name and the price. Scope a tighter layout to this module's
   blocks only — regular theme listings stay untouched. Leftover row-stretch
   space lands *below* the add-to-cart controls instead. */
.psm-relatedproducts .product-miniature .card {
  min-height: 0;
  border: 1px solid #f8f8f8;
}

.psm-relatedproducts .product-miniature .card-body,
.psm-relatedproducts .product-miniature__infos {
  justify-content: flex-start;
}

.psm-relatedproducts .product-miniature__infos__top {
  height: auto;
}

.psm-relatedproducts .product-miniature__infos__bottom {
  margin-top: 0;
}

/* The reviews module's placeholder row reserves ~44px above the price even
   for products with no stars to show. Collapse it inside our blocks only
   when it's actually empty — cards with real review stars keep them. */
.psm-relatedproducts .product-miniature .product-list-reviews:has(.grade-stars:empty) {
  display: none;
}

.psm-relatedproducts__subtitle {
  color: #555;
  margin: 0;
}

.psm-relatedproducts__card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background: #fff;
}

.psm-relatedproducts__card-image {
  display: block;
  aspect-ratio: 1 / 1;
  background: #fff;
}

.psm-relatedproducts__card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.psm-relatedproducts__card-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.875rem;
}

.psm-relatedproducts__card-brand {
  color: #6b7280;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.psm-relatedproducts__card-title {
  color: inherit;
  font-weight: 600;
}

.psm-relatedproducts__card-price {
  font-weight: 700;
}

.psm-relatedproducts__card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: auto;
}

.psm-relatedproducts__add-form {
  margin-top: 0.25rem;
}

/* ----- Grid layout: respect the rule's columns_* setting -----
   Some themes (hummingbird) style `.products` as a CSS grid, others
   (classic descendants like eshop) lay product lists out with Bootstrap
   `.row`/`.col-*` classes and leave `.products` unstyled. Declare
   `display: grid` ourselves so the column count works on every theme.
*/
.psm-relatedproducts--grid .psm-relatedproducts__list.products {
  display: grid;
  grid-template-columns: repeat(var(--psmrp-cols-mobile), minmax(0, 1fr));
  gap: var(--psmrp-gap);
}

@media (min-width: 768px) {
  .psm-relatedproducts--grid .psm-relatedproducts__list.products {
    grid-template-columns: repeat(var(--psmrp-cols-tablet), minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .psm-relatedproducts--grid .psm-relatedproducts__list.products {
    grid-template-columns: repeat(var(--psmrp-cols-desktop), minmax(0, 1fr));
  }
}

/* ----- Slider layout: horizontally scrollable strip -----
   Each card is sized so that exactly `columns_*` cards fit in the
   viewport at the matching breakpoint. The merchant's max_products
   value drives how many cards are loaded; columns_desktop/tablet/mobile
   drive how many are visible without scrolling.
*/
.psm-relatedproducts--slider .psm-relatedproducts__viewport {
  position: relative;
}

.psm-relatedproducts--slider .psm-relatedproducts__list.products {
  display: grid;
  grid-template-columns: none;
  grid-auto-flow: column;
  /* Subtract gaps proportionally so the cards-per-view count is exact. */
  grid-auto-columns: calc(
    (100% - (var(--psmrp-cols-mobile) - 1) * var(--psmrp-gap))
    / var(--psmrp-cols-mobile)
  );
  gap: var(--psmrp-gap);
  overflow-x: auto;
  scroll-behavior: smooth;
  /* proximity, not mandatory: mandatory hijacks free wheel/trackpad
     scrolling mid-gesture; the JS steps land on card boundaries anyway. */
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  padding-bottom: 0.5rem;
}

/* Once the JS has wired the arrow controls it adds `--enhanced` on the
   section; only then is the scrollbar hidden. No JS → the thin scrollbar
   above stays as the fallback affordance. The symmetric padding/negative
   margin gives card borders and shadows room inside the scroll container,
   which otherwise clips them on the first/last card. */
.psm-relatedproducts--slider.psm-relatedproducts--enhanced .psm-relatedproducts__list.products {
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 12px;
  margin: -12px;
  scroll-padding-inline: 12px;
}

.psm-relatedproducts--slider.psm-relatedproducts--enhanced .psm-relatedproducts__list.products::-webkit-scrollbar {
  display: none;
}

/* ----- Slider prev/next arrows ----- */
.psm-relatedproducts__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  /* Above card-level overlays (theme quick-view buttons sit around 10). */
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid #e5e7eb;
  border-radius: 50%;
  background: #fff;
  color: #1f2937;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: box-shadow 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.psm-relatedproducts__nav svg {
  width: 1.25rem;
  height: 1.25rem;
}

.psm-relatedproducts__nav:hover {
  border-color: #9ca3af;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
}

.psm-relatedproducts__nav:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.psm-relatedproducts__nav:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.psm-relatedproducts__nav[hidden] {
  display: none;
}

/* The arrows live in a reserved gutter left/right of the strip (see the
   __viewport padding below) so they never overlap the product cards.
   Sections are often full-bleed, so the gutter stays inside the viewport. */
.psm-relatedproducts__nav--prev {
  inset-inline-start: 0;
}

.psm-relatedproducts__nav--next {
  inset-inline-end: 0;
}

/* Reserve the arrow gutters only once the JS has wired the controls. */
@media (min-width: 768px) {
  .psm-relatedproducts--slider.psm-relatedproducts--enhanced .psm-relatedproducts__viewport {
    padding-inline: 3.25rem;
  }
}

/* On touch-size screens swiping is the affordance: drop the arrows (and
   their gutters) instead of overlaying them on the cards. */
@media (max-width: 767.98px) {
  .psm-relatedproducts__nav {
    display: none;
  }
}

/* The chevrons point toward previous/next content: mirror them on RTL.
   Themes often apply RTL via body{direction:rtl} without html[dir], so the
   JS also toggles the --rtl class from the computed direction. */
[dir='rtl'] .psm-relatedproducts__nav svg,
.psm-relatedproducts--rtl .psm-relatedproducts__nav svg {
  transform: scaleX(-1);
}

@media (min-width: 768px) {
  .psm-relatedproducts--slider .psm-relatedproducts__list.products {
    grid-auto-columns: calc(
      (100% - (var(--psmrp-cols-tablet) - 1) * var(--psmrp-gap))
      / var(--psmrp-cols-tablet)
    );
  }
}

@media (min-width: 1024px) {
  .psm-relatedproducts--slider .psm-relatedproducts__list.products {
    grid-auto-columns: calc(
      (100% - (var(--psmrp-cols-desktop) - 1) * var(--psmrp-gap))
      / var(--psmrp-cols-desktop)
    );
  }
}

.psm-relatedproducts--slider .psm-relatedproducts__list.products > .product-miniature {
  scroll-snap-align: start;
}

@media (prefers-reduced-motion: reduce) {
  .psm-relatedproducts--slider .psm-relatedproducts__list.products {
    scroll-behavior: auto;
  }
}

/* ----- "Images only" layout: compact row of clickable thumbnails -----
   No name, no price — just the product image linking to the product page.
   Honors columns_* like the grid layout.
*/
.psm-relatedproducts--images .psm-relatedproducts__images {
  display: grid;
  grid-template-columns: repeat(var(--psmrp-cols-mobile), minmax(0, 1fr));
  gap: var(--psmrp-gap);
}

.psm-relatedproducts--images .psm-relatedproducts__card-body {
  padding: 0.5rem;
}

@media (min-width: 768px) {
  .psm-relatedproducts--images .psm-relatedproducts__images {
    grid-template-columns: repeat(var(--psmrp-cols-tablet), minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .psm-relatedproducts--images .psm-relatedproducts__images {
    grid-template-columns: repeat(var(--psmrp-cols-desktop), minmax(0, 1fr));
  }
}

.psm-relatedproducts--images .psm-relatedproducts__image-tile {
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.psm-relatedproducts--images .psm-relatedproducts__image-tile:hover,
.psm-relatedproducts--images .psm-relatedproducts__image-tile:focus-visible {
  border-color: #9ca3af;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.psm-relatedproducts--images .psm-relatedproducts__image-tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.psm-relatedproducts--images .psm-relatedproducts__image-tile-fallback {
  display: block;
  width: 100%;
  height: 100%;
  background: #f3f4f6;
}

/* ----- "List" layout: one horizontal row per product -----
   Small thumbnail, product name (flex-grows), price aligned right.
   Columns_* is intentionally ignored — list is always one column.
*/
.psm-relatedproducts--list .psm-relatedproducts__rows {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid #e5e7eb;
}

.psm-relatedproducts--list .psm-relatedproducts__row {
  border-bottom: 1px solid #e5e7eb;
}

.psm-relatedproducts--list .psm-relatedproducts__card {
  display: grid;
  grid-template-columns: minmax(5rem, 8rem) 1fr;
  border: 0;
  border-radius: 0;
}

.psm-relatedproducts--list .psm-relatedproducts__row-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0.5rem;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.psm-relatedproducts--list .psm-relatedproducts__row-link:hover,
.psm-relatedproducts--list .psm-relatedproducts__row-link:focus-visible {
  background-color: #f9fafb;
  text-decoration: none;
}

.psm-relatedproducts--list .psm-relatedproducts__row-thumb {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}

.psm-relatedproducts--list .psm-relatedproducts__row-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.psm-relatedproducts--list .psm-relatedproducts__row-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.95rem;
  line-height: 1.3;
}

.psm-relatedproducts--list .psm-relatedproducts__row-price {
  flex: 0 0 auto;
  font-weight: 600;
  white-space: nowrap;
  margin-inline-start: 1rem;
}

@media (max-width: 575px) {
  .psm-relatedproducts--list .psm-relatedproducts__row-thumb {
    flex-basis: 48px;
    width: 48px;
    height: 48px;
  }
  .psm-relatedproducts--list .psm-relatedproducts__row-link {
    gap: 0.75rem;
    padding: 0.6rem 0.25rem;
  }
}
