/* CSS Variables for theming */
:root {
    /* Light mode colors */
    --bg-primary: #f0f2f5;
    --bg-secondary: #fff;
    --bg-tertiary: #f7f7f7;
    --text-primary: #1c1e21;
    --text-secondary: #65676b;
    --border-color: #ddd;
    --input-bg: #fff;
    --button-bg: #1877f2;

    /* Semantic colors */
    --success-color: #008000;
    --error-color: #d32f2f;
    --warning-color: #ff8c00;
}

body.dark-mode {
    /* Dark mode colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --bg-tertiary: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #555;
    --input-bg: #1e1e1e;

    /* Semantic colors for dark mode */
    --success-color: #4ade80;
    --error-color: #ef5350;
    --warning-color: #ffa500;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

html,
body {
    min-height: 100%;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    padding: 0;
    margin: 0;
}

/* Dark mode base styles */
body.dark-mode {
    color: var(--text-primary);
}

/* Removed - no longer using container */

/* Removed - consolidated above */

/* Input and button styles for dark mode */
body.dark-mode input {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

body.dark-mode button:not(.theme-toggle) {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

body.dark-mode button:not(.theme-toggle):not(:disabled):hover {
    background-color: var(--bg-secondary);
    border-color: #777;
}

/* Code blocks and containers */
body.dark-mode .agent-card-display,
body.dark-mode #modal-json-content,
body.dark-mode .session-context-id,
body.dark-mode #chat-messages {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

body.dark-mode #chat-messages {
    border-color: var(--border-color);
}

/* Message styles */
body.dark-mode .message.user {
    background-color: #0066cc;
}

body.dark-mode .message.agent {
    background-color: #3a3a3a;
    color: var(--text-primary);
}

body.dark-mode .message.agent-progress {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
}

/* Containers and sections */
body.dark-mode .collapsible-content,
body.dark-mode .http-headers-content,
body.dark-mode .message-metadata-content,
body.dark-mode .session-details-container {
    border-color: var(--border-color);
}

body.dark-mode .session-details-container,
body.dark-mode .session-details-header {
    background-color: var(--bg-secondary);
}

body.dark-mode .session-details-header:hover {
    background-color: #3a3a3a;
}

body.dark-mode .modal-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

body.dark-mode .attachment-chip,
body.dark-mode .modality-tag {
    background-color: #3a3a3a;
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Text colors */
body.dark-mode .http-headers-header,
body.dark-mode .message-metadata-header {
    color: #f0f0f0;
}

body.dark-mode .placeholder-text {
    color: #888;
}

body.dark-mode .session-info-row strong {
    color: var(--text-secondary);
}

body.dark-mode .chat-info {
    color: var(--text-primary);
}

/* Three Column Layout */
.three-column-layout {
    display: grid;
    grid-template-columns: 320px 1fr 380px;
    gap: 0;
    height: calc(100vh - 80px);
    background-color: var(--bg-primary);
    animation: fadeInContainer 0.5s ease-out;
}

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

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

@media (max-width: 1400px) {
    .three-column-layout {
        grid-template-columns: 280px 1fr 320px;
    }
}

@media (max-width: 1024px) {
    .three-column-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    /* Ignore desktop sidebar collapse on small screens */
    .three-column-layout.collapsed-left,
    .three-column-layout.collapsed-right {
        grid-template-columns: 1fr !important;
    }

    .left-panel,
    .right-panel {
        display: none;
    }
}

/* Desktop: collapse side panels to a narrow rail; widen & center chat when both hidden */
@media (min-width: 1025px) {
    .three-column-layout.collapsed-left {
        grid-template-columns: 44px minmax(0, 1fr) minmax(260px, 380px);
    }

    .three-column-layout.collapsed-right {
        grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) 44px;
    }

    .three-column-layout.collapsed-left.collapsed-right {
        grid-template-columns: 44px minmax(0, 1fr) 44px;
    }

    .three-column-layout.collapsed-left.collapsed-right .center-panel {
        justify-self: center;
        width: min(1100px, 100%);
        max-width: 1100px;
        box-sizing: border-box;
    }

    .three-column-layout.collapsed-left .left-panel-body,
    .three-column-layout.collapsed-right .right-panel-body {
        display: none !important;
    }

    .three-column-layout.collapsed-left .left-panel {
        padding: 12px 6px;
        align-items: center;
        overflow: visible;
    }

    .three-column-layout.collapsed-right .right-panel {
        padding: 12px 6px;
        align-items: center;
        overflow: visible;
    }

    .three-column-layout.collapsed-left .sidebar-toggle-btn--left {
        align-self: center;
        margin-bottom: 0;
    }

    .three-column-layout.collapsed-right .sidebar-toggle-btn--right {
        align-self: center;
        margin-bottom: 0;
    }
}

h1 {
    color: #1c1e21;
    font-size: 2em;
    margin: 0;
    font-weight: 700;
    letter-spacing: -0.5px;
}

h2 {
    color: var(--text-primary);
    font-size: 1.3em;
    margin: 0;
    font-weight: 600;
}

body.dark-mode h1,
body.dark-mode h2 {
    color: var(--text-primary);
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    background: var(--bg-secondary);
    border-bottom: 3px solid #e4e6eb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 80px;
    box-sizing: border-box;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-container h1 {
    margin: 0;
    background: linear-gradient(135deg, #1877f2 0%, #0d5dbf 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

body.dark-mode .header-container {
    border-bottom-color: var(--border-color);
}

body.dark-mode .header-container h1 {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Left Panel - Configuration */
.left-panel {
    background: var(--bg-secondary);
    border-right: 2px solid var(--border-color);
    /* Bottom matches .center-panel padding so Connect lines up with the chat input bar */
    padding: 8px 10px 25px 10px;
    height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-width: 0;
}

.left-panel-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.left-panel-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.left-panel-body>.connect-btn-container {
    flex-shrink: 0;
    margin-top: 8px;
}

/* Compact cards in the left scroll area — more fits vertically; Connect stays below */
.left-panel .sidebar-toggle-btn,
.right-panel .sidebar-toggle-btn {
    margin-bottom: 6px;
}

.left-panel-scroll .panel-section {
    margin-bottom: 8px;
    padding: 10px 12px;
}

.left-panel-scroll .panel-section .panel-title {
    margin: 0 0 6px 0;
    padding-bottom: 5px;
    font-size: 0.72em;
    letter-spacing: 0.4px;
}

.left-panel-scroll .url-input-container {
    gap: 8px;
}

.left-panel-scroll .auth-inputs {
    margin-top: 8px;
}

.left-panel-scroll .auth-input-group {
    margin-bottom: 10px;
}

.left-panel-scroll .session-details-header {
    padding: 7px 10px;
    font-size: 0.85em;
}

.left-panel-scroll .session-details-content.expanded {
    max-height: 220px;
}

.left-panel-scroll #add-header-btn,
.left-panel-scroll #add-metadata-btn {
    padding: 7px 12px;
    font-size: 0.85em;
}

.left-panel #connect-btn {
    padding: 10px 16px;
    font-size: 0.92em;
}

.left-panel-scroll #agent-card-url {
    padding: 8px 11px;
    font-size: 0.88em;
}

.left-panel-scroll .auth-type-select {
    padding: 8px 10px;
    font-size: 0.88em;
}

/* Center Panel - Chat (outer panel does not scroll; #chat-messages scrolls) */
.center-panel {
    background: var(--bg-primary);
    padding: 25px 30px;
    overflow: hidden;
    height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    min-width: 0;
    box-sizing: border-box;
}

/* Right Panel - Agent Card */
.right-panel {
    background: var(--bg-secondary);
    border-left: 2px solid var(--border-color);
    /* Top padding matches .left-panel so collapse toggles share one baseline */
    padding: 8px 20px 20px 20px;
    height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-width: 0;
}

.right-panel-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-toggle-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    margin-bottom: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.sidebar-toggle-btn:hover {
    background: var(--bg-tertiary);
    border-color: #1877f2;
}

.sidebar-toggle-btn--left {
    align-self: flex-end;
}

.sidebar-toggle-btn--right {
    align-self: flex-start;
}

body.dark-mode .sidebar-toggle-btn {
    background: var(--bg-tertiary);
}

/* Panel Sections */
.panel-section {
    margin-bottom: 25px;
    padding: 20px;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 2px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.panel-title {
    font-size: 1.1em;
    font-weight: 700;
    margin: 0 0 15px 0;
    color: var(--text-primary);
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.9em;
}

body.dark-mode .left-panel,
body.dark-mode .right-panel {
    background: var(--bg-secondary);
}

body.dark-mode .center-panel {
    background: var(--bg-primary);
}

body.dark-mode .panel-section {
    background: var(--bg-tertiary);
}

/* Toggle Switch */
.theme-toggle {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 28px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.slider:after {
    position: absolute;
    content: "☀";
    font-size: 14px;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    transition: opacity 0.3s;
}

input:checked+.slider:after {
    content: "☾";
    left: 7px;
    right: auto;
    color: #fff;
}

input:checked+.slider {
    background-color: #2196F3;
}

input:checked+.slider:before {
    transform: translateX(32px);
}

body.dark-mode .slider {
    background-color: #555;
}

body.dark-mode input:checked+.slider {
    background-color: #2196F3;
}

.toggle-icon {
    display: inline-block;
    transition: transform 0.2s;
    font-size: 0.8em;
    margin-right: 8px;
}

#chat-container,
#chat-container.chat-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: none;
    overflow: hidden;
}

.url-input-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-input-container {
    display: flex;
    gap: 12px;
    margin-top: 0;
}

.connect-btn-container {
    display: flex;
    justify-content: stretch;
}

.connect-btn-container #connect-btn {
    width: 100%;
    justify-content: center;
}

@media (max-width: 1024px) {
    .message {
        max-width: 90%;
    }

    h1 {
        font-size: 1.8em;
    }

    h2 {
        font-size: 1.3em;
    }

    .header-container {
        padding: 15px 20px;
    }

    .header-actions {
        gap: 12px;
    }

    .new-session-btn {
        padding: 8px 16px;
        font-size: 0.85em;
    }

    .center-panel {
        padding: 15px;
    }
}

@media (max-width: 768px) {
    .header-container {
        flex-wrap: wrap;
        gap: 15px;
        height: auto;
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}

/* Removed - no longer needed with three-column layout */

/* Removed - no longer needed with three-column layout */

/* Removed - no longer needed with three-column layout */

/* Authentication Section Styles */
.auth-section {
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background-color: transparent;
    box-shadow: none;
}

body.dark-mode .auth-section {
    background-color: transparent;
}

.auth-label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.auth-type-select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.auth-type-select:hover {
    border-color: #1877f2;
    background-color: var(--bg-secondary);
}

.auth-type-select:focus {
    outline: none;
    border-color: #1877f2;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

body.dark-mode .auth-type-select {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

body.dark-mode .auth-type-select:hover {
    background-color: var(--bg-tertiary);
    border-color: #1877f2;
}

.auth-inputs {
    margin-top: 15px;
    min-height: 20px;
}

.auth-input-group {
    margin-bottom: 15px;
}

.auth-input-group label {
    display: block;
    font-size: 0.85em;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.auth-input-group input,
.auth-input-group select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9em;
    box-sizing: border-box;
    font-family: 'Courier New', monospace;
    transition: all 0.2s ease;
}

.auth-input-group input:focus,
.auth-input-group select:focus {
    outline: none;
    border-color: #1877f2;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

.auth-input-group input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.auth-input-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 10px;
}

/* Removed - no longer needed with three-column layout */

#headers-list,
#metadata-list {
    margin-bottom: 12px;
    max-height: 300px;
    overflow-y: auto;
}

.header-item,
.metadata-item {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    align-items: center;
}

.header-item input,
.metadata-item input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid #e4e6eb;
    border-radius: 8px;
    font-size: 0.95em;
    transition: all 0.2s ease;
}

.header-item input:focus,
.metadata-item input:focus {
    outline: none;
    border-color: #1877f2;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

.remove-header-btn,
.remove-metadata-btn {
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.remove-header-btn:hover,
.remove-metadata-btn:hover {
    background-color: #c82333;
    transform: scale(1.05);
}

#add-header-btn,
#add-metadata-btn {
    background-color: #1877f2;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(24, 119, 242, 0.3);
    width: 100%;
    font-size: 0.9em;
}

#add-header-btn:hover,
#add-metadata-btn:hover {
    background-color: #166fe5;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(24, 119, 242, 0.4);
}

.left-panel-scroll .panel-section:last-of-type {
    margin-bottom: 0;
}

#agent-card-url,
#chat-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9em;
    transition: all 0.2s ease;
    background-color: var(--input-bg);
    color: var(--text-primary);
    box-sizing: border-box;
}

#agent-card-url {
    font-family: 'Courier New', monospace;
}

#chat-input {
    flex-grow: 1;
    font-size: 1em;
}

#agent-card-url:focus,
#chat-input:focus {
    outline: none;
    border-color: #1877f2;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

#agent-card-url::placeholder,
#chat-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

#connect-btn,
#send-btn {
    padding: 12px 24px;
    border: none;
    background-color: #1877f2;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1em;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(24, 119, 242, 0.3);
}

