/**
 * KOT-343 — Filter & sort toolbar (search results + category pages).
 *
 * Loaded AFTER public/css/styles.css so these rules can override the legacy
 * inline button styles without touching the 13k-line stylesheet.
 * Logical properties only (inset-inline-*), so RTL and LTR behave the same.
 */

.listing-toolbar {
    position: relative;
    display: inline-flex;
    max-width: 100%;
    margin-bottom: 20px;
}

/* Inside the page header the toolbar must not disturb the baseline. */
.category-header-actions .listing-toolbar {
    margin-bottom: 0;
}

.listing-toolbar-form {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    max-width: 100%;
}

.listing-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    max-width: 100%;
}

.listing-toolbar .top-filter-btn,
.listing-toolbar .top-sort-btn {
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: #F5EEDC;
    color: #38244C;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    transition: background .2s, color .2s, box-shadow .2s;
}

.listing-toolbar .top-filter-btn:hover,
.listing-toolbar .top-sort-btn:hover,
.listing-toolbar .top-filter-btn[aria-expanded="true"],
.listing-toolbar .top-sort-btn[aria-expanded="true"] {
    background: #FFF0F0;
    color: #E8565A;
}

.listing-toolbar .top-filter-btn:focus-visible,
.listing-toolbar .top-sort-btn:focus-visible,
.listing-popover-close:focus-visible,
.listing-option input:focus-visible,
.listing-select:focus-visible {
    outline: 2px solid #FF7073;
    outline-offset: 2px;
}

.listing-toolbar .listing-filter-btn.has-active-filters {
    box-shadow: inset 0 0 0 2px #FF7073;
}

.listing-filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #FF7073;
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}

.listing-sort-label {
    display: inline-block;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Popovers ───────────────────────────────────────────────────────────── */
.listing-popover {
    position: absolute;
    top: calc(100% + 10px);
    inset-inline-end: 0;
    z-index: 60;
    width: 360px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
    box-sizing: border-box;
    padding: 18px;
    background: #FFFFFF;
    border: 1px solid #EFE7D6;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(56, 36, 76, .18);
    text-align: start;
}

.listing-popover[hidden] {
    display: none !important;
}

.listing-popover-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.listing-popover-title {
    margin: 0;
    color: #38244C;
    font-family: 'Changa', sans-serif;
    font-size: 16px;
    font-weight: 800;
}

.listing-popover-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #F5EEDC;
    color: #38244C;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
}

.listing-popover-close:hover {
    background: #FFE1E2;
    color: #E8565A;
}

.listing-group {
    min-width: 0;
    margin: 0 0 14px;
    padding: 0;
    border: 0;
}

.listing-group:last-of-type {
    margin-bottom: 8px;
}

.listing-group-label {
    display: block;
    margin: 0 0 8px;
    color: #6A778B;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .2px;
    text-transform: uppercase;
}

.listing-options {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.listing-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    color: #38244C;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    cursor: pointer;
}

.listing-option:hover {
    background: #FFF4F4;
}

.listing-option.is-selected {
    background: #FFF0F0;
    color: #E8565A;
    font-weight: 800;
}

.listing-option input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: #FF7073;
    flex: 0 0 auto;
}

.listing-select {
    width: 100%;
    min-height: 42px;
    box-sizing: border-box;
    padding: 0 12px;
    border: 1px solid #E8DFC9;
    border-radius: 10px;
    background: #FFFDF8;
    color: #38244C;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.listing-reset {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    margin-top: 6px;
    padding: 0 16px;
    border-radius: 8px;
    background: #F5EEDC;
    color: #38244C;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.listing-reset:hover {
    background: #FFE1E2;
    color: #E8565A;
}

.listing-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(56, 36, 76, .32);
}

.listing-backdrop[hidden] {
    display: none !important;
}

/* While the AJAX swap is in flight, dim the stale results. */
html.listing-updating [data-listing-region] {
    opacity: .55;
    pointer-events: none;
    transition: opacity .15s ease;
}

/* ── Phones: buttons share the row, panels become a bottom sheet ────────── */
@media (max-width: 767px) {
    .listing-toolbar {
        display: block;
        width: 100%;
        margin-bottom: 16px;
    }

    .listing-toolbar-form,
    .listing-toolbar-actions {
        width: 100%;
    }

    .listing-toolbar .top-filter-btn,
    .listing-toolbar .top-sort-btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 10px 12px;
        font-size: 13px;
    }

    .listing-sort-label {
        max-width: 100%;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        line-height: 1.25;
    }

    .listing-popover {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        max-width: 100%;
        max-height: min(78vh, 640px);
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        border-radius: 18px 18px 0 0;
        border-bottom: none;
        padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
        z-index: 1000;
    }

    .listing-backdrop {
        z-index: 999;
    }

    .listing-popover-head {
        position: sticky;
        top: -20px;
        z-index: 1;
        margin: -20px -18px 14px;
        padding: 16px 18px 12px;
        background: #FFFFFF;
        border-bottom: 1px solid #F2EAD9;
        border-radius: 18px 18px 0 0;
    }
}