/**
 * Search page — mobile-first, responsive (v2)
 */

:root {
    --search-panel-px: 1rem;
    --search-sticky-footer-h: 4.25rem;
}

@media (min-width: 768px) {
    :root {
        --search-panel-px: 1.25rem;
    }
}

/* ---- Page ---- */
.page-search-v2 {
    background: var(--soft-bg);
}

.search-v2 {
    padding-top: 0.5rem;
    padding-bottom: calc(var(--bottom-nav-height, 64px) + env(safe-area-inset-bottom, 0px) + 1rem);
}

@media (min-width: 992px) {
    .search-v2 {
        padding-bottom: 2rem;
    }
}

.search-v2__container {
    max-width: 1000px;
}

.search-v2-topbar {
    margin-bottom: 0.85rem;
}

.search-v2-topbar__title {
    margin: 0 0 0.2rem;
    font-size: clamp(1.35rem, 4vw, 1.6rem);
    font-weight: 700;
    color: var(--text);
}

.search-v2-topbar__sub {
    margin: 0;
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.search-v2__layout {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

@media (min-width: 768px) {
    .search-v2__layout {
        display: grid;
        grid-template-columns: minmax(200px, 220px) minmax(0, 1fr);
        align-items: start;
        gap: 1rem;
    }
}

/* ---- Navigation (mobile: sticky pills) ---- */
.search-v2-nav {
    display: flex;
    flex-direction: row;
    gap: 0.35rem;
    padding: 0.4rem;
    margin: 0 -0.25rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding: 0.4rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    touch-action: pan-x;
}

.search-v2-nav::-webkit-scrollbar {
    display: none;
}

@media (max-width: 767.98px) {
    .search-v2-nav {
        position: sticky;
        top: var(--nav-total-height, 56px);
        z-index: 1020;
        margin-left: calc(-1 * var(--bs-gutter-x, 0.75rem));
        margin-right: calc(-1 * var(--bs-gutter-x, 0.75rem));
        padding-left: calc(var(--bs-gutter-x, 0.75rem) + 0.35rem);
        padding-right: calc(var(--bs-gutter-x, 0.75rem) + 0.35rem);
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        box-shadow: 0 4px 12px rgba(91, 31, 150, 0.08);
    }
}

@media (min-width: 768px) {
    .search-v2-nav {
        flex-direction: column;
        overflow: visible;
        margin: 0;
        position: sticky;
        top: calc(var(--nav-total-height, 56px) + 0.5rem);
        scroll-snap-type: none;
    }
}

.search-v2-nav__heading {
    display: none;
    margin: 0 0 0.4rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

@media (min-width: 768px) {
    .search-v2-nav__heading {
        display: block;
    }
}

.search-v2-nav__item {
    flex: 1 1 0;
    min-width: 5.5rem;
    max-width: 100%;
    scroll-snap-align: center;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.55rem;
    min-height: 48px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    text-align: left;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, border-color 0.15s;
}

@media (max-width: 767.98px) {
    .search-v2-nav__item {
        flex-direction: column;
        justify-content: center;
        text-align: center;
        gap: 0.25rem;
        padding: 0.55rem 0.4rem;
        min-height: 56px;
    }
}

@media (min-width: 768px) {
    .search-v2-nav__item {
        flex: none;
        width: 100%;
        min-width: 0;
        flex-direction: row;
        text-align: left;
        padding: 0.75rem 0.7rem;
    }
}

.search-v2-nav__icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--soft-bg);
    color: var(--primary);
    font-size: 0.9rem;
}

@media (min-width: 768px) {
    .search-v2-nav__icon {
        width: 36px;
        height: 36px;
    }
}

.search-v2-nav__text {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    min-width: 0;
    flex: 1;
}

.search-v2-nav__label {
    font-size: 0.8rem;
    color: var(--primary-dark);
    font-weight: 700;
    line-height: 1.2;
}

.search-v2-nav__label--short {
    display: block;
}

.search-v2-nav__label--full,
.search-v2-nav__hint,
.search-v2-nav__arrow {
    display: none;
}

@media (min-width: 768px) {
    .search-v2-nav__label--short {
        display: none;
    }

    .search-v2-nav__label--full,
    .search-v2-nav__hint {
        display: block;
    }

    .search-v2-nav__hint {
        font-size: 0.7rem;
        color: var(--text-muted);
        font-weight: 400;
    }

    .search-v2-nav__arrow {
        display: block;
        margin-left: auto;
        font-size: 0.65rem;
        color: var(--text-muted);
    }
}

.search-v2-nav__item.is-active {
    background: var(--soft-lavender);
    border-color: rgba(123, 44, 191, 0.2);
}

.search-v2-nav__item.is-active .search-v2-nav__icon {
    background: var(--primary);
    color: #fff;
}

/* ---- Main content ---- */
.search-v2-main {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}

.search-v2-card {
    overflow: hidden;
}

.search-v2-panels {
    scroll-margin-top: calc(var(--nav-total-height, 56px) + 4.5rem);
}

.search-hub-panel,
.search-v2-panel {
    display: none;
}

.search-hub-panel.is-active,
.search-v2-panel.is-active {
    display: block;
    padding: 1rem var(--search-panel-px);
    padding-bottom: calc(var(--search-panel-px) + var(--search-sticky-footer-h) + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 768px) {
    .search-hub-panel.is-active,
    .search-v2-panel.is-active {
        padding-bottom: var(--search-panel-px);
    }
}

.search-v2-panel__head {
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    .search-v2-panel__head {
        display: none;
    }
}

.search-v2-panel__title {
    margin: 0 0 0.2rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.search-v2-panel__sub {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ---- Form primitives ---- */
.search-v2-label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.search-v2-hint {
    margin: 0.5rem 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.search-v2-query {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.85rem;
    min-height: 48px;
    background: #fff;
    border: 1px solid var(--lavender);
    border-radius: var(--radius-sm);
}

@media (min-width: 768px) {
    .search-v2-query {
        min-height: 52px;
        padding: 0 1rem;
    }
}

.search-v2-query:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(123, 44, 191, 0.12);
}

.search-v2-query__icon {
    color: var(--primary);
    flex-shrink: 0;
}

.search-v2-query__input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    font-size: 16px; /* prevents iOS zoom on focus */
    color: var(--text);
    outline: none;
    padding: 0.6rem 0;
}

.search-v2-query--id {
    padding-left: 0;
}

.search-v2-query__prefix {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    min-height: 48px;
    background: var(--soft-lavender);
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 0.88rem;
    border-right: 1px solid var(--lavender);
}

.search-v2-segment {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    margin-bottom: 1rem;
    padding: 0.3rem;
    background: var(--soft-bg);
    border-radius: var(--radius-sm);
}

.search-v2-segment__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 44px;
    padding: 0.5rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.search-v2-segment__btn i {
    color: var(--primary);
}

.search-v2-segment__btn.is-active {
    background: #fff;
    color: var(--primary-dark);
    box-shadow: 0 1px 4px rgba(91, 31, 150, 0.1);
}

.basic-search-panel {
    display: none;
}

.basic-search-panel.is-active {
    display: block;
}

.search-v2-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.65rem;
}

.search-v2-chip,
.hub-chip {
    min-height: 40px;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--lavender);
    border-radius: 999px;
    background: #fff;
    color: var(--primary-dark);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
}

.search-v2-chip:hover,
.hub-chip:hover {
    border-color: var(--primary-light);
    background: var(--soft-lavender);
}

.hub-chip.is-active,
.search-v2-chip.is-active {
    border-color: var(--primary);
    background: var(--soft-lavender);
    font-weight: 600;
}

/* ---- Advanced filters ---- */
.search-v2-filters__bar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--lavender);
}

