/* Design tokens - VSCode & Solarized inspired */
:root {
    color-scheme: light;

    /* Surfaces & Text - Light mode (clean grays) */
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;

    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;

    /* Brand - Muted teal */
    --primary: 174 64% 48%;
    --primary-foreground: 0 0% 100%;

    --secondary: 174 30% 94%;
    --secondary-foreground: 174 15% 25%;

    /* Accents & States */
    --muted: 174 25% 96%;
    --muted-foreground: 174 12% 45%;

    --accent: 174 35% 92%;
    --accent-foreground: 174 20% 20%;

    --success: 142 76% 36%;
    --warning: 45 93% 47%;
    --error: 0 84.2% 60.2%;

    /* Chrome */
    --border: 174 20% 88%;
    --input: 174 20% 88%;
    --ring: 222.2 84% 4.9%;
    --radius: 0.4rem;  /* Tighter corners */

    /* Shadows */
    --shadow-color: 222 10% 20%;
}

/* Dark mode - Solarized-inspired */
[data-theme="dark"] {
    color-scheme: dark;

    /* Solarized base03/base02 */
    --background: 193 100% 11%;      /* #002b36 */
    --foreground: 44 87% 94%;        /* #fdf6e3 - base3 */

    --card: 192 81% 14%;             /* #073642 - base02 */
    --card-foreground: 44 87% 94%;

    /* Solarized cyan for primary */
    --primary: 175 59% 40%;          /* #2aa198 */
    --primary-foreground: 44 87% 94%;

    --secondary: 192 90% 18%;
    --secondary-foreground: 186 8% 55%;  /* base0 */

    /* Accents & States - Solarized palette */
    --muted: 192 90% 18%;
    --muted-foreground: 186 13% 59%;     /* base00 */

    --accent: 194 80% 22%;
    --accent-foreground: 44 87% 94%;

    --success: 68 100% 30%;          /* Solarized green */
    --warning: 45 100% 51%;          /* Solarized yellow */
    --error: 1 71% 52%;              /* Solarized red */

    /* Chrome */
    --border: 193 99% 21%;
    --input: 192 90% 18%;
    --ring: 175 59% 40%;

    /* Shadows */
    --shadow-color: 0 0% 0%;
}

/* Theme-aware syntax highlighting */
:root #hljs-dark {
    display: none;
}

[data-theme="dark"] #hljs-light {
    display: none;
}

[data-theme="dark"] #hljs-dark {
    display: block;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    font-size: 14px;  /* Comfortable reading size */
    margin: 0;
    padding: 0;
    background: hsl(var(--background));
    min-height: 100vh;
    color: hsl(var(--foreground));
    display: flex;
    overflow: hidden;
}

@media (max-width: 768px) {
    body {
        overflow: visible;
    }
}

.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
}

/* ============================================
   TOP APPLICATION TOOLBAR
   ============================================ */

.app-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 50px;
    background: hsl(var(--card));
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    padding: 0 16px;
    flex-shrink: 0;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-left {
    flex: 0 0 auto;
}

.toolbar-center {
    flex: 1 1 auto;
    justify-content: center;
    max-width: 600px;
}

.toolbar-right {
    flex: 0 0 auto;
    position: relative;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    color: hsl(var(--foreground));
    letter-spacing: 0.5px;
}

.toolbar-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
}

/* Content wrapper below toolbar */
.app-content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar,
.main-area {
    height: 100%;
}

@media (max-width: 768px) {
    .toolbar-center {
        display: none; /* Hide agent selector on mobile, show in hamburger menu */
    }

    .toolbar-label {
        display: none;
    }
}

.sidebar {
    width: 260px;  /* Narrower */
    background: hsl(var(--card) / 0.95);
    backdrop-filter: blur(8px);
    border-right: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: relative;
    transition: width 0.2s ease;
}

.sidebar.slim {
    width: 52px;  /* Slimmer */
}

@media (max-width: 768px) {
    .sidebar:not(.slim) {
        width: 100%;
        max-height: 280px;
        border-right: none;
        border-bottom: 1px solid hsl(var(--border) / 0.5);
    }

    .sidebar.slim {
        width: 52px;
        height: 100vh;
        border-right: 1px solid hsl(var(--border) / 0.5);
        border-bottom: none;
    }
}

.status-indicator {
    flex-shrink: 0;
    margin-left: auto;
}

.sidebar.slim .status-indicator {
    margin-left: 0;
}

.status-indicator circle {
    fill: hsl(var(--muted-foreground));
    stroke: hsl(var(--border));
    stroke-width: 1;
}

.status-indicator.connecting circle {
    fill: hsl(45, 93%, 47%);
    animation: pulseStatus 2s ease-in-out infinite;
}

.status-indicator.connected circle {
    fill: hsl(142, 76%, 36%);
}

.status-indicator.error circle {
    fill: hsl(0, 84%, 60%);
}

@keyframes pulseStatus {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.hamburger-btn {
    width: 36px;  /* Smaller */
    height: 36px;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    color: hsl(var(--foreground));
    font-size: 18px;
    flex-shrink: 0;
}

.hamburger-btn:hover {
    background: hsl(var(--accent));
    border-color: hsl(var(--border));
    transform: scale(1.03);
}

.hamburger-icon {
    display: inline-block;
    pointer-events: none;
}

/* Sidebar footer removed - user menu now in top toolbar */

.sidebar.slim .sidebar-footer {
    padding: 6px;
    justify-content: center;
}

.user-menu-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.15s ease;
    font-size: 18px;
    position: relative;
}

.sidebar.slim .user-menu-btn {
    width: 36px;
    padding: 0;
    border-radius: 50%;
    gap: 0;
}

.user-menu-btn:hover {
    background: hsl(var(--accent));
    border-color: hsl(var(--border));
    transform: scale(1.03);
}

.user-icon {
    pointer-events: none;
    flex-shrink: 0;
}

