/* ========================================
   Quantum Beam - Apple HIG Theme
   SF Pro typography, layered surfaces, hairline borders
   ======================================== */

/* Root Variables - Light Mode (Default) */
:root {
    /* Apple surface hierarchy */
    --apple-page: #FEFFFE;
    --apple-shell: #F6F7F9;
    --apple-card: #FFFFFF;
    --apple-elevated: #FFFFFF;
    --apple-text: #1D1D1F;
    --apple-muted: #86868b;
    --apple-blue: #2c8fea;
    --apple-border: rgba(0, 0, 0, 0.06);
    --apple-hover: rgba(0, 0, 0, 0.03);

    /* Blue Theme Colors */
    --primary-50: #F5F9FD;
    --primary-100: #E5EFFB;
    --primary-200: #BFDBFE;
    --primary-300: #93c5fd;
    --primary-400: #2c8fea;
    --primary-500: #2c8fea;
    --primary-600: #2c8fea;
    --primary-700: #2480d4;
    --primary-800: #004999;
    --primary-900: #003D80;
    
    /* Neutral Colors */
    --gray-50: #F6F7F9;
    --gray-100: #FFFFFF;
    --gray-200: #E8E8ED;
    --gray-300: #D2D2D7;
    --gray-400: #AEAEB2;
    --gray-500: #86868b;
    --gray-600: #6E6E73;
    --gray-700: #48484A;
    --gray-800: #2C2C2E;
    --gray-900: #1D1D1F;
    
    /* Semantic Colors */
    --success: #34C759;
    --success-light: rgba(52, 199, 89, 0.1);
    --warning: #FF9500;
    --warning-light: rgba(255, 149, 0, 0.1);
    --error: #FF3B30;
    --error-light: rgba(255, 59, 48, 0.1);
    --info: #2c8fea;
    --info-light: rgba(0, 113, 227, 0.1);
    
    /* Typography — Apple system stack (SF Pro on macOS/iOS, Segoe UI on Windows) */
    --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Segoe UI', system-ui, 'Helvetica Neue', Arial, sans-serif;
    --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Segoe UI', system-ui, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', ui-monospace, 'JetBrains Mono', Menlo, Monaco, Consolas, monospace;
    
    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1rem;

    /* Buttons — compact rectangular controls */
    --btn-radius: 6px;
    --btn-padding-y: 0.4375rem;
    --btn-padding-x: 0.8125rem;
    --btn-font-size: 0.8125rem;
    --btn-font-weight: 500;
    --btn-height: 30px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 16px 0 rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 8px 24px 0 rgba(0, 0, 0, 0.1);
    --shadow-xs: 0 1px 1px 0 rgba(0, 0, 0, 0.04);
    
    /* Typography */
    --text-primary: var(--apple-text);
    --border-color: var(--apple-border);
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Sidebar */
    --sidebar-width: 252px;
    --nav-sidebar-width: 72px;
    --topbar-height: 56px;

    /* Page layout aliases */
    --bg-primary: #FEFFFE;
    --bg-secondary: #F6F7F9;

    /* Code, logs, and data tables — stable across theme (not inverted gray scale) */
    --surface-code-bg: #FFFFFF;
    --surface-code-header-bg: #F6F7F9;
    --surface-code-header-text: #1D1D1F;
    --surface-code-text: #1D1D1F;
    --surface-code-border: rgba(0, 0, 0, 0.08);
    --surface-logs-bg: #FFFFFF;
    --surface-logs-text: #1D1D1F;
    --surface-logs-muted: #6E6E73;
    --surface-logs-border: rgba(0, 0, 0, 0.06);
    --table-header-bg: #F6F7F9;
    --table-header-text: #1D1D1F;
    --table-row-even-bg: #FFFFFF;
    --table-row-odd-bg: #F6F7F9;
    --table-row-text: #1D1D1F;
    --table-row-border: rgba(0, 0, 0, 0.06);

    /* Playground canvas — between shell grey and white cards */
    --playground-surface: #f5f5f3;
}

/* Light mode — explicit when data-theme is set */
html[data-theme="light"] {
    --app-canvas-bg: #f5f5f3;
    --app-chrome-bg: #eeedea;
    --apple-page: #f5f5f3;
    --apple-shell: #eeedea;
    --apple-card: #FFFFFF;
    --apple-elevated: #FFFFFF;
    --gray-50: #f5f5f3;
    --gray-100: #FFFFFF;
    --bg-primary: #f5f5f3;
    --bg-secondary: #f5f5f3;
    --playground-surface: #f5f5f3;
    --surface-code-bg: #FFFFFF;
    --surface-code-header-bg: #F6F7F9;
    --surface-code-header-text: #1D1D1F;
    --surface-code-text: #1D1D1F;
    --surface-code-border: rgba(0, 0, 0, 0.08);
    --surface-logs-bg: #FFFFFF;
    --surface-logs-text: #1D1D1F;
    --surface-logs-muted: #6E6E73;
    --surface-logs-border: rgba(0, 0, 0, 0.06);
    --table-header-bg: #F6F7F9;
    --table-header-text: #1D1D1F;
    --table-row-even-bg: #FFFFFF;
    --table-row-odd-bg: #F6F7F9;
    --table-row-text: #1D1D1F;
    --table-row-border: rgba(0, 0, 0, 0.06);
    --playground-surface: #f5f5f3;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --app-canvas-bg: #101010;
    --app-sidebar-bg: #101010;
    --app-header-bg: #101010;
    --apple-page: #101010;
    --apple-shell: #101010;
    --apple-card: #1c1c1c;
    --apple-elevated: #1C1C1E;
    --apple-text: #F5F5F7;
    --apple-muted: #86868b;
    --apple-blue: #2c8fea;
    --apple-border: rgba(255, 255, 255, 0.06);
    --apple-hover: rgba(255, 255, 255, 0.04);

    --primary-50: rgba(44, 143, 234, 0.12);
    --primary-100: rgba(44, 143, 234, 0.18);
    --primary-200: rgba(44, 143, 234, 0.28);
    --primary-300: #5ca3ec;
    --primary-400: #2c8fea;
    --primary-500: #2c8fea;
    --primary-600: #2c8fea;
    --primary-700: #2480d4;
    --primary-800: #1a6fbf;
    --primary-900: #0f5a9e;
    
    --gray-50: #0A0A0F;
    --gray-100: #15151B;
    --gray-200: #1C1C1E;
    --gray-300: #2C2C2E;
    --gray-400: #48484A;
    --gray-500: #636366;
    --gray-600: #86868b;
    --gray-700: #AEAEB2;
    --gray-800: #D2D2D7;
    --gray-900: #F5F5F7;
    
    --success: #30D158;
    --success-light: rgba(48, 209, 88, 0.12);
    --warning: #FF9F0A;
    --warning-light: rgba(255, 159, 10, 0.12);
    --error: #FF453A;
    --error-light: rgba(255, 69, 58, 0.12);
    --info: #2c8fea;
    --info-light: rgba(44, 143, 234, 0.12);
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 8px 0 rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 4px 16px 0 rgba(0, 0, 0, 0.6);
    --shadow-xl: 0 8px 24px 0 rgba(0, 0, 0, 0.7);
    --shadow-dark-lg: 0 20px 60px rgba(0, 0, 0, 0.8);
    
    --text-primary: var(--apple-text);
    --border-color: var(--apple-border);
    
    --glow-primary: 0 0 16px rgba(44, 143, 234, 0.22);
    --glow-hover: 0 0 24px rgba(44, 143, 234, 0.32);

    --bg-primary: #101010;
    --bg-secondary: #1c1c1c;

    --surface-code-bg: #141414;
    --surface-code-header-bg: #1c1c1c;
    --surface-code-header-text: #f3f4f6;
    --surface-code-text: #e8e8ed;
    --surface-code-border: rgba(255, 255, 255, 0.08);
    --surface-logs-bg: #141414;
    --surface-logs-text: #e8e8ed;
    --surface-logs-muted: #9ca3af;
    --surface-logs-border: rgba(255, 255, 255, 0.08);
    --table-header-bg: #1c1c1c;
    --table-header-text: #f3f4f6;
    --table-row-even-bg: #1c1c1c;
    --table-row-odd-bg: #181818;
    --table-row-text: #e8e8ed;
    --table-row-border: rgba(255, 255, 255, 0.08);

    --playground-surface: #101010;
}

/* Smooth theme transitions - Enhanced */
*,
*::before,
*::after {
    transition: background-color var(--transition-base), 
                color var(--transition-base), 
                border-color var(--transition-base),
                box-shadow var(--transition-base),
                opacity var(--transition-base);
}

/* Faster transitions for interactive elements */
button,
a,
input,
textarea,
select,
.nav-link,
.btn-primary,
.btn-secondary,
.btn-icon,
.tab-btn,
.filter-btn,
.example-query {
    transition: all var(--transition-fast);
}

/* Disable transitions during initial load for performance */
.preload * {
    transition: none !important;
}

/* Reset & Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.47059;
    letter-spacing: -0.011em;
    color: var(--apple-text);
    background: var(--apple-page);
    min-height: 100vh;
}

button,
input,
textarea,
select,
optgroup,
label {
    font-family: inherit;
    letter-spacing: inherit;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    letter-spacing: -0.022em;
    font-weight: 600;
}

code, pre, kbd, samp {
    font-family: var(--font-mono);
}

/* Dark mode body background */
[data-theme="dark"] body {
    background: var(--apple-page);
}

[data-theme="dark"] .container {
    position: relative;
    z-index: 1;
}

/* ============================================
   CUSTOM SCROLLBARS - Dark Mode Enhanced
============================================ */

[data-theme="dark"] ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: var(--gray-50);
    border-radius: 6px;
    border: 1px solid var(--gray-200);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--gray-400), var(--gray-500));
    border-radius: 6px;
    border: 2px solid var(--gray-50);
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--primary-500), var(--primary-600));
    box-shadow: 
        inset 0 0 6px rgba(0, 0, 0, 0.3),
        0 0 10px rgba(44, 143, 234, 0.5);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:active {
    background: linear-gradient(180deg, var(--primary-600), var(--primary-700));
}

/* Firefox scrollbar */
[data-theme="dark"] * {
    scrollbar-width: thin;
    scrollbar-color: var(--gray-500) var(--gray-50);
}

/* Dark Mode Enhancements */
[data-theme="dark"] .header {
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-300);
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
}

[data-theme="dark"] .nav-link:hover,
[data-theme="dark"] .nav-link.active {
    background: rgba(44, 143, 234, 0.15);
    color: var(--primary-600);
    box-shadow: 0 0 10px rgba(44, 143, 234, 0.2);
}

[data-theme="dark"] .hero-title {
    color: var(--gray-900);
}

[data-theme="dark"] .hero-subtitle {
    color: var(--gray-700);
}

[data-theme="dark"] .feature-badge {
    background: var(--gray-100);
    color: var(--gray-800);
    border: 1px solid var(--gray-200);
}

[data-theme="dark"] .query-container {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
}

[data-theme="dark"] .query-input {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--gray-900);
}

[data-theme="dark"] .query-input:focus {
    background: var(--gray-100);
    border-color: var(--primary-500);
    box-shadow: 
        0 0 0 3px rgba(44, 143, 234, 0.2),
        0 0 20px rgba(44, 143, 234, 0.1);
    outline: none;
}

[data-theme="dark"] .example-query {
    background: var(--gray-200);
    color: var(--primary-600);
    border-color: var(--gray-300);
}

[data-theme="dark"] .example-query:hover {
    background: var(--gray-300);
}

[data-theme="dark"] .stat-card {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
}

[data-theme="dark"] .stat-card:hover {
    background: var(--gray-200);
}

[data-theme="dark"] .stat-icon {
    background: var(--gray-200);
}

[data-theme="dark"] .tuning-panel,
[data-theme="dark"] .tuning-panel-horizontal {
    background: var(--gray-100);
    border-color: var(--gray-200);
}

[data-theme="dark"] .tuning-header {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
}

[data-theme="dark"] .tuning-content {
    background: var(--gray-100);
}

[data-theme="dark"] .control-number {
    background: #141414;
    border-color: rgba(255, 255, 255, 0.12);
    color: #f5f5f7;
    -webkit-text-fill-color: #f5f5f7;
}

[data-theme="dark"] .control-slider {
    background: var(--gray-300);
}

[data-theme="dark"] .preset-btn {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-800);
}

[data-theme="dark"] .preset-btn:hover {
    background: var(--gray-200);
}

[data-theme="dark"] .tuning-stats {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

[data-theme="dark"] .loading-header {
    background: linear-gradient(135deg, var(--gray-200), var(--gray-300));
}

[data-theme="dark"] .loading-header h3 {
    color: var(--gray-900);
}

[data-theme="dark"] .loading-time {
    color: var(--gray-800);
}

[data-theme="dark"] .stage {
    background: var(--gray-100);
    border-color: var(--gray-200);
}

[data-theme="dark"] .stage.active {
    background: var(--gray-200);
    border-color: var(--primary-500);
    box-shadow: 
        0 0 0 3px rgba(44, 143, 234, 0.2),
        0 0 20px rgba(44, 143, 234, 0.1);
}

[data-theme="dark"] .results-section {
    background: #1c1c1c;
    padding: var(--spacing-xl);
    border-radius: var(--radius-xl);
}

[data-theme="dark"] .results-header {
    border-bottom-color: var(--gray-200);
}

[data-theme="dark"] .results-tabs {
    border-bottom-color: var(--gray-200);
}

[data-theme="dark"] .tab-btn {
    color: var(--gray-700);
}

[data-theme="dark"] .tab-btn.active {
    color: var(--primary-600);
}

[data-theme="dark"] .table-wrapper {
    border-color: var(--gray-200);
}

[data-theme="dark"] th {
    background: linear-gradient(to bottom, var(--gray-200), var(--gray-300));
    color: var(--gray-900);
    border-bottom: 2px solid var(--gray-400);
}

[data-theme="dark"] .table-wrapper {
    border-color: var(--gray-300);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] td {
    color: var(--gray-900);
}

[data-theme="dark"] tbody tr:hover {
    background: rgba(44, 143, 234, 0.1);
    box-shadow: inset 2px 0 0 var(--primary-500);
}

[data-theme="dark"] tbody tr:nth-child(even) {
    background: var(--gray-50);
}

[data-theme="dark"] .code-block {
    background: var(--surface-code-bg);
    border-color: var(--surface-code-border);
    box-shadow:
        inset 0 1px 3px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .code-header {
    background: var(--surface-code-header-bg);
    color: var(--surface-code-header-text);
    border-bottom-color: var(--surface-code-border);
}

[data-theme="dark"] .btn-copy {
    background: rgba(255, 255, 255, 0.08);
    color: var(--surface-code-header-text);
    border-color: var(--surface-code-border);
}

[data-theme="dark"] .btn-copy:hover {
    background: rgba(255, 255, 255, 0.14);
}

[data-theme="dark"] pre {
    color: var(--surface-code-text);
}

[data-theme="dark"] pre code {
    color: var(--surface-code-text);
}

[data-theme="dark"] .processing-log {
    background: var(--surface-logs-bg);
    border-color: var(--surface-logs-border);
    box-shadow:
        inset 0 1px 3px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .log-header {
    background: var(--surface-code-header-bg);
    color: var(--surface-code-header-text);
    border-bottom-color: var(--surface-logs-border);
}

[data-theme="dark"] .log-content {
    color: #22c55e;
    font-family: var(--font-mono);
}

[data-theme="dark"] .log-timestamp {
    color: var(--primary-600);
}

[data-theme="dark"] .log-component {
    color: #a78bfa;
}

[data-theme="dark"] .log-message {
    color: var(--surface-logs-text);
}

[data-theme="dark"] .footer {
    background: var(--gray-100);
    border-top: 1px solid var(--gray-300);
    box-shadow: 
        0 -1px 3px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .footer-section a:hover {
    color: var(--primary-500);
    text-shadow: 0 0 8px rgba(44, 143, 234, 0.5);
}

[data-theme="dark"] .history-container {
    background: var(--gray-100);
}

[data-theme="dark"] .history-item {
    background: var(--gray-50);
    border-color: var(--gray-200);
}

[data-theme="dark"] .history-item:hover {
    background: var(--gray-200);
}

[data-theme="dark"] .kb-form-card,
[data-theme="dark"] .kb-entries-card,
[data-theme="dark"] .kb-preview-card {
    background: var(--gray-100);
}

[data-theme="dark"] .form-input {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-900);
}

[data-theme="dark"] .form-input:focus {
    background: var(--gray-50);
    border-color: var(--primary-500);
}

[data-theme="dark"] .kb-entry-item {
    background: var(--gray-50);
    border-color: var(--gray-200);
}

[data-theme="dark"] .kb-entry-item:hover {
    background: var(--gray-200);
}

[data-theme="dark"] .modal-content {
    background: var(--gray-100);
}

[data-theme="dark"] .modal-header {
    border-bottom-color: var(--gray-200);
}

[data-theme="dark"] .modal-body {
    background: var(--gray-100);
}

[data-theme="dark"] .modal-footer {
    border-top-color: var(--gray-200);
}

[data-theme="dark"] .modal-info-item {
    background: var(--gray-50);
}

[data-theme="dark"] .btn-secondary {
    background: var(--gray-100);
    color: var(--primary-600);
    border-color: var(--primary-600);
}

[data-theme="dark"] .btn-secondary:hover {
    background: var(--gray-200);
}

[data-theme="dark"] .btn-icon {
    color: var(--gray-700);
}

[data-theme="dark"] .btn-icon:hover {
    background: var(--gray-200);
    color: var(--gray-900);
}

[data-theme="dark"] .toast {
    background: var(--gray-100);
    color: var(--gray-900);
    border: 1px solid var(--gray-300);
    box-shadow: 
        0 10px 25px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.1),
        0 0 20px rgba(44, 143, 234, 0.2);
    backdrop-filter: blur(10px);
}

[data-theme="dark"] .error-section {
    background: var(--gray-100);
    padding: var(--spacing-2xl);
    border-radius: var(--radius-xl);
}

[data-theme="dark"] .feedback-section {
    border-top-color: var(--gray-200);
}

[data-theme="dark"] .btn-feedback {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-800);
}

[data-theme="dark"] .btn-feedback:hover {
    background: var(--gray-200);
}

/* Dark Mode Premium Effects - Enhanced with glows */
[data-theme="dark"] .btn-primary {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    box-shadow: var(--glow-primary), 0 4px 12px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(44, 143, 234, 0.3);
}

[data-theme="dark"] .btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-500));
    box-shadow: var(--glow-hover), 0 6px 20px rgba(0, 0, 0, 0.5);
    transform: translateY(-2px);
    border-color: rgba(44, 143, 234, 0.5);
}

[data-theme="dark"] .btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--glow-primary);
}

[data-theme="dark"] .query-container {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .query-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(44, 143, 234, 0.1), transparent);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

[data-theme="dark"] .stat-card {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-500), var(--primary-600));
    opacity: 0;
    transition: opacity 0.3s;
}

[data-theme="dark"] .stat-card:hover {
    box-shadow: 
        0 8px 24px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(44, 143, 234, 0.2),
        var(--glow-primary);
    transform: translateY(-4px);
    border-color: var(--primary-500);
}

[data-theme="dark"] .stat-card:hover::before {
    opacity: 1;
}

