/**
 * Product Grid/Carousel Widget - Optimized Styles
 *
 * Performance optimizations:
 * - Low specificity (max 2-3 levels)
 * - CSS custom properties for theming
 * - GPU-accelerated animations
 * - Paint containment
 * - Reduced motion support
 *
 * @package Storedash_Checkout
 * @version 2.8.5
 * @updated 2025-10-13
 */

/* ============================================
   CSS Custom Properties
   ============================================ */

:root {
    --pg-primary: #E65500;
    --pg-card-bg: #ffffff;
    --pg-border: #e5e7eb;
    --pg-text: #1f2937;
    --pg-text-light: #6b7280;
    --pg-radius: 12px;
    --pg-spacing: 16px;
    --pg-transition: 0.2s ease;
}

/* ============================================
   Grid Layout - Low Specificity
   ============================================ */

.storedash-products-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

/* ============================================
   Product Card - Performance Optimized
   ============================================ */

.product-card {
    position: relative;
    background: var(--pg-card-bg);
    border: 1px solid var(--pg-border);
    border-radius: var(--pg-radius);
    padding: var(--pg-spacing);
    display: flex;
    flex-direction: column;

    /* Paint containment for better performance */
    contain: layout style;
}

/* Optional hover effect - only when enabled */
.has-card-hover .product-card {
    transition: transform var(--pg-transition), box-shadow var(--pg-transition);
    will-change: auto; /* Don't pre-allocate until hover */
}

.has-card-hover .product-card:hover {
    transform: translateY(-4px); /* GPU accelerated */
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
    will-change: transform; /* Hint GPU on hover */
}

/* ============================================
   Product Image
   ============================================ */

.product-image {
    position: relative;
    overflow: hidden;
    margin-bottom: var(--pg-spacing);
    border-radius: 8px;
    width: 100%; /* Ensure container takes full width */
}

/* ============================================
   Product Badges - Positioned relative to card (ignores card padding)
   ============================================ */

.product-badge {
    position: absolute !important;
    z-index: 10;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    display: inline-block;
    margin: 0; /* No margin by default - Elementor controls will override if user sets values */
}

/* Badge Position Classes - Stick to absolute corner of card */
.product-badge.badge-position-top-left {
    top: 0 !important;
    left: 0 !important;
    right: auto !important;
    bottom: auto !important;
}

.product-badge.badge-position-top-right {
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: auto !important;
}

.product-image img {
    width: 100% !important; /* Override inline width attribute */
    height: auto !important; /* Override inline height attribute - let aspect-ratio control it */
    max-width: 100%; /* Ensure image never exceeds container */
    display: block; /* Remove inline spacing */
    /* object-fit will be set by Elementor control */
}

/* Optional image zoom - only when enabled */
.has-image-zoom .product-image img {
    transition: transform 0.3s ease;
}

.has-image-zoom .product-card:hover .product-image img {
    transform: scale(1.05); /* GPU accelerated */
}

/* ============================================
   Product Badges - New Badge System
   ============================================ */

.product-badge {
    position: absolute !important;
    z-index: 10;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    display: inline-block;
}

/* Badge Position Classes - Stick to absolute corner */
.product-badge.badge-position-top-left {
    top: 0 !important;
    left: 0 !important;
    right: auto !important;
    bottom: auto !important;
}

.product-badge.badge-position-top-right {
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: auto !important;
}

/* Badge Type Specific Styles (overridden by Elementor controls) */
.product-badge.badge-sale {
    /* Styles controlled by Elementor */
}

.product-badge.badge-new {
    /* Styles controlled by Elementor */
}

.product-badge.badge-out-of-stock {
    /* Styles controlled by Elementor */
}

/* Legacy sale-badge class - kept for backwards compatibility */
.sale-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: #ef4444;
    color: #ffffff;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    z-index: 2;
}

/* ============================================
   Product Info
   ============================================ */

.product-info {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.product-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}

.product-title a {
    color: var(--pg-text);
    text-decoration: none;
    transition: color var(--pg-transition);
}

.product-title a:hover {
    color: var(--pg-primary);
}