.user-name-display {
    font-size: 12px;  /* Smaller */
    font-weight: 500;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
    pointer-events: none;
}

.sidebar.slim .user-name-display {
    display: none;
}

.user-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: 0 3px 10px hsl(var(--shadow-color) / 0.15);
    min-width: 180px;
    z-index: 10000;
}

.user-menu.open {
    display: block;
}

.user-menu-header {
    padding: 10px 12px;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--muted) / 0.3);
}

.user-menu-username {
    font-weight: 600;
    color: hsl(var(--foreground));
    font-size: 12px;
}

.user-menu-item {
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s ease;
    color: hsl(var(--foreground));
    font-size: 12px;
    text-align: left;
}

.user-menu-item:hover {
    background: hsl(var(--accent));
}

.menu-item-icon {
    width: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-item-text {
    flex: 1;
}

.theme-toggle {
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: var(--radius);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 16px;
}

.theme-toggle:hover {
    background: hsl(var(--accent));
    transform: scale(1.03);
}

.logout-btn {
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: var(--radius);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 16px;
}

.logout-btn:hover {
    background: hsl(var(--error) / 0.1);
    border-color: hsl(var(--error));
    transform: scale(1.03);
}

.username-display {
    font-size: 0.85em;
    color: hsl(var(--muted-foreground));
    font-weight: 500;
    padding: 4px 10px;
    background: hsl(var(--muted) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid hsl(var(--border) / 0.5);
}

@media (max-width: 768px) {
    .username-display {
        display: none !important;
    }
}

.new-chat-btn {
    width: 100%;
    padding: 8px 12px;  /* Tighter */
    background: linear-gradient(to right, hsl(var(--primary)), hsl(var(--primary) / 0.9));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.05s ease, box-shadow 0.15s ease;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.3);
}

.new-chat-icon {
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar.slim .new-chat-btn {
    padding: 8px;
    width: 36px;
    height: 36px;
    min-width: 36px;
    margin-left: auto;
    margin-right: auto;
}

.sidebar.slim .new-chat-icon {
    margin: 0;
}

.sidebar.slim .new-chat-text {
    display: none;
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;  /* Tighter */
}

.sidebar.slim .sessions-list {
    padding: 4px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sidebar.slim .session-group-header {
    display: none;
}

.sidebar.slim .bulk-action-bar {
    display: none !important;
}

.sidebar.slim .checkbox-placeholder,
.sidebar.slim .indicator-placeholder,
.sidebar.slim .session-checkbox,
.sidebar.slim .session-indicator {
    display: none;
}

.session-item {
    padding: 8px 10px;  /* Much tighter */
    margin-bottom: 2px;
    border-radius: 0.3rem;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

.sidebar.slim .session-item {
    padding: 6px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    margin-left: auto;
    margin-right: auto;
}

.session-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;  /* Tighter */
    min-width: 0;
}

.sidebar.slim .session-content {
    display: none;
}

.session-icon {
    display: none;
    flex-shrink: 0;
    font-size: 20px;
    text-align: center;
}

.sidebar.slim .session-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    font-size: 9px;
    line-height: 1.1;
}

.session-icon-date {
    font-weight: 600;
}

.session-icon-time {
    font-size: 8px;
    opacity: 0.7;
}

.session-indicator {
    color: hsl(var(--primary));
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
    width: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-placeholder {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.indicator-placeholder {
    width: 16px;
    flex-shrink: 0;
}

.session-item:hover {
    background: hsl(var(--accent) / 0.5);
}

.session-item.active {
    background: hsl(var(--primary) / 0.12);
    border: 1px solid hsl(var(--primary) / 0.3);
    box-shadow: 0 1px 4px hsl(var(--primary) / 0.12);
}

.session-item.selected {
    background: hsl(var(--primary) / 0.18);
    border: 1px solid hsl(var(--primary) / 0.5);
    box-shadow: 0 1px 4px hsl(var(--primary) / 0.18);
}

.session-title {
    font-weight: 500;
    font-size: 12px;  /* Smaller */
    line-height: 1.3;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-meta {
    font-size: 11px;  /* Smaller */
    color: hsl(var(--muted-foreground));
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;  /* Much tighter */
    transition: max-width 0.2s ease;
}

.sidebar:not(.slim) ~ .main-area {
    max-width: calc(100% - 260px);
}

.sidebar.slim ~ .main-area {
    max-width: calc(100% - 52px);
}

@media (max-width: 768px) {
    .sidebar:not(.slim) ~ .main-area {
        max-width: 100%;
        padding: 8px;
    }

    .sidebar.slim ~ .main-area {
        max-width: calc(100% - 52px);
        padding: 8px;
    }
}

.header {
    text-align: center;
    margin-bottom: 16px;  /* Tighter */
    background: hsl(var(--card));
    padding: 16px;  /* Much tighter */
    border-radius: var(--radius);
    box-shadow: 0 2px 6px hsl(var(--shadow-color) / 0.06);
    border: 1px solid hsl(var(--border) / 0.5);
}

@media (max-width: 768px) {
    .header {
        margin-bottom: 12px;
        padding: 14px 12px;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .header p {
        font-size: 0.9rem;
    }
}

.header h1 {
    margin: 0 0 6px 0;  /* Tighter */
    font-size: 1.5rem;  /* Smaller */
    font-weight: 600;
    background: linear-gradient(to right, hsl(var(--primary)), hsl(var(--primary) / 0.8));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    margin: 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.95rem;  /* Smaller */
}

.chat-container {
    background: hsl(var(--card) / 0.8);
    backdrop-filter: blur(8px);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px hsl(var(--shadow-color) / 0.08);
    border: 1px solid hsl(var(--border) / 0.5);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

@media (max-width: 768px) {
    .chat-container {
        flex: 1;
        min-height: 360px;
    }
}

.messages {
    flex: 1;
    padding: 12px;  /* Tighter */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--muted-foreground) / 0.3) transparent;
}

.messages::-webkit-scrollbar {
    width: 8px;  /* Thinner */
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, hsl(var(--muted-foreground) / 0.4), hsl(var(--muted-foreground) / 0.15));
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.message {
    margin-bottom: 14px;  /* Tighter */
    animation: fadeInUp 150ms ease-out;
}

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

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

.message.assistant {
    text-align: left;
}

.message-content {
    display: inline-block;
    padding: 10px 14px;  /* Tighter */
    border-radius: 0.6rem;
    max-width: 75%;
    word-wrap: break-word;
    position: relative;
}

/* Message timestamps */
.message-timestamp {
    display: block;
    font-size: 0.7rem;
    color: var(--text-color-muted, #839496);
    margin-top: 2px;
    opacity: 0.6;
    transition: opacity 0.2s ease;
    cursor: default;
    user-select: none;
}

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

.message.assistant .message-timestamp {
    text-align: left;
    margin-left: 4px;
}

.message-timestamp:hover {
    opacity: 1;
}

/* Dark mode timestamp adjustments */
[data-theme="dark"] .message-timestamp {
    color: var(--text-color-muted, #93a1a1);
}

@media (max-width: 768px) {
    .message-content {
        max-width: 90%;
        padding: 10px 12px;
    }
}

.message.user .message-content {
    background: linear-gradient(to right, hsl(var(--primary)), hsl(var(--primary) / 0.9));
    color: hsl(var(--primary-foreground));
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.25);
}

.message.user .message-content::after {
    content: "";
    position: absolute;
    right: -5px;
    top: 14px;
    width: 0; height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 5px solid hsl(var(--primary) / 0.9);
}

.message.assistant .message-content {
    background: hsl(var(--card) / 0.9);
    color: hsl(var(--foreground));
    border: 1px solid hsl(var(--border) / 0.5);
    box-shadow: 0 2px 8px hsl(var(--shadow-color) / 0.06);
}

.message.assistant .message-content::after {
    content: "";
    position: absolute;
    left: -5px;
    top: 14px;
    width: 0; height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 5px solid hsl(var(--card) / 0.9);
}

/* Enhanced markdown styling */
.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin: 12px 0 6px 0;  /* Tighter */
    font-weight: 600;
    color: hsl(var(--foreground));
    line-height: 1.25;
}

.message-content h1 { font-size: 1.25rem; }
.message-content h2 { font-size: 1.1rem; }
.message-content h3 { font-size: 1rem; }
.message-content h4 { font-size: 0.95rem; }

.message-content p {
    margin: 6px 0;  /* Tighter */
    line-height: 1.5;
    color: hsl(var(--foreground) / 0.9);
}

.message-content ul, .message-content ol {
    margin: 6px 0;  /* Tighter */
    padding-left: 18px;
}

.message-content li {
    margin: 3px 0;  /* Tighter */
}

.message-content blockquote {
    border-left: 2px solid hsl(var(--border));  /* Thinner */
    margin: 8px 0;
    padding-left: 12px;
    font-style: italic;
    background: hsl(var(--muted) / 0.3);
    padding: 8px 12px;
    border-radius: 0.3rem;
}

.message-content code {
    background: hsl(var(--muted) / 0.5);
    border: 1px solid hsl(var(--border) / 0.5);
    color: hsl(var(--accent-foreground));
    padding: 2px 5px;
    border-radius: 0.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: linear-gradient(180deg, hsl(var(--card) / 0.9), hsl(var(--card) / 0.7));
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: var(--radius);
    padding: 10px;  /* Tighter */
    overflow-x: auto;
    margin: 10px 0;  /* Tighter */
    position: relative;
    box-shadow: inset 0 1px 0 hsl(var(--foreground) / 0.03);
}

@media (max-width: 768px) {
    .message-content pre {
        padding: 8px;
        font-size: 12px;
    }
}

.message-content pre .copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    padding: 4px 8px;
    border-radius: 0.25rem;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, transform 0.05s ease;
    font-weight: 500;
}

.message-content pre:hover .copy-button {
    opacity: 1;
}

.message-content pre .copy-button:hover {
    background: hsl(var(--primary) / 0.9);
    transform: translateY(-1px);
}

.message-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: hsl(var(--foreground));
}

.message-content table {
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: 0.3rem;
    overflow: hidden;
    margin: 10px 0;  /* Tighter */
    width: 100%;
}

@media (max-width: 768px) {
    .message-content table {
        font-size: 12px;
    }

    .message-content th, .message-content td {
        padding: 6px 8px;
    }
}

.message-content th, .message-content td {
    padding: 6px 10px;  /* Tighter */
    text-align: left;
    border-top: 1px solid hsl(var(--border) / 0.5);
}

.message-content th {
    background: hsl(var(--muted) / 0.6);
    color: hsl(var(--foreground));
    font-weight: 600;
    border-top: none;
}

.message-content strong {
    font-weight: 600;
    color: hsl(var(--foreground));
}

.message-content em {
    font-style: italic;
}

.message-content a {
    color: hsl(var(--primary));
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message-content a:hover {
    text-decoration-thickness: 2px;
}

.message.user .message-content code {
    background: hsl(var(--primary-foreground) / 0.2);
    border-color: hsl(var(--primary-foreground) / 0.3);
}

.message.user .message-content pre {
    background: hsl(var(--primary-foreground) / 0.1);
    border-color: hsl(var(--primary-foreground) / 0.2);
}

/* Typing indicator */
.typing-indicator {
    display: inline-block;
    position: relative;
}

.typing-indicator::after {
    content: '';
    display: inline-block;
    width: 3px;
    height: 1em;
    background-color: currentColor;
    animation: blink 1s infinite;
    margin-left: 2px;
}

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

/* Persistent streaming indicator */
.streaming-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    margin-top: 8px;
    font-size: 11px;
    color: hsl(var(--muted-foreground));
    opacity: 0.7;
}

.streaming-indicator .dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: hsl(var(--primary));
    animation: pulse 1.4s infinite;
}

.streaming-indicator .dot:nth-child(1) {
    animation-delay: 0s;
}

.streaming-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.streaming-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    30% {
        opacity: 1;
        transform: scale(1.4);
    }
}


.input-area {
    padding: 12px;  /* Tighter */
    display: flex;
    gap: 8px;
    border-top: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--card) / 0.5);
    backdrop-filter: blur(8px);
}

