/* ============================================
   COMPREHENSIVE RESPONSIVE FIXES
   Mobile-First Approach for All Pages
   ============================================ */

/* Global Mobile Fixes */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
}

* {
    box-sizing: border-box;
    max-width: 100%;
}

/* Container Responsive Fixes */
.container {
    width: 100%;
    max-width: 100%;
    padding: 0 1rem;
    margin: 0 auto;
    overflow-x: hidden;
}

/* ============================================
   PRODUCT DETAIL PAGE RESPONSIVE
   ============================================ */

/* Product Layout - Mobile First */
.product-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    align-items: start;
}

/* Product Gallery Mobile */
.product-gallery {
    position: relative !important;
    top: auto !important;
    order: 1;
}

.product-details {
    order: 2;
}

/* Action Buttons Mobile */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* Image Gallery Navigation - Mobile Friendly */
.main-image {
    position: relative;
}

.main-image button {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Thumbnail Gallery - Mobile Scroll */
.thumbnail-gallery {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 0.5rem 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.thumbnail-gallery::-webkit-scrollbar {
    display: none;
}

.thumbnail-gallery img {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
}

/* ============================================
   CHECKOUT PAGE RESPONSIVE
   ============================================ */

/* Checkout Layout - Mobile First */
.checkout-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

/* Order Summary Mobile */
.order-summary {
    position: relative !important;
    top: auto !important;
    order: 1;
    margin-bottom: 2rem;
}

.checkout-form {
    order: 2;
}

/* ============================================
   ACCOUNT PAGE RESPONSIVE
   ============================================ */

/* Account Layout - Mobile First */
.account-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

/* Account Sidebar Mobile */
.account-sidebar {
    order: 1;
    margin-bottom: 1rem;
}

.account-content {
    order: 2;
}

/* Account Navigation - Mobile Horizontal Scroll */
.account-nav {
    display: flex;
    overflow-x: auto;
    gap: 0.5rem;
    padding: 0.5rem 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.account-nav::-webkit-scrollbar {
    display: none;
}

.account-nav button {
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 44px;
    padding: 0.75rem 1rem;
}

/* Stats Grid Mobile */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* ============================================
   FORM RESPONSIVE FIXES
   ============================================ */

/* Form Elements Mobile */
.form-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    width: 100%;
}

input, select, textarea {
    width: 100%;
    min-height: 44px;
    padding: 0.75rem;
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 8px;
    border: 1px solid var(--color-border, #ddd);
}

button {
    min-height: 44px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
}

/* ============================================
   NAVIGATION RESPONSIVE FIXES
   ============================================ */

/* Mobile Menu */
.mobile-menu-toggle {
    display: block;
    background: none;
    border: none;
    font-size: 1.5rem;
    padding: 0.5rem;
    cursor: pointer;
}

.desktop-nav {
    display: none;
}

/* User Menu Mobile */
.user-menu-dropdown {
    position: fixed !important;
    top: 60px !important;
    right: 1rem !important;
    left: 1rem !important;
    width: auto !important;
    max-width: none !important;
    z-index: 9999;
}

/* ============================================
   TABLET RESPONSIVE (768px+)
   ============================================ */

@media (min-width: 768px) {
    .container {
        padding: 0 2rem;
    }
    
    /* Product Detail - Tablet */
    .product-layout {
        grid-template-columns: 1fr 1fr;
        gap: 2.5rem;
    }
    
    .product-gallery {
        position: sticky;
        top: 100px;
        order: 1;
    }
    
    .product-details {
        order: 2;
    }
    
    .action-buttons {
        grid-template-columns: 1fr 1fr;
    }
    
    .thumbnail-gallery img {
        width: 80px;
        height: 80px;
    }
    
    /* Checkout - Tablet */
    .checkout-layout {
        grid-template-columns: 1.2fr 1fr;
        gap: 2.5rem;
    }
    
    .order-summary {
        position: sticky;
        top: 100px;
        order: 2;
        margin-bottom: 0;
    }
    
    .checkout-form {
        order: 1;
    }
    
    /* Account - Tablet */
    .account-layout {
        grid-template-columns: 200px 1fr;
        gap: 2rem;
    }
    
    .account-sidebar {
        order: 1;
        margin-bottom: 0;
    }
    
    .account-content {
        order: 2;
    }
    
    .account-nav {
        flex-direction: column;
        overflow-x: visible;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Form - Tablet */
    .form-row {
        flex-direction: row;
        align-items: end;
    }
    
    /* Navigation - Tablet */
    .mobile-menu-toggle {
        display: none;
    }
    
    .desktop-nav {
        display: flex;
    }
    
    .user-menu-dropdown {
        position: absolute !important;
        top: 100% !important;
        right: 0 !important;
        left: auto !important;
        width: 250px !important;
    }
}

/* ============================================
   DESKTOP RESPONSIVE (1024px+)
   ============================================ */

@media (min-width: 1024px) {
    .container {
        padding: 0 3rem;
        max-width: 1400px;
    }
    
    /* Product Detail - Desktop */
    .product-layout {
        gap: 3rem;
    }
    
    .product-gallery {
        top: 120px;
    }
    
    /* Checkout - Desktop */
    .checkout-layout {
        grid-template-columns: 1.5fr 1fr;
        gap: 3rem;
    }
    
    /* Account - Desktop */
    .account-layout {
        grid-template-columns: 250px 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================================
   LARGE DESKTOP (1280px+)
   ============================================ */

@media (min-width: 1280px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   MOBILE SPECIFIC FIXES
   ============================================ */

@media (max-width: 767px) {
    /* Typography Mobile */
    h1 {
        font-size: 2rem !important;
        line-height: 1.2;
        margin-bottom: 1rem;
    }
    
    h2 {
        font-size: 1.5rem !important;
        line-height: 1.3;
        margin-bottom: 0.75rem;
    }
    
    h3 {
        font-size: 1.25rem !important;
        line-height: 1.4;
        margin-bottom: 0.5rem;
    }
    
    /* Spacing Mobile */
    .container {
        padding: 0 1rem;
    }
    
    main {
        padding: 2rem 0 !important;
    }
    
    /* Buttons Mobile */
    .btn {
        width: 100%;
        justify-content: center;
        padding: 1rem;
        font-size: 1rem;
    }
    
    /* Cards Mobile */
    .card {
        margin-bottom: 1rem;
        border-radius: 12px;
    }
    
    /* Tables Mobile */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
    
    /* Modal Mobile */
    .modal {
        margin: 1rem;
        max-width: calc(100vw - 2rem);
    }
    
    /* Sticky Elements Mobile */
    .sticky-mobile {
        position: relative !important;
        top: auto !important;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Touch-friendly buttons */
    button, .btn, a[role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    *:hover {
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Improve touch scrolling */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION FIXES
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce header height in landscape */
    .site-header {
        min-height: 50px;
    }
    
    /* Adjust sticky positioning */
    .product-gallery {
        position: relative !important;
        top: auto !important;
    }
    
    .order-summary {
        position: relative !important;
        top: auto !important;
    }
}

/* ============================================
   HIGH DPI DISPLAY OPTIMIZATIONS
   ============================================ */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Crisp borders on high DPI */
    .border-thin {
        border-width: 0.5px;
    }
    
    /* Optimize images */
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Focus indicators */
*:focus {
    outline: 2px solid var(--color-accent-primary, #007bff);
    outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--color-accent-primary, #007bff);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 10000;
}

.skip-link:focus {
    top: 6px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}