/* SingleSelectDropdown — polished to the Kivu theme.
   Same class names / DOM that create() builds, so it stays a drop-in for every
   `new SingleSelectDropdown({...})` already in the app. Only visuals changed,
   plus styles for the open-state arrow, layering, empty/loading and validation. */

.single-select-dropdown {
    position: relative;
    width: 100%;
    /* per-page sizing knobs — override in the page CSS as needed */
    --ssd-control-min-height: 42px;
    --ssd-list-max-height: 260px;
}

/* the open dropdown (or focused) layers above its neighbours.
   No z-index when closed, so the open panel isn't trapped under a later sibling. */
.single-select-dropdown.ssd-open,
.single-select-dropdown:focus-within {
    z-index: 40;
}

/* closed control */
.single-select-dropdown .kivu-search-field {
    position: relative;
    display: flex;
    align-items: center;
    min-height: var(--ssd-control-min-height);
    padding: 6px 40px 6px 14px;
    background: #ffffff;
    border: 1px solid var(--kivu-border-color, #e9e9e9);
    border-radius: 11px;
    box-shadow: var(--kivu-black-shadow-sm, 0px 1px 2px rgba(0, 0, 0, .05));
    cursor: pointer;
    outline: none;
    transition: border-color .25s ease, box-shadow .25s ease;
}

.single-select-dropdown:not(.dropdown-disabled) .kivu-search-field:is(:hover, :focus) {
    border-color: var(--kivu-primary-color, #3489CA);
    box-shadow: 0 0 0 3px rgba(52, 137, 202, .14);
}

.single-select-dropdown .text {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    font-size: var(--ssd-text-size, 14px);
    color: var(--kivu-text-color, #485159);
}

/* placeholder — note the JS emits .not-selectable (the old .unselectable rule never matched) */
.single-select-dropdown .text.not-selectable {
    color: #9aa9b8;
    font-weight: 300;
}

/* optional leading icon */
.single-select-dropdown .icon-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 10px;
}

.single-select-dropdown .icon-container .icon:first-child,
.single-select-dropdown .icon-container img {
    height: 20px;
    width: 20px;
    object-fit: contain;
}

/* arrow — flips while open (.ssd-open is toggled in open()/close()) */
.single-select-dropdown .dropdown-icon-svg {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    opacity: .55;
    transition: transform .3s ease;
}

.single-select-dropdown.ssd-open .dropdown-icon-svg {
    transform: translateY(-50%) rotate(180deg);
}

/* disabled control */
.single-select-dropdown.dropdown-disabled .kivu-search-field {
    cursor: not-allowed;
    background: var(--kivu-disabled-background, #EEEEEE);
    box-shadow: none;
}

.single-select-dropdown.dropdown-disabled .text {
    color: #9aa9b8;
}

/* hidden tab helper the component injects */
.tabableInput {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: none !important;
    opacity: 0;
    z-index: -1;
}

/* open panel — open/close is animated by the JS slideDown/slideUp */
.single-select-dropdown .drop-down {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 12;
    background: #ffffff;
    border: 1px solid var(--kivu-border-color, #e9e9e9);
    border-radius: 13px;
    padding: 6px;
    box-shadow: 0 16px 36px rgba(15, 28, 46, .16);
}

/* search row — icon then field (flex, no overlap) */
.single-select-dropdown .search {
    display: flex;
    align-items: center;
    gap: 9px;
    background: #e9edf3;
    border: 1px solid #d3dae5;
    border-radius: 9px;
    padding: 0 12px;
    height: 38px;
    margin: 2px 2px 8px;
    box-sizing: border-box;
    overflow: hidden;
}

.single-select-dropdown .search-icon {
    height: 20px;
    width: 20px;
    object-fit: contain;
    opacity: .6;
    flex-shrink: 0;
}

.single-select-dropdown .ajax-search-field {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: #e9edf3;
    height: 32px;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    font-size: 13px;
    color: var(--kivu-text-color, #485159);
}

.single-select-dropdown .ajax-search-field::placeholder {
    color: #9aa9b8;
}

/* options */
.single-select-dropdown .list {
    max-height: var(--ssd-list-max-height);
    overflow-y: auto;
    overflow-x: hidden;
}

.single-select-dropdown .list::-webkit-scrollbar {
    width: 6px;
}

.single-select-dropdown .list::-webkit-scrollbar-thumb {
    background: #d6e1ee;
    border-radius: 3px;
}

.single-select-dropdown .option {
    padding: 2px;
    cursor: pointer;
}

.single-select-dropdown .inner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    padding: 8px 11px;
    border: 1px solid transparent;
    border-radius: 9px;
    transition: background .18s ease, border-color .18s ease;
}

.single-select-dropdown .option:not(.option-disabled):hover .inner,
.single-select-dropdown .highlighted .inner {
    background: #D9EEFF;
    border-color: #D9EEFF;
}

.single-select-dropdown .option-content {
    width: 100%;
}

.single-select-dropdown .option .heading {
    font-size: 14px;
    font-weight: 600;
    color: var(--kivu-text-color, #485159);
}

.single-select-dropdown .option .subheading {
    font-size: 12px;
    font-weight: 300;
    font-style: italic;
    color: var(--kivu-primary-color, #3489CA);
}

.single-select-dropdown .option .heading,
.single-select-dropdown .option .subheading {
    overflow-wrap: anywhere;
}

@media (max-width: 1250px) {
    .single-select-dropdown .option .heading {
        font-size: 13px;
    }
    .single-select-dropdown .option .subheading {
        font-size: 11px;
    }
    .single-select-dropdown .ajax-search-field {
        font-size: 12.5px;
    }
}

/* selected + selected/highlighted combo */
.single-select-dropdown .option-selected .inner {
    background: var(--kivu-primary-color, #3489CA);
    border-color: var(--kivu-primary-color, #3489CA);
}

.single-select-dropdown .option-selected .heading {
    color: #ffffff;
}

.single-select-dropdown .option-selected .subheading {
    color: rgba(255, 255, 255, .85);
}

.single-select-dropdown .option-selected.highlighted .inner {
    background: var(--deep-sea, #1A4565);
    border-color: var(--deep-sea, #1A4565);
}

/* disabled option */
.single-select-dropdown .option-disabled {
    opacity: .45;
    cursor: not-allowed;
}

/* empty + loading data states (rendered by add()/search()) */
.single-select-dropdown .empty-note {
    padding: 14px 12px;
    text-align: center;
    font-size: 13px;
    color: #9aa9b8;
}

.single-select-dropdown .loading-note {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 16px 12px;
}

.single-select-dropdown .loading-note .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--kivu-primary-color, #3489CA);
    opacity: .4;
    animation: ssd-pulse 1s infinite ease-in-out;
}

.single-select-dropdown .loading-note .dot:nth-child(2) { animation-delay: .15s; }
.single-select-dropdown .loading-note .dot:nth-child(3) { animation-delay: .3s; }

@keyframes ssd-pulse {
    0%, 100% { opacity: .3; transform: scale(.85); }
    50% { opacity: 1; transform: scale(1); }
}

/* bootstrapValidator: keep the required * / feedback icon clear of the arrow.
   (Visual hooks only — the validator wiring stays per-page; no validation logic here.) */
/* shift the arrow left only while the validator is showing an icon
   (has-success/has-error), and return to normal once the icon is gone */
.has-success .single-select-dropdown .dropdown-icon-svg,
.has-error .single-select-dropdown .dropdown-icon-svg { right: 38px; }

.single-select-dropdown .ssd-feedback {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    pointer-events: none;
}

.single-select-dropdown.ssd-invalid .kivu-search-field {
    border-color: var(--kivu-danger-color, #FF3B30);
}

.single-select-dropdown.ssd-invalid:not(.dropdown-disabled) .kivu-search-field:is(:hover, :focus) {
    box-shadow: 0 0 0 3px rgba(255, 59, 48, .14);
}

.single-select-dropdown.ssd-invalid .ssd-feedback { color: var(--kivu-danger-color, #FF3B30); }
.single-select-dropdown.ssd-valid .ssd-feedback { color: #1faa6c; }
