/**
 * MitraHelp - Universal Searchable Select Dropdown Styles
 * Seamlessly integrates text search into all <select> elements across the project
 * Crafted for Bootstrap 5.3 & Plus Jakarta Sans typography
 */

/* 1. Visually Hidden Native Select (Remains active & focusable for HTML5 validation & forms) */
.searchable-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* 2. Wrapper */
.searchable-select-wrapper {
    position: relative;
    display: block;
    width: 100%;
}

/* 3. Trigger Button - Form Select Replacement */
.searchable-select-trigger {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    text-align: left !important;
    background-image: none !important; /* Remove native BS SVG chevron */
    padding-right: 0.75rem !important;
    user-select: none;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, background-color 0.15s ease;
    font-weight: 500;
    color: var(--text-dark, #0f172a);
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
}

.searchable-select-trigger:hover:not(:disabled) {
    border-color: #94a3b8;
    background-color: #f8fafc;
}

.searchable-select-trigger:focus,
.searchable-select-trigger.active {
    border-color: #3b82f6 !important;
    outline: 0 !important;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.2) !important;
    background-color: #ffffff;
}

.searchable-select-trigger:disabled,
.searchable-select-trigger.disabled {
    background-color: #e2e8f0 !important;
    opacity: 0.65;
    cursor: not-allowed;
    border-color: #cbd5e1 !important;
}

/* Trigger Label Text */
.searchable-select-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0.5rem;
    flex-grow: 1;
}

.searchable-select-placeholder {
    color: #94a3b8 !important;
    font-weight: 400;
}

/* Chevron Caret Icon */
.searchable-select-caret {
    font-size: 0.75rem;
    color: #64748b;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), color 0.2s ease;
    flex-shrink: 0;
}

.searchable-select-trigger.active .searchable-select-caret {
    transform: rotate(180deg);
    color: #2563eb;
}

/* Small Variant */
.searchable-select-sm .searchable-select-trigger {
    padding: 0.35rem 0.65rem !important;
    font-size: 0.8rem !important;
    border-radius: 6px !important;
}

.searchable-select-sm .searchable-select-caret {
    font-size: 0.68rem;
}

/* Large Variant */
.searchable-select-lg .searchable-select-trigger {
    padding: 0.6rem 1rem !important;
    font-size: 0.95rem !important;
    border-radius: 10px !important;
}

/* Validation States */
.searchable-select-trigger.is-invalid {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 0.2rem rgba(239, 68, 68, 0.2) !important;
}

.searchable-select-trigger.is-valid {
    border-color: #22c55e !important;
}

/* 4. Floating Dropdown Menu */
.searchable-select-dropdown {
    position: fixed;
    z-index: 100000;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: searchSelectFadeIn 0.15s ease-out;
}

@keyframes searchSelectFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.searchable-select-dropdown.dropup {
    animation: searchSelectFadeUp 0.15s ease-out;
}

@keyframes searchSelectFadeUp {
    from {
        opacity: 0;
        transform: translateY(4px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 5. Search Bar Inside Dropdown */
.searchable-select-search-wrap {
    position: relative;
    padding: 0.5rem;
    background: #f8fafc;
    border-bottom: 1px solid #f1f5f9;
}

.searchable-select-search-inner {
    position: relative;
    display: flex;
    align-items: center;
}

.searchable-select-search-icon {
    position: absolute;
    left: 0.75rem;
    font-size: 0.8rem;
    color: #94a3b8;
    pointer-events: none;
}

.searchable-select-search-input {
    width: 100%;
    padding: 0.42rem 2rem 0.42rem 2.1rem;
    font-size: 0.82rem;
    font-family: inherit;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    outline: none;
    color: #0f172a;
    background: #ffffff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.searchable-select-search-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.searchable-select-search-input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.searchable-select-clear-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    display: none;
}

.searchable-select-clear-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* 6. Meta info bar */
.searchable-select-meta-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: 0.72rem;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 1px solid #f1f5f9;
}

/* 7. Scrollable Options List */
.searchable-select-list {
    max-height: 240px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.35rem 0;
    margin: 0;
    list-style: none;
    overscroll-behavior: contain;
}

.searchable-select-list::-webkit-scrollbar {
    width: 5px;
}

.searchable-select-list::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.searchable-select-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.searchable-select-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Option Items */
.searchable-select-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
    color: #334155;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
    user-select: none;
}

.searchable-select-item:hover,
.searchable-select-item.highlighted {
    background-color: #eff6ff;
    color: #1e40af;
}

.searchable-select-item.selected {
    background-color: #dbeafe;
    color: #1e3a8a;
    font-weight: 600;
}

.searchable-select-item.selected .searchable-select-check {
    opacity: 1;
}

.searchable-select-item.disabled {
    color: #94a3b8;
    background: transparent !important;
    cursor: not-allowed;
    opacity: 0.6;
}

.searchable-select-check {
    font-size: 0.75rem;
    color: #2563eb;
    margin-left: 0.5rem;
    opacity: 0;
    flex-shrink: 0;
}

/* Search Query Text Highlight */
.searchable-select-item mark {
    background: #fef08a !important;
    color: #854d0e !important;
    padding: 0 0.15rem;
    border-radius: 2px;
    font-weight: 700;
}

/* Optgroup Header */
.searchable-select-group-header {
    padding: 0.4rem 0.75rem 0.2rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    background: #ffffff;
    user-select: none;
}

/* Empty / No Results Message */
.searchable-select-empty {
    padding: 1.25rem 0.75rem;
    text-align: center;
    color: #64748b;
    font-size: 0.82rem;
}

.searchable-select-empty i {
    font-size: 1.25rem;
    color: #94a3b8;
    margin-bottom: 0.35rem;
    display: block;
}
