/* Category Carousel Styles */
.carousel-container {
    width: 100%;
    padding: 2rem 0;
    overflow: hidden;
}

.carousel {
    --items: 8;
    --carousel-duration: 40s;
    --carousel-width: min(90vw, 1400px);
    --carousel-item-width: 280px;
    --carousel-item-height: 400px;
    --carousel-item-gap: 1.5rem;
    --carousel-height: 435px;
    
    position: relative;
    width: var(--carousel-width);
    height: var(--carousel-height);
    margin: 0 auto;
    overflow: hidden;
    
    /* إزالة التأثير الضبابي للحواف عندما تكون العناصر قليلة */
    mask-image: none;
    -webkit-mask-image: none;
}

/* إضافة التأثير الضبابي فقط عندما تكون العناصر كثيرة */
.carousel[data-items="6"],
.carousel[data-items="7"],
.carousel[data-items="8"],
.carousel[data-items="9"],
.carousel[data-items="10"] {
    mask-image: linear-gradient(
        to right,
        transparent,
        black 10% 90%,
        transparent
    );
    -webkit-mask-image: linear-gradient(
        to right,
        transparent,
        black 10% 90%,
        transparent
    );
}

/* تحديث ديناميكي للمتغيرات بناءً على عدد العناصر - محسن */
.carousel[data-items="1"] { 
    --items: 8; 
    --carousel-duration: 35s;
    --carousel-item-gap: 1rem;
}
.carousel[data-items="2"] { 
    --items: 8; 
    --carousel-duration: 35s;
    --carousel-item-gap: 1rem;
}
.carousel[data-items="3"] { 
    --items: 9; 
    --carousel-duration: 40s;
    --carousel-item-gap: 1rem;
}
.carousel[data-items="4"] { 
    --items: 8; 
    --carousel-duration: 35s;
    --carousel-item-gap: 1.2rem;
}
.carousel[data-items="5"] { 
    --items: 10; 
    --carousel-duration: 45s;
    --carousel-item-gap: 1.2rem;
}

.carousel:hover > article {
    animation-play-state: paused;
}

.carousel > article {
    position: absolute;
    top: 0;
    left: calc(100% + var(--carousel-item-gap));
    width: var(--carousel-item-width);
    height: var(--carousel-item-height);
    margin-top: 1rem;
    margin-bottom: 1rem;
    display: grid;
    grid-template-rows: 200px auto 1fr auto;
    gap: 0.5rem;
    
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    
    /* Animation */
    will-change: transform;
    animation-name: marquee;
    animation-duration: var(--carousel-duration);
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-delay: calc(
        var(--carousel-duration) / var(--items) * var(--i) * -1
    );
    
    /* تحسين الأداء */
    transform: translateZ(0);
    backface-visibility: hidden;
}

.carousel > article:hover {
    transform: translateY(-4px);
}

.carousel img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px 12px 0 0;
}

.carousel > article > *:not(img) {
    padding: 0 1rem;
}

.carousel > article > div {
    grid-row: span 2;
    display: grid;
    grid-template-rows: subgrid;
    font-size: 0.875rem;
    padding-bottom: 1rem;
}

.carousel > article h2 {
    font-size: 1.25rem;
    font-weight: 600;
    padding: 0.75rem 1rem 0.5rem;
    margin: 0;
    text-align: center;
}

