/* stylelint-disable no-descending-specificity */

/* =========================================================
   GRID CONTRACT (FINAL)
   ========================================================= */

.grid {
  /* ---------- Defaults ---------- */
  --grid-col-1: 1fr;
  --grid-col-2: 1fr;
  --gap-spacing: var(--spacing-md);

  /* ---------- Grid container ---------- */

  > :where(ul, .columns-wrapper) {
    display: grid;
    gap: var(--gap-spacing);
  }

  /* ---------- Grid size flags (desktop only) ---------- */
  &.grid-3 {
    --grid-size: 3;
  }

  &.grid-4 {
    --grid-size: 4;
  }

  &.grid-5 {
    --grid-size: 5;
  }

  &.grid-6 {
    --grid-size: 6;
  }

  /* ---------- 2-column distributions (desktop only) ---------- */

  &.cols-50-50 {
    --grid-col-1: 1fr;
    --grid-col-2: 1fr;
  }

  &.cols-25-75 {
    --grid-col-1: 1fr;
    --grid-col-2: 3fr;
  }

  &.cols-75-25 {
    --grid-col-1: 3fr;
    --grid-col-2: 1fr;
  }

  &.cols-33-66 {
    --grid-col-1: 1fr;
    --grid-col-2: 2fr;
  }

  &.cols-66-33 {
    --grid-col-1: 2fr;
    --grid-col-2: 1fr;
  }

  &.cols-40-60 {
    --grid-col-1: 2fr;
    --grid-col-2: 3fr;
  }

  &.cols-60-40 {
    --grid-col-1: 3fr;
    --grid-col-2: 2fr;
  }

  /* ---------- Gap modifiers ---------- */
  &.gap-xs {
    --gap-spacing: var(--spacing-xs);
  }

  &.gap-sm {
    --gap-spacing: var(--spacing-sm);
  }

  &.gap-md {
    --gap-spacing: var(--spacing-md);
  }

  &.gap-lg {
    --gap-spacing: var(--spacing-lg);
  }

  &.gap-xl {
    --gap-spacing: var(--spacing-xl);
  }

  &.gap-none {
    --gap-spacing: 0;
  }

  /* =====================================================
     GRID-1 : Media / Content layout
     ===================================================== */

  &.grid-1 {
    .cards-card-body {
      margin-left: 0;
      margin-right: 0;
    }

    li.mobile-cards-spacing {
      .cards-card-body {
        margin-left: var(--spacing-sm);
        margin-right: var(--spacing-sm);
      }
    }

    /* Tablet & Desktop: media | content */
    @media (min-width: 600px) {
      >ul>li {
        display: grid;
        grid-template-columns: var(--grid-col-1, 1fr) var(--grid-col-2, 1fr);
        gap: var(--gap-spacing);
        align-items: center;
      }

      /* default order */
      .cards-card-image {
        order: 1;
      }

      .cards-card-body {
        order: 2;
      }

      &.content-media {
        .cards-card-image {
          order: 2;
        }

        .cards-card-body {
          order: 1;
        }
      }
    }
  }

  &.grid-scroll {
    position: relative;
    
    > :where(ul, .columns-wrapper) {
      overflow: hidden;
      scroll-snap-type: x mandatory;
      -webkit-overflow-scrolling: touch;
      display: flex;
      gap: var(--gap-spacing);
      scroll-behavior: smooth;

      &:not([data-scroll-init="true"]) {
        display: grid;
      }
    }

    > :where(ul, .columns-wrapper)>li {
      width: 100%;
      scroll-snap-align: start;
    }

    &.no-arrows {
      .slider-arrows, .custom-scrollbar {
        display: none;
      }
    }
  }
}

/* =====================================================
   RESPONSIVE LAYOUT (GLOBAL RULES)
   ===================================================== */

/* ---------- Mobile: always 1 column ---------- */
@media (max-width: 599px) {
  .grid> :where(ul, .columns-wrapper) {
    grid-template-columns: 1fr;
  }
}

