/* Segment filter dropdown — includes/stores-segment-filter.php, used in stores_overview and stores_filtered */

.segment-filter {
    position: relative;
    width: 100%;
}

/* Toggle: matches the search inputs in the filter box */
.segment-filter-toggle {
    display: flex;
    align-items: center;
    gap: max(.25rem, calc(.25 * var(--su)));
    width: 100%;
    /* same inline padding as the search inputs, so text and arrow line up with their text and icon */
    padding: max(.75rem, calc(.75 * var(--su))) max(1.25rem, calc(1.25 * var(--su)));
    border: 1px solid var(--cbw-deep-pine-20);
    border-radius: .5rem;
    background-color: transparent;
    font-family: var(--pk-text-font-family);
    font-size: var(--scaling-body-xs-normal);
    font-weight: 500;
    /* "normal", like the text inputs, so the toggle is exactly as tall as them */
    line-height: normal;
    color: var(--cbw-deep-pine-100);
    text-align: left;
    cursor: pointer;
    transition: .2s ease-in-out border-color, .2s ease-in-out background-color;
}

.segment-filter-toggle:hover,
.segment-filter.is-open .segment-filter-toggle {
    border-color: var(--cbw-deep-pine-100);
}

.segment-filter-toggle:focus-visible {
    outline: 2px solid var(--cbw-deep-pine-100);
    outline-offset: 2px;
}

.segment-filter.has-selection .segment-filter-toggle {
    background-color: var(--cbw-emerald-10);
    border-color: var(--cbw-emerald-100);
}

.segment-filter-count {
    color: var(--cbw-teal);
}

.segment-filter-chevron {
    /* same box as the inputs' search icon (background-size .875), the arrow is centred in it */
    position: relative;
    flex-shrink: 0;
    margin-left: auto;
    width: max(.875rem, calc(.875 * var(--su)));
    aspect-ratio: 1;
}

.segment-filter-chevron::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 57%;
    aspect-ratio: 1;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translate(-50%, -75%) rotate(45deg);
    transition: transform .2s ease-in-out;
}

.segment-filter.is-open .segment-filter-chevron::before {
    transform: translate(-50%, -25%) rotate(-135deg);
}

/* Panel */
.segment-filter-panel {
    position: absolute;
    top: calc(100% + max(.5rem, calc(.5 * var(--su))));
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: max(.75rem, calc(.75 * var(--su)));
    padding: max(.75rem, calc(.75 * var(--su)));
    background-color: var(--cbw-white-100);
    border: 1px solid var(--cbw-deep-pine-10);
    border-radius: .5rem;
    box-shadow: 0 max(.5rem, calc(.5 * var(--su))) max(1.5rem, calc(1.5 * var(--su))) var(--cbw-black-5);
}

.segment-filter-panel[hidden] {
    display: none;
}

/* Open: drop in from the toggle. Close: segment-filter.js adds .is-closing and hides after the animation */
.segment-filter-panel {
    transform-origin: top center;
    animation: segment-filter-in .22s cubic-bezier(.2, .8, .2, 1) both;
}

.segment-filter-panel.is-closing {
    animation: segment-filter-out .15s ease-in both;
    pointer-events: none;
}

/* rows follow the panel with a small stagger */
.segment-filter-panel:not(.is-closing) .segment-filter-option {
    animation: segment-filter-row-in .25s ease-out both;
    animation-delay: calc(min(var(--i, 0), 8) * 20ms + 60ms);
}

@keyframes segment-filter-in {
    from { opacity: 0; transform: translateY(-.5rem) scaleY(.96); }
    to   { opacity: 1; transform: none; }
}

@keyframes segment-filter-out {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: translateY(-.375rem) scaleY(.98); }
}

@keyframes segment-filter-row-in {
    from { opacity: 0; transform: translateY(-.25rem); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .segment-filter-panel,
    .segment-filter-panel.is-closing,
    .segment-filter-panel .segment-filter-option {
        animation: none;
    }
}

.segment-filter-list {
    display: flex;
    flex-direction: column;
    gap: max(.5rem, calc(.5 * var(--su)));
    max-height: min(45vh, max(18rem, calc(20 * var(--su))));
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Row */
.segment-filter-option {
    position: relative;
    display: flex;
    width: 100%;
    box-sizing: border-box;
    align-items: center;
    gap: max(.75rem, calc(.75 * var(--su)));
    /* fixed row height: long names are cut off with an ellipsis (full name in the title attribute) */
    height: max(3rem, calc(3 * var(--su)));
    flex-shrink: 0;
    padding: 0 max(.75rem, calc(1 * var(--su))) 0 max(1rem, calc(1.25 * var(--su)));
    background-color: var(--cbw-deep-pine-2-5);
    border: 1px solid var(--cbw-deep-pine-10);
    border-radius: .25rem;
    cursor: pointer;
    transition: .2s ease-in-out background-color, .2s ease-in-out border-color;
}

.segment-filter-option:hover {
    border-color: var(--cbw-deep-pine-20);
}

.segment-filter-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--scaling-body-xs-normal);
    color: var(--cbw-deep-pine-60);
    transition: .2s ease-in-out color;
}

.segment-filter-option:has(input:checked) {
    background-color: var(--cbw-emerald-5);
    border-color: var(--cbw-emerald-40);
}

.segment-filter-option:has(input:checked) .segment-filter-name {
    color: var(--cbw-deep-pine-100);
}

/* Native checkbox stays focusable, the span draws it */
.segment-filter-option input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.segment-filter-checkbox {
    position: relative;
    flex-shrink: 0;
    width: max(1.25rem, calc(1.25 * var(--su)));
    aspect-ratio: 1;
    background-color: var(--cbw-white-100);
    border: 1px solid var(--cbw-deep-pine-10);
    border-radius: .25rem;
    transition: .2s ease-in-out background-color, .2s ease-in-out border-color;
}

.segment-filter-checkbox::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 45%;
    width: 30%;
    height: 55%;
    border-right: 1.5px solid var(--cbw-deep-pine-100);
    border-bottom: 1.5px solid var(--cbw-deep-pine-100);
    transform: translate(-50%, -50%) rotate(45deg);
    opacity: 0;
    transition: opacity .18s ease;
}

.segment-filter-option input:checked + .segment-filter-checkbox {
    background-color: var(--cbw-emerald-100);
    border-color: var(--cbw-emerald-100);
}

.segment-filter-option input:checked + .segment-filter-checkbox::after {
    opacity: 1;
}

.segment-filter-option input:focus-visible + .segment-filter-checkbox {
    outline: 2px solid var(--cbw-deep-pine-100);
    outline-offset: 2px;
}
