/* ========================================
   ANIMATIONS LIBRARY v1.0 - Phase 5
   Performance-optimized Animations
   ======================================== */

/* =====================
   1. FADE ANIMATIONS
   ===================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 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 fadeInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Animation Classes */
.animate-fadeIn { animation: fadeIn var(--duration-300) var(--ease-out) forwards; }
.animate-fadeOut { animation: fadeOut var(--duration-300) var(--ease-out) forwards; }
.animate-fadeInUp { animation: fadeInUp var(--duration-300) var(--ease-out) forwards; }
.animate-fadeInDown { animation: fadeInDown var(--duration-300) var(--ease-out) forwards; }
.animate-fadeInLeft { animation: fadeInLeft var(--duration-300) var(--ease-out) forwards; }
.animate-fadeInRight { animation: fadeInRight var(--duration-300) var(--ease-out) forwards; }

/* =====================
   2. SCALE ANIMATIONS
   ===================== */

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    14% { transform: scale(1.3); }
    28% { transform: scale(1); }
    42% { transform: scale(1.3); }
    70% { transform: scale(1); }
}

.animate-scaleIn { animation: scaleIn var(--duration-300) var(--ease-out) forwards; }
.animate-scaleOut { animation: scaleOut var(--duration-300) var(--ease-out) forwards; }
.animate-pulse { animation: pulse 2s var(--ease-in-out) infinite; }
.animate-heartbeat { animation: heartbeat 1.5s var(--ease-in-out) infinite; }

/* =====================
   3. SLIDE ANIMATIONS
   ===================== */

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.animate-slideInUp { animation: slideInUp var(--duration-300) var(--ease-out) forwards; }
.animate-slideInDown { animation: slideInDown var(--duration-300) var(--ease-out) forwards; }
.animate-slideInLeft { animation: slideInLeft var(--duration-300) var(--ease-out) forwards; }
.animate-slideInRight { animation: slideInRight var(--duration-300) var(--ease-out) forwards; }

/* =====================
   4. ROTATE ANIMATIONS
   ===================== */

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes spinReverse {
    from { transform: rotate(360deg); }
    to { transform: rotate(0deg); }
}

.animate-spin { animation: spin 1s linear infinite; }
.animate-spin-slow { animation: spin 2s linear infinite; }
.animate-spin-reverse { animation: spinReverse 1s linear infinite; }

/* =====================
   5. BOUNCE ANIMATIONS
   ===================== */

@keyframes bounce {
    0%, 20%, 53%, 100% {
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
        transform: translateY(0);
    }
    40%, 43% {
        animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
        transform: translateY(-15px);
    }
    70% {
        animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
        transform: translateY(-7px);
    }
    90% {
        transform: translateY(-2px);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

.animate-bounce { animation: bounce 1s ease infinite; }
.animate-bounceIn { animation: bounceIn var(--duration-500) var(--ease-bounce) forwards; }

/* =====================
   6. SHAKE ANIMATIONS
   ===================== */

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

.animate-shake { animation: shake 0.5s ease; }
.animate-wiggle { animation: wiggle 0.5s ease; }

/* =====================
   7. ATTENTION SEEKERS
   ===================== */

@keyframes flash {
    0%, 50%, 100% { opacity: 1; }
    25%, 75% { opacity: 0; }
}

@keyframes rubberBand {
    0% { transform: scale(1); }
    30% { transform: scaleX(1.25) scaleY(0.75); }
    40% { transform: scaleX(0.75) scaleY(1.25); }
    50% { transform: scaleX(1.15) scaleY(0.85); }
    65% { transform: scaleX(0.95) scaleY(1.05); }
    75% { transform: scaleX(1.05) scaleY(0.95); }
    100% { transform: scale(1); }
}

@keyframes jello {
    0%, 11.1%, 100% { transform: none; }
    22.2% { transform: skewX(-12.5deg) skewY(-12.5deg); }
    33.3% { transform: skewX(6.25deg) skewY(6.25deg); }
    44.4% { transform: skewX(-3.125deg) skewY(-3.125deg); }
    55.5% { transform: skewX(1.5625deg) skewY(1.5625deg); }
    66.6% { transform: skewX(-0.78125deg) skewY(-0.78125deg); }
    77.7% { transform: skewX(0.390625deg) skewY(0.390625deg); }
    88.8% { transform: skewX(-0.1953125deg) skewY(-0.1953125deg); }
}

.animate-flash { animation: flash 1s ease infinite; }
.animate-rubberBand { animation: rubberBand 0.8s ease; }
.animate-jello { animation: jello 1s ease; }

/* =====================
   8. GLOW ANIMATIONS
   ===================== */

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px rgba(99, 102, 241, 0.5),
                    0 0 10px rgba(99, 102, 241, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(99, 102, 241, 0.8),
                    0 0 30px rgba(99, 102, 241, 0.5);
    }
}

@keyframes glowSuccess {
    0%, 100% {
        box-shadow: 0 0 5px rgba(16, 185, 129, 0.5),
                    0 0 10px rgba(16, 185, 129, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.8),
                    0 0 30px rgba(16, 185, 129, 0.5);
    }
}

@keyframes glowDanger {
    0%, 100% {
        box-shadow: 0 0 5px rgba(239, 68, 68, 0.5),
                    0 0 10px rgba(239, 68, 68, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.8),
                    0 0 30px rgba(239, 68, 68, 0.5);
    }
}

.animate-glow { animation: glow 2s ease-in-out infinite; }
.animate-glow-success { animation: glowSuccess 2s ease-in-out infinite; }
.animate-glow-danger { animation: glowDanger 2s ease-in-out infinite; }

/* =====================
   9. LOADING ANIMATIONS
   ===================== */

@keyframes dotPulse {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.loading-dots {
    display: inline-flex;
    gap: var(--space-1);
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary-500);
    animation: dotPulse 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; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

/* Spinner */
.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--color-primary-500);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.loading-spinner.lg {
    width: 48px;
    height: 48px;
    border-width: 4px;
}

/* =====================
   10. SCROLL ANIMATIONS
   ===================== */

/* Intersection Observer based */
.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: all var(--duration-500) var(--ease-out);
}