.input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

@media (max-width: 768px) {
    .input-area {
        padding: 10px;
        gap: 6px;
    }
}

.message-input {
    width: 100%;
    padding: 8px 12px;  /* Tighter */
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) + 1px);
    outline: none;
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    transition: border-color 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    min-height: 52px;  /* Tighter */
    max-height: 180px;
}

.input-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.input-hint {
    font-size: 0.7rem;  /* Smaller */
    color: hsl(var(--muted-foreground));
    padding: 0 4px;
    line-height: 1.2;
}

.token-counter {
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground));
    padding: 0 4px;
    line-height: 1.2;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .message-input {
        padding: 10px 12px;
        font-size: 14px;
        border-radius: var(--radius);
    }
}

.message-input:focus {
    border-color: hsl(var(--primary) / 0.5);
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
    background: hsl(var(--card) / 0.98);
}

.message-input::placeholder {
    color: hsl(var(--muted-foreground));
}

.send-button {
    padding: 8px 16px;  /* Tighter */
    background: linear-gradient(to right, hsl(var(--primary)), hsl(var(--primary) / 0.9));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: calc(var(--radius) + 1px);
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.05s ease, box-shadow 0.15s ease;
    font-size: 13px;
}

@media (max-width: 768px) {
    .send-button {
        padding: 10px 18px;
        font-size: 14px;
        border-radius: var(--radius);
        min-width: 70px;
    }
}

