/* Поиск и фильтры на карте (этап 1 ТЗ). Макеты: Figma, «Поиск В2 — 1…3»:
   на карте только поле поиска; теги-фильтры — в его панели, выбранные — чипами под полем.
   Поле, чипы и панель одной ширины и стоят по центру карты. */

.search-box {
    position: absolute;
    /* там же, где раньше стоял ряд фильтров */
    top: calc(var(--promo-offset) + 94px);
    z-index: 6;
    left: 50%;
    width: 480px;
    transform: translateX(-50%);
    font-family: var(--font-family);
    color: var(--color-black);
    /* сам контейнер карту не перекрывает — нажатия ловят только его элементы */
    pointer-events: none;
}

.search-box > * {
    pointer-events: auto;
}

.search-box [hidden] {
    display: none !important;
}

/* Выбранные фильтры под полем */
.search-selected {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-8);
    margin-top: var(--space-8);
}

.search-selected__chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 4px 9px 12px;
    border-radius: 50px;
    background: var(--color-black);
    box-shadow: var(--shadow-map-control);
    color: var(--color-white);
    font-size: var(--font-size-13);
    line-height: var(--line-height-16);
    white-space: nowrap;
}

.search-selected__remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 21px;
    height: 16px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}

.search-selected__remove img {
    display: block;
    width: 9px;
    height: 9px;
}

/* Чип тега в панели поиска: серый, выбранный — чёрный с галочкой */
.filter-chip {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    padding: 10px 12px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--color-gray-bg);
    font-family: inherit;
    font-size: var(--font-size-13);
    line-height: var(--line-height-16);
    color: var(--color-black);
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.filter-chip.is-selected {
    background: var(--color-black);
    color: var(--color-white);
}

.filter-chip.is-selected::before {
    content: "";
    width: 12px;
    height: 8.57px;
    background: url("/images/icons/check-white.svg") no-repeat center / contain;
}

/* «Нравится» — с сердцем; у выбранного сердце белое, галочка не нужна */
.filter-chip--favorites {
    gap: 5px;
}

.filter-chip__icon,
.search-selected__icon {
    display: block;
    width: 12px;
    height: 10.1px;
}

.filter-chip--favorites.is-selected .filter-chip__icon {
    filter: invert(1);
}

.filter-chip--favorites.is-selected::before {
    content: none;
}

/* Панель при пустом поле: теги и недавние запросы */
.search-idle {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 10px 16px 8px;
}

.search-idle__section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-idle__section--recent {
    gap: var(--space-4);
}

.search-idle__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    font-size: var(--font-size-12);
    line-height: var(--line-height-16);
    color: var(--color-gray-text);
}

.search-idle__head button {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    color: var(--color-black);
    cursor: pointer;
}

.search-idle__tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-8);
}

/* недавние запросы внутри секции — без собственных боковых отступов */
.search-idle .search-row--recent {
    padding: 10px 0;
}

.search-idle .search-row--recent:hover,
.search-idle .search-row--recent:focus-visible {
    background: none;
}

/* Поле */
.search-field {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    height: 44px;
    padding: 0 8px 0 14px;
    box-sizing: border-box;
    background: var(--color-white);
    border: 1px solid rgba(0, 0, 0, 0.35);
    border-radius: 22px;
    box-shadow: var(--shadow-map-control);
}

/* Поле в фокусе: открыта панель поиска */
body.search-open .search-field {
    border: 1.5px solid var(--color-black);
    /* рамка толще на полпикселя с каждой стороны — содержимое не должно сдвигаться */
    padding: 0 7.5px 0 13.5px;
}

.search-field button {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.search-field__icon {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
}

.search-field input {
    flex: 1 1 0;
    min-width: 0;
    height: 40px;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-family: inherit;
    /* не мельче 16px, иначе iOS масштабирует страницу при фокусе */
    font-size: var(--font-size-16);
    line-height: var(--line-height-22);
    color: var(--color-black);
    caret-color: var(--color-black);
    -webkit-appearance: none;
    appearance: none;
}

.search-field input::placeholder {
    color: var(--color-gray-light);
    opacity: 1;
}

.search-field__clear {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-14) !important;
    background: var(--color-gray-bg) !important;
}

.search-field__clear img {
    width: 9px;
    height: 9px;
}

/* Под полем в режиме «на карте»: выход из поиска и (пока скрыт) счётчик найденного.
   Фон и тень — у плашки со счётчиком; пока он скрыт, остаётся одна кнопка. */