[data-theme="dark"] .history-container {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .kb-form-card,
[data-theme="dark"] .kb-entries-card,
[data-theme="dark"] .kb-preview-card {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .tuning-panel {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .modal-content {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.8),
        0 0 0 1px rgba(255, 255, 255, 0.1),
        var(--glow-primary);
    backdrop-filter: blur(20px);
}

[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

/* Better text contrast in dark mode */
[data-theme="dark"] .hero-title {
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .query-label {
    color: var(--gray-800);
}

[data-theme="dark"] .char-count {
    color: var(--gray-600);
}

[data-theme="dark"] .example-label {
    color: var(--gray-700);
}

/* Dark mode loading state improvements */
[data-theme="dark"] .loading-spinner {
    border-color: var(--gray-300);
    border-top-color: var(--primary-500);
    box-shadow: 0 0 20px rgba(44, 143, 234, 0.3);
}

[data-theme="dark"] .stage-number {
    background: var(--gray-200);
    color: var(--gray-800);
}

[data-theme="dark"] .stage.active .stage-number {
    background: var(--primary-500);
    color: white;
}

[data-theme="dark"] .stage-icon {
    background: var(--gray-200);
    color: var(--gray-700);
}

[data-theme="dark"] .stage.active .stage-icon {
    background: var(--primary-500);
    color: white;
}

/* Dark mode input placeholders */
[data-theme="dark"] .query-input::placeholder {
    color: var(--gray-500);
}

[data-theme="dark"] .form-input::placeholder {
    color: var(--gray-500);
}

/* Dark mode search inputs */
[data-theme="dark"] .search-box input {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-900);
}

[data-theme="dark"] .search-box input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(44, 143, 234, 0.2);
}

[data-theme="dark"] .kb-search-box input {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-900);
}

[data-theme="dark"] .kb-search-box input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(44, 143, 234, 0.2);
}

/* Dark mode filter buttons */
[data-theme="dark"] .filter-btn {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-800);
}

[data-theme="dark"] .filter-btn:hover {
    background: var(--gray-200);
    border-color: var(--gray-400);
}

[data-theme="dark"] .filter-btn.active {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: white;
}

[data-theme="dark"] .kb-filter-btn {
    background: var(--gray-50);
    color: var(--gray-800);
}

[data-theme="dark"] .kb-filter-btn:hover {
    background: var(--gray-200);
}

[data-theme="dark"] .kb-filter-btn.active {
    background: var(--primary-500);
    color: white;
}

/* Dark mode badges and status indicators */
[data-theme="dark"] .history-badge {
    background: var(--primary-500);
}

[data-theme="dark"] .nav-link.active .history-badge {
    background: white;
    color: var(--primary-600);
}

[data-theme="dark"] .kb-entry-category {
    background: var(--primary-200);
    color: var(--primary-800);
}

[data-theme="dark"] .kb-entry-id {
    background: var(--gray-200);
    color: var(--gray-800);
}

/* Dark mode toggle switch — keep gradient treatment */
[data-theme="dark"] .slider-switch {
    background: linear-gradient(90deg, #c9a0b8 0%, #8aaed4 55%, #7eb8d8 100%);
    box-shadow:
        inset 2px 3px 8px rgba(0, 0, 0, 0.22),
        inset -1px -1px 4px rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] input:checked + .slider-switch {
    background: linear-gradient(90deg, #2e1f5c 0%, #5c2d82 55%, #b8367a 100%);
    box-shadow:
        inset 2px 3px 10px rgba(0, 0, 0, 0.45),
        inset -1px -1px 4px rgba(255, 255, 255, 0.05);
}

/* Dark mode dividers */
[data-theme="dark"] .tuning-control {
    border-bottom-color: var(--gray-200);
}

[data-theme="dark"] .form-section {
    border-bottom-color: var(--gray-200);
}

/* Template Management Styles */
.color-scheme-group {
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.color-scheme-group h5 {
    margin: 0 0 0.75rem 0;
    font-size: 0.95rem;
    color: var(--gray-900);
    font-weight: 600;
}

.color-input-group {
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.color-input-group label {
    min-width: 100px;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.color-picker {
    width: 60px;
    height: 38px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
}

.color-text {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

.template-column-item:hover {
    border-color: var(--primary-300);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.template-group-item:hover {
    border-color: var(--primary-300);
}

.template-mode-option:hover {
    border-color: var(--primary-400);
    background: var(--primary-50);
}

.template-mode-option input[type="radio"]:checked ~ div {
    color: var(--primary-700);
}

input[type="radio"]:checked + .template-mode-option,
.template-mode-option:has(input[type="radio"]:checked) {
    border-color: var(--primary-500);
    background: var(--primary-50);
}

/* Container */
.container {
    max-width: 1400px; /* Increased from 1200px for better use of space */
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
}

/* ============================================
   DUAL-PANEL LAYOUT
============================================ */

.main {
    flex: 1;
    min-height: 0;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

.main:has(.playground-canvas) {
    background: var(--playground-surface);
    padding: var(--spacing-sm);
    overflow: hidden;
}

[data-theme="dark"] .main:has(.playground-canvas) {
    background: #101010;
}

[data-theme="dark"] .main {
    background: #101010;
}

.dual-panel-container {
    position: relative;
    flex: 1;
    min-height: 0;
    height: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    --chat-panel-width: 380px;
    overflow: hidden;
}

/* Playground canvas — surround uses --playground-surface; cards use --playground-panel-* */
.playground-canvas {
    --playground-panel-bg: #ffffff;
    --playground-panel-surface: #ffffff;
    --playground-panel-border: rgba(0, 0, 0, 0.07);
    background: var(--playground-surface);
    border-radius: var(--radius-2xl);
    height: 100%;
    min-height: 0;
}

[data-theme="dark"] .playground-canvas {
    --playground-panel-bg: #1c1c1c;
    --playground-panel-surface: #1c1c1c;
    --playground-panel-border: rgba(255, 255, 255, 0.08);
}

.playground-canvas > .results-section,
.playground-canvas > .error-section {
    position: relative;
    overflow: hidden;
    padding-right: 0;
    box-sizing: border-box;
}

.playground-canvas > .error-section {
    overflow-y: auto;
    z-index: 20;
}

/* Legacy alias — left panel removed */
.left-panel {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Empty State */
.empty-state {
    padding: var(--spacing-xl);
}

.empty-content {
    text-align: center;
    color: var(--gray-500);
}

.empty-content i {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
    color: var(--primary-400);
    opacity: 0.5;
}

.empty-content h3 {
    font-size: 1.5rem;
    margin-bottom: var(--spacing-sm);
    color: var(--gray-600);
}

.empty-content p {
    font-size: 1rem;
    color: var(--gray-500);
}

[data-theme="dark"] .empty-content {
    color: var(--gray-600);
}

[data-theme="dark"] .empty-content i {
    color: var(--primary-500);
    opacity: 0.7;
}

[data-theme="dark"] .empty-content h3 {
    color: var(--gray-700);
}

[data-theme="dark"] .empty-content p {
    color: var(--gray-600);
}

/* Floating chat copilot */
.right-panel {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    bottom: var(--spacing-sm);
    width: var(--chat-panel-width);
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 30;
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--apple-border);
    background: var(--apple-card);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

[data-theme="dark"] .chat-header {
    background: var(--gray-200);
    border-bottom-color: var(--gray-300);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.chat-clear-btn {
    background: transparent;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.chat-clear-btn:hover {
    background: var(--error-light);
    border-color: var(--error);
    color: var(--error);
}

.chat-clear-btn:active {
    transform: scale(0.95);
}

[data-theme="dark"] .chat-clear-btn {
    border-color: var(--gray-400);
    color: var(--gray-400);
}

[data-theme="dark"] .chat-clear-btn:hover {
    background: var(--error-dark);
    border-color: var(--error);
    color: var(--error);
}

.chat-title i {
    font-size: 1.5rem;
    color: var(--primary-600);
}

.chat-title h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

[data-theme="dark"] .chat-title h2 {
    color: var(--gray-900);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.message {
    display: flex;
    gap: var(--spacing-sm);
    animation: messageSlideIn 0.3s ease-out;
}

.user-message {
    flex-direction: row;
    justify-content: flex-start;
}

.user-message .message-avatar {
    order: 2;
    margin-left: var(--spacing-sm);
    margin-right: 0;
}

.user-message .message-content {
    order: 1;
    margin-left: auto;
    margin-right: 0;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
}

.user-message .message-avatar {
    background: var(--primary-500);
    color: white;
}

.bot-message .message-avatar {
    background: var(--gray-200);
    color: var(--gray-700);
}

[data-theme="dark"] .bot-message .message-avatar {
    background: var(--gray-300);
    color: var(--gray-800);
}

.message-content {
    flex: 1;
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    max-width: 85%;
}

.user-message .message-content {
    background: var(--primary-500);
    color: white;
    border-bottom-right-radius: 4px;
}

.bot-message .message-content {
    background: var(--gray-100);
    color: var(--gray-900);
    border-bottom-left-radius: 4px;
}

[data-theme="dark"] .bot-message .message-content {
    background: var(--gray-200);
    color: var(--gray-900);
}

.message-content p {
    margin: 0 0 var(--spacing-sm) 0;
    line-height: 1.6;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-suggestions {
    font-size: 0.875rem;
    font-weight: 600;
    margin-top: var(--spacing-sm);
    color: var(--gray-600);
}

[data-theme="dark"] .message-suggestions {
    color: var(--gray-700);
}

.suggestion-list {
    list-style: none;
    padding: 0;
    margin: var(--spacing-sm) 0 0 0;
}

.suggestion-list li {
    padding: var(--spacing-xs) 0;
    padding-left: var(--spacing-md);
    position: relative;
    color: var(--gray-600);
    font-size: 0.875rem;
}

.suggestion-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--primary-500);
}

[data-theme="dark"] .suggestion-list li {
    color: var(--gray-700);
}

/* Query Result Cards */
.query-result-card {
    margin: var(--spacing-md) 0;
    padding: var(--spacing-md);
    background: var(--gray-50);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    animation: messageSlideIn 0.3s ease-out;
}

[data-theme="dark"] .query-result-card {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

.query-result-card:hover {
    border-color: var(--primary-400);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.query-result-card.active {
    border-color: var(--primary-500);
    background: var(--primary-50);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .query-result-card.active {
    background: var(--primary-100);
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(44, 143, 234, 0.2);
}

.result-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-sm);
    gap: var(--spacing-sm);
}

.result-card-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 600;
    color: var(--gray-900);
    font-size: 1rem;
    flex: 1;
}

.result-card-title i {
    color: var(--primary-500);
    font-size: 1.1rem;
}

.result-card-time {
    font-size: 0.75rem;
    color: var(--gray-500);
    white-space: nowrap;
}

[data-theme="dark"] .result-card-time {
    color: var(--gray-600);
}

.result-card-summary {
    color: var(--gray-700);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: var(--spacing-sm);
}

[data-theme="dark"] .result-card-summary {
    color: var(--gray-800);
}

.result-card-meta {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-xs);
}

.result-card-stats {
    display: flex;
    gap: var(--spacing-md);
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--gray-600);
}

.result-card-stats span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.result-card-stats i {
    font-size: 0.75rem;
    color: var(--primary-500);
}

[data-theme="dark"] .result-card-stats {
    color: var(--gray-700);
}

.result-card-badges {
    display: flex;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
}

.result-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--primary-100);
    color: var(--primary-700);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

[data-theme="dark"] .result-badge {
    background: var(--primary-200);
    color: var(--primary-800);
}

.result-badge i {
    font-size: 0.7rem;
}

.result-card-footer {
    margin-top: var(--spacing-xs);
    padding-top: var(--spacing-xs);
    border-top: 1px solid var(--gray-200);
}

[data-theme="dark"] .result-card-footer {
    border-top-color: var(--gray-300);
}

.result-card-hint {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-style: italic;
}

[data-theme="dark"] .result-card-hint {
    color: var(--gray-600);
}

/* Chat Input */
.chat-input-container {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

[data-theme="dark"] .chat-input-container {
    background: var(--gray-200);
    border-top-color: var(--gray-300);
}

.chat-input-wrapper {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: var(--spacing-md);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    resize: none;
    background: white;
    color: var(--gray-900);
    min-height: 44px;
    max-height: 120px;
    line-height: 1.5;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .chat-input {
    background: var(--gray-100);
    border-color: var(--gray-400);
    color: var(--gray-900);
}

[data-theme="dark"] .chat-input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(44, 143, 234, 0.2);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary-500);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--primary-600);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.chat-send-btn:active {
    transform: translateY(0);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-input-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--spacing-xs);
}

.chat-input-footer .char-count {
    font-size: 0.75rem;
    color: var(--gray-500);
}

[data-theme="dark"] .chat-input-footer .char-count {
    color: var(--gray-600);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .dual-panel-container {
        height: auto;
        min-height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg));
    }

    .playground-canvas > .results-section,
    .playground-canvas > .error-section {
        position: relative;
        inset: auto;
        min-height: 420px;
        padding-right: var(--spacing-lg);
        padding-bottom: calc(400px + var(--spacing-lg));
    }

    .right-panel {
        top: auto;
        left: var(--spacing-md);
        right: var(--spacing-md);
        bottom: var(--spacing-md);
        width: auto;
        height: 380px;
    }
}

@media (max-width: 768px) {
    .dual-panel-container {
        padding: 0 var(--spacing-md);
        gap: var(--spacing-md);
    }
    
    .chat-messages {
        padding: var(--spacing-md);
    }
    
    .message-content {
        max-width: 90%;
    }
}

/* Header */
.header {
    background: white;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--gray-200);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: -0.1rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-700);
}

.logo-image {
    height: 40px;
    width: auto;
    object-fit: contain;
    filter: brightness(1);
    transition: filter 0.2s ease;
}

[data-theme="dark"] .logo-image {
    filter: brightness(1.3) contrast(1.1);
    opacity: 1;
}

.logo-text-container {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-700);
    line-height: 1.2;
}

.logo-subtext {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--gray-600);
    line-height: 1;
    text-transform: lowercase;
    letter-spacing: 0.5px;
}

[data-theme="dark"] .logo-subtext {
    color: var(--gray-400);
}

.logo i {
    font-size: 1.5rem;
}

.nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

.nav-link {
    text-decoration: none;
    color: var(--gray-600);
    font-weight: 500;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.nav-link:hover, .nav-link.active {
    color: var(--primary-600);
    background: var(--primary-50);
}

/* Hamburger Menu Button */
.hamburger-menu-btn {
    margin-right: var(--spacing-md);
    padding: var(--spacing-sm);
    background: transparent;
    border: none;
    color: var(--gray-600);
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.hamburger-menu-btn:hover {
    background: var(--gray-100);
    color: var(--primary-600);
}

[data-theme="dark"] .hamburger-menu-btn {
    color: var(--gray-400);
}

[data-theme="dark"] .hamburger-menu-btn:hover {
    background: var(--gray-200);
    color: var(--primary-500);
}

/* Sidebar Menu (Claude/ChatGPT style) */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100vh;
    background: var(--apple-card);
    border-right: 1px solid var(--apple-border);
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform var(--transition-base), left var(--transition-base), visibility var(--transition-base);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}

[data-theme="dark"] .sidebar-menu {
    background: var(--apple-card);
    border-right: 1px solid var(--apple-border);
}

.sidebar-menu.active {
    left: var(--nav-sidebar-width, 252px);
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--gray-200);
}

[data-theme="dark"] .sidebar-header {
    border-bottom-color: var(--gray-300);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

[data-theme="dark"] .sidebar-header h2 {
    color: var(--gray-900);
}

.sidebar-close-btn {
    padding: var(--spacing-sm);
    background: transparent;
    border: none;
    color: var(--gray-600);
    cursor: pointer;
    font-size: 1.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.sidebar-close-btn:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

[data-theme="dark"] .sidebar-close-btn {
    color: var(--gray-400);
}

[data-theme="dark"] .sidebar-close-btn:hover {
    background: var(--gray-200);
    color: var(--gray-900);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.sidebar-new-conversation-btn {
    width: 100%;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-weight: 500;
}

.sidebar-conversations-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    overflow-y: auto;
}

.sidebar-conversation-item {
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    position: relative;
}

.sidebar-conversation-item:hover {
    background: var(--gray-100);
    border-color: var(--gray-200);
}

[data-theme="dark"] .sidebar-conversation-item:hover {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

.sidebar-conversation-item.active {
    background: var(--primary-50);
    border-color: var(--primary-200);
}

[data-theme="dark"] .sidebar-conversation-item.active {
    background: var(--primary-200);
    border-color: var(--primary-400);
}

.sidebar-conversation-title {
    font-weight: 500;
    color: var(--gray-900);
    font-size: 0.9375rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

[data-theme="dark"] .sidebar-conversation-title {
    color: var(--gray-900);
}

.sidebar-conversation-preview {
    font-size: 0.8125rem;
    color: var(--gray-600);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
}

[data-theme="dark"] .sidebar-conversation-preview {
    color: var(--gray-500);
}

.sidebar-conversation-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: var(--spacing-xs);
}

[data-theme="dark"] .sidebar-conversation-meta {
    color: var(--gray-400);
}

.sidebar-conversation-actions {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    display: flex;
    gap: var(--spacing-xs);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.sidebar-conversation-item:hover .sidebar-conversation-actions {
    opacity: 1;
}

.sidebar-conversation-delete-btn {
    padding: var(--spacing-xs);
    background: transparent;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-conversation-delete-btn:hover {
    background: var(--error-light);
    color: var(--error);
}

[data-theme="dark"] .sidebar-conversation-delete-btn:hover {
    background: var(--error-light);
    color: var(--error);
}

.sidebar-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-2xl);
    text-align: center;
    color: var(--gray-500);
}

.sidebar-empty i {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.sidebar-empty p {
    font-size: 1rem;
    margin-bottom: var(--spacing-xs);
}

.sidebar-empty-subtitle {
    font-size: 0.875rem;
    color: var(--gray-400);
}

[data-theme="dark"] .sidebar-empty {
    color: var(--gray-400);
}

[data-theme="dark"] .sidebar-empty-subtitle {
    color: var(--gray-500);
}

/* Hero Section */
.hero {
    text-align: center;
    padding: var(--spacing-2xl) 0;
}

.hero-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--gray-900);
    margin-bottom: var(--spacing-md);
    line-height: 1.2;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--gray-600);
    margin-bottom: var(--spacing-xl);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.hero-features {
    display: flex;
    justify-content: center;
    gap: var(--spacing-lg);
    flex-wrap: wrap;
}

.feature-badge {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    font-weight: 500;
    color: var(--gray-700);
}

.feature-badge i {
    color: var(--success);
}

/* Query Section */
.query-section {
    margin-bottom: var(--spacing-2xl);
}

.query-container {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--spacing-xl);
    width: 100%;
    margin-bottom: var(--spacing-2xl);
}

.query-input-wrapper {
    width: 100%;
    max-width: 100%;
}

.query-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--spacing-md);
}

.query-label i {
    color: var(--primary-600);
}

/* Document Scope Section */
.document-scope-section {
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
}

.scope-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 600;
    color: var(--gray-700);
    cursor: pointer;
    user-select: none;
}

.scope-header i {
    color: var(--primary-600);
}

.scope-toggle {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    padding: var(--spacing-xs);
    transition: color var(--transition-fast);
}

.scope-toggle:hover {
    color: var(--primary-600);
}

.scope-content {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--gray-200);
}

.scope-group {
    margin-bottom: var(--spacing-lg);
}

.scope-group:last-child {
    margin-bottom: 0;
}

.scope-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: var(--spacing-sm);
    font-size: 0.9rem;
}

.scope-label i {
    color: var(--primary-600);
}