#connect-btn:hover,
#send-btn:hover:not(:disabled) {
    background-color: #166fe5;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(24, 119, 242, 0.4);
}

#chat-input:disabled {
    background-color: #f7f7f7;
    cursor: not-allowed;
    border-color: #e4e6eb;
}

#send-btn:disabled {
    background-color: #e4e6eb;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

body.dark-mode #chat-input:disabled {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Multimodal UI Support */
.chat-input-wrapper {
    margin-top: 0;
    flex-shrink: 0;
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 10px;
    border: 2px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.file-input-hidden {
    display: none;
}

.attach-btn {
    padding: 12px 14px;
    border: 2px solid #e4e6eb;
    background-color: #f3f4f6;
    border-radius: 8px;
    cursor: pointer;
    margin-left: 0;
    margin-right: 0;
    transition: all 0.2s ease;
}

.attach-btn:hover:not(:disabled) {
    background-color: #e5e7eb;
    border-color: #1877f2;
    transform: scale(1.05);
}

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

.attach-icon {
    font-size: 1.3em;
    font-weight: bold;
}

.attachments-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
    min-height: 0;
    padding: 10px;
    background-color: var(--bg-primary);
    border-radius: 8px;
    border: 2px dashed var(--border-color);
}

.attachments-preview:empty {
    display: none;
}

