/*
// Choices.js - Custom overrides for DaisyUI theme
// Base Choices.js CSS is imported in multi_select_controller.js
*/

/* Hide native select visually when Choices.js is active */
select[data-multi-select-target="select"]:not(.is-hidden) {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
}

select.is-hidden {
    display: none !important;
}

/* Hide native select arrow and styling when Choices.js is active */
select[data-multi-select-target="select"],
select.is-hidden {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;

    &::-ms-expand {
        display: none;
    }
}

/* Use CSS custom properties for DaisyUI theming */
.choices {
    --choices-bg-color: hsl(var(--b1));
    --choices-bg-color-disabled: hsl(var(--b2));
    --choices-bg-color-dropdown: hsl(var(--b1));
    --choices-text-color: hsl(var(--bc));
    --choices-keyline-color: hsl(var(--b3));
    --choices-primary-color: hsl(var(--p));
    --choices-disabled-color: hsl(var(--b2));
    --choices-item-disabled-color: hsl(var(--bc) / 0.5);
    --choices-highlighted-color: hsl(var(--b2));
    --choices-highlight-color: hsl(var(--p));
    --choices-border-radius: 0.5rem;
    --choices-border-radius-item: 0.375rem;
    --choices-z-index: 50;
    --choices-input-height: 3rem;

    width: 100%;
    margin-bottom: 0;
    font-size: 1rem;
}

.choices__inner {
    @apply bg-base-100;
    border-width: var(--select-border-width, 0.5px);
    border-color: var(--color-secondary);
    border-radius: var(--select-border-radius, 0.5rem);
    min-height: calc(var(--size-field, .25rem) * 10);
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;

    &:focus-within {
        border-color: var(--select-focus-border-color, hsl(var(--p)));
        box-shadow: 0 0 0 1px var(--select-focus-border-color, hsl(var(--p)));
        outline: 1px solid var(--select-focus-border-color, hsl(var(--p)));
        outline-offset: 2px;
    }
}



/* When dropdown is open, adjust inner border radius */
.choices.is-open .choices__inner {
    border-radius: var(--select-border-radius, 0.5rem) var(--select-border-radius, 0.5rem) 0 0;
}

.choices__input {
    @apply !bg-transparent;
    flex: 1 1 auto;
    min-width: 3rem;
    max-width: 100%;
    display: inline-flex;
    align-items: center;
    height: 100%;
    line-height: normal;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;

    &::placeholder {
        @apply text-base-content/50;
        line-height: normal;
    }
}

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

.choices__list--dropdown {
    padding: 0.5rem 0;
    border-radius: 0 0 var(--select-border-radius, 0.5rem) var(--select-border-radius, 0.5rem);
}

.has-no-choices {
    color: #999;
    text-align: center;
    font-size: 0.75rem;
    padding: 0.5rem 0;
}

.choices__list--multiple {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    flex: 0 1 auto;
    min-width: 0;

    .choices__item {
        display: inline-flex;
        align-items: center;
        @apply badge badge-primary;
        font-size: 0.875rem;
        font-weight: 500;
        word-break: break-word;
        box-sizing: border-box;
        flex-shrink: 0;
        max-width: 100%;
        line-height: 1.5;

        &[data-deletable] {
            padding-right: 0.25rem;
        }

        .choices__button {
            border-left: 1px solid hsl(var(--pc) / 0.5);
            padding: 0;
            margin-left: 0.5rem;
            margin-right: 0;
            cursor: pointer;
            background: transparent;
            border-top: none;
            border-right: none;
            border-bottom: none;
            font-size: 0;
            line-height: 1;
            width: 1rem;
            height: 1rem;
            min-width: 1rem;
            position: relative;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            vertical-align: middle;
            opacity: 0.75;

            /* Create X icon using pseudo-elements */
            &::before,
            &::after {
                content: "";
                position: absolute;
                width: 0.625rem;
                height: 1.5px;
                background-color: currentColor;
                border-radius: 1px;
                top: 50%;
                left: 50%;
            }

            &::before {
                transform: translate(-50%, -50%) rotate(45deg);
            }

            &::after {
                transform: translate(-50%, -50%) rotate(-45deg);
            }

            &:hover,
            &:focus {
                @apply text-error;
                opacity: 1;
            }
        }
    }
}

.choices__list--dropdown {
    border-radius: var(--select-border-radius, 0.5rem);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    margin-top: 0;
    max-height: 20rem;
    overflow-y: auto;

    &.is-hidden,
    &[style*="display: none"] {
        display: none !important;
    }

    /* Hide empty dropdown */
    &:empty {
        display: none !important;
    }

    .choices__input {
        @apply border-b border-base-300;
    }

    .choices__item {
        &--selectable {
            &.is-highlighted {
                @apply bg-base-200;
            }
        }

        &--disabled {
            @apply text-base-content/50;
        }
    }

    .choices__group {
        .choices__heading {
            @apply border-b border-base-300;
        }
    }
}

/* Hide dropdown container when no choices available */
.choices__dropdown {

    &.is-hidden,
    &[style*="display: none"] {
        display: none !important;
    }
}

.choices__placeholder {
    @apply text-base-content/50;
    opacity: 1;
}

.choices__list--multiple .choices__item {
    margin-bottom: 0;
}

/* Hide placeholder when there are items - CSS-only solution using :has() */
.choices__inner:has(.choices__list--multiple .choices__item) .choices__placeholder,
.choices__inner:has(.choices__item) .choices__placeholder {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
    pointer-events: none !important;
}

.choices__placeholder.is-hidden,
.choices__placeholder[data-placeholder-hidden="true"],
.choices__placeholder[style*="display: none"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
    pointer-events: none !important;
}

/* Hide placeholder when container has items (via class added by JS) */
.choices.has-items .choices__placeholder {
    display: none !important;
}

/* CSS fallback: hide placeholder when there are items in the list */
.choices__inner:has(.choices__list--multiple .choices__item) .choices__placeholder {
    display: none !important;
}

/* Note: Empty dropdown hiding is handled by Choices.js itself via noChoicesText option */

/* Hide "no choices" and "no results" messages */
.choices__notice {
    display: none !important;
}

.choices__notice--no-results,
.choices__notice--no-choices {
    display: none !important;
}

/* Hide input when disabled due to no choices */
.choices.is-disabled .choices__input {
    display: none !important;
}

/* Error state styling */
.choices.is-invalid .choices__inner {
    @apply border-error;
    border-color: hsl(var(--er)) !important;

    &:focus-within {
        border-color: hsl(var(--er)) !important;
        box-shadow: 0 0 0 1px hsl(var(--er)) !important;
        outline-color: hsl(var(--er)) !important;
    }
}