/* mobile-responsive.css - Advanced Responsive Styles */
/* This file should be loaded AFTER main styles */

/* ==================== 900px and below ==================== */
@media (max-width: 900px) {
    /* Container adjustments */
    .container {
        padding: 0 15px !important;
        max-width: 100% !important;
    }
    
    /* Product grid adjustments */
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;
        gap: 15px !important;
    }
    
    /* Category grid */
    .categories-grid {
        justify-content: center !important;
    }
    
    /* Search form adjustments */
    .filters-form {
        flex-wrap: wrap !important;
    }
    
    .search-box {
        min-width: 100% !important;
    }
    
    /* Modal adjustments for tablets */
    .modal-content {
        max-width: 95% !important;
    }
    
    .modal-product {
        grid-template-columns: 1fr 1fr !important;
    }
    
    .modal-image {
        padding: 25px !important;
    }
    
    .modal-image img {
        max-height: 250px !important;
    }
    
    .modal-info {
        padding: 25px !important;
    }
}

/* ==================== 768px and below ==================== */
@media (max-width: 768px) {
    /* Product grid - 3 products per row */
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
        gap: 12px !important;
    }
    
    /* Product card adjustments */
    .product-card {
        height: auto !important;
        min-height: 260px !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .product-image {
        height: 110px !important;
        padding: 12px !important;
        flex-shrink: 0 !important;
    }
    
    .product-content {
        padding: 12px !important;
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        min-height: 0 !important;
    }
    
    /* Product title with dynamic height */
    .product-title {
        font-size: 0.9rem !important;
        min-height: 2.6em !important;
        max-height: 5.2em !important;
        overflow: hidden !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 4 !important;
        -webkit-box-orient: vertical !important;
        flex-shrink: 0 !important;
        line-height: 1.3 !important;
        margin-bottom: 6px !important;
    }
    
    /* Product actions - vertical layout */
    .product-actions {
        flex-direction: column !important;
        gap: 8px !important;
        margin-top: auto !important;
        flex-shrink: 0 !important;
    }
    
    .quantity-control {
        width: 100% !important;
        min-width: 100% !important;
        justify-content: center !important;
        height: 28px !important;
    }
    
    .qty-btn {
        width: 26px !important;
        height: 26px !important;
        font-size: 0.8rem !important;
    }
    
    .qty-input {
        width: 30px !important;
        height: 26px !important;
        font-size: 0.9rem !important;
    }
    
    .add-to-cart-btn {
        width: 100% !important;
        min-height: 30px !important;
        font-size: 0.85rem !important;
    }
    
    /* Modal adjustments */
    .modal-product {
        grid-template-columns: 1fr !important;
    }
    
    .modal-image {
        height: 220px !important;
        padding: 20px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .modal-image img {
        max-width: 100% !important;
        max-height: 180px !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain !important;
    }
    
    .modal-info {
        padding: 20px !important;
    }
    
    .modal-title {
        font-size: 1.3rem !important;
        line-height: 1.3 !important;
        margin-bottom: 12px !important;
    }
    
    .modal-price {
        font-size: 1.6rem !important;
        margin-bottom: 15px !important;
    }
    
    /* Category buttons */
    .categories-grid {
        gap: 8px !important;
    }
    
    .category-btn {
        padding: 8px 14px !important;
        font-size: 0.85rem !important;
    }
}

/* ==================== 650px and below ==================== */
@media (max-width: 650px) {
    /* Product grid - 2 products per row */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    /* Product card adjustments */
    .product-card {
        min-height: 280px !important;
    }
    
    .product-image {
        height: 120px !important;
    }
    
    .product-title {
        font-size: 0.88rem !important;
        min-height: 2.4em !important;
        max-height: 4.8em !important;
        -webkit-line-clamp: 4 !important;
    }
    
    .product-price {
        font-size: 1.05rem !important;
        margin: 8px 0 !important;
        flex-shrink: 0 !important;
    }
    
    /* Product meta - compact */
    .product-meta {
        margin: 6px 0 !important;
        flex-shrink: 0 !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
    }
    
    .product-brand {
        font-size: 0.78rem !important;
        width: 100% !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
    
    .stock-badge {
        font-size: 0.72rem !important;
        padding: 3px 8px !important;
    }
    
    /* NEW LAYOUT: Stacked quantity and add-to-cart */
    .product-actions {
        gap: 8px !important;
        display: grid !important;
        grid-template-rows: auto auto !important;
    }
    
    .quantity-control {
        height: 30px !important;
        order: 1 !important;
    }
    
    .qty-btn {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.85rem !important;
    }
    
    .qty-input {
        width: 32px !important;
        height: 28px !important;
        font-size: 0.95rem !important;
    }
    
    .add-to-cart-btn {
        min-height: 32px !important;
        font-size: 0.88rem !important;
        padding: 0 10px !important;
        order: 2 !important;
    }
    
    /* Filters */
    .filter-select {
        width: 100% !important;
    }
    
    /* Modal refinements */
    .modal-image {
        height: 200px !important;
    }
    
    .modal-image img {
        max-height: 160px !important;
    }
    
    .modal-title {
        font-size: 1.2rem !important;
    }
    
    .modal-price {
        font-size: 1.5rem !important;
    }
}

/* ==================== 500px and below ==================== */
@media (max-width: 500px) {
    /* Product grid - Maintain 2 products per row */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    
    /* Product card adjustments */
    .product-card {
        min-height: 260px !important;
    }
    
    .product-image {
        height: 100px !important;
        padding: 10px !important;
    }
    
    .product-content {
        padding: 10px !important;
    }
    
    .product-title {
        font-size: 0.85rem !important;
        min-height: 2.2em !important;
        max-height: 4.4em !important;
        -webkit-line-clamp: 4 !important;
        line-height: 1.25 !important;
    }
    
    .product-brand {
        font-size: 0.75rem !important;
    }
    
    .stock-badge {
        font-size: 0.7rem !important;
        padding: 2px 7px !important;
    }
    
    .stock-badge i {
        font-size: 0.65rem !important;
    }
    
    .product-price {
        font-size: 0.95rem !important;
        margin-bottom: 10px !important;
    }
    
    /* Product actions - optimized */
    .product-actions {
        gap: 6px !important;
    }
    
    .quantity-control {
        height: 28px !important;
    }
    
    .qty-btn {
        width: 26px !important;
        height: 26px !important;
        font-size: 0.8rem !important;
    }
    
    .qty-input {
        width: 30px !important;
        height: 26px !important;
        font-size: 0.9rem !important;
    }
    
    .add-to-cart-btn {
        min-height: 30px !important;
        font-size: 0.85rem !important;
        padding: 0 8px !important;
    }
    
    /* Badges */
    .badge {
        top: 6px !important;
        left: 6px !important;
        padding: 3px 8px !important;
        font-size: 0.7rem !important;
    }
    
    /* Modal mobile optimizations */
    .modal-content {
        max-width: 98% !important;
        max-height: 95vh !important;
        margin: 10px !important;
    }
    
    .modal-image {
        height: 180px !important;
        padding: 15px !important;
    }
    
    .modal-image img {
        max-height: 140px !important;
    }
    
    .modal-info {
        padding: 15px !important;
    }
    
    .modal-title {
        font-size: 1.1rem !important;
        line-height: 1.3 !important;
        margin-bottom: 10px !important;
    }
    
    .modal-meta {
        gap: 8px !important;
        margin-bottom: 15px !important;
    }
    
    .modal-category {
        font-size: 0.75rem !important;
        padding: 4px 10px !important;
    }
    
    .modal-price {
        font-size: 1.4rem !important;
        margin-bottom: 12px !important;
    }
    
    .modal-stock {
        font-size: 0.85rem !important;
        padding: 6px 12px !important;
        margin-bottom: 20px !important;
    }
    
    .modal-description {
        font-size: 0.9rem !important;
        max-height: 120px !important;
        margin-bottom: 20px !important;
        line-height: 1.5 !important;
    }
    
    .modal-quantity {
        gap: 10px !important;
        margin-bottom: 15px !important;
    }
    
    .modal-qty-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 1rem !important;
    }
    
    .modal-qty-input {
        width: 50px !important;
        height: 36px !important;
        font-size: 1rem !important;
    }
    
    .modal-actions {
        gap: 10px !important;
    }
    
    .modal-add-btn,
    .modal-view-btn {
        padding: 12px !important;
        font-size: 0.95rem !important;
    }
}

/* ==================== 450px and below ==================== */
@media (max-width: 450px) {
    /* Product grid - Maintain 2 products per row */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    
    /* Product card - more compact */
    .product-card {
        min-height: 240px !important;
    }
    
    .product-image {
        height: 90px !important;
        padding: 8px !important;
    }
    
    .product-title {
        font-size: 0.8rem !important;
        min-height: 2em !important;
        max-height: 4em !important;
        -webkit-line-clamp: 4 !important;
    }
    
    .product-brand {
        font-size: 0.72rem !important;
    }
    
    .stock-badge {
        font-size: 0.68rem !important;
        padding: 2px 6px !important;
    }
    
    .stock-badge i {
        font-size: 0.63rem !important;
    }
    
    .product-price {
        font-size: 0.9rem !important;
        margin-bottom: 8px !important;
    }
    
    /* Product actions - extra compact */
    .product-actions {
        gap: 5px !important;
    }
    
    .quantity-control {
        height: 26px !important;
    }
    
    .qty-btn {
        width: 24px !important;
        height: 24px !important;
        font-size: 0.75rem !important;
    }
    
    .qty-input {
        width: 28px !important;
        height: 24px !important;
        font-size: 0.85rem !important;
    }
    
    .add-to-cart-btn {
        min-height: 28px !important;
        font-size: 0.8rem !important;
        padding: 0 6px !important;
    }
    
    /* Modal ultra-compact */
    .modal-image {
        height: 160px !important;
        padding: 12px !important;
    }
    
    .modal-image img {
        max-height: 120px !important;
    }
    
    .modal-info {
        padding: 12px !important;
    }
    
    .modal-title {
        font-size: 1rem !important;
        margin-bottom: 8px !important;
    }
    
    .modal-price {
        font-size: 1.3rem !important;
        margin-bottom: 10px !important;
    }
    
    .modal-description {
        font-size: 0.85rem !important;
        max-height: 100px !important;
        margin-bottom: 15px !important;
    }
    
    .modal-quantity {
        gap: 8px !important;
        margin-bottom: 12px !important;
    }
    
    .modal-qty-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.9rem !important;
    }
    
    .modal-qty-input {
        width: 45px !important;
        height: 32px !important;
        font-size: 0.9rem !important;
    }
    
    .modal-add-btn,
    .modal-view-btn {
        padding: 10px !important;
        font-size: 0.9rem !important;
    }
}

