/* ============================================
   THEME SYSTEM - CSS Variables
   ============================================ */

:root {
    /* Light Theme - Blue (Default) */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;
    --bg-input: #f1f5f9;
    --bg-trace: #0f172a;
    --bg-trace-header: #020617;

    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --text-sidebar: #cbd5e1;
    --text-sidebar-active: #ffffff;

    --border-color: #e2e8f0;
    --border-sidebar: #334155;

    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #dbeafe;
    --accent-dark: #1e40af;

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Dark Theme */
body.theme-dark {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-sidebar: #020617;
    --bg-sidebar-hover: #1e293b;
    --bg-input: #334155;
    --bg-trace: #0f172a;
    --bg-trace-header: #020617;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --text-sidebar: #94a3b8;
    --text-sidebar-active: #ffffff;

    --border-color: #334155;
    --border-sidebar: #475569;

    --accent-light: rgba(59, 130, 246, 0.2);
}

/* Color Themes */
body.theme-blue {
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-dark: #1e40af;
}

body.theme-green {
    --accent: #10b981;
    --accent-hover: #059669;
    --accent-dark: #047857;
}

body.theme-purple {
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --accent-dark: #6d28d9;
}

body.theme-orange {
    --accent: #f97316;
    --accent-hover: #ea580c;
    --accent-dark: #c2410c;
}

body.theme-pink {
    --accent: #ec4899;
    --accent-hover: #db2777;
    --accent-dark: #be185d;
}

body.theme-indigo {
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-dark: #4338ca;
}

/* ============================================
   BASE STYLES
   ============================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   SIDEBAR
   ============================================ */

.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    /* border-right: 1px solid var(--border-sidebar); */
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    justify-content: flex-start;
    height: 64px;
    background: var(--bg-secondary);
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: #ffffff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 18px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    padding: 4px;
}

.brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-sidebar-active);
    letter-spacing: 0.5px;
}

.brand-subtitle {
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: 'Courier New', monospace;
}

.sidebar-content {
    flex: 1;
    overflow: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-secondary);
}

.sidebar-section {
    margin-bottom: 24px;
    flex-shrink: 0;
}

.sidebar-section:first-child {
    margin-bottom: 16px;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}

.context-box {
    background-color: var(--bg-tertiary);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border-sidebar);
    font-size: 12px;
    font-family: 'Courier New', monospace;
}

.context-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.context-item:last-child {
    margin-bottom: 0;
}

.context-value {
    color: var(--accent);
    font-weight: 600;
}

.context-value.success {
    color: var(--success);
}

.history-list-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.history-list-container::-webkit-scrollbar {
    width: 6px;
}

.history-list-container::-webkit-scrollbar-track {
    background: transparent;
}

.history-list-container::-webkit-scrollbar-thumb {
    background: var(--border-sidebar);
    border-radius: 3px;
}

.history-load-more {
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 11px;
}

.history-load-more-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.history-load-more-content i {
    font-size: 12px;
    color: var(--accent);
}

.history-list-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.sidebar-history-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-history-section .sidebar-section-title {
    flex-shrink: 0;
}

.history-search-container {
    position: relative;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.history-search-input {
    width: 100%;
    padding: 8px 32px 8px 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-sidebar);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-primary);
    transition: all 0.2s;
    box-sizing: border-box;
}

.history-search-input::placeholder {
    color: var(--text-tertiary);
}

.history-search-input:focus {
    outline: none;
    border-color: var(--accent);
    background-color: var(--bg-secondary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.history-search-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 12px;
    pointer-events: none;
}

.history-list {
    list-style: none;
}

.history-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    margin-bottom: 4px;
}

.history-item:hover {
    background-color: var(--bg-sidebar-hover);
}

.history-item.active {
    color: var(--text-sidebar-active);
    background-color: var(--bg-sidebar-hover);
}

.history-item i {
    color: var(--accent);
    width: 16px;
}