.scope-options {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.scope-option {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.scope-option:hover {
    background: var(--primary-50);
    border-color: var(--primary-300);
}

.scope-option input[type="radio"],
.scope-option input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    appearance: none;
    width: 1.15rem;
    height: 1.15rem;
    border: 2px solid var(--gray-400);
    display: grid;
    place-content: center;
    transition: all var(--transition-fast);
}

.scope-option input[type="radio"] {
    border-radius: 50%;
}

.scope-option input[type="checkbox"] {
    border-radius: 4px;
}

.scope-option input[type="radio"]::before,
.scope-option input[type="checkbox"]::before {
    content: "";
    width: 0.65rem;
    height: 0.65rem;
    transform: scale(0);
    transition: transform var(--transition-fast);
    box-shadow: inset 1em 1em var(--primary-600);
}

.scope-option input[type="radio"]::before {
    border-radius: 50%;
}

.scope-option input[type="checkbox"]::before {
    border-radius: 2px;
}

.scope-option input[type="radio"]:checked,
.scope-option input[type="checkbox"]:checked {
    border-color: var(--primary-600);
    background-color: var(--primary-50);
}

.scope-option input[type="radio"]:checked::before,
.scope-option input[type="checkbox"]:checked::before {
    transform: scale(1);
}

.scope-option input[type="radio"]:checked + span,
.scope-option input[type="checkbox"]:checked + span {
    font-weight: 600;
    color: var(--primary-700);
}

.folder-list {
    margin-top: var(--spacing-xs);
    margin-left: var(--spacing-lg);
    max-height: 200px;
    overflow-y: auto;
}

.folder-option {
    font-size: 0.9rem;
}

.folder-loading,
.folder-empty,
.folder-error {
    padding: var(--spacing-sm);
    color: var(--gray-500);
    font-size: 0.85rem;
    font-style: italic;
}

.folder-error {
    color: var(--error);
}

[data-theme="dark"] .document-scope-section {
    background: var(--gray-100);
    border-color: var(--gray-200);
}

[data-theme="dark"] .scope-option {
    background: var(--gray-50);
    border-color: var(--gray-200);
}

[data-theme="dark"] .scope-option:hover {
    background: var(--gray-200);
    border-color: var(--primary-400);
}

.input-group {
    position: relative;
}

.query-input {
    width: 100%;
    padding: var(--spacing-lg);
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--gray-900);
    background: var(--gray-50);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    resize: vertical;
    transition: all var(--transition-base);
}

.query-input:focus {
    outline: none;
    border-color: var(--primary-500);
    background: white;
    box-shadow: 0 0 0 3px var(--primary-100);
}

.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--spacing-md);
}

.char-count {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-icon {
    min-height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    font-family: var(--font-sans);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    border: none;
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    line-height: 1.2;
    white-space: nowrap;
}

.btn-primary {
    background: var(--apple-blue);
    color: white;
    box-shadow: none;
}

.btn-primary:hover {
    background: var(--primary-700);
    transform: none;
    box-shadow: none;
    filter: brightness(1.05);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    transform: none;
    opacity: 0.6;
}

.btn-secondary {
    background: var(--apple-elevated);
    color: var(--apple-text);
    border: 1px solid var(--apple-border);
}

.btn-secondary:hover {
    background: var(--apple-hover);
}

.btn-icon {
    width: var(--btn-height);
    height: var(--btn-height);
    min-width: var(--btn-height);
    padding: 0;
    background: transparent;
    color: var(--gray-600);
    border-radius: var(--btn-radius);
}

.btn-icon:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

/* Danger Button (Small) - for destructive actions */
.btn-danger-sm {
    min-height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    font-family: var(--font-sans);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    line-height: 1.2;
    background: var(--error-light);
    color: var(--error);
    border: 1px solid var(--error);
}

.btn-danger-sm:hover {
    background: var(--error);
    color: white;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-danger-sm:active {
    transform: translateY(0);
}

.btn-danger-sm:disabled {
    background: var(--gray-300);
    color: var(--gray-500);
    border-color: var(--gray-400);
    cursor: not-allowed;
    transform: none;
}

/* Example Queries */
.example-queries {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
}

.example-label {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-right: var(--spacing-sm);
}

.example-query {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
    background: var(--primary-50);
    color: var(--primary-700);
    border: 1px solid var(--primary-200);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.example-query:hover {
    background: var(--primary-100);
    border-color: var(--primary-300);
}

/* In-tab processing state (Dashboard spinner / other tabs message) */
.tab-processing-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    min-height: 280px;
    padding: var(--spacing-xl);
    color: var(--gray-500);
}

.tab-processing-state i {
    font-size: 2rem;
    margin-bottom: var(--spacing-md);
    color: var(--primary-400);
    opacity: 0.7;
}

.tab-processing-state .loading-spinner {
    margin-bottom: var(--spacing-md);
}

.tab-processing-state .loading-text {
    margin: 0;
    max-width: 420px;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

#formattedResults:has(.tab-processing-state),
#rawResults:has(.tab-processing-state),
#insightsContent:has(.tab-processing-state),
#forecastContent:has(.tab-processing-state) {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 280px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--primary-200);
    border-top-color: var(--primary-600);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

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

/* Legacy loading stage styles (kept for audit log tab compatibility) */
.loading-stages {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xl);
}

.stage {
    display: grid;
    grid-template-columns: 40px 50px 1fr 80px;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    background: white;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    opacity: 0.6;
    transition: all var(--transition-base);
}

.stage.active {
    opacity: 1;
    background: var(--primary-50);
    border-color: var(--primary-600);
    box-shadow: 0 0 0 3px var(--primary-100);
    transform: scale(1.02);
}

.stage.completed {
    opacity: 0.8;
    background: var(--success-light);
    border-color: var(--success);
}

.stage-number {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    color: var(--gray-600);
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.875rem;
}

.stage.active .stage-number {
    background: var(--primary-600);
    color: white;
    animation: pulse 2s ease-in-out infinite;
}

.stage.completed .stage-number {
    background: var(--success);
    color: white;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.stage-icon {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    border-radius: var(--radius-md);
    color: var(--gray-500);
    font-size: 1.25rem;
}

.stage.active .stage-icon {
    background: var(--primary-600);
    color: white;
}

.stage.completed .stage-icon {
    background: var(--success);
    color: white;
}

.stage-content {
    flex: 1;
}

.stage-title {
    font-weight: 600;
    color: var(--gray-800);
    font-size: 0.9375rem;
    margin-bottom: var(--spacing-xs);
}

.stage-text {
    font-size: 0.8125rem;
    color: var(--gray-600);
}

.stage.active .stage-text {
    color: var(--primary-700);
}

.stage-details {
    margin-top: var(--spacing-xs);
    color: var(--gray-500);
    font-size: 0.75rem;
    line-height: 1.4;
}

.stage.active .stage-details {
    display: block !important;
}

.stage-time {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: var(--spacing-xs);
}

.stage.completed .stage-time {
    color: var(--success);
    font-weight: 600;
}

.stage-status {
    font-size: 0.625rem;
    color: var(--gray-400);
}

.stage.active .stage-status {
    color: var(--primary-600);
    animation: blink 1s ease-in-out infinite;
}

.stage.completed .stage-status {
    color: var(--success);
}

.stage.completed .stage-status i::before {
    content: "\f00c";  /* Checkmark */
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Processing Log */
.processing-log {
    background: var(--surface-logs-bg);
    border: 1px solid var(--surface-logs-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    max-height: 400px;
    margin-top: var(--spacing-lg);
    flex-shrink: 0;
    overflow-y: auto;
}

.log-header {
    padding: var(--spacing-md);
    background: var(--surface-code-header-bg);
    color: var(--surface-code-header-text);
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    border-bottom: 1px solid var(--surface-logs-border);
}

.log-content {
    padding: var(--spacing-md);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.6;
    color: var(--surface-logs-text);
    max-height: 250px;
    overflow-y: auto;
}

.log-entry {
    margin-bottom: var(--spacing-xs);
    padding: var(--spacing-xs) 0;
    border-bottom: 1px solid var(--surface-logs-border);
}

.log-entry.debug-entry {
    background: rgba(59, 130, 246, 0.05);
    padding: var(--spacing-sm);
    margin: var(--spacing-xs) 0;
    border-radius: 4px;
    border-left: 3px solid #3b82f6;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-main {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.log-timestamp {
    color: #60a5fa;
    margin-right: var(--spacing-sm);
}

.log-component {
    color: #a78bfa;
    margin-right: var(--spacing-sm);
    font-weight: 600;
    min-width: 180px;
    display: inline-block;
}

.log-component.success {
    color: #10b981;
}

.log-component.error {
    color: #ef4444;
}

.log-component.warning {
    color: #f59e0b;
}

.log-message {
    color: var(--surface-logs-text);
    flex: 1;
}

.details-toggle {
    background: none;
    border: none;
    color: #60a5fa;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.9rem;
    margin-left: auto;
}

.details-toggle:hover {
    background: rgba(44, 143, 234, 0.1);
    color: #93c5fd;
}

.log-details {
    margin-top: var(--spacing-sm);
    padding: var(--spacing-sm);
    background: var(--surface-code-header-bg);
    border-radius: 4px;
    border-left: 2px solid #3b82f6;
    overflow-x: auto;
}

.log-details pre {
    margin: 0;
    color: var(--surface-code-text);
    font-size: 0.85rem;
    font-family: var(--font-mono);
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* --- TAB SCROLLING FIX --- */
/* Critical: All flex containers in the scrolling chain must have min-height: 0 */
/* This allows children to shrink and enables proper overflow scrolling */

/* Results Section */
.results-section {
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0 !important; /* CRITICAL: Allow children to shrink */
    overflow: hidden;
    height: 100%;
    padding: var(--spacing-lg);
    padding-bottom: 0; /* Remove bottom padding to prevent cutoff */
    box-sizing: border-box;
    position: relative; /* Ensure proper stacking context */
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--gray-200);
    flex: 0 0 auto; /* Fixed header - no shrinking */
    position: relative;
    z-index: 50; /* Ensure header is above content but below tabs */
}

.results-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.results-title h3 {
    font-size: 1.5rem;
    color: var(--gray-900);
}

.success-icon {
    color: var(--success);
    font-size: 1.5rem;
}

.results-meta {
    font-size: 0.875rem;
    color: var(--gray-600);
}

/* Tabs — bottom bar in Playground */
.results-tabs {
    display: flex;
    gap: var(--spacing-sm);
    flex: 0 0 auto;
    position: relative;
    z-index: 100;
    background: transparent;
}

.results-tabs-bottom {
    border-top: 2px solid var(--gray-200);
    border-bottom: none;
    margin-top: auto;
    margin-bottom: 0;
    padding-top: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    flex-shrink: 0;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
}

[data-theme="dark"] .results-tabs-bottom {
    border-top-color: var(--gray-300);
}

.results-tabs:not(.results-tabs-bottom) {
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: var(--spacing-lg);
}

.tab-btn {
    padding: var(--spacing-md) var(--spacing-lg);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    position: relative;
    z-index: 101; /* Ensure tabs are clickable - higher than tabs container */
    pointer-events: auto !important; /* Force tabs to be clickable */
    user-select: none; /* Prevent text selection on click */
    -webkit-tap-highlight-color: transparent; /* Remove mobile tap highlight */
}

.tab-btn:hover {
    color: var(--primary-600);
}

.tab-btn.active {
    color: var(--primary-600);
    border-bottom-color: var(--primary-600);
}

.results-tabs-bottom .tab-btn {
    border-bottom: 2px solid transparent;
    border-top: 2px solid transparent;
    margin-bottom: 0;
}

.results-tabs-bottom .tab-btn.active {
    border-bottom-color: transparent;
    border-top-color: var(--primary-600);
}

/* Per-tab empty state in Playground */
.tab-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    min-height: 0;
    padding: var(--spacing-xl);
    color: var(--gray-500);
}

.tab-empty-state i {
    font-size: 2.5rem;
    margin-bottom: var(--spacing-md);
    color: var(--primary-400);
    opacity: 0.55;
}

.tab-empty-state h4 {
    margin: 0 0 var(--spacing-sm);
    font-size: 1.125rem;
    color: var(--gray-700);
    font-weight: 600;
}

.tab-empty-state p {
    margin: 0;
    max-width: 420px;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--gray-500);
}

[data-theme="dark"] .tab-empty-state h4 {
    color: var(--gray-800);
}

[data-theme="dark"] .tab-empty-state p {
    color: var(--gray-600);
}

.tab-pane {
    display: none !important; /* Force hide all tabs by default */
    width: 100%;
}

.tab-pane.active {
    display: flex !important; /* Only show active tab */
    flex-direction: column;
    animation: fadeIn var(--transition-base);
    width: 100%;
    flex: 1 1 0; /* Use 0 instead of auto to force proper height calculation */
    min-height: 0 !important; /* CRITICAL: Enable scrolling */
    max-height: 100% !important; /* Constrain to parent height to enable scrolling */
    height: 100% !important; /* Ensure it takes full height of parent */
    overflow-y: auto; /* Scroll only when content overflows */
    overflow-x: hidden;
}

/* Empty tabs — no scroll chrome when content fits */
.tab-pane.active:has(.tab-empty-state),
.tab-pane.active:has(.tab-processing-state) {
    overflow-y: hidden;
}

/* Remove double scrollbar for raw-tab and sql-tab - let inner containers handle scrolling */
#raw-tab.active,
#sql-tab.active {
    overflow-y: hidden !important; /* Remove scrollbar from tab-pane */
    overflow-x: hidden !important;
    touch-action: pan-y; /* Enable vertical scrolling on touch devices */
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 1; /* Ensure tab content is above background - lower than tabs */
    overscroll-behavior: contain;
    will-change: scroll-position;
    padding-bottom: 0 !important; /* Remove any padding from tab-pane itself */
}

#formatted-tab {
    padding: var(--spacing-md);
    padding-bottom: calc(var(--spacing-2xl) * 8) !important; /* Significantly increased padding at bottom - force with !important */
    min-height: 0;
    overflow: visible; /* Parent .tab-pane.active handles scrolling */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto; /* Allow tab to grow and fill available space */
    width: 100%; /* Ensure full width */
    height: auto !important; /* Allow content to determine height - important for scrolling */
    max-height: none !important; /* Don't constrain height - let it grow so parent can scroll */
    position: relative; /* Ensure proper positioning */
}

#formatted-tab:has(.tab-empty-state),
#formatted-tab:has(.tab-processing-state) {
    padding-bottom: var(--spacing-md) !important;
    height: 100% !important;
    max-height: 100% !important;
}

#raw-tab {
    padding: var(--spacing-md);
    box-sizing: border-box;
    height: 100% !important; /* Take full height of parent */
    min-height: 0 !important; /* Allow shrinking */
    max-height: 100% !important; /* Constrain to parent height */
    position: relative; /* Ensure proper positioning */
    display: flex; /* Use flexbox for proper layout */
    flex-direction: column; /* Stack content vertically */
    overflow: hidden !important; /* Remove scrollbar from tab-pane */
}

#raw-tab.active,
#sql-tab.active,
#insights-tab.active,
#logs-tab.active {
    display: flex !important; /* Override .tab-pane to ensure visibility when active */
    flex-direction: column;
}

#raw-tab.active > div:first-child {
    flex-shrink: 0;
}

#raw-tab.active .table-wrapper {
    flex: 1 1 auto !important; /* Allow it to grow and fill available space */
    min-height: 400px !important; /* Set minimum height to ensure table is visible */
    max-height: 100% !important; /* Constrain to parent height */
    overflow-x: auto !important; /* Allow horizontal scrolling for wide tables */
    overflow-y: auto !important; /* Enable vertical scrolling - this will be the only scrollbar */
    margin-bottom: var(--spacing-md) !important; /* Reduced margin */
    padding-bottom: var(--spacing-md) !important; /* Reduced padding */
    width: 100%; /* Ensure full width */
    position: relative; /* Ensure proper positioning */
    height: 100% !important; /* Take full height of parent */
}

#raw-tab.active .table-wrapper:has(.tab-empty-state),
#raw-tab.active .table-wrapper:has(.tab-processing-state) {
    min-height: 0 !important;
    overflow-y: hidden !important;
    display: flex;
    flex-direction: column;
}

#insights-tab.active:has(.tab-empty-state),
#insights-tab.active:has(.tab-processing-state),
#forecast-tab.active:has(.tab-empty-state),
#forecast-tab.active:has(.tab-processing-state),
#logs-tab.active:has(.tab-empty-state) {
    overflow-y: hidden !important;
}

#insightsContent:has(.tab-empty-state),
#insightsContent:has(.tab-processing-state),
#forecastContent:has(.tab-empty-state),
#forecastContent:has(.tab-processing-state),
#logsContent:has(.tab-empty-state) {
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Fix raw tab table overflow issue */
#raw-tab.active .table-wrapper table {
    margin-bottom: calc(var(--spacing-2xl) * 2) !important; /* Extra margin on table itself */
    width: 100% !important; /* Ensure table takes full width */
    min-height: 300px !important; /* Ensure table has minimum height */
}

/* Ensure table body can grow */
#raw-tab.active .table-wrapper tbody {
    display: table-row-group; /* Ensure proper table layout */
}

/* Remove the ::after spacer for raw-tab - no longer needed */
#raw-tab.active::after {
    display: none !important;
}

#sql-tab {
    padding: 0;
    box-sizing: border-box;
    height: 100% !important; /* Take full height of parent */
    min-height: 0 !important; /* Allow shrinking */
    max-height: 100% !important; /* Constrain to parent height */
    position: relative; /* Ensure proper positioning */
    overflow: hidden !important; /* Remove scrollbar from tab-pane */
}

#sql-tab.active {
    display: flex !important;
    flex-direction: column;
    padding: var(--spacing-md);
    height: 100% !important;
    overflow: hidden !important; /* Remove scrollbar from tab-pane */
}

#sql-tab.active .code-block {
    margin: 0 !important; /* Remove margins */
    flex: 1 1 auto !important; /* Grow to fill available space */
    min-height: 0; /* Allow shrinking */
    max-height: 100% !important; /* Constrain to parent height */
    height: 100% !important; /* Take full height */
    display: flex !important;
    flex-direction: column;
    overflow: hidden !important; /* Remove scrollbar from code-block container */
}

/* Ensure SQL code block pre has proper scrolling - this will be the only scrollbar */
#sql-tab.active .code-block pre {
    padding: var(--spacing-md) !important; /* Standard padding */
    margin: 0 !important; /* Remove margins */
    overflow-y: auto !important; /* Enable vertical scrolling - this will be the only scrollbar */
    overflow-x: auto !important; /* Keep horizontal scrolling for long lines */
    max-height: 100% !important; /* Constrain to parent height */
    height: 100% !important; /* Take full height */
    flex: 1 1 auto !important; /* Grow to fill available space */
    min-height: 0 !important; /* Allow shrinking */
}

#insights-tab {
    padding: var(--spacing-md);
    padding-bottom: calc(var(--spacing-2xl) * 8) !important; /* Significantly increased padding at bottom - force with !important */
    box-sizing: border-box;
    height: auto !important; /* Allow content to determine height */
    max-height: none !important; /* Don't constrain height */
    position: relative; /* Ensure proper positioning */
}

#insights-tab #insightsContent {
    min-height: 0;
    margin-bottom: calc(var(--spacing-2xl) * 6) !important; /* Significantly increased margin at bottom to ensure content is visible */
    padding-bottom: calc(var(--spacing-2xl) * 4) !important; /* Additional padding at bottom */
    width: 100%; /* Ensure full width */
    height: auto !important; /* Allow content to determine height */
    max-height: none !important; /* Don't constrain height */
    position: relative; /* Ensure proper positioning */
}

/* Add extra space after insights content */
#insights-tab #insightsContent::after {
    content: '';
    display: block;
    height: calc(var(--spacing-2xl) * 4) !important; /* Large spacer to ensure bottom content is visible */
    width: 100%;
    flex-shrink: 0;
}

/* Add extra scrollable space at the end of insights tab - only when active */
#insights-tab.active::after {
    content: '';
    display: block;
    height: calc(var(--spacing-2xl) * 6) !important; /* Large spacer to ensure bottom content is visible */
    width: 100%;
    flex-shrink: 0;
    position: relative;
    z-index: 0; /* Ensure it's behind content */
}

/* Remove the ::after spacer for sql-tab - no longer needed */
#sql-tab.active::after {
    display: none !important;
}

#logs-tab {
    /* Logs tab has its own container with scrolling */
    padding: 0;
}