.send-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.3);
}

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

.send-button:disabled {
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Load More button - appears at top of message list */
.load-more-btn {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: all 0.2s ease;
    text-align: center;
}

.load-more-btn:hover:not(:disabled) {
    background: hsl(var(--accent));
    transform: translateY(-1px);
    box-shadow: 0 2px 8px hsl(var(--shadow-color) / 0.1);
}

.load-more-btn:active:not(:disabled) {
    transform: translateY(0);
}

.load-more-btn:disabled {
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    cursor: wait;
    opacity: 0.7;
}

.controls {
    display: flex;
    flex-direction: column;
    background: hsl(var(--card) / 0.8);
    backdrop-filter: blur(8px);
    padding: 14px;  /* Tighter */
    border-radius: var(--radius);
    box-shadow: 0 2px 6px hsl(var(--shadow-color) / 0.06);
    border: 1px solid hsl(var(--border) / 0.5);
    margin-bottom: 12px;  /* Tighter */
}

@media (max-width: 768px) {
    .controls {
        padding: 12px;
        margin-bottom: 8px;
    }
}

.control-group {
    margin-bottom: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

.agent-info-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: hsl(var(--muted));
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.agent-info-label {
    font-weight: 500;
    color: hsl(var(--muted-foreground));
}

.agent-info-value {
    font-weight: 600;
    color: hsl(var(--foreground));
}

.agent-info-hint {
    margin-left: auto;
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
    font-style: italic;
}

@media (max-width: 768px) {
    .agent-info-hint {
        display: none;
    }
}

.model-display-section {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;  /* Tighter */
    background: linear-gradient(to right, hsl(var(--primary) / 0.08), hsl(var(--primary) / 0.05));
    border: 1px solid hsl(var(--primary) / 0.2);
    border-radius: var(--radius);
}

.model-label {
    font-size: 12px;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
}

.model-name {
    font-size: 13px;
    font-weight: 600;
    color: hsl(var(--primary));
}

@media (max-width: 768px) {
    .control-group {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-bottom: 16px;
    }
}

label {
    display: inline-flex;
    align-items: center;
    font-weight: 500;
    color: hsl(var(--foreground));
    white-space: nowrap;
    font-size: 12px;  /* Smaller */
}

@media (max-width: 768px) {
    label {
        white-space: normal;
        margin-bottom: 6px;
    }

    .desktop-label {
        display: none;
    }

    .mobile-label {
        display: inline-flex;
    }
}

@media (min-width: 769px) {
    .mobile-label {
        display: none;
    }
}

select {
    height: 30px;  /* Smaller */
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: 0.3rem;
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    transition: border-color 0.12s ease;
}

@media (max-width: 768px) {
    select {
        width: 100%;
        height: 38px;
        font-size: 13px;
    }
}

select:focus {
    outline: none;
    border-color: hsl(var(--primary) / 0.5);
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}

input[type="checkbox"] {
    margin-right: 6px;
    width: 14px;
    height: 14px;
    accent-color: hsl(var(--primary));
}

.status {
    padding: 8px 12px;  /* Tighter */
    border-radius: 0.3rem;
    margin-bottom: 8px;
    font-size: 0.85em;
    font-weight: 500;
    border: 1px solid;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.status.connecting {
    background-color: hsl(var(--warning) / 0.1);
    border-color: hsl(var(--warning) / 0.3);
    color: hsl(var(--warning));
}

.status.connecting::before {
    background-color: hsl(var(--warning));
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status.connected {
    background-color: hsl(var(--success) / 0.1);
    border-color: hsl(var(--success) / 0.3);
    color: hsl(var(--success));
}

.status.connected::before {
    background-color: hsl(var(--success));
}

.status.error {
    background-color: hsl(var(--error) / 0.1);
    border-color: hsl(var(--error) / 0.3);
    color: hsl(var(--error));
}

.status.error::before {
    background-color: hsl(var(--error));
}

.tool-info {
    background: linear-gradient(135deg, hsl(var(--primary) / 0.05), hsl(var(--accent) / 0.1));
    border: 1px solid hsl(var(--primary) / 0.2);
    padding: 10px;  /* Tighter */
    border-radius: 0.3rem;
    margin: 8px 0;  /* Tighter */
    font-size: 0.85em;
}

.tool-info strong {
    color: hsl(var(--primary));
}

.tool-info [style*="cursor: pointer"]:hover {
    color: hsl(var(--primary) / 0.8);
    transition: color 0.15s ease;
}

/* Tool call messages */
.tool-message {
    margin: 8px 0;
}

.tool-call {
    background: hsl(var(--muted) / 0.3);
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: var(--radius);
    overflow: hidden;
}

.tool-call[open] {
    background: hsl(var(--muted) / 0.4);
}

.tool-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    list-style: none;
    transition: background 0.12s ease;
}

.tool-summary::-webkit-details-marker {
    display: none;
}

.tool-summary:hover {
    background: hsl(var(--accent) / 0.5);
}

.tool-icon {
    font-size: 16px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.tool-name {
    font-weight: 600;
    color: hsl(var(--foreground));
    font-size: 13px;
}

.tool-param-preview {
    flex: 1;
    color: hsl(var(--muted-foreground));
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-expand-icon {
    margin-left: auto;
    font-size: 10px;
    color: hsl(var(--muted-foreground));
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.tool-details {
    padding: 12px;
    border-top: 1px solid hsl(var(--border) / 0.5);
    font-size: 12px;
    background: hsl(var(--card) / 0.6);
}

.tool-params-section {
    margin-bottom: 12px;
}

.tool-params-section strong {
    display: block;
    margin-bottom: 6px;
    color: hsl(var(--foreground));
    font-size: 12px;
}

.tool-param {
    padding: 4px 8px;
    margin: 3px 0;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border) / 0.3);
    border-radius: calc(var(--radius) - 2px);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
}

.param-key {
    color: hsl(var(--primary));
    font-weight: 600;
    margin-right: 6px;
}

.param-value {
    color: hsl(var(--foreground) / 0.9);
    word-break: break-word;
}

.tool-result-section {
    padding-top: 8px;
}

.tool-result-section strong {
    display: block;
    margin-bottom: 6px;
    color: hsl(var(--foreground));
    font-size: 12px;
}

.tool-result-content {
    font-size: 11px;
    color: hsl(var(--foreground) / 0.85);
    font-style: italic;
}

.tool-result-content pre {
    margin: 0;
    padding: 10px;
    background: hsl(var(--background));
    border-top: 1px solid hsl(var(--border) / 0.3);
    border-right: 1px solid hsl(var(--border) / 0.3);
    border-bottom: 1px solid hsl(var(--border) / 0.3);
    border-left: 3px solid hsl(var(--primary) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    box-shadow: inset 0 1px 3px hsl(var(--shadow-color) / 0.15);
    overflow-x: auto;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Ubuntu Mono', ui-monospace, 'SF Mono', 'Cascadia Code', 'Roboto Mono', Menlo, Monaco, Consolas, monospace;
    font-size: 13px;  /* Increased from 11px for better readability */
    max-height: 300px;
    color: hsl(var(--foreground) / 0.9);
}

.message-content details {
    border: 1px dashed hsl(var(--border) / 0.5);
    border-radius: 0.4rem;
    padding: 10px 12px;  /* Tighter */
    background: hsl(var(--muted) / 0.3);
    margin: 10px 0;  /* Tighter */
}

.message-content details summary {
    cursor: pointer;
    font-weight: 600;
    color: hsl(var(--foreground));
    list-style: none;
    padding: 4px 0;
}

.message-content details summary::-webkit-details-marker {
    display: none;
}

.message-content details[open] summary {
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    margin-bottom: 8px;
    padding-bottom: 8px;
}

/* Temporal group headers */
.session-group-header {
    padding: 8px 12px 4px;  /* Tighter */
    font-size: 10px;  /* Smaller */
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 10px;
}

.session-group-header:first-child {
    margin-top: 0;
}

/* Selection mode */
.session-item input[type="checkbox"] {
    margin-right: 10px;
    width: 16px;
    height: 16px;
    accent-color: hsl(var(--primary));
    cursor: pointer;
}

.session-item.selected {
    background: hsl(var(--primary) / 0.15);
    border: 1px solid hsl(var(--primary) / 0.4);
}

.session-item.selection-mode {
    display: flex;
    flex-direction: row;
    align-items: center;
}

.session-item.selection-mode > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Bulk action bar */
.bulk-action-bar {
    display: flex;  /* Always visible for consistent UX */
    flex-direction: column;
    padding: 8px 12px 6px;  /* Tighter bottom */
    background: linear-gradient(to bottom, hsl(var(--primary) / 0.08), hsl(var(--primary) / 0.12));
    border-bottom: 1px solid hsl(var(--primary) / 0.25);
    box-shadow: 0 1px 4px hsl(var(--shadow-color) / 0.04);
    gap: 4px;
}

.bulk-action-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.bulk-action-bar .selected-count {
    font-size: 11px;  /* Smaller */
    font-weight: 600;
    color: hsl(var(--foreground));
    flex: 1;
}

.bulk-action-mode {
    font-size: 10px;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    opacity: 0.8;
}

.bulk-action-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

.bulk-action-buttons button {
    padding: 4px;
    width: 28px;  /* Smaller */
    height: 28px;
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.bulk-action-buttons button:hover:not(:disabled) {
    background: hsl(var(--accent));
    transform: scale(1.03);
    box-shadow: 0 1px 4px hsl(var(--shadow-color) / 0.08);
}

.bulk-action-buttons button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.bulk-action-buttons #deleteSelectedBtn {
    background: hsl(var(--error) / 0.1);
    border-color: hsl(var(--error) / 0.4);
}

.bulk-action-buttons #deleteSelectedBtn:hover:not(:disabled) {
    background: hsl(var(--error) / 0.2);
    border-color: hsl(var(--error));
    box-shadow: 0 1px 4px hsl(var(--error) / 0.2);
}

/* Cancel button */
#cancelButton {
    padding: 8px 16px;  /* Tighter */
    background: linear-gradient(to right, hsl(var(--error)), hsl(var(--error) / 0.8));
    color: white;
    border: none;
    border-radius: calc(var(--radius) + 1px);
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.05s ease, box-shadow 0.15s ease;
    font-size: 13px;
    display: none;
}

#cancelButton:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px hsl(var(--error) / 0.3);
}

#cancelButton:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    #cancelButton {
        padding: 10px 18px;
        font-size: 14px;
        border-radius: var(--radius);
        min-width: 70px;
    }
}