/* ==================== 350px and below ==================== */
@media (max-width: 350px) {
    /* Product grid - Keep 2 products per row */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 4px !important;
    }
    
    /* Product card - minimal height */
    .product-card {
        min-height: 220px !important;
    }
    
    .product-image {
        height: 80px !important;
        padding: 6px !important;
    }
    
    .product-content {
        padding: 8px !important;
    }
    
    .product-title {
        font-size: 0.75rem !important;
        min-height: 1.8em !important;
        max-height: 3.6em !important;
        -webkit-line-clamp: 3 !important;
        line-height: 1.2 !important;
    }
    
    .product-brand {
        font-size: 0.68rem !important;
    }
    
    .stock-badge {
        font-size: 0.65rem !important;
        padding: 2px 5px !important;
    }
    
    .stock-badge i {
        font-size: 0.6rem !important;
    }
    
    .product-price {
        font-size: 0.85rem !important;
        margin-bottom: 6px !important;
    }
    
    /* Product actions - minimal */
    .product-actions {
        gap: 4px !important;
    }
    
    .quantity-control {
        height: 24px !important;
    }
    
    .qty-btn {
        width: 22px !important;
        height: 22px !important;
        font-size: 0.7rem !important;
    }
    
    .qty-input {
        width: 26px !important;
        height: 22px !important;
        font-size: 0.8rem !important;
    }
    
    .add-to-cart-btn {
        min-height: 26px !important;
        font-size: 0.75rem !important;
        padding: 0 4px !important;
    }
    
    /* Modal for very small screens */
    .modal-content {
        max-width: 100% !important;
        margin: 5px !important;
        border-radius: 8px !important;
    }
    
    .modal-image {
        height: 140px !important;
        padding: 10px !important;
    }
    
    .modal-image img {
        max-height: 100px !important;
    }
    
    .modal-info {
        padding: 10px !important;
    }
    
    .modal-title {
        font-size: 0.95rem !important;
        margin-bottom: 6px !important;
    }
    
    .modal-price {
        font-size: 1.2rem !important;
        margin-bottom: 8px !important;
    }
    
    .modal-description {
        font-size: 0.8rem !important;
        max-height: 80px !important;
        margin-bottom: 12px !important;
    }
    
    .modal-quantity {
        gap: 6px !important;
        margin-bottom: 10px !important;
    }
    
    .modal-qty-btn {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.85rem !important;
    }
    
    .modal-qty-input {
        width: 40px !important;
        height: 30px !important;
        font-size: 0.85rem !important;
    }
    
    .modal-actions {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .modal-add-btn,
    .modal-view-btn {
        width: 100% !important;
        padding: 8px !important;
        font-size: 0.85rem !important;
    }
}

