/*
 * Choices.js (foundation26/Resources/Public/JavaScript/choices/) in the house style: selects in Powermail forms and
 * on the branddam26 asset page. Loaded only where such a select renders (f:asset, identifier f26Choices), not on
 * every page. Moved here from powermailenhancer26 (choices-bootstrap.css) in foundation26 1.18.407.
 *
 * Look after the Select of shadcn/ui and Radix (1.18.510): the field is a .form-control (same height, border, radius,
 * focus ring), the open list a popover (page background, hairline, shadow, inner padding), options with a rounded
 * highlight on --bs-surface-100 and a check on the chosen one, chosen values of a multiple select as quiet chips.
 * Tokens only (--bs-*), so the dark mode flips with the page. Colours never rely on a site setting without fallback.
 */
/**
 * Choices.js Bootstrap Integration
 * Custom styles to match Bootstrap design system
 */

/* ====================================================================
   Base Container Styles
   ==================================================================== */
/* Debug: Always show dropdown  
.choices__list--dropdown,.choices__list[aria-expanded]{display:block!important;visibility:visible!important;opacity:1!important;position:static!important;z-index:9999!important}.choices.is-open{overflow:visible!important}.choices__list--dropdown .choices__list,.choices__list[aria-expanded] .choices__list{display:block!important;max-height:none!important}
*/
.choices {
    position: relative;
    margin-bottom: 0;
    font-size: 1rem;
    background-color: var(--bs-body-bg);
    border-radius: var(--bs-border-radius);
}

.choices:focus {
    outline: none;
}

.choices:last-child {
    margin-bottom: 0;
}

.choices.is-disabled .choices__inner,
.choices.is-disabled .choices__input {
    cursor: not-allowed;
    user-select: none;
}

.choices.is-disabled .choices__item {
    cursor: not-allowed;
}

/* ====================================================================
   Inner Container (Main Input Area)
   ==================================================================== */

/* The field: a .form-control – same height (also empty: a multiple select without choice stays a field), border,
   radius and focus ring */
.choices__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    width: 100%;
    min-height: calc(1.5em + 0.75rem + var(--bs-border-width, 1px) * 2);
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    padding: 0.375rem 2.25rem 0.375rem 0.75rem;
    border: var(--bs-border-width, 1px) var(--bs-border-style, solid) hsl(from var(--bs-border-color) h s l / var(--bs-border-opacity));
    border-radius: var(--bs-form-border-radius, var(--bs-border-radius));
    font-size: 1rem;
    font-weight: var(--bs-font-weight-light);
    line-height: 1.5;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.choices[data-type*='select-multiple'] .choices__inner {
    padding: 0.25rem 0.75rem;
}

.is-focused .choices__inner,
.is-open .choices__inner {
    border-color: var(--settings-form-focus-color, var(--bs-focus-color));
    box-shadow: 0 0 0 0.25rem color-mix(in srgb, var(--settings-form-focus-color, var(--bs-focus-color)), transparent 75%);
}

.is-open .choices__inner {
}

.is-flipped.is-open .choices__inner {
    border-radius: inherit;
}

/* ====================================================================
   List Styles
   ==================================================================== */

.choices__list {
    margin: 0;
    padding-left: 0;
    list-style: none;
}

/* Single Select List */
.choices__list--single {
    display: inline-block;
    padding: 0;
    width: 100%;
}

.choices__list--single .choices__item {
    width: 100%;
}

/* Multiple Select List */
.choices__list--multiple {
    display: contents;
}

/* Chosen values of a multiple select: quiet chips (shadcn Badge «secondary») */
.choices__list--multiple .choices__item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: var(--settings-badge-radius, 20rem); /* Badge & Checkbox Radius (1.18.485) */
    font-size: 0.875rem;
    font-weight: var(--bs-font-weight-medium, 500);
    line-height: 1.5;
    color: var(--bs-body-color);
    padding: 0 0.375rem 0 0.625rem;
    margin: 0;
    background-color: var(--bs-surface-100);
    border: var(--bs-border-width, 1px) solid transparent;
    word-break: break-word;
    box-sizing: border-box;
}

.choices__list--multiple .choices__item.is-highlighted {
    background-color: var(--bs-surface-200);
}

.choices[data-type*="select-multiple"] .choices__button, .choices[data-type*="text"] .choices__button {
    border-left: none;
    padding: 0;
    margin: 0;
}


/* Dropdown List */
.choices__list--dropdown,
.choices__list[aria-expanded] {
    visibility: hidden;
    z-index: 100 !important;
    position: absolute;
    width: 100%;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-width: var(--bs-border-width, 1px);
    border-style: var(--bs-border-style, solid);
    border-color: hsl(from var(--bs-border-color) h s l / var(--bs-border-opacity-muted, var(--bs-border-opacity)));
    top: 100%;
    margin-top: 0.25rem;
    padding: 0.25rem;
    border-radius: var(--settings-dropdown-border-radius, var(--settings-form-border-radius, var(--bs-border-radius-default)));
    word-break: break-word;
    will-change: visibility;
    box-shadow: var(--bs-box-shadow);
}

