/* ========================================
   RESPONSIVE FIXES - COMPREHENSIVE PATCH
   Apply mobile-first responsive design
   ======================================== */

/* ========================================
   1. TOUCH TARGET IMPROVEMENTS
   All interactive elements minimum 44x44px
   ======================================== */

@media (max-width: 768px) {

    /* Buttons */
    .btn {
        min-height: 48px;
        padding: 14px 24px;
        font-size: 16px;
        /* Prevent iOS zoom */
    }

    .btn-lg {
        min-height: 56px;
        padding: 18px 32px;
    }

    .btn-icon {
        width: 48px;
        height: 48px;
    }

    /* Links and nav items */
    .mobile-nav a {
        min-height: 56px;
        display: flex;
        align-items: center;
        padding: 16px 0;
        font-size: 16px;
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        min-height: 48px;
        padding: 12px 16px;
        font-size: 16px;
        /* Prevent iOS zoom */
    }

    textarea {
        min-height: 120px;
    }

    /* Product action buttons */
    .action-btn {
        width: 48px;
        height: 48px;
    }

    /* Quantity controls */
    .qty-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .qty-input {
        min-height: 44px;
        min-width: 60px;
    }
}

/* ========================================
   2. PRODUCT GRID RESPONSIVENESS
   Mobile-first approach with proper breakpoints
   ======================================== */

.products-grid {
    display: grid;
    grid-template-columns: 1fr;
    /* Mobile: 1 column */
    gap: 20px;
    width: 100%;
}

/* Tablet: 2 columns */
@media (min-width: 481px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;
    }
}

/* Small Desktop: 3 columns */
@media (min-width: 769px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 30px;
    }
}

/* Desktop: 4 columns */
@media (min-width: 1025px) {
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 34px;
    }
}

/* Specific grid variations */
.products-grid-3 {
    grid-template-columns: 1fr;
}