.search-count {
    display: flex;
    align-items: center;
    gap: var(--space-12);
    margin-top: var(--space-8);
}

.search-count:has(.search-count__text:not([hidden])) {
    padding: 6px 6px 6px 14px;
    background: var(--color-white);
    border-radius: var(--radius-20);
    box-shadow: var(--shadow-map-control);
}

.search-count {
    font-size: var(--font-size-12);
    line-height: var(--line-height-16);
}

.search-count__text {
    flex: 1 1 0;
    min-width: 0;
}

.search-count__reset,
.search-button {
    flex: 0 0 auto;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--color-black);
    color: var(--color-white);
    font-family: inherit;
    font-size: var(--font-size-12);
    line-height: var(--line-height-14);
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.search-count__reset {
    height: var(--height-button-s);
    padding: 0 14px;
    box-shadow: var(--shadow-map-control);
}

.search-button {
    height: var(--height-button-m);
    padding: 0 20px;
}

.search-panel__footer {
    padding: 10px 16px 6px;
}

.search-panel__footer .search-button {
    width: 100%;
}

/* Панель результатов */
.search-panel {
    margin-top: 10px;
    padding: 6px 0 8px;
    /* точную высоту выставляет скрипт по видимой области (с учётом клавиатуры) */
    max-height: 60vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    background: var(--color-white);
    border-radius: var(--radius-14);
    box-shadow: var(--shadow-map-panel);
    -webkit-overflow-scrolling: touch;
}

.search-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 6px;
    font-size: var(--font-size-12);
    line-height: var(--line-height-16);
    color: var(--color-gray-text);
}

.search-panel__header button {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    color: var(--color-black);
    cursor: pointer;
}

.search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 6px 16px;
    border: 0;
    background: none;
    font-family: inherit;
    text-align: left;
    color: var(--color-black);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.search-row:hover,
.search-row:focus-visible {
    background: var(--color-gray-bg);
    outline: 0;
}

/* Недавний запрос */
.search-row--recent {
    padding: 11px 16px;
    font-size: var(--font-size-16);
    line-height: var(--line-height-22);
}

.search-row--recent > img {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
}

.search-row__text {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-row__remove {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin: -6px -10px -6px 0;
}

.search-row__remove img {
    width: 10px;
    height: 10px;
}

/* Заведение в результатах */
.search-row__thumb {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-8);
    object-fit: cover;
    background: var(--color-gray-bg);
}

.search-row__body {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.search-row__name {
    font-size: 15px;
    line-height: var(--line-height-20);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-row__name b {
    font-weight: 700;
}

.search-row__sub b {
    font-weight: 600;
    color: var(--color-black);
}

/* Строка тега в результатах */
.search-row__hash {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-8);
    background: var(--color-gray-bg);
    font-size: var(--font-size-18);
    line-height: var(--line-height-24);
    color: var(--color-gray-text);
}

.search-panel__note {
    padding: 8px 16px 2px;
    font-size: var(--font-size-12);
    line-height: var(--line-height-16);
    color: var(--color-gray-text);
}

.search-row__sub {
    font-size: var(--font-size-12);
    line-height: var(--line-height-16);
    color: var(--color-gray-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-row__vacancies {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px 4px 6px;
    background: var(--color-gray-bg);
    border-radius: 50px;
    font-size: var(--font-size-12);
    line-height: var(--line-height-16);
}

.search-row__vacancies img {
    width: 10px;
    height: 10px;
}

/* Популярные теги */
.search-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 4px 16px 8px;
}

.search-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--color-gray-bg);
    font-family: inherit;
    font-size: var(--font-size-13);
    line-height: var(--line-height-16);
    color: var(--color-black);
    cursor: pointer;
    white-space: nowrap;
}

.search-chip img {
    width: 12px;
    height: 12px;
}

/* Ничего не найдено */
.search-empty {
    padding: 18px 16px 12px;
    text-align: center;
}

.search-empty p {
    margin: 0 0 14px;
    font-size: var(--font-size-16);
    line-height: var(--line-height-22);
}


/* Приглушение карты под открытым поиском */
.search-dim {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(255, 255, 255, 0.6);
}

.search-dim[hidden] {
    display: none;
}

@media (max-width: 600px) {
    /* поле и панель под ним — по центру карты, с равными отступами от её краёв */
    .search-box {
        left: 24px;
        right: 24px;
        width: auto;
        transform: none;
    }
}