.choices__list--dropdown.is-active,
.choices__list[aria-expanded].is-active {
    visibility: visible;
}

/* The search box of a single select lies over the field: hide the value under it – only when there is a search */
.choices[data-type*='select-one']:has(.choices__list--dropdown.is-active .choices__input) .choices__inner .choices__list {
    color: transparent;
}

.is-flipped .choices__list--dropdown,
.is-flipped .choices__list[aria-expanded] {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 0.25rem;
}

.choices__list--dropdown .choices__list,
.choices__list[aria-expanded] .choices__list {
    position: relative;
    max-height: 18rem;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
}

/* Options: rounded rows, the highlight (hover, keys) a quiet surface with the normal text colour */
.choices__list--dropdown .choices__item,
.choices__list[aria-expanded] .choices__item {
    position: relative;
    padding: 0.375rem 2rem 0.375rem 0.5rem;
    font-size: 1rem;
    border-radius: var(--bs-border-radius-4);
}

.choices__list--dropdown .choices__item--selectable.is-highlighted,
.choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
    background-color: var(--bs-surface-100);
    color: var(--bs-body-color);
}

/* The chosen option carries a check (currentColor, so it follows the text in both modes) */
.choices__list--dropdown .choices__item--choice.is-selected::before,
.choices__list[aria-expanded] .choices__item--choice.is-selected::before {
    content: '';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    width: 1rem;
    height: 1rem;
    transform: translateY(-50%);
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* An open list must lie above what follows: a section (.section-content, z-index 1) is a stacking context of its own,
   and the next one – the footer too – would paint over the list. The section with the open field rises, below the
   floating header (1030). */
.section-content:has(.choices.is-open),
.frame-section:has(.choices.is-open) {
    z-index: 1020;
}

/* The placeholder («Please choose») stands in the field only, not as an option (as Radix Select); a choice is cleared
   with the × of the field */
.choices__list--dropdown .choices__item--choice.choices__placeholder,
.choices__list[aria-expanded] .choices__item--choice.choices__placeholder {
    display: none;
}

.choices__list--dropdown .choices__item.has-no-results,
.choices__list--dropdown .choices__item.has-no-choices {
    color: var(--bs-text-muted);
}

/* ====================================================================
   Items
   ==================================================================== */

.choices__item {
    cursor: default;
}

.choices__item--selectable {
    cursor: pointer;
}

.choices__item--disabled {
    cursor: not-allowed;
    user-select: none;
    opacity: 0.5;
}

/* Remove Button */
.choices__button {
    text-indent: -9999px;
    appearance: none;
    border: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    padding: 0;
    margin: 0 0 0 0.5rem;
    width: 0.875rem;
    height: 0.875rem;
    opacity: 0.75;
}

.choices__button:hover,
.choices__button:focus {
    opacity: 1;
}

.choices__button:focus {
    outline: none;
}

/* The × of a chip in the text colour (mask + currentColor, not a white image) */
.choices__list--multiple .choices__button {
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='m6 6 12 12'/%3E%3C/svg%3E") center / 0.75rem no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='m6 6 12 12'/%3E%3C/svg%3E") center / 0.75rem no-repeat;
    opacity: 0.6;
}

/* ====================================================================
   Input Field
   ==================================================================== */

.choices__input {
    display: inline-block;
    vertical-align: baseline;
    background-color: transparent;
    color: inherit;
    font: inherit;
    font-size: 1rem;
    margin-bottom: 0;
    border: 0;
    border-radius: 0;
    max-width: 100%;
    padding: 0.25rem 0;
    /* The search input is type=search: Firefox and Safari draw their own field (frame and focus ring) inside ours */
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none;
}

.choices__input:focus,
.choices__input:focus-visible {
    outline: 0;
    box-shadow: none;
}

.choices__input::-webkit-search-decoration,
.choices__input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.choices__input::placeholder {
    color: var(--bs-text-muted);
    opacity: 1;
}

/* ====================================================================
   Placeholder
   ==================================================================== */

.choices__placeholder {
    color: var(--bs-text-muted);
    opacity: 1;
}

/* ====================================================================
   Groups
   ==================================================================== */

.choices__group .choices__heading {
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid hsl(from var(--bs-border-color) h s l / var(--bs-border-opacity-muted));
    color: var(--bs-text-muted);
}

/* ====================================================================
   Error State Integration
   ==================================================================== */

