/* ============================================
   WREN DESIGN SYSTEM - ANIMATIONS
   Unified animation system using design tokens
   ============================================ */

/* ========================================
   KEYFRAMES - Core Animations
   ======================================== */

/* 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(var(--space-4));
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(calc(-1 * var(--space-4)));
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scale animations */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

/* Slide animations */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

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

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Pulse animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

/* Shake animation (for errors) */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* Bounce animation */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
        animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    50% {
        transform: translateY(-10px);
        animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
    }
}

/* Skeleton loading */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Focus ring pulse */
@keyframes focusPulse {
    0% { box-shadow: 0 0 0 0 var(--wren-terracotta-light); }
    50% { box-shadow: 0 0 0 4px var(--wren-terracotta-light); }
    100% { box-shadow: 0 0 0 0 var(--wren-terracotta-light); }
}

/* ========================================
   ANIMATION CLASSES
   ======================================== */

/* Duration */
.animate-fast { animation-duration: var(--transition-fast); }
.animate-normal { animation-duration: var(--transition); }
.animate-slow { animation-duration: var(--transition-slow); }

/* Timing functions */
.animate-ease { animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); }
.animate-bounce { animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); }
.animate-modal { animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); }

/* Fill mode */
.animate-forwards { animation-fill-mode: forwards; }
.animate-both { animation-fill-mode: both; }

/* Delay */
.animate-delay-100 { animation-delay: 100ms; }
.animate-delay-200 { animation-delay: 200ms; }
.animate-delay-300 { animation-delay: 300ms; }
.animate-delay-500 { animation-delay: 500ms; }

/* Fade */
.animate-fade-in {
    animation: fadeIn var(--transition) ease both;
}

.animate-fade-in-up {
    animation: fadeInUp var(--transition-slow) cubic-bezier(0.16, 1, 0.3, 1) both;
}

.animate-fade-in-down {
    animation: fadeInDown var(--transition-slow) cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Scale */
.animate-scale-in {
    animation: scaleIn var(--transition-modal) cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Slide */
.animate-slide-in-right {
    animation: slideInRight var(--transition-slow) cubic-bezier(0.16, 1, 0.3, 1) both;
}

.animate-slide-in-left {
    animation: slideInLeft var(--transition-slow) cubic-bezier(0.16, 1, 0.3, 1) both;
}

.animate-slide-in-up {
    animation: slideInUp var(--transition-modal) cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Continuous animations */
.animate-spin {
    animation: spin 1s linear infinite;
}

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

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

/* Error shake */
.animate-shake {
    animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--gray-200) 25%,
        var(--gray-100) 50%,
        var(--gray-200) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius);
}

.skeleton-text {
    height: 1em;
    margin-bottom: var(--space-2);
}

.skeleton-heading {
    height: 1.5em;
    width: 60%;
    margin-bottom: var(--space-3);
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
}

.skeleton-button {
    height: var(--input-height);
    width: 100px;
    border-radius: var(--radius-lg);
}

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

.stagger-children > * {
    animation: fadeInUp var(--transition-slow) cubic-bezier(0.16, 1, 0.3, 1) both;
}

.stagger-children > *:nth-child(1) { animation-delay: 0ms; }
.stagger-children > *:nth-child(2) { animation-delay: 50ms; }
.stagger-children > *:nth-child(3) { animation-delay: 100ms; }
.stagger-children > *:nth-child(4) { animation-delay: 150ms; }
.stagger-children > *:nth-child(5) { animation-delay: 200ms; }
.stagger-children > *:nth-child(6) { animation-delay: 250ms; }
.stagger-children > *:nth-child(7) { animation-delay: 300ms; }
.stagger-children > *:nth-child(8) { animation-delay: 350ms; }
.stagger-children > *:nth-child(9) { animation-delay: 400ms; }
.stagger-children > *:nth-child(10) { animation-delay: 450ms; }

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

.hover-lift {
    transition: transform var(--transition), box-shadow var(--transition);
}

.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.hover-scale {
    transition: transform var(--transition);
}

.hover-scale:hover {
    transform: scale(1.02);
}

.hover-glow {
    transition: box-shadow var(--transition);
}

.hover-glow:hover {
    box-shadow: 0 0 20px var(--wren-terracotta-light);
}

/* ========================================
   REDUCED MOTION
   ======================================== */

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

    .animate-spin {
        animation: none;
    }

    .animate-pulse {
        animation: none;
    }

    .animate-bounce {
        animation: none;
    }

    .skeleton {
        animation: none;
        background: var(--gray-200);
    }
}
