:root {
    --filter-dark-bg: #304b36;
    --filter-border: #c0d3c3;
    --filter-accent-yellow: #dce8df;
    --filter-btn-green: #507154;
    --filter-btn-green-hover: #3d5f41;
}

.property-filter-wrapper {
    background: #fff;
    border: 1px solid rgba(80, 113, 84, .2);
    border-radius: 18px;
    box-shadow: 0 14px 34px rgba(25, 61, 51, 0.1);
    margin-bottom: 28px;
    overflow: visible;
}
.property-filter-wrapper form { margin: 0; }

/* === HEADER === */
.filter-header {
    background: linear-gradient(115deg, #374b38 0%, #48674c 58%, #4e6e52 100%);
    border-radius: 10px 10px 0 0;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}
.filter-header-left {
    display: flex;
    align-items: center;
}
.filter-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

/* === TABS === */
.filter-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
}
.filter-tab {
    padding: 11px 20px !important;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    border-radius: 10px;
}
.filter-tab:hover {
    color: #cbd5e1;
}
.filter-tab.active {
    color: #fff;
    background: #50715469;
}
.filter-tab.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 20px;
    right: 20px;
    height: 2px;
    background: var(--filter-accent-yellow);
}

/* === HEADER CHECKBOXES === */
.header-checkbox {
    color: #cbd5e1 !important;
    font-size: 13px !important;
}
.header-checkbox input[type="checkbox"] {
    accent-color: var(--filter-accent-yellow);
    width: 16px !important;
    height: 16px !important;
}
.header-checkbox:hover {
    color: #fff !important;
}

/* === BODY === */
.filter-body {
    padding: 24px 24px 5px 24px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdfb 100%);
}

/* === FLEX ROW === */
.filter-body .flex-row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -9px;
    margin-bottom: 10px;
    align-items: flex-start;
}
.filter-body .flex-row:last-child {
    margin-bottom: 0;
}

/* === FIELD WRAPPER === */
.filter-field-wrapper {
    flex: 0 0 auto;
    width: 20%;
    padding: 5px 9px;
    box-sizing: border-box;
    margin-bottom: 5px;
}

/* Скрытие полей */
.filter-field-wrapper.hidden {
    display: none !important;
}

/* === FIELDS === */
.filter-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    height: 100%;
}
.filter-field label {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    white-space: nowrap;
}
.filter-field label span {
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    text-transform: none;
    white-space: nowrap;
}
.filter-field select,
.filter-field input[type="text"],
.filter-field input[type="number"] {
    height: 37px;
    border: 1px solid var(--filter-border);
    border-radius: 6px;
    padding: 0 13px;
    font-size: 13px;
    color: #1e293b;
    background: #fff;
    outline: none;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}
.filter-field select:focus,
.filter-field input:focus {
    border-color: var(--filter-btn-green);
    box-shadow: 0 0 0 2px rgba(79, 110, 86, 0.2);
}

/* Современный компактный вид контролов фильтра. */
.filter-field select,
.filter-field input[type="text"],
.filter-field input[type="number"],
.multiselect-toggle {
    background: #f8fbf9;
    border-color: #cbdccf;
    box-shadow: inset 0 1px 2px rgba(48, 75, 54, .04);
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.filter-field select:hover,
.filter-field input[type="text"]:hover,
.filter-field input[type="number"]:hover,
.multiselect-toggle:hover {
    background: #fff;
    border-color: #9fbea4;
}
.filter-field select:focus,
.filter-field input:focus,
.multiselect-toggle:focus-visible {
    background: #fff;
    border-color: var(--filter-btn-green);
    box-shadow: 0 0 0 3px rgba(80, 113, 84, .13);
}

/* === RANGE === */
.filter-range {
    display: flex;
    align-items: center;
    gap: 6px;
}
.filter-range input { 
    flex: 1; 
    min-width: 0; 
}
.range-dash { 
    color: #94a3b8; 
    font-size: 14px; 
    flex-shrink: 0;
}

/* === ROOMS BUTTONS === */
.filter-rooms-buttons {
    display: flex;
    gap: 4px;
}
.room-btn {
    width: 18%;
    height: 38px;
    border: 1px solid var(--filter-border);
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.room-btn:hover {
    border-color: #999;
    background: #f8fafc;
}
.room-btn.active {
    background: var(--filter-dark-bg);
    border-color: var(--filter-dark-bg);
    color: #fff;
}
.room-plus {
    font-size: 10px;
    margin-left: 1px;
}

/* === CHECKBOXES === */
.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #334155;
    white-space: nowrap;
}
.filter-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--filter-btn-green);
    flex-shrink: 0;
}
.filter-checkbox input[type="checkbox"]:hover {
    opacity: 0.8;
}

