/* Searchable Dropdown Styles */
.searchable-dropdown {
    position: relative;
    width: 100%;
    min-width: 0;
}

.dropdown-selection {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 8px 12px;
    background: var(--surface-primary, #ffffff);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.dropdown-selection:hover {
    border-color: var(--accent-primary, #3b82f6);
}

.dropdown-selection:focus {
    outline: none;
    border-color: var(--accent-primary, #3b82f6);
    box-shadow: 0 0 0 3px var(--accent-primary-light, rgba(59, 130, 246, 0.1));
}

.dropdown-selection.disabled {
    background: var(--surface-disabled, #f3f4f6);
    cursor: not-allowed;
    opacity: 0.6;
}

.selection-content {
    flex: 1;
    display: flex;
    align-items: center;
    min-width: 0;
}

.selection-text {
    flex: 1;
    color: var(--text-primary, #1f2937);
    font-size: 14px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selection-text:empty::after {
    content: attr(data-placeholder);
    color: var(--text-muted, #9ca3af);
}

.selection-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--text-secondary, #6b7280);
    transition: transform 0.2s ease;
}

.searchable-dropdown.open .selection-arrow {
    transform: rotate(180deg);
}

.selection-clear {
    display: none;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 8px;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.selection-clear:hover {
    background: var(--surface-secondary, #f3f4f6);
    color: var(--status-danger, #ef4444);
}

.dropdown-content {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--surface-primary, #ffffff);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    margin-top: 4px;
    max-height: 300px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.dropdown-search {
    position: relative;
    padding: 12px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    background: var(--surface-secondary, #f9fafb);
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 4px;
    font-size: 14px;
    background: var(--surface-primary, #ffffff);
    color: var(--text-primary, #1f2937);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary, #3b82f6);
    box-shadow: 0 0 0 3px var(--accent-primary-light, rgba(59, 130, 246, 0.1));
}

.search-icon {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary, #6b7280);
    pointer-events: none;
}

.dropdown-results {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.results-list {
    padding: 0;
}

.result-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light, #f3f4f6);
    transition: background-color 0.2s ease;
}

.result-item:last-child {
    border-bottom: none;
}

.result-item:hover,
.result-item.active {
    background: var(--accent-primary-light, rgba(59, 130, 246, 0.1));
}

.result-item.selected {
    background: var(--accent-primary, #3b82f6);
    color: white;
}

.result-text {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary, #1f2937);
    line-height: 1.4;
}

.result-item.selected .result-text {
    color: white;
}

.result-meta {
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
    margin-left: auto;
    padding-left: 12px;
}

.loading-message,
.no-results-message {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-secondary, #6b7280);
    font-size: 14px;
}

.loading-message i {
    margin-right: 8px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Size variants */
.searchable-dropdown.size-sm .dropdown-selection {
    min-height: 36px;
    padding: 6px 10px;
}

.searchable-dropdown.size-sm .selection-text {
    font-size: 13px;
}

.searchable-dropdown.size-lg .dropdown-selection {
    min-height: 48px;
    padding: 10px 14px;
}

.searchable-dropdown.size-lg .selection-text {
    font-size: 16px;
}

/* Error state */
.searchable-dropdown.error .dropdown-selection {
    border-color: var(--status-danger, #ef4444);
}

.searchable-dropdown.error .dropdown-selection:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Success state */
.searchable-dropdown.success .dropdown-selection {
    border-color: var(--status-success, #10b981);
}

.searchable-dropdown.success .dropdown-selection:focus {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Multi-select styles (for future enhancement) */
.searchable-dropdown.multi .selection-content {
    flex-wrap: wrap;
    gap: 4px;
    min-height: 32px;
}

.selection-tag {
    display: inline-flex;
    align-items: center;
    background: var(--accent-primary, #3b82f6);
    color: white;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 12px;
    gap: 4px;
}

.selection-tag .tag-remove {
    cursor: pointer;
    opacity: 0.8;
}

.selection-tag .tag-remove:hover {
    opacity: 1;
}

/* Responsive design */
@media (max-width: 768px) {
    .dropdown-content {
        max-height: 250px;
    }

    .dropdown-search {
        padding: 8px;
    }

    .result-item {
        padding: 12px;
    }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    :root {
        --surface-primary: #1f2937;
        --surface-secondary: #374151;
        --text-primary: #f9fafb;
        --text-secondary: #d1d5db;
        --border-color: #4b5563;
        --accent-primary: #60a5fa;
    }
}

/* Integration with existing form styles */
.form-group .searchable-dropdown {
    margin-top: 4px;
}

.form-group .searchable-dropdown .dropdown-selection {
    border-color: var(--border-color, #d1d5db);
    background: var(--surface-primary, #ffffff);
}

.form-group .searchable-dropdown .dropdown-selection:focus {
    border-color: var(--accent-primary, #3b82f6);
    box-shadow: 0 0 0 3px var(--accent-primary-light, rgba(59, 130, 246, 0.1));
}

/* Accessibility improvements */
.searchable-dropdown:focus-within .dropdown-selection {
    border-color: var(--accent-primary, #3b82f6);
    box-shadow: 0 0 0 3px var(--accent-primary-light, rgba(59, 130, 246, 0.1));
}

.result-item[aria-selected="true"] {
    background: var(--accent-primary, #3b82f6);
    color: white;
}

/* Print styles */
@media print {
    .searchable-dropdown .dropdown-content {
        display: none !important;
    }

    .searchable-dropdown .selection-arrow,
    .searchable-dropdown .selection-clear {
        display: none !important;
    }
}