.medialem-product-search {
    position: relative;
}

.medialem-product-search *,
.medialem-product-search *::before,
.medialem-product-search *::after {
    box-sizing: border-box;
}

/* Filter bar */
.medialem-product-search__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.medialem-product-search__filter {
    position: relative;
}

/* Filter buttons (the <summary>) */
.medialem-product-search__btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: 1px solid #d0d5dd;
    border-radius: 999px;
    background: #fff;
    color: #1d2939;
    font-size: 0.95rem;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease;
}

.medialem-product-search__btn::-webkit-details-marker {
    display: none;
}

.medialem-product-search__btn:hover {
    border-color: #98a2b3;
}

.medialem-product-search__filter.is-active > .medialem-product-search__btn {
    border-color: currentColor;
    font-weight: 600;
}

.medialem-product-search__btn-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.375rem;
    border-radius: 999px;
    background: #2b66a6;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}

.medialem-product-search__btn-caret {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform 0.15s ease;
}

.medialem-product-search__filter[open]
    > .medialem-product-search__btn
    .medialem-product-search__btn-caret {
    transform: rotate(180deg);
}

/* Popover */
.medialem-product-search__popover {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    z-index: 40;
    min-width: 260px;
    max-width: 92vw;
    background: #fff;
    color: #1d2939;
    border: 1px solid #eaecf0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
}

.medialem-product-search__popover--right {
    left: auto;
    right: 0;
}

.medialem-product-search__popover-inner {
    padding: 1rem;
    max-height: 60vh;
    overflow-y: auto;
}

.medialem-product-search__popover-actions {
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem 1rem;
    border-top: 1px solid #eaecf0;
}

.medialem-product-search__apply {
    padding: 0.4rem 1rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #2b66a6;
    font-weight: 600;
    cursor: pointer;
}

/* Options (radios) */
.medialem-product-search__options {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.medialem-product-search__option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.25rem;
    cursor: pointer;
    border-radius: 6px;
}

.medialem-product-search__option:hover {
    background: rgba(16, 24, 40, 0.04);
}

/* Search field */
.medialem-product-search__search {
    flex: 1 1 220px;
    min-width: 0;
}

.medialem-product-search__search-input {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid #d0d5dd;
    border-radius: 999px;
    background: #fff;
    color: #1d2939;
    font-size: 0.95rem;
    line-height: 1.2;
}

/* Price */
.medialem-product-search__price {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.medialem-product-search__price-input {
    width: 100%;
    min-width: 0;
    padding: 0.5rem 0.625rem;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 0.95rem;
    color: inherit;
}

.medialem-product-search__price-sep {
    flex: 0 0 auto;
    opacity: 0.6;
}

/* Category tree */
.medialem-product-search__tree,
.medialem-product-search__children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.medialem-product-search__children {
    padding-left: 1.5rem;
}

.medialem-product-search__node-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.15rem 0;
}

.medialem-product-search__category {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    line-height: 1.3;
}

.medialem-product-search__category input[type="checkbox"] {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin: 0;
    cursor: pointer;
}

.medialem-product-search__tree-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    color: inherit;
}

.medialem-product-search__tree-toggle-icon {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid currentColor;
    transition: transform 0.15s ease;
}

.medialem-product-search__node--collapsed
    > .medialem-product-search__node-row
    .medialem-product-search__tree-toggle-icon {
    transform: rotate(-90deg);
}

/* Submit button */
.medialem-product-search__submit {
    padding: 0.7rem 1.5rem;
    border: 1px solid transparent;
    border-radius: 999px;
    background: #2b66a6;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition:
        transform 0.15s ease,
        opacity 0.15s ease,
        background-color 0.15s ease;
}

.medialem-product-search__submit:hover {
    transform: translateY(-1px);
    opacity: 0.95;
}

.medialem-product-search__notice {
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    color: #b42318;
}

/*
 * The Hello Elementor reset (reset.css) paints every <button> magenta (#c36)
 * with white text on :hover/:focus. Re-assert our buttons' own colours inside
 * the widget. These class selectors out-rank the theme's element selectors, and
 * Elementor's element-scoped Style controls still out-rank these, so the colour
 * controls keep working.
 */
.medialem-product-search__submit:hover,
.medialem-product-search__submit:focus {
    background-color: #2b66a6;
    color: #fff;
}

.medialem-product-search__apply:hover,
.medialem-product-search__apply:focus {
    background-color: transparent;
    color: #2b66a6;
}

.medialem-product-search__tree-toggle:hover,
.medialem-product-search__tree-toggle:focus {
    background-color: transparent;
    color: inherit;
}

.medialem-product-search__backdrop {
    display: none;
}

.medialem-product-search .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Mobile: bottom-sheet popovers + backdrop */
@media (max-width: 767px) {
    .medialem-product-search__bar {
        gap: 0.5rem;
    }

    .medialem-product-search__filter,
    .medialem-product-search__submit {
        flex: 1 1 auto;
    }

    .medialem-product-search__search {
        flex: 1 1 100%;
    }

    .medialem-product-search__btn {
        width: 100%;
        justify-content: space-between;
    }

    .medialem-product-search__popover {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        max-width: none;
        max-height: 80vh;
        overflow-y: auto;
        border-radius: 16px 16px 0 0;
        z-index: 1001;
    }

    .medialem-product-search__popover-inner {
        max-height: none;
    }

    .medialem-product-search.is-popover-open .medialem-product-search__backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(16, 24, 40, 0.45);
        z-index: 1000;
    }
}
