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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Login page */
.min-vh-100 {
    min-height: 100vh;
}

.card {
    border-radius: 12px;
}

/* Dashboard layout */
.dashboard-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    background: #ffffff;
    border-right: 1px solid #dee2e6;
    overflow-y: auto;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    background: #ffffff;
    border-bottom: 1px solid #dee2e6;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1.5rem;
    background: #f8f9fa;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 1rem;
    background: #ffffff;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.chat-input-container {
    background: #ffffff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.message {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border-radius: 8px;
    box-sizing: border-box;
}

.message.user {
    background: #e3f2fd;
    margin-left: 20%;
    margin-right: 0;
    max-width: 80%;
}

.message.ai {
    background: #f5f5f5;
    margin-right: 20%;
    margin-left: 0;
    max-width: 80%;
}

.message-header {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #495057;
}

.message-content {
    color: #212529;
    line-height: 1.6;
    white-space: pre-wrap; /* Preserve line breaks and spaces */
}

.message-content br {
    margin-bottom: 0.5rem;
}

/* Questions sidebar */
.questions-section {
    padding: 1.5rem;
}

.questions-section h6 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
    margin-bottom: 1rem;
}

.question-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.question-item:hover {
    background: #e9ecef;
    border-color: var(--primary-color);
    transform: translateX(4px);
}

.question-item.active {
    background: #e3f2fd;
    border-color: var(--primary-color);
}

