/**
 * Styles d'optimisation des performances
 * Animations, transitions et optimisations visuelles
 */

/* ============================================
   OPTIMISATIONS GÉNÉRALES
   ============================================ */

/* Utiliser contain pour isoler les rendus */
.card,
.modal,
.dropdown-menu {
    contain: layout style paint;
}

/* Optimiser les animations avec will-change */
.animated,
.transition,
[data-aos] {
    will-change: transform, opacity;
}

/* Réinitialiser will-change après l'animation */
.animated.done,
.transition.done {
    will-change: auto;
}

/* ============================================
   LAZY LOADING - ÉTATS
   ============================================ */

/* Image en cours de chargement */
img[data-src],
img[loading="lazy"]:not(.loaded) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    min-height: 100px;
}

/* Animation de shimmer pour le skeleton */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Image chargée */
img.loaded {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Image en erreur */
img.error {
    background: #f8d7da;
    border: 2px dashed #dc3545;
    position: relative;
}

img.error::after {
    content: '⚠️ Erreur de chargement';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #dc3545;
    font-size: 12px;
    white-space: nowrap;
}

/* ============================================
   SKELETON LOADERS
   ============================================ */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: 4px;
}

.skeleton-text:last-child {
    width: 80%;
}

.skeleton-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
}

.skeleton-card {
    height: 200px;
    border-radius: 8px;
}

/* ============================================
   OPTIMISATION DES FONTS
   ============================================ */

/* Font display swap pour éviter le FOIT */
@font-face {
    font-display: swap;
}

/* Optimiser le rendu du texte */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ============================================
   OPTIMISATION DES IMAGES
   ============================================ */

/* Aspect ratio pour éviter les layout shifts */
.img-container {
    position: relative;
    overflow: hidden;
}

.img-container::before {
    content: '';
    display: block;
    padding-top: 56.25%; /* 16:9 par défaut */
}

.img-container.ratio-1-1::before {
    padding-top: 100%; /* 1:1 */
}

.img-container.ratio-4-3::before {
    padding-top: 75%; /* 4:3 */
}

.img-container.ratio-21-9::before {
    padding-top: 42.857%; /* 21:9 */
}

.img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ============================================
   OPTIMISATION DES ANIMATIONS
   ============================================ */

/* Réduire les animations pour les préférences utilisateur */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Utiliser transform au lieu de position pour les animations */
.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

.scale-in {
    animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   OPTIMISATION DES MODALS
   ============================================ */

/* Backdrop avec backdrop-filter (GPU accelerated) */
.modal-backdrop {
    backdrop-filter: blur(5px);
    will-change: opacity;
}

/* Modal avec transform pour GPU acceleration */
.modal {
    transform: translateZ(0);
    will-change: transform, opacity;
}

/* ============================================
   OPTIMISATION DES SCROLLS
   ============================================ */

/* Smooth scroll natif */
html {
    scroll-behavior: smooth;
}

/* Optimiser le scroll sur mobile */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
}

/* ============================================
   MODE CONNEXION LENTE
   ============================================ */

/* Styles pour connexion lente */
body.slow-connection img[data-src] {
    background: #f5f5f5;
}

body.slow-connection video {
    display: none;
}

body.slow-connection .heavy-content {
    display: none;
}

body.slow-connection .light-content {
    display: block;
}

/* ============================================
   OPTIMISATION DES CARTES
   ============================================ */

/* Éviter les repaints lors du hover */
.card {
    transform: translateZ(0);
    backface-visibility: hidden;
}

.card:hover {
    transform: translateY(-5px) translateZ(0);
    transition: transform 0.3s ease;
}

/* ============================================
   OPTIMISATION DES LISTES
   ============================================ */

/* Virtualisation des longues listes */
.virtual-list {
    overflow-y: auto;
    contain: strict;
}

.virtual-list-item {
    contain: layout style paint;
}

/* ============================================
   OPTIMISATION DES FORMULAIRES
   ============================================ */

/* Éviter les reflows lors de la validation */
.form-control {
    contain: layout style;
}

/* ============================================
   OPTIMISATION DES TABLEAUX
   ============================================ */

/* Optimiser le rendu des grands tableaux */
.table {
    contain: layout style;
}

.table tbody {
    contain: layout style paint;
}

/* ============================================
   LOADING STATES
   ============================================ */

/* Spinner optimisé avec CSS */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: #009EF7;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    will-change: transform;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

/* ============================================
   OPTIMISATION DES TRANSITIONS
   ============================================ */

/* Transitions GPU accelerated */
.smooth-transition {
    transition: transform 0.3s ease, opacity 0.3s ease;
    will-change: transform, opacity;
}

/* ============================================
   OPTIMISATION DES OMBRES
   ============================================ */

/* Utiliser box-shadow avec parcimonie */
.shadow-optimized {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Éviter les ombres multiples */
.shadow-optimized:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.3s ease;
}

/* ============================================
   PRINT OPTIMIZATIONS
   ============================================ */

@media print {
    /* Masquer les éléments non nécessaires à l'impression */
    .no-print,
    nav,
    footer,
    .sidebar,
    .modal,
    .tooltip {
        display: none !important;
    }

    /* Optimiser les couleurs pour l'impression */
    * {
        color: #000 !important;
        background: #fff !important;
    }

    /* Éviter les sauts de page dans les éléments */
    .card,
    .table,
    .section {
        page-break-inside: avoid;
    }
}

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

/* Optimiser pour mobile */
@media (max-width: 768px) {
    /* Réduire les animations sur mobile */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }

    /* Simplifier les ombres */
    .shadow,
    .shadow-sm,
    .shadow-lg {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
    }

    /* Désactiver les effets de hover sur mobile */
    .card:hover,
    .btn:hover {
        transform: none !important;
    }
}

/* ============================================
   DARK MODE OPTIMIZATIONS
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Optimiser les couleurs pour le dark mode */
    img[data-src],
    img[loading="lazy"]:not(.loaded) {
        background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 50%, #2a2a2a 75%);
    }

    .skeleton {
        background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 50%, #2a2a2a 75%);
    }
}

/* ============================================
   ACCESSIBILITY OPTIMIZATIONS
   ============================================ */

/* Focus visible pour l'accessibilité */
:focus-visible {
    outline: 2px solid #009EF7;
    outline-offset: 2px;
}

/* Améliorer la lisibilité */
.readable {
    max-width: 65ch;
    line-height: 1.6;
}

/* ============================================
   CRITICAL CSS INLINE
   ============================================ */

/* Styles critiques pour le above-the-fold */
.hero,
.header,
.nav {
    contain: layout style;
}

