/**
 * OTP Auth Suite - Enhanced Frontend Animations
 * Premium animations inspired by Myntra, Nykaa, and Giva
 * Mobile-optimized with 60fps performance
 */

/* ========================================
   ENHANCED KEYFRAME ANIMATIONS
======================================== */

/* Smooth modal entrance - slide up with fade */
@keyframes oas-modal-entrance {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal backdrop fade */
@keyframes oas-backdrop-fade {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Smooth fade in with slight movement */
@keyframes oas-fade-in-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Smooth fade in with scale */
@keyframes oas-fade-in-scale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Slide in from right (for mobile modals) */
@keyframes oas-slide-in-right {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Slide in from left */
@keyframes oas-slide-in-left {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Smooth bounce (for success states) */
@keyframes oas-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Gentle pulse (for loading/waiting states) */
@keyframes oas-pulse-gentle {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

/* Shimmer effect for loading states */
@keyframes oas-shimmer-enhanced {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

/* Rotating spinner (smooth) */
@keyframes oas-spin-smooth {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Progress bar fill animation */
@keyframes oas-progress-fill {
    from {
        transform: scaleX(0);
        transform-origin: left;
    }
    to {
        transform: scaleX(1);
        transform-origin: left;
    }
}

/* Ripple effect (for button clicks) */
@keyframes oas-ripple {
    0% {
        transform: scale(0);
        opacity: 0.5;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

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

/* Success checkmark animation */
@keyframes oas-checkmark {
    0% {
        stroke-dashoffset: 100;
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        stroke-dashoffset: 0;
        opacity: 1;
    }
}

/* Notification slide in */
@keyframes oas-notification-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Skeleton loading pulse */
@keyframes oas-skeleton-pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
    100% {
        opacity: 1;
    }
}

/* Heartbeat animation (for wishlist) */
@keyframes oas-heartbeat {
    0%, 100% {
        transform: scale(1);
    }
    10%, 30% {
        transform: scale(1.2);
    }
    20%, 40% {
        transform: scale(1.1);
    }
}

/* Smooth glow effect */
@keyframes oas-glow {
    0%, 100% {
        box-shadow: 0 0 5px var(--oas-primary-shadow);
    }
    50% {
        box-shadow: 0 0 20px var(--oas-primary-shadow), 0 0 30px var(--oas-primary-shadow);
    }
}

/* Float animation (for tooltips/popovers) */
@keyframes oas-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

/* Zoom in */
@keyframes oas-zoom-in {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Rotate and fade */
@keyframes oas-rotate-fade {
    from {
        opacity: 0;
        transform: rotate(-180deg) scale(0);
    }
    to {
        opacity: 1;
        transform: rotate(0deg) scale(1);
    }
}

/* ========================================
   APPLY ANIMATIONS TO ELEMENTS
======================================== */

/* Modal entrance animation */
#oas-modal.oas-active .oas-modal-container {
    animation: oas-modal-entrance 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Modal backdrop */
#oas-modal.oas-active {
    animation: oas-backdrop-fade 0.3s ease forwards;
}

/* OTP input boxes - sequential fade in */
.oas-otp-input {
    animation: oas-fade-in-scale 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.oas-otp-input:nth-child(1) { animation-delay: 0.05s; }
.oas-otp-input:nth-child(2) { animation-delay: 0.1s; }
.oas-otp-input:nth-child(3) { animation-delay: 0.15s; }
.oas-otp-input:nth-child(4) { animation-delay: 0.2s; }
.oas-otp-input:nth-child(5) { animation-delay: 0.25s; }
.oas-otp-input:nth-child(6) { animation-delay: 0.3s; }

/* Button ripple effect container */
.oas-btn-primary,
.oas-btn-secondary {
    position: relative;
    overflow: hidden;
}

/* Success message bounce */
.oas-success-message {
    animation: oas-bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

/* Loading spinner - smooth rotation */
.oas-loading-spinner,
.oas-spinner {
    animation: oas-spin-smooth 0.8s linear infinite;
    will-change: transform;
}

/* Shimmer for loading skeletons */
.oas-skeleton,
.oas-loading-skeleton {
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0) 0%,
        rgba(255,255,255,0.5) 50%,
        rgba(255,255,255,0) 100%
    );
    background-size: 1000px 100%;
    animation: oas-shimmer-enhanced 2s infinite linear;
}

/* Progress bar animation */
.oas-progress-bar,
.oas-otp-progress {
    transform-origin: left;
    animation: oas-progress-fill 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Notification entrance */
.oas-notification {
    animation: oas-notification-slide-in 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Wishlist heart animation */
.oas-wishlist-btn.oas-added,
.oas-wishlist-heart.oas-active {
    animation: oas-heartbeat 0.6s ease-in-out;
}

/* Card hover enhancement */
.oas-order-card,
.oas-stat-card,
.oas-wallet-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);
}

.oas-order-card:hover,
.oas-stat-card:hover,
.oas-wallet-card:hover {
    transform: translateY(-4px);
}

/* Button hover effects */
.oas-btn-primary,
.oas-btn-secondary {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.oas-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(252, 39, 121, 0.3);
}

.oas-btn-primary:active {
    transform: translateY(0);
    transition-duration: 0.1s;
}

/* Input focus animation */
.oas-input:focus,
.oas-phone-input:focus,
.oas-otp-input:focus {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 0 3px var(--oas-primary-light);
}

/* Menu items slide in */
.oas-menu-item {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.oas-menu-item:hover {
    transform: translateX(5px);
}

/* Avatar pulse on upload */
.oas-avatar-uploading {
    animation: oas-pulse-gentle 1.5s infinite;
}

/* OTP resend timer animation */
.oas-resend-timer {
    animation: oas-fade-in-up 0.3s ease;
}

/* Form validation animation */
.oas-form-group.oas-error .oas-input {
    animation: oas-shake 0.5s;
}

/* Success checkmark */
.oas-success-icon {
    animation: oas-zoom-in 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ========================================
   MOBILE-SPECIFIC ANIMATIONS
======================================== */
@media (max-width: 768px) {
    /* Modal slides from bottom on mobile */
    #oas-modal.oas-active .oas-modal-container {
        animation: oas-slide-in-bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    }
    
    @keyframes oas-slide-in-bottom {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    /* Faster animations on mobile for better perceived performance */
    .oas-btn-primary,
    .oas-menu-item,
    .oas-order-card {
        transition-duration: 0.2s;
    }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
======================================== */

/* Use GPU acceleration for animated elements */
.oas-modal-container,
.oas-btn-primary,
.oas-order-card,
.oas-menu-item,
.oas-loading-spinner {
    will-change: transform;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Reduce animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .oas-loading-spinner,
    .oas-spinner {
        animation-duration: 0.8s !important;
    }
}

/* ========================================
   STAGGER ANIMATIONS FOR LISTS
======================================== */

/* Dashboard stats cards - stagger entrance */
.oas-stat-card {
    animation: oas-fade-in-up 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.oas-stat-card:nth-child(1) { animation-delay: 0.1s; }
.oas-stat-card:nth-child(2) { animation-delay: 0.2s; }
.oas-stat-card:nth-child(3) { animation-delay: 0.3s; }
.oas-stat-card:nth-child(4) { animation-delay: 0.4s; }

/* Order cards - stagger entrance */
.oas-order-card {
    animation: oas-fade-in-up 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.oas-order-card:nth-child(1) { animation-delay: 0.05s; }
.oas-order-card:nth-child(2) { animation-delay: 0.1s; }
.oas-order-card:nth-child(3) { animation-delay: 0.15s; }
.oas-order-card:nth-child(4) { animation-delay: 0.2s; }

/* Wishlist items - stagger entrance */
.oas-wishlist-item {
    animation: oas-fade-in-scale 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.oas-wishlist-item:nth-child(odd) { animation-delay: 0.05s; }
.oas-wishlist-item:nth-child(even) { animation-delay: 0.1s; }

/* ========================================
   MICRO-INTERACTIONS
======================================== */

/* Tab switching */
.oas-tab {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.oas-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--oas-primary);
    animation: oas-progress-fill 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Toggle switch animation */
.oas-toggle-switch {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.oas-toggle-switch:checked {
    animation: oas-bounce 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Dropdown menu animation */
.oas-dropdown-menu {
    animation: oas-fade-in-up 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: top;
}

/* Badge notification pulse */
.oas-notification-badge {
    animation: oas-pulse-gentle 2s infinite;
}

/* Cart count animation */
.oas-cart-count.oas-updated {
    animation: oas-bounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Rating stars fill animation */
.oas-rating-star {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.oas-rating-star:hover {
    transform: scale(1.2);
}

/* ========================================
   LOADING STATES
======================================== */

/* Skeleton screen animations */
.oas-skeleton-text,
.oas-skeleton-avatar,
.oas-skeleton-card {
    animation: oas-skeleton-pulse 1.5s ease-in-out infinite;
}

/* Button loading state */
.oas-btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.oas-btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: oas-spin-smooth 0.6s linear infinite;
}

/* ========================================
   ACCESSIBILITY ENHANCEMENTS
======================================== */

/* Focus visible improvements */
.oas-btn:focus-visible,
.oas-input:focus-visible,
.oas-menu-item:focus-visible {
    outline: 3px solid var(--oas-primary);
    outline-offset: 2px;
    transition: outline-offset 0.2s ease;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .oas-btn-primary {
        border: 2px solid currentColor;
    }
}
