/**
 * LOADING UX - Améliorations de l'expérience utilisateur au chargement
 * Squelettes, animations, états de chargement
 * @version 4.0.0
 */

/* ===========================
   LOADER PRINCIPAL
   =========================== */

.app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 50%, var(--color-primary-light) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 1;
    transition: opacity 0.3s ease-out, visibility 0.3s ease-out;
}

.app-loader.fade-out {
    opacity: 0;
    visibility: hidden;
}

.app-loader-content {
    text-align: center;
    color: var(--text-light);
}

@media (max-width: 992px) {
    .app-loader-content {
        width: 95%;
    }
}

.app-loader-logo {
    width: 350px;
    height: 350px;
    margin-bottom: var(--spacing-lg);
    animation: pulse 3s ease-in-out infinite;
    background-image: url('../images/mag-bastou-tiger-01.jpg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.app-loader-title {
    font-size: var(--font-size-3xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-sm);
    font-family: var(--font-family-secondary);
    color: var(--text-light);
}

.app-loader-subtitle {
    font-size: var(--font-size-lg);
    opacity: 0.9;
    margin-bottom: var(--spacing-xxl);
    color: var(--text-light);
}

.app-loader-progress {
    width: 240px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: var(--spacing-md);
    box-shadow: var(--shadow-sm);
}

.app-loader-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-secondary-light), var(--color-info-light));
    border-radius: var(--radius-sm);
    width: 0%;
    transition: width 0.3s ease-out;
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

.app-loader-status {
    font-size: var(--font-size-sm);
    opacity: 0.8;
    min-height: 1.2rem;
    color: var(--text-light);
    text-align: left;
    font-weight: var(--font-weight-medium);
}

@keyframes pulse {
    0%,
    100% {
        transform: scale(1) rotate(0deg);
        filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    }

    50% {
        transform: scale(1.1) rotate(5deg);
        filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
    }
}

/* ===========================
   SQUELETTES DE CHARGEMENT
   =========================== */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: var(--radius-md);
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Squelette carte du monde */
.world-map-skeleton {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    color: #1976d2;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: var(--radius-lg);
    min-height: 400px;
    position: relative;
    overflow: hidden;
}

.world-map-skeleton::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        left: -100%;
    }

    100% {
        left: 100%;
    }
}

/* Squelettes drapeaux */
.flags-skeleton {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 1rem;
}

.flag-skeleton {
    width: 60px;
    height: 80px;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    position: relative;
}

.flag-skeleton::after {
    content: '';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 8px;
    background: #d0d0d0;
    border-radius: 4px;
}

/* Squelettes voyages */
.voyages-skeleton {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.2rem;
    padding: 1rem 0;
}

.voyage-skeleton {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.voyage-skeleton-image {
    height: 110px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

.voyage-skeleton-content {
    padding: 0.7em 1em 0.9em 1em;
}

.voyage-skeleton-title {
    height: 20px;
    background: #e0e0e0;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    width: 80%;
}

.voyage-skeleton-meta {
    height: 14px;
    background: #f0f0f0;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    width: 60%;
}

.voyage-skeleton-description {
    height: 12px;
    background: #f0f0f0;
    border-radius: 4px;
    margin-bottom: 0.3rem;
    width: 100%;
}

.voyage-skeleton-description:last-child {
    width: 70%;
}

/* ===========================
   ÉTATS DE CHARGEMENT PROGRESSIF
   =========================== */

.progressive-load {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.progressive-load.loaded {
    opacity: 1;
    transform: translateY(0);
}

.progressive-load.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* Délais échelonnés pour l'animation */
.progressive-load:nth-child(1) {
    transition-delay: 0.1s;
}

.progressive-load:nth-child(2) {
    transition-delay: 0.2s;
}

.progressive-load:nth-child(3) {
    transition-delay: 0.3s;
}

.progressive-load:nth-child(4) {
    transition-delay: 0.4s;
}

.progressive-load:nth-child(5) {
    transition-delay: 0.5s;
}

/* ===========================
   INDICATEURS DE CHARGEMENT
   =========================== */

.loading-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e0e0e0;
    border-top: 2px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-dots {
    display: inline-flex;
    gap: 2px;
}

.loading-dots span {
    width: 4px;
    height: 4px;
    background: var(--color-primary);
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* ===========================
   OPTIMISATIONS IMAGES
   =========================== */

.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.lazy-image.loaded {
    opacity: 1;
}

.lazy-image.error {
    opacity: 0.5;
    filter: grayscale(100%);
}

/* Placeholder pour images en cours de chargement */
.image-placeholder {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 2rem;
    position: relative;
    overflow: hidden;
}

.image-placeholder::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 2s infinite;
}

/* ===========================
   FEEDBACK UTILISATEUR
   =========================== */

.loading-message {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease-out;
}

.loading-message.show {
    transform: translateY(0);
    opacity: 1;
}

.loading-message-icon {
    color: var(--color-primary);
    font-size: 1.2rem;
}

.loading-message-text {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* ===========================
   ÉTATS D'ERREUR
   =========================== */

.error-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.error-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.error-state-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.error-state-message {
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.error-state-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===========================
   RESPONSIVE
   =========================== */

@media (max-width: 768px) {
    .app-loader-logo {
        width: 60px;
        height: 60px;
        margin-bottom: var(--spacing-md);
    }

    .app-loader-title {
        font-size: var(--font-size-2xl);
    }

    .app-loader-subtitle {
        font-size: var(--font-size-base);
    }

    .app-loader-progress {
        width: 180px;
        height: 5px;
    }

    .voyages-skeleton {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .flags-skeleton {
        gap: 0.5rem;
    }

    .flag-skeleton {
        width: 50px;
        height: 70px;
    }

    .loading-message {
        bottom: 10px;
        right: 10px;
        left: 10px;
        padding: 0.75rem 1rem;
    }
}

@media (max-width: 480px) {
    .app-loader-logo {
        width: 230px;
        height: 230px;
        margin-bottom: var(--spacing-sm);
        text-align: center;
    }

    .app-loader-title {
        font-size: var(--font-size-xl);
    }

    .app-loader-subtitle {
        font-size: var(--font-size-sm);
        margin-bottom: var(--spacing-xl);
    }

    .app-loader-progress {

        .error-state {
            padding: 1rem;
        }

        .error-state-actions {
            flex-direction: column;
            align-items: center;
        }
    }

    /* ===========================
   PRÉFÉRENCES UTILISATEUR
   =========================== */

    @media (prefers-reduced-motion: reduce) {

        .skeleton,
        .loading-spinner,
        .loading-dots span,
        .progressive-load,
        .world-map-skeleton::before,
        .image-placeholder::before {
            animation: none !important;
        }

        .app-loader {
            transition: none !important;
        }

        .progressive-load {
            transition: opacity 0.1s ease-out !important;
            transform: none !important;
        }
    }

    /* ===========================
   DARK MODE SUPPORT
   =========================== */

    @media (prefers-color-scheme: dark) {

        .skeleton,
        .voyage-skeleton-title,
        .voyage-skeleton-meta,
        .voyage-skeleton-description {
            background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
            background-size: 200% 100%;
        }

        .flag-skeleton {
            background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
            background-size: 200% 100%;
        }

        .flag-skeleton::after {
            background: #4a4a4a;
        }

        .world-map-skeleton {
            background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
            color: #60a5fa;
        }

        .loading-message {
            background: #1f2937;
            color: #f9fafb;
        }

        .error-state-title {
            color: #f9fafb;
        }
    }