.product-sku {
    font-size: 13px;
    color: var(--pg-text-light);
    margin-bottom: 8px;
}

.product-rating {
    margin-bottom: 8px;
}

.product-excerpt {
    font-size: 14px;
    color: var(--pg-text-light);
    line-height: 1.5;
    margin-bottom: auto; /* Push subsequent items to bottom */
}

.product-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--pg-primary);
    margin-bottom: 12px;
    margin-top: auto; /* Price always at bottom of .product-info */
}

.product-price del {
    color: #9ca3af;
    font-weight: 400;
    font-size: 16px;
    margin-right: 8px;
}

/* ============================================
   Add to Cart Button
   ============================================ */

.product-actions {
    margin-top: 0; /* Button directly after price */
}

.product-add-to-cart {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--pg-primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--pg-transition);
}

.product-add-to-cart svg {
    flex-shrink: 0;
}

.product-add-to-cart:hover {
    background: #cc4d00;
    transform: translateY(-2px);
    box-shadow: none;
}

.product-add-to-cart:active {
    transform: translateY(0);
}

.product-add-to-cart.loading {
    opacity: 0.7;
    pointer-events: none;
}

.product-add-to-cart.added {
    background: #22c55e;
}

.product-add-to-cart:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================
   Section Heading
   ============================================ */

.storedash-widget-header {
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.storedash-section-heading {
    margin: 0;
    padding: 0;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--pg-text);
    flex: 1;
}