/* Logs Tab */
.logs-container {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
}

.logs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
    background: var(--gray-50);
}

[data-theme="dark"] .logs-header {
    background: var(--gray-200);
    border-bottom-color: var(--gray-300);
}

.logs-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

[data-theme="dark"] .logs-header h3 {
    color: var(--gray-900);
}

.logs-content {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-md);
    padding-bottom: calc(var(--spacing-2xl) * 5);
    background: var(--surface-logs-bg);
    color: var(--surface-logs-text);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    min-height: 0;
}

.logs-content .log-entry {
    margin-bottom: var(--spacing-xs);
    padding: var(--spacing-xs) 0;
    border-bottom: 1px solid var(--surface-logs-border);
}

.btn-sm {
    min-height: 26px;
    padding: 0.3125rem 0.625rem;
    font-size: 0.75rem;
}

/* Container that holds all tab panes */
.tab-content {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;      /* let it take remaining height */
    display: flex;
    flex-direction: column;
    min-height: 0;       /* allow children to shrink vertically */
    overflow: hidden;    /* keep scroll only on panes, not on this wrapper */
    position: relative;
    height: 100%; /* Ensure it takes full available height */
    max-height: 100%; /* Constrain to parent */
}

#formattedResults {
    width: 100%;
    max-width: 100%;
    min-height: 200px; /* Minimum height to ensure content area is visible */
    overflow: visible; /* Let content flow naturally, parent handles scrolling */
    display: block; /* Ensure content is displayed */
    position: relative; /* Ensure proper positioning */
    flex: 1 1 auto; /* Allow content to grow and fill available space */
    visibility: visible; /* Ensure visibility */
    opacity: 1; /* Ensure opacity */
    height: auto !important; /* Allow height to grow with content - enables scrolling when content exceeds parent */
    max-height: none !important; /* Don't constrain - let it grow so parent .tab-pane.active can scroll */
    margin-bottom: calc(var(--spacing-2xl) * 4) !important; /* Significantly increased margin at bottom to ensure content is visible */
    padding-bottom: calc(var(--spacing-2xl) * 2) !important; /* Additional padding at bottom */
}

#formattedResults:has(.tab-empty-state),
#formattedResults:has(.tab-processing-state) {
    min-height: 0;
    height: 100% !important;
    max-height: 100% !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    display: flex;
    flex-direction: column;
}

#formattedResults:has(.tab-empty-state)::after,
#formattedResults:has(.tab-processing-state)::after {
    display: none;
}

/* Add extra scrollable space at the end of formatted results using pseudo-element */
#formattedResults::after {
    content: '';
    display: block;
    height: calc(var(--spacing-2xl) * 6) !important; /* Large spacer to ensure bottom content is visible */
    width: 100%;
    flex-shrink: 0;
}

/* Forecast Content Styling */
#forecastContent {
    width: 100%;
    max-width: 100%;
    min-height: 200px;
    overflow: visible;
    display: block;
    position: relative;
    flex: 1 1 auto;
    visibility: visible;
    opacity: 1;
    height: auto !important;
    max-height: none !important;
    margin-bottom: calc(var(--spacing-2xl) * 4) !important;
    padding-bottom: calc(var(--spacing-2xl) * 2) !important;
    color: var(--text-primary, #ffffff);
}

/* Add extra scrollable space at the end of forecast content */
#forecastContent::after {
    content: '';
    display: block;
    height: calc(var(--spacing-2xl) * 6) !important;
    width: 100%;
    flex-shrink: 0;
}

/* Ensure PowerBI dashboard and other dynamic content is visible */
/* Don't force display: block on all children - let them use their natural display */
#formattedResults > * {
    visibility: visible;
    opacity: 1;
    position: relative; /* Ensure proper positioning */
}

/* PowerBI dashboard should be block */
#formattedResults .powerbi-dashboard {
    display: block;
    visibility: visible;
    opacity: 1;
    min-height: auto;
    width: 100%;
    position: relative;
}

/* Playground dashboard: scroll inside #formattedResults, keep bottom tabs fixed */
#formatted-tab.dashboard-tab--scrollable {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0 !important;
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    padding-bottom: var(--spacing-md) !important;
}

#formatted-tab.dashboard-tab--scrollable > div:first-child {
    flex: 0 0 auto;
}

#formattedResults.dashboard-scroll-host {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0 !important;
    padding-bottom: var(--spacing-xl) !important;
}

#formattedResults.dashboard-scroll-host::after {
    display: none !important;
}

/* Visualization dashboard should be block */
#formattedResults .viz-dashboard {
    display: block;
    visibility: visible;
    opacity: 1;
    min-height: auto;
    width: 100%;
    position: relative;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Table */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    margin: var(--spacing-md) 0;
}

/* Fix raw tab table wrapper - this rule is now handled above, keeping for compatibility */

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

th, td {
    padding: var(--spacing-md) var(--spacing-lg);
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

th {
    background: linear-gradient(to bottom, var(--primary-50), var(--primary-100));
    font-weight: 600;
    color: var(--primary-900);
    position: sticky;
    top: 0;
    letter-spacing: 0.025em;
    font-size: 0.875rem;
    text-transform: uppercase;
}

td {
    color: var(--gray-800);
    font-variant-numeric: tabular-nums;
}

tbody tr:hover {
    background: var(--primary-50);
    cursor: pointer;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Zebra striping for better readability */
tbody tr:nth-child(even) {
    background: var(--gray-50);
}

tbody tr:nth-child(even):hover {
    background: var(--primary-50);
}

/* Code Block */
.code-block {
    background: var(--surface-code-bg);
    border: 1px solid var(--surface-code-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

/* General code-block styles */
.code-block pre {
    flex: 1;
    overflow-y: auto; /* Enable vertical scrolling */
    overflow-x: auto; /* Allow horizontal scrolling for long lines */
    min-height: 0;
}

/* SQL tab code-block pre - handled above in #sql-tab.active .code-block pre */

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--surface-code-header-bg);
    color: var(--surface-code-header-text);
    font-size: 0.875rem;
    font-weight: 600;
    flex: 0 0 auto;
    border-bottom: 1px solid var(--surface-code-border);
}

.btn-copy {
    min-height: 26px;
    padding: 0.3125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: var(--btn-font-weight);
    background: rgba(0, 0, 0, 0.06);
    color: var(--surface-code-header-text);
    border: 1px solid var(--surface-code-border);
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-copy:hover {
    background: rgba(0, 0, 0, 0.1);
}

pre {
    padding: var(--spacing-lg);
    color: var(--surface-code-text);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    overflow-x: auto;
    background: transparent;
}

/* Feedback */
.feedback-section {
    margin-top: var(--spacing-xl);
    padding: var(--spacing-xl) var(--spacing-lg) var(--spacing-lg) var(--spacing-lg);
    border-top: 2px solid var(--gray-200);
    text-align: center;
    flex: 0 0 auto; /* Fixed footer - don't shrink */
    background: var(--gray-50);
}

[data-theme="dark"] .feedback-section {
    background: var(--gray-100);
}

.feedback-question {
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: var(--spacing-md);
}

.feedback-buttons {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
}

.btn-feedback {
    min-height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.btn-feedback:hover {
    border-color: var(--primary-600);
    color: var(--primary-600);
    transform: none;
}

/* Error Section */
.error-section {
    padding: var(--spacing-2xl);
    text-align: center;
}

.error-content {
    max-width: 400px;
    margin: 0 auto;
}

.error-icon {
    font-size: 3rem;
    color: var(--error);
    margin-bottom: var(--spacing-md);
}

.error-content h3 {
    font-size: 1.5rem;
    color: var(--gray-900);
    margin-bottom: var(--spacing-sm);
}

.error-content p {
    color: var(--gray-600);
    margin-bottom: var(--spacing-lg);
}

/* Stats Section */
.stats-section {
    margin-top: var(--spacing-2xl);
    margin-bottom: var(--spacing-2xl);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
}

.stat-card {
    background: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    transition: all var(--transition-base);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-50);
    color: var(--primary-600);
    border-radius: var(--radius-md);
    font-size: 1.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-600);
}

/* Footer */
.footer {
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: var(--spacing-2xl) 0;
    margin-top: var(--spacing-2xl);
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-xl);
    margin-bottom: var(--spacing-xl);
}

.footer-section h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: var(--spacing-md);
}

.footer-section p, .footer-section a {
    color: var(--gray-600);
    text-decoration: none;
    display: block;
    margin-bottom: var(--spacing-sm);
    transition: color var(--transition-fast);
}

.footer-section a:hover {
    color: var(--primary-600);
}

.footer-bottom {
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--gray-200);
    text-align: center;
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: var(--spacing-xl);
    right: var(--spacing-xl);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--gray-900);
    color: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    opacity: 0;
    transform: translateY(20px);
    transition: all var(--transition-base);
    pointer-events: none;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Responsive Design */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
    }
    
    .hero-features {
        flex-direction: column;
        align-items: stretch;
    }
    
    .nav {
        gap: var(--spacing-sm);
    }
    
    .nav-link {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 0.875rem;
    }
    
    .results-tabs {
        overflow-x: auto;
    }
    
    .feedback-buttons {
        flex-direction: column;
    }
}

/* History Badge */
.history-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    margin-left: 8px;
    background: var(--primary-500);
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    line-height: 1;
}

.nav-link .history-badge {
    background: var(--primary-600);
    transition: var(--transition-base);
}

.nav-link.active .history-badge {
    background: white;
    color: var(--primary-600);
}

/* History Section */
.history-section {
    padding: var(--spacing-2xl) 0;
    animation: fadeIn 0.3s ease-in;
    width: 100%;
    max-width: 100%;
    display: none; /* Hidden by default, shown via JavaScript */
}

.history-container {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xl);
    border-bottom: 2px solid var(--gray-100);
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.history-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.history-title i {
    font-size: 1.75rem;
    color: var(--primary-600);
}

.history-title h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
}

.history-count {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--primary-50);
    color: var(--primary-700);
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-md);
}

.history-actions {
    display: flex;
    gap: var(--spacing-md);
    align-items: center;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 12px;
    color: var(--gray-400);
    font-size: 0.875rem;
}

.search-box input {
    padding: 0.625rem 0.75rem 0.625rem 2.5rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    width: 250px;
    transition: var(--transition-base);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-100);
}

/* History Filters */
.history-filters {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--gray-100);
    overflow-x: auto;
}

.filter-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: 2px solid var(--gray-200);
    background: white;
    color: var(--gray-700);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-base);
    white-space: nowrap;
}

.filter-btn:hover {
    border-color: var(--primary-300);
    background: var(--primary-50);
    color: var(--primary-700);
}

.filter-btn.active {
    border-color: var(--primary-500);
    background: var(--primary-500);
    color: white;
}

.filter-btn i {
    font-size: 0.875rem;
}

/* History List */
.history-list {
    max-height: 600px;
    overflow-y: auto;
    padding: var(--spacing-lg);
}

.history-item {
    padding: var(--spacing-lg);
    border: 2px solid var(--gray-100);
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-md);
    cursor: pointer;
    transition: var(--transition-base);
    background: white;
}

.history-item:hover {
    border-color: var(--primary-300);
    background: var(--primary-50);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: var(--spacing-sm);
    gap: var(--spacing-md);
}

.history-item-question {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* History Item Badges */
.history-item .history-badge {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: help;
    margin-left: 0;
    min-width: 1.5rem;
    padding: 0;
}

.history-item .history-badge:hover {
    transform: scale(1.15);
}

.viz-badge {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.insights-badge {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.1));
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.filter-badge {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.1));
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.history-item-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.history-item-status.success {
    background: var(--success-light);
    color: var(--success);
}

.history-item-status.failed {
    background: var(--error-light);
    color: var(--error);
}

.history-item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    font-size: 0.875rem;
    color: var(--gray-600);
}

.history-item-meta-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.history-item-meta-item i {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.history-item-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--gray-100);
}

.history-item-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.btn-history {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    min-height: 26px;
    padding: 0.3125rem 0.625rem;
    border: 1px solid var(--gray-200);
    background: white;
    color: var(--gray-700);
    font-size: 0.75rem;
    font-weight: var(--btn-font-weight);
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: var(--transition-base);
}

.btn-history:hover {
    border-color: var(--primary-500);
    background: var(--primary-50);
    color: var(--primary-700);
}

.btn-history i {
    font-size: 0.75rem;
}

/* History Empty State */
.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-2xl);
    text-align: center;
    min-height: 300px;
}

.history-empty i {
    font-size: 4rem;
    color: var(--gray-300);
    margin-bottom: var(--spacing-md);
}

.history-empty h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: var(--spacing-sm);
}

.history-empty p {
    color: var(--gray-500);
    max-width: 400px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    animation: fadeIn 0.2s ease-in;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
    display: flex;
    flex-direction: column;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xl);
    border-bottom: 2px solid var(--gray-100);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    background: var(--gray-100);
    color: var(--gray-600);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-base);
}

.modal-close:hover {
    background: var(--error-light);
    color: var(--error);
}

.modal-body {
    padding: var(--spacing-xl);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-md);
    padding: var(--spacing-xl);
    border-top: 2px solid var(--gray-100);
}

/* Modal Content Sections */
.modal-section {
    margin-bottom: var(--spacing-xl);
}

.modal-section:last-child {
    margin-bottom: 0;
}

.modal-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.modal-section-title i {
    color: var(--primary-600);
}

.modal-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.modal-info-item {
    padding: var(--spacing-md);
    background: var(--gray-50);
    border-radius: var(--radius-md);
}

.modal-info-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.modal-info-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
}

/* Settings Modal Styles */
.settings-modal-content {
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

.settings-body {
    padding: var(--spacing-xl);
}

.settings-section {
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-xl);
    border-bottom: 1px solid var(--gray-200);
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.settings-section-header h3 {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.settings-section-header h3 i {
    color: var(--primary-600);
}

.settings-description {
    font-size: 0.9rem;
    color: var(--gray-600);
    line-height: 1.6;
    margin: 0;
}

/* Switch Toggle Styles — gradient pill track + floating white thumb */
.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-switch {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, #f5c4d0 0%, #c8ddf5 52%, #a8d8f0 100%);
    transition: background 0.3s ease, box-shadow 0.2s ease;
    border-radius: 999px;
    box-shadow:
        inset 2px 3px 8px rgba(0, 0, 0, 0.12),
        inset -1px -1px 4px rgba(255, 255, 255, 0.45);
}

.slider-switch:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: linear-gradient(145deg, #ffffff 0%, #f2f2f2 100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow:
        2px 3px 8px rgba(0, 0, 0, 0.18),
        0 1px 2px rgba(0, 0, 0, 0.1);
}

.switch input:checked + .slider-switch {
    background: linear-gradient(90deg, #3d2a6e 0%, #6b2d8e 52%, #d44a9a 100%);
    box-shadow:
        inset 2px 3px 10px rgba(0, 0, 0, 0.32),
        inset -1px -1px 4px rgba(255, 255, 255, 0.1);
}

.switch input:checked + .slider-switch:before {
    transform: translateX(24px);
}

.switch input:focus-visible + .slider-switch {
    outline: 2px solid rgba(107, 45, 142, 0.45);
    outline-offset: 2px;
}

[data-theme="dark"] .settings-section-header h3 {
    color: var(--apple-text);
}

[data-theme="dark"] .settings-description {
    color: var(--apple-muted);
}

[data-theme="dark"] .control-label {
    color: var(--gray-800);
}

[data-theme="dark"] .control-hint {
    color: var(--gray-600);
}

[data-theme="dark"] .control-hint span {
    color: var(--primary-400);
}

[data-theme="dark"] .tuning-presets h4,
[data-theme="dark"] .tuning-stats h4 {
    color: var(--gray-800);
}

/* OneDrive Folder Browser Styles */
.onedrive-folder-list {
    background: var(--gray-50);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
}

.onedrive-folder-item {
    padding: 0.75rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.onedrive-folder-item:hover {
    background-color: var(--primary-50);
}

.onedrive-folder-item i {
    color: var(--primary-500);
    font-size: 1rem;
}

.onedrive-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--gray-600);
    padding: 0.5rem;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
}

.breadcrumb-item {
    color: var(--primary-600);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.breadcrumb-item:hover {
    color: var(--primary-700);
    text-decoration: underline;
}

[data-theme="dark"] .onedrive-folder-list {
    background: var(--gray-100);
    border-color: var(--gray-300);
}

[data-theme="dark"] .onedrive-folder-item:hover {
    background-color: var(--primary-100);
}

[data-theme="dark"] .onedrive-breadcrumb {
    background: var(--gray-100);
    color: var(--gray-400);
}

[data-theme="dark"] .breadcrumb-item {
    color: var(--primary-400);
}

[data-theme="dark"] .breadcrumb-item:hover {
    color: var(--primary-300);
}

/* Print Styles */
@media print {
    .header, .footer, .feedback-section, .example-queries, .history-section {
        display: none;
    }
}

/* Responsive: History */
@media (max-width: 768px) {
    .history-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .history-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .search-box input {
        width: 100%;
    }
    
    .history-item-header {
        flex-direction: column;
    }
    
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .modal-info-grid {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   Knowledge Base Section Styles
   ======================================== */

.knowledge-base-section {
    padding: 2rem 0;
    width: 100%;
    max-width: 100%;
    display: none; /* Hidden by default, shown via JavaScript */
}

.knowledge-base-section.kb-cards-page {
    padding: 0;
    box-sizing: border-box;
}

.kb-container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.kb-header {
    margin-bottom: 2rem;
    text-align: center;
}

.kb-title h2 {
    font-size: 2rem;
    color: var(--primary-700);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.kb-subtitle {
    color: var(--gray-600);
    font-size: 1.125rem;
    max-width: 600px;
    margin: 0 auto;
}

/* Three Column Layout */
.kb-content-wrapper {
    display: grid;
    grid-template-columns: 2fr 350px 300px;
    gap: 1.5rem;
    margin-top: 2rem;
}

.kb-left-panel {
    min-width: 0; /* Prevent grid blowout */
}

.kb-middle-panel {
    position: sticky;
    top: 2rem;
    align-self: start;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

.kb-right-panel {
    position: sticky;
    top: 2rem;
    align-self: start;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

.kb-form-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

.kb-preview-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    height: fit-content;
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
}

.kb-preview-card h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.125rem;
    flex-shrink: 0;
}

.kb-preview-card .code-block {
    margin-top: 1rem;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.kb-preview-card pre {
    font-size: 0.8125rem;
    line-height: 1.5;
    font-family: var(--font-mono);
    overflow: hidden !important;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

/* Form Sections */
.form-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--gray-200);
}

.form-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.form-section-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Form Groups */
.form-group {
    margin-bottom: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
}

.form-label .required {
    color: var(--error);
    margin-left: 0.25rem;
}

.help-text {
    display: block;
    font-size: 0.8125rem;
    color: var(--gray-500);
    font-weight: 400;
    margin-top: 0.25rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-family: var(--font-sans);
    color: var(--gray-900);
    background: white;
    transition: all var(--transition-base);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input::placeholder {
    color: var(--gray-400);
}

textarea.form-input {
    resize: vertical;
    min-height: 100px;
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

select.form-input {
    cursor: pointer;
}

/* Dynamic Lists */
.dynamic-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.dynamic-item {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.dynamic-item .form-input {
    flex: 1;
}

.btn-remove {
    padding: 0;
    background: var(--error-light);
    color: var(--error);
    border: none;
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all var(--transition-base);
    flex-shrink: 0;
    width: var(--btn-height);
    height: var(--btn-height);
    min-height: var(--btn-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.btn-remove:hover {
    background: var(--error);
    color: white;
}

.btn-add {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    background: var(--primary-50);
    color: var(--primary-700);
    border: 1px dashed var(--primary-300);
    border-radius: var(--btn-radius);
    font-weight: var(--btn-font-weight);
    cursor: pointer;
    transition: all var(--transition-base);
    font-size: var(--btn-font-size);
}

.btn-add:hover {
    background: var(--primary-100);
    border-color: var(--primary-500);
    color: var(--primary-800);
}

/* Example Item */
.example-item {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
}

.example-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.example-item-number {
    font-weight: 600;
    color: var(--primary-700);
    font-size: 0.875rem;
}

.example-fields {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding-top: 1.5rem;
    margin-top: 2rem;
    border-top: 2px solid var(--gray-200);
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
    min-width: 88px;
}

/* Success Message */
.kb-success-message {
    background: var(--success-light);
    border: 2px solid var(--success);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideIn 0.3s ease-out;
}

.kb-success-message i {
    font-size: 2rem;
    color: var(--success);
}

.kb-success-message h4 {
    color: var(--success);
    margin-bottom: 0.25rem;
}

.kb-success-message p {
    color: #065f46;
    margin: 0;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Info Icon / Tooltip */
.info-icon {
    background: none;
    border: none;
    color: var(--primary-500);
    cursor: help;
    padding: 0;
    margin-left: 0.5rem;
    font-size: 0.875rem;
    transition: color var(--transition-base);
    position: relative;
}

.info-icon:hover {
    color: var(--primary-700);
}

.info-icon[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--gray-900);
    color: white;
    font-size: 0.75rem;
    line-height: 1.4;
    border-radius: var(--radius-md);
    white-space: normal;
    width: 280px;
    text-align: left;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.info-icon[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--gray-900);
    opacity: 0;
    transition: opacity var(--transition-base);
    z-index: 1000;
}

.info-icon:hover[data-tooltip]::after,
.info-icon:hover[data-tooltip]::before {
    opacity: 1;
}

/* Right Panel: KB Entries */
.kb-entries-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex item to shrink */
}

.kb-entries-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--gray-200);
}

.kb-entries-header h3 {
    font-size: 1.25rem;
    color: var(--primary-700);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.kb-entries-stats {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.kb-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.kb-stat i {
    color: var(--primary-500);
}

.kb-stat span {
    font-weight: 600;
    color: var(--primary-700);
}

/* Search Box */
.kb-search-box {
    position: relative;
    margin-bottom: 1rem;
}

.kb-search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
}

.kb-search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: all var(--transition-base);
}

.kb-search-box input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Filter Tabs */
.kb-filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.kb-filter-btn {
    padding: 0.5rem 0.75rem;
    background: var(--gray-100);
    color: var(--gray-700);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
}

.kb-filter-btn:hover {
    background: var(--gray-200);
}

.kb-filter-btn.active {
    background: var(--primary-500);
    color: white;
}

/* Entries List */
.kb-entries-list {
    flex: 1;
    overflow-y: auto;
    margin: 0 -1.5rem;
    padding: 0 1.5rem;
}

.kb-entry-item {
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    cursor: pointer !important;
    transition: all var(--transition-base);
    user-select: none;
}

.kb-entry-item:hover {
    background: white;
    border-color: var(--primary-300);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.kb-entry-item:active {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
}

.kb-entry-item.active {
    background: var(--primary-50);
    border-color: var(--primary-500);
}

.kb-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.kb-entry-title {
    font-weight: 600;
    color: var(--gray-900);
    font-size: 0.9375rem;
    line-height: 1.4;
    flex: 1;
}

.kb-entry-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.kb-entry-id {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-family: var(--font-mono);
    background: white;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.btn-edit-kb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--btn-height);
    height: var(--btn-height);
    min-height: var(--btn-height);
    padding: 0;
    border: none;
    background: transparent;
    color: var(--gray-400);
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.75rem;
}

.btn-edit-kb:hover {
    background: var(--primary-100);
    color: var(--primary-600);
    transform: none;
}

.btn-edit-kb:active {
    transform: scale(0.96);
}

.btn-delete-kb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--btn-height);
    height: var(--btn-height);
    min-height: var(--btn-height);
    padding: 0;
    border: none;
    background: transparent;
    color: var(--gray-400);
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.75rem;
}

.btn-delete-kb:hover {
    background: var(--error-light);
    color: var(--error);
    transform: none;
}

.btn-delete-kb:active {
    transform: scale(0.96);
}

.kb-entry-meta {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.75rem;
    color: var(--gray-600);
}

.kb-entry-meta-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.kb-entry-meta-item i {
    font-size: 0.625rem;
}

.kb-entry-category {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--primary-100);
    color: var(--primary-700);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

/* Loading State */
.kb-entries-loading {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
}

.kb-entries-loading i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--primary-500);
}

/* Empty State */
.kb-entries-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--gray-500);
}

.kb-entries-empty i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--gray-400);
}

