/* Integrated Search Layout - Sidebar + Results */

.integrated-search-layout {
    display: flex;
    height: calc(100vh - 100px);
    margin: 0 -15px;
    background-color: #f8f9fa;
}

/* Left Sidebar - Search Filters */
.search-sidebar {
    width: 350px;
    min-width: 350px;
    background: white;
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e7e7e7;
    background-color: #f8f8f8;
    background-image: linear-gradient(to bottom, #ffffff 0%, #f8f8f8 100%);
    border-color: #e7e7e7;
    color: #333;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 1px 5px rgba(0,0,0,.075);
}

.sidebar-header h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
    text-shadow: 0 1px 0 rgba(255,255,255,.5);
}

.sidebar-description {
    margin: 0;
    font-size: 14px;
    color: #777;
    opacity: 1;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

/* Ensure filter content areas don't constrain dropdown widths */
.filter-content {
    width: 100%;
    box-sizing: border-box;
    padding: 16px;
    overflow: hidden;
}

/* Ensure filter sections use full available width */
.filter-section {
    width: 100%;
    margin-bottom: 20px;
    box-sizing: border-box;
}

/* Filter Stats */
.filter-stats {
    display: flex;
    margin-bottom: 25px;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid #e9ecef;
}

.stat-item {
    flex: 1;
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 24px;
    font-weight: bold;
    color: #495057;
    line-height: 1;
}

.stat-label {
    display: block;
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-item:first-child .stat-number {
    color: #28a745;
}

.stat-item:last-child .stat-number {
    color: #007bff;
}

/* Filter Sections */
.filter-section {
    margin-bottom: 20px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background: white;
}

.filter-heading {
    margin: 0;
    padding: 12px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-size: 14px;
    font-weight: 600;
    color: #495057;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
}

.filter-heading:hover {
    background: #e9ecef;
}

.toggle-icon {
    margin-right: 8px;
    font-size: 12px;
    transition: transform 0.3s ease;
    display: inline-block;
}

.filter-heading.collapsed .toggle-icon {
    transform: rotate(0deg);
}

.filter-heading:not(.collapsed) .toggle-icon {
    transform: rotate(90deg);
}

.filter-content {
    padding: 16px;
    overflow: hidden;
}

.filter-content.collapsed {
    display: none;
}

/* When filter content is expanded, ensure it doesn't constrain dropdown widths */
.filter-content:not(.collapsed) {
    width: 100%;
    box-sizing: border-box;
}

.filter-content:not(.collapsed) .form-group {
    width: 100%;
    box-sizing: border-box;
}

/*.filter-content:not(.collapsed) select {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}*/

/* Form Groups */
.form-group {
    margin-bottom: 16px;
    width: 100%;
}

.form-group:last-child {
    margin-bottom: 0;
}

/* Ensure form groups don't constrain dropdown widths */
.filter-section .form-group {
    width: 100% !important;
    max-width: none !important;
}

.filter-section .form-group select {
    width: 100% !important;
    max-width: 100% !important;
}

.control-label {
    font-size: 13px;
    font-weight: 500;
    color: #495057;
    margin-bottom: 6px;
    display: block;
}

/* Compact Form Controls */
/*.filter-dropdown.compact {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 90px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 6px;
    font-size: 13px;
    box-sizing: border-box;
    overflow: hidden;
}*/

/* Ensure all select elements in filter sections have consistent width and height */
.filter-section select,
.filter-section .filter-dropdown,
.filter-section select[multiple],
.sidebar-content select,
.sidebar-content select[multiple],
.integrated-search-layout .filter-section select,
.integrated-search-layout .sidebar-content select,
div.filter-section select[multiple],
div.sidebar-content select[multiple] {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: 90px !important;
    box-sizing: border-box !important;
    border: 1px solid #ced4da !important;
    border-radius: 4px !important;
    padding: 6px !important;
    font-size: 13px !important;
}

/* More specific overrides to ensure width consistency across all dropdowns */
.search-sidebar select[data-filter],
.search-sidebar .filter-dropdown,
.filter-section select[data-filter],
.filter-section .filter-dropdown.compact,
select[data-filter="methods"],
select[data-filter="stakeholders"],
select[data-filter="studyType"],
select[data-filter="interventions"],
select[data-filter="diseaseNames"],
select[data-filter="diseaseCats"] {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: 90px !important;
    box-sizing: border-box !important;
    border: 1px solid #ced4da !important;
    border-radius: 4px !important;
    padding: 6px !important;
    font-size: 13px !important;
    display: block !important;
}

/* Override any Bootstrap form-control styles that might interfere */
.filter-section .form-control,
.sidebar-content .form-control {
    width: 100% !important;
    height: 90px !important;
}

/* Ultra-specific overrides to force width consistency - these should override everything */
body .integrated-search-layout .search-sidebar .sidebar-content .filter-section .form-group select,
body .integrated-search-layout .search-sidebar .sidebar-content .filter-section .form-group .filter-dropdown,
body .integrated-search-layout .search-sidebar .sidebar-content .filter-section .form-group select[multiple],
body .integrated-search-layout .search-sidebar .sidebar-content .filter-section .form-group select[data-filter] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 90px !important;
    box-sizing: border-box !important;
    display: block !important;
    overflow: hidden !important;
}

/* Emergency override: prevent any dropdown from being wider than its container */
.search-sidebar select,
.search-sidebar .filter-dropdown {
    max-width: 258px !important;
    width: 258px !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

/* Force specific problematic dropdowns to proper width */
select[data-filter="diseaseCats"],
select[data-filter="diseaseNames"],
select[data-filter="interventions"] {
    width: 258px !important;
    max-width: 258px !important;
    min-width: 258px !important;
}

select[data-filter="methods"],
select[data-filter="stakeholders"],
select[data-filter="studyType"] {
    width: 258px !important;
    max-width: 258px !important;
    min-width: 258px !important;
}

/* Target specific problem dropdowns by data-filter attribute */
select[data-filter="methods"],
select[data-filter="stakeholders"],
select[data-filter="studyType"],
select[data-filter="interventions"],
select[data-filter="diseaseNames"],
select[data-filter="diseaseCats"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 90px !important;
    box-sizing: border-box !important;
    display: block !important;
}

/* Force a consistent width for all filter dropdowns */
.filter-dropdown.compact {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    display: block !important;
}

.filter-dropdown.compact:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

.filter-dropdown.compact:disabled {
    opacity: 0.6;
    background-color: #f8f9fa;
    cursor: not-allowed;
}

.filter-dropdown.loading {
    opacity: 0.7;
    background-color: #f8f9fa;
    cursor: wait;
    background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><circle cx="8" cy="8" r="7" fill="none" stroke="%23007bff" stroke-width="2" stroke-linecap="round" stroke-dasharray="31.416" stroke-dashoffset="31.416"><animate attributeName="stroke-dashoffset" dur="2s" values="31.416;0" repeatCount="indefinite"/></circle></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px 16px;
    padding-right: 35px;
}

/* Filter option count styling */
.filter-option-count {
    color: #6c757d;
    font-size: 11px;
    font-weight: 500;
}

/* Dynamic filter feedback */
.filter-updated {
    border-left: 3px solid #28a745;
    animation: filterHighlight 0.5s ease-out;
}

@keyframes filterHighlight {
    0% {
        background-color: #d4edda;
        border-left-color: #28a745;
    }
    100% {
        background-color: transparent;
        border-left-color: transparent;
    }
}

/* Age Range Compact */
.age-range-compact {
    display: flex;
    align-items: center;
    gap: 8px;
}

.age-input.compact {
    width: 70px;
    height: 32px;
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    text-align: center;
    font-size: 13px;
}

.age-separator {
    color: #6c757d;
    font-weight: 500;
    font-size: 14px;
}

/* Year Range Compact */
.year-range-compact {
    display: flex;
    align-items: center;
    gap: 8px;
}

.year-input.compact {
    width: 80px;
    height: 32px;
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    text-align: center;
    font-size: 13px;
}

.year-separator {
    color: #6c757d;
    font-weight: 500;
    font-size: 14px;
}

/* Checkbox Groups */
.checkbox-group.compact {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    font-size: 13px;
    color: #495057;
    cursor: pointer;
    padding: 4px 0;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 8px;
}

.checkbox-text {
    flex: 1;
}

/* Radio Groups */
.radio-group.compact {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.radio-label {
    display: flex;
    align-items: center;
    font-size: 13px;
    color: #495057;
    cursor: pointer;
    padding: 4px 0;
}

.radio-label input[type="radio"] {
    margin-right: 8px;
}

.radio-text {
    flex: 1;
}

/* Age Suggestions */
.age-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ced4da;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    margin-top: 2px;
}

.age-suggestions-list {
    display: flex;
    flex-direction: column;
}

.age-suggestion {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    color: #495057;
    transition: background-color 0.2s;
}

.age-suggestion:hover, .age-suggestion:focus {
    background-color: #f8f9fa;
    outline: none;
}

.age-suggestion.active {
    background-color: #e3f2fd;
    color: #1976d2;
    font-weight: 500;
}

/* Select2 Enhancement for Icons and Selection Count */
.select2-selection__placeholder i.glyphicon {
    margin-right: 5px;
    color: #666;
}

.select2-selection__placeholder.selection-count-indicator {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 3px;
    padding: 2px 6px;
    margin: 2px 2px 2px 0;
    font-size: 11px;
    color: #155724;
    display: inline-block;
    white-space: nowrap;
    position: relative;
    z-index: 1;
}

.select2-selection__placeholder.selection-count-indicator i.glyphicon {
    color: #28a745;
}

/* Ensure the selection count indicator doesn't interfere with other Select2 elements */
.select2-container--default .select2-selection--multiple .select2-selection__rendered .select2-selection__placeholder.selection-count-indicator {
    float: left;
    clear: none;
    margin-right: 5px;
}

/* Make sure the selection area has enough space */
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    min-height: 24px;
    overflow: visible;
}

/* Sidebar Actions */
.sidebar-actions {
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
    margin-top: 20px;
}

/* Right Panel - Results */
.results-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

.results-header {
    padding: 20px 30px;
    border-bottom: 1px solid #e9ecef;
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.results-title h2 {
    margin: 0 0 8px 0;
    font-size: 24px;
    color: #212529;
}

.results-summary {
    color: #6c757d;
    font-size: 14px;
}

.results-controls {
    display: flex;
    gap: 20px;
    align-items: center;
}

.view-controls .btn-group .btn {
    font-size: 12px;
    padding: 6px 12px;
    cursor: pointer;
}

.view-controls .btn-group .btn.active {
    background-color: #337ab7;
    border-color: #2e6da4;
    color: white;
}

.view-controls .btn-group .btn:hover:not(.active) {
    background-color: #e6e6e6;
    border-color: #adadad;
}

.view-controls .btn-group .btn input[type="radio"] {
    display: none; /* Hide radio buttons, use labels for styling */
}

.export-controls .btn {
    font-size: 12px;
    padding: 6px 16px;
}

/* Results Content */
.results-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: #f8f9fa;
}

/* Loading State */
.results-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
}