@media (min-width: 481px) {
    .products-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 769px) {
    .products-grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.products-grid-4 {
    grid-template-columns: 1fr;
}

@media (min-width: 481px) {
    .products-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 769px) {
    .products-grid-4 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1025px) {
    .products-grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ========================================
   3. IMAGE RESPONSIVENESS
   ======================================== */

/* Global image fixes */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Product card images with consistent aspect ratio */
.product-image {
    position: relative;
    width: 100%;
    aspect-ratio: 5 / 6;
    /* Use modern aspect-ratio instead of padding-top */
    overflow: hidden;
    background: #F8F9FA;
}

/* Fallback for older browsers */
@supports not (aspect-ratio: 1) {
    .product-image {
        padding-top: 120%;
        /* 5:6 aspect ratio fallback */
        height: 0;
    }

    .product-image img {
        position: absolute;
        top: 0;
        left: 0;
    }
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Remove fixed heights from product cards */
.product-card {
    min-height: auto;
    /* Was: min-height: 480px */
    height: auto;
}

@media (min-width: 769px) {
    .product-card {
        min-height: 460px;
        /* Only on desktop for consistency */
    }
}

/* ========================================
   3b. PRODUCT PAGE RESPONSIVENESS
   ======================================== */

@media (max-width: 768px) {
    .product-details {
        grid-template-columns: 1fr;
        gap: 30px;
    }

    .product-gallery {
        position: static;
        /* Remove sticky on mobile */
        margin-bottom: 20px;
    }
}

/* ========================================
   4. HEADER & NAVIGATION MOBILE
   ======================================== */

@media (max-width: 992px) {
    .header-content {
        flex-wrap: wrap;
        gap: 15px;
    }

    /* Hide search and call on mobile */
    .header-center,
    .header-call {
        display: none;
    }

    /* Logo takes priority */
    .logo {
        order: 1;
        flex: 0 0 auto;
    }

    /* Icons and toggle on right */
    .header-right {
        order: 2;
        margin-left: auto;
    }

    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        font-size: 24px;
        color: var(--text-dark);
        background: none;
        border: none;
        cursor: pointer;
        order: 3;
    }

    /* Navigation bar - hide on mobile */
    .nav-bar {
        display: none;
    }
}

@media (max-width: 768px) {
    .main-header {
        padding: 12px 0;
    }

    .logo-text {
        font-size: 20px !important;
    }

    .logo-subtitle {
        font-size: 10px !important;
    }

    .header-icons {
        gap: 8px;
    }

    .header-icon-btn {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .icon-label {
        display: none;
        /* Hide text labels on mobile */
    }

    .icon-badge {
        top: -4px;
        right: -4px;
        width: 18px;
        height: 18px;
        font-size: 10px;
    }
}

/* Mobile menu styling */
.mobile-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    max-width: 85vw;
    height: 100vh;
    background: var(--bg-white);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-menu.active {
    transform: translateX(0);
}

/* Mobile menu overlay */
.mobile-menu::before {
    content: '';
    position: fixed;
    top: 0;
    left: -100vw;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: -1;
}

.mobile-menu.active::before {
    opacity: 1;
    pointer-events: all;
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    font-size: 18px;
}

.mobile-menu-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--text-dark);
    background: none;
    border: none;
    cursor: pointer;
}

.mobile-nav ul {
    padding: 0;
    list-style: none;
}

.mobile-nav li {
    border-bottom: 1px solid var(--border-color);
}

.mobile-nav a {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    font-weight: 500;
    font-size: 16px;
    color: var(--text-dark);
    text-decoration: none;
    min-height: 56px;
    transition: background 0.2s ease;
}

.mobile-nav a:hover {
    background: var(--bg-light);
    color: var(--secondary-color);
}

/* ========================================
   5. FORM & INPUT RESPONSIVENESS
   ======================================== */

@media (max-width: 768px) {

    /* Stack form rows */
    .form-row {
        flex-direction: column;
        gap: 20px;
    }

    .form-group {
        width: 100%;
    }

    /* Full-width buttons */
    .btn-block,
    .checkout-form .btn,
    .cart-summary .btn {
        width: 100%;
        justify-content: center;
    }

    /* Form sections */
    .form-section {
        padding: 20px;
        margin-bottom: 20px;
    }

    .section-header h2 {
        font-size: 20px;
    }
}

/* ========================================
   6. TABLE RESPONSIVENESS
   ======================================== */

@media (max-width: 768px) {

    /* Hide desktop table, show mobile cards */
    .cart-table-wrapper {
        display: none;
    }

    .cart-mobile {
        display: block;
    }

    /* Admin tables - horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 20px;
        border: 1px solid var(--border-color);
        border-radius: 4px;
    }

    table {
        min-width: 600px;
        /* Force horizontal scroll for complex tables */
        font-size: 14px;
    }

    table th,
    table td {
        padding: 10px 8px;
        white-space: nowrap;
    }
}

@media (min-width: 769px) {
    .cart-mobile {
        display: none;
    }

    .cart-table-wrapper {
        display: block;
    }
}

/* ========================================
   7. MODAL & DIALOG MOBILE
   ======================================== */

