:root {
    --primary-color: #0d6efd;
    --success-color: #198754;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #0dcaf0;
    --dark-color: #212529;
    --light-bg: #f8f9fa;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--light-bg);
    min-height: 100vh;
}

.navbar-brand {
    font-weight: 600;
    font-size: 1.2rem;
}

.navbar-brand i {
    margin-right: 0.4rem;
}

.nav-link {
    font-weight: 500;
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
    transition: all 0.3s ease;
}

.nav-link:hover {
    transform: translateY(-2px);
}

.nav-link.active {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 0.25rem;
}

/* Stats Cards */
.stat-card {
    background: white;
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    height: 100%;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.stat-card .stat-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.stat-card .stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.stat-card .stat-label {
    color: #6c757d;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .stat-sublabel {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.stat-card.blue { border-left: 4px solid var(--primary-color); }
.stat-card.blue .stat-icon { color: var(--primary-color); }

.stat-card.green { border-left: 4px solid var(--success-color); }
.stat-card.green .stat-icon { color: var(--success-color); }

.stat-card.orange { border-left: 4px solid var(--warning-color); }
.stat-card.orange .stat-icon { color: var(--warning-color); }

.stat-card.red { border-left: 4px solid var(--danger-color); }
.stat-card.red .stat-icon { color: var(--danger-color); }

.stat-card.cyan { border-left: 4px solid var(--info-color); }
.stat-card.cyan .stat-icon { color: var(--info-color); }

/* Data Table */
.data-table-container {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-top: 2rem;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.table-header h4 {
    margin: 0;
    font-weight: 600;
}

.search-box {
    max-width: 300px;
}

.table {
    margin-bottom: 0;
}

.table thead th {
    background-color: var(--light-bg);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #dee2e6;
    cursor: pointer;
    user-select: none;
}

.table thead th:hover {
    background-color: #e9ecef;
}

.table tbody tr {
    transition: background-color 0.2s ease;
}

.table tbody tr:hover {
    background-color: rgba(13, 110, 253, 0.05);
}

.badge-custom {
    padding: 0.35em 0.65em;
    font-weight: 500;
}

/* Filters */
.filters-container {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.filter-group {
    margin-bottom: 1rem;
}

.filter-group label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: block;
}

/* Loading Spinner */
#loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
}

#loading-spinner .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Charts */
.chart-container {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-top: 2rem;
}

/* Utility Classes */
.text-truncate-custom {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
}

.clickable {
    cursor: pointer;
}

.stat-card.clickable:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.quick-stat-item.clickable:hover {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    transition: background 0.2s ease;
}

.section-title {
    font-weight: 600;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
}

/* Responsive */
@media (max-width: 768px) {
    .stat-card {
        margin-bottom: 1rem;
    }
    
    .table-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .search-box {
        max-width: 100%;
        width: 100%;
        margin-top: 1rem;
    }
}

/* Database Size Bar */
.size-bar {
    height: 20px;
    background: linear-gradient(to right, var(--success-color), var(--warning-color), var(--danger-color));
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.size-bar-inner {
    height: 100%;
    background: rgba(255, 255, 255, 0.3);
    transition: width 0.3s ease;
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #dee2e6;
}

.pagination-info {
    color: #6c757d;
}

/* Action Buttons */
.btn-action {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    margin-right: 0.25rem;
}

/* Details Panel */
.details-panel {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-top: 1rem;
}

.details-panel .detail-row {
    display: flex;
    padding: 0.75rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.details-panel .detail-row:last-child {
    border-bottom: none;
}

.details-panel .detail-label {
    font-weight: 600;
    width: 200px;
    color: #495057;
}

.details-panel .detail-value {
    flex: 1;
    color: #212529;
}

/* Quick Stats Row */
.quick-stats {
    background: linear-gradient(135deg, var(--primary-color), #0a58ca);
    color: white;
    border-radius: 0.5rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.quick-stats h3 {
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.quick-stat-item {
    text-align: center;
}

.quick-stat-value {
    font-size: 2rem;
    font-weight: 700;
    display: block;
}

.quick-stat-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 0.5rem;
}

/* Extra small buttons for modals */
.btn-xs {
    padding: 0.15rem 0.4rem;
    font-size: 0.75rem;
    line-height: 1.2;
}

/* Modal table sticky header */
.modal .table thead.sticky-top th {
    background-color: #f8f9fa;
    z-index: 1;
}

/* Modal scrollable content */
.modal-body .table-responsive {
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
}

/* Chart containers */
.data-table-container canvas {
    max-width: 100%;
}

/* Global Search */
#global-search-results {
    position: fixed;
    background: #ffffff;
    border: 1px solid #b0b8c1;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1060;
    width: 350px;
}

#global-search-results .search-category {
    padding: 0.4rem 0.75rem;
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    border-bottom: 1px solid #dee2e6;
}

#global-search-results .search-result-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    background: #ffffff;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.875rem;
    transition: background 0.15s;
}

#global-search-results .search-result-item:hover {
    background: #e8f0fe;
}

#global-search-results .search-result-item:last-child {
    border-bottom: none;
}

#global-search-results .search-no-results {
    padding: 1rem;
    text-align: center;
    color: #6c757d;
}

