/**
 * D40 Static Cart CSS Fixes
 * 
 * Contains overrides for Elementor and other theme conflicts
 * These styles have higher specificity and use !important to ensure they override any conflicting styles
 */

/* ==================== */
/* ELEMENTOR CONFLICT FIXES */
/* ==================== */

/* Stronger cart icon container selector to override Elementor */
body .d40-static-cart-icon-container,
html body .d40-static-cart-icon-container,
.d40-static-cart-icon-container.cart-visible {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 999 !important;
}

/* Ensure icon and count are visible */
body .d40-static-cart-icon,
html body .d40-static-cart-icon {
    color: white !important;
}

body .d40-static-cart-count,
html body .d40-static-cart-count {
    display: block !important;
}

/* Fix button conflict with Elementor and prevent cart buttons looking like theme buttons */
body .d40-static-cart-checkout,
html body .d40-static-cart-checkout {
    background-color: #0073aa !important;
    color: #fff !important;
    width: 100% !important;
    padding: 12px 15px !important;
}

/* ==================== */
/* CART CONTAINER AND OVERLAY FIXES */
/* ==================== */

/* Ensure cart container appears when active */
body .d40-static-cart-container.active,
html body .d40-static-cart-container.active,
.d40-static-cart-container.active {
    right: 0 !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 999999 !important;
}

/* Ensure overlay appears when active */
body .d40-static-cart-overlay.active,
html body .d40-static-cart-overlay.active,
.d40-static-cart-overlay.active {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 999998 !important;
}

/* ==================== */
/* CART ITEMS FIXES */
/* ==================== */

/* Ensure cart items are properly displayed */
body .d40-static-cart-items,
html body .d40-static-cart-items {
    padding: 15px !important;
    overflow-y: auto !important;
    max-height: 50vh !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Ensure cart buttons work properly */
body .d40-static-cart-container .d40-static-cart-remove,
html body .d40-static-cart-container .d40-static-cart-remove,
.d40-static-cart-container .d40-static-cart-remove {
    display: inline-block !important;
    margin-left: 10px !important;
    cursor: pointer !important;
    color: #e94b35 !important;
    text-decoration: none !important;
    border: none !important;
    background: transparent !important;
    padding: 3px 8px !important;
}

/* Ensure checkout button is visible */
body .d40-static-cart-checkout,
html body .d40-static-cart-checkout,
.d40-static-cart-checkout {
    display: block !important;
    width: 100% !important;
    padding: 10px !important;
    background-color: #0073aa !important;
    color: white !important;
    border: none !important;
    cursor: pointer !important;
    text-align: center !important;
    font-weight: bold !important;
}

/* ==================== */
/* ANIMATION STYLES */
/* ==================== */

/* Animation keyframes */
@keyframes d40CartPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes d40CartShake {
    0% { transform: translateX(0); }
    25% { transform: translateX(5px); }
    50% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
    100% { transform: translateX(0); }
}

@keyframes d40CartSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Cart quantity animations */
.d40-static-cart-count.pulse {
    animation: d40CartPulse 0.5s ease-in-out;
}

.d40-static-cart-count.shake {
    animation: d40CartShake 0.5s ease-in-out;
}

/* Loading spinner animation */
.d40-static-cart-icon-container.updating .d40-static-cart-icon {
    animation: d40CartSpin 1s linear infinite;
}

/* ==================== */
/* MISC UI ELEMENT FIXES */
/* ==================== */

/* Fix for remove button styling */
.d40-static-cart-remove {
    background: none !important;
    border: none !important;
    padding: 0 !important;
    color: #cc0000 !important;
    text-decoration: underline !important;
    cursor: pointer !important;
    font-size: 0.9em !important;
    margin-left: 10px !important;
    display: inline-block !important;
    min-height: auto !important;
}

.d40-static-cart-remove:hover {
    color: #990000 !important;
    text-decoration: none !important;
}

/* Fix for cart item controls layout */
.d40-static-cart-item-controls {
    display: flex !important;
    align-items: center !important;
    flex-wrap: wrap !important;
}

.d40-static-cart-item-controls label {
    margin-right: 5px !important;
}

.d40-static-cart-item-qty {
    width: 60px !important;
    margin-right: 10px !important;
}

/* Force count to be visible */
body .d40-static-cart-count,
.d40-static-cart-count {
    position: absolute !important;
    top: -5px !important;
    right: -5px !important;
    background-color: #e94b35 !important;
    color: white !important;
    border-radius: 50% !important;
    min-width: 18px !important;
    height: 18px !important;
    font-size: 12px !important;
    line-height: 18px !important;
    text-align: center !important;
    font-weight: bold !important;
    display: block !important;
}

.d40-static-cart-icon-container.updating .d40-static-cart-icon {
    position: relative !important;
}

.d40-static-cart-icon-container.updating .d40-static-cart-icon::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid rgba(0,0,0,0.2);
    border-top: 2px solid #000;
    border-radius: 50%;
    animation: d40CartSpin 1s linear infinite;
}

/* Loading spinner overlay */
.d40-cart-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: all; /* Ensure it blocks interactions while loading */
}

.d40-cart-loading.active {
    opacity: 1;
    visibility: visible;
}

.d40-cart-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3); /* White border for contrast */
    border-top: 4px solid #fff; /* White spinner for visibility */
    border-radius: 50%;
    animation: d40CartSpin 1s linear infinite;
    box-shadow: 0 0 10px rgba(0,0,0,0.2); /* Add shadow for depth */
}
