/* Custom Dropdown Styles */
.custom-dropdown {
    position: relative;
    width: 100%;
    font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    isolation: isolate; /* Create stacking context */
    z-index: 50;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(79, 70, 229, 0.2);
    border-radius: 12px;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    min-height: 48px;
}

.dropdown-trigger:hover {
    border-color: rgba(79, 70, 229, 0.4);
    background: rgba(255, 255, 255, 0.95);
}

.dropdown-trigger.active {
    border-color: #4F46E5;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.dropdown-trigger.selected {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(79, 70, 229, 0.5);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
}

.dropdown-trigger.selected:hover {
    background: rgba(255, 255, 255, 1);
    border-color: rgba(79, 70, 229, 0.6);
}

.dropdown-trigger.error {
    border-color: #EF4444;
    background: rgba(254, 242, 242, 0.9);
}

.dropdown-placeholder {
    color: #9CA3AF;
    flex: 1;
    text-align: left;
}

.dropdown-selected {
    flex: 1;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 20px;
}

.dropdown-selected-content {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.dropdown-selected-text {
    color: #111827;
    font-weight: 600;
    font-size: 14px;
}

.dropdown-selected-meta {
    color: #4F46E5;
    font-size: 11px;
    font-weight: 600;
    background: rgba(79, 70, 229, 0.15);
    padding: 3px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid rgba(79, 70, 229, 0.2);
    white-space: nowrap;
}

.dropdown-icon {
    width: 20px;
    height: 20px;
    color: #6B7280;
    transition: transform 0.2s ease;
}

.dropdown-trigger.active .dropdown-icon {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    z-index: 100;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(79, 70, 229, 0.2);
    border-radius: 12px;
    box-shadow: 
        0 20px 40px -5px rgba(0, 0, 0, 0.15),
        0 10px 25px -5px rgba(0, 0, 0, 0.1);
    max-height: 300px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    min-width: 200px;
}

.dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-search {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(79, 70, 229, 0.1);
}

.dropdown-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(209, 213, 219, 0.5);
    border-radius: 8px;
    font-size: 14px;
    background: rgba(249, 250, 251, 0.8);
    color: #374151;
    transition: all 0.2s ease;
}

