/**
 * FilterDropdown Component Styles
 * Self-contained styles for the FilterDropdown component
 * Matches FilterItemSelector patterns for consistency
 */

/* FilterDropdown inherits filter-group from filter-item-selector.css */
/* This file only contains dropdown-specific styles */

/* Dropdown Wrapper */
.filter-dropdown-wrapper {
    position: relative;
    width: 100%;
}

/* Ensure FilterDropdown trigger has proper styling in all contexts */
#certificatesPopup .filter-dropdown-trigger,
#uploadPopup .filter-dropdown-trigger,
#pcbUploadPopup .filter-dropdown-trigger,
#generateKeyModal .filter-dropdown-trigger,
#parameterModal .filter-dropdown-trigger,
.filter-dropdown-trigger {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 8px 12px !important;
    border: 1px solid #dddfe0 !important; /* Full border like other dropdowns */
    border-radius: 8px !important; /* All 4 corners rounded like other dropdowns */
    background: white !important; /* Ensure solid white background */
    cursor: pointer !important;
    transition: border-color 0.2s ease !important;
    position: relative !important;
    min-height: 32px !important;
    user-select: none !important;
    margin: 0 !important; /* Remove any margin that might affect appearance */
    font-size: 11px !important; /* Match FilterItemSelector font-size */
    color: #4a5568 !important; /* Match FilterItemSelector color */
}

/* Dropdown Trigger - Base styles (already defined above with #certificatesPopup specificity) */

/* Hover and focus states - ensure they work in all contexts */
#certificatesPopup .filter-dropdown-trigger:hover,
#uploadPopup .filter-dropdown-trigger:hover,
#pcbUploadPopup .filter-dropdown-trigger:hover,
#generateKeyModal .filter-dropdown-trigger:hover,
#parameterModal .filter-dropdown-trigger:hover,
.filter-dropdown-trigger:hover {
    border-color: #2d8998 !important; /* Full border color change on hover */
}

#certificatesPopup .filter-dropdown-wrapper.open .filter-dropdown-trigger,
#uploadPopup .filter-dropdown-wrapper.open .filter-dropdown-trigger,
#pcbUploadPopup .filter-dropdown-wrapper.open .filter-dropdown-trigger,
#generateKeyModal .filter-dropdown-wrapper.open .filter-dropdown-trigger,
#parameterModal .filter-dropdown-wrapper.open .filter-dropdown-trigger,
.filter-dropdown-wrapper.open .filter-dropdown-trigger {
    border-color: #2d8998 !important; /* Full border color when open */
}

#certificatesPopup .filter-dropdown-trigger:focus-within,
#uploadPopup .filter-dropdown-trigger:focus-within,
#pcbUploadPopup .filter-dropdown-trigger:focus-within,
#generateKeyModal .filter-dropdown-trigger:focus-within,
#parameterModal .filter-dropdown-trigger:focus-within,
.filter-dropdown-trigger:focus-within {
    box-shadow: none !important;
    border-color: #2d8998 !important;
    outline: none !important;
}