.loading-content i {
    font-size: 48px;
    color: #007bff;
    margin-bottom: 20px;
}

.loading-content h4 {
    color: #495057;
    margin-bottom: 10px;
}

.loading-content p {
    color: #6c757d;
    margin: 0;
}

/* Empty State */
.results-empty {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
}

.empty-content {
    max-width: 500px;
}

.empty-content i {
    font-size: 64px;
    color: #dee2e6;
    margin-bottom: 20px;
}

.empty-content h3 {
    color: #495057;
    margin-bottom: 15px;
}

.empty-content p {
    color: #6c757d;
    margin-bottom: 25px;
}

.quick-tips {
    text-align: left;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.quick-tips h5 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 16px;
}

.quick-tips ul {
    margin: 0;
    padding-left: 20px;
}

.quick-tips li {
    color: #6c757d;
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.5;
}

/* Results Container */
.results-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: calc(100vh - 200px); /* Prevent container from exceeding viewport */
}

.results-section {
    margin-bottom: 40px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    overflow: hidden;
    flex-shrink: 0; /* Prevent sections from shrinking */
}

.results-section .table-responsive {
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid #e9ecef;
}

.section-title {
    padding: 20px 25px;
    margin: 0;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-size: 18px;
    color: #495057;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-title .badge {
    background-color: #007bff;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

/* Results Table */
.results-table {
    margin: 0;
    font-size: 14px;
}

.results-table thead th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    color: #495057;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 15px 12px;
}

