/* Raile Woo - product category mosaic */
.raile-category-mosaic {
    --raile-category-gap: 20px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: var(--raile-category-gap);
    width: 100%;
}

.raile-category-mosaic__item {
    position: relative;
    display: block;
    min-width: 0;
    overflow: hidden;
    background: #f2f2f2;
    color: inherit;
    text-decoration: none !important;
    aspect-ratio: 1 / 1;
}

.raile-category-mosaic__item--featured {
    grid-column: 1;
    grid-row: 1 / span 2;
    aspect-ratio: auto;
}

/* Items 2-5 are placed as a 2 x 2 grid in the right half. */
.raile-category-mosaic__item:nth-child(2),
.raile-category-mosaic__item:nth-child(4) {
    grid-column: 2;
}

.raile-category-mosaic__item:nth-child(2) {
    grid-row: 1;
    width: calc(50% - (var(--raile-category-gap) / 2));
    justify-self: start;
}

.raile-category-mosaic__item:nth-child(3) {
    grid-column: 2;
    grid-row: 1;
    width: calc(50% - (var(--raile-category-gap) / 2));
    justify-self: end;
}

.raile-category-mosaic__item:nth-child(4) {
    grid-row: 2;
    width: calc(50% - (var(--raile-category-gap) / 2));
    justify-self: start;
}

.raile-category-mosaic__item:nth-child(5) {
    grid-column: 2;
    grid-row: 2;
    width: calc(50% - (var(--raile-category-gap) / 2));
    justify-self: end;
}

.raile-category-mosaic__image,
.raile-category-mosaic__placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.raile-category-mosaic__image {
    display: block;
    object-fit: cover;
    object-position: center;
    transition: transform 0.45s ease;
}

.raile-category-mosaic__placeholder {
    display: block;
    background: #f2f2f2;
}

.raile-category-mosaic__title {
    font-family: "Playfair Display", serif;
    position: absolute;
    left: 30px;
    bottom: 30px;
    z-index: 2;
    display: block;
    margin: 0;
    color: #111;
    font-size: clamp(16px, 1.15vw, 22px);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    font-size: 26px;
}

@media (hover: hover) and (pointer: fine) {
    .raile-category-mosaic__item:hover .raile-category-mosaic__image {
        transform: scale(1.025);
    }
}

/* Tablet: featured category across the top, remaining categories 2 x 2. */
@media (max-width: 1080px) {
    .raile-category-mosaic {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: auto;
        gap: 16px;
    }

    .raile-category-mosaic__item,
    .raile-category-mosaic__item:nth-child(n) {
        grid-column: auto;
        grid-row: auto;
        width: 100%;
        justify-self: stretch;
        aspect-ratio: 1 / 1;
    }

    .raile-category-mosaic__item--featured,
    .raile-category-mosaic__item--featured:nth-child(n) {
        grid-column: 1 / -1;
        aspect-ratio: 16 / 9;
    }

    .raile-category-mosaic__title {
        left: 16px;
        bottom: 15px;
        font-size: 30px;
    }
}