/* Dropdown Text (legacy - keeping for backwards compatibility) */
.filter-dropdown-text {
    flex: 1 !important;
    font-size: 11px !important; /* Match FilterItemSelector font-size */
    line-height: 1.4 !important; /* Match FilterItemSelector line-height */
    color: #4a5568 !important; /* Match FilterItemSelector color */
    text-align: left !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Placeholder state */
.filter-dropdown-text.placeholder {
    color: #9ca3af;
}

/* Dropdown Input (new - replaces text for filtering) */
.filter-dropdown-input {
    flex: 1 !important;
    font-size: 11px !important; /* Match FilterItemSelector font-size */
    line-height: 1.4 !important; /* Match FilterItemSelector line-height */
    color: #4a5568 !important; /* Match FilterItemSelector color */
    border: none !important;
    outline: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    font-family: inherit !important;
    box-shadow: none !important;
}

.filter-dropdown-input:focus {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
}

.filter-dropdown-input::placeholder {
    color: #9ca3af;
    opacity: 1;
}

/* Dropdown Arrow */
.filter-dropdown-arrow {
    font-size: 10px !important;
    color: #4a5568 !important;
    margin-left: 8px !important;
    transition: transform 0.2s ease !important;
    flex-shrink: 0 !important;
}

.filter-dropdown-wrapper.open .filter-dropdown-arrow {
    transform: rotate(180deg);
}

/* Clear Button in Trigger */
.filter-dropdown-trigger .filter-clear-x {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 18px;
    height: 18px;
    border-radius: 3px;
    background: transparent;
    border: none;
    color: #6b7280;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-left: 8px;
    margin-right: 4px;
    z-index: 1;
}

.filter-dropdown-trigger .filter-clear-x:hover {
    background: #e6f4fa;
    color: #3d7b8f;
}

/* Dropdown List */
#certificatesPopup .filter-dropdown-list,
#uploadPopup .filter-dropdown-list,
#pcbUploadPopup .filter-dropdown-list,
#generateKeyModal .filter-dropdown-list,
#parameterModal .filter-dropdown-list,
.filter-dropdown-list {
    position: fixed !important; /* Use fixed positioning to escape container constraints */
    background: white !important; /* Ensure solid white background */
    border: 1px solid #dddfe0 !important; /* Match theme border color */
    border-radius: 0 0 8px 8px !important; /* Rounded bottom corners */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
    max-height: 200px !important;
    overflow-y: auto !important;
    z-index: 10000 !important; /* High z-index to overlay all other components */
    display: none !important;
    width: auto !important; /* Width will be set dynamically by JavaScript to match trigger */
    box-sizing: border-box !important; /* Include border in width calculation */
    /* Optimize for smooth position updates during scroll */
    will-change: top, left !important; /* Hint browser to optimize for position changes */
    backface-visibility: hidden !important; /* Prevent flickering during updates */
}

#certificatesPopup .filter-dropdown-list.open,
#uploadPopup .filter-dropdown-list.open,
#pcbUploadPopup .filter-dropdown-list.open,
#generateKeyModal .filter-dropdown-list.open,
#parameterModal .filter-dropdown-list.open,
.filter-dropdown-list.open {
    display: block !important;
}

/* Custom scrollbar for dropdown list */
.filter-dropdown-list::-webkit-scrollbar {
    width: 8px;
}

.filter-dropdown-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.filter-dropdown-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.filter-dropdown-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Dropdown Options */
.filter-dropdown-option {
    padding: 8px 12px !important;
    font-size: 11px !important; /* Match FilterItemSelector font-size */
    line-height: 1.4 !important; /* Match FilterItemSelector line-height */
    color: #4a5568 !important; /* Match FilterItemSelector color */
    cursor: pointer !important;
    transition: background 0.15s, color 0.15s !important;
    border-radius: 0 !important;
    user-select: none !important;
}

.filter-dropdown-option:first-child {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.filter-dropdown-option:last-child {
    border-bottom-left-radius: 8px; /* Rounded bottom corners */
    border-bottom-right-radius: 8px; /* Rounded bottom corners */
}

.filter-dropdown-option:hover {
    background: #f3f4f6 !important; /* Match FilterItemSelector hover */
}

.filter-dropdown-option.selected {
    background: #f0f7ff !important; /* Match FilterItemSelector selected background */
    color: black !important; /* Match FilterItemSelector selected color */
    font-weight: 500 !important; /* Match FilterItemSelector selected font-weight */
}

.filter-dropdown-option.selected:hover {
    background: #cbd5df !important; /* Match FilterItemSelector selected hover */
}

.filter-dropdown-option.highlighted {
    background: #e5f4fa !important; /* Lighter highlight for keyboard navigation */
    color: #2d8998 !important;
}

.filter-dropdown-option.highlighted.selected {
    background: #cbd5df !important; /* Highlighted + selected state */
}

/* No results message */
.filter-dropdown-option.filter-dropdown-no-results {
    color: #9ca3af !important;
    font-style: italic;
    cursor: default !important;
    background: transparent !important;
}

.filter-dropdown-option.filter-dropdown-no-results:hover {
    background: transparent !important;
}

/* Disabled option styling */
.filter-dropdown-option.disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    color: #9ca3af !important;
    pointer-events: none !important;
}

.filter-dropdown-option.disabled:hover {
    background: transparent !important;
}

/* Group header styling (parent/category items) */
.filter-dropdown-option.filter-dropdown-group {
    font-weight: 600;
    color: #0ea5e9;
    background: rgba(14, 165, 233, 0.08);
    border-left: 3px solid #0ea5e9;
    padding-left: 9px; /* 12px - 3px border */
}

.filter-dropdown-option.filter-dropdown-group:hover {
    background: rgba(14, 165, 233, 0.15);
}

.filter-dropdown-option.filter-dropdown-group.selected {
    background: rgba(14, 165, 233, 0.2);
    color: #0ea5e9;
}

/* ==================== DARK MODE ==================== */
@media (prefers-color-scheme: dark) {
    .filter-dropdown-trigger {
        background: #1a1d20 !important;
        color: #e5e7eb;
        border-color: rgba(255, 255, 255, 0.12) !important; /* Full border in dark mode */
    }
    
    .filter-dropdown-trigger:hover,
    .filter-dropdown-wrapper.open .filter-dropdown-trigger {
        border-color: #2d8998 !important; /* Full border color change */
    }
    
    .filter-dropdown-trigger:focus-within {
        box-shadow: none !important;
        border-color: #2d8998 !important;
    }
    
    .filter-dropdown-text {
        color: #9ca3af;
    }
    
    .filter-dropdown-text.placeholder {
        color: #6b7280;
    }
    
    .filter-dropdown-arrow {
        color: #9ca3af;
    }
    
    .filter-dropdown-trigger .filter-clear-x {
        color: #8b95a0;
        background: transparent;
    }
    
    .filter-dropdown-trigger .filter-clear-x:hover {
        background: #374151;
        color: #e5e7eb;
    }
    
    .filter-dropdown-list {
        background: #1a1d20 !important;
        border-color: rgba(255, 255, 255, 0.12);
    }
    
    .filter-dropdown-list::-webkit-scrollbar-track {
        background: #0f1113;
    }
    
    .filter-dropdown-list::-webkit-scrollbar-thumb {
        background: #3a3d40;
    }
    
    .filter-dropdown-list::-webkit-scrollbar-thumb:hover {
        background: #4a4d50;
    }
    
    .filter-dropdown-option {
        color: #9ca3af;
    }
    
    .filter-dropdown-option:hover {
        background: #2a2d30;
    }
    
    .filter-dropdown-option.selected {
        background: #2d8998;
        color: white;
        border-left-color: #4fb3c5;
    }
    
    .filter-dropdown-option.selected:hover {
        background: #3a9faf;
    }
    
    .filter-dropdown-input {
        color: #9ca3af;
    }
    
    .filter-dropdown-input::placeholder {
        color: #6b7280;
    }
    
    .filter-dropdown-option.highlighted {
        background: #2a3f47 !important;
        color: #4fb3c5 !important;
    }
    
    .filter-dropdown-option.highlighted.selected {
        background: #3a9faf !important;
    }
    
    .filter-dropdown-option.filter-dropdown-no-results {
        color: #6b7280 !important;
    }
    
    /* Group header styling in dark mode */
    .filter-dropdown-option.filter-dropdown-group {
        color: #38bdf8;
        background: rgba(56, 189, 248, 0.1);
        border-left-color: #38bdf8;
    }
    
    .filter-dropdown-option.filter-dropdown-group:hover {
        background: rgba(56, 189, 248, 0.18);
    }
    
    .filter-dropdown-option.filter-dropdown-group.selected {
        background: rgba(56, 189, 248, 0.25);
        color: #38bdf8;
    }
}

/* Inline Layout - Label and dropdown in same row */
.filter-group-inline {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
}

.filter-group-inline .filter-label-row {
    margin-bottom: 0;
    flex-shrink: 0;
}

.filter-group-inline .filter-label-row label {
    margin-bottom: 0;
    white-space: nowrap;
}

.filter-group-inline > div:last-child {
    flex-grow: 1;
}
