/*
 * Filter options while a selection is loading.
 * Styles apply to an option's own content, never to its nested list, so a parent brand
 * and its children each keep their own state (opacity would otherwise multiply).
 */
[data-bmw-tax] > li[data-bmw-term] > :not(ul) {
    transition:
        opacity 0.32s cubic-bezier(0.2, 0.8, 0.2, 1),
        filter 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

[data-bmw-tax] > li[data-bmw-term] {
    transition: opacity 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/*
 * While loading every option looks the same, whatever it was before: values rendered without
 * products (bmw-filter-zero-count, opacity 0.5 on the item) take the common pending look and
 * then the state the index or the next page gives them.
 */
.bmw-filters-loading [data-bmw-tax] > li.bmw-filter-zero-count,
#sidebar-shop.bmw-filters-loading [data-bmw-tax] > li.bmw-filter-zero-count {
    opacity: 1;
}

/*
 * Pending: options wait for their new state with a soft pulse. The pulse animates filter,
 * not a mask: a mask clips painting to the element's box, and theme checkboxes drawn by
 * ::before reach a pixel beyond the link box, so their edge was cut off.
 */
.bmw-filters-loading [data-bmw-tax] > li[data-bmw-term] > :not(ul) {
    opacity: 0.5;
    filter: saturate(0.35);
    animation: bmw-filters-pulse 1.4s cubic-bezier(0.4, 0, 0.6, 1) 0.3s infinite;
}

/* Known to be available (from the index) and the selected values: back to normal at once. */
.bmw-filters-loading [data-bmw-tax] > li.bmw-filter-live > :not(ul),
.bmw-filters-loading [data-bmw-tax] > li.chosen > :not(ul) {
    opacity: 1;
    filter: none;
    animation: none;
}

/* Still waiting for its new state: not clickable until the page or the index answers. */
.bmw-filters-loading [data-bmw-tax] > li[data-bmw-term]:not(.bmw-filter-live):not(.chosen):not(.bmw-filter-predicted-off) {
    cursor: progress;
}

.bmw-filters-loading [data-bmw-tax] > li[data-bmw-term]:not(.bmw-filter-live):not(.chosen) > a {
    pointer-events: none;
}

/* Known to have no products for the pending selection: settled and not clickable. */
.bmw-filters-loading [data-bmw-tax] > li.bmw-filter-predicted-off > :not(ul) {
    opacity: 0.4;
    filter: grayscale(1);
    animation: none;
}

.bmw-filters-loading [data-bmw-tax] > li.bmw-filter-predicted-off {
    cursor: not-allowed;
}

.bmw-filters-loading [data-bmw-tax] > li.bmw-filter-predicted-off > a {
    pointer-events: none;
}

@keyframes bmw-filters-pulse {
    50% {
        filter: saturate(0.35) opacity(0.55);
    }
}

@media (prefers-reduced-motion: reduce) {
    [data-bmw-tax] > li[data-bmw-term] > :not(ul) {
        transition: none;
    }

    .bmw-filters-loading [data-bmw-tax] > li[data-bmw-term] > :not(ul) {
        animation: none;
    }
}
