/* ============================================
   RESULTS: the page frame, toolbar, grid, empty state, "Show more", compare picks
   Views/Shared/Components/_ResultsLayout (main.bl-results-frame), _ResultsToolbar (div.bl-toolbar)
   and _ResultsGrid (div.bl-results). Every page that lists stays as a grid (/Listings,
   /Favorites) gets its width, gutters, header and grid from here, so they line up;
   page CSS only adds what is its own (map, chips, breadcrumbs, intro).
   Behaviour: js/app/listing-card.js (infinite scroll, sort auto-submit). Loaded by _Layout.
   ============================================ */

/* --- Page frame: content --page-max wide plus the gutters, the same box as the home rails and
   the header pill, so a results page lines up with the rest of the site --- */
.bl-results-frame {
    width: 100%;
    max-width: calc(var(--page-max) + 2 * var(--gutter));
    margin: 0 auto;
    padding: var(--space-4) var(--gutter) var(--space-12);
}

@media (min-width: 768px) {
    .bl-results-frame {
        padding-top: var(--space-6);
    }
}

/* --- Toolbar ---
   Phones: the heading and its count, then one row of chip buttons (icon + short label) that
   scrolls sideways when it is wider than the screen. The row bleeds to the screen edges so the
   chips slide under them, and is padded so focus rings and the active chip's border never get
   cut off. From 768px the row sits right of the heading, labels in full (Sort shows its value);
   it still scrolls rather than wraps if a long heading leaves it too little room. */
.bl-toolbar {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0 0 var(--space-5);
}

.bl-toolbar__heading {
    min-width: 0;
}

.bl-toolbar .bl-toolbar__title {
    margin: 0;
    color: var(--color-ink);
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.bl-toolbar__sub {
    margin: var(--space-1) 0 0;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.bl-toolbar__actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    margin: 0 calc(-1 * var(--gutter));
    padding: var(--space-1) var(--gutter);
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-padding-inline: var(--gutter);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.bl-toolbar__actions::-webkit-scrollbar {
    display: none;
}

.bl-toolbar__actions > * {
    flex: none;
}

/* Every action (chips, and the page's link when it is a primary button): one height, padding
   and type size, icon + label, never wrapping inside. */
.bl-toolbar .bl-toolbar__btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 14px;
    font-size: 14px;
    line-height: 1.2;
    white-space: nowrap;
}

.bl-toolbar .bl-toolbar__btn > i {
    font-size: 0.875rem;
}

/* Favorites: the tab bar has it on phones. */
.bl-toolbar .bl-toolbar__saved {
    display: none;
}

/* --- Sort: a chip with the native select laid over it --- */
.bl-toolbar__sort {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
}

.bl-toolbar .bl-toolbar__sort-chip {
    position: relative;
}

.bl-toolbar__sort-value {
    display: none;
    color: var(--color-ink);
    font-weight: 600;
}

/* The real control (.bl-select, components/forms.css): covers the whole chip, invisible, so a tap
   anywhere opens the picker. Only background-color is cleared, so the .bl-select chevron is still
   there when the select shows as itself (no JS, below). */
.bl-toolbar .bl-toolbar__select {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: inherit;
    background-color: transparent;
    color: var(--color-ink);
    font: inherit;
    font-size: 1rem; /* no zoom on focus in iOS Safari */
    opacity: 0;
    cursor: pointer;
    appearance: none;
}

.bl-toolbar .bl-toolbar__sort-chip:has(.bl-toolbar__select:focus-visible) {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
    .bl-toolbar .bl-toolbar__sort-chip:hover {
        border-color: var(--color-ink);
    }
}

/* Apply: only without JS (listing-card.js submits on change). */
.bl-toolbar .bl-toolbar__apply {
    display: none;
}

@media (scripting: none) {
    .bl-toolbar .bl-toolbar__apply {
        display: inline-flex;
    }

    /* The select shows as itself, so the choice made is visible before Apply. */
    .bl-toolbar .bl-toolbar__sort-chip > :not(.bl-toolbar__select):not(label) {
        display: none;
    }

    .bl-toolbar .bl-toolbar__sort-chip {
        padding: 0;
        border: 0;
    }

    /* The .bl-select look (border, chevron), chip height. */
    .bl-toolbar .bl-toolbar__select {
        position: static;
        width: auto;
        min-height: 44px;
        padding: 0 var(--space-10) 0 var(--space-4);
        border: 1px solid var(--bl-field-border);
        background-color: var(--color-surface);
        opacity: 1;
    }

    /* "Best match" (value "") is a real choice, not a placeholder: ink, not muted. */
    .bl-toolbar .bl-toolbar__select:not(:disabled):has(> option[value=""]:checked) {
        color: var(--color-ink);
    }
}

.bl-toolbar__chevron {
    font-size: 0.6875rem;
    transition: rotate var(--duration-fast) var(--ease-out);
}

.bl-toolbar .bl-toolbar__btn > .bl-toolbar__chevron {
    font-size: 0.6875rem;
}

@media (min-width: 768px) {
    .bl-toolbar {
        flex-direction: row;
        align-items: flex-end;
        justify-content: space-between;
        gap: var(--space-6);
    }

    .bl-toolbar .bl-toolbar__title {
        font-size: 1.75rem;
    }

    /* Beside the heading: no bleed; the padding keeps room for the focus rings. */
    .bl-toolbar__actions {
        flex: 0 1 auto;
        margin: calc(-1 * var(--space-1));
        padding: var(--space-1);
        scroll-padding-inline: 0;
    }

    .bl-toolbar .bl-toolbar__saved {
        display: inline-flex;
    }

    .bl-toolbar__sort-label::after {
        content: ":";
    }

    .bl-toolbar__sort-label {
        color: var(--color-text-muted);
    }

    .bl-toolbar__sort-value {
        display: inline;
    }
}

/* --- New Year button + menu (the search page while the New Year's skin is on) ---
   A chip in the season's gold (the --ny-* tokens live on .theme-newyear, which is on body
   whenever the button renders) with a twinkling sparkle and one slow sheen; pressed-looking
   (.is-active) while the search is filtered to New Year's stays. The menu is a .bl-popover of
   plain links; without JS it shows in place as a row of chips. */
.theme-newyear .bl-toolbar .bl-toolbar__newyear {
    position: relative;
    overflow: hidden;
    border-color: var(--ny-line);
    color: var(--ny-gold-text);
    font-weight: 600;
    isolation: isolate;
}

.theme-newyear .bl-toolbar .bl-toolbar__newyear .ny-sparkle {
    width: 16px;
    height: 16px;
    animation: bl-ny-twinkle 2.8s var(--ease-in-out) infinite;
}

/* The sheen: a soft light band that crosses the chip now and then (transform only). */
.theme-newyear .bl-toolbar .bl-toolbar__newyear::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(105deg, transparent 30%, var(--ny-tint) 50%, transparent 70%);
    pointer-events: none;
    transform: translateX(-100%);
    animation: bl-ny-sheen 5.6s var(--ease-in-out) infinite;
}

