/* Mobile Inventory Page Fixes */

/* Mobile Filter Wrapper - Ensure proper display on mobile */
@media (max-width: 1024px) {
    /* Fix filter button visibility */
    .mobile-filter-wrapper {
        display: block !important;
        position: relative;
        z-index: 10;
        margin-bottom: 20px;
    }
    
    .mobile-filter .mobile-search-btn {
        display: flex !important;
        width: 100%;
        justify-content: space-between;
        align-items: center;
        padding: 16px 22px;
        margin: 0 0 15px 0;
        background-color: #6c98e1;
        color: #fff;
        cursor: pointer;
    }
    
    /* Ensure mobile search filter is properly positioned */
    form.mobile-search-filter {
        position: fixed;
        width: 85%;
        max-width: 400px;
        left: -100%;
        top: 0;
        min-height: 100vh;
        height: 100vh;
        overflow-y: auto;
        transition: left 0.3s ease;
        background-color: #ffffff;
        z-index: 100001;
        visibility: visible !important;
    }
    
    /* Active state for mobile filter */
    form.mobile-search-filter.active {
        left: 0 !important;
        visibility: visible !important;
    }
    
    /* Mobile overlay */
    .mobile-overlay {
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 100000;
        display: none;
    }
    
    .mobile-overlay.active {
        display: block !important;
    }
    
    /* Hide desktop filter on mobile */
    .classic-filter-row.sidebar-sm-mg-bt {
        display: none !important;
    }
    
    /* Adjust content column width on mobile */
    .col-md-9 {
        width: 100% !important;
        padding: 0 15px;
    }
    
    /* Fix inventory items layout */
    #listings-result {
        width: 100%;
        overflow-x: hidden;
    }
    
    #listings-result .stm-listing-directory-list-loop,
    #listings-result .stm-isotope-listing-animated,
    #listings-result .car-listing-row {
        display: flex;
        flex-wrap: wrap;
        margin: 0 -5px;
    }
    
    /* Inventory items responsive */
    #listings-result .col-md-3,
    #listings-result .col-md-4,
    #listings-result .col-sm-6 {
        width: 50% !important;
        padding: 5px !important;
        float: none !important;
    }
    
    /* Single listing card adjustments */
    .stm-listing-single-loop,
    .stm-listing-directory-single {
        margin-bottom: 15px;
        width: 100%;
    }
    
    /* Fix filter form elements */
    form.mobile-search-filter .filter {
        padding: 0 20px;
        margin: 0;
    }
    
    form.mobile-search-filter .row {
        margin: 0;
    }
    
    form.mobile-search-filter .col-md-12 {
        padding: 0;
        margin-bottom: 15px;
    }
    
    form.mobile-search-filter select,
    form.mobile-search-filter input[type="text"],
    form.mobile-search-filter input[type="number"] {
        width: 100% !important;
        height: 45px !important;
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    /* Sticky filter actions at bottom */
    form.mobile-search-filter .sticky-filter-actions {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        background: #fff;
        border-top: 1px solid #ddd;
        padding: 15px;
        display: flex;
        justify-content: space-between;
        z-index: 100002;
    }
    
    form.mobile-search-filter .sticky-filter-actions .show-car-btn {
        flex: 1;
        margin-right: 10px;
        background-color: #6c98e1;
        color: #fff;
        border: none;
        padding: 12px;
        font-size: 14px;
        font-weight: 600;
    }
    
    form.mobile-search-filter .sticky-filter-actions .mobile-reset-btn {
        padding: 12px 20px;
        background: #f5f5f5;
        color: #333;
        text-decoration: none;
        border: 1px solid #ddd;
    }
}

/* Small mobile devices */
@media (max-width: 768px) {
    /* Single column for inventory on very small screens */
    #listings-result .col-md-3,
    #listings-result .col-md-4,
    #listings-result .col-sm-6 {
        width: 100% !important;
        padding: 10px !important;
    }
    
    /* Adjust filter panel width */
    form.mobile-search-filter {
        width: 90%;
        max-width: none;
    }
    
    /* Larger touch targets */
    form.mobile-search-filter select,
    form.mobile-search-filter input[type="text"],
    form.mobile-search-filter input[type="number"] {
        height: 48px !important;
        padding: 10px !important;
    }
}

/* Fix Select2 dropdowns on mobile */
@media (max-width: 1024px) {
    .select2-container {
        width: 100% !important;
    }
    
    .select2-dropdown {
        width: 100% !important;
    }
    
    .select2-container--open .select2-dropdown {
        z-index: 200002 !important;
    }
}

/* Fix scrolling issues */
html.mobile-search-filter-opened {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* Ensure proper z-index hierarchy */
.mobile-overlay {
    z-index: 99999 !important;
}

form.mobile-search-filter {
    z-index: 100000 !important;
}

.select2-container--open .select2-dropdown {
    z-index: 100003 !important;
}

/* Additional responsive fixes */
@media (max-width: 1024px) {
    /* Fix container padding */
    .archive-listing-page .container {
        padding: 0 10px;
    }
    
    /* Fix row margins */
    .archive-listing-page .row {
        margin-left: 0;
        margin-right: 0;
    }
    
    /* Ensure proper spacing */
    .stm-ajax-row {
        padding: 0;
    }
    
    /* Fix action bar on mobile */
    .stm-listing-directory-title-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .stm-listing-directory-title-bar .title {
        margin-bottom: 10px;
    }
    
    /* Sort options responsive */
    .stm-listing-directory-sorting-options {
        width: 100%;
        justify-content: space-between;
    }
}