/* Sortable Table Columns */
.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background-color 0.2s ease;
}

.sortable:hover {
    background-color: #e9ecef !important;
}

.sorted-asc,
.sorted-desc {
    background-color: #e3f2fd !important;
}

.sort-icon {
    display: inline-block;
    margin-left: 0.25rem;
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ============================================================================
   Grouped Navigation Styling (Phase 3)
   ============================================================================ */

/* Dropdown menus */
.navbar-nav .dropdown-menu {
    min-width: 220px;
    border-radius: 0.25rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Dropdown items */
.navbar-nav .dropdown-item {
    padding: 0.5rem 1rem;
    transition: background-color 0.2s ease;
}

.navbar-nav .dropdown-item i {
    width: 20px;
    margin-right: 8px;
    text-align: center;
}

.navbar-nav .dropdown-item:hover {
    background-color: rgba(13, 110, 253, 0.1);
}

/* Dropdown toggle arrow */
.navbar-nav .dropdown-toggle::after {
    margin-left: 0.5rem;
}

/* Active state for dropdown items */
.navbar-nav .dropdown-item.active {
    background-color: rgba(13, 110, 253, 0.15);
    font-weight: 600;
}

/* Platform group hover effect */
.navbar-nav .dropdown:hover > .nav-link {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 0.25rem;
}

/* ============================================
   Dark Mode Overrides
   Bootstrap 5.3 handles its own components via
   data-bs-theme="dark" on <html>. These rules
   override our custom components.
   ============================================ */

[data-bs-theme="dark"] {
    --light-bg: #1a1d20;
}

[data-bs-theme="dark"] body {
    background-color: #1a1d20;
    color: #dee2e6;
}

/* Stat cards */
[data-bs-theme="dark"] .stat-card {
    background: #2b2f33;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    color: #dee2e6;
}
[data-bs-theme="dark"] .stat-card .stat-label {
    color: #9ba5ae;
}
[data-bs-theme="dark"] .stat-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* Data table containers & filters */
[data-bs-theme="dark"] .data-table-container,
[data-bs-theme="dark"] .filters-container,
[data-bs-theme="dark"] .chart-container {
    background: #2b2f33;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Table headers */
[data-bs-theme="dark"] .table thead th {
    background-color: #343a40;
    border-bottom-color: #495057;
    color: #adb5bd;
}
[data-bs-theme="dark"] .table thead th:hover {
    background-color: #3d4349;
}
[data-bs-theme="dark"] .table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Quick stats bar on dashboard */
[data-bs-theme="dark"] .quick-stats {
    background: #2b2f33;
    color: #dee2e6;
}
[data-bs-theme="dark"] .quick-stat-item .quick-stat-value {
    color: #dee2e6;
}
[data-bs-theme="dark"] .quick-stat-item .quick-stat-label {
    color: #9ba5ae;
}
[data-bs-theme="dark"] .quick-stat-item.clickable:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Section titles */
[data-bs-theme="dark"] .section-title {
    color: #dee2e6;
}

/* Cards in modals / detail views */
[data-bs-theme="dark"] .card {
    background-color: #2b2f33;
    border-color: #495057;
}
[data-bs-theme="dark"] .card-header {
    background-color: #343a40 !important;
    border-bottom-color: #495057;
    color: #dee2e6;
}

/* Accordion */
[data-bs-theme="dark"] .accordion-button {
    background-color: #343a40;
    color: #dee2e6;
}
[data-bs-theme="dark"] .accordion-button:not(.collapsed) {
    background-color: #3d4349;
    color: #dee2e6;
}
[data-bs-theme="dark"] .accordion-item {
    background-color: #2b2f33;
    border-color: #495057;
}

/* Global search results */
[data-bs-theme="dark"] #global-search-results {
    background: #2b2f33;
    border-color: #495057;
    color: #dee2e6;
}
[data-bs-theme="dark"] #global-search-results .search-result-item:hover {
    background: #343a40;
}

/* Dark mode toggle button */
#dark-mode-toggle {
    font-size: 1rem;
    line-height: 1;
    padding: 0.3rem 0.5rem;
    transition: transform 0.3s ease;
}
#dark-mode-toggle:hover {
    transform: rotate(20deg);
}