/* ============= Code Playground ============= */
.code-playground {
    margin: 0.8rem 0;
    background: hsl(var(--card));
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border) / 0.5);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.playground-toolbar {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    padding: 0.6rem;  /* Tighter */
    background: hsl(var(--muted) / 0.5);
    border-bottom: 1px solid hsl(var(--border) / 0.5);
}

.playground-status {
    margin-left: auto;
    font-size: 0.8rem;
    color: hsl(var(--muted-foreground));
    font-weight: 500;
}

.playground-run-btn,
.playground-clear-btn {
    padding: 0.4rem 0.8rem;  /* Tighter */
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.playground-run-btn {
    background: linear-gradient(to right, hsl(var(--primary)), hsl(var(--primary) / 0.9));
    color: hsl(var(--primary-foreground));
    border-color: transparent;
}

.playground-run-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px hsl(var(--primary) / 0.25);
}

.playground-clear-btn:hover {
    background: hsl(var(--accent));
}

.playground-editor {
    width: 100%;
    min-height: 130px;  /* Tighter */
    max-height: 350px;
    padding: 0.8rem;
    border: none;
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}

.playground-editor:focus {
    background: hsl(var(--card) / 0.98);
}

.playground-output {
    min-height: 70px;  /* Tighter */
    max-height: 260px;
    overflow-y: auto;
    padding: 0.8rem;
    background: hsl(var(--muted) / 0.3);
    border-top: 1px solid hsl(var(--border) / 0.5);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
}