@media (max-width: 768px) {

    .modal,
    .quick-view-modal,
    .dialog {
        max-width: calc(100% - 32px);
        margin: 16px;
        max-height: calc(100vh - 32px);
        overflow-y: auto;
    }

    .modal-content {
        padding: 20px;
    }

    .modal-header {
        padding: 16px 20px;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-footer {
        padding: 16px 20px;
        flex-direction: column;
        gap: 12px;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

/* ========================================
   8. HERO & BANNER MOBILE
   ======================================== */

@media (max-width: 768px) {
    .hero-section {
        height: 400px;
    }

    .hero-content {
        height: 400px;
        padding: 0 20px;
    }

    .hero-title {
        font-size: 32px;
        line-height: 1.2;
    }

    .hero-subtitle {
        font-size: 14px;
    }

    .hero-description {
        font-size: 16px;
    }

    .hero-prev,
    .hero-next {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .hero-prev {
        left: 10px;
    }

    .hero-next {
        right: 10px;
    }
}

@media (max-width: 480px) {
    .hero-section {
        height: 350px;
    }

    .hero-content {
        height: 350px;
    }

    .hero-title {
        font-size: 28px;
    }
}

/* ========================================
   9. SHOP FILTERS MOBILE
   ======================================== */

@media (max-width: 992px) {
    .shop-layout {
        flex-direction: column;
    }

    .shop-sidebar {
        width: 100%;
        position: relative;
        top: 0;
        margin-bottom: 30px;
    }

    .shop-main {
        width: 100%;
    }

    /* Collapsible filters on mobile */
    .filter-toggle {
        display: block;
        width: 100%;
        background: var(--primary-color);
        color: white;
        padding: 14px 20px;
        border: none;
        border-radius: 4px;
        font-size: 16px;
        font-weight: 500;
        cursor: pointer;
        margin-bottom: 20px;
    }

    .shop-sidebar.collapsed .sidebar-widgets {
        display: none;
    }
}

/* Shop filter option row layout (prevents label/count overlap) */
.shop-sidebar .sidebar-widget .color-filter .color-option,
.shop-sidebar .sidebar-widget .size-filter .size-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    width: 100%;
}

.shop-sidebar .sidebar-widget .color-filter .color-swatch {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    display: inline-block;
    border: 1px solid #ddd;
    flex: 0 0 16px;
}

.shop-sidebar .sidebar-widget .filter-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shop-sidebar .sidebar-widget .filter-count {
    flex: 0 0 auto;
    margin-left: auto;
    color: var(--text-light);
    font-size: 0.9em;
    white-space: nowrap;
}

.shop-sidebar .sidebar-widget .size-filter .size-option {
    justify-content: space-between;
}

.shop-sidebar .sidebar-widget .size-filter .size-option-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
}

@media (max-width: 480px) {
    .shop-sidebar .sidebar-widget .filter-label {
        white-space: normal;
        overflow: visible;
        text-overflow: initial;
    }
}

/* ========================================
   10. CHECKOUT MOBILE OPTIMIZATION
   ======================================== */

@media (max-width: 768px) {
    .checkout-layout {
        flex-direction: column;
    }

    .checkout-form-section,
    .checkout-summary {
        width: 100%;
    }

    .checkout-steps {
        flex-wrap: wrap;
        gap: 10px;
        padding: 20px 0;
    }

    .step {
        flex: 1 1 calc(50% - 5px);
        min-width: 140px;
    }

    .step-number {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .step-label {
        font-size: 12px;
    }

    .saved-addresses {
        flex-direction: column;
    }

    .saved-address-card {
        width: 100%;
    }
}

/* ========================================
   11. PRODUCT DETAIL MOBILE
   ======================================== */

@media (max-width: 768px) {
    .product-detail-layout {
        flex-direction: column;
    }

    .product-gallery,
    .product-info {
        width: 100%;
    }

    .product-thumbnails {
        justify-content: center;
        overflow-x: auto;
    }

    .product-title {
        font-size: 24px;
    }

    .product-price {
        font-size: 28px;
    }

    .product-tabs {
        flex-direction: column;
    }

    .tab-btn {
        width: 100%;
        text-align: left;
        border-bottom: 1px solid var(--border-color);
        border-radius: 0;
    }
}

/* ========================================
   12. FOOTER MOBILE
   ======================================== */

@media (max-width: 768px) {
    .footer-content {
        display: flex;
        flex-direction: column;
        text-align: center;
    }

    .footer-column {
        width: 100%;
        margin-bottom: 30px;
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }

    .footer-links {
        flex-direction: column;
        gap: 10px;
    }
}

/* ========================================
   13. UTILITY CLASSES FOR RESPONSIVE
   ======================================== */

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Hide on desktop */
@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block;
    }
}

/* Responsive text alignment */
@media (max-width: 768px) {
    .text-center-mobile {
        text-align: center;
    }

    .text-left-mobile {
        text-align: left;
    }
}

/* ========================================
   14. NOTIFICATION BAR MOBILE
   ======================================== */

@media (max-width: 768px) {
    .notification-bar {
        font-size: 12px;
        padding: 8px 0;
    }

    .notification-text {
        padding: 0 15px;
    }
}

/* ========================================
   15. PREVENT HORIZONTAL SCROLL
   Critical fix for mobile overflow
   ======================================== */

html {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
}

* {
    box-sizing: border-box;
}

/* Ensure all containers respect viewport width */
.shop-layout,
.checkout-layout {
    max-width: 100%;
    overflow-x: hidden;
}

/* Prevent horizontal overflow on sections and main */
section,
main {
    max-width: 100%;
    /* Use 'hidden' instead of 'clip' to maintain sticky positioning compatibility */
    overflow-x: hidden;
}

/* Fix for images and media */
img,
video,
iframe,
svg {
    max-width: 100%;
    height: auto;
}

/* ========================================
   16. PAGE-SPECIFIC RESPONSIVE FIXES
   (Moves critical inline layouts into CSS)
   ======================================== */

/* Order tracking */
.order-tracking-tracking {
    margin-top: 30px;
    padding: 20px;
    background: var(--bg-light);
    border-radius: 12px;
}

.order-tracking-tracking-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.order-tracking-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    margin-top: 40px;
    align-items: start;
}