.chat-input-wrapper .attachments-preview {
    margin-top: 0;
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-size: 0.85em;
    max-width: 280px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.attachment-chip:hover {
    border-color: #1877f2;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

body.dark-mode .attachment-chip {
    background-color: var(--bg-secondary);
}

.attachment-thumbnail {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #d1d5db;
}

.attachment-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.attachment-name {
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.dark-mode .attachment-name {
    color: var(--text-primary);
}

.attachment-size {
    font-size: 0.9em;
    color: #6b7280;
}

body.dark-mode .attachment-size {
    color: var(--text-secondary);
}

.attachment-remove {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 1.2em;
    line-height: 1;
    transition: color 0.2s;
}

.attachment-remove:hover {
    color: #ef4444;
}

.agent-card-display {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    box-sizing: border-box;
    /* Border + padding live here so the scrollbar aligns with the visible JSON frame */
    background-color: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.agent-card-display pre {
    margin: 0;
}

#agent-card-content {
    background-color: transparent;
    padding: 0;
    border: none;
    box-shadow: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-height: none;
    overflow: visible;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
    line-height: 1.5;
    display: block;
}

body.dark-mode .agent-card-display {
    border-color: var(--border-color);
    background-color: var(--bg-primary);
}

.right-panel .panel-section {
    padding: 15px;
}

.right-panel .agent-card-panel-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 0;
}

.right-panel .agent-card-panel-section>.panel-title,
.right-panel .agent-card-panel-section>#validation-errors {
    flex-shrink: 0;
}

.right-panel #validation-errors {
    padding: 10px 0;
    min-height: 40px;
}

