/* CustomSearchFilter — замена Select2
 * Используется в формах поиска круизов (#form-1, #form-2)
 */

/* Базовый контейнер */
.filter-wrapper {
    position: relative;
    width: 100%;
}

/* Кнопка-триггер */
.filter-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 1.3rem;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
    text-align: left;
    min-height: 40px;
    transition:
        border-color 0.15s ease-in-out,
        box-shadow 0.15s ease-in-out;
}

.filter-trigger:hover {
    border-color: #999;
}

.filter-trigger:focus {
    outline: none;
    border-color: #66afe9;
    box-shadow: 0 0 0 2px rgba(102, 175, 233, 0.3);
}

.filter-trigger-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
    padding-right: 6px;
}

.filter-trigger-text.filter-trigger-placeholder {
    color: #999;
}

.filter-trigger-arrow {
    flex: 0 0 auto;
    font-size: 10px;
    color: #666;
    transition: transform 0.2s ease;
}

.filter-trigger[aria-expanded="true"] .filter-trigger-arrow {
    transform: rotate(180deg);
}

/* Дропдаун — рендерится в document.body (портал), позиционируется через JS
   инлайн-стилями top/left/width в координатах документа (absolute + scroll-offset).
   Именно absolute (а не fixed) устойчив к transform на родителях сайта
   (плагины плавного скролла, слайдеры и т.п.), которые ломают position:fixed. */
.filter-dropdown {
    position: absolute;
    z-index: 10000;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    max-height: 340px;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(-6px);
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
    pointer-events: none;
}

/* Пока элемент скрыт (не открыт) — не занимает места */
.filter-dropdown[hidden] {
    display: none;
}

.filter-dropdown.is-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Поиск */
.filter-search-wrap {
    padding: 8px 8px 4px;
    flex: 0 0 auto;
}

.filter-search {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.4;
    box-sizing: border-box;
    transition: border-color 0.15s ease;
}

.filter-search[readonly] {
    opacity: 1.55;
    cursor: default;
    background: #fafafa;
    color: #aaa;
}

.filter-search[readonly]::placeholder {
    color: #bbb;
}

.filter-search:not([readonly]) {
    opacity: 1;
    cursor: text;
    background: #fff;
    border-color: #66afe9;
}

.filter-search:focus {
    outline: none;
    border-color: #66afe9;
    box-shadow: 0 0 0 2px rgba(102, 175, 233, 0.2);
}

/* Список опций */
.filter-options-list {
    flex: 1 1 auto;
    overflow-y: auto;
    max-height: 210px;
    padding: 2px 0;
}

/* Скроллбар */
.filter-options-list::-webkit-scrollbar {
    width: 6px;
}
.filter-options-list::-webkit-scrollbar-track {
    background: transparent;
}
.filter-options-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
.filter-options-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Опции (чекбоксы) */
.filter-option {
    display: flex;
    align-items: center;
    padding: 5px 12px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.4;
    color: #333;
    transition: background 0.1s ease;
    user-select: none;
    margin: 0;
}

.filter-option:hover {
    background: #f5f5f5;
}

.filter-option.filter-option--checked {
    background: #e8f0fe;
}

.filter-option .filter-checkbox {
    flex: 0 0 auto;
    margin-right: 8px;
    margin-top: 0;
    pointer-events: none; /* клик идёт на label */
}

.filter-option.filter-option--hidden {
    display: none;
}

/* Группировка (для ship, dlit) */
.filter-group-label {
    padding: 6px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #eee;
    margin-top: 4px;
}

.filter-group-label:first-child {
    margin-top: 0;
}

/* Кнопка подтверждения */
.filter-apply-wrap {
    padding: 6px 8px 8px;
    flex: 0 0 auto;
    border-top: 1px solid #eee;
}

.filter-apply {
    display: block;
    width: 100%;
    padding: 7px 12px;
    background: #2d7bcb;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
    text-align: center;
}

.filter-apply:hover {
    background: #1a5fa8;
}

.filter-apply:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(45, 123, 203, 0.4);
}

/* Состояние загрузки */
.filter-trigger.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

.filter-trigger.is-loading .filter-trigger-text::after {
    content: "...";
    animation: filter-loading-dots 1.2s steps(3, end) infinite;
}

@keyframes filter-loading-dots {
    0% {
        content: "";
    }
    33% {
        content: ".";
    }
    66% {
        content: "..";
    }
    100% {
        content: "...";
    }
}

/* Пустое состояние */
.filter-no-results {
    padding: 20px 12px;
    text-align: center;
    color: #999;
    font-size: 13px;
}

/* Адаптация для мобильных */
@media (max-width: 576px) {
    .filter-dropdown {
        max-height: 300px;
    }
    .filter-options-list {
        max-height: 180px;
    }
    .filter-option {
        padding: 8px 12px;
        font-size: 14px;
    }
}
