/**
 * Product Grid — layout fixes + mobile Load More styles.
 * Enqueued globally in functions.php.
 */

/* ==========================================================
   HIGH-1: Enforce square aspect-ratio on product thumbnails

   ~70% of thumbnails are 1000×1000. The rest are 1000×(877–999).
   Without a fixed ratio, rows have uneven tile heights.
   aspect-ratio: 1/1 + object-fit: cover crops the few non-square
   images by at most ~12% off the bottom — acceptable since the
   subject is always centered.

   Replaces: .product.type-product img (my_custom_css.css:2779-2790)
   ========================================================== */
.product-grid-section .product.type-product img {
    aspect-ratio: 1 / 1;
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
    margin: 0 auto;
}

/* ==========================================================
   HIGH-2: Consistent tile sizing via .product-item rules

   Previously had ZERO CSS rules. Tiles relied entirely on
   content size, causing inconsistent heights within rows.
   display: flex + flex-direction: column lets the image fill
   available space while the title stays at the bottom.

   Adds rules for: .product-item (functions.php col wrapper)
   ========================================================== */
.product-grid-section .product-item {
    display: flex;
}

.product-grid-section .product-item > li.product {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.product-grid-section .product-item > li.product > a,
.product-grid-section .product-item > li.product > span {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.product-grid-section .product-item > li.product .woocommerce-loop-product__title {
    margin-top: auto;
}

/* ==========================================================
   MED-4: Remove min-height: 100vh on product grid sections

   .section-py forces min-height: 100vh globally. This creates
   large empty gaps below product grids that have fewer products.
   Override for product-grid-section only — other sections that
   use section-py are unaffected.

   Overrides: .section-py (my_custom_css.css:1019-1038)
   ========================================================== */
.product-grid-section.section-py {
    min-height: auto;
}

/* ==========================================================
   MED-5: Line-clamp product titles to 2 lines max

   Without a clamp, long product names wrap to 3+ lines and
   create uneven tile heights within the same row. 2 lines
   accommodates most names; longer ones get ellipsis.

   Overrides: .woocommerce-loop-product__title
              (my_custom_css.css:2768-2775)
   ========================================================== */
.product-grid-section .woocommerce-loop-product__title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================================
   MED-6: Row-gap for consistent vertical spacing

   display_category_products() outputs plain .row divs with
   no row-gap. The only vertical spacing was mb-4 on each tile.
   Adding row-gap on .carousel-item gives consistent spacing
   between the two rows of tiles.
   ========================================================== */
.product-grid-section .carousel-item .row {
    row-gap: 0;
    align-items: flex-start;
}

/* ==========================================================
   LOW-9: Carousel arrow sizing and spacing

   Bootstrap default icons are 2rem (32px). The arrows sit
   inside a .custom-product-slider wrapper that's right-aligned
   via d-flex justify-content-end. Current CSS only sets
   width: auto — no explicit sizing or hover feedback.

   Overrides: .custom-product-slider (my_custom_css.css:3007-3010)
   ========================================================== */
.product-grid-section .custom-product-slider .carousel-control-prev,
.product-grid-section .custom-product-slider .carousel-control-next {
    width: 2.5rem;
    height: 2.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.product-grid-section .custom-product-slider .carousel-control-prev:hover,
.product-grid-section .custom-product-slider .carousel-control-next:hover {
    background: rgba(255, 255, 255, 0.25);
}

.product-grid-section .custom-product-slider .carousel-control-prev-icon,
.product-grid-section .custom-product-slider .carousel-control-next-icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* bg-sky variant: dark arrows on light background */
.product-grid-section.bg-sky .custom-product-slider .carousel-control-prev,
.product-grid-section.bg-sky .custom-product-slider .carousel-control-next {
    background: rgba(50, 50, 50, 0.1);
    border-color: rgba(50, 50, 50, 0.2);
}

.product-grid-section.bg-sky .custom-product-slider .carousel-control-prev:hover,
.product-grid-section.bg-sky .custom-product-slider .carousel-control-next:hover {
    background: rgba(50, 50, 50, 0.25);
}

/* ==========================================================
   MOBILE: Replace carousel with vertical scroll + Load More
   ========================================================== */
@media (max-width: 767px) {

    /* --- Flatten carousel: show all slides at once --- */
    .product-grid-section .carousel-item {
        display: block !important;
        float: none !important;
        margin-right: 0 !important;
    }
    .product-grid-section .carousel-inner {
        overflow: visible !important;
    }
    .product-grid-section .carousel-item,
    .product-grid-section .carousel-item .row {
        transform: none !important;
        transition: none !important;
    }

    /* --- Hide carousel controls --- */
    .product-grid-section .custom-product-slider {
        display: none !important;
    }

    /* --- Hide ghost tiles --- */
    .product-grid-section .product-item[aria-hidden="true"] {
        display: none !important;
    }

    /* --- Hide save-to-board button on mobile grid tiles --- */
    .product-grid-section .ei-board-btn {
        display: none !important;
    }

    /* --- Hidden product tiles (JS adds this class) --- */
    .product-grid-section .product-item.mobile-hidden {
        display: none !important;
    }

    /* --- Two-line subcategory headings --- */
    .product-grid-section .heading-brand,
    .product-grid-section .heading-desc {
        display: block;
    }

    .product-grid-section .heading-brand {
        font-size: 1.6em;
        line-height: 1.2;
    }

    .product-grid-section .heading-desc {
        font-size: 0.8em;
        letter-spacing: 0.05em;
        opacity: 0.7;
        line-height: 1.3;
    }

    /* --- Load More button --- */
    .load-more-wrapper {
        text-align: center;
        padding: 0.25rem 0 3rem;
    }

    .product-grid-section .load-more-btn {
        background: transparent;
        color: #fff;
        border: 1px solid rgba(255, 255, 255, 0.4);
        border-radius: 25px;
        padding: 1.2rem 2rem;
        cursor: pointer;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
        transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
    }

    .product-grid-section .load-more-btn:hover,
    .product-grid-section .load-more-btn:active,
    .product-grid-section .load-more-btn.is-hovered {
        background: rgba(255, 255, 255, 0.85) !important;
        border-color: #fff !important;
        color: #000 !important;
    }

    .load-more-label {
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.1em;
    }

    .load-more-cat {
        font-size: 1.8rem;
    }

    /* bg-sky variant: dark text/border */
    .product-grid-section .load-more-btn.load-more-light {
        color: #333;
        border-color: rgba(50, 50, 50, 0.4);
    }

    .product-grid-section .load-more-btn.load-more-light:hover,
    .product-grid-section .load-more-btn.load-more-light:active,
    .product-grid-section .load-more-btn.load-more-light.is-hovered {
        background: rgba(50, 50, 50, 0.85) !important;
        border-color: #333 !important;
        color: #fff !important;
    }

    /* Animated CSS chevron arrow — centered above button */
    .load-more-arrow {
        display: block;
        position: relative;
        width: 36px;
        height: 36px;
        margin: 0 auto 1.25rem;
        transform: rotate(45deg);
        border-right: 2px solid #fff;
        border-bottom: 2px solid #fff;
        border-left: none;
        border-top: none;
    }

    .load-more-arrow::before {
        content: '';
        position: absolute;
        width: 24px;
        height: 24px;
        left: 50%;
        top: 50%;
        margin: -12px 0 0 -12px;
        border-right: 1px solid #fff;
        border-bottom: 1px solid #fff;
        border-left: none;
        border-top: none;
        animation: loadMoreArrow 2s infinite;
    }

    .load-more-wrapper.load-more-light .load-more-arrow {
        border-color: #333;
    }

    .load-more-wrapper.load-more-light .load-more-arrow::before {
        border-color: #333;
    }

    @keyframes loadMoreArrow {
        0%   { opacity: 1; }
        100% { opacity: 0; transform: translate(-10px, -10px); }
    }
}