.theme-newyear .bl-toolbar .bl-toolbar__newyear.is-active {
    border-color: var(--ny-gold);
    background-color: var(--ny-tint);
    color: var(--ny-gold-text);
}

@media (hover: hover) and (pointer: fine) {
    .theme-newyear .bl-toolbar .bl-toolbar__newyear:hover {
        border-color: var(--ny-gold);
        color: var(--ny-gold-text);
    }
}

.bl-toolbar__newyear[aria-expanded="true"] .bl-toolbar__chevron {
    rotate: 180deg;
}

.bl-toolbar__menu {
    width: 280px;
}

.bl-toolbar .bl-toolbar__menu-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-2) var(--space-3) var(--space-1);
    color: var(--color-ink);
    font-size: 0.875rem;
    font-weight: 700;
}

.bl-toolbar__menu-title .ny-sparkle {
    width: 14px;
    height: 14px;
}

.bl-toolbar__menu-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.bl-toolbar .bl-toolbar__menu-item {
    justify-content: space-between;
}

.bl-toolbar .bl-toolbar__menu-item[aria-current="true"] {
    color: var(--green-800);
    font-weight: 600;
}

.bl-toolbar__menu-item .fa-check {
    color: var(--color-primary);
    font-size: 0.8125rem;
}

/* ui.js swaps data-popover-nojs for hidden as soon as it runs, so the panel stays closed while
   scripts load. */
.bl-toolbar__menu[data-popover-nojs] {
    display: none;
}

/* Without JS the menu's links sit in the row, as chips (the row scrolls on phones). */
@media (scripting: none) {
    .bl-toolbar .bl-toolbar__newyear {
        display: none;
    }

    .bl-toolbar .bl-toolbar__menu[data-popover-nojs] {
        position: static;
        display: flex;
        flex: none;
        align-items: center;
        gap: var(--space-2);
        width: auto;
        min-width: 0;
        max-width: none;
        padding: 0;
        border: 0;
        background: transparent;
        box-shadow: none;
        overflow: visible;
    }

    .bl-toolbar__menu[data-popover-nojs] .bl-toolbar__menu-list {
        display: flex;
        gap: var(--space-2);
    }

    .bl-toolbar__menu[data-popover-nojs] .bl-toolbar__menu-item {
        width: auto;
        white-space: nowrap;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-pill);
    }

    .bl-toolbar .bl-toolbar__menu[data-popover-nojs] .bl-toolbar__menu-title {
        white-space: nowrap;
    }
}

