/* ============================================
   Responsive Styles
   ============================================ */

/* Large Desktop */
@media (max-width: 1400px) {
    .container {
        padding: 0 20px;
    }
    
    .categories-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .mega-menu {
        width: 100%;
    }
}

/* Desktop */
@media (max-width: 1200px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .footer-content {
        grid-template-columns: repeat(2, 1fr);
        gap: 40px;
    }
    
    .slide-text h1 {
        font-size: 40px;
    }
    
    .phone-3d {
        width: 180px;
        height: 360px;
    }
}

/* Tablet */
@media (max-width: 992px) {
    :root {
        --header-height: 64px;
    }
    
    .top-bar-links {
        display: none;
    }
    
    .search-bar {
        max-width: 400px;
    }
    
    .main-nav {
        display: none;
    }
    
    .mobile-menu-toggle {
        display: flex;
    }
    
    .categories-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }
    
    .category-card {
        padding: 24px 16px;
    }
    
    .category-icon {
        width: 60px;
        height: 60px;
    }
    
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    
    .features-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .slider-3d {
        height: 400px;
    }
    
    .slide-content {
        gap: 40px;
    }
    
    .slide-text h1 {
        font-size: 32px;
    }
    
    .slide-text p {
        font-size: 16px;
    }
    
    .slide-price .current-price {
        font-size: 28px;
    }
    
    .phone-3d {
        width: 150px;
        height: 300px;
    }
    
    .phone-front {
        border-radius: 30px;
    }
    
    .phone-screen {
        border-radius: 24px;
    }
    
    .phone-notch {
        width: 80px;
        height: 25px;
    }
    
    .floating-specs {
        display: none;
    }
    
    .deals-content h2 {
        font-size: 28px;
    }
    
    .countdown-item {
        padding: 12px 16px;
        min-width: 60px;
    }
    
    .countdown-value {
        font-size: 24px;
    }
    
    .mega-menu {
        display: none;
    }
    
    .bottom-nav {
        display: flex;
    }
    
    body {
        padding-bottom: 70px;
    }
}

/* Mobile Landscape */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }
    
    .header-content {
        gap: 16px;
    }
    
    .logo-text {
        font-size: 20px;
    }
    
    .search-bar {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        padding: 12px 16px;
        background: var(--surface-light);
        border-bottom: 1px solid var(--neutral-200);
        max-width: 100%;
        display: none;
    }
    
    .search-bar.active {
        display: block;
    }
    
    .header-actions {
        gap: 12px;
    }
    
    .header-action span {
        display: none;
    }
    
    .categories-section {
        padding: 40px 0;
    }
    
    .section-title {
        font-size: 22px;
        margin-bottom: 24px;
    }
    
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .category-card {
        padding: 20px 12px;
    }
    
    .category-icon {
        width: 50px;
        height: 50px;
    }
    
    .category-icon svg {
        width: 28px;
        height: 28px;
    }
    
    .category-card h3 {
        font-size: 13px;
    }
    
    .products-section {
        padding: 40px 0;
    }
    
    .slider-3d {
        height: auto;
        min-height: 500px;
    }
    
    .slide-content {
        flex-direction: column-reverse;
        text-align: center;
        padding: 30px 0;
    }
    
    .slide-text {
        max-width: 100%;
    }
    
    .slide-text h1 {
        font-size: 28px;
    }
    
    .slide-price {
        justify-content: center;
    }
    
    .slide-price .current-price {
        font-size: 24px;
    }
    
    .slide-text .btn-primary {
        width: 100%;
        justify-content: center;
    }
    
    .phone-3d {
        width: 120px;
        height: 240px;
    }
    
    .phone-front {
        border-radius: 24px;
    }
    
    .phone-screen {
        border-radius: 18px;
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: 8px;
    }
    
    .phone-notch {
        width: 60px;
        height: 20px;
        border-radius: 0 0 12px 12px;
    }
    
    .slider-controls {
        position: relative;
        bottom: 0;
        margin-top: 20px;
    }
    
    .deals-banner {
        padding: 50px 0;
    }
    
    .deals-content h2 {
        font-size: 22px;
    }
    
    .deals-content p {
        font-size: 14px;
    }
    
    .countdown {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .countdown-item {
        padding: 10px 14px;
        min-width: 50px;
    }
    
    .countdown-value {
        font-size: 20px;
    }
    
    .countdown-label {
        font-size: 10px;
    }
    
    .features-grid {
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }
    
    .feature-item {
        padding: 16px;
    }
    
    .feature-icon {
        width: 60px;
        height: 60px;
    }
    
    .feature-icon svg {
        width: 28px;
        height: 28px;
    }
    
    .feature-item h3 {
        font-size: 14px;
    }
    
    .feature-item p {
        font-size: 12px;
    }
    
    .footer-content {
        grid-template-columns: 1fr;
        gap: 32px;
    }
    
    .footer-bottom {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }
    
    .payment-methods {
        flex-direction: column;
        gap: 8px;
    }
    
    .cart-sidebar {
        width: 100%;
        left: -100%;
    }
    
    [dir="rtl"] .cart-sidebar {
        right: -100%;
    }
    
    .brands-slider {
        gap: 24px;
    }
    
    .brand-item {
        padding: 16px 24px;
    }
    
    .brand-logo {
        font-size: 16px;
    }
    
    .airpod-case {
        width: 140px;
        height: 120px;
        border-radius: 35px 35px 45px 45px;
    }
    
    .airpod {
        width: 14px;
        height: 40px;
        top: -35px;
    }
    
    .airpod.left {
        left: 35px;
    }
    
    .airpod.right {
        right: 35px;
    }
    
    .airpod::before {
        width: 4px;
        height: 25px;
        bottom: -22px;
    }
}

