/* iOS Safari Styles - Оптимізовано */

@supports (-webkit-touch-callout: none) {
    /* Viewport Height Fix */
    :root {
        --vh: 1vh;
    }
    
    .vh-100 {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }
    
    /* Safe Area Support */
    .container {
        padding-left: max(var(--spacing-md), env(safe-area-inset-left));
        padding-right: max(var(--spacing-md), env(safe-area-inset-right));
    }
    
    .footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Touch Optimizations */
    .btn,
    .nav-link,
    .cart-link,
    .wishlist-link,
    .logo-img,
    .search-btn {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }
    
    /* Form Elements */
    input,
    select,
    textarea {
        font-size: 16px;
    }
    
    input[type="search"] {
        -webkit-appearance: none;
        appearance: none;
        border-radius: var(--border-radius-md);
    }
    
    input[type="radio"],
    input[type="checkbox"] {
        accent-color: var(--color-primary);
    }
    
    .btn {
        -webkit-appearance: none;
        appearance: none;
        border-radius: var(--border-radius-md);
    }
    
    select {
        -webkit-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 16px;
        padding-right: 40px;
    }
    
    /* Sliders */
    .categories-slider,
    .products-slider {
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        overscroll-behavior: contain;
    }
    
    .categories-slider .category-card,
    .products-slider .product-card {
        scroll-snap-align: start;
        scroll-snap-stop: normal;
    }
    
    /* Body */
    body {
        overscroll-behavior-x: none;
        overscroll-behavior-y: auto;
    }
    
    /* User Selection */
    .slider-btn,
    .hamburger,
    .nav-link,
    .btn {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    .category-name,
    .product-name,
    .section-title {
        -webkit-user-select: text;
        user-select: text;
    }
    
    /* Mobile Layout для iOS Safari */
    @media (max-width: 767.98px) {
        html,
        body {
            transform: none;
            perspective: none;
        }
        
        .auth-container {
            background: #f7f9fb;
            transform: none;
            perspective: none;
        }
        
        body {
            padding-top: 0;
            overflow-x: hidden;
            position: relative;
        }
        
        /* Main content з padding-top для header та padding-bottom для меню */
        main,
        .main-content {
            padding-top: 60px;
            min-height: 100vh;
            padding-bottom: calc(70px + env(safe-area-inset-bottom));
        }
        
        /* Фіксований Header */
        .header {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            width: 100%;
            z-index: 100;
        }
        
        .main-header {
            padding: var(--spacing-sm) 0;
        }
        
        .header-content {
            -webkit-tap-highlight-color: transparent;
            min-height: 60px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .logo-img {
            user-select: none;
            height: 48px;
            max-width: 160px;
        }
        
        .cart-link,
        .hamburger {
            -webkit-tap-highlight-color: rgba(255, 20, 147, 0.15);
            touch-action: manipulation;
            min-height: 48px;
            min-width: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .hamburger span {
            border-radius: 1px;
        }
        
        .cart-icon {
            font-size: 28px;
            line-height: 1;
        }
        
        /* Фіксоване нижнє меню - без transform для стабільності */
        .mobile-bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            width: 100%;
            pointer-events: auto;
            z-index: 1000;
            padding-bottom: env(safe-area-inset-bottom);
        }
        
        /* Padding для контенту щоб не перекривався з нижнім меню */
        .cart-section,
        .profile-container,
        .wishlist-section,
        main > section:last-child {
            padding-bottom: calc(70px + env(safe-area-inset-bottom));
        }
        
        /* Критичне виправлення для сторінок профілю */
        body.profile-page {
            min-height: 100vh;
            min-height: calc(var(--vh, 1vh) * 100);
        }
        
        body.profile-page .profile-container {
            padding-bottom: calc(90px + env(safe-area-inset-bottom));
        }
        
        body.profile-page .profile-actions {
            margin-bottom: calc(20px + env(safe-area-inset-bottom));
        }
    }
    
    @media (max-width: 575.98px) {
        main,
        .main-content {
            padding-top: 56px;
            padding-bottom: calc(80px + env(safe-area-inset-bottom));
        }
        
        .header-content {
            min-height: 56px;
        }
        
        .cart-section,
        .profile-container,
        .wishlist-section,
        main > section:last-child {
            padding-bottom: calc(80px + env(safe-area-inset-bottom));
        }
        
        body.profile-page .profile-container {
            padding-bottom: calc(100px + env(safe-area-inset-bottom));
        }
    }
    
    @media (max-width: 400px) {
        main,
        .main-content {
            padding-top: 52px;
            padding-bottom: calc(80px + env(safe-area-inset-bottom));
        }
        
        .header-content {
            min-height: 52px;
        }
    }
    
    /* Mobile Menu Optimizations */
    .mobile-menu {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
    }
    
    .mobile-menu-nav a {
        -webkit-tap-highlight-color: rgba(255, 20, 147, 0.1);
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        padding: var(--spacing-md);
        text-decoration: none;
    }
    
    .category-card,
    .product-card {
        -webkit-tap-highlight-color: rgba(255, 20, 147, 0.1);
        display: flex;
        flex-direction: column;
        text-align: center;
    }
    
    .btn {
        -webkit-tap-highlight-color: rgba(255, 20, 147, 0.2);
        min-height: 48px;
        min-width: 48px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        white-space: nowrap;
    }
    
    .category-name,
    .product-name {
        text-align: center;
        -webkit-user-select: text;
        user-select: text;
        word-break: break-word;
        hyphens: auto;
        -webkit-hyphens: auto;
    }
    
    .category-emoji,
    .product-emoji {
        font-size: 3rem;
        line-height: 1;
        display: block;
        text-align: center;
        width: 100%;
        font-family: "Apple Color Emoji", system-ui, sans-serif;
        font-variant-emoji: emoji;
        text-rendering: optimizeSpeed;
    }
    
    /* Footer iOS Optimizations */
    .footer-main {
        padding-bottom: env(safe-area-inset-bottom, var(--spacing-md));
    }
    
    .footer-main .container {
        padding-left: max(var(--spacing-sm), env(safe-area-inset-left));
        padding-right: max(var(--spacing-sm), env(safe-area-inset-right));
    }
    
    .footer-section {
        -webkit-tap-highlight-color: transparent;
    }
    
    .footer-links a {
        -webkit-tap-highlight-color: rgba(255, 215, 0, 0.1);
        touch-action: manipulation;
    }
    
    .footer-contact {
        -webkit-user-select: text;
        user-select: text;
    }
    
    .copyright,
    .footer-dev {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1a1a1a;
        --text-color: #ffffff;
        --border-color: #333333;
    }
    
    @supports (-webkit-touch-callout: none) {
        .card {
            background: #2a2a2a;
            border-color: #333333;
        }
        
        .category-placeholder,
        .product-placeholder {
            background: #333333;
            color: #666666;
        }
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    @supports (-webkit-touch-callout: none) {
        .categories-slider,
        .products-slider {
            scroll-behavior: auto;
        }
        
        .fade-in,
        .slide-in-up,
        .slider-btn,
        .cart-icon {
            animation: none;
            transition: none;
        }
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 500px) {
    @supports (-webkit-touch-callout: none) {
        .hero-section {
            height: auto;
            min-height: 100vh;
            min-height: calc(var(--vh, 1vh) * 100);
        }
        
        .section-padding {
            padding: var(--spacing-lg) 0;
        }
    }
}
