/**
 * UBChoices Custom Styles
 * Matches Choices.js appearance with Bootstrap form-control and bootstrap-select styling
 */

/* =============================================
   BASE LAYOUT - Fix flex container issues
   ============================================= */

/* Ensure Choices takes full width in flex containers */
.choices {
    position: relative;
    width: 100%;
    min-width: 0; /* Allow shrinking in flex */
    flex: 1 1 auto;
    margin-bottom: 0;
}

/* Ensure inner container also takes full width */
.choices__inner {
    width: 100%;
    min-width: 0;
}

/* =============================================
   FORM-CONTROL MATCHING STYLES
   ============================================= */

/* Match form-control height and padding */
.choices__inner {
    min-height: 42px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    background-color: #fff;
    border: 1px solid #dfdfe6;
    border-radius: 6px;
    color: #898b92;
    line-height: 1.5;
    vertical-align: middle;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

/* Adjust padding when remove button is present */
.choices[data-type*="select-one"] .choices__inner {
    padding-right: 2.5rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Focus state - match form-control focus */
.choices.is-focused .choices__inner,
.choices.is-open .choices__inner {
    border-color: var(--primary, #5943be);
    box-shadow: none;
    outline: none;
}

/* Support for bg-light on original select */
.bg-light + .choices .choices__inner {
    background-color: #f8f9fa;
}

/* Disabled state */
.choices.is-disabled .choices__inner {
    background-color: #f7f8fa;
    opacity: 1;
    border-color: #dfdfe6;
    cursor: not-allowed;
}

/* =============================================
   SINGLE SELECT STYLES
   ============================================= */

/* Single select - match bootstrap-select dropdown toggle */
.choices[data-type*="select-one"] .choices__inner {
    display: flex;
    align-items: center;
}

/* Add left padding when select has an icon before it */
.ubx-select2-container .choices[data-type*="select-one"] .choices__inner,
.ubx-select-icon + select.ub-choice + .choices[data-type*="select-one"] .choices__inner,
.ubx-select-icon ~ .choices[data-type*="select-one"] .choices__inner {
    padding-left: 2.25rem;
}

/* Single select item text */
.choices[data-type*="select-one"] .choices__item {
    color: #898b92;
    font-size: 0.875rem;
}

/* Selected item in single select */
.choices[data-type*="select-one"] .choices__item--selectable {
    color: #333;
}

/* Arrow button - match bootstrap-select */
.choices[data-type*="select-one"]::after {
    content: "";
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #898b92;
    margin-top: 0;
    border-radius: 0;
}

.choices[data-type*="select-one"].is-open::after {
    border-top: none;
    border-bottom: 5px solid #898b92;
}

/* =============================================
   REMOVE/CLEAR BUTTON STYLES
   ============================================= */

/* Remove button for single select */
.choices[data-type*="select-one"] .choices__button {
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    padding: 0;
    width: 16px;
    height: 16px;
    border: none;
    background-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23898b92' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 12px;
    opacity: 0.5;
    cursor: pointer;
}

.choices[data-type*="select-one"] .choices__button:hover {
    opacity: 1;
}

.choices[data-type*="select-one"] .choices__button:focus {
    outline: none;
}

/* Remove button for multi-select items */
.choices__button {
    border: none;
    background-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 10px;
    padding: 0;
    margin-left: 6px;
    width: 14px;
    height: 14px;
    cursor: pointer;
}

/* =============================================
   MULTI-SELECT STYLES
   ============================================= */

/* Multi-select inner - ensure consistent height when empty */
.choices[data-type*="select-multiple"] .choices__inner {
    min-height: 42px;
    padding: 0.375rem 0.75rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

/* Multi-select list container needs gap */
.choices__list--multiple {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Ensure input in multi-select doesn't collapse */
.choices[data-type*="select-multiple"] .choices__input {
    min-width: 100px;
    padding: 0;
    margin: 0;
    background: transparent;
    min-height: 28px;
    line-height: 28px;
}

/* When no items selected, input should fill the space */
.choices[data-type*="select-multiple"] .choices__list--multiple:empty + .choices__input {
    flex: 1;
}

/* Multi-select selected items */
.choices__list--multiple .choices__item {
    background-color: var(--primary, #5943be);
    border: 1px solid var(--primary, #5943be);
    border-radius: 4px;
    color: #fff;
    font-size: 0.8125rem;
    padding: 0.2rem 0.5rem;
    margin: 0;
    display: inline-flex;
    align-items: center;
}

.choices__list--multiple .choices__item.is-highlighted {
    background-color: var(--hov-primary, #4835a0);
    border-color: var(--hov-primary, #4835a0);
}

/* =============================================
   DROPDOWN STYLES
   ============================================= */

/* Dropdown container */
.choices__list--dropdown,
.choices__list[aria-expanded] {
    border: 1px solid #dfdfe6;
    border-top: none;
    border-radius: 0 0 6px 6px;
    background-color: #fff;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow-y: auto;
}

/* When opening upward */
.choices.is-flipped .choices__list--dropdown,
.choices.is-flipped .choices__list[aria-expanded] {
    border-top: 1px solid #dfdfe6;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    z-index: 9999;
}

/* Dropdown items */
.choices__list--dropdown .choices__item,
.choices__list[aria-expanded] .choices__item {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: #333;
}

/* Dropdown item hover/highlight */
.choices__list--dropdown .choices__item--selectable.is-highlighted,
.choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
    background-color: var(--primary, #5943be);
    color: #fff;
}

/* Selected item in dropdown */
.choices__list--dropdown .choices__item--selectable.is-selected,
.choices__list[aria-expanded] .choices__item--selectable.is-selected {
    color: var(--primary);
    background-color: rgba(89, 67, 190, 0.1);
}

/* Disabled items */
.choices__list--dropdown .choices__item--disabled,
.choices__list[aria-expanded] .choices__item--disabled {
    color: #aaa;
    cursor: not-allowed;
}

/* Group headings */
.choices__group .choices__heading {
    font-weight: 600;
    font-size: 0.75rem;
    color: #898b92;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #eee;
}

/* =============================================
   SEARCH INPUT STYLES
   ============================================= */

/* Search input in dropdown */
.choices__input {
    font-size: 0.875rem;
    color: #333;
    background-color: #fff;
    border: none;
    padding: 0.5rem;
    margin: 0;
}

.choices__input:focus {
    outline: none;
}

/* Search input placeholder */
.choices__input::placeholder {
    color: #898b92;
}

/* =============================================
   PLACEHOLDER STYLES
   ============================================= */

/* Placeholder text */
.choices__placeholder {
    color: #898b92 !important;
    opacity: 0.7;
}

/* =============================================
   NO RESULTS / NO CHOICES
   ============================================= */

.choices__list--dropdown .choices__item--disabled.has-no-results,
.choices__list--dropdown .choices__item--disabled.has-no-choices {
    padding: 0.5rem 0.75rem;
    background: #f5f5f5;
    margin: 0.25rem;
    border-radius: 0.2rem;
    text-align: center;
    color: #898b92;
}

/* =============================================
   SIZE VARIANTS
   ============================================= */

/* Small size - matches form-control-sm */
.choices--sm .choices__inner,
.form-group-sm .choices__inner,
.form-control-sm + .choices .choices__inner {
    min-height: 31px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    border-radius: 4px;
}

.choices--sm .choices__list--dropdown .choices__item,
.form-group-sm .choices .choices__list--dropdown .choices__item {
    padding: 0.35rem 0.5rem;
    font-size: 0.8125rem;
}

/* Large size - matches form-control-lg */
.choices--lg .choices__inner,
.form-group-lg .choices__inner,
.form-control-lg + .choices .choices__inner {
    min-height: 48px;
    padding: 0.55rem 1rem;
    font-size: 1rem;
    border-radius: 6px;
}

.choices--lg .choices__list--dropdown .choices__item,
.form-group-lg .choices .choices__list--dropdown .choices__item {
    padding: 0.6rem 1rem;
    font-size: 1rem;
}

/* =============================================
   INPUT GROUP COMPATIBILITY
   ============================================= */

/* Within input-group */
.input-group .choices {
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
}

.input-group .choices .choices__inner {
    border-radius: 0;
}

.input-group > .choices:first-child .choices__inner {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

.input-group > .choices:last-child .choices__inner {
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

/* =============================================
   VALIDATION STATES
   ============================================= */

/* Invalid state */
.is-invalid + .choices .choices__inner,
.was-validated select:invalid + .choices .choices__inner,
.choices.is-invalid .choices__inner {
    border-color: #dc3545;
}

/* Valid state */
.is-valid + .choices .choices__inner,
.was-validated select:valid + .choices .choices__inner,
.choices.is-valid .choices__inner {
    border-color: #28a745;
}

/* =============================================
   RTL SUPPORT
   ============================================= */

[dir="rtl"] .choices[data-type*="select-one"]::after {
    right: auto;
    left: 1rem;
}

[dir="rtl"] .choices[data-type*="select-one"] .choices__button {
    right: auto;
    left: 2rem;
}

[dir="rtl"] .choices[data-type*="select-one"] .choices__inner {
    padding-right: 0.75rem;
    padding-left: 2.5rem;
}

[dir="rtl"] .choices__list--multiple .choices__item {
    margin: 0.15rem 0 0.15rem 0.25rem;
}

[dir="rtl"] .choices__button {
    margin-left: 0;
    margin-right: 6px;
}

/* =============================================
   BOOTSTRAP-SELECT COMPATIBILITY CLASSES
   ============================================= */

/* Support .rounded-0 class */
.rounded-0 .choices__inner {
    border-radius: 0 !important;
}

