/* ========================================================================== 
   ADVANCED ANIMATION SYSTEM
   Smooth animations, micro-interactions, and delightful user experiences
   ========================================================================== */

/* ============== ANIMATION VARIABLES ============== */

:root {
    /* Animation Durations */
    --duration-instant: 0ms;
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 350ms;
    --duration-slower: 500ms;
    --duration-slowest: 750ms;
    
    /* Easing Functions */
    --ease-linear: linear;
    --ease-in: cubic-bezier(0.4, 0, 1, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --ease-elastic: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-back: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --ease-anticipate: cubic-bezier(0.25, 0.1, 0.25, 1);
    
    /* Spring Physics */
    --spring-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --spring-gentle: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --spring-wobbly: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    
    /* Animation Delays for Staggering */
    --stagger-1: 0ms;
    --stagger-2: 50ms;
    --stagger-3: 100ms;
    --stagger-4: 150ms;
    --stagger-5: 200ms;
    --stagger-6: 250ms;
    --stagger-7: 300ms;
    --stagger-8: 350ms;
}

/* ============== CORE KEYFRAMES ============== */

/* 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);
    }
}

/* Scale Animations */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
    }
    to {
        transform: scale(1);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.1);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Slide Animations */
@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);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Rotation Animations */
@keyframes rotateIn {
    from {
        opacity: 0;
        transform: rotate(-180deg);
    }
    to {
        opacity: 1;
        transform: rotate(0);
    }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    14% { transform: scale(1.3); }
    28% { transform: scale(1); }
    42% { transform: scale(1.3); }
    70% { transform: scale(1); }
}

/* Bounce Animations */
@keyframes bounce {
    0%, 20%, 53%, 80%, 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(-30px);
    }
    70% {
        animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
        transform: translateY(-15px);
    }
    90% {
        transform: translateY(-4px);
    }
}

@keyframes rubber {
    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); }
}

/* Shake and Wobble */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

@keyframes wobble {
    0% { transform: translateX(0%); }
    15% { transform: translateX(-25%) rotate(-5deg); }
    30% { transform: translateX(20%) rotate(3deg); }
    45% { transform: translateX(-15%) rotate(-3deg); }
    60% { transform: translateX(10%) rotate(2deg); }
    75% { transform: translateX(-5%) rotate(-1deg); }
    100% { transform: translateX(0%); }
}

/* Attention Seekers */
@keyframes flash {
    0%, 50%, 100% { opacity: 1; }
    25%, 75% { opacity: 0; }
}

@keyframes swing {
    20% { transform: rotate(15deg); }
    40% { transform: rotate(-10deg); }
    60% { transform: rotate(5deg); }
    80% { transform: rotate(-5deg); }
    100% { transform: rotate(0deg); }
}

/* Loading Animations */
@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

@keyframes skeleton {
    0% { opacity: 1; }
    50% { opacity: 0.4; }
    100% { opacity: 1; }
}

@keyframes dots {
    0%, 20% { color: transparent; text-shadow: 0.25em 0 0 transparent, 0.5em 0 0 transparent; }
    40% { color: currentColor; text-shadow: 0.25em 0 0 transparent, 0.5em 0 0 transparent; }
    60% { text-shadow: 0.25em 0 0 currentColor, 0.5em 0 0 transparent; }
    80%, 100% { text-shadow: 0.25em 0 0 currentColor, 0.5em 0 0 currentColor; }
}

