/*
 * dropdown-picker itself is the positioning context for the
 * option list, and shows a focus ring since it's the thing that
 * actually receives keyboard focus (see tabIndex in build()).
 */
dropdown-picker {
    position: relative;
    display: inline-block;
    width: 100%;
    outline: none;
}

dropdown-picker:focus-visible {
    outline: 2px solid;
    outline-offset: 2px;
}

/*
 * The header is the visible, always-present trigger. It needs a
 * pointer cursor since clicking it is what opens/closes the list.
 * The caret (::after) is a plain CSS triangle, not an image, so
 * there's nothing to load and no extra markup for it.
 */
dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5em;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.5em 0.8em;
    background: white;
}

dropdown-header::after {
    content: "";
    flex-shrink: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid currentColor;
    transition: transform 0.15s ease;
}

/*
 * Flip the caret to point up while open, so the header itself
 * reflects state without any extra JS beyond the "open" attribute
 * DropdownPicker.js already reflects.
 */
dropdown-picker[open] dropdown-header::after {
    transform: rotate(180deg);
}

/*
 * The wrapper DropdownPicker.js creates around all choice-option
 * children. Hidden by default...
 */
dropdown-picker [data-option-list] {
    display: none;
}

/*
 * ...and shown, positioned as a single block under the header,
 * only when the picker has been opened. This is the one rule
 * doing the real work: it reads the "open" attribute
 * DropdownPicker.js reflects onto itself in
 * openDropdown()/close().
 *
 * isolation: isolate creates a new stacking context scoped to
 * just this wrapper, so a large z-index here only has to beat
 * other content *within this new context* - it can't be
 * out-stacked by some unrelated part of the page that happens to
 * use a big z-index of its own, and we don't have to guess a
 * number that beats every current and future overlay on the site.
 */
dropdown-picker[open] [data-option-list] {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: 0.25em;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    isolation: isolate;
    z-index: 1;
    /* max-height: 9rem; */
    overflow-y: auto;
    overflow-x: hidden;
}

dropdown-picker [data-option-list] choice-option {
    display: block;
    padding: 0.5em 0.8em;
    cursor: pointer;
}

dropdown-picker [data-option-list] choice-option:not([disabled]):hover {
    background: #f0f0f0;
}

dropdown-picker choice-option[selected] {
    font-weight: bold;
}

dropdown-picker choice-option[disabled] {
    cursor: not-allowed;
    opacity: 0.5;
}

.overlay-content.dropdown-open {
    overflow-y: visible;
}