/* History session items in sidebar */
.sidebar-history-session {
    padding: 10px 12px;
    margin-bottom: 6px;
    background-color: var(--bg-tertiary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    position: relative;
}

.sidebar-history-session:hover {
    background-color: var(--bg-sidebar-hover);
}

/* Loading state for sessions */
.sidebar-history-session.loading-session {
    cursor: wait;
}

.sidebar-history-session.loading-session:hover {
    background-color: var(--bg-tertiary);
}

.session-loading-spinner {
    display: inline-block;
    margin-left: 6px;
}

.session-loading-spinner i {
    animation: spin 1s linear infinite;
}

/* Current session (active) - most prominent with accent background */
.sidebar-history-session.active {
    border-left-color: var(--accent);
    border-left-width: 4px;
    background-color: var(--accent-light);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-history-session.active:hover {
    background-color: var(--accent-light);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Pinned sessions - distinct styling with warning color */
.sidebar-history-session.pinned {
    border-left-color: var(--warning);
    border-left-width: 3px;
    background-color: var(--bg-tertiary);
    position: relative;
}

.sidebar-history-session.pinned:hover {
    background-color: var(--bg-sidebar-hover);
}

.sidebar-history-session.pinned::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: linear-gradient(to bottom, var(--warning), var(--accent));
    border-radius: 6px 0 0 6px;
}

/* When session is both active and pinned - prioritize active styling */
.sidebar-history-session.active.pinned {
    border-left-color: var(--accent);
    border-left-width: 4px;
    background-color: var(--accent-light);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-history-session.active.pinned:hover {
    background-color: var(--accent-light);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.sidebar-history-session.active.pinned::before {
    display: none;
    /* Hide pinned gradient when active */
}

.sidebar-history-session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    gap: 8px;
}

.sidebar-history-session-id {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    flex: 1;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Make active session ID more prominent */
.sidebar-history-session.active .sidebar-history-session-id {
    color: var(--accent-dark);
    font-weight: 700;
}

.pinned-icon {
    color: var(--warning);
    font-size: 10px;
    flex-shrink: 0;
}

.sidebar-history-session-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    position: relative;
}

.session-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 3px;
    font-size: 12px;
    opacity: 0.6;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.session-menu-btn:hover {
    opacity: 1;
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.session-context-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 1000;
    overflow: hidden;
    animation: slideDown 0.2s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.context-menu-item {
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
    font-family: inherit;
}

.context-menu-item:hover {
    background-color: var(--bg-tertiary);
}

.context-menu-item-danger {
    color: var(--error);
}

.context-menu-item-danger:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

.context-menu-item i {
    width: 16px;
    text-align: center;
    font-size: 12px;
}

.session-pin-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 10px;
    opacity: 0.6;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.session-pin-btn:hover {
    opacity: 1;
    background-color: var(--bg-sidebar-hover);
    color: var(--warning);
}

.session-pin-btn.pinned {
    color: var(--warning);
    opacity: 1;
}

.session-pin-btn.pinned:hover {
    color: var(--accent);
}

.session-name-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 10px;
    opacity: 0.6;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.session-name-btn:hover {
    opacity: 1;
    background-color: var(--bg-sidebar-hover);
    color: var(--accent);
}

.sidebar-history-session-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    cursor: pointer;
}

.sidebar-history-session-time {
    font-size: 10px;
    color: var(--text-tertiary);
}

.sidebar-history-session-preview {
    font-size: 11px;
    color: var(--text-sidebar);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
    cursor: pointer;
}

.sidebar-history-session-count {
    font-size: 10px;
    color: var(--text-tertiary);
}

.sidebar-footer {
    padding: 16px;
    /* border-top: 1px solid var(--border-sidebar); */
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 13.4%;
    justify-content: center;
}

.sidebar-new-session-btn {
    background: var(--accent);
    border: none;
    color: white;
    padding: 12px 16px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    width: 100%;
    box-shadow: var(--shadow-sm);
}

.sidebar-new-session-btn:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.sidebar-new-session-btn i {
    width: 16px;
    font-size: 14px;
}

.sidebar-btn {
    background: transparent;
    border: 1px solid var(--border-sidebar);
    color: var(--text-sidebar);
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    transition: all 0.2s;
}

.sidebar-btn:hover {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.sidebar-btn i {
    width: 16px;
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.3s ease;
}


.toolbar {
    height: 64px;
    background-color: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    justify-content: flex-start;
}

.toolbar-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: left;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    padding-right: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
    animation: pulse 2s infinite;
}

.status-dot.disconnected {
    background-color: var(--error);
    box-shadow: 0 0 8px var(--error);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    width: 36px;
    height: 36px;
    font-size: 16px;
}

.icon-btn i {
    display: inline-block;
    font-size: inherit;
}

.trace-toggle-btn {
    gap: 6px;
    padding: 8px 12px;
    width: auto;
    min-width: 80px;
}

.trace-toggle-label {
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
}

.language-selector-container {
    display: flex;
    align-items: center;
}

.language-selector {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
    min-width: 120px;
}

.language-selector:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--accent);
}

.language-selector:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.2);
}

