/**
 * WCC Loader System - Cercle stylé avec couleur personnalisable
 * Compatible avec tous les thèmes et responsive
 */

/* Variables CSS pour personnalisation */
:root {
    --wcc-loader-color: #0073aa;
    --wcc-loader-size: 24px;
    --wcc-loader-thickness: 3px;
}

/* Loader principal - Spinner rond */
.wcc-loader {
    display: inline-block;
    width: var(--wcc-loader-size);
    height: var(--wcc-loader-size);
    border: var(--wcc-loader-thickness) solid rgba(0, 0, 0, 0.1);
    border-top: var(--wcc-loader-thickness) solid var(--wcc-loader-color);
    border-radius: 50%;
    animation: wcc-spin 1s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

/* Animation de rotation */
@keyframes wcc-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loader pour boutons */
.wcc-button-loader {
    position: relative;
    pointer-events: none;
}

.wcc-button-loader .wcc-loader {
    width: 16px;
    height: 16px;
    border-width: 2px;
    margin-right: 6px;
}

/* Loader overlay plein écran */
.wcc-loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    backdrop-filter: blur(2px);
}

.wcc-loader-overlay .wcc-loader {
    width: 40px;
    height: 40px;
    border-width: 4px;
    margin-right: 0;
}

.wcc-loader-overlay .wcc-loader-text {
    margin-left: 15px;
    font-size: 16px;
    color: #333;
    font-weight: 500;
}

/* Loader spécialisés par type d'action */
.wcc-loader-cart {
    --wcc-loader-color: #e74c3c; /* Rouge pour panier */
}

.wcc-loader-checkout {
    --wcc-loader-color: #2ecc71; /* Vert pour checkout */
}

.wcc-loader-update {
    --wcc-loader-color: #f39c12; /* Orange pour mise à jour */
}

/* États des boutons avec loader */
.wcc-loading {
    opacity: 0.7;
    cursor: not-allowed !important;
    pointer-events: none;
}

.wcc-loading:hover {
    opacity: 0.7 !important;
}

/* Animation d'apparition du loader */
.wcc-loader-fade-in {
    animation: wcc-fadeIn 0.3s ease-in-out;
}

@keyframes wcc-fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* Responsiveness */
@media (max-width: 768px) {
    .wcc-loader-overlay .wcc-loader {
        width: 35px;
        height: 35px;
        border-width: 3px;
    }
    
    .wcc-loader-overlay .wcc-loader-text {
        font-size: 14px;
        margin-left: 12px;
    }
    
    .wcc-button-loader .wcc-loader {
        width: 14px;
        height: 14px;
        border-width: 2px;
        margin-right: 4px;
    }
}

@media (max-width: 480px) {
    .wcc-loader-overlay .wcc-loader {
        width: 30px;
        height: 30px;
        border-width: 3px;
    }
    
    .wcc-loader-overlay .wcc-loader-text {
        font-size: 13px;
        margin-left: 10px;
    }
}

/* Mode sombre */
@media (prefers-color-scheme: dark) {
    .wcc-loader-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .wcc-loader-overlay .wcc-loader-text {
        color: #fff;
    }
    
    .wcc-loader {
        border-color: rgba(255, 255, 255, 0.2);
        border-top-color: var(--wcc-loader-color);
    }
}

/* Animation pour mouvement réduit (accessibilité) */
@media (prefers-reduced-motion: reduce) {
    .wcc-loader {
        animation: none;
        border-top-color: var(--wcc-loader-color);
        opacity: 0.8;
    }
    
    .wcc-loader::after {
        content: '⏳';
        position: absolute;
        top: -2px;
        left: -2px;
        font-size: calc(var(--wcc-loader-size) * 0.8);
    }
}

/* Contraste élevé (accessibilité) */
@media (prefers-contrast: high) {
    .wcc-loader {
        border-color: transparent;
        border-top-color: var(--wcc-loader-color);
        border-width: calc(var(--wcc-loader-thickness) + 1px);
    }
    
    .wcc-loader-overlay {
        background: rgba(255, 255, 255, 0.95);
        border: 2px solid #000;
    }
}

/* Styles pour différentes tailles */
.wcc-loader-small {
    --wcc-loader-size: 16px;
    --wcc-loader-thickness: 2px;
}

.wcc-loader-medium {
    --wcc-loader-size: 24px;
    --wcc-loader-thickness: 3px;
}

.wcc-loader-large {
    --wcc-loader-size: 32px;
    --wcc-loader-thickness: 4px;
}

.wcc-loader-xlarge {
    --wcc-loader-size: 48px;
    --wcc-loader-thickness: 5px;
}

/* Integration avec les boutons existants */
.wcc-confirm-step.wcc-loading,
.wcc-cloned-add-to-cart.wcc-loading,
#wcc-direct-checkout-button.wcc-loading,
.wcc-cloned-direct-checkout.wcc-loading,
.wcc-modify-order-button.wcc-loading {
    position: relative;
}

.wcc-confirm-step.wcc-loading::before,
.wcc-cloned-add-to-cart.wcc-loading::before,
#wcc-direct-checkout-button.wcc-loading::before,
.wcc-cloned-direct-checkout.wcc-loading::before,
.wcc-modify-order-button.wcc-loading::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #fff;
    border-radius: 50%;
    animation: wcc-spin 1s linear infinite;
}

/* Style alternatif pour thèmes clairs */
.wcc-light-theme .wcc-confirm-step.wcc-loading::before,
.wcc-light-theme .wcc-cloned-add-to-cart.wcc-loading::before,
.wcc-light-theme #wcc-direct-checkout-button.wcc-loading::before,
.wcc-light-theme .wcc-cloned-direct-checkout.wcc-loading::before,
.wcc-light-theme .wcc-modify-order-button.wcc-loading::before {
    border-color: rgba(0, 0, 0, 0.2);
    border-top-color: var(--wcc-loader-color);
}

/* Messages de chargement contextuels */
.wcc-loader-message {
    display: none;
    font-size: 12px;
    color: #666;
    margin-top: 5px;
    text-align: center;
}

.wcc-loading + .wcc-loader-message {
    display: block;
}

/* Pulse animation pour feedback visuel */
@keyframes wcc-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.wcc-loading {
    animation: wcc-pulse 2s ease-in-out infinite;
}

/* Z-index management pour éviter les conflits */
.wcc-loader-overlay {
    z-index: 999999;
}

.wcc-loader-overlay.wcc-high-z {
    z-index: 9999999;
}

/* Support RTL */
[dir="rtl"] .wcc-button-loader .wcc-loader {
    margin-right: 0;
    margin-left: 6px;
}

[dir="rtl"] .wcc-loader-overlay .wcc-loader-text {
    margin-left: 0;
    margin-right: 15px;
}