.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

.reveal-left {
    opacity: 0;
    transform: translateX(-30px);
    transition: all var(--duration-500) var(--ease-out);
}

.reveal-left.active {
    opacity: 1;
    transform: translateX(0);
}

.reveal-right {
    opacity: 0;
    transform: translateX(30px);
    transition: all var(--duration-500) var(--ease-out);
}

.reveal-right.active {
    opacity: 1;
    transform: translateX(0);
}

.reveal-scale {
    opacity: 0;
    transform: scale(0.9);
    transition: all var(--duration-500) var(--ease-out);
}

.reveal-scale.active {
    opacity: 1;
    transform: scale(1);
}

/* Stagger children */
.stagger-children > * {
    opacity: 0;
    transform: translateY(20px);
    transition: all var(--duration-300) var(--ease-out);
}

.stagger-children.active > *:nth-child(1) { transition-delay: 0ms; opacity: 1; transform: translateY(0); }
.stagger-children.active > *:nth-child(2) { transition-delay: 50ms; opacity: 1; transform: translateY(0); }
.stagger-children.active > *:nth-child(3) { transition-delay: 100ms; opacity: 1; transform: translateY(0); }
.stagger-children.active > *:nth-child(4) { transition-delay: 150ms; opacity: 1; transform: translateY(0); }
.stagger-children.active > *:nth-child(5) { transition-delay: 200ms; opacity: 1; transform: translateY(0); }
.stagger-children.active > *:nth-child(6) { transition-delay: 250ms; opacity: 1; transform: translateY(0); }
.stagger-children.active > *:nth-child(7) { transition-delay: 300ms; opacity: 1; transform: translateY(0); }
.stagger-children.active > *:nth-child(8) { transition-delay: 350ms; opacity: 1; transform: translateY(0); }

/* =====================
   11. HOVER EFFECTS
   ===================== */

.hover-lift {
    transition: transform var(--duration-200) var(--ease-out);
}

.hover-lift:hover {
    transform: translateY(-4px);
}

.hover-scale {
    transition: transform var(--duration-200) var(--ease-out);
}

.hover-scale:hover {
    transform: scale(1.02);
}

.hover-glow {
    transition: box-shadow var(--duration-300) var(--ease-out);
}

.hover-glow:hover {
    box-shadow: var(--shadow-primary);
}

.hover-border {
    transition: border-color var(--duration-200) var(--ease-out);
}

.hover-border:hover {
    border-color: var(--color-primary-500);
}

/* =====================
   12. MOTION PREFERENCES
   ===================== */

@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;
    }
    
    .reveal,
    .reveal-left,
    .reveal-right,
    .reveal-scale {
        opacity: 1;
        transform: none;
    }
}

/* =====================
   13. NUMBER COUNTER
   ===================== */

@keyframes countUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.counter {
    display: inline-block;
    animation: countUp var(--duration-500) var(--ease-out) forwards;
}

/* =====================
   14. TYPING ANIMATION
   ===================== */

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: var(--color-primary-500); }
}

.typing-effect {
    overflow: hidden;
    border-right: 2px solid var(--color-primary-500);
    white-space: nowrap;
    animation: 
        typing 3.5s steps(40, end),
        blink-caret 0.75s step-end infinite;
}

/* =====================
   15. GRADIENT ANIMATION
   ===================== */

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.animate-gradient {
    background: linear-gradient(-45deg, 
        var(--color-primary-500), 
        var(--color-secondary-500), 
        var(--color-success-500), 
        var(--color-warning-500)
    );
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
}

.animate-gradient-text {
    background: linear-gradient(-45deg, 
        var(--color-primary-500), 
        var(--color-secondary-500), 
        var(--color-primary-500)
    );
    background-size: 200% 200%;
    animation: gradientShift 3s ease infinite;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