.icon-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============================================
   CHAT CONTAINER
   ============================================ */

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
    padding: 24px;
    background-color: var(--bg-primary);
    scroll-behavior: smooth;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto 24px;
    animation: fadeInUp 0.5s ease-out forwards;
    opacity: 0;
    transform: translateY(10px);
    overflow: visible;
    position: relative;
}

/* Allow messages with charts to expand to full width */
/* .message:has(.chart-container) {
    max-width: 100%;
    margin-left: -24px;
    margin-right: -24px;
    width: calc(100% + 48px);
} */

.message:has(.chart-container) .flex-1 {
    width: 100%;
    max-width: 100%;
}

/* Make chart container extend to edges and take full width */
.message:has(.chart-container) .chart-container {
    margin-left: 0;
    margin-right: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 24px;
    width: 100% !important;
    max-width: 100% !important;
}

.message.user {
    flex-direction: row-reverse;
    margin-left: auto;
    overflow: visible;
}

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

.agent-avatar {
    background-color: var(--accent-light);
    border: 1px solid var(--accent);
    color: var(--accent);
}

.user-avatar {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.message-bubble-container {
    position: relative;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.message-bubble {
    padding: 16px 20px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    font-size: 14px;
    line-height: 1.6;
    max-width: 100%;
    overflow: visible;
}

.agent-bubble {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-top-left-radius: 4px;
}

.user-bubble {
    background-color: var(--accent);
    color: white;
    border-top-right-radius: 4px;
}

.message-timestamp-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    justify-content: flex-end;
}

.message-timestamp {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 0 4px;
    opacity: 0.7;
}

.message.user .message-timestamp {
    text-align: right;
}

.message-copy-btn {
    background: transparent;
    border: none;
    border-radius: 4px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
    color: var(--text-secondary);
    font-size: 11px;
    padding: 0;
    z-index: 10;
    pointer-events: auto;
    -webkit-user-select: none;
    user-select: none;
}

.message.user:hover .message-timestamp-container .message-copy-btn {
    opacity: 0.8;
}

.message-copy-btn:hover {
    background: var(--bg-tertiary);
}

/* ============================================
   FEEDBACK BUTTONS
   ============================================ */
.feedback-container {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.feedback-btn {
    background: var(--bg-secondary);
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 32px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.feedback-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.feedback-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.feedback-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    box-shadow: none;
}

.feedback-btn-up.active,
.feedback-btn-up:disabled {
    background: #dcfce7;
    border-color: #22c55e;
    color: #166534;
    box-shadow: 0 1px 3px rgba(34, 197, 94, 0.2);
}

.feedback-btn-down.active,
.feedback-btn-down:disabled {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
    box-shadow: 0 1px 3px rgba(239, 68, 68, 0.2);
}

.feedback-confirmation {
    color: var(--success);
    font-size: 12px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.feedback-error {
    color: var(--error);
    font-size: 12px;
    margin-top: 4px;
}

.retry-loading {
    color: var(--accent);
    font-size: 12px;
    margin-top: 8px;
    padding: 8px;
    background: var(--accent-light);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.retry-indicator {
    text-align: center;
    color: var(--text-secondary);
    font-size: 11px;
    margin: 8px 0;
    font-style: italic;
    opacity: 0.7;
}

/* Dark theme adjustments for feedback buttons */
body.theme-dark .feedback-btn {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

body.theme-dark .feedback-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

body.theme-dark .feedback-btn-up.active,
body.theme-dark .feedback-btn-up:disabled {
    background: rgba(34, 197, 94, 0.15);
    border-color: #22c55e;
    color: #86efac;
}

body.theme-dark .feedback-btn-down.active,
body.theme-dark .feedback-btn-down:disabled {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #fca5a5;
}
    color: var(--accent);
    opacity: 1 !important;
}

.message-copy-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.message-copy-btn:active {
    transform: scale(0.95);
}

.message-bubble ul {
    margin: 12px 0;
    padding-left: 20px;
}

.message-bubble li {
    margin: 6px 0;
}

/* Cognitive Trace */
.cognitive-trace {
    background-color: var(--bg-trace);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-sidebar);
    margin-bottom: 12px;
}

.trace-header {
    background-color: var(--bg-trace-header);
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.trace-header:hover {
    background-color: var(--bg-sidebar-hover);
}

.trace-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.trace-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--warning);
    animation: pulse 1s infinite;
}

.trace-label {
    font-size: 10px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--accent);
}

.trace-content {
    padding: 12px;
    font-size: 10px;
    font-family: 'Courier New', monospace;
    color: var(--text-sidebar);
    max-height: 200px;
    overflow-y: auto;
    background-color: rgba(15, 23, 42, 0.5);
}

.trace-line {
    margin-bottom: 4px;
    padding: 2px 0;
}

.trace-line.action {
    color: var(--warning);
}

.trace-line.input {
    color: #fbbf24;
    padding-left: 16px;
}

.trace-line.observation {
    color: var(--success);
}

.trace-line.security {
    color: var(--error);
    font-weight: 700;
}

/* Charts */
.chart-container {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 400px;
    height: auto;
    margin: 16px 0;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 16px;
    box-sizing: border-box;
    box-shadow: var(--shadow-sm);
    display: block;
    position: relative;
    overflow: visible;
}

/* Ensure charts are responsive */
.chart-container canvas {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
}

/* Ensure ECharts instance takes full width */
.chart-container>div {
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible;
}

/* Ensure ECharts tooltips are visible and properly positioned */
div[id^="echarts-tooltip"] {
    z-index: 99999 !important;
    pointer-events: none;
}

/* Ensure ECharts text elements are visible in light mode */
body.theme-light .chart-container text,
body.theme-light .chart-container tspan {
    fill: #0f172a !important;
}

/* Ensure ECharts text elements are visible in dark mode */
body.theme-dark .chart-container text,
body.theme-dark .chart-container tspan {
    fill: #f1f5f9 !important;
}

/* Ensure ECharts axis labels are visible */
body.theme-light .chart-container .echarts-axis-label {
    color: #0f172a !important;
}

body.theme-dark .chart-container .echarts-axis-label {
    color: #f1f5f9 !important;
}

/* Force pie/donut chart label colors in light mode */
body.theme-light .chart-container text[style*="fill"] {
    fill: #0f172a !important;
}

/* Ensure label lines are visible in light mode */
body.theme-light .chart-container line[stroke] {
    stroke: #0f172a !important;
}

/* Override any light grey colors in labels for light mode */
body.theme-light .chart-container text[fill="#999"],
body.theme-light .chart-container text[fill="#999999"],
body.theme-light .chart-container text[fill="#cccccc"],
body.theme-light .chart-container text[fill="#e0e0e0"],
body.theme-light .chart-container text[fill="rgb(153, 153, 153)"],
body.theme-light .chart-container text[fill="rgb(204, 204, 204)"],
body.theme-light .chart-container text[fill="rgb(224, 224, 224)"] {
    fill: #0f172a !important;
}

/* Consistent styling for pie and donut chart labels - handled by JavaScript, CSS as fallback */
/* The JavaScript code ensures pie/donut charts get consistent label colors */

/* Ensure the bubble container with charts takes full width */
.flex-1:has(.chart-container) {
    width: 100%;
    max-width: 100%;
    overflow: visible;
}

/* Ensure flex-1 containers don't clip tooltips */
.flex-1 {
    overflow: visible;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    font-size: 13px;
}

/* Structured text tables (converted from text) */
.structured-text-table {
    margin: 12px 0;
    font-size: 13px;
}

.structured-text-table .structured-key {
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    width: 40%;
    vertical-align: top;
}

.structured-text-table .structured-value {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: top;
}

.structured-text-table tr:last-child .structured-key,
.structured-text-table tr:last-child .structured-value {
    border-bottom: none;
}

.data-table th {
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    padding: 10px;
    color: var(--text-secondary);
    font-weight: 600;
    background-color: var(--bg-tertiary);
}

.data-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.badge.HIGH,
.badge.Critical {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid #ef4444;
}

.badge.LOW,
.badge.Minor {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
    border: 1px solid #10b981;
}

.badge.Major {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
    border: 1px solid #f59e0b;
}

/* ============================================
   INPUT AREA
   ============================================ */

.input-area {
    background-color: var(--bg-secondary);
    padding: 20px 24px 24px;
}

.input-container {
    max-width: 900px;
    margin: 0 auto;
}

.suggestion-chips {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.suggestion-chip {
    white-space: nowrap;
    font-size: 12px;
    background-color: var(--accent-light);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-chip:hover {
    background-color: var(--accent);
    color: white;
}

.input-form {
    position: relative;
    display: flex;
    align-items: center;
}

.input-field {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 14px;
    border-radius: 12px;
    padding: 14px 50px 14px 16px;
    outline: none;
    transition: all 0.2s;
}

.input-field:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input-field:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 10px 16px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--accent-light);
}

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

.input-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    padding: 0 4px;
}

