/* The catalog's single GET form belongs to the sticky header. Keep the modal
   outside that stacking context and let the header observer measure all rows. */
.site-header.site-header-with-categories { flex-wrap: wrap; }
.site-header .header-category-filter { padding-top: .5rem; }
.site-header .category-filter-bar {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}
.site-header .category-filter-fields { width: 100%; }
.site-header .category-filter-bar .filter-label { margin-bottom: .25rem; }
.site-header .category-picker-toggle { min-height: 44px; }
.site-header .category-filter-clear { width: 44px; height: 44px; }

/* Category labels and counts share one row. Matching child names occupy their
   own row so narrow screens never squeeze three independent text columns. */
.category-filter-bar .category-picker-menu {
    min-width: min(26rem, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    padding: .5rem;
    background: #fff;
    border: 1px solid #e2dbea;
    border-radius: .9rem;
    box-shadow: 0 .75rem 2rem rgba(47, 31, 72, .14);
}
.category-filter-bar .category-picker-search-wrap { margin: .125rem .125rem .5rem; }
.category-filter-bar .category-picker-search {
    min-height: 44px;
    font-size: 1rem;
    border-radius: .65rem;
    background: #faf9fc;
}
.category-filter-bar .category-picker-search:focus {
    background: #fff;
    border-color: #8b72b0;
    outline: none;
    box-shadow: 0 0 0 2px rgba(83, 55, 119, .13);
}
.category-filter-bar .category-picker-options {
    max-height: min(22rem, 50vh);
    max-height: min(22rem, 50dvh);
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
}
/* The visual viewport can shrink independently of layout when a phone keyboard
   opens. The controller supplies its bottom edge; reserve space for the search
   field, menu padding and a small gap beneath the independently scrolling list. */
.site-header .category-filter-bar .category-picker-options {
    max-height: min(22rem, max(44px, calc(var(--category-viewport-bottom, 100vh) - var(--site-header-height, 12rem) - 5rem)));
    max-height: min(22rem, max(44px, calc(var(--category-viewport-bottom, 100dvh) - var(--site-header-height, 12rem) - 5rem)));
}
.category-filter-bar .category-picker-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    column-gap: .75rem;
    row-gap: .2rem;
    min-height: 44px;
    padding: .65rem .7rem;
    border-radius: .6rem;
    text-align: left;
    font-size: .9375rem;
    line-height: 1.4;
}
/* Explicitly preserve filtering when the grid rule overrides native display. */
.category-filter-bar .category-picker-option[hidden] { display: none; }
.category-filter-bar .category-picker-option > span:first-child {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    font-weight: 600;
    overflow-wrap: anywhere;
}
.category-filter-bar .category-picker-option > small {
    grid-column: 2;
    grid-row: 1;
    margin-top: .1rem;
    padding: .15rem .45rem;
    border-radius: .4rem;
    background: #f1edf6;
    color: #6b567f;
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
    white-space: nowrap;
}
.category-filter-bar .category-picker-option > [data-matching-subcategories] {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    color: #746c80;
    font-size: .8rem;
    font-style: normal;
    font-weight: 400;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.category-filter-bar .category-picker-option:hover,
.category-filter-bar .category-picker-option:focus-visible {
    background: #f5f1fa;
    color: #503777;
}
.category-filter-bar .category-picker-option:focus-visible {
    outline: 2px solid #8b72b0;
    outline-offset: -2px;
}
.category-filter-bar .category-picker-option.active,
.category-filter-bar .category-picker-option:active { background: #503b77; color: #fff; }
.category-filter-bar .category-picker-option.active > small,
.category-filter-bar .category-picker-option:active > small { background: rgba(255,255,255,.15); color: #fff; }
.category-filter-bar .category-picker-option.active > [data-matching-subcategories],
.category-filter-bar .category-picker-option:active > [data-matching-subcategories] { color: rgba(255,255,255,.85); }

@media (max-width: 991.98px) {
    /* Anchor both menus to the entire filter row from their first visible frame.
       Popper positions asynchronously; a wide menu starting at the right-hand
       toggle can otherwise enlarge Android's layout viewport before it settles.
       Override compact-screen placement, retaining Bootstrap dismissal/keyboard
       behavior and the desktop Popper placement. Do not hide page overflow. */
    .category-filter-bar .category-filter-fields { position: relative; }
    .category-filter-bar .category-picker { position: static; }
    .category-filter-bar .category-picker-menu {
        position: absolute !important;
        top: calc(100% + .35rem) !important;
        bottom: auto !important;
        left: 0 !important;
        right: auto !important;
        transform: none !important;
        margin: 0 !important;
        width: min(100%, 26rem);
        min-width: 0;
        max-width: 100%;
    }
    .category-filter-bar .category-picker-menu[aria-labelledby="subcategory-toggle"] {
        left: auto !important;
        right: 0 !important;
    }
}
