/* Search results page: the filter panel folds out of the bar above the results (loaded only on the
   search results routes). It used to be a 260px sidebar, which left the grid too narrow for the third
   card; the grid now has the container to itself and keeps new_style.css's own column count. */

.search-results-layout {
    margin-top: 1.5rem;
}

.search-results-main .sorting-controls {
    margin-top: 0;
}

.search-date-error {
    margin: 1rem 0 0;
    padding: 0.75rem 1rem;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #991b1b;
    font-weight: 500;
}

/* --- The button that folds the panel out --- */
.filter-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-width: 11rem;
    padding: 0.45rem 1.35rem;
    border: 2px solid #3b82f6;
    border-radius: 8px;
    background: #ffffff;
    color: #1e40af;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
}

.filter-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.25);
}

.filter-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

/* Open: the same gradient as the primary buttons, so an open panel is unmistakable */
.filter-toggle.is-open {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    border-color: transparent;
    color: #ffffff;
}

.filter-toggle-icon {
    width: 1.1rem;
    height: 1.1rem;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
}

/* The handles are filled so the track does not show through them */
.filter-toggle-icon circle {
    fill: #ffffff;
}

.filter-toggle.is-open .filter-toggle-icon circle {
    fill: currentColor;
}

/* How many filters are on, so the count survives the panel being shut */
.filter-toggle-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: #1e40af;
    color: #ffffff;
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.filter-toggle.is-open .filter-toggle-count {
    background: rgba(255, 255, 255, 0.25);
}

.filter-toggle-caret {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform 0.25s ease;
}

.filter-toggle.is-open .filter-toggle-caret {
    transform: rotate(180deg);
}

/* --- The fold itself: a grid row that grows from nothing to its content's height --- */
.search-filters-panel {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.32s ease;
}

.search-filters-panel.is-open {
    grid-template-rows: 1fr;
}

.search-filters-panel > * {
    overflow: hidden;
    min-height: 0;
    /* Hidden only once it has finished folding shut, so nothing inside takes the keyboard meanwhile */
    visibility: hidden;
    transition: visibility 0s linear 0.32s;
}

.search-filters-panel.is-open > * {
    visibility: visible;
    transition: visibility 0s;
}

/* --- Filter panel --- */
/* Deliberately tight: this is a control strip above the results, not content in its own right. */
.search-filters {
    position: relative;
    border-top: 1px solid #e5e7eb;
    padding-top: 0.85rem;
}

/* In the top right corner, in the space the tick-box column leaves above itself, so shutting the
   panel from inside it costs no height. */
.filter-close {
    position: absolute;
    top: 0.35rem;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #6b7280;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.filter-close:hover {
    background: #eff6ff;
    color: #1e40af;
}

.filter-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

/* Three columns with a job each: the sliders, the things you tick, and what is currently on with the
   buttons that act on it. Each column stacks its own contents, so nothing is offset to meet anything
   in the column beside it. The last is narrower - it holds pills and two buttons, not controls. */
.search-filters-form {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 0.9fr);
    gap: 1.25rem 2.5rem;
    align-items: start;
}

.filter-column {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    min-width: 0;
}

/* The third column is a summary, so it is set off by a rule rather than being another run of fields */
.filter-column-summary {
    gap: 1rem;
    padding-left: 2.5rem;
    border-left: 1px solid #e9eef4;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    border: none;
    margin: 0;
    padding: 0;
    width: 100%;
    min-width: 0;
}

/* A group whose control is a set of chips rather than one field. They sit in equal tracks instead of
   taking the width of their own label, so a column of them reads as one block rather than a ragged
   edge - two across where there is room, one where there is not. */
.filter-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
    gap: 0.4rem;
    /* Half a slider's band, so a row of chips sits about where a slider track does */
    padding-top: 0.3rem;
}

/* --- Third column: what is on now --- */
.filter-summary-title {
    font-family: inherit;
    font-weight: 600;
    color: #374151;
    font-size: 0.82rem;
    line-height: 1.15rem;
}

.filter-summary-empty {
    margin: 0.3rem 0 0;
    color: #9aa4b2;
    font-size: 0.85rem;
}

.search-filters .active-filters-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.3rem 0 0;
    padding: 0;
    list-style: none;
}

.filter-group > label,
.filter-group legend {
    font-weight: 600;
    color: #374151;
    font-size: 0.82rem;
    margin: 0;
    padding: 0;
    width: 100%;
    /* One line for every label, so every control under one starts at the same height */
    min-height: 1.15rem;
    line-height: 1.15rem;
}