.dropdown-search-input:focus {
    outline: none;
    border-color: #4F46E5;
    background: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.dropdown-search-input::placeholder {
    color: #9CA3AF;
}

.dropdown-options {
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
}

.dropdown-options::-webkit-scrollbar {
    width: 6px;
}

.dropdown-options::-webkit-scrollbar-track {
    background: transparent;
}

.dropdown-options::-webkit-scrollbar-thumb {
    background: rgba(79, 70, 229, 0.2);
    border-radius: 3px;
}

.dropdown-options::-webkit-scrollbar-thumb:hover {
    background: rgba(79, 70, 229, 0.3);
}

.dropdown-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

.dropdown-option:hover {
    background: rgba(79, 70, 229, 0.05);
    border-color: rgba(79, 70, 229, 0.1);
}

.dropdown-option.selected {
    background: rgba(79, 70, 229, 0.1);
    border-color: rgba(79, 70, 229, 0.2);
}

.dropdown-option-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dropdown-option-name {
    font-weight: 500;
    color: #111827;
    font-size: 14px;
}

.dropdown-option-meta {
    font-size: 12px;
    color: #6B7280;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dropdown-option-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    background: rgba(79, 70, 229, 0.1);
    color: #4F46E5;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
}

.dropdown-add-new {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(79, 70, 229, 0.1);
    background: rgba(79, 70, 229, 0.02);
}

.dropdown-add-button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dropdown-add-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.dropdown-add-button:active {
    transform: translateY(0);
}

.dropdown-add-icon {
    width: 16px;
    height: 16px;
}

.dropdown-empty {
    padding: 24px 16px;
    text-align: center;
    color: #6B7280;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.dropdown-empty-icon {
    width: 48px;
    height: 48px;
    color: #D1D5DB;
    flex-shrink: 0;
}

.dropdown-loading {
    padding: 24px 16px;
    text-align: center;
    color: #6B7280;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.dropdown-loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #E5E7EB;
    border-top: 2px solid #4F46E5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Form validation states */
.form-group.error .dropdown-trigger {
    border-color: #EF4444;
    background: rgba(254, 242, 242, 0.9);
}

.form-group.success .dropdown-trigger {
    border-color: #10B981;
    background: rgba(236, 253, 245, 0.9);
}

/* Mobile responsive */
@media (max-width: 640px) {
    .dropdown-menu {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
        margin-top: 0;
        transform: translateY(100%);
    }
    
    .dropdown-menu.open {
        transform: translateY(0);
    }
    
    .dropdown-option {
        padding: 16px;
    }
    
    .dropdown-search {
        padding: 16px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .dropdown-trigger {
        background: rgba(17, 24, 39, 0.9);
        border-color: rgba(79, 70, 229, 0.3);
        color: #F9FAFB;
    }
    
    .dropdown-trigger:hover {
        background: rgba(17, 24, 39, 0.95);
    }
    
    .dropdown-trigger.active {
        background: rgba(17, 24, 39, 1);
    }
    
    .dropdown-menu {
        background: rgba(17, 24, 39, 0.95);
        border-color: rgba(79, 70, 229, 0.3);
    }
    
    .dropdown-search-input {
        background: rgba(31, 41, 55, 0.8);
        border-color: rgba(75, 85, 99, 0.5);
        color: #F9FAFB;
    }
    
    .dropdown-search-input:focus {
        background: rgba(31, 41, 55, 1);
    }
    
    .dropdown-option-name {
        color: #F9FAFB;
    }
    
    .dropdown-option-meta {
        color: #9CA3AF;
    }
}

/* Animation enhancements */
.dropdown-option {
    position: relative;
    overflow: hidden;
}

.dropdown-option::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(79, 70, 229, 0.1), transparent);
    transition: left 0.5s ease;
}

.dropdown-option:hover::before {
    left: 100%;
}

/* Focus states for accessibility */
.dropdown-trigger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.3);
}

.dropdown-option:focus-visible {
    outline: none;
    background: rgba(79, 70, 229, 0.1);
    border-color: rgba(79, 70, 229, 0.2);
}

/* Inline form styles */
.dropdown-inline-form {
    padding: 16px;
    background: rgba(249, 250, 251, 0.9);
    border-radius: 8px;
    margin: 8px;
}

.inline-form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-weight: 600;
    color: #374151;
    font-size: 14px;
}

.inline-form-cancel {
    background: none;
    border: none;
    font-size: 18px;
    color: #6B7280;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.inline-form-cancel:hover {
    background: rgba(156, 163, 175, 0.2);
    color: #374151;
}

.inline-form-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inline-form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.inline-form-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid rgba(209, 213, 219, 0.8);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    color: #374151;
    transition: all 0.2s ease;
}

.inline-form-input:focus {
    outline: none;
    border-color: #4F46E5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.inline-form-input::placeholder {
    color: #9CA3AF;
}

.inline-form-select {
    padding: 8px 12px;
    border: 1px solid rgba(209, 213, 219, 0.8);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.inline-form-select:focus {
    outline: none;
    border-color: #4F46E5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.inline-form-save {
    background: #10B981;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.inline-form-save:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.inline-form-save:active {
    transform: translateY(0);
}

.inline-form-error {
    display: none;
    color: #EF4444;
    font-size: 12px;
    margin-top: 4px;
    padding: 4px 8px;
    background: rgba(254, 242, 242, 0.8);
    border-radius: 4px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.inline-form-success {
    display: none;
    color: #10B981;
    font-size: 12px;
    margin-top: 4px;
    padding: 4px 8px;
    background: rgba(236, 253, 245, 0.8);
    border-radius: 4px;
    border: 1px solid rgba(16, 185, 129, 0.2);
}