.kb-entries-empty h4 {
    font-size: 1.125rem;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.kb-entries-empty p {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* Responsive: Knowledge Base */
@media (max-width: 1400px) {
    .kb-content-wrapper {
        grid-template-columns: 1fr 350px;
    }
    
    .kb-middle-panel {
        grid-column: 1;
        grid-row: 2;
    }
    
    .kb-right-panel {
        grid-column: 2;
        grid-row: 1 / 3;
    }
}

@media (max-width: 1024px) {
    .kb-content-wrapper {
        grid-template-columns: 1fr;
    }
    
    .kb-middle-panel {
        grid-column: auto;
        grid-row: auto;
        position: static;
        max-height: 600px;
    }
    
    .kb-right-panel {
        grid-column: auto;
        grid-row: auto;
        position: static;
        max-height: 500px;
    }
}

@media (max-width: 768px) {
    .kb-form-card {
        padding: 1.5rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn-primary,
    .form-actions .btn-secondary {
        width: 100%;
    }
    
    .kb-entries-card {
        padding: 1rem;
    }
    
    .kb-filter-tabs {
        flex-wrap: wrap;
    }
}

/* ========================================
   Tuning Panel Styles
   ======================================== */

.query-section {
    display: flex;
    flex-direction: column; /* Stack vertically: query input then tuning panel */
    gap: 0; /* No gap, tuning panel has its own margin */
    max-width: 1400px;
    margin: 0 auto; /* Center the entire section */
}

.tuning-panel {
    flex-shrink: 0;
    width: 320px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
    border: 1px solid var(--gray-200);
    position: sticky;
    top: 100px;
    max-height: calc(100vh - 120px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease, max-height 0.3s ease;
}

/* Horizontal variant - appears at top */
.tuning-panel-horizontal {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto 1.5rem auto;
    position: relative;
    top: 0;
    max-height: 70px; /* Collapsed by default */
}

.tuning-panel-horizontal .tuning-content {
    display: none; /* Collapsed by default */
    max-height: 400px;
    overflow-y: auto;
}

.tuning-panel-horizontal.expanded {
    max-height: 500px;
}

.tuning-panel-horizontal.expanded .tuning-content {
    display: block;
}

.tuning-panel-horizontal .tuning-header {
    cursor: pointer;
}

.tuning-panel-horizontal .tuning-toggle i {
    transform: rotate(90deg); /* Point down when collapsed */
}

.tuning-panel-horizontal.expanded .tuning-toggle i {
    transform: rotate(-90deg); /* Point up when expanded */
}

.tuning-panel.collapsed {
    width: 48px;
}

.tuning-panel.collapsed .tuning-content {
    display: none;
}

.tuning-panel.collapsed .tuning-title h3 {
    display: none;
}

.tuning-panel.collapsed .tuning-toggle i {
    transform: rotate(180deg);
}

.tuning-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    color: white;
}

.tuning-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.tuning-title h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.tuning-title i {
    font-size: 1.25rem;
}

.tuning-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.tuning-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

.tuning-toggle i {
    transition: transform 0.3s;
}

.tuning-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.tuning-description {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin: 0 0 1.5rem 0;
    line-height: 1.5;
}

.tuning-control {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--gray-100);
}

.tuning-control:last-of-type {
    border-bottom: none;
}

.control-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
}

.control-label span {
    flex: 1;
}

.info-btn {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: help;
    padding: 0;
    margin-left: 0.5rem;
    transition: color 0.2s;
}

.info-btn:hover {
    color: var(--primary-500);
}

.control-input-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.control-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--gray-200);
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-500);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: background 0.2s;
}

.control-slider::-webkit-slider-thumb:hover {
    background: var(--primary-600);
}

.control-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-500);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-number {
    width: 70px;
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--btn-radius);
    font-size: 0.8125rem;
    text-align: center;
    font-family: var(--font-mono);
    color: var(--gray-900);
    background: #ffffff;
    -webkit-text-fill-color: currentColor;
}

.control-number:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(44, 143, 234, 0.15);
}

.control-hint {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-hint span {
    font-weight: 600;
    color: var(--primary-600);
}

.hint-badge {
    background: var(--primary-100);
    color: var(--primary-700);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.control-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Switch styles are defined in main switch section (line 3405) */

.toggle-status {
    font-size: 0.875rem;
    color: var(--gray-600);
    font-weight: 500;
}

.tuning-presets {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--gray-100);
}

.tuning-presets h4 {
    margin: 0 0 1rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.preset-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: var(--primary-50);
    border-color: var(--primary-300);
    color: var(--primary-700);
    transform: translateX(4px);
}

.preset-btn i {
    color: var(--primary-500);
}

.tuning-actions {
    margin-top: 1.5rem;
}

.btn-reset {
    width: 100%;
    min-height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: var(--btn-radius);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    color: var(--gray-700);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    transition: all 0.2s;
}

.btn-reset:hover {
    background: var(--gray-200);
    border-color: var(--gray-400);
}

.tuning-stats {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.stat-row:last-child {
    margin-bottom: 0;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--gray-600);
}

.stat-value {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--primary-600);
}

.query-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* Mobile Responsive */
@media (max-width: 1024px) {
    .query-section {
        flex-direction: column;
    }
    
    .tuning-panel {
        width: 100%;
        position: static;
        max-height: none;
    }
    
    .tuning-panel.collapsed {
        width: 100%;
        max-height: 60px;
    }
}

/* ============================================
   ADDITIONAL DARK MODE ENHANCEMENTS
============================================ */

/* Enhanced Focus States for Accessibility */
[data-theme="dark"] *:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(44, 143, 234, 0.2);
}

[data-theme="dark"] button:focus-visible,
[data-theme="dark"] a:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(44, 143, 234, 0.3), var(--glow-primary);
}

/* Enhanced Input Focus States */
[data-theme="dark"] input:focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 
        0 0 0 3px rgba(44, 143, 234, 0.2),
        0 0 20px rgba(44, 143, 234, 0.15);
}

/* Skeleton Loading States for Dark Mode */
[data-theme="dark"] .skeleton {
    background: linear-gradient(
        90deg,
        var(--gray-200) 0%,
        var(--gray-300) 50%,
        var(--gray-200) 100%
    );
    background-size: 200% 100%;
    animation: skeletonLoading 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes skeletonLoading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Enhanced Card Hover Effects */
[data-theme="dark"] .stat-card:hover,
[data-theme="dark"] .kb-form-card:hover,
[data-theme="dark"] .kb-entries-card:hover,
[data-theme="dark"] .kb-preview-card:hover {
    transform: translateY(-4px) scale(1.01);
}

/* Enhanced Button Press Effects */
[data-theme="dark"] .btn-primary:active,
[data-theme="dark"] .btn-secondary:active {
    transform: translateY(1px) scale(0.98);
}

/* Enhanced Feature Badge */
[data-theme="dark"] .feature-badge {
    background: linear-gradient(135deg, var(--gray-100), var(--gray-200));
    border: 1px solid var(--gray-300);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .feature-badge:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.4),
        0 0 15px rgba(44, 143, 234, 0.2);
}

/* Enhanced Tabs */
[data-theme="dark"] .tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: #2c8fea;
    box-shadow: none;
}

[data-theme="dark"] .tab-btn {
    position: relative;
}

[data-theme="dark"] .tab-btn:hover {
    background: rgba(44, 143, 234, 0.1);
    color: #2c8fea;
}

[data-theme="dark"] .results-section > .playground-tab-footer .tab-btn.active:not(.workspace-tab) {
    color: #2c8fea;
    border-top-color: #2c8fea;
}

/* Enhanced Tuning Panel */
[data-theme="dark"] .tuning-header {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .tuning-stats {
    background: linear-gradient(135deg, var(--gray-200), var(--gray-300));
    border: 1px solid var(--gray-400);
    box-shadow: 
        inset 0 1px 3px rgba(0, 0, 0, 0.3),
        0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Enhanced History Items */
[data-theme="dark"] .history-item {
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .history-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-500);
    opacity: 0;
    transition: opacity 0.3s;
}

[data-theme="dark"] .history-item:hover::before {
    opacity: 1;
}

[data-theme="dark"] .history-item:hover {
    border-color: var(--primary-500);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(44, 143, 234, 0.2);
}

/* Enhanced Loading States */
[data-theme="dark"] .loading-state.completed {
    background: linear-gradient(135deg, #064e3b 0%, #065f46 100%);
    border-left: 4px solid #22c55e;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(34, 197, 94, 0.3);
}

/* Enhanced Error States */
[data-theme="dark"] .error-section {
    background: linear-gradient(135deg, var(--gray-100), var(--gray-200));
    border: 1px solid var(--error);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .error-icon {
    filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.5));
}

/* Enhanced Selection */
[data-theme="dark"] ::selection {
    background: rgba(44, 143, 234, 0.3);
    color: var(--gray-900);
}

[data-theme="dark"] ::-moz-selection {
    background: rgba(44, 143, 234, 0.3);
    color: var(--gray-900);
}

/* Enhanced Scrollbar for Code Blocks */
[data-theme="dark"] .code-block pre::-webkit-scrollbar,
[data-theme="dark"] .processing-log::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

[data-theme="dark"] .code-block pre::-webkit-scrollbar-thumb,
[data-theme="dark"] .processing-log::-webkit-scrollbar-thumb {
    background: var(--gray-500);
    border-radius: 4px;
}

[data-theme="dark"] .code-block pre::-webkit-scrollbar-thumb:hover,
[data-theme="dark"] .processing-log::-webkit-scrollbar-thumb:hover {
    background: var(--primary-500);
}

/* Enhanced Tooltip Styling */
[data-theme="dark"] [data-tooltip]::before {
    background: var(--gray-200);
    color: var(--gray-900);
    border: 1px solid var(--gray-400);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.6),
        0 0 20px rgba(44, 143, 234, 0.2);
}

/* Pulse Animation for Active Elements */
[data-theme="dark"] .stage.active .stage-number {
    animation: pulse 2s ease-in-out infinite, glowPulse 2s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% {
        box-shadow: 
            0 0 10px rgba(44, 143, 234, 0.5),
            0 0 20px rgba(44, 143, 234, 0.3);
    }
    50% {
        box-shadow: 
            0 0 20px rgba(44, 143, 234, 0.8),
            0 0 40px rgba(44, 143, 234, 0.5);
    }
}

/* Enhanced Modal Backdrop */
[data-theme="dark"] .modal-overlay {
    backdrop-filter: blur(8px);
    animation: fadeIn 0.2s ease-in;
}

/* Enhanced Empty States */
[data-theme="dark"] .history-empty,
[data-theme="dark"] .kb-entries-empty {
    background: var(--gray-100);
    border: 2px dashed var(--gray-400);
    border-radius: var(--radius-lg);
}

/* Enhanced Dividers */
[data-theme="dark"] .form-section,
[data-theme="dark"] .tuning-control {
    border-bottom-color: var(--gray-300);
}

/* Enhanced Range Sliders */
[data-theme="dark"] input[type="range"] {
    accent-color: var(--primary-500);
}

[data-theme="dark"] input[type="range"]::-webkit-slider-thumb {
    box-shadow: 0 0 10px rgba(44, 143, 234, 0.5);
}

[data-theme="dark"] input[type="range"]::-moz-range-thumb {
    box-shadow: 0 0 10px rgba(44, 143, 234, 0.5);
}

/* Enhanced Checkbox and Radio Buttons */
[data-theme="dark"] input[type="checkbox"]:checked,
[data-theme="dark"] input[type="radio"]:checked {
    accent-color: var(--primary-500);
}

/* Smooth Theme Transition */
[data-theme="dark"] * {
    transition: background-color 0.3s ease, 
                color 0.3s ease, 
                border-color 0.3s ease,
                box-shadow 0.3s ease;
}

/* Export Buttons */
.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    background: var(--primary-600);
    color: white;
    border: none;
    border-radius: var(--btn-radius);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: none;
}

.btn-export:hover {
    background: var(--primary-700);
    transform: none;
    box-shadow: none;
}

.btn-export:active {
    transform: scale(0.98);
}

.btn-export i {
    font-size: 0.75rem;
}

[data-theme="dark"] .btn-export {
    background: #2c8fea;
    box-shadow: none;
    border: 1px solid rgba(44, 143, 234, 0.35);
}

[data-theme="dark"] .btn-export:hover {
    background: #2480d4;
    box-shadow: none;
    transform: none;
}

.export-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.export-menu,
.report-export-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--gray-50);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    min-width: 180px;
    margin-top: 0.5rem;
}

[data-theme="dark"] .export-menu,
[data-theme="dark"] .report-export-menu {
    background: var(--gray-100);
    border-color: var(--gray-300);
    box-shadow: var(--shadow-dark-lg);
}

.export-option {
    width: 100%;
    padding: 0.75rem;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--gray-900);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all var(--transition-fast);
}

[data-theme="dark"] .export-option {
    color: var(--gray-900);
}

.export-option:hover {
    background: var(--gray-100);
}

[data-theme="dark"] .export-option:hover {
    background: var(--gray-800);
}

/* ============================================
   INSIGHTS DARK MODE STYLING
   ============================================ */
[data-theme="dark"] .insight-section {
    color: var(--text-primary);
}

[data-theme="dark"] .insight-section p {
    color: #d1d5db !important;
    font-weight: 400;
    font-size: 0.8125rem;
}

[data-theme="dark"] .insight-section h3,
[data-theme="dark"] .insight-section h4,
[data-theme="dark"] .insight-section h5 {
    color: var(--primary-400) !important;
}

