/**
 * Animations CSS - Micro-interactions & Effects
 * Phase 3.1 - Premium Theme System
 */

/* =====================
 * KEYFRAME ANIMATIONS
 * ===================== */

/* Fade In */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Fade In with Direction */
@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 fadeInLeft {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Slide Animations */
@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

/* Scale Animations */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleUp {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes zoomOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.3);
    }
}

/* Bounce */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Pulse */
@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 0 0 var(--color-primary);
    }
    70% {
        box-shadow: 0 0 0 15px transparent;
    }
    100% {
        box-shadow: 0 0 0 0 transparent;
    }
}

/* Shake */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

/* Swing */
@keyframes swing {
    20% {
        transform: rotate(15deg);
    }
    40% {
        transform: rotate(-10deg);
    }
    60% {
        transform: rotate(5deg);
    }
    80% {
        transform: rotate(-5deg);
    }
    100% {
        transform: rotate(0deg);
    }
}

/* Wobble */
@keyframes wobble {
    0% {
        transform: translateX(0%);
    }
    15% {
        transform: translateX(-10%) rotate(-5deg);
    }
    30% {
        transform: translateX(8%) rotate(3deg);
    }
    45% {
        transform: translateX(-6%) rotate(-3deg);
    }
    60% {
        transform: translateX(4%) rotate(2deg);
    }
    75% {
        transform: translateX(-2%) rotate(-1deg);
    }
    100% {
        transform: translateX(0%);
    }
}

/* Flip */
@keyframes flipInX {
    0% {
        opacity: 0;
        transform: perspective(400px) rotateX(90deg);
    }
    40% {
        transform: perspective(400px) rotateX(-10deg);
    }
    70% {
        transform: perspective(400px) rotateX(10deg);
    }
    100% {
        opacity: 1;
        transform: perspective(400px) rotateX(0deg);
    }
}

@keyframes flipInY {
    0% {
        opacity: 0;
        transform: perspective(400px) rotateY(90deg);
    }
    40% {
        transform: perspective(400px) rotateY(-10deg);
    }
    70% {
        transform: perspective(400px) rotateY(10deg);
    }
    100% {
        opacity: 1;
        transform: perspective(400px) rotateY(0deg);
    }
}

/* Rotate */
@keyframes rotateIn {
    from {
        opacity: 0;
        transform: rotate(-200deg);
    }
    to {
        opacity: 1;
        transform: rotate(0);
    }
}

