/**
 * Pinterest Grid Layout Fix
 * 
 * @package PinterestShop
 * @version 1.0.0
 */

/* ==========================================================================
   PINTEREST GRID LAYOUT FIX
   ========================================================================== */

/* Ensure proper grid layout for homepage products */
.homepage-products-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
    gap: 25px !important;
    align-items: start !important;
    margin-bottom: 50px;
}

/* Product card styling */
.homepage-product-card {
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    transition: all 0.4s ease;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: fit-content;
    width: 100%;
}

.homepage-product-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

/* Image container with fixed heights for Pinterest effect */
.homepage-product-image {
    position: relative;
    overflow: hidden;
    width: 100%;
}

.homepage-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
    display: block;
}

.homepage-product-card:hover .homepage-product-image img {
    transform: scale(1.08);
}

/* Product info section */
.homepage-product-info {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* Elementor products grid */
.elementor-products-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
    gap: 25px !important;
    align-items: start !important;
    margin-bottom: 50px;
}

.elementor-product-card {
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    transition: all 0.4s ease;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: fit-content;
    width: 100%;
}

.elementor-product-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.elementor-product-image {
    position: relative;
    overflow: hidden;
    width: 100%;
}

.elementor-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
    display: block;
}

.elementor-product-card:hover .elementor-product-image img {
    transform: scale(1.08);
}

.elementor-product-info {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   RESPONSIVE GRID LAYOUT
   ========================================================================== */

/* Large screens (1200px+) - 4 columns */
@media (min-width: 1200px) {
    .homepage-products-grid,
    .elementor-products-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* Medium screens (768px - 1199px) - 3 columns */
@media (max-width: 1199px) and (min-width: 768px) {
    .homepage-products-grid,
    .elementor-products-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 20px !important;
    }
}

/* Mobile screens (768px and below) - 2 columns */
@media (max-width: 768px) {
    .homepage-products-grid,
    .elementor-products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
        padding: 0 10px;
    }

    .homepage-product-card,
    .elementor-product-card {
        min-width: 0; /* Prevent overflow */
    }
}

/* Very small screens (400px and below) - 1 column */
@media (max-width: 400px) {
    .homepage-products-grid,
    .elementor-products-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
        padding: 0 15px;
    }
}

/* ==========================================================================
   PINTEREST HEIGHT VARIATIONS
   ========================================================================== */

/* Uniform height for all product images */
.homepage-product-image,
.elementor-product-image {
    height: 300px !important;
}

/* Override any random height classes */
.pinterest-height-1 .homepage-product-image,
.pinterest-height-1 .elementor-product-image,
.pinterest-height-2 .homepage-product-image,
.pinterest-height-2 .elementor-product-image,
.pinterest-height-3 .homepage-product-image,
.pinterest-height-3 .elementor-product-image,
.pinterest-height-4 .homepage-product-image,
.pinterest-height-4 .elementor-product-image,
.pinterest-height-5 .homepage-product-image,
.pinterest-height-5 .elementor-product-image,
.pinterest-height-6 .homepage-product-image,
.pinterest-height-6 .elementor-product-image {
    height: 300px !important;
}

/* ==========================================================================
   LOADING STATES
   ========================================================================== */

.homepage-products-grid.loading,
.elementor-products-grid.loading {
    opacity: 0.6;
    pointer-events: none;
}

.homepage-products-grid.loading::after,
.elementor-products-grid.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #e60023;
    border-radius: 50%;
    animation: pinterestSpin 1s linear infinite;
    transform: translate(-50%, -50%);
}

@keyframes pinterestSpin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ==========================================================================
   MOBILE ACTION BUTTONS
   ========================================================================== */

/* Mobile uses same grid layout with 2 columns */
@media (max-width: 768px) {
    .homepage-products-grid,
    .elementor-products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }

    /* Force overlays to behave like desktop - hidden by default */
    .homepage-product-overlay,
    .elementor-product-overlay,
    .product-overlay,
    .product-click-overlay {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /* Show overlays only on hover */
    .homepage-product-card:hover .homepage-product-overlay,
    .elementor-product-card:hover .elementor-product-overlay,
    .product-card:hover .product-overlay,
    .homepage-product-card:hover .product-click-overlay {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
}

    .quick-action-btn,
    .elementor-action-btn {
        width: 44px !important; /* Touch-friendly size */
        height: 44px !important;
        border-radius: 50%;
        background: rgba(255,255,255,0.95) !important;
        color: #333 !important;
        border: none;
        cursor: pointer;
        transition: all 0.3s ease;
        display: flex !important;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
        touch-action: manipulation; /* Improve touch response */
    }

    .quick-action-btn:active,
    .elementor-action-btn:active {
        transform: scale(0.95);
        background: #fff !important;
    }

    .btn-add-cart:hover,
    .btn-add-cart:active {
        background: #e60023 !important;
        color: #fff !important;
    }

    .btn-save:hover,
    .btn-save:active,
    .btn-save.saved {
        background: #ff6b6b !important;
        color: #fff !important;
    }

    .btn-quick-view:hover,
    .btn-quick-view:active {
        background: #333 !important;
        color: #fff !important;
    }

    /* Ensure buttons don't interfere with card clicks */
    .homepage-product-card,
    .elementor-product-card {
        position: relative;
    }

    /* Prevent card click when clicking buttons */
    .homepage-product-overlay,
    .elementor-product-overlay {
        pointer-events: auto;
        z-index: 10;
    }

    .product-quick-actions,
    .elementor-product-actions {
        pointer-events: auto;
        z-index: 11;
    }

    /* Make product info area clickable for navigation */
    .homepage-product-info,
    .elementor-product-info {
        cursor: pointer;
        position: relative;
        z-index: 5;
    }
}

/* Very small mobile adjustments */
@media (max-width: 400px) {
    .quick-action-btn,
    .elementor-action-btn {
        width: 40px !important;
        height: 40px !important;
        font-size: 16px;
    }

    .product-quick-actions,
    .elementor-product-actions {
        bottom: 8px;
        right: 8px;
        gap: 6px;
    }
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

.homepage-product-card,
.elementor-product-card {
    animation: pinterestFadeInUp 0.6s ease-out;
}

.homepage-product-card:nth-child(even),
.elementor-product-card:nth-child(even) {
    animation-delay: 0.1s;
}

.homepage-product-card:nth-child(3n),
.elementor-product-card:nth-child(3n) {
    animation-delay: 0.2s;
}

@keyframes pinterestFadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   FALLBACK FOR OLDER BROWSERS
   ========================================================================== */

/* Fallback for browsers that don't support CSS Grid */
@supports not (display: grid) {
    .homepage-products-grid,
    .elementor-products-grid {
        display: flex;
        flex-wrap: wrap;
        margin: -12.5px;
    }
    
    .homepage-product-card,
    .elementor-product-card {
        flex: 0 0 calc(25% - 25px);
        margin: 12.5px;
    }
    
    @media (max-width: 1199px) {
        .homepage-product-card,
        .elementor-product-card {
            flex: 0 0 calc(33.333% - 25px);
        }
    }
    
    @media (max-width: 767px) {
        .homepage-product-card,
        .elementor-product-card {
            flex: 0 0 calc(50% - 25px);
        }
    }
    
    @media (max-width: 479px) {
        .homepage-product-card,
        .elementor-product-card {
            flex: 0 0 calc(100% - 25px);
        }
    }
}