/* Mobile Portrait */
@media (max-width: 480px) {
    .logo-icon svg {
        width: 32px;
        height: 32px;
    }
    
    .logo-text {
        font-size: 18px;
    }
    
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .products-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .product-card {
        border-radius: var(--radius-sm);
    }
    
    .product-image {
        padding: 16px;
    }
    
    .product-placeholder {
        width: 80px;
        height: 130px;
        border-radius: 16px;
    }
    
    .product-info {
        padding: 12px;
    }
    
    .product-brand {
        font-size: 10px;
    }
    
    .product-title {
        font-size: 13px;
        margin: 4px 0;
    }
    
    .product-rating {
        margin-bottom: 8px;
    }
    
    .stars {
        font-size: 12px;
    }
    
    .rating-count {
        font-size: 10px;
    }
    
    .product-price {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        margin-bottom: 8px;
    }
    
    .current-price {
        font-size: 15px;
    }
    
    .old-price {
        font-size: 12px;
    }
    
    .add-to-cart {
        padding: 10px;
        font-size: 12px;
    }
    
    .add-to-cart span {
        display: none;
    }
    
    .product-badges {
        top: 8px;
        right: 8px;
    }
    
    [dir="ltr"] .product-badges {
        left: 8px;
    }
    
    .badge {
        padding: 3px 8px;
        font-size: 10px;
    }
    
    .product-actions {
        top: 8px;
        left: 8px;
    }
    
    [dir="rtl"] .product-actions {
        right: 8px;
    }
    
    .product-actions button {
        width: 32px;
        height: 32px;
    }
    
    .product-actions button svg {
        width: 16px;
        height: 16px;
    }
    
    .slide-text h1 {
        font-size: 24px;
    }
    
    .slide-text p {
        font-size: 14px;
        margin-bottom: 16px;
    }
    
    .slide-badge {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    .slider-btn {
        width: 40px;
        height: 40px;
    }
    
    .section-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    
    .section-header .section-title {
        text-align: right;
    }
    
    [dir="ltr"] .section-header .section-title {
        text-align: left;
    }
    
    /* .mobile-nav removed to avoid conflict with bottom bar */
    /*
    .mobile-nav {
        width: 280px;
        right: -280px;
    }
    
    [dir="ltr"] .mobile-nav {
        left: -280px;
    }
    */
    
    .bottom-nav-item span:not(.bottom-cart-count) {
        font-size: 10px;
    }
    
    .bottom-nav-item svg {
        width: 22px;
        height: 22px;
    }
}

/* Very Small Screens */
@media (max-width: 360px) {
    .container {
        padding: 0 12px;
    }
    
    .slide-text h1 {
        font-size: 20px;
    }
    
    .deals-content h2 {
        font-size: 18px;
    }
    
    .countdown-item {
        padding: 8px 10px;
        min-width: 45px;
    }
    
    .countdown-value {
        font-size: 18px;
    }
    
    .category-card h3 {
        font-size: 12px;
    }
    
    .category-count {
        font-size: 11px;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .slider-3d {
        min-height: 350px;
    }
    
    .slide-content {
        flex-direction: row;
        padding: 20px 0;
    }
    
    .slide-text h1 {
        font-size: 24px;
    }
    
    .phone-3d {
        width: 100px;
        height: 200px;
    }
    
    .bottom-nav {
        display: none;
    }
    
    body {
        padding-bottom: 0;
    }
}

/* Print styles */
@media print {
    .header,
    .main-nav,
    .bottom-nav,
    .cart-sidebar,
    .cart-overlay,
    .top-bar {
        display: none !important;
    }
    
    body {
        padding: 0;
        background: white;
    }
    
    .container {
        max-width: 100%;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .phone-3d,
    .airpods-3d {
        animation: none;
    }
    
    .slide-3d {
        transform: none;
    }
    
    .slide-3d.active {
        transform: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --primary-500: #d35400;
        --neutral-500: #333;
    }
    
    .product-card {
        border-width: 2px;
    }
    
    .btn-primary,
    .add-to-cart,
    .btn-checkout {
        border: 2px solid currentColor;
    }
}

/* ==========================================================================
   FIXES FOR MOBILE RESPONSIVENESS (SLIDER & PRODUCT GRID)
   ========================================================================== */

/* Fix for Main Slider on Mobile */
@media (max-width: 768px) {
    .hero-slider-3d {
        height: auto !important;
        min-height: 250px; /* Reasonable height for mobile */
        perspective: none !important; /* Disable 3D perspective */
    }
    
    .hero-slides-container {
        transform-style: flat !important;
        height: 250px; /* Match min-height or auto */
    }

    .hero-slide {
        width: 100% !important;
        left: 0 !important;
        height: 100% !important;
        border-radius: 12px !important;
        transform: none !important; /* Reset 3D transforms */
        opacity: 0;
        transition: opacity 0.5s ease;
        position: absolute;
        top: 0;
    }

    .hero-slide.active {
        opacity: 1;
        z-index: 2;
    }
    
    .hero-slide.prev,
    .hero-slide.next,
    .hero-slide.hidden {
        opacity: 0;
        z-index: 1;
    }

    .hero-slide img {
        width: 100% !important;
        height: 100% !important;
        border-radius: 12px !important;
        object-fit: cover !important;
        display: block !important;
    }
    
    /* Adjust content position */
    .hero-slide-content {
        padding: 1rem;
        text-align: center;
        bottom: 0;
        width: 100%;
    }
    
    .hero-slide-content h2 {
        font-size: 1.5rem;
    }
    
    .hero-buttons {
        justify-content: center;
    }
    
    .hero-arrows {
        padding: 0 10px;
    }
    
    .hero-arrows button {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}

/* ==========================================================================
   CRITICAL MOBILE FIXES - FINAL
   ========================================================================== */

@media (max-width: 992px) {
    /* GLOBAL OVERFLOW FIX - AGGRESSIVE */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        position: relative !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .container, .main-content, .products-section {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: hidden !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
        margin: 0 !important;
        display: block !important;
        box-sizing: border-box !important;
    }
    
    /* RESET GRID FOR MOBILE */
    .products-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    /* PRODUCT CARD SIZING & ALIGNMENT */
    .product-card {
        width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        background: var(--bg-primary);
        border-radius: 12px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
    }

    .product-image {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1/1 !important;
        max-height: none !important; /* Allow aspect ratio to control */
        position: relative !important;
    }
    
    .product-image img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        border-radius: 12px 12px 0 0 !important;
        display: block !important;
    }
    
    .product-info {
        padding: 10px !important;
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
        justify-content: space-between !important;
    }

    .product-name {
        font-size: 0.8rem !important;
        line-height: 1.3 !important;
        height: 2.6em !important; /* 2 lines */
        overflow: hidden !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        white-space: normal !important; /* Allow wrapping */
        margin-bottom: 6px !important;
        color: var(--text-primary) !important;
    }

    .product-price {
        font-size: 0.9rem !important;
        flex-wrap: wrap !important;
        margin-top: auto !important;
    }

    /* HEADER & FILTER BUTTONS */
    .products-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        padding: 10px 5px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .mobile-filter-toggle {
        width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 0 10px 0 !important;
    }

    /* SIDEBAR DRAWER - FORCE FIXED POSITION */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        height: 100vh !important;
        width: 85% !important;
        max-width: 300px !important;
        background: var(--bg-primary) !important;
        z-index: 9999 !important;
        transition: transform 0.3s ease !important;
        overflow-y: auto !important;
        box-shadow: 0 0 20px rgba(0,0,0,0.3) !important;
        display: block !important;
        /* RTL Support handled below */
    }

    /* RTL/LTR Sidebar Handling */
    html[dir="rtl"] .sidebar {
        right: 0 !important;
        left: auto !important;
        transform: translateX(100%) !important;
    }
    
    html[dir="ltr"] .sidebar {
        left: 0 !important;
        right: auto !important;
        transform: translateX(-100%) !important;
    }

    .sidebar.active {
        transform: translateX(0) !important;
    }
    
    /* Overlay */
    .sidebar-overlay {
        position: fixed !important;
        inset: 0 !important;
        background: rgba(0,0,0,0.5) !important;
        z-index: 9990 !important;
        display: none !important;
    }
    
    .sidebar-overlay.active {
        display: block !important;
    }
}

/* Fix for very small screens */
@media (max-width: 400px) {
    .products-grid {
        gap: 8px !important;
    }
    
    .product-name {
        font-size: 0.85rem !important;
    }
}

/* ==========================================================================
   PRODUCT DETAILS PAGE FIXES
   ========================================================================== */

@media (max-width: 992px) {
    .product-main {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
        padding: 1.5rem !important;
        display: grid !important;
    }
    
    .main-image {
        aspect-ratio: 1/1 !important;
        height: auto !important;
    }
    
    .thumbnails {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 0.5rem !important;
    }
    
    .product-info-content {
        padding: 0 !important;
    }
    
    .product-title {
        font-size: 1.5rem !important;
    }
}

/* ==========================================================================
   SUPPLEMENTAL MOBILE STYLES (Details & Components)
   ========================================================================== */

@media (max-width: 992px) {
    /* SIDEBAR CLOSE BUTTON */
    .sidebar-close {
        display: flex !important;
        position: absolute;
        top: 15px;
        right: 15px;
        background: var(--bg-secondary);
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        cursor: pointer;
        z-index: 2001;
    }
    
    html[dir="ltr"] .sidebar-close {
        right: auto;
        left: 15px;
    }

    /* FILTER TOGGLE BUTTON */
    .mobile-filter-toggle {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
        padding: 0.8rem 1.2rem;
        background: var(--bg-primary);
        border: 1px solid var(--border);
        border-radius: 8px;
        margin-bottom: 1rem !important;
        width: 100%;
        justify-content: center;
        font-weight: 700;
        cursor: pointer;
        color: var(--text-primary);
        box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    }

    /* HIDE VIEW TOGGLE */
    .view-toggle {
        display: none !important;
    }

    /* PRODUCT CARD DETAILS */
    .product-info {
        padding: 8px 10px !important;
    }
    
    .product-brand {
        font-size: 0.75rem !important;
        margin-bottom: 2px !important;
        display: block;
    }

    .product-name {
        font-size: 0.85rem !important;
        height: 2.4em;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        margin-bottom: 4px !important;
    }
    
    .product-rating {
        display: none !important;
    }
    
    .product-price {
        margin-top: 4px !important;
        flex-wrap: wrap;
        gap: 4px;
        display: flex;
        align-items: center;
    }
    
    .current-price {
        font-size: 0.95rem !important;
        color: var(--primary);
        font-weight: 800;
    }
    
    .original-price {
        font-size: 0.8rem !important;
    }
    
    .product-actions {
        top: 6px !important;
        right: 6px !important;
        left: auto !important;
    }
    
    html[dir="ltr"] .product-actions {
        left: 6px !important;
        right: auto !important;
    }
    
    .add-to-cart {
        width: 30px !important;
        height: 30px !important;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        font-size: 0.8rem !important;
    }
    
    .add-to-cart span {
        display: none;
    }
}