/* Spinner */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Loading Dots */
@keyframes loadingDots {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Skeleton Loading */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Float */
@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Heartbeat */
@keyframes heartbeat {
    0% {
        transform: scale(1);
    }
    14% {
        transform: scale(1.2);
    }
    28% {
        transform: scale(1);
    }
    42% {
        transform: scale(1.2);
    }
    70% {
        transform: scale(1);
    }
}

/* Ripple */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* Progress Bar */
@keyframes progressIndeterminate {
    0% {
        left: -35%;
        right: 100%;
    }
    60% {
        left: 100%;
        right: -90%;
    }
    100% {
        left: 100%;
        right: -90%;
    }
}

/* =====================
 * ANIMATION CLASSES
 * ===================== */

.animate-none { animation: none; }

/* Fade */
.animate-fadeIn {
    animation: fadeIn var(--transition-normal) ease-out forwards;
}

.animate-fadeOut {
    animation: fadeOut var(--transition-normal) ease-out forwards;
}

.animate-fadeInUp {
    animation: fadeInUp 0.6s ease-out forwards;
}

.animate-fadeInDown {
    animation: fadeInDown 0.6s ease-out forwards;
}

.animate-fadeInLeft {
    animation: fadeInLeft 0.6s ease-out forwards;
}

.animate-fadeInRight {
    animation: fadeInRight 0.6s ease-out forwards;
}

/* Slide */
.animate-slideUp {
    animation: slideUp 0.4s ease-out forwards;
}

.animate-slideDown {
    animation: slideDown 0.4s ease-out forwards;
}

.animate-slideInLeft {
    animation: slideInLeft 0.4s ease-out forwards;
}

.animate-slideInRight {
    animation: slideInRight 0.4s ease-out forwards;
}

/* Scale */
.animate-scaleIn {
    animation: scaleIn 0.3s ease-out forwards;
}

.animate-scaleUp {
    animation: scaleUp 0.5s ease-out forwards;
}

.animate-zoomIn {
    animation: zoomIn 0.3s ease-out forwards;
}

.animate-zoomOut {
    animation: zoomOut 0.3s ease-out forwards;
}

/* Bounce */
.animate-bounce {
    animation: bounce 1s infinite;
}

.animate-bounceIn {
    animation: bounceIn 0.6s forwards;
}

/* Pulse */
.animate-pulse {
    animation: pulse 2s infinite;
}

.animate-pulseGlow {
    animation: pulseGlow 1.5s infinite;
}

/* Shake */
.animate-shake {
    animation: shake 0.5s forwards;
}

/* Swing */
.animate-swing {
    animation: swing 1s forwards;
}

/* Wobble */
.animate-wobble {
    animation: wobble 1s forwards;
}

/* Flip */
.animate-flipInX {
    animation: flipInX 0.6s forwards;
}

.animate-flipInY {
    animation: flipInY 0.6s forwards;
}

/* Rotate */
.animate-rotateIn {
    animation: rotateIn 0.6s forwards;
}

/* Spin (Loading) */
.animate-spin {
    animation: spin 1s linear infinite;
}

/* Float */
.animate-float {
    animation: float 3s ease-in-out infinite;
}

/* Heartbeat */
.animate-heartbeat {
    animation: heartbeat 1.5s ease-in-out infinite;
}

/* =====================
 * ANIMATION DELAYS
 * ===================== */

.delay-75 { animation-delay: 75ms; }
.delay-100 { animation-delay: 100ms; }
.delay-150 { animation-delay: 150ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-500 { animation-delay: 500ms; }
.delay-700 { animation-delay: 700ms; }
.delay-1000 { animation-delay: 1000ms; }

/* Stagger delays for lists */
.stagger-1 { animation-delay: 100ms; }
.stagger-2 { animation-delay: 200ms; }
.stagger-3 { animation-delay: 300ms; }
.stagger-4 { animation-delay: 400ms; }
.stagger-5 { animation-delay: 500ms; }
.stagger-6 { animation-delay: 600ms; }
.stagger-7 { animation-delay: 700ms; }
.stagger-8 { animation-delay: 800ms; }

/* =====================
 * ANIMATION DURATIONS
 * ===================== */

.duration-fast { animation-duration: 0.15s; }
.duration-normal { animation-duration: 0.3s; }
.duration-slow { animation-duration: 0.5s; }
.duration-slower { animation-duration: 0.8s; }
.duration-slowest { animation-duration: 1s; }

/* =====================
 * ANIMATION MODES
 * ===================== */

.fill-forwards { animation-fill-mode: forwards; }
.fill-backwards { animation-fill-mode: backwards; }
.fill-both { animation-fill-mode: both; }

.animate-once { animation-iteration-count: 1; }
.animate-twice { animation-iteration-count: 2; }
.animate-infinite { animation-iteration-count: infinite; }

.animate-paused { animation-play-state: paused; }
.animate-running { animation-play-state: running; }

/* =====================
 * HOVER EFFECTS
 * ===================== */

/* Lift on hover */
.hover-lift {
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.hover-lift:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

/* Scale on hover */
.hover-scale {
    transition: transform var(--transition-normal);
}

.hover-scale:hover {
    transform: scale(1.05);
}

.hover-scale-sm:hover {
    transform: scale(1.02);
}

.hover-scale-lg:hover {
    transform: scale(1.1);
}

/* Glow on hover */
.hover-glow {
    transition: box-shadow var(--transition-normal);
}

.hover-glow:hover {
    box-shadow: 0 0 20px var(--color-primary-light);
}

/* Brightness on hover */
.hover-bright {
    transition: filter var(--transition-normal);
}

.hover-bright:hover {
    filter: brightness(1.1);
}

/* Opacity on hover */
.hover-fade {
    transition: opacity var(--transition-normal);
}

.hover-fade:hover {
    opacity: 0.8;
}

/* Rotate on hover */
.hover-rotate {
    transition: transform var(--transition-normal);
}

.hover-rotate:hover {
    transform: rotate(5deg);
}

/* Shake on hover */
.hover-shake:hover {
    animation: shake 0.5s;
}

/* Pulse on hover */
.hover-pulse:hover {
    animation: pulse 0.5s;
}

/* =====================
 * CLICK/ACTIVE EFFECTS
 * ===================== */

.active-scale:active {
    transform: scale(0.95);
}

.active-scale-sm:active {
    transform: scale(0.98);
}

/* =====================
 * FOCUS EFFECTS
 * ===================== */

.focus-ring:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.focus-glow:focus {
    outline: none;
    box-shadow: 0 0 15px var(--color-primary);
}

/* =====================
 * SCROLL REVEAL CLASSES
 * (Work with IntersectionObserver)
 * ===================== */

/* Initial hidden state */
[data-animate] {
    opacity: 0;
}

[data-animate="fadeIn"] { opacity: 0; }
[data-animate="fadeInUp"] { opacity: 0; transform: translateY(30px); }
[data-animate="fadeInDown"] { opacity: 0; transform: translateY(-30px); }
[data-animate="fadeInLeft"] { opacity: 0; transform: translateX(30px); }
[data-animate="fadeInRight"] { opacity: 0; transform: translateX(-30px); }
[data-animate="scaleIn"] { opacity: 0; transform: scale(0.9); }
[data-animate="zoomIn"] { opacity: 0; transform: scale(0.5); }

/* Animated state (add .is-visible via JS) */
[data-animate].is-visible {
    opacity: 1;
    transform: none;
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

/* Stagger children */
[data-stagger] > * {
    opacity: 0;
    transform: translateY(20px);
}

[data-stagger].is-visible > * {
    opacity: 1;
    transform: none;
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

[data-stagger].is-visible > *:nth-child(1) { transition-delay: 0.1s; }
[data-stagger].is-visible > *:nth-child(2) { transition-delay: 0.2s; }
[data-stagger].is-visible > *:nth-child(3) { transition-delay: 0.3s; }
[data-stagger].is-visible > *:nth-child(4) { transition-delay: 0.4s; }
[data-stagger].is-visible > *:nth-child(5) { transition-delay: 0.5s; }
[data-stagger].is-visible > *:nth-child(6) { transition-delay: 0.6s; }
[data-stagger].is-visible > *:nth-child(7) { transition-delay: 0.7s; }
[data-stagger].is-visible > *:nth-child(8) { transition-delay: 0.8s; }

/* =====================
 * RIPPLE EFFECT (Button)
 * ===================== */

.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
}

.ripple:active::after {
    animation: ripple 0.6s ease-out;
}

/* =====================
 * LOADING STATES
 * ===================== */

/* Skeleton loader */
.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--color-surface-alt);
}

.skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: shimmer 1.5s infinite;
    background-size: 200% 100%;
}

/* Loading dots */
.loading-dots {
    display: inline-flex;
    gap: var(--spacing-xs);
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--color-primary);
    border-radius: 50%;
    animation: loadingDots 1.4s infinite ease-in-out 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: 0; }

