/**
 * Animations - SIRH IPSCO
 * Animations fluides et loading states
 * Version: 1.0
 */

/* ========================================
   KEYFRAMES - ANIMATIONS DE BASE
   ======================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

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

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

@keyframes slideDown {
    from {
        max-height: 0;
        opacity: 0;
    }
    to {
        max-height: 500px;
        opacity: 1;
    }
}

/* ========================================
   CLASSES D'ANIMATION
   ======================================== */
.animate-fade-in {
    animation: fadeIn 0.5s ease-out;
}

.animate-fade-in-up {
    animation: fadeInUp 0.5s ease-out;
}

.animate-fade-in-down {
    animation: fadeInDown 0.5s ease-out;
}

.animate-slide-in-right {
    animation: slideInRight 0.5s ease-out;
}

.animate-slide-in-left {
    animation: slideInLeft 0.5s ease-out;
}

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

.animate-pulse {
    animation: pulse 2s infinite;
}

.animate-bounce {
    animation: bounce 1s infinite;
}

.animate-spin {
    animation: spin 1s linear infinite;
}

.animate-shake {
    animation: shake 0.5s;
}

/* ========================================
   ANIMATIONS D'ENTRÉE POUR CARDS
   ======================================== */
.card-enter {
    animation: fadeInUp 0.5s ease-out;
}

.card-enter:nth-child(1) { animation-delay: 0.05s; }
.card-enter:nth-child(2) { animation-delay: 0.1s; }
.card-enter:nth-child(3) { animation-delay: 0.15s; }
.card-enter:nth-child(4) { animation-delay: 0.2s; }
.card-enter:nth-child(5) { animation-delay: 0.25s; }
.card-enter:nth-child(6) { animation-delay: 0.3s; }

/* ========================================
   LOADING STATES - SPINNERS
   ======================================== */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color, #667eea);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

.spinner-sm {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.spinner-lg {
    width: 60px;
    height: 60px;
    border-width: 4px;
}

.spinner-primary {
    border-top-color: var(--primary-color, #667eea);
}

.spinner-success {
    border-top-color: var(--success-color, #28a745);
}

.spinner-danger {
    border-top-color: var(--danger-color, #dc3545);
}

.spinner-warning {
    border-top-color: var(--warning-color, #ffc107);
}

/* ========================================
   LOADING STATES - SKELETON
   ======================================== */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
    border-radius: 0.5rem;
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}

.skeleton-title {
    height: 1.5rem;
    width: 60%;
    margin-bottom: 1rem;
}

.skeleton-card {
    height: 150px;
    margin-bottom: 1rem;
}

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

/* ========================================
   LOADING OVERLAY
   ======================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s;
}

.loading-overlay-dark {
    background: rgba(0, 0, 0, 0.7);
}

.loading-content {
    text-align: center;
}

.loading-content .spinner {
    margin-bottom: 1rem;
}

.loading-text {
    color: #333;
    font-size: 1rem;
    font-weight: 500;
}

/* ========================================
   TRANSITIONS AMÉLIORÉES
   ======================================== */
.smooth-transition {
    transition: all 0.3s ease;
}

.smooth-transition:hover {
    transform: translateY(-2px);
}

.smooth-scale {
    transition: transform 0.3s ease;
}

.smooth-scale:hover {
    transform: scale(1.05);
}

.smooth-rotate {
    transition: transform 0.3s ease;
}

.smooth-rotate:hover {
    transform: rotate(5deg);
}

/* ========================================
   HOVER EFFECTS
   ======================================== */
.hover-lift {
    transition: all 0.3s ease;
}

.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.hover-grow {
    transition: transform 0.3s ease;
}

.hover-grow:hover {
    transform: scale(1.05);
}

.hover-shadow {
    transition: box-shadow 0.3s ease;
}

.hover-shadow:hover {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.hover-glow {
    transition: box-shadow 0.3s ease;
}

.hover-glow:hover {
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
}

/* ========================================
   ANIMATIONS POUR MODALS
   ======================================== */
.modal.fade .modal-dialog {
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.3s ease-out;
}

.modal.show .modal-dialog {
    transform: scale(1);
    opacity: 1;
}

/* ========================================
   ANIMATIONS POUR ALERTS
   ======================================== */
.alert-enter {
    animation: slideInRight 0.5s ease-out;
}

.alert-exit {
    animation: slideInLeft 0.5s ease-out reverse;
}

/* ========================================
   ANIMATIONS POUR DROPDOWNS
   ======================================== */
.dropdown-menu {
    animation: fadeInDown 0.3s ease-out;
}

/* ========================================
   ANIMATIONS POUR TOOLTIPS
   ======================================== */
.tooltip {
    animation: fadeIn 0.2s ease-out;
}

/* ========================================
   PROGRESS BAR ANIMATIONS
   ======================================== */
.progress-bar {
    transition: width 0.6s ease;
}

.progress-bar-animated {
    animation: shimmer 2s infinite;
}

/* ========================================
   BADGE ANIMATIONS
   ======================================== */
.badge-pulse {
    animation: pulse 2s infinite;
}

.badge-bounce {
    animation: bounce 1s infinite;
}

/* ========================================
   BUTTON LOADING STATE
   ======================================== */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #ffffff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn-loading.btn-outline-primary::after,
.btn-loading.btn-outline-secondary::after {
    border-color: currentColor;
    border-top-color: transparent;
}

/* ========================================
   SLIDE TOGGLE
   ======================================== */
.slide-toggle {
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.slide-toggle.collapsed {
    max-height: 0;
}

.slide-toggle.expanded {
    max-height: 1000px;
}

/* ========================================
   FADE TOGGLE
   ======================================== */
.fade-toggle {
    transition: opacity 0.3s ease;
}

.fade-toggle.hidden {
    opacity: 0;
    pointer-events: none;
}

.fade-toggle.visible {
    opacity: 1;
}

/* ========================================
   NOTIFICATION ANIMATIONS
   ======================================== */
.notification-enter {
    animation: slideInRight 0.5s ease-out;
}

.notification-exit {
    animation: slideInRight 0.5s ease-out reverse;
}

/* ========================================
   CARD FLIP ANIMATION
   ======================================== */
.card-flip {
    perspective: 1000px;
}

.card-flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.card-flip:hover .card-flip-inner {
    transform: rotateY(180deg);
}

.card-flip-front,
.card-flip-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
}

.card-flip-back {
    transform: rotateY(180deg);
}

/* ========================================
   SCROLL ANIMATIONS
   ======================================== */
.scroll-fade-in {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.scroll-fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   TYPING ANIMATION
   ======================================== */
@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink {
    50% { border-color: transparent; }
}

.typing-effect {
    overflow: hidden;
    border-right: 2px solid;
    white-space: nowrap;
    animation: typing 3s steps(40), blink 0.75s step-end infinite;
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */
/* Utiliser will-change pour les animations fréquentes */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Forcer l'accélération matérielle */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ========================================
   REDUCED MOTION
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