/* ==================== 300px and below ==================== */
@media (max-width: 300px) {
    /* Force 2 products per row even on tiny screens */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 3px !important;
    }
    
    /* Minimal product card */
    .product-card {
        min-height: 200px !important;
    }
    
    .product-image {
        height: 70px !important;
        padding: 5px !important;
    }
    
    .product-title {
        font-size: 0.7rem !important;
        min-height: 1.6em !important;
        max-height: 3.2em !important;
        -webkit-line-clamp: 3 !important;
        line-height: 1.15 !important;
    }
    
    .product-price {
        font-size: 0.8rem !important;
    }
    
    .add-to-cart-btn {
        font-size: 0.7rem !important;
    }
}

/* ==================== Modal Image Protection ==================== */
/* Ensure modal images are always visible and properly sized */
.modal-image {
    position: relative !important;
    overflow: hidden !important;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%) !important;
}

.modal-image img {
    display: block !important;
    margin: 0 auto !important;
    transition: transform 0.3s ease !important;
}

/* Modal close button positioning */
.modal-close {
    position: fixed !important;
    top: 10px !important;
    right: 10px !important;
    z-index: 1001 !important;
    background: rgba(255, 255, 255, 0.9) !important;
}

/* ==================== Dynamic Content Utilities ==================== */
/* These styles ensure content flows properly in all scenarios */

