/* Filter Popup Module CSS */
/* Based on existing modal design patterns */

.filter-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.filter-popup-overlay.show {
    opacity: 1;
    visibility: visible;
}

.filter-popup {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.filter-popup-overlay.show .filter-popup {
    transform: scale(1);
}

.filter-popup-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8f9fa;
}

.filter-popup-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1976d2;
}

.filter-popup-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.filter-popup-close:hover {
    background-color: #f0f0f0;
    color: #333;
}

.filter-popup-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.filter-popup-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: #f8f9fa;
}

/* Filter Groups */
.filter-group {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    margin-bottom: 16px;
    background: #fdfdfd;
}

.filter-group-header {
    padding: 12px 16px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.filter-group-combination {
    display: flex;
    align-items: center;
    gap: 8px;
}

.combination-toggle {
    background: #1976d2;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    min-width: 45px;
}

.combination-toggle:hover {
    background: #1565c0;
}

.combination-toggle.or-mode {
    background: #ff9800;
}

.combination-toggle.or-mode:hover {
    background: #f57c00;
}

.filter-group-actions {
    display: flex;
    gap: 8px;
}

.add-condition-btn, .remove-group-btn {
    background: none;
    border: 1px solid #ddd;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.add-condition-btn:hover {
    background: #e3f2fd;
    border-color: #1976d2;
    color: #1976d2;
}

.remove-group-btn:hover {
    background: #ffebee;
    border-color: #d32f2f;
    color: #d32f2f;
}

.filter-group-body {
    padding: 16px;
}

/* Filter Conditions */
.filter-condition {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 12px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    position: relative;
}

.filter-condition:last-child {
    margin-bottom: 0;
}

.filter-field {
    min-width: 180px;
}

.filter-operator {
    min-width: 120px;
}

.filter-value {
    flex: 1;
    min-width: 120px;
}

.filter-condition select, .filter-condition input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.filter-condition select:focus, .filter-condition input:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

.remove-condition-btn {
    background: none;
    border: none;
    color: #d32f2f;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.remove-condition-btn:hover {
    background: #ffebee;
}

/* Add Group Button */
.add-group-section {
    text-align: center;
    margin-top: 20px;
}

.add-group-btn {
    background: #f5f5f5;
    border: 2px dashed #ddd;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    color: #666;
    font-size: 14px;
    transition: all 0.2s ease;
}

.add-group-btn:hover {
    background: #e3f2fd;
    border-color: #1976d2;
    color: #1976d2;
}

/* Group Combination Selector */
.group-combination-section {
    margin-bottom: 20px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #1976d2;
}

.group-combination-label {
    font-size: 13px;
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
    display: block;
}

.group-combination-selector {
    display: flex;
    gap: 8px;
}

/* Preview Section */
.filter-preview {
    margin-top: 16px;
    padding: 12px;
    background: #f0f7ff;
    border: 1px solid #bbdefb;
    border-radius: 4px;
    font-size: 13px;
}

.filter-preview-label {
    font-weight: 500;
    color: #1976d2;
    margin-bottom: 4px;
}

.filter-preview-count {
    color: #333;
}

/* Active Filter Indicator */
.filter-indicator {
    background: #1976d2;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.filter-indicator:hover {
    background: #1565c0;
}

.filter-indicator .close-btn {
    margin-left: 6px;
    font-weight: bold;
    cursor: pointer;
}

/* Force proper positioning */
.dropdown-toggle {
    position: relative !important;
    z-index: 1;
    min-width: 180px;
}

/* Dropdown z-index fixes for filter popup */
.filter-popup .dropdown-menu {
    z-index: 1090 !important;
    position: absolute !important;
    transform: none !important;
    will-change: auto !important;
}

.filter-popup .dropdown {
    position: relative !important;
    overflow: visible !important;
}

.filter-popup .dropdown-menu.show {
    z-index: 1090 !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Ensure filter popup modal doesn't clip dropdowns */
.filter-popup {
    overflow: visible !important;
}

.filter-popup-body {
    overflow: visible !important;
}

.filter-group {
    overflow: visible !important;
}

.filter-condition {
    overflow: visible !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .filter-popup {
        width: 95%;
        max-height: 90vh;
    }
    
    .filter-condition {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .filter-field, .filter-operator, .filter-value {
        min-width: unset;
    }
    
    .remove-condition-btn {
        position: absolute;
        top: 8px;
        right: 8px;
    }
}

/* Loading State */
.filter-loading {
    text-align: center;
    padding: 20px;
    color: #666;
}

.filter-loading i {
    font-size: 16px;
    margin-right: 8px;
}

/* Error State */
.filter-error {
    color: #d32f2f;
    font-size: 12px;
    margin-top: 4px;
}

/* Field Search */
.field-search {
    position: relative;
    margin-bottom: 8px;
}

.field-search input {
    padding-right: 30px;
}

.field-search .search-icon {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    font-size: 12px;
}

/* Custom Dropdown Styling */
.filter-dropdown {
    position: relative;
    display: inline-block;
    min-width: 180px;
}

.filter-dropdown select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23666' d='M0 0h12L6 8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

/* Field Selector Button Styling */
.field-selector-btn {
    width: 100% !important;
    text-align: left !important;
    justify-content: space-between !important;
    display: flex !important;
    align-items: center !important;
}

.field-selector-btn .field-selector-text {
    text-align: left;
    flex: 1;
}

.field-selector-btn::after {
    margin-left: auto !important;
    margin-right: 0 !important;
}