.powermail_field_error .choices__inner {
    border-color: var(--bs-danger-base);
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='red' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M21.73 18l-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3e%3cpath d='M12 9v4'/%3e%3cpath d='M12 17h.01'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.powermail_field_error .choices__inner:focus,
.powermail_field_error .is-focused .choices__inner {
    border-color: hsl(from var(--bs-danger-base) h s l / var(--bs-border-opacity-strong));
    box-shadow: 0 0 0 0.25rem hsl(from var(--bs-danger-base) h s l / 0.25);
}

/* ====================================================================
   Floating Label Adjustments
   ==================================================================== */

.form-label-floating .powermail_field:has(.choices) > .powermail_label {
    z-index: 3;
}

/* Enlarge inner box so the floated label has room (mirrors .form-control padding) */
.form-label-floating .powermail_field:has(.choices) .choices__inner {
    padding-top: 1.25rem;
    padding-bottom: 0.25rem;
}

/* Hide the Choices.js own placeholder text in the *displayed* field — the
   label takes its role visually. Scoped to the single/multiple list so the
   matching choice in the dropdown stays visible. */
.form-label-floating .powermail_field:has(.choices) .choices__list--single .choices__placeholder,
.form-label-floating .powermail_field:has(.choices) .choices__list--multiple .choices__placeholder {
    opacity: 0;
}

/* Float label up when:
   - Choices is focused/open
   - Single-select has a non-placeholder value selected
   - Multi-select has at least one item */
.form-label-floating .powermail_field:has(.choices.is-focused) > .powermail_label,
.form-label-floating .powermail_field:has(.choices .choices__list--single .choices__item:not(.choices__placeholder)) > .powermail_label,
.form-label-floating .powermail_field:has(.choices .choices__list--multiple .choices__item) > .powermail_label {
    top: 0.25rem;
    font-size: var(--bs-font-size-extra-small);
    opacity: 1;
    transform: translateY(0);
    font-weight: var(--bs-font-weight-bold);
    color: var(--settings-form-focus-color, var(--bs-focus-color));
}

/* ====================================================================
   Responsive Adjustments
   ==================================================================== */

@media (max-width: 640px) {
    .choices__list--dropdown,
    .choices__list[aria-expanded] {
        width: 100%;
    }
    
    .choices__item--selectable {
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
}

/* ====================================================================
   Accessibility
   ==================================================================== */

/* Custom SVG icon container for single select */
.choices[data-type*='select-one'] .choices-icon {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.choices[data-type*='select-one'] .choices-icon svg {
    display: block;
    width: 1rem;
    height: 1rem;
    color: var(--bs-text-muted);
}

.choices[data-type*='select-one'] .choices-icon.is-clearable {
    pointer-events: auto;
    cursor: pointer;
}

.choices[data-type*='select-one'] .choices-icon.is-clearable:hover svg {
    color: var(--bs-primary-base);
}

.choices[data-type*='select-one'][dir='rtl']::after {
    left: 11.5px;
    right: auto;
}

.choices[data-type*='select-multiple'] .choices__inner,
.choices[data-type*='text'] .choices__inner {
    cursor: text;
}

.choices[data-type*='select-multiple'] .choices__input {
    flex: 1 1 6rem;
    min-width: 6rem;
    padding: 0;
}

.choices[data-type*='select-one'] .choices__input {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--bs-border-radius);
    margin: 0;
}

.choices[data-type*='select-one'] .choices__list--dropdown .choices__input {
    padding: .125rem 0.75rem;
    border: none;
    border-radius: var(--bs-border-radius);
    position: absolute;
    top: -2.6875rem
}

.choices__list--dropdown .choices__item--selectable::after,
.choices__list[aria-expanded] .choices__item--selectable::after {
    content: none;
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
}

/* ====================================================================
   Backdrop-Filter (configurable via bs_background_backdropfilter)
   Class lands on .choices via JS propagation when editor opts in.
   Values mirror foundation26/Resources/Public/Css/bootstrap-utilities.css.
   ==================================================================== */

.choices.backdrop-filter-blur-1 .choices__list--dropdown,
.choices.backdrop-filter-blur-1 .choices__list[aria-expanded] {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.choices.backdrop-filter-blur-2 .choices__list--dropdown,
.choices.backdrop-filter-blur-2 .choices__list[aria-expanded] {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.choices.backdrop-filter-blur-3 .choices__list--dropdown,
.choices.backdrop-filter-blur-3 .choices__list[aria-expanded] {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.choices.backdrop-filter-blur-4 .choices__list--dropdown,
.choices.backdrop-filter-blur-4 .choices__list[aria-expanded] {
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}
.choices.backdrop-filter-blur-5 .choices__list--dropdown,
.choices.backdrop-filter-blur-5 .choices__list[aria-expanded] {
    backdrop-filter: blur(36px);
    -webkit-backdrop-filter: blur(36px);
}
