/* ================================
   SYSTÈME DE CHARGEMENT MODERNE
   ================================ */

/* Variables CSS pour le système de chargement */
:root {
    --loading-primary: #60a5fa;
    --loading-secondary: #e2e8f0;
    --loading-skeleton-base: #f1f5f9;
    --loading-skeleton-highlight: #e2e8f0;
    --loading-animation-duration: 1.5s;
    --loading-border-radius: 0.375rem;
}

/* ================================
   ÉTATS DE CHARGEMENT GLOBAUX
   ================================ */

/* État initial - contenu visible mais avec overlay de chargement */
.app-loading {
    position: relative;
}

.app-loading .app-content {
    filter: blur(2px);
    opacity: 0.3;
    transition: all 0.3s ease;
}

.app-loaded .app-content {
    filter: none;
    opacity: 1;
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================================
   SKELETON LOADER OVERLAY
   ================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    z-index: 999999; /* ✅ Z-index élevé pour être au-dessus de tout */
    display: flex;
    flex-direction: column;
    opacity: 1;
    visibility: visible;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ✅ Skeleton rapide pour éviter le FOUC initial */
.quick-skeleton {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%) !important;
}

.loading-overlay.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* ================================
   HEADER SKELETON
   ================================ */

.skeleton-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--loading-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 10000;
}

.skeleton-logo {
    width: 150px;
    height: 32px;
    background: var(--loading-skeleton-base);
    border-radius: var(--loading-border-radius);
    animation: skeleton-pulse var(--loading-animation-duration) ease-in-out infinite;
}

.skeleton-nav {
    display: flex;
    gap: 1.5rem;
}

.skeleton-nav-item {
    width: 80px;
    height: 20px;
    background: var(--loading-skeleton-base);
    border-radius: var(--loading-border-radius);
    animation: skeleton-pulse var(--loading-animation-duration) ease-in-out infinite;
}

.skeleton-nav-item:nth-child(2) {
    animation-delay: 0.2s;
}

.skeleton-nav-item:nth-child(3) {
    animation-delay: 0.4s;
}

/* ================================
   CONTENT SKELETON
   ================================ */

.skeleton-content {
    flex: 1;
    padding: 90px 2rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Hero section skeleton */
.skeleton-hero {
    text-align: center;
    margin-bottom: 4rem;
}

.skeleton-title {
    width: 60%;
    height: 48px;
    background: var(--loading-skeleton-base);
    border-radius: var(--loading-border-radius);
    margin: 0 auto 1.5rem;
    animation: skeleton-pulse var(--loading-animation-duration) ease-in-out infinite;
}

.skeleton-subtitle {
    width: 80%;
    height: 20px;
    background: var(--loading-skeleton-base);
    border-radius: var(--loading-border-radius);
    margin: 0 auto 0.75rem;
    animation: skeleton-pulse var(--loading-animation-duration) ease-in-out infinite;
    animation-delay: 0.2s;
}

.skeleton-subtitle:last-child {
    width: 65%;
    animation-delay: 0.4s;
}

/* Cards grid skeleton */
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 3rem;
}

.skeleton-card {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--loading-secondary);
}

.skeleton-card-icon {
    width: 48px;
    height: 48px;
    background: var(--loading-skeleton-base);
    border-radius: 50%;
    margin-bottom: 1rem;
    animation: skeleton-pulse var(--loading-animation-duration) ease-in-out infinite;
}

.skeleton-card-title {
    width: 70%;
    height: 24px;
    background: var(--loading-skeleton-base);
    border-radius: var(--loading-border-radius);
    margin-bottom: 1rem;
    animation: skeleton-pulse var(--loading-animation-duration) ease-in-out infinite;
    animation-delay: 0.3s;
}

.skeleton-card-text {
    width: 100%;
    height: 16px;
    background: var(--loading-skeleton-base);
    border-radius: var(--loading-border-radius);
    margin-bottom: 0.5rem;
    animation: skeleton-pulse var(--loading-animation-duration) ease-in-out infinite;
    animation-delay: 0.5s;
}

.skeleton-card-text:last-child {
    width: 85%;
    animation-delay: 0.7s;
}

/* ================================
   LOADING INDICATOR
   ================================ */

.loading-indicator {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #64748b;
    font-size: 0.875rem;
    font-weight: 500;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--loading-secondary);
    border-top: 2px solid var(--loading-primary);
    border-radius: 50%;
    animation: loading-spin 1s linear infinite;
}

