/* =============================================
   🔧 MOBILE SCROLL FIX - Naprawia zacinanie się na telefonie
   ============================================= */

/* FIX 1: Normalne scrollowanie */
body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    height: auto !important;
    min-height: 100vh;
    max-height: none !important;
    position: relative !important;
}

/* FIX 2: Optymalizuj main-content */
.main-content {
    overflow-x: hidden !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
    position: relative;
    height: auto !important;
    min-height: calc(100vh - 60px) !important;
    max-height: none !important;
}

/* FIX 3: Wyłącz ciężkie animacje na mobile */
@media (max-width: 768px) {
    /* CRITICAL: Force proper scrolling on mobile */
    body {
        overflow-y: auto !important;
        position: relative !important;
        height: auto !important;
        min-height: 100vh !important;
    }
    
    body:not(.mobile-menu-open) {
        overflow-y: auto !important;
        position: relative !important;
    }
    
    html, body {
        width: 100%;
        overflow-x: hidden;
    }
    
    /* Wyłącz transition na scrollowaniu */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }
    
    /* Wyłącz pseudo-elementy z animacjami */
    .category-card::before,
    .product-card::before,
    .achievement-item::before,
    .recent-post-item::after,
    .category-item::before,
    .parent-category::before,
    .subcategory-item::before,
    .filter-btn::before,
    .admin-tab::before,
    .stat-card::before,
    .post-card::before,
    .category-header::before,
    .admin-header::before {
        display: none !important;
    }
    
    /* Uproszczone transitions */
    .btn,
    .card,
    .post-card,
    .product-card,
    .category-card,
    .parent-category,
    .subcategory-item,
    .filter-btn,
    .admin-tab,
    .stat-card {
        transition: opacity 0.1s ease !important;
    }
    
    /* Disable transform animations */
    .btn:hover,
    .card:hover,
    .post-card:hover,
    .parent-category:hover,
    .subcategory-item:hover,
    .filter-btn:hover {
        transform: none !important;
    }
    
    /* Optymalizuj fixed elements */
    .mobile-menu-btn,
    .landing-nav,
    .forum-nav {
        position: fixed;
    }
    
    /* CRITICAL FIX: Force mobile menu button to be visible and clickable */
    .mobile-menu-btn {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        position: fixed !important;
        top: 5px !important;
        left: 10px !important;
        width: 48px !important;
        height: 48px !important;
        background: var(--bg-secondary) !important;
        border: 2px solid var(--accent-primary) !important;
        border-radius: 12px !important;
        color: var(--text-primary) !important;
        cursor: pointer !important;
        box-shadow: 0 4px 12px rgba(88, 166, 255, 0.4) !important;
        align-items: center !important;
        justify-content: center !important;
        transition: all 0.2s ease !important;
        -webkit-tap-highlight-color: rgba(88, 166, 255, 0.3) !important;
    }
    
    .mobile-menu-btn:active {
        background: var(--accent-primary) !important;
        transform: scale(0.9) !important;
    }
    
    .mobile-menu-btn svg {
        display: block !important;
        pointer-events: none !important;
    }
    
    /* Smooth scroll behavior */
    html {
        scroll-behavior: auto !important; /* Wyłącz smooth scroll - powoduje lag */
        -webkit-overflow-scrolling: touch;
    }
    
    /* Wyłącz ciężkie shadows na mobile */
    .card,
    .post-card,
    .product-card,
    .category-card,
    .achievement-item {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2) !important;
    }
    
    /* Optymalizuj images */
    img {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        image-rendering: -webkit-optimize-contrast;
    }
    
    /* Wyłącz hover effects na mobile */
    .btn:hover,
    .card:hover,
    .post-card:hover,
    .product-card:hover {
        transform: none !important;
    }
    
    /* Fix dla modal scrolling */
    .modal {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Prevent rubber band effect - ONLY when modal is open */
    body.modal-open {
        position: fixed !important;
        width: 100% !important;
        height: 100vh !important;
        overflow: hidden !important;
        top: 0;
        left: 0;
    }
    
    /* Optymalizuj sidebar drawer */
    .mobile-drawer {
        transform: translateX(-300px);
        transition: transform 0.2s ease;
    }
    
    .mobile-drawer.active {
        transform: translateX(0);
    }
    
    /* Fix dla infinite scroll */
    .posts-container,
    .marketplace-grid,
    .products-grid {
        contain: layout style paint;
    }
}

/* FIX 4: Lazy loading dla images (prevent lag) */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* FIX 5: Reduce motion dla users z preference */
@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;
    }
}

/* FIX 6: Prevent iOS zoom on input focus */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important; /* iOS nie zoomuje jeśli font >= 16px */
    }
}

/* FIX 7: Better touch targets */
@media (max-width: 768px) {
    button,
    a,
    input[type="submit"],
    .btn {
        min-height: 44px; /* iOS recommended touch target */
        min-width: 44px;
    }
}

/* FIX 8: Prevent overscroll bounce (rubber band) - but allow scrolling */
@media (max-width: 768px) {
    html {
        overscroll-behavior-y: contain;
        overscroll-behavior-x: none;
    }
    
    body:not(.mobile-menu-open):not(.modal-open) {
        overscroll-behavior-y: auto;
    }
}

/* FIX 9: Optimize z-index layers */
@media (max-width: 768px) {
    .app-sidebar { z-index: 9998 !important; }
    .mobile-sidebar-overlay { z-index: 9997 !important; }
    .mobile-menu-btn { z-index: 9999 !important; }
    .app-topbar { 
        z-index: 998 !important; 
        padding-left: 70px !important; /* Make space for hamburger button */
        left: 0 !important;
        top: 0 !important;
        height: 60px !important;
    }
    .modal { z-index: 10000 !important; }
    
    /* Ensure topbar doesn't cover the menu button */
    .topbar-right {
        margin-left: auto;
    }
    
    /* Make sure main-content has proper margin */
    .main-content {
        margin-top: 60px !important;
        padding-top: 20px !important;
    }
}

/* FIX 10: Performance monitoring hint */
/* Jeśli nadal jest lag, sprawdź:
   1. Chrome DevTools -> Performance
   2. Lighthouse -> Performance audit
   3. Wyłącz wszystkie browser extensions
*/



