/* Filter Sidebar Styles */
.filter-sidebar {
    position: sticky;
    top: 20px;
    width: 250px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    z-index: 1;
}


.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e5e7eb;
}

.filter-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin: 0;
}

.clear-filter-icon {
    background: none;
    border: none;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    color: #666;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    outline: none;
    box-shadow: none;
}

.clear-filter-icon:focus {
    outline: none;
    box-shadow: none;
}

.clear-filter-icon:hover {
    background-color: #f8f9fa;
    color: #dc3545;
    transform: scale(1.1);
}

.clear-filter-icon svg {
    width: 20px;
    height: 20px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-label {
    display: block;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
    font-size: 14px;
}

.filter-sidebar .filter-select {
    width: 100%;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background-color: #fff;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    transition: border-color 0.3s ease;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

.filter-select:focus {
    outline: none;
    border-color: #0048d8;
    box-shadow: 0 0 0 2px rgba(0, 72, 216, 0.2);
}

.filter-select:hover {
    border-color: #bbb;
}

/* Loading and error states */
.loading {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-style: italic;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 20px 0;
    position: relative;
}

.loading::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #0048d8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error {
    text-align: center;
    padding: 20px;
    color: #dc3545;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin: 10px 0;
}

/* Smooth content transition */
.grid {
    transition: all 0.3s ease-in-out;
}

/* Prevent layout shift during loading */
.filter-layout .content {
    min-height: 400px;
}




/* Integration with existing layout */
.filter-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.filter-layout .content {
    flex: 1;
    min-width: 0;
    min-height: 400px;
}

/* Ensure proper spacing */
.filter-sidebar + .content {
    margin-left: 0;
}

/* Select2 Customization */
.select2-container--default .select2-selection--single {
    height: 40px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background-color: #fff;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 38px;
    padding-left: 12px;
    padding-right: 30px; /* Tạo không gian cho nút clear */
    color: #333;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 38px;
    right: 8px;
}

/* Select2 Clear Button Styling */
.select2-container--default .select2-selection--single .select2-selection__clear {
    position: absolute;
    right: 30px; /* Đặt bên trái mũi tên dropdown */
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    color: #999;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1;
}

.select2-container--default .select2-selection--single .select2-selection__clear:hover {
    color: #dc3545;
    background-color: #f8f9fa;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Đảm bảo nút clear không bị che khuất */
.select2-container--default .select2-selection--single {
    position: relative;
}

/* Điều chỉnh cho trường hợp có placeholder */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #999;
    padding-right: 30px; /* Tạo không gian cho nút clear */
}

/* Điều chỉnh cho dropdown arrow khi có clear button */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    right: 8px;
    z-index: 2; /* Đảm bảo arrow ở trên clear button */
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #0048d8;
    box-shadow: 0 0 0 2px rgba(0, 72, 216, 0.2);
}

.select2-dropdown {
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #0048d8;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 8px 12px;
}

/* Date Range Filter Styles - Moved to critical CSS for better performance */

/* Mobile Filter Toggle Button */
.mobile-filter-toggle {
    display: none;
    position: relative;
    left:0;
    z-index: 2;
    background: #0048d8;
    border: none;
    color:#fff;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 72, 216, 0.3);
    transition: all 0.3s ease;
    align-items: center;
    gap: 8px;
}


.mobile-filter-toggle:hover {
    background: #003bb3;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 72, 216, 0.4);
}

.mobile-filter-toggle svg {
    width: 20px;
    height: 20px;
}

/* Mobile Filter Close Button */
.mobile-filter-close {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    color: #666;
    transition: all 0.3s ease;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
}

.mobile-filter-close:hover {
    background-color: #f8f9fa;
    color: #dc3545;
    transform: scale(1.1);
}

.mobile-filter-close svg {
    width: 20px;
    height: 20px;
}

/* Filter Header Actions */
.filter-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Mobile Overlay */
.mobile-filter-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-filter-overlay.active {
    opacity: 1;
}

/* Responsive Design */
@media (max-width: 600px) {
    /* Show mobile toggle button */
    .mobile-filter-toggle {
        display: flex;
    }
    
    /* Show mobile close button */
    .mobile-filter-close {
        display: flex;
    }
    
    /* Hide filter sidebar by default on mobile */
    .filter-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: white;
        z-index: 1;
        transition: left 0.3s ease;
        overflow-y: auto;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        border: none;
        border-radius: 0;
        margin: 0;
        padding: 20px;
    }
    
    /* Show sidebar when active */
    .filter-sidebar.active {
        left: 0;
    }
    
    /* Show overlay when sidebar is active */
    .mobile-filter-overlay.active {
        display: block;
    }
    
    /* Adjust content when sidebar is open */
    .filter-layout {
        flex-direction: column;
    }
    
    .filter-layout .content {
        width: 100%;
        margin-left: 0;
    }
    
    #filter-results .grid-cols-3{
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
}