/**
 * Unified Dropdown System CSS
 * 
 * Standardized styles for all dropdown types that work consistently
 * across different contexts (modals, filters, forms, etc.)
 */

/* Base dropdown container */
.unified-dropdown {
    position: relative;
    display: inline-block;
    width: 100%;
    font-family: inherit;
}

/* Dropdown trigger button */
.unified-dropdown .dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 1rem;
    background-color: var(--background-panel);
    border: 1px solid var(--border-color-dark);
    border-radius: 37px;
    color: var(--text-primary-dark);
    font-size: 0.95rem;
    cursor: pointer;
    text-align: center;
    user-select: none;
}

.unified-dropdown .dropdown-trigger:hover {
    border-color: var(--hover-border);
    background-color: var(--hover-bg);
}

.unified-dropdown .dropdown-trigger:focus {
    outline: none;
    border-color: var(--hover-border);
    background-color: var(--hover-bg);
}

.unified-dropdown[aria-expanded="true"] .dropdown-trigger {
    border-color: var(--hover-border);
    background-color: var(--hover-bg);
}

/* Dropdown value text */
.unified-dropdown .dropdown-value {
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 1.2em;
}

.unified-dropdown .dropdown-value.placeholder {
    color: var(--text-secondary-dark, #a0aec0);
    font-style: italic;
}

/* Dropdown icon */
.unified-dropdown .dropdown-icon {
    display: flex;
    align-items: center;
    margin-left: 0.5rem;
    flex-shrink: 0;
    color: var(--text-primary-dark);
}

.unified-dropdown .dropdown-icon svg {
    stroke: currentColor;
    width: 12px;
    height: 12px;
}

.unified-dropdown[aria-expanded="true"] .dropdown-icon {
    transform: rotate(180deg);
}

/* Dropdown panel */
.unified-dropdown .dropdown-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--background-panel);
    border: 1px solid var(--border-color-dark);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    padding: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.unified-dropdown.dropdown-open .dropdown-panel {
    opacity: 1;
    pointer-events: auto;
}

/* Search input */
.unified-dropdown .dropdown-search {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color-dark, #4a5568);
    flex-shrink: 0;
}

