/* ==========================================
   IPHONE OPTIMIZATION - BASE SETUP
   ========================================== */

/* Critical: Prevent zooming and ensure proper scaling */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Smooth scrolling for iOS */
    -webkit-overflow-scrolling: touch;
}

body {
    margin: 0;
    padding: 0;
    /* Prevent horizontal scroll */
    overflow-x: hidden;
    width: 100%;
    /* Better font rendering on iOS */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}


/* ==========================================
   IPHONE 5/SE (320px) SPECIFIC
   ========================================== */
@media only screen and (max-width: 374px) {
    /* Page container */
    .page-container {
        padding: 10px;
        max-width: 100%;
    }

    /* Header adjustments */
    .page-header {
        margin-bottom: 15px;
    }

    .page-title {
        font-size: 1.25rem;
        line-height: 1.3;
    }

    .products-count {
        font-size: 0.8rem;
    }

    /* Breadcrumb */
    .breadcrumb {
        font-size: 12px;
        margin-bottom: 12px;
    }

    /* Filter toggle button */
    .mobile-filter-toggle {
        padding: 10px;
        font-size: 0.9rem;
        margin-bottom: 15px;
    }

    /* Toolbar */
    .toolbar {
        flex-direction: column;
        gap: 10px;
        padding-bottom: 12px;
        margin-bottom: 15px;
    }

    .results-info {
        font-size: 0.85rem;
    }

    .sort-options {
        width: 100%;
    }

    .sort-options select {
        width: 100%;
        padding: 8px 10px;
        font-size: 13px;
    }

    /* Products Grid */
    .products-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Product Cards */
    .product-card {
        padding: 10px;
        border-radius: 8px;
    }

    .product-image-container {
        height: 160px;
        margin-bottom: 10px;
    }

    .product-category {
        font-size: 0.7rem;
        padding: 3px 8px;
        margin-bottom: 6px;
    }

    .product-name {
        font-size: 0.9rem;
        margin-bottom: 6px;
        min-height: 2.4em;
    }

    .product-summary {
        font-size: 0.75rem;
        margin-bottom: 8px;
        -webkit-line-clamp: 2;
    }

    .product-price {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    .product-meta {
        font-size: 0.75rem;
        margin-bottom: 10px;
    }

    .product-actions {
        gap: 6px;
    }

    .btn {
        padding: 8px;
        font-size: 0.8rem;
    }

    .btn-secondary {
        padding: 8px 10px;
    }

    /* Filter Sidebar */
    .filters-sidebar {
        width: 85%;
        max-width: 280px;
        padding: 15px;
    }

    .filter-header h2 {
        font-size: 1.1rem;
    }

    .filter-title {
        font-size: 0.9rem;
        margin-bottom: 10px;
    }

    .filter-option {
        padding: 8px;
        font-size: 0.85rem;
    }

    .search-box input {
        padding: 10px 40px 10px 12px;
        font-size: 13px;
    }

    /* Empty State */
    .empty-state {
        padding: 40px 15px;
    }

    .empty-state i {
        font-size: 48px;
    }

    .empty-state h3 {
        font-size: 1.2rem;
    }

    .empty-state p {
        font-size: 0.9rem;
    }

    /* Section headers */
    .section-header {
        margin-bottom: 15px;
        padding-bottom: 10px;
    }

    .section-title {
        font-size: 1.15rem;
    }

    .view-all-link {
        font-size: 0.85rem;
    }

    /* Slider wrapper */
    .slider-wrapper {
        padding: 15px 8px;
        border-radius: 8px;
    }

    /* Slick slider adjustments */
    .product-slider .slick-slide {
        padding: 0 4px;
    }

    .product-slider .slick-list {
        margin: 0 -4px;
    }

    .product-slider .slick-dots {
        bottom: -20px;
    }

    .product-slider .slick-dots li button {
        width: 8px;
        height: 8px;
    }

    .product-slider .slick-dots li.slick-active button {
        width: 18px;
    }

    /* Product card in slider */
    .carousel-item .product-card {
        padding: 8px;
    }

    .carousel-item .product-img-wrapper {
        height: 140px;
        margin-bottom: 8px;
    }

    .carousel-item .product-title {
        font-size: 11px;
        min-height: 32px;
        margin-bottom: 6px;
    }

    .carousel-item .current-price {
        font-size: 14px;
    }

    .carousel-item .product-rating {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .carousel-item .add-to-cart {
        font-size: 10px;
        padding: 6px 8px;
    }

    .carousel-item .wishlist {
        width: 32px;
        padding: 6px;
        font-size: 12px;
    }
}

/* ==========================================
   IPHONE 6/7/8 (375px) SPECIFIC
   ========================================== */
@media only screen and (min-width: 375px) and (max-width: 413px) {
    .page-container {
        padding: 12px;
    }

    .page-title {
        font-size: 1.35rem;
    }

    .products-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .product-card {
        padding: 12px;
    }

    .product-image-container {
        height: 180px;
    }

    .product-name {
        font-size: 0.95rem;
    }

    .product-price {
        font-size: 1.2rem;
    }

    /* Slider adjustments */
    .carousel-item .product-img-wrapper {
        height: 160px;
    }

    .carousel-item .product-title {
        font-size: 12px;
    }

    .carousel-item .current-price {
        font-size: 15px;
    }
}

/* ==========================================
   IPHONE 6/7/8 PLUS (414px) SPECIFIC
   ========================================== */
@media only screen and (min-width: 414px) and (max-width: 575px) {
    .page-container {
        padding: 15px;
    }

    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .product-card {
        padding: 10px;
    }

    .product-image-container {
        height: 160px;
    }

    .product-name {
        font-size: 0.85rem;
    }

    .product-summary {
        font-size: 0.75rem;
    }

    .product-price {
        font-size: 1.15rem;
    }

    .btn {
        padding: 8px;
        font-size: 0.8rem;
    }

    /* Keep single column for sliders on Plus */
    .carousel-item .product-card {
        padding: 10px;
    }
}

/* ==========================================
   SAFARI MOBILE SPECIFIC FIXES
   ========================================== */

/* Fix for iOS input zoom */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="tel"],
select,
textarea {
    font-size: 16px !important; /* Prevents zoom on focus */
}

/* Fix Safari's bottom bar covering content */
.page-container {
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* Prevent text inflation on landscape */
@media (orientation: landscape) {
    body {
        -webkit-text-size-adjust: 100%;
    }
}

/* ==========================================
   TOUCH OPTIMIZATION
   ========================================== */

/* Larger touch targets for mobile */
@media (max-width: 576px) {
    .btn,
    .filter-option,
    button,
    a.clear-filters-btn {
        min-height: 44px; /* Apple's recommended minimum */
        min-width: 44px;
    }

    .product-actions .btn {
        min-height: 40px;
    }

    /* Navigation arrows */
    .slick-prev,
    .slick-next {
        min-width: 44px;
        min-height: 44px;
    }

    /* Filter checkboxes and options */
    .filter-option {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Search button */
    .search-box button {
        min-width: 44px;
        min-height: 44px;
    }
}

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

/* Reduce animations on older devices */
@media (max-width: 576px) {
    * {
        /* Simpler transitions for better performance */
        transition-duration: 0.2s !important;
    }

    .product-card:hover {
        /* Reduce transform on hover for performance */
        transform: translateY(-2px);
    }

    .product-img {
        /* Disable image scaling on older devices */
        transform: none !important;
    }
}

/* Use GPU acceleration */
.product-card,
.filters-sidebar,
.btn {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ==========================================
   IMAGE OPTIMIZATION FOR MOBILE
   ========================================== */

@media (max-width: 576px) {
    /* Optimize image rendering */
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }

    .product-image,
    .product-img {
        /* Better image quality on retina */
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* ==========================================
   PREVENT LAYOUT SHIFTS
   ========================================== */

/* Reserve space for images */
.product-image-container,
.product-img-wrapper {
    position: relative;
}

.product-image-container::before,
.product-img-wrapper::before {
    content: '';
    display: block;
    padding-top: 100%; /* 1:1 aspect ratio */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}

.product-image,
.product-img {
    /* position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; */
}

/* ==========================================
   ORIENTATION CHANGES
   ========================================== */

@media (max-width: 767px) and (orientation: landscape) {
    .page-header {
        margin-bottom: 15px;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .product-card {
        padding: 8px;
    }

    .product-image-container {
        height: 140px;
    }

    .product-name {
        font-size: 0.8rem;
        -webkit-line-clamp: 2;
    }

    .product-summary {
        display: none; /* Hide to save space */
    }
}

/* ==========================================
   NOTCH/SAFE AREA SUPPORT (iPhone X+)
   ========================================== */

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

    .page-container {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .filters-sidebar {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
}

/* ==========================================
   SCROLLING OPTIMIZATION
   ========================================== */

@media (max-width: 576px) {
    /* Smooth scrolling */
    .filters-sidebar,
    .main-content {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }

    /* Momentum scrolling */
    .products-grid {
        -webkit-overflow-scrolling: touch;
    }
}

/* ==========================================
   PREVENT ACCIDENTAL ACTIONS
   ========================================== */

/* Prevent double-tap zoom */
button,
a,
.btn {
    touch-action: manipulation;
}

/* Prevent text selection on buttons */
.btn,
button,
.product-card {
    -webkit-user-select: none;
    user-select: none;
}

/* Allow text selection in content */
.product-name,
.product-summary,
.product-price {
    -webkit-user-select: text;
    user-select: text;
}

/* ==========================================
   LOADING STATES FOR SLOW CONNECTIONS
   ========================================== */

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

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

/* ==========================================
   DARK MODE SUPPORT (iOS 13+)
   ========================================== */

@media (prefers-color-scheme: dark) {
    /* Optional: Add dark mode styles if needed */
    /* Uncomment and customize as needed
    body {
        background: #1a1a1a;
        color: #ffffff;
    }

    .product-card {
        background: #2c2c2c;
        border-color: #404040;
    }
    */
}

/* ==========================================
   REDUCED MOTION (Accessibility)
   ========================================== */

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