.results-table tbody td {
    padding: 12px;
    vertical-align: middle;
    border-bottom: 1px solid #f1f3f4;
}

.results-table tbody tr:hover {
    background-color: #f8f9fa;
}

.actions-column {
    width: 100px;
    text-align: center;
}

.btn-view-study {
    font-size: 11px;
    padding: 4px 12px;
}

/* No Results */
.no-results {
    text-align: center;
    padding: 60px 30px;
    color: #6c757d;
}

.no-results i {
    font-size: 48px;
    color: #dee2e6;
    margin-bottom: 20px;
}

.no-results h4 {
    color: #495057;
    margin-bottom: 15px;
}

.no-results ul {
    text-align: left;
    max-width: 400px;
    margin: 20px auto 0;
}

.no-results li {
    margin-bottom: 8px;
}

/* Pagination */
.pagination-container {
    padding: 20px 25px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    text-align: center;
}

/* Loading Animation */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.glyphicon-refresh-animate {
    animation: spin 1s infinite linear;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .search-sidebar {
        width: 320px;
        min-width: 320px;
    }
    
    .results-header {
        padding: 15px 20px;
    }
    
    .results-content {
        padding: 20px;
    }
}

@media (max-width: 992px) {
    .integrated-search-layout {
        height: auto;
        min-height: calc(100vh - 100px);
    }
    
    .search-sidebar {
        width: 280px;
        min-width: 280px;
    }
    
    .filter-dropdown.compact {
        height: 80px;
    }
    
    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .results-controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .results-container {
        max-height: calc(100vh - 300px);
    }
    
    .results-section .table-responsive {
        max-height: 50vh;
    }
}