/* Mobile: one category per row. */
@media (max-width: 767px) {
    .raile-category-mosaic {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .raile-category-mosaic__item,
    .raile-category-mosaic__item:nth-child(n),
    .raile-category-mosaic__item--featured,
    .raile-category-mosaic__item--featured:nth-child(n) {
        grid-column: 1;
        grid-row: auto;
        width: 100%;
        aspect-ratio: 4 / 3;
    }

    .raile-category-mosaic__title {
        left: 14px;
        bottom: 13px;
        font-size: 30px;
    }
}

/* Raile Woo - product carousel */
.raile-products-carousel {
    --raile-carousel-per-view: 4;
    --raile-carousel-gap: 20px;
    position: relative;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

/*
 * Optional one-sided breakout.
 * Add the custom CSS class `products-carousel` to the parent Gutenberg Group.
 * Only carousels inside that group extend to the right viewport edge.
 */
.products-carousel {
    overflow: visible !important;
}

.products-carousel .raile-products-carousel {
    /*
     * Keep the left edge exactly where the Gutenberg container starts,
     * but extend only the right side to the viewport edge.
     * No hard-coded site container width is needed here.
     */
    --raile-carousel-content-width: 100%;
    width: calc(100% + ((100vw - 100%) / 2));
    max-width: none;
    overflow: visible !important;
}

.raile-products-carousel__viewport {
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    scroll-behavior: smooth;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    cursor: grab;
    touch-action: auto;
    user-select: none;
}

.raile-products-carousel__viewport::-webkit-scrollbar {
    display: none;
}

.raile-products-carousel__viewport.is-dragging,
.raile-products-carousel__viewport.is-settling {
    scroll-behavior: auto;
    scroll-snap-type: none;
}

.raile-products-carousel__viewport.is-dragging {
    cursor: grabbing;
    user-select: none;
}

.raile-products-carousel__viewport.is-dragging a,
.raile-products-carousel__viewport.is-dragging img {
    pointer-events: none;
}

.raile-products-carousel__track {
    display: flex;
    gap: var(--raile-carousel-gap);
    align-items: stretch;
}

.raile-products-carousel__slide {
    flex: 0 0 calc((100% - (var(--raile-carousel-gap) * (var(--raile-carousel-per-view) - 1))) / var(--raile-carousel-per-view));
    min-width: 0;
    margin: 0;
    scroll-snap-align: start;
}

.products-carousel .raile-products-carousel__slide {
    /* Keep card width based on the original Gutenberg content width while the viewport breaks out right. */
    flex-basis: calc((var(--raile-carousel-content-width) - (var(--raile-carousel-gap) * (var(--raile-carousel-per-view) - 1))) / var(--raile-carousel-per-view));
}

.raile-products-carousel__image-link,
.raile-products-carousel__image {
    display: block;
    width: 100%;
}

.raile-products-carousel__image-link {
    overflow: hidden;
    background: #f5f5f5;
    text-decoration: none;
}

.raile-products-carousel__image {
    height: auto;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    transition: transform .35s ease;
}

.raile-products-carousel__arrow {
    position: absolute;
    top: 42%;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, .14);
    border-radius: 999px;
    background: #fff;
    color: #111;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transform: translateY(-50%);
}

.raile-products-carousel__arrow--prev {
    left: -21px;
}

.raile-products-carousel__arrow--next {
    right: -21px;
}

.raile-products-carousel__arrow:disabled,
.raile-products-carousel.is-static .raile-products-carousel__arrow {
    opacity: .3;
    cursor: default;
}

.raile-products-carousel__dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.raile-products-carousel__dot {
    width: 8px;
    height: 8px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: currentColor;
    opacity: .25;
    cursor: pointer;
}

.raile-products-carousel__dot.is-active {
    opacity: 1;
}

@media (max-width: 1180px) {
    .raile-products-carousel__arrow--prev { left: 6px; }
    .raile-products-carousel__arrow--next { right: 6px; }
}

@media (max-width: 767px) {
    .raile-products-carousel__arrow {
        width: 38px;
        height: 38px;
    }
}

/* Raile Woo - product image swap on hover (Astra/WooCommerce + custom carousel) */
.woocommerce ul.products li.product .astra-shop-thumbnail-wrap,
.woocommerce ul.products li.product .woocommerce-loop-product__link,
.raile-products-carousel__image-link {
    position: relative;
}

/* Disable Astra/theme thumbnail zoom for product cards. */
.woocommerce ul.products li.product .astra-shop-thumbnail-wrap img,
.woocommerce ul.products li.product .woocommerce-loop-product__link img,
.raile-products-carousel__image {
    transform: none !important;
}

/*
 * Keep the primary image visible underneath at all times.
 * Only the secondary image fades in/out on top. This avoids the brief
 * washed-out/ghosted moment that happens when both images change opacity.
 */
.woocommerce ul.products li.product .astra-shop-thumbnail-wrap img:not(.raile-product-hover-image),
.woocommerce ul.products li.product .woocommerce-loop-product__link > img:not(.raile-product-hover-image),
.raile-product-primary-image {
    opacity: 1 !important;
}

.raile-product-hover-image {
    position: absolute !important;
    inset: 0;
    z-index: 2;
    display: block;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    object-fit: cover;
    opacity: 0;
    pointer-events: none;
    transform: none !important;
    will-change: opacity;
    backface-visibility: hidden;
    transition: opacity .58s cubic-bezier(.22, .61, .36, 1) !important;
}

/* Custom carousel keeps the same 3:4 crop for both images. */
.raile-products-carousel__image-link .raile-product-hover-image {
    aspect-ratio: 3 / 4;
}

@media (hover: hover) and (pointer: fine) {
    .woocommerce ul.products li.product:hover .raile-product-hover-image,
    .raile-products-carousel__slide:hover .raile-product-hover-image {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .raile-product-hover-image {
        transition-duration: .01ms !important;
    }
}
