/**
 * DealerHub Vehicles Pro - Filters & Pagination Styles
 * Filter interface and pagination components
 */

/* ========================================
   FILTER CONTAINER
   ======================================== */

.dh-filters {
    background-color: var(--dh-filter-bg, #f9fafb);
    border: 1px solid var(--dh-filter-border, #e5e7eb);
    border-radius: var(--dh-card-radius);
    padding: var(--dh-spacing-lg);
    margin-bottom: var(--dh-spacing-xl);
}

.dh-filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--dh-spacing-lg);
    flex-wrap: wrap;
    gap: var(--dh-spacing-md);
}

.dh-filters-title {
    font-size: var(--dh-font-size-xl);
    font-weight: 700;
    color: var(--dh-heading-color);
    margin: 0;
}

.dh-filters-reset {
    padding: 8px 20px;
    background-color: var(--dh-filter-button-bg, #dc2626);
    color: var(--dh-filter-button-text, #ffffff);
    border: none;
    border-radius: var(--dh-btn-radius);
    font-size: var(--dh-font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--dh-transition-base);
}

.dh-filters-reset:hover {
    background-color: var(--dh-secondary-hover);
    transform: translateY(-1px);
}

/* ========================================
   FILTER GRID
   ======================================== */

.dh-filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--dh-spacing-md);
}

@media (min-width: 768px) {
    .dh-filters-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .dh-filters-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ========================================
   FILTER GROUP
   ======================================== */

.dh-filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dh-filter-label {
    font-size: var(--dh-font-size-sm);
    font-weight: 600;
    color: var(--dh-filter-label-color, #1f2937) !important;
    margin: 0;
}

.dh-filter-input,
.dh-filter-select {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--dh-filter-field-bg, #ffffff);
    border: 1px solid var(--dh-filter-field-border, #d1d5db);
    border-radius: var(--dh-btn-radius);
    font-size: var(--dh-font-size-base);
    color: var(--dh-filter-field-text, #1f2937) !important;
    transition: all var(--dh-transition-base);
}

.dh-filter-input:focus,
.dh-filter-select:focus {
    outline: none;
    border-color: var(--dh-filter-input-focus);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

.dh-filter-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.dh-filter-select option {
    background-color: #ffffff;
    color: #1f2937;
    padding: 8px;
}

/* Range inputs */
.dh-filter-range {
    display: flex;
    gap: 8px;
    align-items: center;
}

.dh-filter-range-separator {
    color: var(--dh-text-secondary);
    font-weight: 600;
}

.dh-filter-range .dh-filter-input {
    flex: 1;
}

/* ========================================
   FILTER ACTIONS
   ======================================== */

.dh-filters-actions {
    display: flex;
    gap: 12px;
    margin-top: var(--dh-spacing-lg);
    padding-top: var(--dh-spacing-lg);
    border-top: 1px solid var(--dh-filter-border);
}

.dh-filters-apply {
    flex: 1;
}

/* ========================================
   ACTIVE FILTERS
   ======================================== */

.dh-active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: var(--dh-spacing-md);
    padding-top: var(--dh-spacing-md);
    border-top: 1px solid var(--dh-filter-border);
}

.dh-active-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background-color: var(--dh-primary-color);
    color: var(--dh-text-white);
    border-radius: 20px;
    font-size: var(--dh-font-size-sm);
    font-weight: 500;
}

.dh-active-filter-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background-color: rgba(255, 255, 255, 0.3);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--dh-transition-fast);
}

.dh-active-filter-remove:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

/* ========================================
   RESULTS INFO
   ======================================== */

.dh-results-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--dh-spacing-lg);
    padding: var(--dh-spacing-md);
    background-color: var(--dh-bg-secondary);
    border-radius: var(--dh-btn-radius);
    flex-wrap: wrap;
    gap: var(--dh-spacing-md);
}

/* PHP renders this container empty and the filter JS only fills it once a filter
   request returns. Until then it drew as a bare padded bar between the filter box
   and the listings, themed but with nothing in it. Collapse it while it is empty;
   it reappears by itself as soon as there is a result count to show. */
.dh-results-info:empty {
    display: none;
}

.dh-results-count {
    font-size: var(--dh-font-size-base);
    color: var(--dh-text-primary);
    font-weight: 600;
}

.dh-results-sort {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dh-results-sort-label {
    font-size: var(--dh-font-size-sm);
    color: var(--dh-text-secondary);
    font-weight: 500;
}

.dh-results-sort-select {
    padding: 6px 32px 6px 12px;
    background-color: var(--dh-bg-primary);
    border: 1px solid var(--dh-border-light);
    border-radius: var(--dh-btn-radius);
    font-size: var(--dh-font-size-sm);
    cursor: pointer;
}

/* ========================================
   PAGINATION
   ======================================== */

.dh-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: var(--dh-spacing-xl);
    padding: var(--dh-spacing-lg) 0;
}

