/* ==============================================
   FILTERS - Search Bar & Filter Pills
   Modern Airbnb-style design
   ============================================== */

/* ----- Variables ----- */
:root {
    --search-bar-bg: var(--bg-primary, #fff);
    --search-bar-border: var(--border-light, #dddddd);
    --search-bar-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);
    --search-bar-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.1), 0 6px 16px rgba(0, 0, 0, 0.1);
    --search-bar-radius: 40px;
    --search-btn-bg: linear-gradient(135deg, #ff385c 0%, #e61e4d 100%);
    --search-btn-hover-shadow: 0 4px 12px rgba(255, 56, 92, 0.4);
    --filter-active-bg: var(--color-primary, #222);
    --filter-active-color: #fff;
}

/* ----- Container ----- */
.search-filters-bar {
    padding: 8px 24px;
    background: transparent;
}

.search-filters-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 100%;
}

/* ----- Primary Search Bar ----- */
.primary-search-bar {
    display: flex;
    align-items: center;
    background: var(--search-bar-bg);
    border: 1px solid var(--search-bar-border);
    border-radius: var(--search-bar-radius);
    box-shadow: var(--search-bar-shadow);
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
    min-height: 54px;
    position: relative;
    transition: box-shadow 0.25s ease, border-color 0.25s ease;
}

.primary-search-bar:hover {
    box-shadow: var(--search-bar-shadow-hover);
}

.primary-search-bar:focus-within {
    box-shadow: var(--search-bar-shadow-hover);
    border-color: transparent;
}

/* ----- Filter Groups (Segments) ----- */
.filter-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px 20px;
    height: 100%;
    cursor: pointer;
    position: relative;
    border-radius: var(--search-bar-radius);
    transition: background 0.2s ease;
    min-width: 0;
}

