/* ================================================
   COMPREHENSIVE MOBILE RESPONSIVE STYLES
   ================================================ */

/* === PRODUCT & CARD GRIDS === */
.grid-3,
.product-grid,
.shop-grid,
.featured-products,
.category-grid,
.vendor-grid {
    display: grid;
    gap: 20px;
}

/* Desktop: 4 columns */
@media (min-width: 1200px) {

    .grid-3,
    .product-grid,
    .shop-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Laptop: 3 columns */
@media (min-width: 969px) and (max-width: 1199px) {

    .grid-3,
    .product-grid,
    .shop-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Tablet: 2 columns */
@media (min-width: 769px) and (max-width: 968px) {

    .grid-3,
    .product-grid,
    .shop-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile: 2 columns (PRIMARY REQUIREMENT) */
@media (max-width: 768px) {

    /* ====== HIDE SHOP SIDEBAR COMPLETELY ====== */
    .sidebar,
    #shopSidebar,
    aside.sidebar,
    .shop-container .sidebar,
    .sidebar-overlay,
    .filter-toggle-btn {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        height: 0 !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }

    /* Make product grid full width */
    .shop-container {
        display: block !important;
    }

    .product-grid {
        width: 100% !important;
    }

    /* ====== END SIDEBAR HIDING ====== */

    .grid-3,
    .product-grid,
    .shop-grid,
    .vendors-grid,
    .featured-products,
    .category-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px;
    }

    .card {
        padding: 15px;
    }

    .product-image {
        height: 150px;
    }
}

/* Small Mobile: 1 column (very small screens) */
@media (max-width: 400px) {

    .grid-3,
    .product-grid {
        grid-template-columns: 1fr !important;
    }

    /* Ensure vendors and shop grids STAY 2 columns even on small screens */
    .vendors-grid,
    .shop-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Allow cards to shrink below their natural width */
    .vendors-grid .vendor-card,
    .shop-grid .card {
        min-width: 0 !important;
        width: 100% !important;
    }
}

/* === MOBILE NAVIGATION === */
@media (max-width: 1024px) {

    /* Hide desktop menu */
    .desktop-only {
        display: none !important;
    }

    /* Show mobile elements */
    .mobile-only {
        display: block !important;
    }

    /* Mobile menu button */
    .mobile-menu-toggle {
        display: flex !important;
        background: none;
        border: none;
        color: var(--text-main);
        font-size: 1.5rem;
        cursor: pointer;
        padding: 10px;
    }

    /* Mobile navigation slide-in */
    .nav-menu {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        background: var(--dark-bg);
        padding: 80px 20px 20px;
        transition: left 0.3s ease;
        z-index: 9999;
        overflow-y: auto;
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.5);
    }

    .nav-menu.active {
        left: 0;
    }

    .nav-menu ul {
        flex-direction: column;
        gap: 0;
    }

    .nav-menu li {
        border-bottom: 1px solid var(--border);
    }

    .nav-menu li a {
        display: block;
        padding: 15px 10px;
        font-size: 1.1rem;
    }

    /* Mobile menu overlay */
    body.menu-open::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.7);
        z-index: 9998;
    }
}

/* === RESPONSIVE HEADER === */
@media (max-width: 768px) {
    header {
        padding: 10px 0;
    }

    .header-container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 15px;
    }

    .logo {
        font-size: 1.2rem !important;
    }

    .header-icons {
        display: flex;
        gap: 15px;
        align-items: center;
    }

    .header-icon-link {
        font-size: 1.3rem;
    }
}

/* === PRODUCT DETAIL PAGE === */
@media (max-width: 768px) {
    .product-header {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }

    .main-product-image {
        height: 300px;
    }

    .product-title {
        font-size: 1.8rem;
    }

    .product-price {
        font-size: 2rem;
    }

    .product-image-gallery {
        position: static;
    }

    .cta-section {
        flex-direction: column;
    }

    .btn-add-cart {
        width: 100%;
    }
}

