/**
 * 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 - compact default for settings/filters/modals */
.unified-dropdown .dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 5px;
    margin-bottom: 0;
    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;
}

/* Onboarding screens: larger pill-style dropdown trigger */
.onboarding-wrapper .unified-dropdown .dropdown-trigger {
    padding: 8px 16px;
    margin-bottom: 45px;
}

.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;
    margin: 10px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 1.2em;
}

/* Dropdown value when showing pills */
.unified-dropdown .dropdown-value.has-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    justify-content: flex-start;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
}

.unified-dropdown .dropdown-value.placeholder {
    color: var(--text-secondary-dark, #a0aec0);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
    font-style: normal;
}

/* Pills for selected region/country labels */
.unified-dropdown .dropdown-pill {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
    color: rgba(35, 38, 43, 1);
    background-color: rgba(171, 171, 171, 1);
    border: none;
    border-radius: 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* 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 - active #5353ED */
.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: #5353ED;
    border-color: #5353ED;
}

/* Checkmark for checkboxes - single checkmark on label only (no span::after to avoid duplicate) */
.unified-dropdown .dropdown-item.checkbox-item input[type="checkbox"]:checked + span::after {
    content: none !important;
    display: none !important;
    visibility: hidden !important;
}

.unified-dropdown .dropdown-item.checkbox-item:has(input[type="checkbox"]:checked)::after {
    content: '';
    position: absolute;
    left: 25px;
    top: 50%;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -50%) rotate(45deg);
    z-index: 1;
}

/* 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 - position relative for checkmark placement */
.unified-dropdown .dropdown-item.checkbox-item {
    gap: 0.75rem;
    align-items: center;
    position: relative;
}

/* Dropdown item labels: no top margin (override .welcome-left label when inside dropdown panel) */
.unified-dropdown label.dropdown-item.checkbox-item {
    margin-top: 0;
}

.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;
    font-weight: 400;
}

/* 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 */
}

/* Compact list style: same spacing and appearance as country select items (dropdown-item-indent) */
.unified-dropdown.dropdown-list-compact .dropdown-item {
    margin-top: 0;
    padding: 0.3rem 1rem;
    border-radius: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.875rem;
}

.unified-dropdown.dropdown-list-compact .dropdown-item:last-child {
    border-bottom: none;
}

.unified-dropdown.dropdown-list-compact .dropdown-item.checkbox-item:has(input[type="checkbox"]:checked)::after {
    left: 25px;
}

/* Tiered / grouped dropdown (e.g. regions and countries) */
.unified-dropdown .dropdown-group {
    margin-bottom: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 14px;
}

.unified-dropdown .dropdown-group:last-child {
    border-bottom: none;
}

.unified-dropdown .dropdown-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem 0.4rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary-dark);
    background: rgba(255, 255, 255, 0.03);
    user-select: none;
}

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

/* Expand/collapse button - right side */
.unified-dropdown .region-expand-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--text-primary-dark);
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    margin-left: auto;
}

.unified-dropdown .region-expand-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Caret points down when closed, rotates to point up when opened */
.unified-dropdown .region-expand-toggle .expand-icon {
    transition: transform 0.2s ease;
    width: 16px;
    height: 16px;
}

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

/* Region header label wrapper - exclude from checkbox-item checkmark styling */
.unified-dropdown .dropdown-group-header label.dropdown-group-header-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    cursor: pointer;
    margin: 0;
}

/* No checkmark or custom checkbox box on region header - use native checkbox only */
.unified-dropdown .dropdown-group-header-label::before,
.unified-dropdown .dropdown-group-header-label::after,
.unified-dropdown .dropdown-group-header-label span::before,
.unified-dropdown .dropdown-group-header-label span::after {
    display: none !important;
}

/* Region toggle: transparent background - strip native appearance so background applies */
.unified-dropdown .dropdown-group-header .dropdown-region-toggle {
    margin: 0;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-button, #5353ED);
    -webkit-appearance: none;
    appearance: none;
    background-color: transparent !important;
    background: transparent !important;
    border: 2px solid var(--border-color-light, rgba(255, 255, 255, 0.4));
    border-radius: 3px;
}

.unified-dropdown .dropdown-group-header .dropdown-region-toggle:not(:checked) {
    background-color: transparent !important;
    background: transparent !important;
}

.unified-dropdown .dropdown-group-header .dropdown-region-toggle:checked {
    background-color: #5353ED !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") !important;
    background-size: 14px 14px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    border-color: #5353ED !important;
}

/* Indeterminate: some (not all) child countries selected - white hyphen on purple */
.unified-dropdown .dropdown-group-header .dropdown-region-toggle:indeterminate {
    background-color: #5353ED !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='6' y1='12' x2='18' y2='12'/%3E%3C/svg%3E") !important;
    background-size: 14px 14px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    border-color: #5353ED !important;
}

.unified-dropdown .dropdown-group-label {
    flex: 1;
    font-weight: 400;
}

/* Countries container - collapsible */
.unified-dropdown .dropdown-group-countries {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.unified-dropdown .dropdown-group-countries.expanded {
    max-height: 2000px; /* Large enough for any region */
}

/* Nested country rows: indent under region and tighter list spacing */
.unified-dropdown .dropdown-item-indent {
    padding: 0.3rem 1rem 0.3rem 2.75rem;
    margin-top: 0 !important;
    margin-bottom: 0;
    margin-left: 0.75rem;
    font-size: 0.875rem;
    border-radius: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* Ensure label elements with dropdown-item-indent have no top margin */
.unified-dropdown label.dropdown-item-indent {
    margin-top: 0 !important;
}

.unified-dropdown .dropdown-group .dropdown-item-indent:last-child {
    border-bottom: none;
}

/* Checkmark alignment for indented items */
.unified-dropdown .dropdown-item-indent.checkbox-item:has(input[type="checkbox"]:checked)::after {
    left: calc(2.75rem - 19px);
}

/* Settings-specific adjustments - dropdowns full width within wrapper */
.settings-content .form-group .unified-dropdown {
    display: block;
    width: 100%;
    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;
}

/* Allow expand/collapse caret to rotate (override force-disable above) */
.unified-dropdown .region-expand-toggle .expand-icon {
    transition: transform 0.2s ease !important;
    animation: none !important;
}

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

/* Restore checkmark on country items (override force-disable transform) */
.unified-dropdown .dropdown-item.checkbox-item:has(input[type="checkbox"]:checked)::after,
.unified-dropdown .dropdown-item-indent.checkbox-item:has(input[type="checkbox"]:checked)::after {
    transform: translate(-50%, -50%) rotate(45deg) !important;
}

/* Light mode: dropdown pill background for select box pills */
[data-theme="light"] .unified-dropdown .dropdown-pill {
    background-color: rgba(230, 230, 235, 1);
}