.output-line {
    padding: 0.2rem 0;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.output-log {
    color: hsl(var(--foreground));
}

.output-warn {
    color: hsl(var(--warning));
}

.output-error {
    color: hsl(var(--error));
    font-weight: 500;
}

.output-result {
    color: hsl(var(--primary));
    font-weight: 500;
}

.output-placeholder {
    color: hsl(var(--muted-foreground));
    font-style: italic;
}

@media (max-width: 768px) {
    .playground-editor {
        font-size: 0.75rem;
        min-height: 110px;
    }

    .playground-output {
        font-size: 0.75rem;
    }

    .playground-toolbar {
        flex-wrap: wrap;
    }
}

/* ============= Diff Container ============= */
.diff-container {
    margin: 0.8rem 0;
    background: hsl(var(--card));
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border) / 0.5);
    overflow: hidden;
}

.diff-container .d2h-wrapper {
    background: transparent;
}

.diff-container .d2h-file-header {
    background: hsl(var(--muted) / 0.5);
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    padding: 0.4rem 0.8rem;
}

.diff-container .d2h-file-name {
    color: hsl(var(--foreground));
    font-weight: 600;
}

.diff-container .d2h-code-side-line {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8em;
}

/* Theme adjustments for diff2html */
.diff-theme-dark .d2h-file-wrapper {
    border-color: hsl(var(--border) / 0.5);
}

.diff-theme-dark .d2h-file-header {
    background: hsl(var(--muted) / 0.3);
}

.diff-theme-dark .d2h-code-linenumber,
.diff-theme-dark .d2h-code-side-linenumber {
    background: hsl(193, 99%, 13%);
    border-color: hsl(var(--border) / 0.5);
    color: hsl(var(--muted-foreground));
}

/* Additions - solarized green */
.diff-theme-dark .d2h-ins,
.diff-theme-dark .d2h-ins.d2h-change {
    background: hsl(68, 100%, 30%, 0.35);
    border-color: hsl(68, 100%, 30%, 0.5);
}

.diff-theme-dark .d2h-code-line.d2h-ins {
    background: hsl(68, 100%, 30%, 0.2);
}

.diff-theme-dark .d2h-ins ins {
    background: hsl(68, 100%, 30%, 0.5);
    color: hsl(68, 80%, 85%);
}

/* Deletions - solarized red */
.diff-theme-dark .d2h-del,
.diff-theme-dark .d2h-del.d2h-change {
    background: hsl(1, 71%, 52%, 0.35);
    border-color: hsl(1, 71%, 52%, 0.5);
}

.diff-theme-dark .d2h-code-line.d2h-del {
    background: hsl(1, 71%, 52%, 0.2);
}

.diff-theme-dark .d2h-del del {
    background: hsl(1, 71%, 52%, 0.5);
    color: hsl(1, 80%, 85%);
}

.diff-theme-dark .d2h-code-line {
    color: hsl(var(--foreground));
    background: hsl(var(--card));
}

.diff-theme-dark .d2h-info {
    background: hsl(var(--muted) / 0.3);
    color: hsl(var(--muted-foreground));
}

.diff-container .error {
    color: hsl(var(--error));
    padding: 0.8rem;
    text-align: center;
    font-weight: 500;
}

@media (max-width: 768px) {
    .diff-container {
        font-size: 0.75em;
    }

    .diff-container .d2h-file-side-diff {
        display: none;
    }
}

/* ============= Mermaid Diagram Container ============= */
.mermaid-container {
    margin: 0.8rem 0;
    padding: 0.8rem;
    background: hsl(var(--muted) / 0.3);
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: auto;
}

.mermaid-container svg {
    max-width: 100%;
    height: auto;
}

.mermaid-container .error {
    color: hsl(var(--error));
    padding: 0.8rem;
    text-align: center;
    font-weight: 500;
}