#agent-card-content:empty {
    display: none;
}

.message {
    padding: 12px 16px;
    border-radius: 18px;
    margin-bottom: 12px;
    max-width: 85%;
    width: fit-content;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
    box-sizing: border-box;
}

.message * {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.message a {
    color: #050505;
    font-weight: bold;
    text-decoration: underline;
}

.message:hover {
    filter: brightness(95%);
}

.kind-chip {
    background-color: #dcdfe3;
    border: 1px solid #c8ccd1;
    color: #050505;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.75em;
    font-weight: 600;
    margin-right: 8px;
    display: inline-block;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.kind-chip-task {
    background-color: #e0f2fe;
    /* light blue */
    border-color: #7dd3fc;
    color: #0c4a6e;
}

.kind-chip-status-update {
    background-color: #fefce8;
    /* light yellow */
    border-color: #fde047;
    color: #713f12;
}

.kind-chip-artifact-update {
    background-color: #dcfce7;
    /* light green */
    border-color: #86efac;
    color: #14532d;
}

.kind-chip-message {
    background-color: #f3e8ff;
    /* light purple */
    border-color: #d8b4fe;
    color: #581c87;
}

.kind-chip-error {
    background-color: #fef2f2;
    /* light red */
    border-color: #fca5a5;
    color: #991b1b;
}

.message.user {
    background-color: #0084ff;
    color: white;
    align-self: flex-end;
}

.message.agent {
    background-color: #e4e6eb;
    color: #050505;
    align-self: flex-start;
    min-width: 0;
}

/* Aggregated agent turns: full width of chat column, no gray card */
.message.agent:has(.agent-turn-wrapper) {
    background-color: transparent;
    max-width: 100%;
    width: 100%;
    align-self: stretch;
    box-sizing: border-box;
}

body.dark-mode .message.agent:has(.agent-turn-wrapper) {
    background-color: transparent;
}

.message.agent:has(.agent-turn-wrapper) > .message-content,
.message.agent.agent-turn-streaming > .message-content {
    width: 100%;
    min-width: 0;
}

.message pre,
.message code {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
    overflow-x: auto;
}

.message.agent-progress {
    background-color: #f0f0f0;
    color: #65676b;
    font-style: italic;
    font-size: 0.9em;
    align-self: flex-start;
}

.message.agent-error {
    background-color: #fbe3e4;
    color: #d12f2f;
    border: 1px solid #f5c6cb;
    align-self: flex-start;
}

.message.agent-loading {
    background-color: #f0f0f0;
    color: #65676b;
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    font-style: italic;
}

body.dark-mode .message.agent-loading {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top-color: #1877f2;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

body.dark-mode .loading-spinner {
    border-color: #555;
    border-top-color: #2196F3;
}

.loading-text {
    font-size: 0.9em;
}

/* Spacing between artifact + message sections in one aggregated agent bubble */
.agent-turn-section-gap {
    height: 12px;
}

/* Collapsible “Thinking” + final answer (single agent turn) */
.agent-turn-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    width: 100%;
    /* Override .message { white-space: pre-wrap } — otherwise whitespace text nodes
       inside <details> render as a large vertical gap. */
    white-space: normal;
}

.message.agent-turn-streaming {
    border: none;
    background: transparent;
    box-shadow: none;
    max-width: 100%;
    width: 100%;
    align-self: stretch;
    box-sizing: border-box;
}

body.dark-mode .message.agent-turn-streaming {
    border: none;
    background: transparent;
}

.thinking-details {
    border-radius: 0;
    background: transparent;
    border: none;
    overflow: visible;
    display: block;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    white-space: normal;
}

body.dark-mode .thinking-details {
    background: transparent;
    border: none;
}

.thinking-summary {
    cursor: pointer;
    list-style: none;
    padding: 2px 0 6px;
    font-weight: 600;
    font-size: 0.9em;
    color: #374151;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    min-height: 0;
}

.thinking-summary-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

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

.thinking-summary::before {
    content: '▾ ';
    display: inline-block;
    transition: transform 0.15s ease;
    color: #9ca3af;
}

.thinking-details:not([open]) .thinking-summary::before {
    content: '▸ ';
}

body.dark-mode .thinking-summary {
    color: var(--text-secondary, #c1c7d0);
}

.thinking-inline-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 2px;
    vertical-align: middle;
    min-height: 1em;
}

.thinking-inline-dots.thinking-inline-dots--hidden {
    display: none !important;
}

.thinking-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6b7280;
    animation: thinking-dot-pulse 1.05s ease-in-out infinite both;
}

.thinking-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 0.3s;
}

