/* Product Card Integration Styles
   Ensures compatibility with existing theme styles */

/* Reset any conflicting styles */
.product-card * {
    box-sizing: border-box;
}

/* Ensure carousel integration works smoothly */
.carousel-slide .product-card {
    height: 100%;
    margin-bottom: 0;
}

/* Override any existing product card styles that might conflict */
.product-card.product-card_style3 {
    /* Reset old styles */
    all: unset;
    /* Apply new styles */
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: var(--product-card-bg);
    border: 1px solid var(--product-card-border);
    border-radius: var(--product-card-radius);
    box-shadow: var(--product-card-shadow);
    transition: var(--product-card-transition);
    overflow: hidden;
    height: 100%;
}

/* Ensure proper spacing in grid layouts */
.products-grid .product-card {
    margin-bottom: 0; /* Remove bottom margin for clean grid */
}

/* Shop page specific styles */
.shop-main .products-grid {
    gap: 1.25rem; /* Consistent gap for shop page */
}

/* Mobile-specific overrides */
@media (max-width: 767px) {
    .shop-main .products-grid {
        gap: 1rem;
    }
}

/* Integration with existing cart drawer */
.product-card .js-open-aside[data-aside="cartDrawer"] {
    /* Ensure cart drawer integration works */
    position: relative;
    z-index: 1;
}

/* Related Products Carousel Integration */
.products-carousel .swiper-slide {
    height: auto;
    display: flex;
}

.products-carousel .swiper-slide .product-card {
    width: 100%;
    height: auto;
    margin-bottom: 0;
    flex: 1;
}

/* Fix swiper container */
.products-carousel .swiper-container {
    overflow: visible;
    padding: 0 50px; /* Space for navigation arrows */
    position: relative;
}

.products-carousel .swiper-wrapper {
    display: flex;
    align-items: stretch;
}

/* Ensure swiper navigation works with product cards */
.products-carousel .products-carousel__prev,
.products-carousel .products-carousel__next {
    z-index: 10;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.products-carousel .products-carousel__prev {
    left: 10px;
}

.products-carousel .products-carousel__next {
    right: 10px;
}

.products-carousel .products-carousel__prev:hover,
.products-carousel .products-carousel__next:hover {
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Product details page specific styles */
.products-carousel .product-card {
    background: var(--product-card-bg);
    border-radius: var(--product-card-radius);
}

/* Fallback grid layout if swiper fails */
.products-carousel .swiper-wrapper {
    display: flex;
    flex-wrap: nowrap;
    gap: 20px;
}

/* Ensure related products section is visible */
.products-carousel {
    margin: 2rem 0;
    padding: 1rem 0;
}

.products-carousel h2 {
    margin-bottom: 2rem;
}

/* Fix for swiper not initializing - Details page fallback */
.products-carousel .swiper-container:not(.swiper-container-initialized) .swiper-wrapper {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    padding: 0;
    position: relative;
    transform: none !important;
}

.products-carousel .swiper-container:not(.swiper-container-initialized) .swiper-slide {
    transform: none !important;
    width: auto !important;
    margin-right: 0 !important;
}

@media (max-width: 1200px) {
    .products-carousel .swiper-container:not(.swiper-container-initialized) .swiper-wrapper {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.25rem;
    }
}

@media (max-width: 768px) {
    .products-carousel .swiper-container:not(.swiper-container-initialized) .swiper-wrapper {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .products-carousel .swiper-container:not(.swiper-container-initialized) .swiper-wrapper {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
}

/* Ensure related products are always visible */
.products-carousel .swiper-slide .product-card {
    display: flex !important;
    flex-direction: column !important;
}

/* Force proper layout for related products */
#related_products .swiper-slide {
    flex-shrink: 0;
    width: auto;
    height: auto;
}

/* Ensure consistent card heights */
#related_products .swiper-wrapper {
    align-items: stretch;
}

#related_products .product-card {
    height: 100%;
    min-height: 400px;
}

/* Loading state for swiper */
.products-carousel .swiper-container {
    min-height: 450px;
    position: relative;
}

.products-carousel .swiper-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1;
}

.products-carousel .swiper-container.swiper-container-initialized::before,
.products-carousel .swiper-container:not(.swiper-container-initialized):has(.swiper-slide)::before {
    display: none;
}

/* Fallback grid for swiper initialization failures */
.products-carousel .swiper-container.swiper-fallback-grid .swiper-wrapper {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    padding: 0;
    transform: none !important;
}

.products-carousel .swiper-container.swiper-fallback-grid .swiper-slide {
    transform: none !important;
    width: auto !important;
    margin-right: 0 !important;
}

@media (max-width: 1200px) {
    .products-carousel .swiper-container.swiper-fallback-grid .swiper-wrapper {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.25rem;
    }
}

@media (max-width: 768px) {
    .products-carousel .swiper-container.swiper-fallback-grid .swiper-wrapper {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .products-carousel .swiper-container.swiper-fallback-grid .swiper-wrapper {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
}

/* Ensure wishlist integration */
.product-card .js-add-wishlist {
    /* Maintain existing wishlist functionality */
    position: relative;
}

/* Loading states for better UX */
.product-card__add-to-cart:disabled {
    pointer-events: none;
    opacity: 0.7;
}

.product-card__add-to-cart.loading {
    position: relative;
    color: transparent;
}

.product-card__add-to-cart.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Ensure proper focus management */
.product-card:focus-within {
    outline: 2px solid var(--product-card-btn-primary);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .product-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .product-card__quick-actions,
    .product-card__actions {
        display: none !important;
    }
}
