/* Native-like Animations and Transitions - Version 1.0 */
/* Provides smooth, native-feeling animations for PWA */

/* ==========================================
   GLOBAL ANIMATION SETTINGS
   ========================================== */

* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    scroll-behavior: smooth;
}

/* ==========================================
   PAGE TRANSITIONS
   ========================================== */

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

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

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

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

/* ==========================================
   SLIDE TRANSITIONS
   ========================================== */

.slide-up {
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-down {
    animation: slideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-left {
    animation: slideLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-right {
    animation: slideRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

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

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

/* ==========================================
   FADE TRANSITIONS
   ========================================== */

.fade-in {
    animation: fadeIn 0.3s ease-in;
}

.fade-out {
    animation: fadeOut 0.3s ease-out;
}

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

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@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);
    }
}

/* ==========================================
   SCALE TRANSITIONS
   ========================================== */

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

.scale-out {
    animation: scaleOut 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.pop-in {
    animation: popIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

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

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ==========================================
   BUTTON INTERACTIONS
   ========================================== */

button, .btn, [role="button"] {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

button:active, .btn:active, [role="button"]:active {
    transform: scale(0.95);
}

/* Ripple effect */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    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;
}

.ripple:active::after {
    width: 300px;
    height: 300px;
}

/* ==========================================
   CARD ANIMATIONS
   ========================================== */

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

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

.card:active {
    transform: translateY(-2px);
}

.card-stack-enter {
    animation: cardStackEnter 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

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

/* Stagger animation for lists */
.card-stack-enter:nth-child(1) { animation-delay: 0s; }
.card-stack-enter:nth-child(2) { animation-delay: 0.05s; }
.card-stack-enter:nth-child(3) { animation-delay: 0.1s; }
.card-stack-enter:nth-child(4) { animation-delay: 0.15s; }
.card-stack-enter:nth-child(5) { animation-delay: 0.2s; }
.card-stack-enter:nth-child(n+6) { animation-delay: 0.25s; }

/* ==========================================
   LOADING ANIMATIONS
   ========================================== */

.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.dots-loading {
    display: inline-flex;
    gap: 8px;
}

.dots-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: dots-bounce 1.4s ease-in-out infinite;
}

.dots-loading span:nth-child(1) { animation-delay: 0s; }
.dots-loading span:nth-child(2) { animation-delay: 0.2s; }
.dots-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dots-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================
   MODAL ANIMATIONS
   ========================================== */

.modal-backdrop {
    animation: backdropFadeIn 0.3s ease-out;
}

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

@keyframes backdropFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

/* ==========================================
   SHAKE ANIMATION (for errors)
   ========================================== */

.shake {
    animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}

/* ==========================================
   PULSE ANIMATION
   ========================================== */

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

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

/* ==========================================
   BOUNCE ANIMATION
   ========================================== */

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

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

/* ==========================================
   ATTENTION SEEKERS
   ========================================== */

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

@keyframes attention {
    0%, 100% {
        transform: scale(1);
    }
    10%, 20% {
        transform: scale(1.1) rotate(-3deg);
    }
    30%, 50%, 70%, 90% {
        transform: scale(1.1) rotate(3deg);
    }
    40%, 60%, 80% {
        transform: scale(1.1) rotate(-3deg);
    }
}

/* ==========================================
   SMOOTH SCROLLING
   ========================================== */

.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================
   TRANSITIONS FOR INTERACTIVE ELEMENTS
   ========================================== */

input, textarea, select {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

input:focus, textarea:focus, select:focus {
    transform: scale(1.02);
}

a {
    transition: all 0.2s ease;
}

a:active {
    opacity: 0.7;
}

/* ==========================================
   NATIVE-LIKE MOMENTUM SCROLLING
   ========================================== */

.native-scroll {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* Hide scrollbar but keep functionality */
.native-scroll::-webkit-scrollbar {
    width: 0;
    background: transparent;
}

/* ==========================================
   SAFE AREA INSETS (for iOS notch)
   ========================================== */

@supports (padding: max(0px)) {
    .safe-area-top {
        padding-top: max(20px, env(safe-area-inset-top));
    }
    
    .safe-area-bottom {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    .safe-area-left {
        padding-left: max(20px, env(safe-area-inset-left));
    }
    
    .safe-area-right {
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* ==========================================
   RESPONSIVE ANIMATIONS
   ========================================== */

@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;
    }
}

/* ==========================================
   DARK MODE SUPPORT
   ========================================== */

@media (prefers-color-scheme: dark) {
    .skeleton {
        background: linear-gradient(
            90deg,
            #2a2a2a 25%,
            #1a1a1a 50%,
            #2a2a2a 75%
        );
    }
}