/* Чекбоксы в строку */
.filter-checkboxes-row-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
    padding-top: 2px;
}
.filter-checkboxes-row-inline .filter-checkbox {
    font-size: 12px;
}

/* === MULTISELECT DROPDOWN === */
.filter-multiselect-dropdown {
    position: relative;
    width: 100%;
}
.multiselect-toggle {
    width: 100%;
    height: 37px;
    border: 1px solid var(--filter-border);
    border-radius: 6px;
    background: #fff;
    padding: 0 13px;
    font-size: 13px;
    color: #1e293b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.multiselect-toggle:hover {
    border-color: #999;
}
.multiselect-toggle i {
    font-size: 10px;
    color: #94a3b8;
    flex-shrink: 0;
}
.multiselect-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.multiselect-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--filter-border);
    border-radius: 12px;
    box-shadow: 0 14px 28px rgba(25, 61, 51, .16);
    padding: 7px;
    z-index: 100;
    display: none;
    max-height: 200px;
    overflow-y: auto;
    min-width: 200px;
}
.multiselect-dropdown.open {
    display: block;
}
.multiselect-dropdown label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 13px;
    border-radius: 3px;
}
.multiselect-dropdown label:hover {
    background: #f1f5f9;
}
.multiselect-dropdown input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--filter-btn-green);
    flex-shrink: 0;
}

/* === ADVANCED PANEL === */
.filter-advanced-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.3s ease, margin 0.3s ease;
    opacity: 0;
    background: #f4f8f4;
    border-top: 1px solid transparent;
    margin: 0 -24px;
    padding: 0 24px;
}
.filter-advanced-panel.open {
    max-height: 900px;
    opacity: 1;
    border-top: 1px solid var(--filter-border);
    padding: 7px 24px 10px;
    margin: 0 -24px;
}
.filter-body { overflow: visible; }
.filter-advanced-panel.open { overflow: visible; }
#fieldRentPets .filter-checkbox,
#fieldRentChildren .filter-checkbox,
#fieldRentFloorRestrictions .filter-checkbox { width: 100%; }
.filter-advanced-panel .flex-row {
    margin: 0 -8px;
}
.filter-advanced-panel .filter-field-wrapper {
    margin-bottom: 0;
}