/* Progress Animations */
@keyframes progress {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes indeterminate {
    0% { transform: translateX(-100%) scaleX(1); }
    50% { transform: translateX(0%) scaleX(0.3); }
    100% { transform: translateX(100%) scaleX(1); }
}

/* ============== ANIMATION UTILITY CLASSES ============== */

/* Fade Animations */
.animate-fade-in { animation: fadeIn var(--duration-normal) var(--ease-out) both; }
.animate-fade-out { animation: fadeOut var(--duration-normal) var(--ease-in) both; }
.animate-fade-in-up { animation: fadeInUp var(--duration-normal) var(--ease-out) both; }
.animate-fade-in-down { animation: fadeInDown var(--duration-normal) var(--ease-out) both; }
.animate-fade-in-left { animation: fadeInLeft var(--duration-normal) var(--ease-out) both; }
.animate-fade-in-right { animation: fadeInRight var(--duration-normal) var(--ease-out) both; }

/* Scale Animations */
.animate-scale-in { animation: scaleIn var(--duration-normal) var(--ease-out) both; }
.animate-scale-out { animation: scaleOut var(--duration-normal) var(--ease-in) both; }
.animate-zoom-in { animation: zoomIn var(--duration-normal) var(--ease-out) both; }
.animate-bounce-in { animation: bounceIn var(--duration-slow) var(--ease-bounce) both; }

/* Slide Animations */
.animate-slide-in-up { animation: slideInUp var(--duration-normal) var(--ease-out) both; }
.animate-slide-in-down { animation: slideInDown var(--duration-normal) var(--ease-out) both; }
.animate-slide-in-left { animation: slideInLeft var(--duration-normal) var(--ease-out) both; }
.animate-slide-in-right { animation: slideInRight var(--duration-normal) var(--ease-out) both; }

/* Rotation Animations */
.animate-rotate-in { animation: rotateIn var(--duration-normal) var(--ease-out) both; }
.animate-spin { animation: spin 1s var(--ease-linear) infinite; }
.animate-pulse { animation: pulse 2s var(--ease-in-out) infinite; }
.animate-heartbeat { animation: heartbeat 1.5s var(--ease-in-out) infinite; }

/* Bounce Animations */
.animate-bounce { animation: bounce 1s var(--ease-out) infinite; }
.animate-rubber { animation: rubber var(--duration-slow) var(--ease-out); }

/* Attention Seekers */
.animate-shake { animation: shake var(--duration-slow) var(--ease-in-out); }
.animate-wobble { animation: wobble 1s var(--ease-in-out); }
.animate-flash { animation: flash 2s var(--ease-in-out) infinite; }
.animate-swing { animation: swing 1s var(--ease-in-out); }

/* Loading States */
.animate-shimmer { animation: shimmer 1.5s var(--ease-in-out) infinite; }
.animate-skeleton { animation: skeleton 1.5s var(--ease-in-out) infinite; }
.animate-dots::after { content: '...'; animation: dots 1.5s steps(5, end) infinite; }

/* Duration Modifiers */
.animate-fast { animation-duration: var(--duration-fast) !important; }
.animate-slow { animation-duration: var(--duration-slow) !important; }
.animate-slower { animation-duration: var(--duration-slower) !important; }
.animate-slowest { animation-duration: var(--duration-slowest) !important; }

/* Delay Modifiers */
.animate-delay-1 { animation-delay: var(--stagger-1) !important; }
.animate-delay-2 { animation-delay: var(--stagger-2) !important; }
.animate-delay-3 { animation-delay: var(--stagger-3) !important; }
.animate-delay-4 { animation-delay: var(--stagger-4) !important; }
.animate-delay-5 { animation-delay: var(--stagger-5) !important; }
.animate-delay-6 { animation-delay: var(--stagger-6) !important; }
.animate-delay-7 { animation-delay: var(--stagger-7) !important; }
.animate-delay-8 { animation-delay: var(--stagger-8) !important; }

/* Repeat Modifiers */
.animate-once { animation-iteration-count: 1 !important; }
.animate-twice { animation-iteration-count: 2 !important; }
.animate-infinite { animation-iteration-count: infinite !important; }

/* ============== MICRO-INTERACTIONS ============== */

/* Hover Effects */
.hover-lift {
    transition: transform var(--duration-fast) var(--ease-out), 
                box-shadow var(--duration-fast) var(--ease-out);
}

.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.hover-lift-lg {
    transition: transform var(--duration-fast) var(--ease-out), 
                box-shadow var(--duration-fast) var(--ease-out);
}

.hover-lift-lg:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
}

.hover-scale {
    transition: transform var(--duration-fast) var(--ease-out);
}

.hover-scale:hover {
    transform: scale(1.05);
}

.hover-scale-sm:hover {
    transform: scale(1.02);
}

.hover-scale-lg:hover {
    transform: scale(1.1);
}

.hover-rotate {
    transition: transform var(--duration-normal) var(--ease-out);
}

.hover-rotate:hover {
    transform: rotate(5deg);
}

.hover-glow {
    transition: box-shadow var(--duration-normal) var(--ease-out);
}

.hover-glow:hover {
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
}

/* Focus Effects */
.focus-ring {
    transition: box-shadow var(--duration-fast) var(--ease-out);
}

.focus-ring:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.focus-ring-danger:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
}

.focus-ring-success:focus {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.3);
}

/* Active States */
.active-scale:active {
    transform: scale(0.95);
}

.active-press:active {
    transform: translateY(1px);
}

/* Loading States */
.loading-overlay {
    position: relative;
    overflow: hidden;
}

.loading-overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.4) 50%, 
        transparent 100%);
    transform: translateX(-100%);
    animation: shimmer 1.5s infinite;
    z-index: 1;
}

/* ============== COMPONENT-SPECIFIC ANIMATIONS ============== */

/* Button Animations */
.btn-animated {
    position: relative;
    overflow: hidden;
    transition: all var(--duration-normal) var(--ease-out);
}

.btn-animated::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.2), 
        transparent);
    transition: left var(--duration-normal) var(--ease-out);
}

.btn-animated:hover::before {
    left: 100%;
}

.btn-ripple {
    position: relative;
    overflow: hidden;
}

.btn-ripple::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0);
    animation: ripple 0.6s linear;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Card Animations */
.card-animated {
    transition: all var(--duration-normal) var(--ease-out);
}

.card-animated:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
}

.card-tilt {
    transition: transform var(--duration-normal) var(--ease-out);
}

.card-tilt:hover {
    transform: perspective(1000px) rotateX(5deg) rotateY(5deg) translateZ(10px);
}