.filter-group:hover {
    background: var(--bg-hover, #f7f7f7);
}

.filter-group.active {
    background: var(--bg-hover, #f7f7f7);
}

.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary, #222);
    margin-bottom: 2px;
    pointer-events: none;
}

.filter-group input[type="text"] {
    border: none;
    background: transparent;
    padding: 0;
    font-size: 14px;
    color: var(--text-secondary, #717171);
    width: 100%;
    outline: none;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.filter-group input[type="text"]::placeholder {
    color: var(--text-muted, #b0b0b0);
}

.filter-group input[type="text"]:focus::placeholder {
    color: transparent;
}

.filter-group .filter-value {
    font-size: 14px;
    color: var(--text-secondary, #717171);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Location group - larger */
.filter-group.location-group {
    flex: 1.5;
    min-width: 180px;
}

/* Date groups */
.filter-group.check-in-group,
.filter-group.check-out-group {
    flex: 0 0 auto;
    min-width: 120px;
}

/* Guests group */
.filter-group.guests-group {
    flex: 0 0 auto;
    min-width: 130px;
}

/* ----- Dividers ----- */
.filter-divider {
    width: 1px;
    height: 32px;
    background: var(--border-light, #dddddd);
    flex-shrink: 0;
    opacity: 0.6;
}

.primary-search-bar:hover .filter-divider,
.primary-search-bar:focus-within .filter-divider {
    opacity: 0.4;
}

/* ----- Submit Button ----- */
.search-submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 48px;
    height: 48px;
    padding: 0 16px;
    border-radius: 24px;
    background: var(--search-btn-bg);
    border: none;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-right: 5px;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.search-submit-btn:hover {
    transform: scale(1.02);
    box-shadow: var(--search-btn-hover-shadow);
}

.search-submit-btn:active {
    transform: scale(0.98);
}

.search-submit-btn .search-btn-text {
    display: none;
}

/* Expanded button on hover */
.primary-search-bar:hover .search-submit-btn .search-btn-text,
.primary-search-bar:focus-within .search-submit-btn .search-btn-text {
    display: inline;
}

.primary-search-bar:hover .search-submit-btn,
.primary-search-bar:focus-within .search-submit-btn {
    padding: 0 20px;
}

/* ----- Inline Filter Button (Hidden on Desktop) ----- */
.filter-btn-inline {
    display: none;
}

/* ----- Secondary Filters (Pills) ----- */
.secondary-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
    -ms-overflow-style: none;
    scrollbar-width: none;
    justify-content: center;
    flex-wrap: wrap;
    background: transparent;
    box-shadow: none;
    border: none;
}

.secondary-filters::-webkit-scrollbar {
    display: none;
}

.filter-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border: 1px solid var(--border-light, #dddddd);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #222);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.filter-pill:hover {
    border-color: var(--text-primary, #222);
}

.filter-pill.active,
.filter-pill.has-value {
    background: var(--filter-active-bg);
    border-color: var(--filter-active-bg);
    color: var(--filter-active-color);
}

.filter-pill i {
    font-size: 10px;
    opacity: 0.7;
    transition: transform 0.2s ease;
}

.filter-pill.active i {
    transform: rotate(180deg);
}

.filter-pill-more {
    background: transparent;
    position: relative;
}

.filter-pill-more i:first-child {
    font-size: 14px;
    opacity: 1;
}

.filter-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: linear-gradient(135deg, #ff385c 0%, #e61e4d 100%);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 9px;
    margin-left: 6px;
    line-height: 1;
}

.filter-pill-more.active .filter-count-badge,
.filter-pill-more.has-filters .filter-count-badge {
    display: inline-flex;
}

@media (max-width: 768px) {
    .filter-pill.filter-pill-more.has-filters {
        background: rgba(255, 56, 92, 0.1);
        border-color: #ff385c;
    }
}

/* ==============================================
   DROPDOWNS - Base Styles
   ============================================== */

.search-dropdown {
    position: fixed;
    top: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary, #fff);
    border-radius: 16px;
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: none;
    contain: layout style paint;
    will-change: opacity;
}

.search-dropdown.active {
    display: block !important;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Dates dropdown - positioned by JavaScript for proper alignment */
.dates-dropdown.active {
    /* JS will set left, top, and transform: none for proper positioning */
}

/* Location Dropdown */
.location-dropdown {
    width: 100%;
    max-width: 500px;
    padding: 16px 0;
}

.dropdown-section {
    padding: 0 8px;
}

.dropdown-section + .dropdown-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light, #ebebeb);
}

.dropdown-section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #717171);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.clear-recent {
    background: none;
    border: none;
    font-size: 12px;
    color: var(--text-secondary, #717171);
    cursor: pointer;
    text-decoration: underline;
}

.clear-recent:hover {
    color: var(--text-primary, #222);
}

.location-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.15s ease;
}

.location-item:hover,
.location-item.selected {
    background: var(--bg-hover, #f7f7f7);
}

.location-item-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary, #f7f7f7);
    border-radius: 12px;
    color: var(--text-secondary, #717171);
    font-size: 18px;
    flex-shrink: 0;
}

.location-item-content {
    flex: 1;
    min-width: 0;
}

.location-item-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary, #222);
    line-height: 1.3;
}

.location-item-name strong {
    font-weight: 700;
}

.location-item-description {
    font-size: 14px;
    color: var(--text-secondary, #717171);
    margin-top: 2px;
}

.dropdown-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary, #717171);
}

.dropdown-empty i {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.dropdown-empty p {
    font-size: 16px;
    font-weight: 500;
    margin: 0 0 4px;
    color: var(--text-primary, #222);
}

.dropdown-empty span {
    font-size: 14px;
}

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

@media (max-width: 768px) {
    .search-filters-bar {
        padding: 6px 10px;
        background: transparent;
    }

    .search-filters-container {
        gap: 6px;
    }

    .primary-search-bar {
        min-height: 46px;
        border-radius: 30px !important;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1), 0 4px 20px rgba(0, 0, 0, 0.08);
        border: none !important;
        /* Allow horizontal scrolling on mobile for all filters */
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        /* Compact padding */
        padding: 4px 6px;
    }
    
    /* Ensure all child elements respect the rounded border */
    .primary-search-bar > * {
        border-radius: 0;
    }
    
    /* First and last filter groups should have rounded corners */
    .primary-search-bar .filter-group:first-child {
        border-top-left-radius: 30px;
        border-bottom-left-radius: 30px;
    }
    
    .primary-search-bar .search-submit-btn {
        border-top-right-radius: 30px !important;
        border-bottom-right-radius: 30px !important;
    }
    
    .primary-search-bar::-webkit-scrollbar {
        display: none;
    }

    .filter-group {
        padding: 6px 10px;
        flex-shrink: 0;
        min-height: 40px; /* Slightly reduced for compactness */
        display: flex;
        flex-direction: column;
        justify-content: center;
        transition: background 0.2s ease;
        border-radius: 20px;
    }
    
    .filter-group:active {
        background: var(--bg-hover, #f7f7f7);
    }

    .filter-group label {
        font-size: 9px;
        font-weight: 600;
        letter-spacing: 0.03em;
        text-transform: uppercase;
        color: var(--text-primary, #222);
        margin-bottom: 1px;
        line-height: 1.1;
    }

    .filter-group input[type="text"],
    .filter-group .filter-value {
        font-size: 12px;
        line-height: 1.2;
        font-weight: 400;
    }
    
    /* More compact sizing for mobile */
    .filter-group.location-group {
        min-width: 140px;
        flex: 1 1 140px;
        max-width: 180px;
    }

    .filter-group.check-in-group,
    .filter-group.check-out-group {
        min-width: 85px;
        flex: 0 0 85px;
        max-width: 110px;
    }

    .filter-group.guests-group {
        min-width: 85px;
        flex: 0 0 85px;
        max-width: 110px;
    }
    
    /* Visual indicator when filter has value */
    .filter-group.has-value .filter-value {
        color: var(--text-primary, #222);
        font-weight: 500;
    }
    
    .filter-group:not(.has-value) .filter-value {
        color: var(--text-muted, #b0b0b0);
    }

    .filter-divider {
        height: 20px;
        margin: 0 2px;
        opacity: 0.5;
    }

    .search-submit-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        padding: 0;
        border-radius: 18px;
        font-size: 13px;
        margin-left: 4px;
        flex-shrink: 0;
    }

    .search-submit-btn .search-btn-text {
        display: none !important;
    }

    .primary-search-bar:hover .search-submit-btn,
    .primary-search-bar:focus-within .search-submit-btn {
        padding: 0;
    }
    
    /* Compact search container */
    .search-filters-container {
        gap: 6px;
    }
    
    .search-filters-bar {
        padding: 6px 10px;
    }

    /* Hide secondary filters on mobile - Filters button is now in search bar */
    .secondary-filters {
        display: none !important;
    }
    
    /* Show Inline Filters Button in Search Bar on Mobile */
    .filter-btn-inline {
        display: flex !important;
        width: 36px;
        height: 36px;
        min-width: 36px;
        padding: 0;
        border: none;
        border-radius: 18px;
        background: transparent;
        color: var(--text-secondary, #717171);
        font-size: 16px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        flex-shrink: 0;
        margin: 0 4px;
        transition: all 0.2s ease;
    }
    
    .filter-btn-inline:hover,
    .filter-btn-inline:focus {
        background: var(--bg-hover, #f7f7f7);
        color: var(--text-primary, #222);
    }
    
    .filter-btn-inline:active {
        transform: scale(0.95);
    }
    
    .filter-btn-inline.active {
        background: rgba(255, 56, 92, 0.1);
        color: #ff385c;
    }
    
    .filter-btn-inline.has-filters {
        color: #ff385c;
    }
    
    /* Filter count badge on inline button */
    .filter-btn-inline .filter-count-badge {
        position: absolute;
        top: -2px;
        right: -2px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        background: linear-gradient(135deg, #ff385c 0%, #e61e4d 100%);
        color: #fff;
        font-size: 10px;
        font-weight: 600;
        border-radius: 8px;
        display: none;
        align-items: center;
        justify-content: center;
        line-height: 1;
        border: 2px solid #fff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    }
    
    .filter-btn-inline.has-filters .filter-count-badge {
        display: flex;
    }

    /* Dropdown positioning on mobile - Bottom sheet style */
    .search-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        transform: translateY(100%) !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: calc(100vh - var(--navbar-height-mobile, 50px) - 80px) !important;
        max-height: calc(100dvh - var(--navbar-height-mobile, 50px) - 80px) !important; /* Support dynamic viewport height */
        max-width: 100% !important;
        width: 100% !important;
        padding-bottom: env(safe-area-inset-bottom, 0) !important; /* Account for safe areas (notch, etc.) */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        /* Ensure dropdown is above everything except navbar */
        z-index: 9999 !important;
    }

    .search-dropdown.active {
        transform: translateY(0) !important;
    }

    .location-dropdown {
        max-width: 100%;
        padding: 16px 0 !important;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0)) !important; /* Extra padding for safe areas */
    }
    
    /* Ensure dropdown content has proper padding */
    .location-dropdown .dropdown-section {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    
    /* Last item padding for safe area */
    .location-dropdown .location-item:last-child {
        margin-bottom: calc(8px + env(safe-area-inset-bottom, 0)) !important;
    }
}

@media (max-width: 540px) {
    .primary-search-bar {
        min-height: 44px;
        border-radius: 28px !important;
        padding: 3px 6px;
    }
    
    /* Update rounded corners for smaller radius */
    .primary-search-bar .filter-group:first-child {
        border-top-left-radius: 28px;
        border-bottom-left-radius: 28px;
    }
    
    .primary-search-bar .search-submit-btn {
        border-top-right-radius: 28px !important;
        border-bottom-right-radius: 28px !important;
    }
    
    .filter-group {
        flex-shrink: 0;
        padding: 5px 8px;
        min-height: 38px;
    }
    
    .filter-group.location-group {
        min-width: 130px;
        flex: 1 1 130px;
        max-width: 160px;
    }

    .filter-group.check-in-group,
    .filter-group.check-out-group {
        min-width: 80px;
        flex: 0 0 80px;
        max-width: 100px;
    }

    .filter-group.guests-group {
        min-width: 80px;
        flex: 0 0 80px;
        max-width: 100px;
    }

    /* Ultra-compact labels on very small screens */
    .filter-group label {
        font-size: 8px;
        margin-bottom: 0;
    }

    .filter-group input[type="text"],
    .filter-group .filter-value {
        font-size: 11px;
        line-height: 1.1;
    }
    
    /* Abbreviate long text */
    .filter-group .filter-value {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    .filter-divider {
        height: 18px;
        flex-shrink: 0;
        margin: 0 1px;
    }

    .search-submit-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        padding: 0;
        flex-shrink: 0;
        border-radius: 16px;
        font-size: 12px;
    }
    
    .search-submit-btn .search-btn-text {
        display: none !important;
    }

    /* Secondary filters hidden on small mobile */
    .secondary-filters {
        display: none !important;
    }
    
    .search-filters-container {
        gap: 4px;
    }
    
    .search-filters-bar {
        padding: 4px 8px;
    }
}

/* ==============================================
   DARK MODE
   ============================================== */

[data-theme="dark"] .primary-search-bar {
    background: var(--bg-secondary, #1e1e1e);
    border-color: var(--border-color, #333);
}

[data-theme="dark"] .filter-group:hover,
[data-theme="dark"] .filter-group.active {
    background: var(--bg-hover, #2a2a2a);
}

[data-theme="dark"] .filter-group label {
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .filter-group input[type="text"],
[data-theme="dark"] .filter-group .filter-value {
    color: var(--text-secondary, #aaa);
}

[data-theme="dark"] .filter-divider {
    background: var(--border-color, #333);
}

[data-theme="dark"] .filter-pill {
    background: var(--bg-secondary, #1e1e1e);
    border-color: var(--border-color, #333);
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .filter-pill:hover {
    border-color: var(--text-primary, #fff);
}

[data-theme="dark"] .filter-pill.active,
[data-theme="dark"] .filter-pill.has-value {
    background: #fff;
    color: #222;
}

[data-theme="dark"] .search-dropdown {
    background: var(--bg-secondary, #1e1e1e);
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .location-item:hover,
[data-theme="dark"] .location-item.selected {
    background: var(--bg-hover, #2a2a2a);
}

[data-theme="dark"] .location-item-icon {
    background: var(--bg-primary, #121212);
}

[data-theme="dark"] .location-item-name {
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .dropdown-section + .dropdown-section {
    border-color: var(--border-color, #333);
}

@media (max-width: 768px) {
    [data-theme="dark"] .primary-search-bar {
        background: rgba(30, 30, 30, 0.95);
    }

    [data-theme="dark"] .secondary-filters {
        background: rgba(30, 30, 30, 0.95);
    }
}