.carousel > article p {
    margin: 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.carousel > article a {
    text-decoration: none;
    font-weight: 500;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    text-align: center;
    place-self: center;
    transition: all 0.3s ease;
    margin: 0.5rem;
}

.carousel > article a:hover {
    transform: translateY(-1px);
}

@keyframes marquee {
    100% {
        transform: translateX(
            calc(
                (var(--items) * (var(--carousel-item-width) + var(--carousel-item-gap))) * -1
            )
        );
    }
}

/* Products Carousel Specific Styles */
.products-carousel-container {
    width: 100%;
    padding: 2rem 0;
    overflow: hidden;
}

.products-carousel {
    --items: 8;
    --carousel-duration: 45s;
    --carousel-width: min(90vw, 1400px);
    --carousel-item-width: 300px;
    --carousel-item-height: 450px;
    --carousel-height: 485px;
    --carousel-item-gap: 1.5rem;
    
    position: relative;
    width: var(--carousel-width);
    height: var(--carousel-height);
    margin: 0 auto;
    overflow: hidden;
    
    /* إزالة التأثير الضبابي للحواف عندما تكون العناصر قليلة */
    mask-image: none;
    -webkit-mask-image: none;
}

/* إضافة التأثير الضبابي فقط عندما تكون العناصر كثيرة */
.products-carousel[data-items="7"],
.products-carousel[data-items="8"],
.products-carousel[data-items="9"],
.products-carousel[data-items="10"] {
    mask-image: linear-gradient(
        to right,
        transparent,
        black 10% 90%,
        transparent
    );
    -webkit-mask-image: linear-gradient(
        to right,
        transparent,
        black 10% 90%,
        transparent
    );
}

/* تحديث ديناميكي للمنتجات - محسن */
.products-carousel[data-items="1"] { 
    --items: 10; 
    --carousel-duration: 40s;
    --carousel-item-gap: 1rem;
}
.products-carousel[data-items="2"] { 
    --items: 10; 
    --carousel-duration: 40s;
    --carousel-item-gap: 1rem;
}
.products-carousel[data-items="3"] { 
    --items: 12; 
    --carousel-duration: 45s;
    --carousel-item-gap: 1rem;
}
.products-carousel[data-items="4"] { 
    --items: 12; 
    --carousel-duration: 45s;
    --carousel-item-gap: 1.2rem;
}
.products-carousel[data-items="5"] { 
    --items: 10; 
    --carousel-duration: 40s;
    --carousel-item-gap: 1.2rem;
}
.products-carousel[data-items="6"] { 
    --items: 12; 
    --carousel-duration: 45s;
    --carousel-item-gap: 1.3rem;
}

.products-carousel:hover > article {
    animation-play-state: paused;
}

.products-carousel > article {
    position: absolute;
    top: 0;
    left: calc(100% + var(--carousel-item-gap));
    width: var(--carousel-item-width);
    height: var(--carousel-item-height);
    display: grid;
    grid-template-rows: 220px auto 1fr auto;
    gap: 0.5rem;
    margin-top: 1rem;
    
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    
    /* Animation */
    will-change: transform;
    animation-name: marquee;
    animation-duration: var(--carousel-duration);
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-delay: calc(
        var(--carousel-duration) / var(--items) * var(--i) * -1
    );
    
    /* تحسين الأداء */
    transform: translateZ(0);
    backface-visibility: hidden;
}

.products-carousel > article:hover {
    transform: translateY(-6px);
}

.product-image {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.products-carousel > article:hover .product-image img {
    transform: scale(1.1);
}

.default-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.discount-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 10;
}

.products-carousel > article h3 {
    font-size: 1.125rem;
    font-weight: 600;
    padding: 0.75rem 1rem 0.5rem;
    margin: 0;
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-content {
    grid-row: span 2;
    display: grid;
    grid-template-rows: 1fr auto auto;
    gap: 0.5rem;
    padding: 0 1rem 1rem;
}

.product-content p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.price-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.discounted-price {
    font-size: 1.125rem;
    font-weight: 700;
}

.original-price {
    font-size: 0.875rem;
    text-decoration: line-through;
}

.current-price {
    font-size: 1.125rem;
    font-weight: 700;
}

.product-content a {
    text-decoration: none;
    font-weight: 500;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    text-align: center;
    transition: all 0.3s ease;
    margin-top: 0.5rem;
}

.product-content a:hover {
    transform: translateY(-2px);
}

/* Loading State */
.carousel-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 0;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty State */
.carousel-empty {
    text-align: center;
    padding: 4rem 0;
    font-size: 1.125rem;
}

/* Responsive Design - نهج متجاوب بالكامل */
@media (max-width: 1200px) {
    .carousel,
    .products-carousel {
        --carousel-width: 95vw;
        --carousel-item-width: 22vw;
        --carousel-item-height: 28vw;
        --carousel-item-gap: 1.5vw;
    }
    
    .products-carousel {
        --carousel-item-height: 32vw;
        --carousel-height: calc(32vw + 2rem);
    }
    
    .carousel {
        --carousel-height: calc(28vw + 2rem);
    }
}

@media (max-width: 768px) {
    .carousel-container,
    .products-carousel-container {
        padding: 1rem 0;
    }
    
    .carousel,
    .products-carousel {
        --carousel-width: 100vw;
        --carousel-item-width: 45vw;
        --carousel-item-height: 55vw;
        --carousel-duration: 30s;
        --carousel-item-gap: 2vw;
        --carousel-height: calc(55vw + 1.5rem);
    }
    
    .products-carousel {
        --carousel-item-height: 65vw;
        --carousel-height: calc(65vw + 1.5rem);
    }
    
    .carousel > article {
        grid-template-rows: 35vw auto 1fr auto;
        margin-top: 0.5rem;
        gap: 0.5rem;
    }
    
    .products-carousel > article {
        grid-template-rows: 40vw auto 1fr auto;
        margin-top: 0.5rem;
        gap: 0.5rem;
    }
    
    .carousel > article h2,
    .products-carousel > article h3 {
        font-size: clamp(0.9rem, 3vw, 1.2rem);
        padding: 0.5rem;
        line-height: 1.3;
    }
    
    .carousel > article > *:not(img) {
        padding: 0 0.75rem;
    }
    
    .product-content {
        padding: 0 0.75rem 0.75rem;
    }
    
    .carousel > article p,
    .product-content p {
        font-size: clamp(0.75rem, 2.5vw, 0.9rem);
        line-height: 1.4;
        -webkit-line-clamp: 2;
    }
    
    .carousel > article a,
    .product-content a {
        padding: 0.5rem 1rem;
        font-size: clamp(0.8rem, 2.5vw, 0.95rem);
        margin: 0.5rem 0;
    }
}

@media (max-width: 480px) {
    .carousel-container,
    .products-carousel-container {
        padding: 0.75rem 0;
    }
    
    .carousel,
    .products-carousel {
        --carousel-width: 100vw;
        --carousel-item-width: 70vw;
        --carousel-item-height: 90vw;
        --carousel-duration: 25s;
        --carousel-item-gap: 3vw;
        --carousel-height: calc(90vw + 1rem);
    }
    
    .products-carousel {
        --carousel-item-height: 100vw;
        --carousel-height: calc(100vw + 1rem);
    }
    
    .carousel > article {
        grid-template-rows: 50vw auto 1fr auto;
        gap: 0.5rem;
        margin-top: 0.25rem;
    }
    
    .products-carousel > article {
        grid-template-rows: 55vw auto 1fr auto;
        gap: 0.5rem;
        margin-top: 0.25rem;
    }
    
    .carousel > article h2,
    .products-carousel > article h3 {
        font-size: clamp(0.9rem, 4.2vw, 1.2rem);
        padding: 0.6rem 0.5rem 0.4rem;
        line-height: 1.3;
        text-align: center;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
        display: block;
        white-space: normal;
        max-height: none;
        overflow: visible;
    }
    
    .carousel > article > *:not(img) {
        padding: 0 0.5rem;
    }
    
    .product-content {
        padding: 0 0.5rem 0.5rem;
    }
    
    .carousel > article p,
    .product-content p {
        font-size: clamp(0.75rem, 3.5vw, 0.9rem);
        line-height: 1.4;
        -webkit-line-clamp: 2;
    }
    
    .carousel > article a,
    .product-content a {
        padding: 0.5rem 0.8rem;
        font-size: clamp(0.8rem, 3.5vw, 0.95rem);
        margin: 0.4rem 0;
    }
    
    .price-section {
        gap: 0.2rem;
        padding: 0.3rem 0;
    }
    
    .discounted-price,
    .current-price {
        font-size: clamp(0.95rem, 4.2vw, 1.15rem);
    }
    
    .original-price {
        font-size: clamp(0.75rem, 3.2vw, 0.9rem);
    }
}

@media (max-width: 360px) {
    .carousel,
    .products-carousel {
        --carousel-item-width: 80vw;
        --carousel-item-height: 100vw;
        --carousel-item-gap: 4vw;
        --carousel-height: calc(100vw + 0.75rem);
    }
    
    .products-carousel {
        --carousel-item-height: 110vw;
        --carousel-height: calc(110vw + 0.75rem);
    }
    
    .carousel > article {
        grid-template-rows: 55vw auto 1fr auto;
        gap: 0.6rem;
    }
    
    .products-carousel > article {
        grid-template-rows: 60vw auto 1fr auto;
        gap: 0.6rem;
    }
    
    .carousel > article h2,
    .products-carousel > article h3 {
        font-size: clamp(0.85rem, 4.8vw, 1.1rem);
        padding: 0.7rem 0.5rem 0.4rem;
        line-height: 1.3;
        text-align: center;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
        display: block;
        white-space: normal;
        max-height: none;
        overflow: visible;
    }
    
    .carousel > article > *:not(img) {
        padding: 0 0.5rem;
    }
    
    .product-content {
        padding: 0 0.5rem 0.5rem;
    }
    
    .price-section {
        padding: 0.4rem 0;
    }
}

/* Direction Control */
.products-carousel.rtl > article {
    left: calc(-85% - var(--carousel-item-gap));
    animation-name: marquee-rtl;
}

.carousel.rtl > article {
    left: calc(-100% - var(--carousel-item-gap));
    animation-name: marquee-rtl;
}

@keyframes marquee-rtl {
    100% {
        transform: translateX(
            calc(
                (var(--items) * (var(--carousel-item-width) + var(--carousel-item-gap)))
            )
        );
    }
}

/* تحسين الانتقال بين الاتجاهات */
.products-carousel > article,
.carousel > article {
    transition: left 0.3s ease;
}