/**
 * Modern Animations & Transitions
 *
 * Provides smooth, performant animations for:
 * - Page transitions
 * - Card hover effects with elevation
 * - Skeleton loading states
 * - Toast & modal animations
 * - Button micro-interactions
 * - Smooth scroll behavior
 */

/* ============================================================================
   SMOOTH SCROLL BEHAVIOR
   ============================================================================ */
html {
    scroll-behavior: smooth;
}

/* 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;
    }
}

/* ============================================================================
   PAGE TRANSITIONS
   ============================================================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

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

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

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

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

/* Page load animation */
body {
    animation: fadeIn 0.3s ease-out;
}

/* Staggered content animations */
.animate-fade-in {
    animation: fadeIn 0.5s ease-out;
}

.animate-fade-in-up {
    animation: fadeInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.animate-fade-in-down {
    animation: fadeInDown 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.animate-slide-in-left {
    animation: slideInLeft 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.animate-slide-in-right {
    animation: slideInRight 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.animate-scale-in {
    animation: scaleIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Staggered delay classes for sequential animations */
.delay-100 { animation-delay: 100ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-400 { animation-delay: 400ms; }
.delay-500 { animation-delay: 500ms; }

/* ============================================================================
   CARD ANIMATIONS
   ============================================================================ */
.app-card,
.metric-card {
    transition:
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-card:hover,
.metric-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.3);
}

/* Card content reveal on hover */
.card-hover-reveal {
    overflow: hidden;
    position: relative;
}

.card-hover-reveal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(126, 58, 242, 0.1), rgba(59, 130, 246, 0.1));
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.card-hover-reveal:hover::before {
    opacity: 1;
}

/* 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);
}

/* ============================================================================
   LOADING STATES
   ============================================================================ */
@keyframes skeleton-pulse {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--hover-bg) 25%,
        var(--border-color) 50%,
        var(--hover-bg) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
}

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

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

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

.skeleton-card {
    height: 200px;
}

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

.spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

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

/* Dots loader */
@keyframes dot-pulse {
    0%, 80%, 100% {
        opacity: 0.4;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

.dots-loader {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
}

.dots-loader span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.dots-loader span:nth-child(2) {
    animation-delay: 0.2s;
}

.dots-loader span:nth-child(3) {
    animation-delay: 0.4s;
}

/* ============================================================================
   BUTTON MICRO-INTERACTIONS
   ============================================================================ */
.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ripple effect */
.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

/* Button hover states */
.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Accent button animation */
.btn-accent {
    position: relative;
    z-index: 1;
}

.btn-accent::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--accent), #3b82f6);
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: inherit;
}

.btn-accent:hover::after {
    opacity: 1;
}

/* Icon button pulse */
@keyframes icon-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.btn-icon:hover {
    animation: icon-pulse 0.6s ease;
}

/* ============================================================================
   TOAST & MODAL ANIMATIONS
   ============================================================================ */
@keyframes slideInFromRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

.toast-enter {
    animation: slideInFromRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-exit {
    animation: slideOutToRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Modal animations */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

.modal-backdrop {
    animation: modalFadeIn 0.2s ease;
}

.modal-content {
    animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================================
   PROGRESS ANIMATIONS
   ============================================================================ */
@keyframes progress-indeterminate {
    0% {
        left: -35%;
        right: 100%;
    }
    60% {
        left: 100%;
        right: -90%;
    }
    100% {
        left: 100%;
        right: -90%;
    }
}

.progress-bar-indeterminate {
    position: relative;
    overflow: hidden;
}

.progress-bar-indeterminate::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -35%;
    background: var(--accent);
    animation: progress-indeterminate 2s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
}

/* ============================================================================
   BADGE & STATUS ANIMATIONS
   ============================================================================ */
@keyframes badge-pop {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.badge-animated {
    animation: badge-pop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
}

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

.scroll-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================================
   HOVER EFFECTS
   ============================================================================ */
/* Shine effect */
@keyframes shine {
    0% {
        background-position: -200% center;
    }
    100% {
        background-position: 200% center;
    }
}

.hover-shine {
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.3) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    background-position: -200% center;
    transition: background-position 0.6s ease;
}

.hover-shine:hover {
    background-position: 200% center;
}

/* Glow effect */
.hover-glow {
    transition: box-shadow 0.3s ease;
}

.hover-glow:hover {
    box-shadow: 0 0 20px rgba(126, 58, 242, 0.4);
}

/* Tilt effect */
.hover-tilt {
    transition: transform 0.3s ease;
}

.hover-tilt:hover {
    transform: perspective(1000px) rotateX(2deg) rotateY(2deg);
}

/* ============================================================================
   FOCUS STATES
   ============================================================================ */
.focus-ring:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(126, 58, 242, 0.3);
}

.focus-ring:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================================
   UTILITY ANIMATION CLASSES
   ============================================================================ */
.transition-all {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.transition-colors {
    transition: color 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
}

.transition-transform {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.transition-opacity {
    transition: opacity 0.3s ease;
}

/* Duration modifiers */
.duration-fast { transition-duration: 150ms; }
.duration-normal { transition-duration: 300ms; }
.duration-slow { transition-duration: 500ms; }

/* Ease functions */
.ease-in { transition-timing-function: ease-in; }
.ease-out { transition-timing-function: ease-out; }
.ease-in-out { transition-timing-function: ease-in-out; }
.ease-smooth { transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); }

/* ============================================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================================ */
/* Use GPU acceleration for transform and opacity */
.gpu-accelerate {
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Remove will-change after animation */
.gpu-accelerate.animation-done {
    will-change: auto;
}