/* Dark mode for insight cards with white background */
[data-theme="dark"] .insight-section div[style*="background: white"],
[data-theme="dark"] .insight-section div[style*="background:white"] {
    background: #1c1c1c !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .insight-section div[style*="color: #1f2937"],
[data-theme="dark"] .insight-section div[style*="color:#1f2937"] {
    color: var(--gray-200) !important;
}

[data-theme="dark"] .insight-section div[style*="color: #4b5563"],
[data-theme="dark"] .insight-section div[style*="color:#4b5563"] {
    color: var(--gray-300) !important;
}

[data-theme="dark"] .insight-section div[style*="color: #6b7280"],
[data-theme="dark"] .insight-section div[style*="color:#6b7280"] {
    color: var(--gray-400) !important;
}

[data-theme="dark"] .insight-section div[style*="background: #f9fafb"],
[data-theme="dark"] .insight-section div[style*="background:#f9fafb"] {
    background: var(--gray-900) !important;
}

[data-theme="dark"] .insight-section div[style*="background: #f3f4f6"],
[data-theme="dark"] .insight-section div[style*="background:#f3f4f6"] {
    background: var(--gray-900) !important;
}

/* Prompt-driven insights & audit report (KB directive layout) */
.prompt-driven-document {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.prompt-driven-section {
    padding: 1.25rem 1.5rem;
    background: var(--card-bg, rgba(255, 255, 255, 0.05));
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.prompt-driven-section-title,
.prompt-driven-h2,
.prompt-driven-h3 {
    margin: 0 0 0.75rem 0;
    color: var(--text-primary, #ffffff);
    line-height: 1.35;
}

.prompt-driven-h4,
.prompt-driven-h5,
.prompt-driven-h6 {
    margin: 1rem 0 0.5rem 0;
    color: var(--text-primary, #ffffff);
    line-height: 1.4;
    font-weight: 600;
}

.prompt-driven-h4 {
    font-size: 1rem;
}

.prompt-driven-h5 {
    font-size: 0.95rem;
}

.prompt-driven-h6 {
    font-size: 0.9rem;
    color: var(--text-secondary, #d1d5db);
}

.prompt-driven-p,
.prompt-driven-body,
.prompt-driven-section-body {
    color: var(--text-primary, #e5e7eb);
    line-height: 1.7;
    font-size: 0.95rem;
}

.prompt-driven-p {
    margin: 0 0 0.75rem 0;
}

.prompt-driven-list,
.prompt-driven-ol {
    margin: 0 0 0.75rem 1.25rem;
    padding: 0;
    color: var(--text-primary, #e5e7eb);
    line-height: 1.6;
}

.prompt-driven-ol {
    list-style: decimal;
}

.prompt-driven-table-wrap {
    overflow-x: auto;
    margin: 0.75rem 0 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
}

.prompt-driven-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.prompt-driven-table th,
.prompt-driven-table td {
    padding: 0.625rem 0.875rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    color: var(--text-primary, #e5e7eb);
}

.prompt-driven-table th {
    background: rgba(255, 255, 255, 0.06);
    font-weight: 600;
    white-space: nowrap;
}

.prompt-driven-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.prompt-driven-table td {
    font-variant-numeric: tabular-nums;
}

.prompt-driven-code {
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

.audit-report-brand-header {
    padding: 1.5rem 2rem;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.audit-report-logo {
    height: 48px;
    width: auto;
    max-width: 220px;
    object-fit: contain;
}

.audit-report-brand-text {
    text-align: right;
}

.audit-report-brand-subtitle {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
}

.audit-report-brand-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #111827;
}

/* Force readable light styling when capturing insights / audit report PDFs in dark mode */
.pdf-export-capture {
    position: fixed;
    left: -10000px;
    top: 0;
    z-index: -1;
    width: 794px;
    max-width: 794px;
    padding: 24px;
    background: #ffffff !important;
    color: #111827 !important;
}

.pdf-export-capture .prompt-driven-section,
.pdf-export-capture .insight-section,
.pdf-export-capture .insight-metric-card,
.pdf-export-capture .insight-card,
.pdf-export-capture .insight-rec-card,
.pdf-export-capture .insight-section--summary,
.pdf-export-capture .insight-risk-item {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    box-shadow: none !important;
}

.pdf-export-capture .prompt-driven-section-title,
.pdf-export-capture .prompt-driven-h2,
.pdf-export-capture .prompt-driven-h3,
.pdf-export-capture .prompt-driven-h4,
.pdf-export-capture .prompt-driven-h5,
.pdf-export-capture .prompt-driven-h6,
.pdf-export-capture .prompt-driven-p,
.pdf-export-capture .prompt-driven-body,
.pdf-export-capture .prompt-driven-section-body,
.pdf-export-capture .prompt-driven-list,
.pdf-export-capture .prompt-driven-ol,
.pdf-export-capture .prompt-driven-table th,
.pdf-export-capture .prompt-driven-table td,
.pdf-export-capture .insight-lead,
.pdf-export-capture .insight-card-body,
.pdf-export-capture .insight-card-title,
.pdf-export-capture .insight-rec-title,
.pdf-export-capture .insight-rec-body,
.pdf-export-capture .insight-metric-value,
.pdf-export-capture .insight-metric-label,
.pdf-export-capture .insight-metric-meta,
.pdf-export-capture .insight-metric-detail,
.pdf-export-capture .insight-list-item,
.pdf-export-capture .insight-risk-item,
.pdf-export-capture .insight-recommendation-text,
.pdf-export-capture .insight-expected-outcome,
.pdf-export-capture .insight-rec-impact,
.pdf-export-capture .audit-report-brand-title,
.pdf-export-capture .audit-report-brand-subtitle {
    color: #111827 !important;
}

.pdf-export-capture .prompt-driven-h6,
.pdf-export-capture .insight-summary-note,
.pdf-export-capture .insight-metric-label,
.pdf-export-capture .insight-metric-meta,
.pdf-export-capture .insight-metric-detail {
    color: #4b5563 !important;
}

.pdf-export-capture .prompt-driven-table th {
    background: #f3f4f6 !important;
}

.pdf-export-capture .prompt-driven-table-wrap {
    border-color: rgba(0, 0, 0, 0.12) !important;
}

.pdf-export-capture .prompt-driven-code {
    background: #f3f4f6 !important;
    color: #111827 !important;
}

.pdf-export-capture .audit-report-brand-header {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
}

.pdf-export-capture .insight-heading,
.pdf-export-capture .insight-heading--primary,
.pdf-export-capture .insight-summary-title {
    color: #1d6fbf !important;
}

.pdf-export-capture .insight-heading--danger {
    color: #dc2626 !important;
}

.pdf-export-capture .executive-summary,
.pdf-export-capture .insight-section.executive-summary {
    background: #f8fafc !important;
    border-color: rgba(44, 143, 234, 0.35) !important;
    border-left-color: #2c8fea !important;
}

.pdf-export-capture .insight-metric-card,
.pdf-export-capture .insight-card {
    background: #f9fafb !important;
}

[data-theme="dark"] .audit-report-brand-header {
    background: #ffffff;
}

[data-theme="light"] .prompt-driven-table th {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .prompt-driven-table th,
[data-theme="light"] .prompt-driven-table td {
    color: var(--text-primary, #1f2937);
}

/* Ensure export buttons are visible */
/* Export buttons styles are defined above (line 5034) */
#rawDataExportButtons {
    display: flex;
}

/* Raw Data Dark Mode Enhancements */
[data-theme="dark"] #raw-tab h3 {
    color: var(--text-primary) !important;
}

/* ========================================
   CONTACTS MODAL STYLES
   ======================================== */

.contacts-section {
    padding: var(--spacing-md);
}

.contacts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.contacts-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.btn-sm {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
}

.contacts-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.contact-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.contact-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary-400);
}

.contact-info {
    flex: 1;
}

.contact-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
}

.contact-email {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.contact-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.btn-edit,
.btn-delete {
    width: var(--btn-height);
    height: var(--btn-height);
    min-height: var(--btn-height);
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--btn-radius);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.btn-edit:hover {
    background: var(--primary-50);
    color: var(--primary-600);
}

.btn-delete:hover {
    background: var(--error-light);
    color: var(--error);
}

.contacts-empty {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-secondary);
}

.contacts-empty i {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.contacts-empty-subtitle {
    font-size: 0.875rem;
    margin-top: var(--spacing-xs);
    opacity: 0.7;
}

.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-50);
}

[data-theme="dark"] .contact-item {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .contact-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary-500);
}

[data-theme="dark"] .btn-edit:hover {
    background: var(--primary-900);
    color: var(--primary-300);
}

[data-theme="dark"] .btn-delete:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error);
}

[data-theme="dark"] .form-group input {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="dark"] .form-group input:focus {
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ========================================
   Templates Management Page Styles
   ======================================== */

/* Templates Section Container */
.templates-section {
    padding: 0;
    width: 100%;
    overflow-x: hidden;
}

.templates-page-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 32px 40px;
    width: 100%;
    box-sizing: border-box;
}

/* Templates Page Header */
.templates-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--spacing-lg);
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.templates-header-content {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    flex: 1;
    min-width: 0;
}

.templates-header-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2c8fea;
    border-radius: 8px;
    color: white;
    font-size: 1.125rem;
    flex-shrink: 0;
    box-shadow: none;
}

.templates-header-text {
    flex: 1;
    min-width: 0;
}

.templates-page-title {
    margin: 0 0 var(--spacing-xs) 0;
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.templates-page-subtitle {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
    font-weight: 400;
    max-width: 700px;
}

.templates-header-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

[data-theme="dark"] .templates-page-title {
    color: #f3f4f6;
}

[data-theme="dark"] .templates-page-subtitle {
    color: #9ca3af;
}

/* Templates Main Card */
.templates-main-card {
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: none;
    overflow: hidden;
}

.templates-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1.25rem;
    gap: var(--spacing-md);
}

.templates-card-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.templates-card-title i {
    font-size: 1.125rem;
    color: var(--primary-600);
}

.templates-card-title h3 {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.templates-card-btn {
    white-space: nowrap;
}

.templates-card-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 0;
}

/* Template type tabs (Table / Visualization) */
.template-type-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.template-type-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: var(--btn-height);
    padding: var(--btn-padding-y) var(--btn-padding-x);
    border: none;
    background: transparent;
    border-radius: var(--btn-radius);
    color: var(--apple-muted);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.template-type-tab:hover {
    background: var(--apple-hover);
    color: var(--apple-text);
}

.template-type-tab.active {
    background: var(--apple-elevated);
    color: var(--apple-blue);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .templates-main-card {
    background: #1c1c1c;
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .templates-card-divider {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .templates-card-title h3 {
    color: #f3f4f6;
}

[data-theme="dark"] .templates-card-title i {
    color: #2c8fea;
}

/* Templates Summary Bar */
.templates-summary-bar {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f5f5f3;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 8px;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    box-shadow: none;
}

.summary-stat {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
    background: #ffffff;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: none;
}

.stat-label {
    color: var(--text-secondary);
    font-weight: 400;
}

.stat-value {
    color: #2c8fea;
    font-weight: 600;
    font-size: 0.875rem;
}

[data-theme="dark"] .templates-summary-bar {
    background: #141414;
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .summary-stat {
    background: #1c1c1c;
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .stat-label {
    color: #9ca3af;
}

[data-theme="dark"] .stat-value {
    color: #2c8fea;
}

/* Templates List Container */
.templates-list-container {
    padding: 1rem 1.25rem 1.25rem;
    min-height: 200px;
    box-sizing: border-box;
}

.templates-list-container .templates-table-wrapper {
    margin: 0;
    padding: 0;
}

.templates-loading {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--gray-500);
}

.templates-loading i {
    font-size: 2rem;
    margin-bottom: var(--spacing-md);
    display: block;
}

.templates-loading p {
    margin: 0;
    color: var(--gray-500);
}

/* Templates Empty State */
.templates-empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray-500);
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-50);
    border-radius: 50%;
    color: var(--primary-300);
    font-size: 2.5rem;
    opacity: 0.6;
}

.templates-empty-state h3 {
    margin: 0 0 var(--spacing-sm) 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-700);
}

.templates-empty-state p {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--gray-500);
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

[data-theme="dark"] .templates-empty-state h3 {
    color: #f3f4f6;
}

[data-theme="dark"] .templates-empty-state p {
    color: #9ca3af;
}

[data-theme="dark"] .empty-state-icon {
    background: #181818;
    color: #2c8fea;
}

[data-theme="dark"] .template-type-tab.active {
    background: #181818;
    color: #2c8fea;
}

[data-theme="dark"] .templates-details-panel {
    border-left-color: rgba(255, 255, 255, 0.08) !important;
}

/* Templates Table */
.templates-table-wrapper {
    overflow-x: auto;
    width: 100%;
    margin: 0;
    background: transparent;
    -webkit-overflow-scrolling: touch;
}

.templates-table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
    min-width: 800px;
}

.templates-table thead {
    background: #f5f5f3;
    position: sticky;
    top: 0;
    z-index: 5;
}

.templates-table th {
    padding: 0.625rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.templates-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-weight: 400;
}

.templates-table tbody tr {
    transition: background-color var(--transition-fast);
}

.templates-table tbody tr:hover {
    background: rgba(44, 143, 234, 0.05);
}

.template-badge {
    display: inline-block;
    padding: 0.375rem 0.75rem;
    background: var(--primary-100);
    color: var(--primary-700);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--primary-200);
    box-shadow: var(--shadow-xs);
}

.template-tag {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    background: var(--gray-100);
    color: var(--gray-700);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--gray-200);
}

.template-tag-more {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--gray-200);
    color: var(--gray-600);
    border-radius: 4px;
    font-size: 0.75rem;
    font-style: italic;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-active {
    background: var(--success-light);
    color: var(--success);
}

.status-inactive {
    background: var(--gray-200);
    color: var(--gray-600);
}

.template-actions {
    display: flex;
    gap: var(--spacing-xs);
    align-items: center;
}

.btn-icon.btn-sm {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 0.875rem;
}

.btn-icon.btn-danger {
    color: var(--error);
}

.btn-icon.btn-danger:hover {
    background: var(--error-light);
    color: var(--error);
}

[data-theme="dark"] .templates-table-wrapper {
    background: transparent;
}

[data-theme="dark"] .templates-table {
    background: transparent;
}

[data-theme="dark"] .templates-table thead {
    background: #141414;
}

[data-theme="dark"] .templates-table th {
    color: #9ca3af;
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .templates-table td {
    color: #e8e8ed;
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .templates-table tbody tr:hover {
    background: rgba(44, 143, 234, 0.08);
}

/* ========================================
   Template Editor Modal Styles
   ======================================== */

.template-editor-modal-content {
    max-width: 1200px;
    width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.template-editor-modal-content .modal-footer {
    position: sticky;
    bottom: 0;
    background: white;
    z-index: 10;
    margin-top: auto;
    flex-shrink: 0;
}

[data-theme="dark"] .template-editor-modal-content .modal-footer {
    background: var(--gray-100);
}

.template-editor-modal-body {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    padding: var(--spacing-xl);
    min-height: 0;
}

.template-editor-modal-body .form-section {
    margin-bottom: var(--spacing-xl);
}

.template-editor-modal-body .form-section:last-child {
    margin-bottom: var(--spacing-lg);
}

/* Color Scheme Grid */
.color-scheme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--spacing-lg);
    margin-top: var(--spacing-md);
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.color-scheme-group {
    background: var(--gray-50);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.color-scheme-group h5 {
    margin: 0 0 var(--spacing-md) 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.color-input-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
}

.color-input-group:last-child {
    margin-bottom: 0;
}

.color-input-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-600);
    margin-bottom: var(--spacing-xs);
}

.color-input-group .color-picker {
    width: 100%;
    height: 40px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    background: transparent;
}

.color-input-group .color-text {
    width: 100%;
    padding: var(--spacing-sm);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    background: white;
    color: var(--gray-900);
}

[data-theme="dark"] .color-scheme-group {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

[data-theme="dark"] .color-input-group .color-text {
    background: var(--gray-100);
    border-color: var(--gray-400);
    color: var(--gray-900);
}

/* Template Preview Container */
.template-preview-container {
    padding: var(--spacing-lg);
    background: var(--gray-50);
    border-radius: var(--radius-md);
    margin-top: var(--spacing-md);
    border: 1px solid var(--gray-200);
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
    min-height: 600px;
}

/* Visual Template Preview - Larger size */
#visualTemplatePreviewContainer {
    min-height: 800px;
    max-height: 90vh;
    overflow: auto;
    padding: 1.5rem;
    background: var(--bg-secondary, #1E293B) !important;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1)) !important;
}

/* Override any white background from template-editor.css */
#visualTemplatePreviewContainer.template-preview-container {
    background: var(--bg-secondary, #1E293B) !important;
}

.template-preview-placeholder {
    color: var(--gray-500);
    text-align: center;
    padding: var(--spacing-xl);
    font-style: italic;
}

.template-preview-table-wrapper {
    width: 100%;
    overflow-x: auto;
    max-width: 100%;
}

.template-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 400px;
}

.template-preview-table th,
.template-preview-table td {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid;
    white-space: nowrap;
}

[data-theme="dark"] .template-preview-container {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

/* Templates Search and Filters */
.templates-search-filters {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: #f5f5f3;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-wrap: wrap;
    align-items: center;
}

.templates-search-filters .search-wrapper {
    flex: 1;
    min-width: 250px;
    position: relative;
}

.templates-search-filters .search-wrapper i {
    position: absolute;
    left: var(--spacing-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    z-index: 1;
    pointer-events: none;
}

.templates-search-filters .search-wrapper input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-primary);
    font-size: 0.8125rem;
    transition: border-color var(--transition-fast);
}

.templates-search-filters .search-wrapper input:focus {
    outline: none;
    border-color: #2c8fea;
    box-shadow: 0 0 0 2px rgba(44, 143, 234, 0.15);
}

.templates-search-filters .filters-wrapper {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.templates-search-filters .filters-wrapper select {
    min-width: 140px;
    padding: 0.5rem 0.75rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-primary);
    font-size: 0.8125rem;
    transition: border-color var(--transition-fast);
    cursor: pointer;
}

.templates-search-filters .filters-wrapper select:focus {
    outline: none;
    border-color: #2c8fea;
    box-shadow: 0 0 0 2px rgba(44, 143, 234, 0.15);
}

[data-theme="dark"] .templates-search-filters {
    background: #141414;
    border-top-color: rgba(255, 255, 255, 0.08);
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .templates-search-filters .search-wrapper input,
[data-theme="dark"] .templates-search-filters .filters-wrapper select {
    background: #1c1c1c;
    border-color: rgba(255, 255, 255, 0.1);
    color: #e8e8ed;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .templates-page-container {
        padding: 20px 16px 32px;
    }
    
    .templates-page-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-md);
    }
    
    .templates-header-content {
        width: 100%;
    }
    
    .templates-header-btn {
        width: 100%;
        justify-content: center;
    }
    
    .templates-card-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-sm);
    }
    
    .templates-card-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .template-editor-modal-content {
        width: 95vw;
        max-height: 95vh;
    }
    
    .color-scheme-grid {
        grid-template-columns: 1fr;
    }
    
    .templates-page-container {
        padding: 16px 12px 24px;
    }
    
    .templates-page-title {
        font-size: 24px;
    }
    
    .templates-header-icon {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }
    
    .templates-table-wrapper {
        font-size: 0.875rem;
    }
    
    .templates-table {
        min-width: 600px;
    }
    
    .templates-summary-bar {
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .summary-stat {
        width: 100%;
        justify-content: space-between;
    }
    
    .templates-search-filters {
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .search-wrapper,
    .filters-wrapper {
        width: 100%;
    }
    
    .filters-wrapper select {
        width: 100%;
    }
    
    .templates-list-container {
        padding: 24px 16px 28px;
    }
    
    .templates-card-header {
        padding: 16px 20px;
    }
}

/* Fix for table structure columns */
.template-column-item {
    max-width: 100%;
    overflow-x: auto;
    box-sizing: border-box;
}

.template-column-options {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
    flex-wrap: wrap;
}

.template-option-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.template-option-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
    accent-color: var(--primary-600);
}

.template-option-checkbox span {
    font-size: 0.875rem;
    color: var(--gray-700);
    font-weight: 500;
}

.template-option-checkbox:hover span {
    color: var(--primary-700);
}

[data-theme="dark"] .template-column-options {
    border-top-color: var(--gray-300);
}

[data-theme="dark"] .template-option-checkbox span {
    color: var(--gray-400);
}

[data-theme="dark"] .template-option-checkbox:hover span {
    color: var(--primary-300);
}

.template-column-grid {
    display: grid;
    grid-template-columns: 2fr 2fr 1fr 1fr 1fr auto;
    gap: var(--spacing-sm);
    align-items: start;
    width: 100%;
    box-sizing: border-box;
}

.template-column-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    align-items: center;
    padding-top: 1.5rem;
    flex-shrink: 0;
}

@media (max-width: 1024px) {
    .template-column-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }
    
    .template-column-actions {
        padding-top: 0;
        flex-direction: row;
        justify-content: flex-start;
    }
}

/* Ensure no horizontal scroll on modal */
.template-editor-modal-content,
.template-editor-modal-body,
.color-scheme-grid,
.template-preview-container {
    box-sizing: border-box;
}

/* Fix for form rows in Basic Info */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* Form help text */
.form-help-text {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: 0.875rem;
    color: var(--gray-500);
    line-height: 1.4;
}

.form-help-text code {
    background: var(--gray-100);
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--primary-700);
}