/* === FORMS & INPUTS === */
@media (max-width: 768px) {

    input,
    select,
    textarea,
    .btn {
        font-size: 16px;
        /* Prevent zoom on iOS */
        min-height: 44px;
        /* Touch target size */
    }

    .form-group {
        margin-bottom: 15px;
    }

    .form-row {
        flex-direction: column;
    }
}

/* === TABLES === */
@media (max-width: 768px) {
    table {
        font-size: 0.85rem;
    }

    .admin-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    thead {
        display: none;
        /* Hide headers on mobile, use card layout */
    }

    tbody tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 15px;
    }

    tbody td {
        display: block;
        text-align: right;
        padding: 8px 0;
        border-bottom: 1px solid var(--border);
    }

    tbody td:last-child {
        border-bottom: none;
    }

    tbody td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: var(--text-muted);
    }
}

/* === MODALS === */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 20px auto;
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* === CART & CHECKOUT === */
@media (max-width: 768px) {
    .cart-grid {
        grid-template-columns: 1fr !important;
    }

    .cart-item {
        flex-direction: column;
        text-align: center;
    }

    .cart-item-image {
        width: 100%;
        max-width: 200px;
        margin: 0 auto 15px;
    }
}

/* === ADMIN PANEL === */
@media (max-width: 768px) {
    .admin-container {
        padding: 15px;
    }

    .admin-header {
        flex-direction: column;
        gap: 15px;
    }

    .admin-stats {
        grid-template-columns: 1fr 1fr !important;
    }

    .card {
        padding: 15px;
    }
}

/* === VENDOR DASHBOARD === */
@media (max-width: 768px) {
    .vendor-stats {
        grid-template-columns: 1fr 1fr !important;
    }

    .stat-card {
        padding: 15px;
    }
}

/* === FOOTER === */
@media (max-width: 768px) {
    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 30px;
    }

    footer {
        padding: 40px 0 100px;
        /* Extra padding for bottom nav */
    }
}

/* === HOMEPAGE HERO === */
@media (max-width: 768px) {
    .hero {
        min-height: 50vh;
        padding: 40px 20px;
    }

    .hero h1 {
        font-size: 2rem !important;
    }

    .hero p {
        font-size: 1rem;
    }

    .hero-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .hero-buttons .btn {
        width: 100%;
    }
}

/* === CATEGORIES === */
@media (max-width: 768px) {
    .categories-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .category-card {
        padding: 20px 15px;
    }

    .category-card i {
        font-size: 2rem;
    }
}

/* === FEATURES SECTION === */
@media (max-width: 768px) {
    .features-grid {
        grid-template-columns: 1fr !important;
    }

    .feature-card {
        padding: 20px;
        text-align: center;
    }
}

/* === BOTTOM NAVIGATION (Mobile Only) === */
@media (max-width: 768px) {
    .bottom-nav {
        display: flex !important;
    }

    /* Add padding to body to prevent content hiding behind bottom nav */
    body {
        padding-bottom: 70px;
    }
}

/* === TOUCH OPTIMIZATION === */
@media (max-width: 768px) {

    /* Larger tap targets */
    a,
    button,
    .btn,
    input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Spacing between interactive elements */
    .btn+.btn {
        margin-left: 0;
        margin-top: 10px;
    }

    /* Remove hover effects on touch devices */
    @media (hover: none) {
        *:hover {
            transform: none;
        }
    }
}

/* === UTILITY CLASSES === */
@media (max-width: 768px) {
    .mobile-hidden {
        display: none !important;
    }

    .mobile-full-width {
        width: 100% !important;
    }

    .mobile-text-center {
        text-align: center !important;
    }

    .mobile-stack {
        flex-direction: column !important;
    }
}

/* === LANDSCAPE ORIENTATION === */
@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        min-height: 70vh;
    }

    .product-image {
        height: 120px;
    }
}

/* === HIGH DPI SCREENS === */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

    /* Crisp images on retina displays */
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* === ACCESSIBILITY === */
@media (max-width: 768px) {

    /* Larger text for readability */
    body {
        font-size: 16px;
    }

    /* Better contrast on small screens */
    .text-muted {
        color: #aaa;
    }
}