.unified-dropdown .dropdown-search input {
    width: 100%;
    padding: 0.5rem;
    background: var(--input-background-dark);
    border: 1px solid var(--border-color-dark, #4a5568);
    border-radius: 6px;
    color: var(--text-primary-dark, #e2e8f0);
    font-size: 0.9rem;
    outline: none;
}

.unified-dropdown .dropdown-search input:focus {
    border-color: var(--primary-button, #85c6f6);
    box-shadow: 0 0 0 2px var(--primary-light, rgba(133, 198, 246, 0.2));
}

.unified-dropdown .dropdown-search input::placeholder {
    color: var(--text-secondary-dark, #a0aec0);
}

/* Dropdown items container */
.unified-dropdown .dropdown-items {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* Individual dropdown items */
.unified-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    margin-top: 0;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary-dark);
    font-size: 0.9rem;
    line-height: 1.4;
    user-select: none;
    justify-content: space-between;
}

.unified-dropdown .dropdown-item:hover {
    background: var(--hover-bg);
}

.unified-dropdown .dropdown-item.keyboard-focus {
    background: var(--primary-light, rgba(133, 198, 246, 0.2));
    outline: 2px solid var(--primary-button, #85c6f6);
    outline-offset: -2px;
}

/* Hide actual inputs - we'll style them with CSS */
.unified-dropdown .dropdown-item input[type="checkbox"],
.unified-dropdown .dropdown-item input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
}

/* Custom checkbox styling - only for multi-select dropdowns */
.unified-dropdown .dropdown-item.checkbox-item::before {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color-light, #718096);
    background: transparent;
    border-radius: 3px;
    flex-shrink: 0;
    position: relative;
    display: block;
}

/* Single-select dropdowns should not have radio buttons - selection shown by highlighting only */

/* Checked state for checkboxes only */
.unified-dropdown .dropdown-item.checkbox-item input[type="checkbox"]:checked + span::before,
.unified-dropdown .dropdown-item.checkbox-item:has(input[type="checkbox"]:checked)::before {
    background: var(--primary-button, #85c6f6);
    border-color: var(--primary-button, #85c6f6);
}

/* Checkmark for checkboxes */
.unified-dropdown .dropdown-item.checkbox-item input[type="checkbox"]:checked + span::after,
.unified-dropdown .dropdown-item.checkbox-item:has(input[type="checkbox"]:checked)::after {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 8px;
    border: solid var(--background-panel, #2d3748);
    border-width: 0 2px 2px 0;
    transform: translateY(-60%) rotate(45deg);
}

/* No radio button dots for single-select dropdowns */
.unified-dropdown .dropdown-item.radio-item::before {
    display: none;
}

.unified-dropdown .dropdown-item.radio-item::after {
    display: none;
}

/* Override any conflicting checkbox styles */
.unified-dropdown .dropdown-item input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
    pointer-events: none;
}

.unified-dropdown .dropdown-item input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
    pointer-events: none;
}

/* Selected item styling - only for single-select dropdowns */
.unified-dropdown .dropdown-item.radio-item:has(input:checked) {
    background: var(--primary-light, rgba(133, 198, 246, 0.1));
    color: var(--text-primary-dark, #e2e8f0);
}

/* Prevent old checkbox styles from interfering */
.unified-dropdown .dropdown-item .checkbox-custom {
    display: none;
}

.unified-dropdown .dropdown-item .checkbox-label {
    display: none;
}

/* Ensure proper spacing for checkbox items */
.unified-dropdown .dropdown-item.checkbox-item {
    gap: 0.75rem;
    align-items: center;
}

.unified-dropdown .dropdown-item.radio-item {
    gap: 0.75rem;
    align-items: center;
}

/* Item text */
.unified-dropdown .dropdown-item span {
    flex: 1;
    margin-left: 0.25rem;
}

/* Disabled state */
.unified-dropdown.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.unified-dropdown.disabled .dropdown-trigger {
    cursor: not-allowed;
    background: var(--disabled-bg, rgba(255, 255, 255, 0.02));
}

/* Size variants */
.unified-dropdown.dropdown-sm .dropdown-trigger {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.unified-dropdown.dropdown-lg .dropdown-trigger {
    padding: 1rem 1.25rem;
    font-size: 1.1rem;
}

/* Width variants */
.unified-dropdown.dropdown-auto {
    width: auto;
    min-width: 200px;
}

.unified-dropdown.dropdown-full {
    width: 100%;
}

.unified-dropdown.dropdown-half {
    width: 50%;
}

/* Modal-specific adjustments */
.modal .unified-dropdown .dropdown-panel {
    z-index: 9999; /* Higher than modal z-index */
}

/* Form-specific adjustments */
.form-group .unified-dropdown {
    margin-bottom: 0;
    display: block;
    margin-top: 0.5rem;
}

/* Filter-specific adjustments */
.filter-grid .unified-dropdown .dropdown-panel {
    z-index: 100; /* Above filter content but below modals */
}

.geographic-section .unified-dropdown .dropdown-item {
    padding: 0.75rem 1rem; /* match default spacing */
}

/* Settings-specific adjustments */
.settings-content .form-group .unified-dropdown {
    display: block;
    margin-top: 0.75rem;
    margin-bottom: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .unified-dropdown .dropdown-panel {
        max-height: 250px;
    }
    
    .unified-dropdown .dropdown-trigger {
        padding: 0.625rem 0.875rem;
        font-size: 0.9rem;
    }
    
    .unified-dropdown .dropdown-item {
        padding: 0.625rem;
        font-size: 0.9rem;
    }
}

/* Loading state */
.unified-dropdown.loading .dropdown-trigger {
    opacity: 0.7;
    cursor: wait;
}

.unified-dropdown.loading .dropdown-icon::after {
    content: '⟳';
    animation: spin 1s linear infinite;
}

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

/* Error state */
.unified-dropdown.error .dropdown-trigger {
    border-color: var(--error-color, #f56565);
    background: rgba(245, 101, 101, 0.1);
}

/* Success state */
.unified-dropdown.success .dropdown-trigger {
    border-color: var(--success-color, #48bb78);
    background: rgba(72, 187, 120, 0.1);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .unified-dropdown .dropdown-trigger {
        border-width: 2px;
    }
    
    .unified-dropdown .dropdown-item::before {
        border-width: 3px;
    }
}

/* Reduce motion support */
@media (prefers-reduced-motion: reduce) {
    .unified-dropdown .dropdown-trigger,
    .unified-dropdown .dropdown-panel,
    .unified-dropdown .dropdown-icon,
    .unified-dropdown .dropdown-item {
        transition: none;
    }
}

/* Force disable all transitions for unified dropdowns */
.unified-dropdown,
.unified-dropdown *,
.unified-dropdown .dropdown-trigger,
.unified-dropdown .dropdown-panel,
.unified-dropdown .dropdown-icon,
.unified-dropdown .dropdown-item,
.unified-dropdown .dropdown-value,
.unified-dropdown .dropdown-items {
    transition: none !important;
    animation: none !important;
    transform: none !important;
}

/* Ensure dropdown panel appears instantly */
.unified-dropdown .dropdown-panel {
    transform: none !important;
}

.unified-dropdown.dropdown-open .dropdown-panel {
    transform: none !important;
}