@media (max-width: 768px) {
    .mermaid-container {
        padding: 0.4rem;
    }
}

/* ============= Markmap Mind Map Container ============= */
.markmap-container {
    margin: 0.8rem 0;
    padding: 0.8rem;
    background: hsl(var(--muted) / 0.3);
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.markmap-container svg {
    width: 100%;
    height: 450px;  /* Slightly taller */
    max-width: 100%;
}

.markmap-container .error {
    color: hsl(var(--error));
    padding: 0.8rem;
    text-align: center;
    font-weight: 500;
}

@media (max-width: 768px) {
    .markmap-container {
        padding: 0.4rem;
    }

    .markmap-container svg {
        height: 360px;
    }
}

/* ============= Timeline Container ============= */
.timeline-container {
    margin: 0.8rem 0;
    padding: 0;
    background: hsl(var(--card));
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border) / 0.5);
    min-height: 260px;  /* Slightly shorter */
    overflow: hidden;
}

/* Dark theme overrides for vis-timeline */
.timeline-dark .vis-timeline {
    background: hsl(var(--card));
    border-color: hsl(var(--border) / 0.5);
}

.timeline-dark .vis-item {
    background-color: hsl(var(--primary) / 0.8);
    border-color: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.timeline-dark .vis-item.vis-selected {
    background-color: hsl(var(--primary));
    border-color: hsl(var(--primary));
}

.timeline-dark .vis-item.vis-box,
.timeline-dark .vis-item.vis-point {
    background-color: hsl(var(--primary) / 0.9);
    border-color: hsl(var(--primary));
}

.timeline-dark .vis-item.vis-range {
    background-color: hsl(var(--primary) / 0.3);
    border-color: hsl(var(--primary) / 0.6);
}

.timeline-dark .vis-time-axis .vis-text {
    color: hsl(var(--foreground));
}

.timeline-dark .vis-time-axis .vis-grid.vis-minor {
    border-color: hsl(var(--border) / 0.5);
}

.timeline-dark .vis-time-axis .vis-grid.vis-major {
    border-color: hsl(var(--border) / 0.5);
}

.timeline-dark .vis-panel {
    background: hsl(var(--card));
}

.timeline-dark .vis-labelset .vis-label {
    color: hsl(var(--foreground));
    border-color: hsl(var(--border) / 0.5);
}

.timeline-dark .vis-current-time {
    background-color: hsl(var(--error));
}

.timeline-container .error {
    color: hsl(var(--error));
    padding: 0.8rem;
    text-align: center;
    font-weight: 500;
}

@media (max-width: 768px) {
    .timeline-container {
        min-height: 220px;
    }
}

/* ============= KaTeX Math Rendering ============= */
.katex-display {
    margin: 0.8rem 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.katex {
    font-size: 1.05em;
}

@media (max-width: 768px) {
    .katex-display {
        font-size: 0.85em;
    }
}

/* ============= Vega-Lite Chart Container ============= */
.vega-viz-container {
    margin: 0.8rem 0;
    padding: 0.8rem;
    background: hsl(var(--muted) / 0.3);
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.vega-viz-container canvas,
.vega-viz-container svg {
    max-width: 100%;
    height: auto;
}

.vega-viz-container .vega-embed {
    width: 100%;
}

.vega-viz-container .vega-embed details {
    background: transparent;
    border: none;
}

.vega-viz-container .vega-actions {
    background: hsl(var(--card) / 0.9);
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    padding: 3px;
}

.vega-viz-container .vega-actions a {
    color: hsl(var(--primary));
    padding: 3px 6px;
    border-radius: calc(var(--radius) - 4px);
}

.vega-viz-container .vega-actions a:hover {
    background: hsl(var(--accent));
    text-decoration: none;
}

.vega-viz-container .error {
    color: hsl(var(--error));
    padding: 0.8rem;
    text-align: center;
    font-weight: 500;
}

@media (max-width: 768px) {
    .vega-viz-container {
        padding: 0.4rem;
        overflow-x: auto;
    }

    .vega-viz-container canvas,
    .vega-viz-container svg {
        max-width: 100%;
    }
}

/* ============= System Prompt Editor Modal ============= */
.system-prompt-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: hsl(var(--background) / 0.95);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.system-prompt-modal-content {
    width: 100%;
    max-width: 1300px;
    height: 88vh;
    background: hsl(var(--card));
    border-radius: var(--radius);
    box-shadow: 0 16px 48px hsl(var(--shadow-color) / 0.25);
    border: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    flex-direction: column;
}

.system-prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;  /* Tighter */
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--muted) / 0.3);
}

.system-prompt-header h2 {
    margin: 0;
    font-size: 1.25rem;  /* Smaller */
    font-weight: 600;
    color: hsl(var(--foreground));
}

.close-btn {
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 16px;
    color: hsl(var(--foreground));
}

.close-btn:hover {
    background: hsl(var(--error) / 0.1);
    border-color: hsl(var(--error));
}

.system-prompt-body {
    flex: 1;
    display: flex;
    gap: 1px;
    overflow: hidden;
    background: hsl(var(--border) / 0.5);
}

.editor-container {
    flex: 2;
    display: flex;
    flex-direction: column;
    background: hsl(var(--card));
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;  /* Tighter */
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--muted) / 0.2);
}

.toolbar-btn {
    padding: 6px 12px;  /* Tighter */
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    cursor: pointer;
    font-weight: 500;
    font-size: 12px;
    transition: all 0.15s ease;
}

.toolbar-btn:hover {
    background: hsl(var(--accent));
    transform: translateY(-1px);
    box-shadow: 0 2px 6px hsl(var(--shadow-color) / 0.08);
}

.toolbar-btn.primary {
    background: linear-gradient(to right, hsl(var(--primary)), hsl(var(--primary) / 0.9));
    color: hsl(var(--primary-foreground));
    border-color: transparent;
}