@media (max-width: 768px) {
    .integrated-search-layout {
        flex-direction: column;
        height: auto;
        margin: 0;
    }
    
    .search-sidebar {
        width: 100%;
        min-width: auto;
        height: auto;
        border-right: none;
        border-bottom: 1px solid #dee2e6;
    }
    
    .sidebar-content {
        max-height: 60vh;
    }
    
    .results-content {
        padding: 15px;
    }
    
    .results-table {
        font-size: 12px;
    }
    
    .results-table thead th,
    .results-table tbody td {
        padding: 8px 6px;
    }
    
    .age-range-compact,
    .year-range-compact {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .age-input.compact,
    .year-input.compact {
        width: 100%;
    }
    
    .age-separator,
    .year-separator {
        display: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .search-sidebar,
    .results-panel,
    .filter-section {
        border: 2px solid #000;
    }
    
    .filter-dropdown.compact,
    .age-input.compact,
    .year-input.compact {
        border: 2px solid #000;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .glyphicon-refresh-animate {
        animation: none;
    }
    
    .toggle-icon,
    .filter-heading,
    .age-suggestion {
        transition: none;
    }
}

/* Focus Management */
.filter-dropdown.compact:focus,
.age-input.compact:focus,
.year-input.compact:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

.checkbox-label:focus-within,
.radio-label:focus-within {
    background-color: rgba(0, 123, 255, 0.1);
    border-radius: 4px;
}

/* Print Styles */
@media print {
    .search-sidebar {
        display: none;
    }
    
    .results-panel {
        width: 100%;
    }
    
    .results-header {
        box-shadow: none;
        border-bottom: 2px solid #000;
    }
    
    .results-table {
        font-size: 12px;
    }
}

.filter-dropdown,
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple,
.select2-dropdown {
    width: 258px !important;
    min-width: 258px !important;
    max-width: 258px !important;
}