/**
 * Mobile Native-Like Experience Enhancements
 * Advanced mobile optimizations, gestures, and native app feel
 * @version 1.0.0
 */

:root {
    --native-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --native-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --native-spring: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --safe-area-top: env(safe-area-inset-top, 44px);
    --safe-area-bottom: env(safe-area-inset-bottom, 34px);
    --haptic-light: 50ms;
    --haptic-medium: 100ms;
    --haptic-heavy: 200ms;
}

/* Enhanced Touch Targets & Feedback */
button, .nav-item, [role="button"], .card {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: all 0.15s var(--native-ease);
    min-height: 44px;
    min-width: 44px;
    position: relative;
    overflow: hidden;
}

/* Enhanced Touch Feedback */
.touch-active {
    transform: scale(0.97) !important;
    filter: brightness(0.95);
    transition: all 0.1s ease !important;
}

button:active, .nav-item:active, [role="button"]:active {
    transform: scale(0.97);
    transition: transform 0.05s ease;
}

/* Ripple Effect for Touch Feedback */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: ripple 0.6s linear;
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Enhanced Pull-to-Refresh */
.pull-refresh-indicator {
    position: fixed;
    top: calc(-60px - var(--safe-area-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(139, 92, 246, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: all 0.4s var(--native-spring);
    opacity: 0;
    pointer-events: none;
}

.pull-refresh-indicator.pulling {
    top: calc(20px + var(--safe-area-top));
    opacity: 1;
    animation: pullBounce 0.3s var(--native-bounce);
}

.pull-refresh-indicator.ready {
    background: rgba(34, 197, 94, 0.95);
    animation: readyPulse 0.8s ease-in-out infinite alternate;
}

.pull-refresh-indicator.refreshing {
    top: calc(20px + var(--safe-area-top));
    opacity: 1;
    background: rgba(59, 130, 246, 0.95);
}

@keyframes pullBounce {
    0% { transform: translateX(-50%) scale(0.8); opacity: 0; }
    50% { transform: translateX(-50%) scale(1.1); }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes readyPulse {
    from { transform: translateX(-50%) scale(1); }
    to { transform: translateX(-50%) scale(1.05); }
}

.pull-icon {
    transition: transform 0.4s var(--native-spring);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pull-refresh-indicator.ready .pull-icon {
    transform: rotate(180deg);
}

.pull-refresh-indicator.refreshing .pull-icon {
    animation: spinSmooth 1.2s linear infinite;
}

@keyframes spinSmooth {
    to { transform: rotate(360deg); }
}

/* Page Transition Effects */
.page-transition-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s var(--native-ease);
}

.page-transition-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Swipe Navigation Indicators */
.swipe-indicator {
    position: fixed;
    top: 50%;
    z-index: 1000;
    width: 40px;
    height: 60px;
    background: rgba(139, 92, 246, 0.8);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    backdrop-filter: blur(10px);
    transform: translateY(-50%) scale(0);
    transition: all 0.3s var(--native-bounce);
    pointer-events: none;
    opacity: 0;
}

.swipe-indicator.left {
    left: 20px;
}

.swipe-indicator.right {
    right: 20px;
}

.swipe-indicator.active {
    transform: translateY(-50%) scale(1);
    opacity: 1;
}

/* Enhanced Bottom Sheet Styles */
.bottom-sheet {
    position: fixed !important;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    background: var(--bg-primary);
    border-radius: 20px 20px 0 0;
    border: 1px solid rgba(139, 92, 246, 0.2);
    box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--safe-area-bottom);
}

.bottom-sheet::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.bottom-sheet-backdrop {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    backdrop-filter: blur(4px);
    transition: all 0.4s var(--native-ease);
}

/* Enhanced Modal Animations */
.modal {
    animation: modalSlideUp 0.4s var(--native-spring);
}

.modal.closing {
    animation: modalSlideDown 0.3s var(--native-ease);
}

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

@keyframes modalSlideDown {
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* Native-Style Navigation Bar */
.nav {
    background: rgba(10, 10, 15, 0.95) !important;
    backdrop-filter: blur(20px) !important;
    border-top: 1px solid rgba(139, 92, 246, 0.1);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    padding-bottom: var(--safe-area-bottom);
}

.nav-item {
    position: relative;
    transition: all 0.2s var(--native-ease);
    border-radius: 12px;
    margin: 0 4px;
    overflow: hidden;
}

.nav-item:hover {
    background: rgba(139, 92, 246, 0.1);
    transform: translateY(-1px);
}

.nav-item.active {
    background: rgba(139, 92, 246, 0.15);
}

.nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 2px;
    background: var(--purple-primary);
    border-radius: 1px;
}

/* Enhanced Card Interactions */
.card {
    transition: all 0.3s var(--native-ease);
    will-change: transform, filter;
}

.card:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 40px rgba(139, 92, 246, 0.2);
}

.card:active {
    transform: translateY(0) scale(0.98);
    transition: all 0.1s ease;
}

/* Native-Style Loading States */
.loading-skeleton {
    background: linear-gradient(
        90deg,
        rgba(139, 92, 246, 0.1) 25%,
        rgba(139, 92, 246, 0.2) 50%,
        rgba(139, 92, 246, 0.1) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 8px;
}

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

/* Enhanced Scrolling Experience */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* iOS-Style Momentum Scrolling */
.momentum-scroll {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Enhanced Focus States for Accessibility */
:focus-visible {
    outline: 2px solid var(--purple-primary) !important;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Native-Style Alerts & Toasts */
.toast {
    animation: toastSlideIn 0.4s var(--native-bounce);
}

.toast.hiding {
    animation: toastSlideOut 0.3s var(--native-ease);
}

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

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

/* Enhanced Input Fields */
input, textarea, select {
    -webkit-appearance: none;
    appearance: none;
    transition: all 0.2s var(--native-ease);
    border-radius: 12px;
    border: 1px solid rgba(139, 92, 246, 0.3);
    background: rgba(139, 92, 246, 0.05);
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
}

input:focus, textarea:focus, select:focus {
    border-color: var(--purple-primary);
    background: rgba(139, 92, 246, 0.1);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

/* Enhanced Button Styles */
.btn-primary {
    background: linear-gradient(135deg, var(--purple-primary), var(--purple-light));
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3);
    transition: all 0.2s var(--native-ease);
    position: relative;
    overflow: hidden;
}

.btn-primary:active {
    transform: scale(0.96);
    box-shadow: 0 2px 10px rgba(139, 92, 246, 0.4);
}

.btn-primary::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 0.6s ease;
}

.btn-primary:hover::before {
    left: 100%;
}

/* Performance Optimizations */
.will-change-transform {
    will-change: transform;
}

.will-change-scroll {
    will-change: scroll-position;
}

.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .pull-refresh-indicator,
    .swipe-indicator,
    .loading-skeleton {
        animation: none !important;
    }
}

/* High Contrast Mode Support */
@media (forced-colors: active) {
    .pull-refresh-indicator {
        background: ButtonFace;
        color: ButtonText;
        border: 1px solid ButtonBorder;
    }
    
    .nav-item.active::after {
        background: Highlight;
    }
}

/* Dark Mode Enhancements */
@media (prefers-color-scheme: dark) {
    .bottom-sheet {
        border-color: rgba(139, 92, 246, 0.3);
        box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.8);
    }
    
    .nav {
        background: rgba(10, 10, 15, 0.98) !important;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    }
}

/* Tablet & Desktop Adaptations */
@media (min-width: 768px) {
    .pull-refresh-indicator {
        display: none; /* Disable on larger screens */
    }
    
    .swipe-indicator {
        display: none; /* Disable on larger screens */
    }
    
    .card:hover {
        transform: translateY(-4px) scale(1.03);
    }
}

/* Ultra-wide screens */
@media (min-width: 1200px) {
    .app {
        max-width: 430px;
        margin: 0 auto;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
    }
}

/* Print Styles */
@media print {
    .nav, .pull-refresh-indicator, .swipe-indicator, .bottom-sheet-backdrop {
        display: none !important;
    }
    
    .page-transition-overlay {
        display: none !important;
    }
}