/* ================================
   ANIMATIONS
   ================================ */

@keyframes skeleton-pulse {
    0%, 100% {
        background-color: var(--loading-skeleton-base);
    }
    50% {
        background-color: var(--loading-skeleton-highlight);
    }
}

@keyframes loading-spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Animation d'apparition progressive des éléments */
.skeleton-card:nth-child(1) { animation-delay: 0.1s; }
.skeleton-card:nth-child(2) { animation-delay: 0.2s; }
.skeleton-card:nth-child(3) { animation-delay: 0.3s; }
.skeleton-card:nth-child(4) { animation-delay: 0.4s; }
.skeleton-card:nth-child(5) { animation-delay: 0.5s; }
.skeleton-card:nth-child(6) { animation-delay: 0.6s; }

/* ================================
   RESPONSIVE
   ================================ */

@media (max-width: 768px) {
    .skeleton-header {
        padding: 0 1rem;
    }
    
    .skeleton-nav {
        display: none;
    }
    
    .skeleton-content {
        padding: 90px 1rem 2rem;
    }
    
    .skeleton-title {
        width: 90%;
        height: 36px;
    }
    
    .skeleton-subtitle {
        width: 95%;
    }
    
    .skeleton-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .skeleton-card {
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .skeleton-header {
        height: 60px;
    }
    
    .skeleton-content {
        padding: 80px 0.5rem 2rem;
    }
    
    .skeleton-logo {
        width: 120px;
        height: 28px;
    }
}

/* ================================
   THEME SOMBRE (optionnel)
   ================================ */

@media (prefers-color-scheme: dark) {
    :root {
        --loading-skeleton-base: #1e293b;
        --loading-skeleton-highlight: #334155;
        --loading-secondary: #334155;
    }
    
    .loading-overlay {
        background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    }
    
    .skeleton-header {
        background: rgba(15, 23, 42, 0.95);
        border-bottom: 1px solid var(--loading-secondary);
    }
    
    .skeleton-card {
        background: #1e293b;
        border: 1px solid var(--loading-secondary);
    }
    
    .loading-indicator {
        color: #94a3b8;
    }
}

/* ================================
   ACCESSIBILITÉ
   ================================ */

@media (prefers-reduced-motion: reduce) {
    .skeleton-pulse,
    .loading-spinner,
    .loading-overlay,
    .app-content {
        animation: none !important;
        transition: none !important;
    }
    
    .loading-overlay.fade-out {
        display: none;
    }
}

/* ================================
   FALLBACK SANS JAVASCRIPT
   ================================ */

.no-js .loading-overlay {
    display: none;
}

.no-js .app-content {
    filter: none !important;
    opacity: 1 !important;
}

/* ================================
   GESTION HEADER ET TEMPLATES
   ================================ */

/* ✅ Header en cours de chargement */
#header-placeholder.template-loading {
    min-height: 80px;
    background: linear-gradient(90deg, 
        rgba(255,255,255,0.8) 25%, 
        rgba(240,240,240,0.8) 50%, 
        rgba(255,255,255,0.8) 75%);
    backdrop-filter: blur(2px);
    z-index: 1000;
}

/* ✅ Header chargé - apparition correcte */
#header-placeholder.template-loaded {
    z-index: 1000;
    opacity: 1;
    visibility: visible;
}

/* ✅ Header global - toujours visible */
.global-header {
    position: sticky !important; /* Garder sticky pour le comportement normal */
    top: 0 !important;
    z-index: 1100 !important; /* Z-index élevé pour être au-dessus du carousel */
    opacity: 1 !important;
    visibility: visible !important;
}

/* ✅ Quand l'app est chargée, s'assurer que le header reste visible */
.app-loaded .global-header {
    z-index: 1000 !important;
    position: relative !important;
}

/* ✅ Footer et feedback */
#footer-placeholder.template-loading {
    min-height: 120px;
}

#feedback-placeholder.template-loading {
    min-height: 40px;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    border-radius: 50%;
}

/* ✅ États d'erreur pour les templates */
.template-error {
    opacity: 0.7;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 4px;
    padding: 8px;
    color: #dc2626;
    font-size: 0.875rem;
    text-align: center;
}

.template-error:before {
    content: "⚠️ Erreur de chargement du template";
} 