/* Flex container for dynamic card heights */
.product-card {
    display: flex !important;
    flex-direction: column !important;
}

.product-content {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important; /* Crucial for flex children */
}

/* Smart title truncation with multi-line support */
.product-title {
    flex-shrink: 0 !important;
    word-break: break-word !important;
    hyphens: auto !important;
}

/* Push actions to bottom */
.product-actions {
    margin-top: auto !important;
    flex-shrink: 0 !important;
}

/* Smart meta information */
.product-meta {
    flex-shrink: 0 !important;
}

/* Fixed height elements */
.product-price,
.stock-badge,
.badge {
    flex-shrink: 0 !important;
}

/* ==================== Touch Device Optimizations ==================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets for mobile */
    .qty-btn,
    .add-to-cart-btn,
    .modal-qty-btn,
    .modal-add-btn,
    .modal-view-btn {
        min-height: 44px !important;
    }
    
    .qty-input,
    .modal-qty-input {
        min-height: 44px !important;
        font-size: 1rem !important;
    }
    
    /* Prevent text selection on buttons */
    button, 
    .product-card,
    .category-btn {
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
    }
    
    /* Better scrolling for modal */
    .modal-content {
        -webkit-overflow-scrolling: touch !important;
    }
}

/* ==================== Print Styles ==================== */
@media print {
    .product-card {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        height: auto !important;
        min-height: auto !important;
    }
    
    .product-actions,
    .badge,
    .quantity-control .qty-btn {
        display: none !important;
    }
    
    .quantity-control .qty-input {
        display: block !important;
        border: 1px solid #ccc !important;
        background: white !important;
    }
    
    .product-title {
        -webkit-line-clamp: unset !important;
        max-height: none !important;
    }
    
    /* Hide interactive elements in print */
    .modal,
    .product-modal,
    .modal-content {
        display: none !important;
    }
}

/* ==================== Orientation Specific ==================== */
@media (max-width: 768px) and (orientation: landscape) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px !important;
    }
    
    .product-card {
        min-height: 220px !important;
    }
    
    .product-image {
        height: 90px !important;
    }
    
    .modal-image {
        height: 160px !important;
    }
    
    .modal-image img {
        max-height: 140px !important;
    }
}