/* Mobile Product Grid Fix for XS View */

/* Ensure proper grid behavior on mobile devices */
@media (max-width: 767px) {
    /* Force products container to use flexbox for better control */
    #products .products.row,
    #js-product-list .products.row {
        display: flex !important;
        flex-wrap: wrap !important;
        margin-left: -5px;
        margin-right: -5px;
    }
    
    /* Ensure product items use flexbox sizing */
    #products .products .product,
    #js-product-list .products .product {
        display: flex !important;
        flex: 0 0 50% !important;
        max-width: 50% !important;
        padding-left: 5px !important;
        padding-right: 5px !important;
        margin-bottom: 10px;
    }
    
    /* Override any conflicting col-xs-6 styles */
    #products .products .col-xs-6,
    #js-product-list .products .col-xs-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
        float: none !important;
        width: auto !important;
    }
    
    /* Ensure product miniature takes full width of its container */
    .product-miniature {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }
    
    /* Fix product description spacing on mobile */
    .product-miniature .product-description {
        padding: 8px !important;
    }
    
    /* Ensure product images scale properly */
    .product-miniature .thumbnail-container {
        width: 100%;
    }
    
    .product-miniature .product-thumbnail img {
        width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
    }
    
    /* Fix any overflow issues */
    #products,
    #js-product-list {
        overflow-x: hidden;
    }
    
    /* Clear floats properly */
    #products .products.row:after,
    #js-product-list .products.row:after {
        content: "";
        display: table;
        clear: both;
    }
    
    /* Handle odd number of products */
    #products .products .product:last-child:nth-child(odd),
    #js-product-list .products .product:last-child:nth-child(odd) {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
}

/* Very small devices (below 480px) - optional single column layout */
@media (max-width: 479px) {
    /* Uncomment if you want single column on very small devices
    #products .products .product,
    #js-product-list .products .product,
    #products .products .col-xs-6,
    #js-product-list .products .col-xs-6 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    */
}

/* Fix for category page specific issues */
.category #products .products.row,
.category #js-product-list .products.row {
    justify-content: flex-start;
}

/* Ensure proper alignment */
@media (max-width: 767px) {
    .category #products .products .product,
    .category #js-product-list .products .product {
        align-items: stretch;
    }
    
    .category .product-miniature {
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    
    .category .product-miniature .thumbnail-container {
        flex: 1;
    }
}