.toolbar-btn.primary:hover {
    box-shadow: 0 3px 10px hsl(var(--primary) / 0.25);
}

.editor-status {
    margin-left: auto;
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: calc(var(--radius) - 2px);
}

.editor-status.success {
    color: hsl(var(--success));
    background: hsl(var(--success) / 0.1);
}

.editor-status.error {
    color: hsl(var(--error));
    background: hsl(var(--error) / 0.1);
}

.editor-status.info {
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.1);
}

.system-prompt-textarea {
    flex: 1;
    padding: 14px;  /* Tighter */
    border: none;
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: none;
    outline: none;
}

.system-prompt-textarea:focus {
    background: hsl(var(--card) / 0.98);
}

.history-sidebar {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: hsl(var(--card));
    border-left: 1px solid hsl(var(--border) / 0.5);
    max-width: 360px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;  /* Tighter */
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--muted) / 0.2);
}

.history-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.icon-btn {
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 14px;
}

.icon-btn:hover {
    background: hsl(var(--accent));
    transform: scale(1.03);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 10px;  /* Tighter */
    margin-bottom: 6px;
    background: hsl(var(--muted) / 0.3);
    border: 1px solid hsl(var(--border) / 0.5);
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all 0.15s ease;
}

.history-item:hover {
    background: hsl(var(--accent));
    transform: translateX(3px);
    box-shadow: 0 2px 6px hsl(var(--shadow-color) / 0.08);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 11px;
}

.commit-hash {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 600;
    color: hsl(var(--primary));
}

.commit-date {
    color: hsl(var(--muted-foreground));
}

.commit-author {
    font-size: 11px;
    color: hsl(var(--muted-foreground));
    margin-bottom: 3px;
}

.commit-message {
    font-size: 12px;
    color: hsl(var(--foreground));
    font-weight: 500;
}

.diff-viewer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 550px;  /* Slightly narrower */
    background: hsl(var(--card));
    border-left: 2px solid hsl(var(--primary));
    box-shadow: -4px 0 16px hsl(var(--shadow-color) / 0.2);
    display: flex;
    flex-direction: column;
    z-index: 10001;
}

.diff-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;  /* Tighter */
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--muted) / 0.3);
}

.diff-header h3 {
    flex: 1;
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.diff-content {
    flex: 1;
    padding: 14px;  /* Tighter */
    overflow-y: auto;
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.loading, .empty, .error {
    padding: 16px;  /* Tighter */
    text-align: center;
    color: hsl(var(--muted-foreground));
    font-size: 13px;
}

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

@media (max-width: 1200px) {
    .system-prompt-modal-content {
        height: 94vh;
    }

    .system-prompt-body {
        flex-direction: column;
    }

    .history-sidebar {
        max-width: none;
        max-height: 260px;
        border-left: none;
        border-top: 1px solid hsl(var(--border) / 0.5);
    }

    .diff-viewer {
        width: 100%;
    }
}

/* ============================================
   AGENT SELECTOR & SETTINGS
   ============================================ */

/* Agent Selector Container */
.agent-selector-container {
    padding: 12px 16px;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--card));
}

.agent-selector-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.agent-selector-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.agent-selector {
    flex: 1;
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 0.9rem;
    cursor: pointer;
}

.agent-selector option {
    background: hsl(var(--background));
    color: hsl(var(--foreground));
}

/* Agent dropdown separator */
.agent-dropdown-separator {
    font-size: 0.65rem;
    color: hsl(var(--border));
    text-align: center;
    padding: 2px 0;
    background: hsl(var(--muted) / 0.3) !important;
}

/* Agent dropdown action (Create New Agent) */
.agent-dropdown-action {
    font-weight: 600;
    color: hsl(var(--primary)) !important;
    background: hsl(var(--accent) / 0.5) !important;
    padding: 8px 10px;
}

.agent-selector:hover {
    border-color: hsl(var(--primary));
}

.agent-selector:focus {
    outline: none;
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 2px hsl(var(--primary) / 0.2);
}

.icon-btn {
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: hsl(var(--accent));
    border-color: hsl(var(--primary));
}

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

/* New Chat Container */
.new-chat-container {
    padding: 12px 16px;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
}

.new-chat-container .new-chat-btn {
    width: 100%;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: hsl(var(--background));
    border-radius: 8px;
    padding: 0;
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: hsl(var(--card));
}

.modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
    color: hsl(var(--foreground));
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}

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

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid hsl(var(--border) / 0.5);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: hsl(var(--card));
}

/* Form Styles */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    color: hsl(var(--foreground));
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-family: inherit;
    font-size: 0.9rem;
}

.form-group textarea {
    resize: vertical;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 2px hsl(var(--primary) / 0.2);
}

.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

.form-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid hsl(var(--border) / 0.5);
}

.form-section h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    color: hsl(var(--foreground));
}

/* Button Styles */
.primary-btn {
    padding: 8px 16px;
    border-radius: 4px;
    border: none;
    background: #268bd2;
    color: white;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.primary-btn:hover {
    background: #2aa198;
}

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

.secondary-btn {
    padding: 8px 16px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

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

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

.danger-btn {
    padding: 8px 16px;
    border-radius: 4px;
    border: none;
    background: #dc322f;
    color: white;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.danger-btn:hover {
    background: #cb4b16;
}

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

/* Heartbeat Status Display */
.heartbeat-status-display {
    margin-top: 12px;
    padding: 12px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.heartbeat-status-active {
    background: rgba(133, 153, 0, 0.1);
    border: 1px solid #859900;
    color: var(--text-color);
}

.heartbeat-status-inactive {
    background: rgba(88, 110, 117, 0.1);
    border: 1px solid #586e75;
    color: var(--text-color-muted);
}

/* Dark Mode Adjustments */
[data-theme="dark"] .modal {
    background: rgba(0, 0, 0, 0.8);
}

/* Agent selector and form elements inherit dark mode from base styles */