/* Header controls for integrated navigation */
.storedash-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.storedash-header-controls .swiper-button-prev,
.storedash-header-controls .swiper-button-next {
    position: static;
    margin: 0;
    width: 44px;
    height: 44px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.storedash-header-controls .swiper-button-prev:after,
.storedash-header-controls .swiper-button-next:after {
    font-size: 18px;
    color: var(--pg-text);
    font-weight: 700;
}

.storedash-header-controls .swiper-button-prev:hover,
.storedash-header-controls .swiper-button-next:hover {
    background: var(--pg-primary);
    transform: scale(1.1);
}

.storedash-header-controls .swiper-button-prev:hover:after,
.storedash-header-controls .swiper-button-next:hover:after {
    color: #ffffff;
}

/* When heading is standalone (not integrated) */
.storedash-widget-header:not(:has(.storedash-header-controls)) {
    display: block;
}

/* ============================================
   Carousel Mode
   ============================================ */

.storedash-products-carousel {
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Prevent stretched slides before Swiper initializes */
.storedash-products-carousel .swiper-wrapper {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
}

.storedash-products-carousel .swiper-slide {
    flex-shrink: 0;
    /* Default width calculation: (100% - gaps) / slides */
    /* Uses CSS custom properties set via inline style in template */
    /* Falls back to 4 slides if custom properties not set */
    width: calc((100% - (var(--gap-size, 20px) * (var(--slides-per-view, 4) - 1))) / var(--slides-per-view, 4));
    min-width: 200px;
}

/* Responsive defaults for non-initialized carousels */
@media (max-width: 1024px) {
    .storedash-products-carousel .swiper-slide {
        width: calc((100% - 40px) / 3); /* 3 slides on tablet */
    }
}

@media (max-width: 768px) {
    .storedash-products-carousel .swiper-slide {
        width: calc((100% - 20px) / 2); /* 2 slides on mobile */
    }
}

/* When Swiper is initialized, it controls everything */
.storedash-products-carousel.swiper-initialized .swiper-slide {
    width: auto; /* Let Swiper control width completely */
    min-width: 0;
}

/* Add space for arrows when positioned outside */
.nav-top-left,
.nav-top-right {
    padding-top: 70px;
}

.nav-bottom-left,
.nav-bottom-right {
    padding-bottom: 70px;
}

.nav-outside {
    padding-left: 70px;
    padding-right: 70px;
}

.storedash-products-carousel .swiper-slide {
    height: auto;
}

.storedash-products-carousel .product-card {
    height: 100%;
}

/* Swiper Navigation */
.storedash-products-carousel .swiper-button-prev,
.storedash-products-carousel .swiper-button-next {
    width: 44px;
    height: 44px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.storedash-products-carousel .swiper-button-prev:after,
.storedash-products-carousel .swiper-button-next:after {
    font-size: 18px;
    color: var(--pg-text);
    font-weight: 700;
}

.storedash-products-carousel .swiper-button-prev:hover,
.storedash-products-carousel .swiper-button-next:hover {
    background: var(--pg-primary);
    transform: scale(1.1);
}

.storedash-products-carousel .swiper-button-prev:hover:after,
.storedash-products-carousel .swiper-button-next:hover:after {
    color: #ffffff;
}

/* Navigation Positioning - Outside */
.nav-outside .swiper-button-prev {
    left: -60px;
}

.nav-outside .swiper-button-next {
    right: -60px;
}

/* Navigation Positioning - Top Left */
.nav-top-left .swiper-button-prev,
.nav-top-left .swiper-button-next {
    top: 0;
    left: 0;
    margin-top: 0;
}

.nav-top-left .swiper-button-next {
    left: 60px;
}

/* Navigation Positioning - Top Right */
.nav-top-right .swiper-button-prev,
.nav-top-right .swiper-button-next {
    top: 0;
    right: 0;
    left: auto;
    margin-top: 0;
}

.nav-top-right .swiper-button-prev {
    right: 60px;
}

/* Navigation Positioning - Bottom Left */
.nav-bottom-left .swiper-button-prev,
.nav-bottom-left .swiper-button-next {
    top: auto;
    bottom: 0;
    left: 0;
    margin-top: 0;
}

.nav-bottom-left .swiper-button-next {
    left: 60px;
}

/* Navigation Positioning - Bottom Right */
.nav-bottom-right .swiper-button-prev,
.nav-bottom-right .swiper-button-next {
    top: auto;
    bottom: 0;
    right: 0;
    left: auto;
    margin-top: 0;
}

.nav-bottom-right .swiper-button-prev {
    right: 60px;
}

/* Swiper Pagination */
.storedash-products-carousel .swiper-pagination {
    margin-top: 24px;
    position: relative;
    bottom: auto;
    display: flex;
    justify-content: center;
}

.storedash-products-carousel .swiper-pagination-bullet {
    width: 12px;
    height: 12px;
    background: #d1d5db;
    opacity: 1;
    transition: all 0.3s ease;
}

.storedash-products-carousel .swiper-pagination-bullet-active {
    background: var(--pg-primary);
    width: 32px;
    border-radius: 6px;
}

/* Pagination Positioning - Top Center */
.pagination-top-center .swiper-pagination {
    margin-top: 0;
    margin-bottom: 24px;
    order: -1;
}

/* Pagination Positioning - Top Left */
.pagination-top-left .swiper-pagination {
    margin-top: 0;
    margin-bottom: 24px;
    order: -1;
    justify-content: flex-start;
}

/* Pagination Positioning - Top Right */
.pagination-top-right .swiper-pagination {
    margin-top: 0;
    margin-bottom: 24px;
    order: -1;
    justify-content: flex-end;
}

/* Pagination Positioning - Bottom Left */
.pagination-bottom-left .swiper-pagination {
    justify-content: flex-start;
}

/* Pagination Positioning - Bottom Right */
.pagination-bottom-right .swiper-pagination {
    justify-content: flex-end;
}

/* ============================================
   Carousel Bleed Effect (Products & Categories)
   ============================================ */

/* Enable overflow on right side only when bleed is active */
.carousel-bleed-enabled.storedash-products-carousel,
.carousel-bleed-enabled.storedash-categories-carousel {
    overflow: visible; /* Allow overflow to right */
}

/* Keep the swiper wrapper contained on left, overflow on right */
.carousel-bleed-enabled .swiper-wrapper {
    overflow: visible;
}

/* Ensure slides can overflow */
.carousel-bleed-enabled .swiper-slide {
    flex-shrink: 0;
}

/* Mask the overflow on the left side only */
.carousel-bleed-enabled.storedash-products-carousel::before,
.carousel-bleed-enabled.storedash-categories-carousel::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 1px;
    background: transparent;
    z-index: 10;
    pointer-events: none;
}

/* Ensure navigation arrows stay within container padding */
.carousel-bleed-enabled .swiper-button-prev,
.carousel-bleed-enabled .swiper-button-next {
    z-index: 20; /* Above overflow cards */
}

/* Make first card flush with left edge by compensating for slide padding */
/* The gap control adds padding to each slide, so we pull the wrapper left to cancel the first card's left padding */
.carousel-bleed-enabled .swiper-wrapper {
    margin-left: calc(var(--swiper-gap, 20px) / -2);
    margin-right: 0; /* Only remove left gap, let right overflow */
    justify-content: flex-start !important; /* Force left alignment, prevent centering */
}

/* ============================================
   Style Presets - Visual Defaults Only
   ============================================ */

/* Modern Minimalist Preset */
.preset-modern_clean .product-card {
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    transition: opacity var(--pg-transition);
}

.preset-modern_clean .product-card:hover {
    opacity: 0.85;
    transform: none;
}

.preset-modern_clean .product-image {
    margin-bottom: 12px;
    border-radius: 0;
}

.preset-modern_clean .product-image img {
    border-radius: 0;
}

.preset-modern_clean .product-title {
    font-size: 14px;
    font-weight: 400;
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.preset-modern_clean .product-title a {
    color: #000000;
}

.preset-modern_clean .product-title a:hover {
    color: #666666;
}

.preset-modern_clean .product-price {
    font-size: 16px;
    font-weight: 500;
    color: #000000;
    margin-bottom: 16px;
}

.preset-modern_clean .product-add-to-cart {
    background: #000000;
    border-radius: 0;
    font-weight: 500;
    font-size: 14px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 14px 24px;
}

.preset-modern_clean .product-add-to-cart:hover {
    background: #333333;
    transform: none;
    box-shadow: none;
}

.preset-modern_clean .storedash-products-grid {
    gap: 32px;
}

/* Bold & Vibrant Preset */
.preset-bold .product-card {
    border-width: 2px;
    border-color: var(--pg-text);
    border-radius: 16px;
    padding: 24px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.preset-bold .product-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.preset-bold .product-image img {
    border-radius: 12px;
}

.preset-bold .product-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.preset-bold .product-price {
    font-size: 22px;
    font-weight: 800;
    color: #dc2626;
    margin-bottom: 16px;
}

.preset-bold .product-add-to-cart {
    background: #dc2626;
    border-radius: 8px;
    font-weight: 700;
    font-size: 15px;
    padding: 14px 24px;
}

.preset-bold .product-add-to-cart:hover {
    background: #b91c1c;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(220, 38, 38, 0.4);
}

.preset-bold .sale-badge {
    background: #dc2626;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 6px;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1024px) {
    .storedash-products-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .storedash-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .product-card {
        padding: 12px;
    }

    .product-image img {
        height: auto;
    }

    .product-title {
        font-size: 14px;
    }

    .product-price {
        font-size: 16px;
    }

    .product-add-to-cart {
        padding: 10px 16px;
        font-size: 14px;
    }

    /* Keep heading and controls inline on mobile */
    .storedash-widget-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 16px;
    }

    .storedash-section-heading {
        font-size: 18px;
        flex: 1;
        min-width: 0; /* Allow text to shrink if needed */
    }

    .storedash-header-controls {
        flex-shrink: 0;
    }

    /* Adjust control button sizes on mobile */
    .storedash-header-controls .swiper-button-prev,
    .storedash-header-controls .swiper-button-next {
        width: 36px;
        height: 36px;
    }

    .storedash-header-controls .swiper-button-prev:after,
    .storedash-header-controls .swiper-button-next:after {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .storedash-products-grid {
        grid-template-columns: 1fr;
    }

    .product-image img {
        height: auto;
    }
}

/* ============================================
   Accessibility - Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    .product-card {
        transition: none !important;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .storedash-products-wrapper {
        display: none;
    }
}

/* ============================================
   Loading State
   ============================================ */

.storedash-products-wrapper.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ============================================
   Hide WooCommerce Elements
   ============================================ */

.product-card .added_to_cart,
.product-card + .added_to_cart,
.storedash-products-wrapper .added_to_cart.wc-forward {
    display: none !important;
}