/* A slider's value belongs on its own label's line, pushed to the far end, rather than stranded in a
   row of its own under the track. That reads as one statement - "bedrooms: 4 or more" - and saves the
   row the readout used to take. */
.filter-group-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
}

.filter-group-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.filter-group-value {
    flex: 0 0 auto;
    /* Set in from the right edge rather than pinned to it: the values still line up with each other
       down the column, without sitting hard against the panel's margin. */
    padding-right: 1.5rem;
    color: #1e40af;
    font-weight: 700;
    /* Fixed-width digits, so the label does not twitch while a handle is being dragged */
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.filter-group-value-sep {
    color: #9aa4b2;
    padding: 0 0.1rem;
}

.filter-group select {
    width: 100%;
    height: 2.25rem;
    padding: 0.3rem 2rem 0.3rem 0.7rem;
    border: 1px solid #dbe3ec;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.88rem;
    color: #1f2937;
    /* The browser's own arrow is the one part of a select that cannot be styled, so it goes and a
       chevron is drawn in its place, in the same blue as the sliders. */
    background-color: #f8fafc;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%231e40af' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 0.7rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.filter-group select:hover {
    border-color: #bfdbfe;
}

.filter-group select:focus {
    outline: none;
    border-color: #3b82f6;
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* --- Price slider: two range inputs stacked on one track; only the thumbs take the pointer --- */
/* The same height as a select, so a slider and a dropdown sit in one band; the track centres itself
   in it and the inputs are centred on the track. */
.price-slider {
    position: relative;
    height: 2.25rem;
    margin: 0 0.4rem;
}

.price-slider-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 5px;
    transform: translateY(-50%);
    background: #e5e7eb;
    border-radius: 3px;
}

.price-slider-range {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    border-radius: 3px;
}

.price-slider input[type="range"] {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 100%;
    height: 28px;
    margin: 0;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
}

.price-slider input[type="range"]::-webkit-slider-runnable-track {
    height: 28px;
    background: none;
    border: none;
}

.price-slider input[type="range"]::-moz-range-track {
    background: none;
    border: none;
}

.price-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    pointer-events: auto;
    width: 22px;
    height: 22px;
    margin-top: 3px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #1e40af;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    cursor: grab;
}

.price-slider input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #1e40af;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    cursor: grab;
}

.price-slider input[type="range"]:focus {
    outline: none;
}

.price-slider input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.35);
}

.price-slider input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.35);
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.88rem;
    color: #1f2937;
    cursor: pointer;
}

/* A bare tick box reads as loose text beside the bordered fields, so each feature is a chip. */
.filter-chip {
    width: 100%;
    min-width: 0;
    padding: 0.3rem 0.7rem;
    border: 1px solid #dbe3ec;
    border-radius: 999px;
    background: #f8fafc;
    box-sizing: border-box;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

/* The label wraps inside the chip instead of widening it */
.filter-chip > span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.filter-chip:hover {
    border-color: #bfdbfe;
    background: #ffffff;
}

.filter-chip:has(input:checked) {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #1e40af;
    font-weight: 600;
}

.filter-chip:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.filter-checkbox input {
    width: 1rem;
    height: 1rem;
    accent-color: #1e40af;
    flex-shrink: 0;
}

/* Under the pills in the third column: the button first, the way you read down to it */
.filter-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.9rem;
    margin-top: auto;
}

.filter-actions .search-btn {
    padding: 0.45rem 1.1rem;
    font-size: 0.88rem;
    box-shadow: none;
}

.filter-reset {
    color: #3b82f6;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* --- Narrower: the summary drops under the two columns of controls, and loses the rule that
       separated it from them. --- */
@media (max-width: 960px) {
    .search-filters-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1.25rem 2rem;
    }

    .filter-column-summary {
        grid-column: 1 / -1;
        padding-left: 0;
        padding-top: 1rem;
        border-left: none;
        border-top: 1px solid #e9eef4;
    }
}

@media (max-width: 620px) {
    .search-filters-form {
        grid-template-columns: minmax(0, 1fr);
        gap: 1.1rem;
    }

    .filter-actions {
        justify-content: space-between;
    }

    .filter-actions .search-btn {
        flex: 1 1 auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .search-filters-panel,
    .filter-toggle,
    .filter-toggle-caret {
        transition: none;
    }
}