/* === FOOTER === */
.filter-footer {
    background: linear-gradient(115deg, #1e201f 0%, #1e201f 58%, #1e201f 100%);
    border-radius: 0 0 10px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 24px;
    gap: 12px;
}
.filter-footer-left, .filter-footer-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.filter-footer-center {
    display: flex;
    justify-content: center;
}

.filter-btn {
    height: 38px;
    padding: 0 16px;
    border: 1px solid #b9cfbc;
    border-radius: 10px;
    background: #fff;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}
.filter-btn:hover { background: #f1f5f9; }

.filter-submit-btn {
    height: 42px;
    padding: 0 28px;
    border: none;
    border-radius: 11px;
    background: #46634a;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
}
.filter-submit-btn:hover { background: var(--filter-btn-green); }
.filter-count-value {
    background: rgba(0,0,0,0.2);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.filter-view-btn {
    height: 38px;
    padding: 0 14px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 10px;
    font-size: 13px;
    color: #edf5ee;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.12);
    transition: all 0.15s ease;
}
.filter-view-btn:hover { color: #fff; background: rgba(255,255,255,0.22); }
.filter-view-btn.active {
    background: var(--filter-btn-green);
    border-color: var(--filter-btn-green);
    color: #fff;
}

/* ── Анти-мерцание: скрываем ВСЕ поля и панель до инициализации JS ── */
.property-filter-wrapper:not(.filter-ready) #filterFieldsContainer,
.property-filter-wrapper:not(.filter-ready) .filter-advanced-panel {
    visibility: hidden;
    pointer-events: none;
}
.property-filter-wrapper:not(.filter-ready) #filterFieldsContainer {
    height: 144px;
    overflow: hidden;
}
.property-filter-wrapper.filter-ready #filterFieldsContainer {
    height: auto;
    overflow: visible;
}
/* ── Оверлей загрузки поверх полей фильтра ── */
.filter-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(255,255,255,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    transition: opacity 0.25s ease;
}
.property-filter-wrapper.filter-ready .filter-loading-overlay {
    opacity: 0;
    pointer-events: none;
}
.filter-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--accent, #10b981);
    border-radius: 50%;
    animation: filterSpin 0.7s linear infinite;
}
@keyframes filterSpin {
    to { transform: rotate(360deg); }
}
/* ── Спиннер в кнопке «Найти» при отправке формы ── */
.filter-submit-btn .btn-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: filterSpin 0.6s linear infinite;
    vertical-align: middle;
}
.filter-submit-btn.is-loading {
    pointer-events: none;
    opacity: 0.7;
}

/* Средние экраны ноутбуков: четыре компактные колонки без влияния на мобильную версию. */
@media (min-width: 769px) and (max-width: 1240px) {
    .filter-header,
    .filter-footer { padding: 11px 18px; }
    .filter-header-right { gap: 8px; }
    .filter-tab { padding: 9px 13px !important; font-size: 13px; }
    .filter-body { padding: 17px 18px 3px; }
    .filter-body .flex-row { margin-inline: -7px; }
    .filter-field-wrapper { width: 25%; padding: 4px 7px; margin-bottom: 7px; }
    .filter-field { gap: 4px; }
    .filter-field label { font-size: 10px; }
    .filter-field select,
    .filter-field input,
    .filter-field button {
        height: 36px;
        padding-inline: 10px;
        font-size: 13px;
    }
    .filter-range { gap: 4px; }
    .multiselect-toggle { height: 36px; padding-inline: 10px; font-size: 13px; }
    .filter-footer { gap: 8px; }
    .filter-btn,
    .filter-view-btn { height: 35px; padding-inline: 11px; font-size: 12px; }
    .filter-submit-btn { height: 38px; padding-inline: 19px; font-size: 13px; }
    .filter-advanced-panel,
    .filter-advanced-panel.open { margin-inline: -18px; padding-inline: 18px; }

    .property-filter-wrapper:not(.filter-ready) #filterFieldsContainer {
        height: 134px;
    }
}

@media (max-width: 1100px) {
    /* Не переводим фильтр на четыре ряда: поля сжимаются, сохраняя пять колонок. */
    .filter-field-wrapper { width: 20%; }
}

@media (min-width: 1100px) and (max-width: 1241px) {
    /* В переходном диапазоне сохраняем пять колонок, чтобы основные поля не уходили на третью строку. */
    .filter-field-wrapper { width: 20%; }
}

@media (max-width: 760px) {
    .property-filter-wrapper { border-radius: 14px; }
    .filter-header { border-radius: 14px 14px 0 0; }
    .filter-footer { border-radius: 0 0 14px 14px; }
    .filter-header,
    .filter-footer { padding-inline: 16px; }
    .filter-body { padding: 18px 16px; }
    .filter-field-wrapper { width: 50%; padding-inline: 6px; }
    .filter-body .flex-row { margin-inline: -6px; }
    .filter-advanced-panel,
    .filter-advanced-panel.open { margin-inline: -16px; padding-inline: 16px; }
    .filter-footer { flex-wrap: wrap; }
    .filter-footer-left,
    .filter-footer-center,
    .filter-footer-right { flex: 1 1 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .filter-field-wrapper { width: 100%; }
    .filter-tabs { width: 100%; overflow-x: auto; }
    .filter-tab { padding-inline: 14px !important; }
    .filter-header-right { width: 100%; gap: 10px; }
    .filter-submit-btn { width: 100%; justify-content: center; }
}