/* ---------- Tablet: always 2 columns ---------- */
@media (min-width: 600px) and (max-width: 991px) {
  .grid:not(.grid-1)> :where(ul, .columns-wrapper) {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---------- Desktop: author-controlled ---------- */
@media (min-width: 992px) {
  /* default 2-column grid */
  .grid:not(.grid-1, .grid-3, .grid-4, .grid-5, .grid-6)> :where(ul, .columns-wrapper) {
    grid-template-columns: var(--grid-col-1) var(--grid-col-2);
  }

  .grid.grid-3> :where(ul, .columns-wrapper) {
    grid-template-columns: repeat(3, 1fr);
  }

  .grid.grid-4> :where(ul, .columns-wrapper) {
    grid-template-columns: repeat(4, 1fr);
  }

  .grid.grid-5> :where(ul, .columns-wrapper) {
    grid-template-columns: repeat(5, 1fr);
  }

  .grid.grid-6> :where(ul, .columns-wrapper) {
    grid-template-columns: repeat(6, 1fr);
  }
}


/* =====================================================
   GRID STYLES
   ===================================================== */

/* ---------- Dividers ---------- */
.grid.grid-dividers {
  > :where(ul, .columns-wrapper)>li {
    .cards-card-body {
      margin-left: 0;
      margin-right: 0;
    }
  }

  > :where(ul, .columns-wrapper)>li:not(:last-child)::after {
    content: "";
    position: absolute;
    inset: auto 0 calc(var(--gap-spacing) / -2);
    height: 1px;
    background: var(--color-border, #ccc);

    @media (min-width: 767px) {
      inset: 0 calc(var(--gap-spacing) / -2) 0 auto;
      width: 1px;
      height: auto;
    }
  }

  &.grid-scroll> :where(ul, .columns-wrapper)>li:not(:last-child)::after {
    @media (max-width: 767px) {
      inset: 0 calc(var(--gap-spacing) / -2) 0 auto;
      width: 1px;
      height: auto;
    }
  }

  @media (min-width: 992px) {
    &:not(.grid-scroll).grid-2> :where(ul, .columns-wrapper)>li:nth-child(2n)::after,
    &:not(.grid-scroll).grid-3> :where(ul, .columns-wrapper)>li:nth-child(3n)::after,
    &:not(.grid-scroll).grid-4> :where(ul, .columns-wrapper)>li:nth-child(4n)::after,
    &:not(.grid-scroll).grid-5> :where(ul, .columns-wrapper)>li:nth-child(5n)::after,
    &:not(.grid-scroll).grid-6> :where(ul, .columns-wrapper)>li:nth-child(6n)::after {
      content: none;
    }
  }
}

/* ---------- Outline ---------- */
.grid.grid-outline {
  > :where(ul, .columns-wrapper) > li,
  > .columns-wrapper > div.dropin-product-item-card {
    border: 1px solid var(--color-border);
  }
}

/* ---------- Grid lines ---------- */
.grid.grid-lines {
  > :where(ul, .columns-wrapper) {
    gap: 0;
    border: 1px solid var(--color-border);
  }

  > :where(ul, .columns-wrapper)>li {
    padding: var(--gap-spacing);
    border-bottom: 1px solid var(--color-border);

    .cards-card-body {
      margin-left: 0;
      margin-right: 0;
    }
  }

  @media (min-width: 600px) {
    &:not(.grid-scroll)
    > :where(ul, .columns-wrapper) {
      border: none;
      row-gap: var(--gap-spacing);
    }

    &:not(.grid-scroll)
    > :where(ul, .columns-wrapper)
    > li {
      border-top: 1px solid var(--color-border);
      border-right: 1px solid var(--color-border);
      border-bottom: 1px solid var(--color-border);
    }

    &:not(.grid-scroll)> :where(ul, .columns-wrapper)>li:nth-child(2n - 1) {
      border-left: 1px solid var(--color-border);
    }
  }

  @media (min-width: 767px) {
    &.grid-scroll > :where(ul, .columns-wrapper) {
      border-right: none;
    }

    &.grid-scroll > :where(ul, .columns-wrapper) > li:last-child {
      border-right: 1px solid var(--color-border);
    }
  }

  @media (min-width: 992px) {
    &:not(.grid-scroll, .grid-1) > :where(ul, .columns-wrapper)>li:nth-child(2n - 1) {
      border-left: none;
    }

    &:not(.grid-scroll).grid-2> :where(ul, .columns-wrapper)>li:nth-child(2n + 1),
    &:not(.grid-scroll).grid-3> :where(ul, .columns-wrapper)>li:nth-child(3n + 1),
    &:not(.grid-scroll).grid-4> :where(ul, .columns-wrapper)>li:nth-child(4n + 1),
    &:not(.grid-scroll).grid-5> :where(ul, .columns-wrapper)>li:nth-child(5n + 1),
    &:not(.grid-scroll).grid-6> :where(ul, .columns-wrapper)>li:nth-child(6n + 1) {
      border-left: 1px solid var(--color-border);
    }
  }
}

.grid.grid-center> :where(ul, .columns-wrapper) {
  .cards-card-image img {
    margin-left: auto;
    margin-right: auto;
  }

  li {
    text-align: center;
  }
}

.grid.grid-middle> :where(ul, .columns-wrapper) {
  align-items: center;
}

.grid-lines> :where(ul, .columns-wrapper) > li:last-child {
  border-bottom: none;
}

.grid-lines.grid-scroll> :where(ul, .columns-wrapper) > li {
  border-right: 1px solid var(--color-border);
  border-bottom: none;
}

.grid-lines.grid-scroll > :where(ul, .columns-wrapper) > li:last-child {
  border-right: none;
}

.grid .grid-scroll {
  &.cols-25-75 {
    > :where(ul, .cards-wrapper) > li {
      --grid-col-1: 1fr;
      --grid-col-2: 3fr;
    }
  }

  &.cols-75-25 {
    > :where(ul, .cards-wrapper) > li {
      --grid-col-1: 3fr;
      --grid-col-2: 1fr;
    }
  }

  &.cols-33-66 {
    > :where(ul, .cards-wrapper) > li {
      --grid-col-1: 1fr;
      --grid-col-2: 2fr;
    }
  }

  &.cols-66-33 {
    > :where(ul, .cards-wrapper) > li {
      --grid-col-1: 2fr;
      --grid-col-2: 1fr;
    }
  }
}

.grid:not(.grid-1.grid-scroll) {
  > :where(ul, .columns-wrapper) {
    &:not(.card-lists-1)>li {
      position: relative;
      display: flex;
      flex-direction: column;
      flex: 0 0 var(--slide-width);

      .cards-card-body {
        display: flex;
        flex-direction: column;
        height: 100%;

        .button-container {
          margin-top: auto;
        }

        /* If there is a second button */
        .button-container + .button-container {
          margin-top: var(--spacing-xs);  
        }
      }
    }
  }
}

.cards-wrapper:has(.grid-scroll:not(.no-arrows)),
.carousel-wrapper:has(.grid-scroll:not(.no-arrows)) {
  padding-bottom: 132px;
}

.section[data-block-status="loaded"]:has(.grid-scroll) {
  display: block !important;
}

@media (max-width: 600px) {
  .grid.grid-icon:not(.grid-1.grid-scroll) {
    > :where(ul, .columns-wrapper) {
      &:not(.card-lists-1)>li {
        flex-direction: row;
        gap: var(--spacing-sm);
        padding: 0 var(--spacing-md);
      }
    }
  }
}