.dh-pagination-item {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    background-color: var(--dh-pagination-bg);
    border: 1px solid var(--dh-pagination-border);
    border-radius: var(--dh-btn-radius);
    font-size: var(--dh-font-size-base);
    font-weight: 500;
    color: var(--dh-text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--dh-transition-base);
}

.dh-pagination-item:hover:not(.dh-pagination-item-active):not(.dh-pagination-item-disabled) {
    background-color: var(--dh-pagination-hover-bg);
    border-color: var(--dh-primary-color);
}

.dh-pagination-item-active {
    background-color: var(--dh-pagination-active-bg);
    border-color: var(--dh-pagination-active-bg);
    color: var(--dh-pagination-active-text);
    cursor: default;
}

.dh-pagination-item-disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.dh-pagination-prev,
.dh-pagination-next {
    font-weight: 600;
}

.dh-pagination-ellipsis {
    border: none;
    background: none;
    cursor: default;
}

/* ========================================
   LOADING STATE
   ======================================== */

.dh-filters-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.dh-filters-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid var(--dh-primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: dh-spin 0.8s linear infinite;
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 767px) {
    .dh-filters {
        padding: var(--dh-spacing-md);
    }
    
    .dh-filters-grid {
        grid-template-columns: 1fr;
    }
    
    .dh-filters-actions {
        flex-direction: column;
    }
    
    /* Improve touch targets for mobile */
    .dh-filter-select,
    .dh-filter-input {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .dh-filters-reset,
    .dh-btn-icon {
        min-height: 44px;
        padding: 12px 20px;
    }
    
    .dh-results-info {
        flex-direction: column;
        text-align: center;
    }
    
    .dh-pagination {
        flex-wrap: wrap;
    }
    
    .dh-pagination-item {
        min-width: 36px;
        height: 36px;
        font-size: var(--dh-font-size-sm);
    }
}

/* ========================================
   WORDPRESS THEME COMPATIBILITY
   ======================================== */

.dh-filters select,
.dh-filters input {
    max-width: 100% !important;
}

.dh-filters label {
    display: block !important;
    margin-bottom: 8px !important;
}


/* ========================================
   MOBILE ACCORDION TOGGLE
   ======================================== */

.dh-filter-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dh-mobile-only {
    display: none !important;
}

.dh-btn-icon {
    padding: 8px 12px;
    background-color: var(--dh-filter-toggle-bg, var(--dh-primary-color));
    color: var(--dh-filter-toggle-text, var(--dh-text-white));
    border: none;
    border-radius: var(--dh-btn-radius);
    cursor: pointer;
    transition: all var(--dh-transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dh-btn-icon:hover {
    background-color: var(--dh-primary-hover);
    opacity: 0.9;
}

.dh-filter-toggle-icon {
    display: inline-block;
    font-size: 12px;
    transition: transform var(--dh-transition-base);
}

/* Collapsible filter panel.
   
   This deliberately animates max-height rather than toggling `display`.
   motors-theme-compat.css sets `display: grid !important` on this panel
   (.dealerhub-vehicles-container .dh-filters-grid), and an !important declaration
   in a stylesheet beats the plain inline `display: none` that jQuery's
   slideToggle() writes when its animation finishes. The panel therefore slid shut
   and snapped straight back open on every click. max-height is not contested by
   anything, so collapsing through it sidesteps the fight entirely. */
#dealerhub-filters-content {
    overflow: hidden;
    max-height: 1500px;
    opacity: 1;
    transition: max-height 300ms ease, opacity 300ms ease;
}

#dealerhub-filters-content.dh-filters-collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    margin-bottom: 0;
    pointer-events: none;
}

@media (max-width: 767px) {
    .dh-mobile-only {
        display: inline-flex !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    .dh-filters-header {
        margin-bottom: var(--dh-spacing-md);
    }
}

/* ========================================
   FILTER LOADING INDICATOR
   ======================================== */

.dh-filter-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--dh-spacing-xl);
    text-align: center;
}

.dh-filter-loading.hidden {
    display: none;
}

.dh-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--dh-border-light);
    border-top-color: var(--dh-primary-color);
    border-radius: 50%;
    animation: dh-spin 0.8s linear infinite;
}

.dh-filter-loading p {
    margin-top: 12px;
    color: var(--dh-text-secondary);
    font-size: var(--dh-font-size-sm);
}

@keyframes dh-spin {
    to {
        transform: rotate(360deg);
    }
}


/* ============================================
   MOBILE RESPONSIVE BUTTONS
   ============================================ */

@media (max-width: 767px) {
    /* Ensure mobile-only toggle is visible on mobile */
    .dh-mobile-only {
        display: inline-flex !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Stack buttons vertically on very small screens */
    .dh-filter-header-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .dh-filter-header-actions button {
        width: 100%;
        justify-content: center;
    }
    
    /* Adjust filter grid for mobile */
    .dh-filters-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (min-width: 480px) and (max-width: 767px) {
    /* On slightly larger mobile screens, keep buttons side by side */
    .dh-filter-header-actions {
        flex-direction: row;
    }
    
    .dh-filter-header-actions button {
        width: auto;
        flex: 1;
    }
}