@media (min-width: 480px) {
    .search-v2-filters__bar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
    }
}

.search-v2-match__label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.search-v2-match__value {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.search-v2-match__value i {
    color: var(--primary);
}

.search-v2-filters__bulk {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
}

@media (min-width: 480px) {
    .search-v2-filters__bulk {
        display: flex;
        width: auto;
    }
}

.search-v2-filters__bulk .btn {
    min-height: 44px;
    font-size: 0.82rem;
}

.search-v2-accordion {
    border: 1px solid var(--lavender);
    border-radius: var(--radius-sm);
    margin-bottom: 0.6rem;
    background: #fff;
}

.search-v2-accordion__head {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 0.85rem 1rem;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--primary-dark);
    cursor: pointer;
    list-style: none;
    touch-action: manipulation;
}

.search-v2-accordion__head::-webkit-details-marker {
    display: none;
}

.search-v2-accordion__head::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.search-v2-accordion[open] .search-v2-accordion__head::after {
    transform: rotate(180deg);
}

.search-v2-fields {
    display: grid;
    gap: 1rem;
    padding: 0 0.85rem 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .search-v2-fields {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

.search-v2-fields--2 {
    grid-template-columns: 1fr;
}

@media (min-width: 480px) {
    .search-v2-fields--2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Marital status + Age on one row */
.search-v2-fields__pair {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    grid-column: 1 / -1;
}

@media (min-width: 576px) {
    .search-v2-fields__pair {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
    }
}

.search-v2-fields__pair > .search-v2-field {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.search-v2-fields > .search-v2-field--range {
    grid-column: 1 / -1;
}

.search-v2-field {
    min-width: 0;
}

.search-v2-field__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    min-height: 2rem;
}

.search-v2-field__head--range {
    justify-content: flex-start;
}

.search-v2-field__quick {
    display: inline-flex;
    gap: 0.65rem;
}

.search-v2-link-btn {
    border: 0;
    background: none;
    padding: 0.35rem 0;
    min-height: 32px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    touch-action: manipulation;
}

.search-v2-field--range .search-v2-label {
    margin: 0;
    line-height: 1.3;
}

.search-v2-range {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.35rem;
    align-items: center;
    flex: 1;
}

.search-v2-range .select2-container {
    width: 100% !important;
    min-width: 0;
}

.search-v2-range .select2-container--bootstrap-5 .select2-selection {
    min-height: 48px;
    display: flex;
    align-items: center;
}

.search-v2-fields__pair .search-v2-range .select2-container--bootstrap-5 .select2-selection,
.search-v2-fields__pair .ts-wrapper.multi .ts-control {
    min-height: 48px;
}

@media (min-width: 768px) {
    .search-v2-fields__pair .search-v2-range .select2-container--bootstrap-5 .select2-selection,
    .search-v2-fields__pair .ts-wrapper.multi .ts-control {
        min-height: 44px;
    }
}

@media (min-width: 768px) {
    .search-v2-range .select2-container--bootstrap-5 .select2-selection {
        min-height: 44px;
    }
}

.search-v2-range__sep {
    align-self: center;
    padding-top: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 48px;
}

@media (min-width: 768px) {
    .search-v2-range__sep {
        line-height: 44px;
    }
}

.advance-select--disabled,
.advance-select--disabled + .ts-wrapper {
    opacity: 0.9;
    pointer-events: none;
}

select.advance-select--disabled {
    background: #f3f0f7;
}

/* ---- Location ---- */
.search-v2-loc {
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
}

.search-v2-loc__block {
    padding-bottom: 1.15rem;
    border-bottom: 1px solid var(--lavender);
}

.search-v2-loc__block:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.search-v2-loc__title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.search-v2-loc__title i {
    color: var(--primary);
}

.search-v2-radius__head {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.search-v2-radius__value {
    font-size: 1.3rem;
    color: var(--primary);
}

.search-v2-radius__unit {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.search-v2-radius__slider {
    --bs-form-range-thumb-bg: var(--primary);
    min-height: 44px;
    margin-bottom: 0.65rem;
}

.search-v2-map-preview {
    margin-top: 0.85rem;
    padding: 1.15rem 0.85rem;
    text-align: center;
    background: linear-gradient(165deg, var(--soft-lavender) 0%, #fff 60%);
    border: 1px dashed rgba(123, 44, 191, 0.22);
    border-radius: var(--radius-sm);
}

.search-v2-map-preview__pin {
    width: 40px;
    height: 40px;
    margin: 0 auto 0.45rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    background: var(--primary);
    color: #fff;
}

.search-v2-map-preview__pin i {
    transform: rotate(45deg);
}

.search-v2-map-preview__title {
    margin: 0 0 0.15rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--primary-dark);
}

.search-v2-map-preview__sub {
    margin: 0;
    font-size: 0.76rem;
    color: var(--text-muted);
}

/* ---- History ---- */
.search-v2-history {
    padding: 0;
    overflow: hidden;
}

.search-v2-history__scroll {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0.85rem var(--search-panel-px);
}

@media (max-width: 575.98px) {
    .search-v2-history__scroll {
        flex-direction: row;
        gap: 0.65rem;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }

    .search-v2-history__col {
        flex: 0 0 min(88vw, 320px);
        scroll-snap-align: start;
        padding: 0.75rem;
        background: var(--soft-bg);
        border: 1px solid var(--lavender);
        border-radius: var(--radius-sm);
    }
}

@media (min-width: 576px) {
    .search-v2-history__scroll {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        padding: 0.95rem 1rem;
    }
}

.search-v2-history__title {
    margin: 0 0 0.55rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.search-v2-history__title i {
    color: var(--primary);
}

.search-v2-history__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.search-v2-history__list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--lavender);
    font-size: 0.8rem;
    min-height: 40px;
}

.search-v2-history__list li:last-child {
    border-bottom: 0;
}

.search-v2-history__link {
    flex-shrink: 0;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}

/* ---- Sticky footer actions (mobile) ---- */
.search-v2-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--lavender);
}

.search-v2-footer--bar {
    gap: 0.5rem;
}

@media (max-width: 767.98px) {
    .search-v2-panel .search-v2-footer.search-hub-form__actions--sticky {
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(var(--bottom-nav-height, 64px) + env(safe-area-inset-bottom, 0px));
        z-index: 1030;
        margin: 0;
        padding: 0.65rem var(--search-panel-px);
        padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid var(--lavender);
        box-shadow: 0 -6px 20px rgba(91, 31, 150, 0.12);
    }

    .search-v2-footer--bar {
        display: grid;
        grid-template-columns: 1fr 1.2fr;
    }

    .search-v2-footer--bar .btn {
        min-height: 48px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.4rem;
        font-size: 0.88rem;
        margin: 0;
    }

    .search-v2-footer--single .btn {
        width: 100%;
        min-height: 48px;
    }
}

@media (min-width: 768px) {
    .search-v2-footer {
        flex-wrap: nowrap;
    }

    .search-v2-footer .btn-primary-rose {
        margin-left: auto;
    }

    .search-v2-footer--bar {
        display: flex;
        justify-content: flex-end;
    }
}

/* ---- Tom Select (touch-friendly) ---- */
#searchLocationForm .ts-wrapper,
#searchAdvancedForm .ts-wrapper {
    width: 100%;
}

#searchLocationForm .ts-wrapper.single .ts-control,
#searchLocationForm .ts-wrapper.multi .ts-control,
#searchAdvancedForm .ts-wrapper.single .ts-control,
#searchAdvancedForm .ts-wrapper.multi .ts-control {
    min-height: 48px;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--lavender);
    background: #fff;
    font-size: 16px;
    box-shadow: none;
}

