/* ============================================
   Animated Add to Cart Feature
   Smooth flying product image animation
   ============================================ */

/* Flying product image animation container */
.cart-fly-animation {
    position: fixed;
    z-index: 99999;
    pointer-events: none;
    will-change: transform, opacity;
}

/* The cloned product image that flies to cart */
.cart-fly-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 2px solid #fff;
    /* Smooth animation properties */
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 0.6s ease-out;
}

/* Responsive sizing for mobile */
@media (max-width: 768px) {
    .cart-fly-image {
        width: 60px;
        height: 60px;
    }
}

/* Cart icon bounce animation when item is added */
.cart-bounce-animation {
    animation: cartBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes cartBounce {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    75% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

/* Cart count number bounce animation */
.cart-count-bounce {
    animation: countBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: inline-block;
}

@keyframes countBounce {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.5);
        color: #ffcc00;
    }
    100% {
        transform: scale(1);
    }
}

/* ============================================
   Mini-Cart Header Title Filling Animation
   Shows a filling animation in the header-title section
   Fills from right to left to show cart is filling up
   ============================================ */

/* Make header-title position relative for absolute positioning of fill line */
.mini-cart .header-title {
    position: relative !important;
    overflow: hidden !important;
    /* Ensure the fill animation doesn't interfere with flex layout */
    isolation: isolate;
}

/* Container for the filling line in header-title */
.mini-cart-header-fill-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
    pointer-events: none;
}

/* The animated filling line - fills from left to right when adding, right to left when removing */
.mini-cart-header-fill-line {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    /* Bright yellow gradient that moves from left to right */
    background: linear-gradient(90deg, #ffcc00 0%, #ffd700 25%, #ffcc00 50%, #ffd700 75%, #ffcc00 100%);
    background-size: 200% 100%;
    /* Smooth transition for width changes */
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    /* Shimmer animation - always running */
    animation: shimmerMove 2s infinite;
    /* Glow effect */
    box-shadow: inset 0 0 15px rgba(255, 204, 0, 0.4),
                0 0 10px rgba(255, 204, 0, 0.3);
    /* Visible edge on the right side */
    border-right: 2px solid rgba(255, 204, 0, 0.9);
    /* Ensure it stays visible */
    opacity: 1;
    z-index: 1;
}

/* Animation for filling from left to right (when adding product) */
.mini-cart-header-fill-line.filling {
    /* Keep shimmer animation running */
    animation: shimmerMove 2s infinite;
    /* Smooth width transition handled by CSS transition */
}

/* Animation for emptying from right to left (when removing product) */
.mini-cart-header-fill-line.emptying {
    /* Keep shimmer animation running, but reverse direction */
    animation: shimmerMoveReverse 2s infinite;
}

/* Shimmer effect on the filling line - moves from left to right (when filling) */
@keyframes shimmerMove {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Reverse shimmer effect - moves from right to left (when emptying) */
@keyframes shimmerMoveReverse {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Fade out animation after animation completes (optional) */
.mini-cart-header-fill-line.fade-out {
    animation: fadeOutFill 0.6s ease-out forwards;
    transition: opacity 0.6s ease-out;
}

@keyframes fadeOutFill {
    to {
        opacity: 0;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}

/* Pulse effect on header-title when item is added or removed */
.mini-cart .header-title.cart-updating {
    animation: headerTitlePulse 0.5s ease-out;
}

@keyframes headerTitlePulse {
    0% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(255, 204, 0, 0.08);
    }
    100% {
        background-color: transparent;
    }
}

/* Ensure text stays above the fill animation */
.mini-cart .header-title p,
.mini-cart .header-title .close-icon {
    position: relative;
    z-index: 2;
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 480px) {
    .cart-fly-image {
        width: 50px;
        height: 50px;
    }
    
    .mini-cart-header-fill-line {
        /* Slightly faster on mobile for better UX */
        animation-duration: 1.2s, 1.5s;
    }
}

/* ============================================
   Performance Optimizations
   ============================================ */

/* Use GPU acceleration for smooth animations */
.cart-fly-animation,
.cart-fly-image,
.mini-cart-header-fill-line {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
    will-change: width, opacity, background-position;
}