@keyframes bl-ny-twinkle {
    0%, 70%, 100% { opacity: 1; transform: scale(1); }
    80% { opacity: 0.6; transform: scale(0.8); }
    90% { opacity: 1; transform: scale(1.15); }
}

@keyframes bl-ny-sheen {
    0%, 55% { transform: translateX(-100%); }
    85%, 100% { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
    .theme-newyear .bl-toolbar .bl-toolbar__newyear .ny-sparkle,
    .theme-newyear .bl-toolbar .bl-toolbar__newyear::after {
        animation: none;
    }

    .theme-newyear .bl-toolbar .bl-toolbar__newyear::after {
        opacity: 0;
    }

    .bl-toolbar__chevron {
        transition: none;
    }
}

/* --- Grid: 1 / 2 / 3 / 4 / 5 / 6 columns (≥360 / 1024 / 1280 / 1440 / 1680), so cards stay
   about 260-290px wide as the frame grows to --page-max; fewer beside an open map (2 from 1024,
   3 from 1440). Phones get two cards a row from 360px, close together; the card turns compact
   at that size by itself (a container query in listing-card.css). --- */
.bl-results {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-8) var(--space-5);
}

.bl-results__item {
    min-width: 0;
}

@media (min-width: 360px) {
    .bl-results {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-6) var(--space-3);
    }
}

@media (min-width: 576px) {
    .bl-results {
        gap: var(--space-8) var(--space-5);
    }
}

@media (min-width: 1024px) {
    .bl-results {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .is-map-open .bl-results {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1280px) {
    .bl-results {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* Wide desktop: five cards a row, six from 1680px (the square photo and the type stay as they
   are). Beside an open map the list keeps three. */
@media (min-width: 1440px) {
    .bl-results {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        column-gap: var(--space-5);
    }

    .is-map-open .bl-results {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* (.is-map-open .bl-results above is more specific, so the map view stays at three.) */
@media (min-width: 1680px) {
    .bl-results {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

/* --- Empty state --- */
.bl-results__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    max-width: 420px;
    margin: var(--space-8) auto;
    padding: var(--space-10) var(--space-4);
    text-align: center;
}

.bl-results__empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-bottom: var(--space-2);
    border-radius: 50%;
    background-color: var(--green-50);
    color: var(--green-700);
    font-size: 1.25rem;
}

.bl-results__empty-title {
    margin: 0;
    color: var(--color-ink);
    font-size: 1.125rem;
    font-weight: 600;
}

.bl-results__empty-body {
    margin: 0 0 var(--space-3);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* --- Show more --- */
.bl-results__pager {
    display: flex;
    justify-content: center;
    margin: var(--space-10) 0 var(--space-4);
}

.bl-results__pager .bl-results__more {
    min-width: 200px;
    min-height: 44px;
    justify-content: center;
}

.bl-results__more[aria-busy="true"] {
    opacity: 0.6;
    pointer-events: none;
}

/* --- Compare picks (ResultsPageModel.Selectable: Favorites) ---
   A "Compare" checkbox under each card, shown only in compare mode (.is-comparing on an
   ancestor). The input stays in the tab order; the pill label is what shows. */
.bl-results__pick {
    position: relative;
    display: none;
    margin-top: var(--space-2);
}

.is-comparing .bl-results__pick {
    display: block;
}

.bl-results__pick .bl-results__pick-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
}

.bl-results__pick-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    margin: 0;
    padding: 0 var(--space-4) 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    background-color: var(--color-surface);
    color: var(--color-ink);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition:
        background-color var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out);
}

.bl-results__pick-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    background-color: var(--color-surface);
    color: transparent;
    font-size: 0.6875rem;
}

.bl-results__pick-input:checked + .bl-results__pick-label {
    border-color: var(--color-primary);
    background-color: var(--green-50);
    color: var(--green-800);
}

.bl-results__pick-input:checked + .bl-results__pick-label .bl-results__pick-box {
    border-color: var(--color-primary);
    background-color: var(--color-primary);
    color: var(--color-surface);
}

.bl-results__pick-input:focus-visible + .bl-results__pick-label {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.bl-results__pick-input:disabled + .bl-results__pick-label {
    cursor: not-allowed;
    opacity: 0.5;
}

@media (hover: hover) and (pointer: fine) {
    .bl-results__pick-input:not(:disabled) + .bl-results__pick-label:hover {
        border-color: var(--color-ink);
    }
}

@media (prefers-reduced-motion: reduce) {
    .bl-results__pick-label {
        transition: none;
    }
}