body.dark-mode .thinking-dot {
    background: #9ca3af;
}

@keyframes thinking-dot-pulse {

    0%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    50% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

.thinking-stream-body {
    padding: 0 0 8px 1.1em;
    font-size: 0.88em;
    line-height: 1.45;
    color: #4b5563;
    word-break: break-word;
    max-height: none;
    overflow-y: visible;
    overflow-x: visible;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.thinking-stream-body.thinking-stream-body--faded {
    opacity: 0.7;
    color: #6b7280;
}

body.dark-mode .thinking-stream-body.thinking-stream-body--faded {
    opacity: 0.78;
    color: #9ca3af;
}

.thinking-stream-body:not(.thinking-stream-body--collapsed) {
    white-space: pre-wrap;
}

/* Until first streamed character: take no layout space (more reliable than :empty). */
.thinking-stream-body.thinking-stream-body--collapsed {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    border: none !important;
}

.thinking-stream-body:not(.thinking-stream-body--collapsed):not(:empty) {
    border-top: none;
    padding-top: 4px;
}

body.dark-mode .thinking-stream-body {
    color: var(--text-secondary, #b8c0cc);
}

/* Live final-answer tokens below Thinking (`metadata.stream_phase === 'final_answer'`). */
.agent-answer-block {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}

.agent-answer-stream-body {
    font-size: 0.95em;
    line-height: 1.55;
    color: #111827;
    word-break: break-word;
    max-height: none;
    overflow-y: visible;
    overflow-x: visible;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    padding: 4px 0 8px;
    opacity: 1;
}

.agent-answer-stream-body.agent-answer-stream-body--collapsed {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

body.dark-mode .agent-answer-stream-body {
    color: var(--text-primary, #e8eaed);
}

.agent-answer-slot {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.agent-answer-slot:empty {
    display: none;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* <-- Fix: Styles for validation status */
.validation-status {
    align-self: flex-end;
    margin-top: 4px;
    font-size: 0.8em;
}

.validation-status.valid,
.success-text {
    color: var(--success-color);
}

.validation-status.invalid {
    color: var(--warning-color);
}

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

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    animation: fadeInModal 0.2s ease-out;
}

@keyframes fadeInModal {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: #fff;
    color: #1c1e21;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 1000px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        padding: 20px;
    }
}

.modal-close-btn {
    position: absolute;
    top: 20px;
    right: 25px;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    color: #888;
    transition: all 0.2s ease;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close-btn:hover {
    color: #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
    transform: rotate(90deg);
}

body.dark-mode .modal-close-btn {
    color: #aaa;
}

body.dark-mode .modal-close-btn:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

#modal-json-content {
    margin: 0;
    box-sizing: border-box;
    background: #f7f7f7;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.6;
    flex: 1;
    min-height: 0;
}

.json-highlight {
    background-color: #ffc107;
    color: #333;
    padding: 0 4px;
    border-radius: 3px;
}

#chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    border: 2px solid #e4e6eb;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 12px;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    width: 100%;
    box-sizing: border-box;
}

body.dark-mode #chat-messages {
    border-color: var(--border-color);
    background-color: var(--bg-secondary);
}

/* Removed - chat info banner no longer needed */

.placeholder-text {
    color: #888;
    text-align: center;
    padding: 20px;
    margin: 0;
    font-style: italic;
    font-size: 1.05em;
}

/* Animation for new messages */
@keyframes slideInMessage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.message {
    animation: slideInMessage 0.3s ease-out;
}

#validation-errors {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    min-height: 60px;
}

#validation-errors .placeholder-text:only-child {
    margin: auto;
    padding: 20px;
}

.validation-error-item {
    background-color: #fef2f2;
    border-left: 4px solid #ef4444;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 10px;
    color: #991b1b;
    font-size: 0.95em;
}

body.dark-mode .validation-error-item {
    background-color: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
}

.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1877f2;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin: 0;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.transport-badge {
    display: inline-block;
    font-size: 0.7em;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 12px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid;
}

.transport-badge.hidden {
    display: none;
}

.transport-badge.jsonrpc {
    background-color: #e0f2fe;
    /* light blue - matching kind-chip-task */
    color: #0c4a6e;
    border-color: #7dd3fc;
}

.transport-badge.http_json,
.transport-badge.http-json {
    background-color: #dcfce7;
    /* light green - matching kind-chip-artifact-update */
    color: #14532d;
    border-color: #86efac;
}

.transport-badge.grpc {
    background-color: #f3e8ff;
    /* light purple - matching kind-chip-message */
    color: #581c87;
    border-color: #d8b4fe;
}

/* Session Management */
/* Removed - chat header container no longer needed */

.session-badge {
    display: inline-block;
    font-size: 0.7em;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    vertical-align: middle;
    letter-spacing: 0.3px;
    border: 1px solid;
}

.session-badge.hidden {
    display: none;
}

.session-badge.active {
    background-color: #dcfce7;
    /* light green */
    color: #14532d;
    border-color: #86efac;
}

.new-session-btn {
    padding: 10px 20px;
    border: none;
    background-color: #1877f2;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(24, 119, 242, 0.3);
    white-space: nowrap;
}

.new-session-btn:hover:not(:disabled) {
    background-color: #166fe5;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(24, 119, 242, 0.4);
}

.new-session-btn:disabled {
    background-color: #e4e6eb;
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.6;
}

body.dark-mode .new-session-btn:disabled {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.session-details-container {
    margin-bottom: 20px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background-color: var(--bg-secondary);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    align-self: flex-start;
    width: 100%;
}

.left-panel-scroll .panel-section .session-details-container {
    margin-bottom: 0;
}

.session-details-header {
    padding: 12px 15px;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    background-color: var(--bg-tertiary);
    transition: background-color 0.2s;
    font-size: 0.95em;
    color: var(--text-primary);
}

.session-details-header:hover {
    background-color: var(--bg-primary);
}

.session-details-header .toggle-icon {
    display: inline-block;
    transition: transform 0.2s;
    margin-right: 8px;
}

.session-details-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.session-details-content.expanded {
    max-height: 300px;
    padding: 15px;
    border-top: 1px solid #e5e7eb;
    overflow-y: auto;
}

.session-details-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.session-info-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.session-info-row strong {
    font-size: 0.9em;
    color: #4b5563;
}

.session-transport {
    font-size: 0.85em;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 10px;
    display: inline-block;
    width: fit-content;
    background-color: #e0f2fe;
    color: #0c4a6e;
    border: 2px solid #7dd3fc;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}


.session-context-id {
    background-color: #f7f7f7;
    padding: 10px 14px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    word-break: break-all;
    color: #374151;
    border: 2px solid #e5e7eb;
    transition: all 0.2s ease;
}

.session-context-id:hover {
    border-color: #1877f2;
    background-color: #fafafa;
}

.session-helper-text {
    font-size: 0.85em;
    color: #6b7280;
    font-style: italic;
    margin: 8px 0 0 0;
    padding: 8px 12px;
    background-color: #f9fafb;
    border-radius: 4px;
    border-left: 3px solid #3b82f6;
}

.modalities-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.modality-tag {
    font-size: 0.8em;
    padding: 5px 10px;
    background-color: #f3f4f6;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    color: #374151;
    white-space: nowrap;
    font-weight: 500;
    transition: all 0.2s ease;
}

.modality-tag:hover {
    border-color: #1877f2;
    background-color: #e5e7eb;
}

.modality-none {
    font-size: 0.85em;
    color: #9ca3af;
    font-style: italic;
}

/* Message Attachments */
.message-attachments {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.attachment-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85em;
    padding: 4px 8px;
    background-color: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    color: white;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    width: fit-content;
}

.message.agent .attachment-badge {
    background-color: rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.2);
    color: #050505;
}

body.dark-mode .message.agent .attachment-badge {
    color: var(--text-primary);
}

/* Media content styles */
.media-container {
    margin: 12px 0;
}

.media-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.media-image:hover {
    transform: scale(1.02);
    cursor: pointer;
}

.media-audio {
    max-width: 100%;
    display: block;
    border-radius: 8px;
}

.media-video {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.file-link {
    display: inline-block;
    padding: 8px 12px;
    background-color: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    text-decoration: none;
    color: #374151;
}

body.dark-mode .file-link {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.file-link:hover {
    background-color: #e5e7eb;
}

body.dark-mode .file-link:hover {
    background-color: var(--bg-secondary);
}

/* Custom Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 5px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

body.dark-mode ::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

body.dark-mode ::-webkit-scrollbar-thumb {
    background: #555;
}

body.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* Mobile Navigation Toggle (for future enhancement) */
@media (max-width: 1024px) {

    .left-panel,
    .right-panel {
        position: fixed;
        top: 80px;
        bottom: 0;
        width: 320px;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .left-panel.mobile-open {
        transform: translateX(0);
        display: block;
    }

    .right-panel {
        right: 0;
        left: auto;
        transform: translateX(100%);
    }

    .right-panel.mobile-open {
        transform: translateX(0);
        display: block;
    }
}

/* Empty states */
.panel-section .placeholder-text {
    font-size: 0.9em;
    padding: 15px;
}

/* Section spacing in left panel */
.left-panel-scroll .panel-section+.panel-section {
    margin-top: 10px;
}

/* Adjust validation errors in right panel */
.right-panel .validation-error-item {
    font-size: 0.85em;
    padding: 10px 12px;
}