/* =====================
 * SPECIAL EFFECTS
 * ===================== */

/* Gradient text animation */
.gradient-text {
    background: linear-gradient(
        135deg,
        var(--color-primary),
        var(--color-secondary),
        var(--color-accent),
        var(--color-primary)
    );
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 5s ease infinite;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Glowing border */
.glow-border {
    position: relative;
}

.glow-border::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: linear-gradient(
        45deg,
        var(--color-primary),
        var(--color-secondary),
        var(--color-accent),
        var(--color-primary)
    );
    background-size: 400% 400%;
    border-radius: inherit;
    z-index: -1;
    animation: gradientShift 3s ease infinite;
    filter: blur(8px);
    opacity: 0.7;
}

/* Typing cursor */
.typing-cursor::after {
    content: '|';
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Number counter animation - CSS only visual */
.counter-animated {
    display: inline-block;
    transition: transform 0.3s;
}

.counter-animated:hover {
    transform: scale(1.1);
}

/* Underline animation */
.underline-animated {
    position: relative;
    text-decoration: none;
}

.underline-animated::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 2px;
    background: var(--color-primary);
    transition: width var(--transition-normal);
}

.underline-animated:hover::after {
    width: 100%;
    right: auto;
    left: 0;
}

/* =====================
 * REDUCED MOTION
 * ===================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    [data-animate],
    [data-stagger] > * {
        opacity: 1 !important;
        transform: none !important;
    }
}
