/**
 * ===============================================================================
 * BALAM AI - Custom Dropdown Component
 * ===============================================================================
 *
 * Styled dropdown replacement for native <select> elements.
 * Works with balam-dropdown.js for behavior (open/close, keyboard nav, sync).
 *
 * Variants:
 *   .custom-dropdown           - Light theme (default)
 *   .custom-dropdown--dark     - Dark theme (for dark modals/cards)
 *
 * HTML Pattern:
 *   <div class="custom-dropdown" data-select="mySelectId">
 *     <button type="button" class="custom-dropdown-trigger">
 *       <span class="custom-dropdown-selected"><span>Choose...</span></span>
 *       <span class="custom-dropdown-arrow"><i class="fas fa-chevron-down"></i></span>
 *     </button>
 *     <div class="custom-dropdown-menu">
 *       <div class="custom-dropdown-option" data-value="opt1">Option 1</div>
 *       <div class="custom-dropdown-option" data-value="opt2">Option 2</div>
 *     </div>
 *   </div>
 *
 * @requires shared-variables.css
 * @requires core/balam-dropdown.js
 * @version 1.0.0
 * ===============================================================================
 */

/* ─── Base Container ───────────────────────────────────────────────────────── */

.custom-dropdown {
    position: relative;
}

/* ─── Trigger Button ───────────────────────────────────────────────────────── */

.custom-dropdown-trigger {
    width: 100%;
    height: auto;
    min-height: 44px;
    padding: 0.75rem 1rem;
    padding-right: 2.5rem;
    margin: 0;
    border: 1px solid var(--balam-border, #e5e7eb);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--balam-text-primary, #1f2937);
    background: linear-gradient(145deg, #ffffff, #f8f9fb);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    text-align: left;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    white-space: nowrap;
}

.custom-dropdown-trigger:hover {
    border-color: var(--balam-primary, #4361ee);
    box-shadow: 0 2px 8px rgba(var(--balam-primary-rgb, 67, 97, 238), 0.15);
}

.custom-dropdown-trigger:focus {
    outline: none;
    border-color: var(--balam-primary, #4361ee);
    box-shadow: 0 0 0 3px rgba(var(--balam-primary-rgb, 67, 97, 238), 0.15);
}

.custom-dropdown.open .custom-dropdown-trigger {
    border-color: var(--balam-primary, #4361ee);
    box-shadow: 0 0 0 3px rgba(var(--balam-primary-rgb, 67, 97, 238), 0.15);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* ─── Selected Value Display ───────────────────────────────────────────────── */

.custom-dropdown-selected {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.custom-dropdown-selected span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-dropdown-selected i {
    font-size: 0.8rem;
    opacity: 0.7;
}

/* ─── Arrow Indicator ──────────────────────────────────────────────────────── */

.custom-dropdown-arrow {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease;
    color: var(--balam-text-secondary, #6b7280);
}

.custom-dropdown.open .custom-dropdown-arrow {
    transform: translateY(-50%) rotate(180deg);
}

/* ─── Dropdown Menu ────────────────────────────────────────────────────────── */

.custom-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff;
    border: 1px solid var(--balam-primary, #4361ee);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12),
                0 4px 12px rgba(var(--balam-primary-rgb, 67, 97, 238), 0.08);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    z-index: 1000;
    transition: max-height 0.25s ease, opacity 0.2s ease;
}

.custom-dropdown.open .custom-dropdown-menu {
    max-height: 280px;
    opacity: 1;
    overflow-y: auto;
}

/* Scrollbar */
.custom-dropdown-menu::-webkit-scrollbar {
    width: 6px;
}

.custom-dropdown-menu::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.custom-dropdown-menu::-webkit-scrollbar-thumb {
    background: var(--balam-primary, #4361ee);
    border-radius: 3px;
}

.custom-dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: var(--balam-secondary, #3730a3);
}

/* ─── Options ──────────────────────────────────────────────────────────────── */

.custom-dropdown-option {
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    transition: all 0.15s ease;
    font-size: 0.875rem;
    color: var(--balam-text-primary, #1f2937);
    border-radius: 6px;
    margin: 0.25rem 0.5rem;
}

.custom-dropdown-option:first-child {
    margin-top: 0.5rem;
}

.custom-dropdown-option:last-child {
    margin-bottom: 0.5rem;
}

.custom-dropdown-option:hover {
    background: rgba(var(--balam-primary-rgb, 67, 97, 238), 0.1);
}

.custom-dropdown-option.selected {
    background: rgba(var(--balam-primary-rgb, 67, 97, 238), 0.15);
    color: var(--balam-primary, #4361ee);
    font-weight: 500;
}

.custom-dropdown-option.selected::after {
    content: '\f00c';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--balam-primary, #4361ee);
}

.custom-dropdown-option i {
    width: 18px;
    text-align: center;
    font-size: 0.85rem;
    opacity: 0.7;
}

.custom-dropdown-option:hover i {
    opacity: 1;
}

.custom-dropdown-option.selected i {
    opacity: 1;
    color: var(--balam-primary, #4361ee);
}

/* ─── Divider ──────────────────────────────────────────────────────────────── */

.custom-dropdown-divider {
    height: 1px;
    background: var(--balam-border, #e5e7eb);
    margin: 0.375rem 0.75rem;
}

/* ===============================================================================
   Dark Variant (.custom-dropdown--dark)
   For use inside dark-themed modals and cards (e.g., assistants configuration).
   =============================================================================== */

.custom-dropdown--dark .custom-dropdown-trigger {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--balam-dark-text-primary, #f1f5f9);
    box-shadow: none;
}

.custom-dropdown--dark .custom-dropdown-trigger:hover {
    border-color: var(--balam-primary, #4361ee);
    box-shadow: 0 2px 8px rgba(var(--balam-primary-rgb, 67, 97, 238), 0.2);
}

.custom-dropdown--dark .custom-dropdown-trigger:focus,
.custom-dropdown--dark.open .custom-dropdown-trigger {
    border-color: var(--balam-primary, #4361ee);
    box-shadow: 0 0 0 3px rgba(var(--balam-primary-rgb, 67, 97, 238), 0.2);
}

.custom-dropdown--dark .custom-dropdown-arrow {
    color: var(--balam-dark-text-secondary, #94a3b8);
}

.custom-dropdown--dark .custom-dropdown-menu {
    background: var(--balam-dark-card-bg, #1e293b);
    border-color: var(--balam-primary, #4361ee);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4),
                0 4px 12px rgba(var(--balam-primary-rgb, 67, 97, 238), 0.15);
}

.custom-dropdown--dark .custom-dropdown-menu::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.custom-dropdown--dark .custom-dropdown-option {
    color: var(--balam-dark-text-primary, #f1f5f9);
}

.custom-dropdown--dark .custom-dropdown-option:hover {
    background: rgba(var(--balam-primary-rgb, 67, 97, 238), 0.15);
}

.custom-dropdown--dark .custom-dropdown-option.selected {
    background: rgba(var(--balam-primary-rgb, 67, 97, 238), 0.2);
}

.custom-dropdown--dark .custom-dropdown-divider {
    background: rgba(255, 255, 255, 0.1);
}

/* ─── Accessibility: Reduced Motion ────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .custom-dropdown-arrow {
        transition: none;
    }

    .custom-dropdown-menu {
        transition: none;
    }

    .custom-dropdown-option {
        transition: none;
    }
}