/* Navigation Animations */
.nav-item-animated {
    position: relative;
    overflow: hidden;
}

.nav-item-animated::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(59, 130, 246, 0.1) 50%, 
        transparent 100%);
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease-out);
}

.nav-item-animated:hover::before {
    transform: translateX(100%);
}

/* Table Row Animations */
.table-row-animated {
    transition: all var(--duration-fast) var(--ease-out);
}

.table-row-animated:hover {
    background-color: var(--neutral-50);
    transform: scale(1.01);
    box-shadow: var(--shadow-sm);
}

/* Form Animations */
.form-group-animated .form-control {
    transition: all var(--duration-normal) var(--ease-out);
}

.form-group-animated .form-control:focus {
    transform: scale(1.02);
}

.form-label-animated {
    transition: all var(--duration-normal) var(--ease-out);
}

.form-group-animated .form-control:focus + .form-label-animated {
    color: var(--primary-500);
    transform: translateY(-2px);
}

/* Modal Animations */
.modal-animated .modal-dialog {
    animation: modalSlideDown var(--duration-normal) var(--ease-out);
}

@keyframes modalSlideDown {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Dropdown Animations */
.dropdown-animated .dropdown-menu {
    animation: dropdownSlideDown var(--duration-fast) var(--ease-out);
}

@keyframes dropdownSlideDown {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============== STAGGERED ANIMATIONS ============== */

.stagger-children > * {
    animation-delay: calc(var(--stagger-2) * var(--stagger-index, 0));
}

.stagger-children > *:nth-child(1) { --stagger-index: 1; }
.stagger-children > *:nth-child(2) { --stagger-index: 2; }
.stagger-children > *:nth-child(3) { --stagger-index: 3; }
.stagger-children > *:nth-child(4) { --stagger-index: 4; }
.stagger-children > *:nth-child(5) { --stagger-index: 5; }
.stagger-children > *:nth-child(6) { --stagger-index: 6; }
.stagger-children > *:nth-child(7) { --stagger-index: 7; }
.stagger-children > *:nth-child(8) { --stagger-index: 8; }
.stagger-children > *:nth-child(9) { --stagger-index: 9; }
.stagger-children > *:nth-child(10) { --stagger-index: 10; }

/* ============== SCROLL ANIMATIONS ============== */

.scroll-fade-in {
    opacity: 0;
    transform: translateY(20px);
    transition: all var(--duration-slow) var(--ease-out);
}

.scroll-fade-in.in-view {
    opacity: 1;
    transform: translateY(0);
}

.scroll-slide-left {
    opacity: 0;
    transform: translateX(-30px);
    transition: all var(--duration-slow) var(--ease-out);
}

.scroll-slide-left.in-view {
    opacity: 1;
    transform: translateX(0);
}

.scroll-slide-right {
    opacity: 0;
    transform: translateX(30px);
    transition: all var(--duration-slow) var(--ease-out);
}

.scroll-slide-right.in-view {
    opacity: 1;
    transform: translateX(0);
}

.scroll-scale-in {
    opacity: 0;
    transform: scale(0.8);
    transition: all var(--duration-slow) var(--ease-out);
}

.scroll-scale-in.in-view {
    opacity: 1;
    transform: scale(1);
}

/* ============== ACCESSIBILITY CONSIDERATIONS ============== */

/* Respect user's 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;
    }
    
    .animate-spin {
        animation: none !important;
    }
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
    .hover-glow:hover {
        box-shadow: 0 0 0 3px currentColor;
    }
    
    .focus-ring:focus {
        box-shadow: 0 0 0 3px currentColor !important;
    }
}

/* ============== PERFORMANCE OPTIMIZATIONS ============== */

/* GPU acceleration for smooth animations */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Optimize for animations */
.will-animate {
    will-change: transform, opacity;
}

.will-animate-complete {
    will-change: auto;
}

/* ============== PRINT STYLES ============== */

@media print {
    /* Disable all animations for print */
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }
}

/* ============== DARK MODE ANIMATIONS ============== */

[data-theme="dark"] .hover-glow:hover {
    box-shadow: 0 0 20px rgba(147, 197, 253, 0.4);
}

[data-theme="dark"] .focus-ring:focus {
    box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.3);
}

[data-theme="dark"] .loading-overlay::before {
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.1) 50%, 
        transparent 100%);
}

/* ============== UTILITY FUNCTIONS FOR JAVASCRIPT ============== */

/* Classes to trigger animations via JavaScript */
.trigger-bounce { animation: bounce 1s var(--ease-out); }
.trigger-shake { animation: shake var(--duration-slow) var(--ease-in-out); }
.trigger-pulse { animation: pulse 1s var(--ease-in-out); }
.trigger-flash { animation: flash 1s var(--ease-in-out); }
.trigger-rubber { animation: rubber var(--duration-slow) var(--ease-out); }
.trigger-wobble { animation: wobble 1s var(--ease-in-out); }
.trigger-swing { animation: swing 1s var(--ease-in-out); }

/* Remove animation classes after completion */
.animation-complete {
    animation: none !important;
}