.footer-text {
    font-size: 10px;
    color: var(--text-tertiary);
}

.footer-text i {
    color: var(--success);
    margin-right: 4px;
}

/* ============================================
   HISTORY PANEL
   ============================================ */

/* History panel removed - history is now always visible in sidebar */

/* ============================================
   THEME SETTINGS PANEL
   ============================================ */

.theme-settings-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.theme-settings-overlay.active {
    display: block;
    opacity: 1;
}

.theme-settings {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: 440px;
    max-width: 90vw;
    max-height: 90vh;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--border-color);
    z-index: 10000;
    overflow: hidden;
    opacity: 0;
    transition: all 0.2s ease;
}

.theme-settings.active {
    display: block;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.theme-settings-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-secondary);
}

.theme-settings-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.theme-settings-icon {
    font-size: 16px;
    color: var(--text-secondary);
}

.theme-settings-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: 0;
}

.theme-close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    font-size: 16px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.theme-close-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.theme-settings-content {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(90vh - 100px);
}

.theme-group {
    margin-bottom: 24px;
}

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

.theme-group-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.theme-group-label i {
    color: var(--text-tertiary);
    font-size: 12px;
}

.theme-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mode-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.theme-option {
    padding: 10px 16px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.theme-option:hover {
    border-color: var(--accent);
    background-color: var(--bg-secondary);
}

.theme-option.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

.theme-option.active i {
    color: white;
}

.theme-option i {
    font-size: 14px;
    color: var(--text-secondary);
}

.theme-option.active i {
    color: white;
}

.color-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.color-option {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    min-height: 70px;
}

.color-preview {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1.5px solid var(--border-color);
    transition: all 0.15s ease;
    position: relative;
}

.color-preview::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.15s ease;
}

