/**
 * Enhanced Filter Panel Styles - Production-like Design
 * Styles for JSPanel-based filter system with widget layout
 */

/* Filter Button Enhancements */
.btn .filter-count {
    font-size: 0.7rem;
    font-weight: 600;
    min-width: 1.2rem;
    height: 1.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

/* Enhanced Filter Panel Container */
.filter-panel-enhanced {
    font-family: var(--bs-font-sans-serif);
    font-size: 0.9rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Filter Header */
.filter-header {
    /* background: linear-gradient(135deg, var(--bs-primary) 0%, var(--bs-info) 100%); */
    color: white;
    padding: 0.5rem 0.75rem;
    /* border-radius: 0.5rem; */
    /* margin: -1rem -1rem 1rem -1rem; */
    flex-shrink: 0; /* Don't shrink the header */
}

.filter-stats .badge {
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
}

/* Filter Widgets Container */
.filter-widgets-container {
    flex: 1; /* Take up most of the available space */
    overflow-y: auto;
    padding-right: 0.5rem;
    min-height: 0; /* Allow flexbox to shrink */
}

/* Responsive grid: as many widgets per row as fit, min 220px each */
.filter-widgets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
    align-items: start;
}

/* Individual Filter Widget */
.filter-widget {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    height: 230px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.filter-widget:hover {
    border-color: var(--bs-primary);
    box-shadow: 0 2px 8px rgba(var(--bs-primary-rgb), 0.12);
}

/* Widget Header */
.filter-widget-header {
    background: var(--bs-tertiary-bg, var(--bs-gray-100));
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--bs-border-color);
    border-radius: 0.5rem 0.5rem 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.4rem;
}

.filter-widget-title {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bs-body-color);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.filter-widget-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-widget-title i {
    color: var(--bs-primary);
}

.filter-widget-count {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    border-radius: 1rem;
    min-width: 2rem;
    text-align: center;
}

/* Widget Body */
.filter-widget-body {
    flex: 1;
    padding: 0.5rem 0.6rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Loading State */
.filter-widget-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-widget-loading .spinner-border {
    width: 1.5rem;
    height: 1.5rem;
}

/* Widget Content */
.filter-widget-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.filter-search-container {
    margin-bottom: 0.5rem;
}

.filter-search-container .form-control {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0.375rem;
}

.filter-options-container {
    flex: 1;
    overflow: hidden;
}

/* Filter Checkboxes */
.filter-checkboxes {
    height: 100%;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.filter-checkboxes .form-check {
    margin-bottom: 0.4rem;
    padding-left: 1.5rem;
}

.filter-checkboxes .form-check-input {
    margin-top: 0.15rem;
}

.filter-checkboxes .form-check-label {
    font-size: 0.8rem;
    line-height: 1.3;
    cursor: pointer;
    word-break: break-word;
    color: var(--bs-body-color);
}

.filter-checkboxes .form-check-label:hover {
    color: var(--bs-primary);
}

/* Custom Scrollbars for Widgets */
.filter-checkboxes::-webkit-scrollbar,
.filter-widgets-container::-webkit-scrollbar {
    width: 4px;
}

.filter-checkboxes::-webkit-scrollbar-track,
.filter-widgets-container::-webkit-scrollbar-track {
    background: var(--bs-gray-100);
    border-radius: 2px;
}

.filter-checkboxes::-webkit-scrollbar-thumb,
.filter-widgets-container::-webkit-scrollbar-thumb {
    background: var(--bs-gray-400);
    border-radius: 2px;
}

.filter-checkboxes::-webkit-scrollbar-thumb:hover,
.filter-widgets-container::-webkit-scrollbar-thumb:hover {
    background: var(--bs-gray-500);
}

/* Filter Footer */
.filter-footer {
    background: var(--bs-gray-50);
    margin: 0.5rem -1rem -1rem -1rem;
    padding: 0.75rem 1rem;
    border-radius: 0 0 0.75rem 0.75rem;
    flex-shrink: 0; /* Don't shrink the footer */
}

.filter-summary {
    color: var(--bs-secondary);
}

.filter-buttons .btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    border-radius: 0.375rem;
}

.filter-buttons .btn-sm {
    font-size: 0.75rem;
    padding: 0.35rem 0.7rem;
}

/* Responsive Grid Adjustments */
@media (max-width: 992px) {
    .filter-widget {
        height: 220px;
    }
}

@media (max-width: 768px) {
    .filter-widgets-grid {
        grid-template-columns: 1fr;
    }
    .filter-widget {
        height: 210px;
    }
    .filter-footer {
        margin: 0.75rem -0.75rem -0.75rem -0.75rem;
        padding: 0.75rem;
    }
}

/* Filter Panel Content */
.filter-panel-content {
    font-size: 0.9rem;
}

.filter-panel-content .form-label {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    color: var(--bs-body-color);
}

.filter-panel-content .form-control {
    font-size: 0.8rem;
    border-radius: 0.375rem;
}

/* Filter Groups */
.filter-group {
    border-bottom: 1px solid var(--bs-border-color);
    padding-bottom: 1rem;
}

.filter-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* Filter Options Container */
.filter-options {
    max-height: 250px;
    overflow-y: auto;
}

/* Custom Scrollbar for Filter Options */
.filter-options::-webkit-scrollbar {
    width: 6px;
}

.filter-options::-webkit-scrollbar-track {
    background: var(--bs-gray-100);
    border-radius: 3px;
}

.filter-options::-webkit-scrollbar-thumb {
    background: var(--bs-gray-400);
    border-radius: 3px;
}

.filter-options::-webkit-scrollbar-thumb:hover {
    background: var(--bs-gray-500);
}

/* Filter Checkboxes */
.filter-checkboxes {
    padding: 0.5rem 0;
}

.filter-checkboxes .form-check {
    margin-bottom: 0.3rem;
    padding-left: 1.5rem;
}

.filter-checkboxes .form-check-input {
    margin-top: 0.2rem;
}

.filter-checkboxes .form-check-label {
    font-size: 0.8rem;
    line-height: 1.3;
    cursor: pointer;
    word-break: break-word;
}

/* Filter Search Input */
.filter-search {
    margin-bottom: 0.5rem !important;
}

/* Filter Select */
.filter-select {
    font-size: 0.8rem;
}

/* JSPanel Customizations */
.jsPanel {
    font-family: var(--bs-font-sans-serif) !important;
    z-index: 9999 !important; /* Ensure panel is above everything */
}

.jsPanel-hdr {
    background: var(--bs-primary) !important;
    color: white !important;
    border-radius: 0.5rem 0.5rem 0 0 !important;
    z-index: 10000 !important; /* Header above panel content */
}

.jsPanel-hdr-title {
    font-weight: 600 !important;
    font-size: 0.9rem !important;
}

.jsPanel-content {
    border-radius: 0 0 0.5rem 0.5rem !important;
    background: var(--bs-body-bg) !important;
    z-index: 9999 !important;
}

/* Loading State */
.filter-loading .fa-spinner {
    animation: spin 1s linear infinite;
}

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

/* Filter Panel Buttons */
.filter-panel-content .btn {
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
}

.filter-panel-content .btn-primary {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

.filter-panel-content .btn-outline-secondary {
    color: var(--bs-secondary);
    border-color: var(--bs-secondary);
}

.filter-panel-content .btn-outline-secondary:hover {
    background-color: var(--bs-secondary);
    border-color: var(--bs-secondary);
    color: white;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .jsPanel {
        width: 90vw !important;
        left: 5vw !important;
    }
    
    .filter-panel-content {
        padding: 1rem !important;
    }
    
    .filter-options {
        max-height: 200px;
    }
}

/* Dark Theme Adjustments */
[data-bs-theme="dark"] .filter-checkboxes::-webkit-scrollbar-track,
[data-bs-theme="dark"] .filter-widgets-container::-webkit-scrollbar-track {
    background: var(--bs-gray-800);
}

[data-bs-theme="dark"] .filter-checkboxes::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] .filter-widgets-container::-webkit-scrollbar-thumb {
    background: var(--bs-gray-600);
}

[data-bs-theme="dark"] .filter-checkboxes::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] .filter-widgets-container::-webkit-scrollbar-thumb:hover {
    background: var(--bs-gray-500);
}

[data-bs-theme="dark"] .jsPanel-content {
    background: var(--bs-dark) !important;
    color: var(--bs-light) !important;
}

[data-bs-theme="dark"] .filter-widget {
    background: var(--bs-gray-900);
    border-color: var(--bs-gray-700);
}

[data-bs-theme="dark"] .filter-widget:hover {
    border-color: var(--bs-primary);
    box-shadow: 0 4px 12px rgba(var(--bs-primary-rgb), 0.25);
}

[data-bs-theme="dark"] .filter-widget-header {
    background: linear-gradient(135deg, var(--bs-gray-800) 0%, var(--bs-gray-700) 100%);
    border-bottom-color: var(--bs-gray-600);
}

[data-bs-theme="dark"] .filter-widget-title {
    color: var(--bs-light);
}

[data-bs-theme="dark"] .filter-footer {
    background: var(--bs-gray-800);
    border-top-color: var(--bs-gray-700);
}

[data-bs-theme="dark"] .filter-header {
    background: linear-gradient(135deg, var(--bs-primary) 0%, var(--bs-info) 100%);
}

/* Filter Count Animation */
.filter-count {
    transition: all 0.3s ease;
}

.filter-count.show {
    transform: scale(1.1);
}

/* Filter Button States */
.btn.filter-active {
    position: relative;
}

.btn.filter-active::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background: var(--bs-warning);
    border-radius: 50%;
    border: 2px solid var(--bs-body-bg);
}

/* ==== DataTables SearchPanes - constrain width & pane layout ==== */
/* The DT Buttons dropdown-menu expands to fit children. Constrain it. */
.dt-button-collection.dtb-collection-closeable {
    max-width: 95vw !important;
    width: 95vw !important;
    max-height: 85vh;
    overflow: auto;
}
.dtsp-panesContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.dtsp-searchPanes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}
.dtsp-searchPane {
    flex: 1 1 260px;
    max-width: 320px;
    min-width: 220px;
}
.dtsp-searchPane.dtsp-hidden { display: none !important; }
.dtsp-searchPane .dataTables_scrollBody {
    max-height: 180px !important;
    height: auto !important;
}