/* Buttons */
.btn-export {
    background: #198754;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-export:hover {
    background: #157347;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-chatgpt {
    background: #10a37f;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-chatgpt:hover {
    background: #0d8c6f;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-email {
    background: #0d6efd;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-email:hover {
    background: #0b5ed7;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-live-excel {
    background: #6f42c1;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-live-excel:hover {
    background: #5a32a3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-powerbi {
    background: #F2C811;
    color: #333;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

.btn-powerbi:hover {
    background: #e0b800;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Excel Level Selector */
.excel-level-selector {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
    font-size: 0.85rem;
}

.excel-level-selector label {
    font-weight: 600;
    color: #495057;
    white-space: nowrap;
}

.excel-level-selector select {
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    border: 1px solid #ced4da;
    font-size: 0.85rem;
    background: #fff;
    cursor: pointer;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

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

/* Mobile responsive */
@media (max-width: 768px) {
    .dashboard-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid #dee2e6;
    }

    .message.user,
    .message.ai {
        margin-left: 0;
        margin-right: 0;
        max-width: 100%;
    }

    .chat-container {
        padding: 1rem;
    }

    .header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
    }

    .result-table {
        font-size: 0.75rem;
    }

    .result-table th,
    .result-table td {
        padding: 0.5rem 0.25rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons button {
        width: 100%;
    }

    .follow-up-btn {
        font-size: 0.85rem;
        padding: 0.6rem 0.8rem;
    }

    .questions-section {
        padding: 1rem;
    }

    .report-details .btn-group-vertical .btn {
        font-size: 0.7rem;
        padding: 0.5rem;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .result-table {
        font-size: 0.7rem;
    }

    .result-table th,
    .result-table td {
        padding: 0.4rem 0.2rem;
    }

    .message {
        padding: 0.75rem;
    }

    .chat-input-container {
        padding: 1rem;
    }
}

/* Result table styling */
.result-table-container {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    margin-top: 1rem;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 100%;
}

.result-table th {
    background: #0d6efd;
    color: white;
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
}

.result-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 2rem;
}

.result-table th.sortable:hover {
    background: #0b5ed7;
}

.result-table th .sort-icon {
    position: absolute;
    right: 0.5rem;
    opacity: 0.6;
    font-size: 0.9rem;
}

.result-table td {
    padding: 0.75rem;
    border-bottom: 1px solid #dee2e6;
}

.result-table tr:hover {
    background: #f8f9fa;
}

.result-table tr:last-child td {
    border-bottom: none;
}

.interactive-cell {
    cursor: pointer;
    transition: all 0.2s;
}

.interactive-cell:hover {
    background: #e3f2fd !important;
    font-weight: 500;
}

/* Action buttons container */
.action-buttons {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Welcome message */
.welcome-message {
    text-align: center;
    color: #6c757d;
    padding: 3rem;
}

.welcome-message h2 {
    color: #212529;
    margin-bottom: 1rem;
}

.welcome-icon {
    margin-bottom: 1rem;
}

.welcome-icon img {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

/* SQL Query Display */
.sql-query-container {
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
}

.sql-query-content {
    margin-top: 0.75rem;
}

.sql-query {
    background: #282c34;
    color: #61dafb;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
}

.sql-query code {
    color: #61dafb;
}

/* Feedback buttons */
.feedback-container {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.feedback-btn {
    padding: 0.25rem 0.75rem;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.feedback-btn:hover {
    background: #f8f9fa;
}

.feedback-btn.active-good {
    background: #d1e7dd;
    border-color: #198754;
    color: #198754;
}

.feedback-btn.active-bad {
    background: #f8d7da;
    border-color: #dc3545;
    color: #dc3545;
}

/* Follow-up questions */
.follow-up-questions {
    margin-top: 1.25rem;
    padding: 1rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.follow-up-header {
    font-size: 0.875rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.75rem;
}

.follow-up-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.follow-up-btn {
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    color: #212529;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.follow-up-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateX(4px);
    box-shadow: 0 3px 8px rgba(13, 110, 253, 0.3);
}

.follow-up-btn:active {
    transform: translateX(2px);
}

/* Query History */
.history-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.history-item:hover {
    background: #e9ecef;
    border-left-color: var(--primary-color);
    transform: translateX(2px);
}

.history-question {
    font-size: 0.85rem;
    color: #212529;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-meta {
    font-size: 0.75rem;
    color: #6c757d;
}

/* Query Metrics */
.query-metrics {
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

/* Chart Container */
.chart-container {
    margin-top: 1.5rem;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.chart-controls {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.btn-chart {
    background: #6610f2;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-chart:hover {
    background: #520dc2;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Keyboard Shortcuts Modal */
.shortcuts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.keyboard-shortcuts-modal {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.keyboard-shortcuts-modal h5 {
    margin-bottom: 1.5rem;
}

.shortcuts-list {
    list-style: none;
    padding: 0;
    margin-bottom: 1.5rem;
}

.shortcuts-list li {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
}

.shortcuts-list kbd {
    background: #212529;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Chart insertion */
.chart-insertion {
    margin-top: 1rem;
}

/* Saved Reports */
.report-item {
    margin-bottom: 0.5rem;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #ffffff;
    overflow: hidden;
}

.report-header {
    padding: 0.75rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    transition: all 0.2s;
    user-select: none;
}

.report-header:hover {
    background: #e9ecef;
}

.report-header strong {
    flex: 1;
    font-size: 0.9rem;
    color: #212529;
}

.toggle-icon {
    font-size: 0.8rem;
    color: #6c757d;
    margin-left: 0.5rem;
}

.report-details {
    padding: 0.75rem;
    background: #ffffff;
    border-top: 1px solid #dee2e6;
}

.report-details .btn-group {
    margin-top: 0.5rem;
    display: flex;
    gap: 0;
}

.report-details .btn-group .btn {
    font-size: 0.75rem;
    padding: 0.375rem 0.5rem;
    flex: 1;
    white-space: nowrap;
}

/* Save Report Button */
.btn-save-report {
    background: #fd7e14;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-save-report:hover {
    background: #dc6607;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* ============= MODE TAB BAR ============= */
.mode-tab-bar {
    display: flex;
    gap: 0;
    padding: 0 20px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
    flex-shrink: 0;
}

.mode-tab {
    padding: 10px 24px;
    border: none;
    background: transparent;
    color: #666;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
}

.mode-tab:hover {
    color: #333;
    background: rgba(0,0,0,0.03);
}

.mode-tab.active {
    color: #7c3aed;
    border-bottom-color: #7c3aed;
    font-weight: 600;
}

/* ============= REPORT BUILDER LAYOUT ============= */
.rb-mode-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.rb-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.rb-conversation {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid #e0e0e0;
}

.rb-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    background: #ffffff;
}

.rb-input-container {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    background: #ffffff;
}

/* Report Builder Preview Panel */
.rb-preview-panel {
    width: 360px;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    background: #fafbfc;
    overflow-y: auto;
    flex-shrink: 0;
}

.rb-preview-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.rb-preview-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.rb-preview-hint {
    color: #999;
    font-size: 13px;
}

.rb-preview-content {
    padding: 16px 20px;
}

.rb-preview-empty {
    color: #999;
    font-size: 14px;
    text-align: center;
    padding: 2rem 1rem;
}

/* Column chips */
.rb-columns {
    margin-bottom: 16px;
}

.rb-columns h5 {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.rb-column-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rb-chip {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background: #e8e8e8;
    color: #555;
}

.rb-chip-number {
    background: #dbeafe;
    color: #1e40af;
}

.rb-chip-currency {
    background: #d1fae5;
    color: #065f46;
}

.rb-chip-percentage {
    background: #fef3c7;
    color: #92400e;
}

.rb-chip-text {
    background: #f3e8ff;
    color: #6b21a8;
}

/* Preview table */
.rb-sample {
    margin-bottom: 16px;
}

.rb-sample h5 {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.rb-preview-table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
}

.rb-preview-table th,
.rb-preview-table td {
    padding: 4px 8px;
    border: 1px solid #e0e0e0;
    text-align: left;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rb-preview-table th {
    background: #f0f0f0;
    font-weight: 600;
    color: #333;
}

/* SQL section */
.rb-sql-section {
    margin-bottom: 16px;
}

.rb-sql-code {
    margin-top: 8px;
    padding: 10px;
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 6px;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: 'Courier New', monospace;
}

/* Export actions in preview */
.rb-export-actions {
    margin-top: 8px;
}

.rb-export-actions .action-buttons {
    flex-direction: column;
}

.rb-export-actions .action-buttons button {
    width: 100%;
    font-size: 0.85rem;
}

/* ============= DARK MODE ============= */
body.dark-mode {
    background: #1a1a1a;
    color: #e0e0e0;
}

/* Dashboard elements */
body.dark-mode .sidebar {
    background: #2d2d2d;
    border-right-color: #404040;
}

body.dark-mode .header {
    background: #2d2d2d;
    border-bottom-color: #404040;
}

body.dark-mode .chat-container {
    background: #1a1a1a;
}

body.dark-mode .chat-messages {
    background: #2d2d2d;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

body.dark-mode .chat-input-container {
    background: #2d2d2d;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Messages */
body.dark-mode .message.user {
    background: #1e3a5f;
    color: #e0e0e0;
}

body.dark-mode .message.ai {
    background: #3a3a3a;
    color: #e0e0e0;
}

body.dark-mode .message-header {
    color: #b0b0b0;
}

body.dark-mode .message-content {
    color: #e0e0e0;
}

/* Welcome message */
body.dark-mode .welcome-message {
    color: #b0b0b0;
}

body.dark-mode .welcome-message h2 {
    color: #e0e0e0;
}

/* Form elements */
body.dark-mode .form-control,
body.dark-mode .form-select {
    background: #3a3a3a;
    border-color: #505050;
    color: #e0e0e0;
}

body.dark-mode .form-control:focus,
body.dark-mode .form-select:focus {
    background: #404040;
    border-color: #0d6efd;
    color: #e0e0e0;
}

body.dark-mode .form-control::placeholder {
    color: #808080;
}

/* Questions and Reports */
body.dark-mode .question-item {
    background: #3a3a3a;
    border-color: #505050;
    color: #e0e0e0;
}

body.dark-mode .question-item:hover {
    background: #454545;
    border-color: #0d6efd;
}

body.dark-mode .question-item.active {
    background: #1e3a5f;
}

body.dark-mode .report-item {
    background: #3a3a3a;
    border-color: #505050;
}

body.dark-mode .report-header {
    background: #2d2d2d;
    color: #e0e0e0;
}

body.dark-mode .report-header:hover {
    background: #404040;
}

body.dark-mode .report-details {
    background: #3a3a3a;
    border-top-color: #505050;
}

body.dark-mode .toggle-icon {
    color: #b0b0b0;
}

/* Tables */
body.dark-mode .result-table {
    color: #e0e0e0;
}

body.dark-mode .result-table th {
    background: #1e5631;
}

body.dark-mode .result-table th.sortable:hover {
    background: #2d7a4a;
}

body.dark-mode .result-table td {
    border-bottom-color: #404040;
}

body.dark-mode .result-table tr:hover {
    background: #3a3a3a;
}

body.dark-mode .interactive-cell:hover {
    background: #1e3a5f !important;
}

/* Buttons */
body.dark-mode .btn-live-excel {
    background: #7c4ddb;
}

body.dark-mode .btn-live-excel:hover {
    background: #9466e8;
}

body.dark-mode .btn-powerbi {
    background: #d4ad00;
    color: #1a1a1a;
}

body.dark-mode .btn-powerbi:hover {
    background: #F2C811;
}

body.dark-mode .excel-level-selector label {
    color: #b0b0b0;
}

body.dark-mode .excel-level-selector select {
    background: #3a3a3a;
    border-color: #505050;
    color: #e0e0e0;
}

body.dark-mode .btn-outline-secondary {
    color: #b0b0b0;
    border-color: #505050;
}

body.dark-mode .btn-outline-secondary:hover {
    background: #505050;
    color: #ffffff;
}

body.dark-mode .btn-outline-danger {
    color: #ff6b6b;
    border-color: #ff6b6b;
}

body.dark-mode .btn-outline-danger:hover {
    background: #ff6b6b;
    color: #ffffff;
}

/* SQL Query */
body.dark-mode .sql-query-container {
    background: #2d2d2d;
}

body.dark-mode .sql-query {
    background: #1a1a1a;
    color: #61dafb;
}

/* Follow-up questions */
body.dark-mode .follow-up-questions {
    background: linear-gradient(135deg, #2d2d2d 0%, #3a3a3a 100%);
    border-left-color: #0d6efd;
}

body.dark-mode .follow-up-header {
    color: #b0b0b0;
}

body.dark-mode .follow-up-btn {
    background: #3a3a3a;
    border-color: #505050;
    color: #e0e0e0;
}

body.dark-mode .follow-up-btn:hover {
    background: #0d6efd;
    color: #ffffff;
    border-color: #0d6efd;
}

/* Feedback buttons */
body.dark-mode .feedback-btn {
    background: #3a3a3a;
    border-color: #505050;
    color: #e0e0e0;
}

body.dark-mode .feedback-btn:hover {
    background: #454545;
}

body.dark-mode .feedback-btn.active-good {
    background: #1e5631;
    border-color: #198754;
    color: #4ade80;
}

body.dark-mode .feedback-btn.active-bad {
    background: #5c1a1a;
    border-color: #dc3545;
    color: #ff6b6b;
}

/* History items */
body.dark-mode .history-item {
    background: #3a3a3a;
}

body.dark-mode .history-item:hover {
    background: #454545;
}

body.dark-mode .history-question {
    color: #e0e0e0;
}

body.dark-mode .history-meta {
    color: #808080;
}

/* Metrics */
body.dark-mode .query-metrics {
    background: #2d2d2d;
}

/* Charts */
body.dark-mode .chart-container {
    background: #2d2d2d;
    border-color: #505050;
}

/* Text colors */
body.dark-mode .text-muted {
    color: #808080 !important;
}

body.dark-mode .text-danger {
    color: #ff6b6b !important;
}

body.dark-mode .text-success {
    color: #4ade80 !important;
}

/* Badges */
body.dark-mode .badge {
    background: #0d6efd;
}

body.dark-mode .badge.bg-success {
    background: #198754 !important;
}

/* Dropdowns */
body.dark-mode .dropdown-menu {
    background: #2d2d2d;
    border-color: #505050;
}

body.dark-mode .dropdown-item {
    color: #e0e0e0;
}

body.dark-mode .dropdown-item:hover {
    background: #3a3a3a;
}

body.dark-mode .dropdown-header {
    color: #b0b0b0;
}

body.dark-mode .dropdown-item-text {
    color: #e0e0e0;
}

body.dark-mode .dropdown-divider {
    border-top-color: #505050;
}

/* Spinners */
body.dark-mode .spinner-border {
    border-color: #505050;
    border-top-color: #0d6efd;
}

/* Scrollbars for table container */
body.dark-mode .result-table-container::-webkit-scrollbar {
    height: 8px;
}

body.dark-mode .result-table-container::-webkit-scrollbar-track {
    background: #2d2d2d;
}

body.dark-mode .result-table-container::-webkit-scrollbar-thumb {
    background: #505050;
    border-radius: 4px;
}

body.dark-mode .result-table-container::-webkit-scrollbar-thumb:hover {
    background: #606060;
}

/* Light mode scrollbars */
.result-table-container::-webkit-scrollbar {
    height: 8px;
}

.result-table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.result-table-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.result-table-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Compact Filter Panel */
.filter-panel-compact {
    padding: 12px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.filter-panel-compact select[multiple] {
    font-size: 0.875rem;
    border-radius: 4px;
}

.filter-panel-compact .badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.25em 0.5em;
}

#filter-badge {
    margin-left: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

#filter-badge:not(:empty) {
    display: inline-block;
    background: #0d6efd;
    color: white;
    border-radius: 10px;
    padding: 0 6px;
    min-width: 18px;
    text-align: center;
}

/* Dark mode for filters */
body.dark-mode .filter-panel-compact {
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
}

body.dark-mode .filter-panel-compact select {
    background-color: #1a1a1a;
    border-color: #505050;
    color: #e0e0e0;
}

body.dark-mode .filter-panel-compact select option {
    background-color: #2d2d2d;
}

body.dark-mode .filter-panel-compact .text-muted {
    color: #909090 !important;
}

/* ============= DARK MODE: REPORT BUILDER ============= */
body.dark-mode .mode-tab-bar {
    background: #2d2d2d;
    border-bottom-color: #404040;
}

body.dark-mode .mode-tab {
    color: #aaa;
}

body.dark-mode .mode-tab:hover {
    color: #ddd;
    background: rgba(255,255,255,0.05);
}

body.dark-mode .mode-tab.active {
    color: #a78bfa;
    border-bottom-color: #a78bfa;
}

body.dark-mode .rb-conversation {
    border-right-color: #404040;
}

body.dark-mode .rb-messages {
    background: #2d2d2d;
}

body.dark-mode .rb-input-container {
    border-top-color: #404040;
    background: #2d2d2d;
}

body.dark-mode .rb-preview-panel {
    background: #1a1a2e;
}

body.dark-mode .rb-preview-header {
    border-bottom-color: #404040;
}

body.dark-mode .rb-preview-header h4 {
    color: #e0e0e0;
}

body.dark-mode .rb-preview-hint {
    color: #808080;
}

body.dark-mode .rb-columns h5,
body.dark-mode .rb-sample h5 {
    color: #aaa;
}

body.dark-mode .rb-chip {
    background: #2a2a4a;
    color: #ccc;
}

body.dark-mode .rb-chip-number {
    background: #1e3a5f;
    color: #93c5fd;
}

body.dark-mode .rb-chip-currency {
    background: #064e3b;
    color: #6ee7b7;
}

body.dark-mode .rb-chip-percentage {
    background: #78350f;
    color: #fcd34d;
}

body.dark-mode .rb-chip-text {
    background: #3b0764;
    color: #d8b4fe;
}

body.dark-mode .rb-preview-table th {
    background: #2d2d2d;
    color: #ccc;
}

body.dark-mode .rb-preview-table th,
body.dark-mode .rb-preview-table td {
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .rb-sql-code {
    background: #0d0d0d;
    color: #61dafb;
}

/* ============= MOBILE: REPORT BUILDER ============= */
@media (max-width: 768px) {
    .rb-layout {
        flex-direction: column;
    }

    .rb-conversation {
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        flex: 1;
        min-height: 0;
    }

    .rb-preview-panel {
        width: 100%;
        min-width: 0;
        max-height: 40vh;
    }

    .mode-tab {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
}

/* ─── Result Summary Card ─────────────────────────────────────────── */
.result-summary-card {
    background: linear-gradient(135deg, #f0f0ff 0%, #e8f4fd 100%);
    border-left: 4px solid #6F42C1;
    border-radius: 6px;
    padding: 12px 16px;
    margin: 10px 0;
    font-size: 0.88rem;
    line-height: 1.6;
    color: #333;
}

body.dark-mode .result-summary-card {
    background: linear-gradient(135deg, #2d2a3e 0%, #1e2a38 100%);
    border-left-color: #9b59b6;
    color: #e0e0e0;
}

/* ─── PDF Export Button ───────────────────────────────────────────── */
.btn-pdf-export {
    background: #dc3545;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-pdf-export:hover {
    background: #c82333;
    color: white;
}

/* ─── Loading Phases ──────────────────────────────────────────────── */
.loading-phases {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: #6c757d;
    font-style: italic;
    font-size: 0.9rem;
}

.loading-phases .spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 2px;
}

body.dark-mode .loading-phases {
    color: #adb5bd;
}

/* ─── Accessibility: Focus Styles ─────────────────────────────────── */
.mode-tab:focus-visible,
.follow-up-btn:focus-visible,
.btn-live-excel:focus-visible,
.btn-powerbi:focus-visible,
.btn-pdf-export:focus-visible,
.btn-export:focus-visible {
    outline: 3px solid #6F42C1;
    outline-offset: 2px;
}

.interactive-cell:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: -1px;
}

/* ─── Skip Navigation (accessibility) ─────────────────────────────── */
.skip-nav {
    position: absolute;
    top: -40px;
    left: 0;
    background: #6F42C1;
    color: white;
    padding: 8px;
    z-index: 100;
    transition: top 0.2s;
}

.skip-nav:focus {
    top: 0;
}

/* ─── High contrast support for chart elements ────────────────────── */
@media (prefers-contrast: high) {
    .result-summary-card {
        border-left-width: 6px;
        font-weight: 600;
    }
    .rb-chip {
        border-width: 2px;
    }
}