.theme-option.active .color-preview {
    border-color: var(--accent);
    border-width: 2px;
}

.theme-option.active .color-preview::after {
    transform: translate(-50%, -50%) scale(1);
}

.color-name {
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
    color: var(--text-secondary);
}

.theme-option.active .color-name {
    color: white;
    font-weight: 500;
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.5s ease-out forwards;
}

.typing-cursor::after {
    content: '▋';
    animation: blink 1s step-start infinite;
    color: var(--accent);
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* ============================================
   SCROLLBAR
   ============================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   LOADING INDICATOR
   ============================================ */

.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

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

/* ============================================
   COGNITIVE TRACE STYLES
   ============================================ */

.cognitive-trace-container {
    margin-bottom: 12px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-trace);
}

.cognitive-trace-header {
    background: var(--bg-trace-header);
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.cognitive-trace-header:hover {
    background: var(--bg-sidebar-hover);
}

.trace-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.trace-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fbbf24;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.trace-label {
    font-size: 10px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    letter-spacing: 1px;
    color: var(--accent);
    text-transform: uppercase;
}

.trace-chevron {
    font-size: 10px;
    color: var(--text-tertiary);
    transition: transform 0.2s;
}

.cognitive-trace-content {
    padding: 12px;
    background: rgba(15, 23, 42, 0.5);
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    line-height: 1.6;
}

.trace-step {
    margin-bottom: 6px;
    padding: 4px 0;
    color: var(--text-tertiary);
}

.trace-action {
    color: #fbbf24;
}

.trace-input {
    color: #fde047;
    padding-left: 16px;
}

.trace-observation {
    color: #34d399;
}

.trace-step {
    white-space: pre-wrap;
    word-break: break-word;
}

.trace-step br {
    display: block;
    content: "";
    margin-top: 2px;
}

/* ============================================
   CUSTOM MODAL DIALOGS
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-container {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-tertiary);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 18px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
}

.modal-message {
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0 0 16px 0;
}

.modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    background-color: var(--bg-input);
    color: var(--text-primary);
    transition: all 0.2s;
    box-sizing: border-box;
    margin-top: 8px;
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent);
    background-color: var(--bg-secondary);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background-color: var(--bg-tertiary);
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.modal-btn-primary {
    background-color: var(--accent);
    color: white;
}

.modal-btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.modal-btn-secondary {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

.modal-btn-secondary:hover {
    background-color: var(--bg-tertiary);
}

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

/* Scrollbar styling for trace content */
.cognitive-trace-content::-webkit-scrollbar {
    width: 6px;
}

.cognitive-trace-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.cognitive-trace-content::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 3px;
}

.cognitive-trace-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Active state for trace toggle button */
.icon-btn.active {
    background: var(--accent-light);
    color: var(--accent);
}

/* ============================================
   EMPTY STATE
   ============================================ */

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    padding: 20px;
}

.empty-state-content {
    text-align: center;
    max-width: 400px;
    background: var(--bg-secondary);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin: 0 auto 20px;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.primary-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

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

.primary-btn i {
    font-size: 14px;
}

/* ============================================
   DATASOURCE RADIO SELECTION
   ============================================ */

.datasource-radio-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
    width: 100%;
}

.datasource-radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.datasource-radio-option:hover {
    border-color: var(--accent);
    background: var(--bg-secondary);
}

.datasource-radio-option input[type="radio"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.datasource-radio-option:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-light);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.datasource-radio-option span {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    text-transform: capitalize;
}
.chart-custom-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    text-align: left;
    padding: 0 8px;
}