@media (min-width: 768px) {
    #searchLocationForm .ts-wrapper.single .ts-control,
    #searchLocationForm .ts-wrapper.multi .ts-control,
    #searchAdvancedForm .ts-wrapper.single .ts-control,
    #searchAdvancedForm .ts-wrapper.multi .ts-control {
        font-size: 0.9rem;
        min-height: 44px;
    }
}

#searchLocationForm .ts-wrapper.focus .ts-control,
#searchAdvancedForm .ts-wrapper.focus .ts-control {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(123, 44, 191, 0.12);
}

#searchLocationForm .ts-dropdown,
#searchAdvancedForm .ts-dropdown {
    border-radius: var(--radius-sm);
    border-color: var(--lavender);
    box-shadow: 0 8px 24px rgba(91, 31, 150, 0.15);
    z-index: 1060;
}

#searchAdvancedForm .ts-dropdown .active,
#searchLocationForm .ts-dropdown .active {
    background: var(--soft-lavender);
    color: var(--primary-dark);
}

#searchAdvancedForm .item,
#searchLocationForm .item {
    background: var(--soft-lavender) !important;
    color: var(--primary-dark) !important;
    border: 0 !important;
    border-radius: 999px !important;
}

#searchAdvancedForm .plugin-checkbox_options .option {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0.55rem 0.85rem;
}

#searchAdvancedForm .plugin-checkbox_options .option input {
    width: 1.1rem;
    height: 1.1rem;
    margin-right: 0.55rem;
    accent-color: var(--primary);
}

#searchAdvancedForm .plugin-clear_button .clear-button {
    color: var(--primary);
    font-size: 1.15rem;
    padding: 0.35rem;
}

@media (max-width: 767.98px) {
    #searchLocationForm .ts-dropdown,
    #searchAdvancedForm .ts-dropdown {
        max-height: min(55vh, 320px);
    }

    #searchAdvancedForm .ts-dropdown .option,
    #searchLocationForm .ts-dropdown .option {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* Very small phones */
@media (max-width: 359.98px) {
    .search-v2-nav__item {
        min-width: 4.75rem;
    }

    .search-v2-nav__label {
        font-size: 0.72rem;
    }
}