.order-tracking-items-card {
    background: var(--bg-white);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.order-tracking-item {
    display: flex;
    gap: 20px;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.order-tracking-item:last-child {
    border-bottom: none;
}

.order-tracking-item-image {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    flex: 0 0 auto;
}

.order-tracking-item-info {
    flex: 1 1 auto;
    min-width: 0;
}

.order-tracking-item-price {
    text-align: right;
    flex: 0 0 auto;
}

.order-tracking-card {
    background: var(--bg-white);
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.order-tracking-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

@media (max-width: 992px) {
    .order-tracking-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 576px) {
    .order-tracking-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .order-tracking-item-image {
        width: 120px;
        height: 120px;
        max-width: 100%;
    }

    .order-tracking-item-price {
        text-align: left;
    }
}

/* ========================================
   17. PRODUCT PAGE MOBILE RESPONSIVENESS
   Comprehensive fixes for product.php
   ======================================== */

/* Product section padding on mobile */
@media (max-width: 768px) {
    .product-section {
        padding: 40px 0;
    }
}

/* Product details grid - stack on mobile */
@media (max-width: 768px) {
    .product-details {
        display: flex;
        flex-direction: column;
        gap: 30px;
        margin: 20px 0;
    }
}

/* Product Gallery Mobile Fixes */
@media (max-width: 768px) {
    .product-gallery {
        position: relative;
        top: auto;
        width: 100%;
        max-width: 100%;
    }
    
    .main-image {
        height: auto;
        max-height: 400px;
        aspect-ratio: 1 / 1;
        width: 100%;
        margin-bottom: 15px;
    }
    
    .main-image img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        background: #f8f9fa;
    }
    
    .image-zoom-icon {
        width: 40px;
        height: 40px;
        top: 10px;
        right: 10px;
    }
    
    .thumbnail-images {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 5px;
    }
    
    .thumbnail {
        height: 70px;
        min-width: 70px;
        flex-shrink: 0;
    }
}

/* Even smaller screens */
@media (max-width: 480px) {
    .main-image {
        max-height: 320px;
    }
    
    .thumbnail-images {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .thumbnail {
        height: 60px;
        min-width: 60px;
    }
}

/* Product Info Mobile Fixes */
@media (max-width: 768px) {
    .product-info-detail {
        padding: 0;
        width: 100%;
    }
    
    .product-badge-group {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 12px;
    }
    
    .badge {
        padding: 4px 12px;
        font-size: 11px;
    }
    
    .product-name {
        font-size: 24px;
        line-height: 1.3;
        margin-bottom: 12px;
        word-wrap: break-word;
    }
    
    .product-price-detail {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .current-price {
        font-size: 28px;
    }
    
    .original-price {
        font-size: 18px;
    }
    
    .discount-badge {
        padding: 4px 10px;
        font-size: 12px;
    }
    
    .product-description {
        font-size: 14px;
        line-height: 1.7;
        margin-bottom: 15px;
    }
    
    .product-features ul {
        margin-bottom: 20px;
    }
    
    .product-features li {
        font-size: 14px;
        gap: 8px;
        margin-bottom: 8px;
    }
}

/* Product Options Mobile */
@media (max-width: 768px) {
    .product-options {
        margin-bottom: 20px;
    }
    
    .option-group {
        margin-bottom: 20px;
    }
    
    .option-group label {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    .quantity-selector {
        width: 100%;
        max-width: 200px;
    }
    
    .qty-btn {
        width: 44px;
        height: 44px;
    }
    
    .qty-input {
        flex: 1;
        height: 44px;
        min-width: 50px;
    }
}

/* Product Actions Mobile */
@media (max-width: 768px) {
    .product-actions-detail {
        flex-direction: column;
        gap: 12px;
        margin-bottom: 25px;
    }
    
    .product-actions-detail .btn {
        width: 100%;
        justify-content: center;
        min-height: 50px;
    }
}

/* Product Meta Mobile */
@media (max-width: 768px) {
    .product-meta {
        padding: 20px 0;
    }
    
    .meta-item {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 10px;
        font-size: 14px;
    }
    
    .meta-item strong {
        min-width: 80px;
    }
    
    .social-share {
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .social-share a {
        width: 40px;
        height: 40px;
    }
}

/* Trust Badges Mobile */
@media (max-width: 768px) {
    .trust-badges {
        flex-direction: column;
        gap: 15px;
        padding: 20px;
        margin-top: 20px;
    }
    
    .trust-item {
        gap: 12px;
    }
    
    .trust-item i {
        font-size: 20px;
        min-width: 24px;
    }
    
    .trust-item span {
        font-size: 14px;
    }
}

/* Product Tabs Mobile */
@media (max-width: 768px) {
    .product-tabs {
        margin: 40px 0;
    }
    
    .tab-buttons {
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        padding-bottom: 0;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .tab-buttons::-webkit-scrollbar {
        display: none;
    }
    
    .tab-btn {
        flex-shrink: 0;
        padding: 12px 16px;
        font-size: 14px;
        white-space: nowrap;
        border-radius: 0;
        border-bottom: 2px solid transparent;
    }
    
    .tab-btn.active::after {
        bottom: -2px;
    }
    
    .tab-content {
        padding: 0;
    }
    
    .tab-pane h3 {
        font-size: 20px;
        margin-bottom: 15px;
    }
    
    .tab-pane h4 {
        font-size: 16px;
        margin: 15px 0 10px;
    }
    
    .tab-pane p,
    .tab-pane li {
        font-size: 14px;
        line-height: 1.7;
    }
    
    .specs-table {
        font-size: 14px;
    }
    
    .specs-table td {
        padding: 10px 8px;
    }
}

/* Breadcrumb Mobile */
@media (max-width: 768px) {
    .breadcrumb {
        font-size: 12px;
        flex-wrap: wrap;
        gap: 5px;
        margin-bottom: 15px;
        padding: 10px 0;
    }
    
    .breadcrumb span {
        margin: 0 3px;
    }
}

/* Related Products Mobile */
@media (max-width: 768px) {
    .related-products {
        padding: 40px 0;
    }
    
    .related-products h2 {
        font-size: 24px;
        margin-bottom: 20px;
    }
}

/* ========================================
   END OF RESPONSIVE FIXES
   ======================================== */