[data-theme="dark"] .form-help-text {
    color: var(--gray-400);
}

[data-theme="dark"] .form-help-text code {
    background: var(--gray-200);
    color: var(--primary-300);
}

/* Playground: Normal / AI mode switch (header center) */
.playground-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 0;
}

.mode-toggle-label {
    border: none;
    background: transparent;
    color: var(--text-secondary, #6b7280);
    font-size: 0.9375rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: pointer;
    padding: 4px 2px;
    transition: color 0.2s ease, opacity 0.2s ease;
    line-height: 1.2;
}

.mode-toggle-label:hover {
    color: var(--text-primary);
}

.mode-toggle-label.active {
    color: var(--text-primary, #f8fafc);
    font-weight: 600;
}

[data-theme="light"] .mode-toggle-label.active {
    color: var(--gray-900, #111827);
}

.mode-toggle-track {
    position: relative;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    padding: 0;
    background: linear-gradient(90deg, #f5c4d0 0%, #c8ddf5 52%, #a8d8f0 100%);
    box-shadow:
        inset 2px 3px 8px rgba(0, 0, 0, 0.12),
        inset -1px -1px 4px rgba(255, 255, 255, 0.45);
    transition: background 0.3s ease, box-shadow 0.2s ease;
}

.playground-mode-toggle[data-mode="ai"] .mode-toggle-track {
    background: linear-gradient(90deg, #3d2a6e 0%, #6b2d8e 52%, #d44a9a 100%);
    box-shadow:
        inset 2px 3px 10px rgba(0, 0, 0, 0.32),
        inset -1px -1px 4px rgba(255, 255, 255, 0.1);
}

.playground-mode-toggle[data-mode="powerbi"] .mode-toggle-track {
    background: linear-gradient(90deg, #f5c4d0 0%, #c8ddf5 52%, #a8d8f0 100%);
    box-shadow:
        inset 2px 3px 8px rgba(0, 0, 0, 0.12),
        inset -1px -1px 4px rgba(255, 255, 255, 0.45);
}

[data-theme="dark"] .playground-mode-toggle[data-mode="powerbi"] .mode-toggle-track {
    background: linear-gradient(90deg, #c9a0b8 0%, #8aaed4 55%, #7eb8d8 100%);
    box-shadow:
        inset 2px 3px 8px rgba(0, 0, 0, 0.22),
        inset -1px -1px 4px rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .playground-mode-toggle[data-mode="ai"] .mode-toggle-track {
    background: linear-gradient(90deg, #2e1f5c 0%, #5c2d82 55%, #b8367a 100%);
    box-shadow:
        inset 2px 3px 10px rgba(0, 0, 0, 0.45),
        inset -1px -1px 4px rgba(255, 255, 255, 0.05);
}

.mode-toggle-track:hover {
    filter: brightness(1.03);
}

.mode-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(145deg, #ffffff 0%, #f2f2f2 100%);
    box-shadow:
        2px 3px 8px rgba(0, 0, 0, 0.18),
        0 1px 2px rgba(0, 0, 0, 0.1);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.playground-mode-toggle[data-mode="ai"] .mode-toggle-thumb {
    transform: translateX(24px);
}

.playground-mode-toggle[data-mode="powerbi"] .mode-toggle-thumb {
    transform: translateX(0);
}

/* Legacy class names — keep for any stale references */
.mode-toggle-btn {
    display: none;
}

.ai-playground-view {
    display: flex;
    flex-direction: column;
    position: absolute;
    inset: 0;
    padding: var(--spacing-sm);
    padding-right: calc(var(--chat-panel-width) + var(--spacing-md));
    box-sizing: border-box;
    overflow: hidden;
}

.ai-playground-view > .results-section {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: var(--spacing-md);
    inset: auto;
    background: var(--playground-panel-bg, #ffffff);
    border: 1px solid var(--playground-panel-border, rgba(0, 0, 0, 0.07));
    border-radius: var(--radius-2xl);
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.08),
        0 0 0 1px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .ai-playground-view > .results-section {
    background: var(--playground-panel-bg, #1c1c1c);
    border-color: var(--playground-panel-border, rgba(255, 255, 255, 0.08));
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

.ai-playground-view > .error-section {
    flex: 1;
    min-height: 0;
    background: var(--apple-card);
    border: 1px solid var(--apple-border);
    border-radius: var(--radius-2xl);
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.08),
        0 0 0 1px rgba(0, 0, 0, 0.04);
}

/* Single-page view: dashboard fills space, footer tabs pinned at bottom, no scroll */
.ai-playground-view > .results-section:not(.has-detail-panels) {
    overflow: visible;
}

.ai-playground-view > .results-section:not(.has-detail-panels) .playground-dashboard-zone {
    flex: 0 0 auto;
}

.ai-playground-view > .results-section.has-detail-panels .playground-dashboard-zone {
    flex: 0 0 auto;
    height: var(--playground-canvas-height, 45vh);
    max-height: var(--playground-canvas-height, 45vh);
}

.ai-playground-view > .results-section:not(.has-detail-panels) .playground-tab-footer {
    margin-top: auto;
}

/* Unified scroll when a detail tab is opened */
.ai-playground-view > .results-section.has-detail-panels {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Playground stack: fixed-height canvas (top) → Footer tabs → Tab content (below footer) */
.playground-dashboard-zone {
    flex: 0 0 auto;
    min-height: 0;
    min-width: 0;
    height: var(--playground-canvas-height, auto);
    max-height: var(--playground-canvas-height, none);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    order: 1;
    -webkit-overflow-scrolling: touch;
}

.playground-dashboard-zone .dashboard-top-header {
    display: none !important;
}

.playground-dashboard-zone .dashboard-top-panel {
    flex: 0 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.playground-dashboard-zone .dashboard-top-body {
    flex: 0 1 auto;
    min-height: 0;
    overflow: visible;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.playground-dashboard-zone #formattedResults {
    flex: 0 1 auto;
    min-height: 0;
    height: auto !important;
    max-height: none !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    overflow: visible;
}

.playground-dashboard-zone .powerbi-dashboard--playground-canvas {
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.playground-dashboard-zone .powerbi-dashboard--playground-canvas .agent-dashboard-canvas {
    flex: 0 1 auto;
    min-height: 0;
    overflow: visible;
    padding: 10px;
}

.playground-dashboard-zone .canvas-chart-height-short .chart-body {
    min-height: 100px;
}

.playground-dashboard-zone .canvas-chart-height-medium .chart-body {
    min-height: 140px;
}

.playground-dashboard-zone .canvas-chart-height-tall .chart-body {
    min-height: 220px;
}

.playground-dashboard-zone .agent-dashboard-flow {
    gap: 10px;
}

.playground-dashboard-zone .dashboard-summary {
    padding: 12px 14px;
    border-radius: 8px;
    box-shadow: none;
}

.playground-dashboard-zone .summary-title {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.45;
}

.playground-dashboard-zone .summary-notes,
.playground-dashboard-zone .summary-note-line {
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.55;
}

[data-theme="dark"] .playground-dashboard-zone .dashboard-summary {
    background: linear-gradient(135deg, rgba(44, 143, 234, 0.18) 0%, rgba(44, 143, 234, 0.06) 38%, #1c1c1c 100%) !important;
    background-image: linear-gradient(135deg, rgba(44, 143, 234, 0.18) 0%, rgba(44, 143, 234, 0.06) 38%, #1c1c1c 100%) !important;
    border: 1px solid rgba(44, 143, 234, 0.35) !important;
    border-left: 3px solid #2c8fea !important;
    box-shadow: 0 0 20px rgba(44, 143, 234, 0.1) !important;
}

[data-theme="dark"] .playground-dashboard-zone .summary-title {
    color: #2c8fea;
    font-weight: 600;
}

[data-theme="dark"] .playground-dashboard-zone .summary-notes,
[data-theme="dark"] .playground-dashboard-zone .summary-note-line {
    color: #9ca3af;
}

.playground-dashboard-zone .kpi-card {
    padding: 10px 14px;
}

.playground-dashboard-zone .kpi-value {
    font-size: clamp(1.1rem, 2.2vw, 1.65rem);
}

.playground-dashboard-zone .kpi-description {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.3;
}

.playground-dashboard-zone .kpis-grid {
    grid-template-columns: repeat(var(--kpi-grid-columns, 3), minmax(0, 1fr));
    gap: 10px;
    width: 100%;
}

.playground-dashboard-zone .canvas-panel-kpis {
    width: 100%;
}

.playground-dashboard-zone .canvas-panel-kpis .dashboard-kpis {
    margin-bottom: 0;
    width: 100%;
}

.playground-dashboard-zone .canvas-panel-chart {
    width: 100% !important;
    grid-column: 1 / -1 !important;
}

.playground-dashboard-zone .chart-card--canvas {
    border-radius: var(--dashboard-radius, 6px);
    overflow: hidden;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow);
}

.playground-dashboard-zone .chart-card--canvas .chart-header {
    padding: 10px 14px 6px;
    border-bottom: 1px solid var(--card-border);
    background: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .playground-dashboard-zone .chart-card--canvas .chart-header {
    background: rgba(0, 0, 0, 0.03);
}

.playground-dashboard-zone .chart-card--canvas .chart-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.playground-dashboard-zone .chart-card--canvas .chart-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 4px 0 0;
}

.playground-dashboard-zone .filters-toolbar {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--dashboard-radius, 6px);
    padding: 8px 12px;
}

.playground-dashboard-zone .filters-toolbar-inner {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 10px 14px;
    width: 100%;
}

.playground-dashboard-zone .filter-control {
    flex: 0 0 auto;
    min-width: 0;
    max-width: 240px;
}

.playground-dashboard-zone .filter-control--date-range {
    flex: 1 1 auto;
    min-width: min(100%, 280px);
    max-width: none;
}

.playground-dashboard-zone .filter-control--date-range .filter-date-range {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.playground-dashboard-zone .filter-control--date-range .filter-date-input {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    max-width: none;
}

.playground-dashboard-zone .filter-reset-btn {
    flex: 0 0 auto;
    align-self: flex-end;
    white-space: nowrap;
    margin-left: auto;
}

@media (max-width: 640px) {
    .playground-dashboard-zone .filters-toolbar-inner {
        flex-wrap: wrap;
    }

    .playground-dashboard-zone .filter-reset-btn {
        margin-left: 0;
    }
}

.dashboard-top-panel {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.dashboard-top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px 8px;
    flex-shrink: 0;
    background: var(--apple-page, var(--gray-50));
}

[data-theme="dark"] .dashboard-top-header {
    background: #1c1c1c;
}

.dashboard-top-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.dashboard-top-body {
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
    padding: 0 8px 16px;
}

.playground-tab-panels--hidden {
    display: none !important;
    flex: 0 0 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
}

.playground-tab-panels {
    flex: 0 0 auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    border-top: 1px solid var(--card-border, rgba(255,255,255,0.08));
    order: 3;
}

.playground-tab-panels .footer-tab-content {
    min-height: min-content;
}

.playground-tab-panels .footer-tab-content .tab-pane.active {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    display: flex !important;
    flex-direction: column;
    padding: 12px 8px 20px;
}

/* Footer tab row — premium workspace navigation (Apple-style segmented control) */
.results-section > .playground-tab-footer.playground-workspace-bar {
    flex: 0 0 auto;
    order: 2;
    margin-top: 0 !important;
    margin-bottom: 0;
    width: 100%;
    z-index: 10;
    padding: 14px 16px 16px;
    border-top: 1px solid rgba(44, 143, 234, 0.22);
    border-bottom: none;
    background:
        linear-gradient(180deg, rgba(44, 143, 234, 0.1) 0%, rgba(44, 143, 234, 0.02) 28%, var(--apple-card) 100%);
    box-shadow:
        0 -12px 40px rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.playground-workspace-bar-inner {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    max-width: 100%;
}

.playground-workspace-bar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-align: center;
    padding: 0 4px;
}

.playground-workspace-eyebrow {
    font-family: var(--font-sans);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #2c8fea;
}

.playground-workspace-subline {
    font-family: var(--font-sans);
    font-size: 0.6875rem;
    font-weight: 400;
    letter-spacing: -0.01em;
    color: rgba(255, 255, 255, 0.38);
}

.playground-workspace-tabs {
    display: flex;
    align-items: stretch;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
    padding: 5px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.32);
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 1px 2px rgba(0, 0, 0, 0.2);
}

.playground-tab-footer .tab-btn.workspace-tab {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    padding: 9px 14px;
    border-radius: 10px;
    border: none !important;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: rgba(255, 255, 255, 0.52);
    background: transparent;
    transition:
        color 0.22s cubic-bezier(0.25, 0.1, 0.25, 1),
        background 0.22s cubic-bezier(0.25, 0.1, 0.25, 1),
        box-shadow 0.22s cubic-bezier(0.25, 0.1, 0.25, 1),
        transform 0.18s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.playground-tab-footer .tab-btn.workspace-tab i {
    font-size: 0.72rem;
    opacity: 0.9;
    flex-shrink: 0;
}

.playground-tab-footer .tab-btn.workspace-tab span {
    white-space: nowrap;
}

.playground-tab-footer .tab-btn.workspace-tab:hover:not(:disabled) {
    color: rgba(255, 255, 255, 0.92);
    background: rgba(255, 255, 255, 0.07);
}

.playground-tab-footer .tab-btn.workspace-tab.active {
    color: #ffffff;
    background: #2c8fea;
    border: none !important;
    box-shadow:
        0 2px 10px rgba(44, 143, 234, 0.42),
        0 1px 0 rgba(255, 255, 255, 0.18) inset;
    transform: none;
}

.playground-tab-footer .tab-btn.workspace-tab.active::after {
    display: none !important;
}

.playground-tab-footer:not(.playground-tabs--disabled) {
    border-top-color: rgba(44, 143, 234, 0.38);
    box-shadow:
        0 -14px 48px rgba(44, 143, 234, 0.12),
        0 -12px 40px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.playground-tab-footer:not(.playground-tabs--disabled) .playground-workspace-tabs {
    border-color: rgba(44, 143, 234, 0.18);
    background: rgba(0, 0, 0, 0.38);
}

.playground-tab-footer:not(.playground-tabs--disabled) .playground-workspace-eyebrow {
    text-shadow: 0 0 20px rgba(44, 143, 234, 0.35);
}

[data-theme="dark"] .results-section > .playground-tab-footer.playground-workspace-bar {
    background:
        linear-gradient(180deg, rgba(44, 143, 234, 0.12) 0%, rgba(44, 143, 234, 0.03) 32%, #1c1c1c 100%);
    border-top-color: rgba(44, 143, 234, 0.28);
}

[data-theme="dark"] .playground-tab-footer .tab-btn.workspace-tab.active {
    color: #ffffff;
    background: #2c8fea;
    border: none !important;
    transform: none;
}

.playground-tabs--disabled .tab-btn.workspace-tab {
    opacity: 0.42;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
}

.playground-tabs--disabled .tab-btn.workspace-tab.active {
    color: rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: none;
    border: none !important;
    transform: none;
}

/* Legacy footer selector — keep for non-workspace bars */
.results-section > .playground-tab-footer:not(.playground-workspace-bar) {
    flex: 0 0 auto;
    order: 2;
    margin-top: 0 !important;
    margin-bottom: 0;
    border-top: 1px solid var(--apple-border);
    border-bottom: 1px solid var(--apple-border);
    padding: 8px 4px 10px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    background: var(--apple-card);
    z-index: 10;
}

.results-section > .playground-tab-footer:not(.playground-workspace-bar) .tab-btn.active {
    border-top-color: var(--primary-600);
    border-bottom-color: transparent;
}

.playground-tabs--disabled .tab-btn:not(.workspace-tab) {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.playground-tabs--disabled .tab-btn:not(.workspace-tab).active {
    border-top-color: transparent;
    color: var(--gray-600);
}

@media (max-width: 900px) {
    .playground-workspace-tabs {
        gap: 4px;
        padding: 4px;
    }

    .playground-tab-footer .tab-btn.workspace-tab {
        padding: 8px 10px;
        font-size: 0.75rem;
    }

    .playground-workspace-subline {
        display: none;
    }
}

@media (max-width: 640px) {
    .playground-tab-footer.playground-workspace-bar {
        padding: 12px 10px 14px;
    }

    .playground-tab-footer .tab-btn.workspace-tab span {
        font-size: 0.6875rem;
    }
}

/* When detail panels hidden, dashboard canvas uses measured height above footer */
.results-section:not(.has-detail-panels) .playground-dashboard-zone {
    flex: 0 0 auto;
}

.playground-dashboard-zone #formattedResults.dashboard-scroll-host {
    overflow: hidden !important;
    flex: 1 1 auto !important;
}

.playground-dashboard-zone .powerbi-dashboard {
    min-height: 0;
    width: 100%;
    height: 100%;
}

.playground-tab-panels .footer-tab-content .tab-pane.active {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    flex: 0 0 auto;
    padding: 16px 8px 24px;
}

.playground-tab-panels #raw-tab.active,
.playground-tab-panels #sql-tab.active {
    overflow: visible !important;
}

.playground-tab-panels #raw-tab.active .table-wrapper {
    max-height: none !important;
    min-height: 0 !important;
    height: auto !important;
    overflow: visible !important;
    overflow-y: visible !important;
    flex: 0 0 auto;
}

.playground-tab-panels .footer-tab-content .tab-pane {
    overflow: visible !important;
    overflow-y: visible !important;
    color: var(--text-primary);
    background: transparent;
}

/* Report table — theme-aware inside playground tabs */
.playground-tab-panels .table-wrapper {
    border-color: var(--card-border, var(--gray-200));
    background: var(--card-bg, #fff);
}

.playground-tab-panels .table-wrapper table {
    background: transparent;
}

.playground-tab-panels th {
    background: var(--table-header-bg);
    color: var(--table-header-text);
    border-bottom: 1px solid var(--table-row-border);
}

.playground-tab-panels td {
    color: var(--table-row-text);
    border-bottom: 1px solid var(--table-row-border);
}

.playground-tab-panels tbody tr:nth-child(odd) {
    background: var(--table-row-even-bg);
}

.playground-tab-panels tbody tr:nth-child(even) {
    background: var(--table-row-odd-bg);
}

.playground-tab-panels tbody tr:hover {
    background: rgba(44, 143, 234, 0.08);
}

[data-theme="dark"] .playground-tab-panels th {
    background: var(--table-header-bg);
    color: var(--table-header-text);
    border-bottom-color: var(--table-row-border);
}

[data-theme="dark"] .playground-tab-panels td {
    color: var(--table-row-text);
    border-bottom-color: var(--table-row-border);
}

[data-theme="dark"] .playground-tab-panels tbody tr:nth-child(odd) {
    background: var(--table-row-even-bg);
}

[data-theme="dark"] .playground-tab-panels tbody tr:nth-child(even) {
    background: var(--table-row-odd-bg);
}

[data-theme="dark"] .playground-tab-panels tbody tr:hover {
    background: rgba(44, 143, 234, 0.1);
}

[data-theme="dark"] .playground-tab-panels .table-wrapper {
    border-color: rgba(255, 255, 255, 0.08);
    background: #1c1c1c;
    box-shadow: none;
}

[data-theme="dark"] .playground-tab-panels #raw-tab,
[data-theme="dark"] .playground-tab-panels #raw-tab.active,
[data-theme="dark"] .playground-tab-panels #insightsContent,
[data-theme="dark"] .playground-tab-panels #forecastContent,
[data-theme="dark"] .playground-tab-panels #sql-tab,
[data-theme="dark"] .playground-tab-panels #logs-tab {
    background: #1c1c1c;
    color: #e8e8ed;
}

/* Insights & forecast — theme-aware cards in playground tabs */
.playground-tab-panels #insightsContent,
.playground-tab-panels #forecastContent {
    color: var(--text-primary);
}

.playground-tab-panels .insight-section p,
.playground-tab-panels .insight-section h3,
.playground-tab-panels .insight-section h4,
.playground-tab-panels .insight-section h5 {
    color: var(--text-primary) !important;
}

.playground-tab-panels .insight-section div[style*="background: white"],
.playground-tab-panels .insight-section div[style*="background:white"] {
    background: var(--card-bg, #fff) !important;
    border-color: var(--card-border, #e5e7eb) !important;
}

.playground-tab-panels .insight-section div[style*="color: #1f2937"],
.playground-tab-panels .insight-section div[style*="color:#1f2937"],
.playground-tab-panels .insight-section div[style*="color: #4b5563"],
.playground-tab-panels .insight-section div[style*="color:#4b5563"],
.playground-tab-panels .insight-section div[style*="color: #6b7280"],
.playground-tab-panels .insight-section div[style*="color:#6b7280"] {
    color: var(--text-secondary) !important;
}

.playground-tab-panels .insight-section div[style*="background: #f9fafb"],
.playground-tab-panels .insight-section div[style*="background:#f9fafb"],
.playground-tab-panels .insight-section div[style*="background: #f3f4f6"],
.playground-tab-panels .insight-section div[style*="background:#f3f4f6"] {
    background: var(--gray-50, #f9fafb) !important;
}

[data-theme="dark"] .playground-tab-panels .insight-section div[style*="background: white"],
[data-theme="dark"] .playground-tab-panels .insight-section div[style*="background:white"] {
    background: #1c1c1c !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .playground-tab-panels .insight-section div[style*="background: #f9fafb"],
[data-theme="dark"] .playground-tab-panels .insight-section div[style*="background:#f9fafb"],
[data-theme="dark"] .playground-tab-panels .insight-section div[style*="background: #f3f4f6"],
[data-theme="dark"] .playground-tab-panels .insight-section div[style*="background:#f3f4f6"] {
    background: #181818 !important;
}

[data-theme="dark"] .playground-tab-panels #rawResults table th {
    background: var(--table-header-bg) !important;
    color: var(--table-header-text) !important;
}

[data-theme="light"] .playground-tab-panels #rawResults table th {
    background: var(--table-header-bg) !important;
    color: var(--table-header-text) !important;
}

[data-theme="light"] .playground-tab-panels #rawResults table td {
    color: var(--table-row-text) !important;
}

[data-theme="dark"] .playground-tab-panels #rawResults table td {
    color: var(--table-row-text) !important;
}

/* Insights tab — minimal, theme-aware panel */
.playground-tab-panels .insights-panel,
#insightsContent .insights-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.55;
}

.playground-tab-panels .insight-section,
#insightsContent .insight-section {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    padding: 1rem 1.125rem;
    box-shadow: none;
}

[data-theme="dark"] .playground-tab-panels .insight-section,
[data-theme="dark"] #insightsContent .insight-section {
    background: #1c1c1c;
    border-color: rgba(255, 255, 255, 0.08);
}

.insight-heading {
    color: #2c8fea;
    margin: 0 0 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.insight-heading--primary {
    color: #2c8fea;
}

.insight-heading--danger {
    color: #ef4444;
}

[data-theme="dark"] .insight-heading,
[data-theme="dark"] .insight-heading--primary {
    color: #2c8fea;
}

.insight-lead {
    font-size: 0.8125rem;
    line-height: 1.55;
    color: var(--text-primary);
    font-weight: 400;
    margin: 0;
}

.insight-summary-title {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.45;
    color: var(--text-primary);
    margin: 0 0 0.5rem;
}

.insight-summary-notes {
    margin: 0;
}

.insight-summary-note {
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.55;
    color: var(--text-secondary);
    margin: 0;
}

.insight-summary-note + .insight-summary-note {
    margin-top: 0.35rem;
}

[data-theme="dark"] .insight-summary-title {
    color: #2c8fea;
    font-weight: 600;
}

[data-theme="dark"] .insight-summary-note {
    color: #b8c5d6;
}

.executive-summary,
.insight-section.executive-summary {
    border-left: 3px solid #2c8fea;
}

[data-theme="dark"] .executive-summary,
[data-theme="dark"] .insight-section.executive-summary {
    background: linear-gradient(135deg, rgba(44, 143, 234, 0.18) 0%, rgba(44, 143, 234, 0.06) 38%, #1c1c1c 100%) !important;
    border: 1px solid rgba(44, 143, 234, 0.35) !important;
    border-left: 3px solid #2c8fea !important;
    box-shadow: 0 0 20px rgba(44, 143, 234, 0.1);
}

.executive-summary {
    padding: 12px 14px !important;
}

.insight-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.5rem;
}

.insight-metric-card {
    padding: 0.75rem 0.875rem;
    background: #f5f5f3;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .insight-metric-card {
    background: #181818;
    border-color: rgba(255, 255, 255, 0.08);
}

.insight-metric-label {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.insight-metric-value {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.insight-metric-meta,
.insight-metric-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.insight-metric-detail {
    margin-top: 0.35rem;
}

.insight-cards-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.insight-card {
    padding: 0.875rem 1rem;
    background: #f5f5f3;
    border-radius: 6px;
    border-left: 3px solid #2c8fea;
    box-shadow: none;
}

[data-theme="dark"] .insight-card {
    background: #181818;
}

.insight-card-header {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.insight-card-icon {
    font-size: 1rem;
    line-height: 1.4;
}

.insight-card-title {
    margin: 0 0 0.25rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.insight-impact-badge {
    font-size: 0.625rem;
    color: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.insight-card-body {
    color: var(--text-secondary);
    line-height: 1.55;
    margin: 0 0 0.625rem;
    font-size: 0.8125rem;
    font-weight: 400;
}

.insight-recommendation {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    padding: 0.625rem 0.75rem;
    border-radius: 6px;
}

[data-theme="dark"] .insight-recommendation {
    background: #141414;
    border-color: rgba(255, 255, 255, 0.08);
}

.insight-recommendation-label {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.insight-recommendation-text {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.55;
}

.insight-expected-outcome {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Patterns, recommendations, risks lists */
.insight-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.insight-list-item {
    padding: 0.625rem 0.75rem;
    background: #f5f5f3;
    border-left: 2px solid #2c8fea;
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-weight: 400;
}

[data-theme="dark"] .insight-list-item {
    background: #181818;
    color: #e8e8ed;
}

.insight-rec-list,
.insight-risk-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.insight-rec-card {
    padding: 0.75rem 0.875rem;
    background: #f5f5f3;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-left-width: 3px;
}

.insight-rec-card--high { border-left-color: #ef4444; }
.insight-rec-card--medium { border-left-color: #f59e0b; }
.insight-rec-card--low { border-left-color: #2c8fea; }

[data-theme="dark"] .insight-rec-card {
    background: #181818;
    border-color: rgba(255, 255, 255, 0.08);
}

.insight-rec-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.insight-rec-priority {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.insight-rec-timeline {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.insight-rec-title {
    margin: 0 0 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.insight-rec-body {
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.55;
    font-size: 0.8125rem;
    font-weight: 400;
}

.insight-rec-impact {
    margin-top: 0.5rem;
    padding: 0.5rem 0.625rem;
    background: rgba(16, 185, 129, 0.08);
    border-radius: 4px;
    border-left: 2px solid #10b981;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

[data-theme="dark"] .insight-rec-impact {
    background: rgba(16, 185, 129, 0.1);
    color: #d1d5db;
}

.insight-risk-item {
    padding: 0.625rem 0.75rem;
    background: rgba(239, 68, 68, 0.06);
    border-left: 2px solid #ef4444;
    border-radius: 4px;
    font-size: 0.8125rem;
    color: var(--text-primary);
    font-weight: 400;
}

[data-theme="dark"] .insight-risk-item {
    background: rgba(239, 68, 68, 0.1);
    color: #e8e8ed;
}

.insight-section--debug {
    border-color: rgba(245, 158, 11, 0.35);
}

.insight-debug-details summary {
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.insight-debug-pre {
    background: #f5f5f3;
    padding: 0.75rem;
    border-radius: 6px;
    overflow: auto;
    margin-top: 0.5rem;
    font-size: 0.6875rem;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .insight-debug-pre {
    background: #141414;
    border-color: rgba(255, 255, 255, 0.08);
    color: #e8e8ed;
}

.insight-impact-badge {
    font-size: 0.625rem;
    color: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.insight-metric-value--sm {
    font-size: 0.75rem !important;
    font-weight: 500;
}

.insight-system-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.insight-system-row {
    padding: 0.625rem 0.75rem;
    border-radius: 4px;
    border-left: 2px solid rgba(0, 0, 0, 0.08);
    background: #f5f5f3;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 400;
}

[data-theme="dark"] .insight-system-row {
    background: #181818;
    border-left-color: rgba(255, 255, 255, 0.08);
}

.insight-system-row--success {
    border-left-color: var(--success, #34c759);
    background: var(--success-light);
}

.insight-system-row--warning {
    border-left-color: var(--warning, #ff9500);
    background: var(--warning-light);
}

.insight-system-row--info {
    border-left-color: var(--info, #2c8fea);
    background: var(--info-light);
}

.insight-system-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.insight-system-text {
    color: var(--text-primary);
    line-height: 1.5;
}

#insights-tab,
#insightsContent {
    background: transparent;
    color: var(--text-primary);
}

/* Legacy alias */
.playground-detail-workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.playground-detail-workspace .playground-tabs-nav {
    display: none;
}

/* Legacy alias */
.playground-footer-workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.footer-tab-content {
    flex: 1;
    min-height: 0;
}

.footer-tab-content .tab-pane {
    overflow-y: auto;
    padding: 12px 16px 24px;
}

.powerbi-embed-view {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: var(--spacing-md);
    box-sizing: border-box;
    background: transparent;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.powerbi-embed-card {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: var(--apple-elevated);
    border: 1px solid var(--apple-border);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-md, 0 4px 24px rgba(0, 0, 0, 0.08));
    overflow: hidden;
}

[data-theme="dark"] .powerbi-embed-card {
    box-shadow: 0 4px 28px rgba(0, 0, 0, 0.35);
}

.powerbi-embed-host {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.powerbi-embed-host iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* Normal / Power BI mode — full width + full height card */
.playground-canvas.playground-mode-powerbi {
    background: var(--playground-surface);
    border-radius: var(--radius-2xl);
    overflow: hidden;
    height: 100%;
    min-height: 0;
}

.playground-canvas.playground-mode-powerbi .powerbi-embed-view {
    display: flex;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: var(--spacing-md);
}

.powerbi-embed-fallback {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f1419 0%, #1a2744 100%);
    padding: 24px;
    border-radius: inherit;
}

.powerbi-embed-fallback-inner {
    text-align: center;
    max-width: 420px;
    color: #f3f4f6;
}

.powerbi-embed-fallback-inner i {
    font-size: 3rem;
    color: #2c8fea;
    margin-bottom: 16px;
}

.powerbi-embed-fallback-inner h2 {
    margin: 0 0 12px;
    font-size: 1.5rem;
}

.powerbi-embed-fallback-inner p {
    color: rgba(243, 244, 246, 0.85);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 1.25rem;
}

[data-theme="light"] .powerbi-embed-fallback {
    background: linear-gradient(160deg, #f5f5f7 0%, #e8ecf4 100%);
}

[data-theme="light"] .powerbi-embed-fallback-inner {
    color: var(--text-primary, #1d1d1f);
}

[data-theme="light"] .powerbi-embed-fallback-inner p {
    color: var(--text-secondary, #6e6e73);
}

.powerbi-open-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.kb-cards-page .kb-cards-layout {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(340px, 1.15fr);
    gap: 16px;
    align-items: start;
}

.kb-page-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 32px 32px;
    width: 100%;
    box-sizing: border-box;
}

.kb-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.kb-page-header-content {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.kb-page-header-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--apple-blue);
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
}

.kb-page-title {
    margin: 0 0 4px;
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--apple-text);
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.kb-page-subtitle {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--apple-muted);
    line-height: 1.5;
    max-width: 640px;
}

.kb-card-form-panel,
.kb-cards-list-panel {
    display: flex;
    flex-direction: column;
    background: var(--apple-card);
    border: 1px solid var(--apple-border);
    border-radius: 10px;
    padding: 0;
    box-shadow: var(--shadow-xs);
}

/* Left — natural content height only */
.kb-card-form-panel {
    height: auto;
    align-self: start;
    overflow: visible;
}

/* Right — height synced to left panel via JS; list scrolls inside */
.kb-cards-list-panel {
    overflow: hidden;
    min-height: 0;
}

.kb-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--apple-border);
    flex-shrink: 0;
    background: var(--apple-card);
}

.kb-panel-title {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--apple-text);
    letter-spacing: -0.01em;
}

.kb-panel-title i {
    color: var(--apple-blue);
    font-size: 0.8125rem;
}

.kb-cards-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(44, 143, 234, 0.1);
    color: var(--apple-blue);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.kb-form {
    display: flex;
    flex-direction: column;
}

.kb-form-scroll {
    padding: 16px 18px;
}

.kb-form-scroll .form-group {
    margin-bottom: 14px;
}

.kb-form-scroll .form-group:last-child {
    margin-bottom: 0;
}

.kb-form-actions {
    flex-shrink: 0;
    margin-top: 0 !important;
    padding: 12px 18px !important;
    border-top: 1px solid var(--apple-border) !important;
    gap: 8px;
}

.kb-cards-list-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 14px 18px 18px;
    gap: 12px;
}

.kb-cards-list-body .kb-search-box {
    flex-shrink: 0;
    margin: 0;
}

.kb-cards-list-body .kb-search-box input {
    width: 100%;
    padding: 8px 12px 8px 34px;
    font-size: 0.8125rem;
    border-radius: 8px;
    border: 1px solid var(--apple-border);
    background: var(--apple-shell);
    color: var(--apple-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.kb-cards-list-body .kb-search-box input:focus {
    outline: none;
    border-color: rgba(44, 143, 234, 0.45);
    box-shadow: 0 0 0 3px rgba(44, 143, 234, 0.12);
    background: var(--apple-card);
}

.kb-cards-list-body .kb-search-box i {
    left: 12px;
    font-size: 0.75rem;
    color: var(--apple-muted);
}

[data-theme="dark"] .kb-cards-list-body .kb-search-box input {
    background: #141414;
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .kb-cards-list-body .kb-search-box input:focus {
    background: #1c1c1c;
}

.kb-sql-input {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.kb-cards-grid {
    display: grid;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    max-height: none;
    align-content: start;
}

.kb-query-card {
    border: 1px solid var(--apple-border);
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--apple-card);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    cursor: pointer;
}

.kb-query-card:hover {
    border-color: rgba(44, 143, 234, 0.28);
    box-shadow: var(--shadow-xs);
}

.kb-query-card-question {
    margin: 0 0 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--apple-text);
    line-height: 1.45;
    letter-spacing: -0.01em;
}

.kb-cards-list-body .kb-entries-empty,
.kb-cards-list-body .kb-entries-loading {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.kb-cards-list-body .kb-entries-empty i {
    font-size: 2rem;
    color: var(--gray-300);
    margin-bottom: 10px;
}

.kb-cards-list-body .kb-entries-empty h4 {
    font-size: 0.875rem;
    margin-bottom: 4px;
}

.kb-cards-list-body .kb-entries-empty p {
    font-size: 0.75rem;
    color: var(--apple-muted);
}

[data-theme="dark"] .kb-page-title {
    color: #f3f4f6;
}

[data-theme="dark"] .kb-page-subtitle {
    color: #9ca3af;
}

[data-theme="dark"] .kb-card-form-panel,
[data-theme="dark"] .kb-cards-list-panel {
    background: #1c1c1c;
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .kb-panel-header {
    background: #1c1c1c;
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .kb-query-card {
    background: #141414;
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .kb-query-card:hover {
    border-color: rgba(44, 143, 234, 0.35);
}

@media (max-width: 1024px) {
    .kb-cards-page .kb-cards-layout {
        grid-template-columns: 1fr;
    }

    .kb-cards-list-panel {
        height: auto !important;
        max-height: none !important;
        min-height: 280px;
    }

    .kb-cards-grid {
        max-height: 360px;
    }
}

@media (max-width: 768px) {
    .kb-page-container {
        padding: 16px 16px 24px;
    }

    .kb-page-header {
        flex-direction: column;
        align-items: stretch;
    }
}

.kb-viz-badge {
    font-size: 0.6875rem;
    padding: 2px 8px;
    border-radius: 999px;
    margin-right: 6px;
    white-space: nowrap;
}

.kb-viz-badge--ready {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.kb-viz-badge--pending {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.kb-viz-badge--failed {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.kb-quick-cards {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

/* Playground chat panel overrides live in chatbot.css (.right-panel .kb-quick-cards) */

/* PDF export capture — must beat dark-theme insight/audit rules defined later in this file */
html[data-theme="dark"] .pdf-export-capture,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-section,
html[data-theme="dark"] .pdf-export-capture .insight-section,
html[data-theme="dark"] .pdf-export-capture .insight-metric-card,
html[data-theme="dark"] .pdf-export-capture .insight-card,
html[data-theme="dark"] .pdf-export-capture .insight-rec-card,
html[data-theme="dark"] .pdf-export-capture .insight-section--summary,
html[data-theme="dark"] .pdf-export-capture .executive-summary,
html[data-theme="dark"] .pdf-export-capture .insight-section.executive-summary {
    background: #ffffff !important;
    color: #111827 !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    box-shadow: none !important;
}

html[data-theme="dark"] .pdf-export-capture .executive-summary,
html[data-theme="dark"] .pdf-export-capture .insight-section.executive-summary {
    background: #f8fafc !important;
    border-color: rgba(44, 143, 234, 0.35) !important;
    border-left-color: #2c8fea !important;
}

html[data-theme="dark"] .pdf-export-capture .prompt-driven-section-title,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-h2,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-h3,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-h4,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-h5,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-h6,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-p,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-body,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-section-body,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-list,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-ol,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-table th,
html[data-theme="dark"] .pdf-export-capture .prompt-driven-table td,
html[data-theme="dark"] .pdf-export-capture .insight-lead,
html[data-theme="dark"] .pdf-export-capture .insight-card-body,
html[data-theme="dark"] .pdf-export-capture .insight-card-title,
html[data-theme="dark"] .pdf-export-capture .insight-rec-title,
html[data-theme="dark"] .pdf-export-capture .insight-rec-body,
html[data-theme="dark"] .pdf-export-capture .insight-metric-value,
html[data-theme="dark"] .pdf-export-capture .insight-list-item,
html[data-theme="dark"] .pdf-export-capture .insight-risk-item,
html[data-theme="dark"] .pdf-export-capture .insight-recommendation-text,
html[data-theme="dark"] .pdf-export-capture .insight-expected-outcome,
html[data-theme="dark"] .pdf-export-capture .insight-rec-impact,
html[data-theme="dark"] .pdf-export-capture .audit-report-brand-title,
html[data-theme="dark"] .pdf-export-capture .audit-report-brand-subtitle,
html[data-theme="dark"] .pdf-export-capture .insight-summary-note,
html[data-theme="dark"] .pdf-export-capture .insight-metric-label,
html[data-theme="dark"] .pdf-export-capture .insight-metric-meta,
html[data-theme="dark"] .pdf-export-capture .insight-metric-detail {
    color: #111827 !important;
}

html[data-theme="dark"] .pdf-export-capture .insight-heading,
html[data-theme="dark"] .pdf-export-capture .insight-heading--primary,
html[data-theme="dark"] .pdf-export-capture .insight-summary-title {
    color: #1d6fbf !important;
}

html[data-theme="dark"] .pdf-export-capture .prompt-driven-table th {
    background: #f3f4f6 !important;
}

html[data-theme="dark"] .pdf-export-capture .insight-metric-card,
html[data-theme="dark"] .pdf-export-capture .insight-card {
    background: #f9fafb !important;
}