/* ============================================
   Responsive Table Scaling
   Auto-shrinks tables to fit smaller screens
   ============================================ */

/* Medium screens (tablets, small laptops ~1024-1280px) */
@media (max-width: 1280px) {
    .table {
        font-size: 0.82rem;
    }
    .table th, .table td {
        padding: 0.35rem 0.5rem;
    }
    .btn-action {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }
    .badge {
        font-size: 0.7rem;
    }
    .filters-container .row > div {
        margin-bottom: 0.5rem;
    }
}

/* Small screens (small laptops ~900-1024px) */
@media (max-width: 1024px) {
    .table {
        font-size: 0.78rem;
    }
    .table th, .table td {
        padding: 0.25rem 0.4rem;
        white-space: nowrap;
    }
    .data-table-container {
        overflow-x: auto;
    }
    .stat-card {
        padding: 1rem;
    }
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
    .section-title {
        font-size: 1.2rem;
    }
}

/* Extra small (very small laptops <900px) */
@media (max-width: 900px) {
    .table {
        font-size: 0.73rem;
    }
    .table th, .table td {
        padding: 0.2rem 0.3rem;
    }
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* Ensure all table containers scroll horizontally when content overflows */
.data-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Modal tables also scroll on small screens */
.modal-body .table-responsive {
    max-height: 60vh;
    overflow-y: auto;
}

/* ===== AI Assistant Chat ===== */
#assistant-messages {
    background-color: var(--bs-body-bg);
}

.assistant-tool-indicator {
    font-style: italic;
    font-size: 0.85rem;
    padding: 2px 8px;
    border-left: 3px solid var(--bs-primary);
    margin: 4px 0;
    color: var(--bs-secondary-color);
}

.assistant-bubble pre.assistant-code-block {
    background: var(--bs-dark-bg-subtle, #2d2d2d);
    color: var(--bs-light, #f8f9fa);
    padding: 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.85rem;
    max-height: 300px;
    overflow: auto;
    margin: 0.5rem 0;
    white-space: pre-wrap;
}

.assistant-bubble code.assistant-inline-code {
    background: var(--bs-dark-bg-subtle, #e9ecef);
    padding: 0.1rem 0.3rem;
    border-radius: 0.25rem;
    font-size: 0.9em;
}

.assistant-bubble table {
    font-size: 0.85rem;
}

.assistant-bubble {
    border: 1px solid var(--bs-border-color);
}

/* Health Analyzer */
.health-finding { transition: box-shadow 0.2s; }
.health-finding:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.bg-orange { background-color: #fd7e14 !important; color: white !important; }

