/* FrugalAI Chat Styles - Complete Rewrite Based on Working Prototype */

/* ==================== */
/* Reset & Base         */
/* ==================== */

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #e0f2f7;
}

/* ==================== */
/* Core Layout - THREE COLUMN */
/* ==================== */

.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ==================== */
/* Left Sidebar: Sessions */
/* ==================== */

.session-sidebar {
    width: 220px;
    min-width: 220px;
    background: #2c3e50;
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #34495e;
    background: #2c3e50;
    flex-shrink: 0;
}

.session-header h2 {
    margin: 0;
    font-size: 1.1em;
    color: white;
}

.new-chat-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    background: #3498db;
    color: white;
    font-size: 1.4em;
    line-height: 1;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-chat-btn:hover {
    background: #2980b9;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.session-item {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    background: transparent;
    transition: background-color 0.2s;
    position: relative;
}

.session-item:hover {
    background: #34495e;
}

.session-item.active {
    background: #3498db;
}

.session-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.session-title {
    display: block;
    font-size: 0.95em;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
}

.session-meta {
    display: block;
    font-size: 0.75em;
    color: #95a5a6;
    margin-top: 3px;
}

.session-delete-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    color: #95a5a6;
    font-size: 1.2em;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.session-item:hover .session-delete-btn {
    opacity: 1;
}

.session-delete-btn:hover {
    color: #e74c3c;
    background: transparent;
}

.session-title-input {
    width: 100%;
    padding: 4px 8px;
    font-size: 0.95em;
    border: 1px solid #3498db;
    border-radius: 4px;
    background: #34495e;
    color: white;
}

.session-title-input:focus {
    outline: none;
    border-color: #2980b9;
}

/* ==================== */
/* Right Sidebar: Config */
/* ==================== */

.config-sidebar {
    width: 280px;
    min-width: 280px;
    background: #f5f5f5;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    transition: width 0.3s, min-width 0.3s;
}

.config-sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
}

.config-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    background: #f5f5f5;
    flex-shrink: 0;
}

.config-header h2 {
    margin: 0;
    font-size: 1.1em;
    color: #37474f;
}

.config-close-btn {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    padding: 5px;
    color: #666;
}

.config-close-btn:hover {
    color: #333;
    background: none;
}

.config-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.config-toggle {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    padding: 5px 10px;
    color: #666;
    margin-left: auto;
}

.config-toggle:hover {
    color: #333;
    background: none;
}

/* Legacy sidebar styles (keep for compatibility) */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: #f5f5f5;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    background: #f5f5f5;
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.1em;
    color: #37474f;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    padding: 5px;
    color: #666;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

/* Right Main Content - CRITICAL: overflow hidden + flex column */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: white;
}

/* Header - fixed height */
.app-header {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 15px;
}

.app-header h1 {
    margin: 0;
    font-size: 1.3em;
    color: #263238;
}

/* Chat Container - CRITICAL: flex 1 + overflow hidden */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat Actions Bar */
.chat-actions {
    padding: 10px 20px;
    flex-shrink: 0;
    border-bottom: 1px solid #e0e0e0;
}

/* Chat Window - THE SCROLLABLE AREA */
#chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 15px 20px;
    background: #fafafa;
    min-height: 0;
}

/* Input Area - fixed at bottom */
.input-area {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
    align-items: center;
}

/* Image Preview Container */
#image-preview-container {
    padding: 10px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

#image-preview {
    max-height: 100px;
    max-width: 200px;
    border-radius: 4px;
}

/* ==================== */
/* Config Groups        */
/* ==================== */

.config-group {
    margin-bottom: 15px;
}

.config-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.85em;
    color: #555;
}

.config-group input[type="text"],
.config-group select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}

.config-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
}

.input-group {
    display: flex;
    gap: 5px;
}

.input-group input {
    flex: 1;
}

/* ==================== */
/* Buttons              */
/* ==================== */

button {
    padding: 10px 15px;
    background-color: #42a5f5;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #2196f3;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.85em;
}

.btn-danger {
    background: #f44336;
}

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

#attach-image-button {
    flex-shrink: 0;
    background-color: #607d8b;
    border-radius: 20px;
    height: 40px;
    padding: 0 15px;
}

#send-button {
    flex-shrink: 0;
    border-radius: 20px;
    height: 40px;
    padding: 0 20px;
}

#remove-image-button {
    padding: 5px 10px;
    font-size: 0.9rem;
}

/* ==================== */
/* Chat Input           */
/* ==================== */

#chat-input {
    flex: 1;
    margin: 0;
    padding: 10px 15px;
    border: 1px solid #ccc;
    border-radius: 20px;
    resize: none;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.5;
    min-height: 40px;
    max-height: 120px;
    overflow-y: auto;
}

#chat-input:focus {
    outline: none;
    border-color: #42a5f5;
}

/* ==================== */
/* Messages             */
/* ==================== */

.message {
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 15px;
    max-width: 85%;
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    line-height: 1.6;
    word-wrap: break-word;
}

.message-content {
    padding-bottom: 18px;
}

.message-timestamp {
    position: absolute;
    bottom: 5px;
    font-size: 0.75em;
    color: rgba(0, 0, 0, 0.5);
}

.user-message {
    background-color: #e3f2fd;
    margin-left: auto;
    margin-right: 10px;
    border-bottom-right-radius: 2px;
}

.user-message .message-timestamp {
    right: 10px;
}

.model-message {
    background-color: #e8f5e9;
    margin-right: auto;
    margin-left: 10px;
    border-bottom-left-radius: 2px;
}

.model-message .message-timestamp {
    left: 10px;
}

/* Message Actions */
.message-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

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

.action-btn {
    padding: 4px 8px;
    font-size: 0.75em;
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    background: white;
    cursor: pointer;
}

.action-btn:hover {
    background: #f0f0f0;
}

.action-edit { color: #1976d2; }
.action-resend { color: #4caf50; }
.action-toggle-raw { color: #ff9800; }
.action-delete { color: #f44336; }

/* Edit Mode */
.message.edit-mode {
    outline: 2px solid #42a5f5;
}

.message-edit-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: inherit;
    resize: vertical;
}

.edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}

/* Raw Content Display */
.message-content.raw-mode {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.message-content.raw-mode pre {
    background: transparent;
    padding: 10px;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    white-space: pre-wrap;
    margin: 0;
}

/* Raw Content Container - Left/Right Layout */
.raw-content-container {
    display: flex;
    gap: 16px;
    padding: 10px;
}

.raw-markdown-pane {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    background: #fafafa;
    padding: 12px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
    margin: 0;
}

.raw-image-pane {
    flex: 0 0 auto;
    max-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px;
    background: #f0f0f0;
    border-radius: 6px;
}

.raw-image-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.raw-image-label {
    font-size: 11px;
    color: #666;
    font-weight: 500;
}

.raw-image-thumbnail {
    max-width: 100%;
    max-height: 120px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid #ddd;
    transition: transform 0.2s, box-shadow 0.2s;
}

.raw-image-thumbnail:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Loading Spinner */
.loading-spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: #4CAF50;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
}

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

/* ==================== */
/* Markdown Content     */
/* ==================== */

.message-content p {
    margin: 0 0 0.8em 0;
}

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

.message-content ul,
.message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-content li {
    margin: 0.3em 0;
}

.message-content pre {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    overflow-x: auto;
    margin: 0.8em 0;
}

.message-content code {
    background: #f0f0f0;
    padding: 2px 5px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content blockquote {
    border-left: 3px solid #ccc;
    margin: 0.5em 0;
    padding: 0.3em 0.8em;
    color: #666;
    font-size: 0.9em;
    line-height: 1.4;
}

.message-content blockquote p {
    margin: 0.3em 0;
}

/* Collapsible thinking/reasoning section */
.message-content details {
    border-left: 3px solid #81c784;
    background: #fafafa;
    margin: 0.8em 0;
    padding: 0;
    font-size: 0.9em;
    line-height: 1.5;
    color: #555;
}

.message-content details summary {
    cursor: pointer;
    padding: 6px 10px;
    font-weight: 600;
    font-size: 0.85em;
    color: #558b2f;
    background: #f1f8e9;
    user-select: none;
}

.message-content details summary:hover {
    background: #dcedc8;
}

.message-content details[open] summary {
    border-bottom: 1px solid #c5e1a5;
}

.message-content details > *:not(summary) {
    padding: 0 10px;
}

.message-content details > p:first-of-type {
    padding-top: 8px;
}

.message-content details > p:last-of-type {
    padding-bottom: 8px;
}

.message-content details img {
    max-width: 250px;
    max-height: 250px;
    margin: 8px 0;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin: 1em 0 0.5em 0;
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child,
.message-content h4:first-child {
    margin-top: 0;
}

.message-content table {
    border-collapse: collapse;
    margin: 0.8em 0;
    width: 100%;
}

.message-content th,
.message-content td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

.message-content th {
    background: #f5f5f5;
}

.message-content img {
    max-width: 300px;
    max-height: 300px;
    cursor: pointer;
    transition: opacity 0.3s;
    border-radius: 6px;
}

.message-content img:hover {
    opacity: 0.8;
}

.message-content a {
    color: #1976d2;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content strong {
    font-weight: 600;
}

.message-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 1em 0;
}

/* ==================== */
/* Model Dropdown       */
/* ==================== */

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

.model-input-container #model-select {
    flex: 1;
    padding-right: 35px;
}

.dropdown-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 5px;
    font-size: 12px;
}

.dropdown-btn:hover {
    color: #42a5f5;
    background: none;
}

.model-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ccc;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.model-dropdown-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.model-dropdown-item:hover {
    background-color: #f5f5f5;
}

.model-dropdown-empty {
    padding: 10px;
    color: #666;
    text-align: center;
    font-style: italic;
}

/* ==================== */
/* Reasoning Content    */
/* ==================== */

.reasoning-content {
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 5px 10px;
    margin-bottom: 10px;
    font-family: monospace;
    font-size: 0.85em;
}

.reasoning-content summary {
    cursor: pointer;
    font-weight: bold;
    padding: 5px 0;
}

.reasoning-text {
    white-space: pre-wrap;
}

.reasoning-text img {
    max-width: 300px;
    max-height: 300px;
    border-radius: 5px;
    margin-top: 10px;
    display: block;
}

.main-content-text img {
    max-width: 350px;
    max-height: 350px;
    border-radius: 8px;
    margin: 10px 0;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ==================== */
/* Raw Mode Container   */
/* ==================== */

#raw-mode-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px 20px;
    overflow: hidden;
}

#raw-mode-container .raw-mode-header {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

#raw-mode-container h3 {
    margin: 0;
    font-size: 1em;
    color: #37474f;
}

#raw-request-input {
    flex: 1;
    min-height: 100px;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    resize: none;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
}

/* Raw Response Dual-Column Layout */
.raw-response-container {
    flex: 2;
    display: flex;
    gap: 15px;
    overflow: hidden;
    min-height: 0;
}

.raw-response-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.raw-response-pane h4 {
    margin: 0 0 8px 0;
    font-size: 0.9em;
    color: #666;
    flex-shrink: 0;
}

#raw-response-output {
    flex: 1;
    overflow-y: auto;
    background: #f5f5f5;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-family: 'Consolas', monospace;
    font-size: 0.85em;
    white-space: pre-wrap;
    margin: 0;
}

#raw-response-rendered {
    flex: 1;
    overflow-y: auto;
    background: #fafafa;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ddd;
}

/* Override message-content padding for raw mode (no timestamp needed) */
#raw-response-rendered.message-content {
    padding-bottom: 10px;
}

/* Mobile: stack vertically */
@media (max-width: 900px) {
    .raw-response-container {
        flex-direction: column;
    }

    .raw-response-pane {
        flex: none;
        min-height: 150px;
        max-height: 300px;
    }
}

/* ==================== */
/* Tools Section        */
/* ==================== */

.tools-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tools-toggle-btn {
    background: none;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 5px 10px;
    color: #666;
}

.tools-toggle-btn:hover {
    color: #ff9800;
    background: none;
}

.tools-list {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tool-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
    transition: opacity 0.2s, background-color 0.2s;
}

.tool-card.tool-disabled {
    opacity: 0.6;
    background: #f5f5f5;
}

.tool-card.tool-disabled .tool-name,
.tool-card.tool-disabled .tool-description {
    color: #999;
}

.tool-card-content {
    flex: 1;
    min-width: 0;
}

.tool-name {
    font-weight: bold;
    color: #37474f;
    word-break: break-word;
    margin-bottom: 6px;
}

.tool-description {
    color: #666;
    font-size: 0.85em;
    line-height: 1.4;
}

.tool-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.tool-actions .tool-enable-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
}

.tool-actions button {
    padding: 4px 6px;
    font-size: 1em;
    line-height: 1;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.tool-actions button:hover {
    background-color: #f0f0f0;
}

.tool-edit-btn { color: #42a5f5; }
.tool-delete-btn { color: #f44336; }

.param-badge {
    background: #e3f2fd;
    color: #1976d2;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8em;
}

.param-badge.required {
    background: #ffebee;
    color: #c62828;
}

.add-tool-btn {
    margin-top: 15px;
    background-color: #ff9800;
    width: 100%;
}

/* ==================== */
/* Mock Mode Section    */
/* ==================== */

.mock-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mock-toggle-btn {
    background: none;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 5px 10px;
    color: #666;
}

.mock-toggle-btn:hover {
    color: #9c27b0;
    background: none;
}

#mock-content {
    margin-top: 10px;
    padding: 10px;
    background: #f9f0ff;
    border: 1px solid #e1bee7;
    border-radius: 6px;
}

.mock-enable-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-weight: normal !important;
    cursor: pointer;
}

.mock-enable-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.mock-delay-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.mock-delay-row label {
    font-size: 0.85em;
    margin: 0;
    white-space: nowrap;
}

#mock-delay-input {
    width: 60px;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}

.mock-delay-row span {
    font-size: 0.85em;
    color: #666;
}

.mock-response-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.mock-response-header .mock-response-label {
    font-size: 0.85em;
    margin: 0;
}

.mock-response-actions {
    display: flex;
    gap: 5px;
}

.mock-action-btn {
    padding: 3px 8px;
    font-size: 0.75em;
    background: #9c27b0;
}

.mock-action-btn:hover {
    background: #7b1fa2;
}

.mock-response-preview {
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 8px;
    font-family: 'Consolas', monospace;
    font-size: 0.85em;
    min-height: 60px;
    max-height: 120px;
    overflow: hidden;
    color: #333;
    white-space: pre-wrap;
    word-break: break-all;
}

.mock-preview-empty {
    color: #999;
    font-style: italic;
}

.mock-preview-truncated::after {
    content: '...';
    color: #9c27b0;
    font-weight: bold;
}

#mock-response-input {
    width: 100%;
    min-height: 120px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.85em;
    resize: vertical;
    background: white;
}

#mock-response-input:focus {
    outline: none;
    border-color: #9c27b0;
}

/* Mock Mode Active Indicator */
.mock-mode-active #send-button {
    background-color: #9c27b0;
}

.mock-mode-active #send-button:hover {
    background-color: #7b1fa2;
}

/* ==================== */
/* Tool Modal           */
/* ==================== */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.tool-modal {
    justify-content: center;
    align-items: center;
}

.tool-modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.tool-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.tool-modal-header h3 {
    margin: 0;
}

.close-tool-modal {
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.close-tool-modal:hover {
    color: #f44336;
}

#tool-form {
    padding: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.params-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}

.param-row {
    display: grid;
    grid-template-columns: 1fr 100px 1fr auto auto auto;
    gap: 8px;
    align-items: center;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 6px;
}

.param-row input,
.param-row select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}

.param-required-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85em;
}

.remove-param-btn {
    background: #f44336;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-param-btn {
    background: #4caf50;
    font-size: 0.9em;
    padding: 8px 12px;
}

.tool-preview {
    background: #263238;
    color: #aed581;
    padding: 12px;
    border-radius: 6px;
    font-family: 'Consolas', monospace;
    font-size: 0.85em;
    max-height: 150px;
    overflow: auto;
    margin: 0;
}

.tool-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.cancel-btn { background: #9e9e9e; }
.save-btn { background: #4caf50; }

/* ==================== */
/* Image Modal          */
/* ==================== */

#image-modal {
    background-color: rgba(0,0,0,0.9);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90%;
    max-height: 90%;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    cursor: pointer;
}

/* ==================== */
/* Tool Call UI         */
/* ==================== */

.tool-calls-container {
    margin-top: 10px;
}

.tool-call-block {
    background: #fff8e1;
    border: 1px solid #ffcc80;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

.tool-call-block.streaming {
    border-style: dashed;
}

.tool-call-block.submitted {
    background: #e8f5e9;
    border-color: #a5d6a7;
}

.tool-call-header {
    font-size: 0.95em;
    margin-bottom: 8px;
    color: #e65100;
}

.tool-call-label {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 4px;
}

.tool-call-args-content {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px;
    font-family: 'Consolas', monospace;
    font-size: 0.85em;
    margin: 0;
    white-space: pre-wrap;
}

.tool-call-response-input {
    width: 100%;
    min-height: 60px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    resize: vertical;
    margin-top: 4px;
}

.tool-call-submit-btn {
    margin-top: 8px;
    background: #ff9800;
}

.tool-call-response-submitted {
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 4px;
    padding: 8px;
    font-family: 'Consolas', monospace;
    font-size: 0.85em;
    margin-top: 4px;
    white-space: pre-wrap;
}

/* Tool Response Block */
.tool-response-block {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

.tool-response-header {
    font-size: 0.95em;
    margin-bottom: 8px;
    color: #1565c0;
}

.tool-response-content {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px;
    font-family: 'Consolas', monospace;
    font-size: 0.85em;
    margin: 0;
    white-space: pre-wrap;
}

/* Tool Response Bubble */
.tool-call-summary {
    background-color: #fff9c4;
    border: 1px solid #fbc02d;
    border-radius: 8px;
    padding: 10px 15px;
    margin-bottom: 10px;
}

.tool-call-summary-header {
    font-weight: bold;
    color: #f57f17;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.tool-call-summary-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tool-call-summary-item {
    font-size: 0.9em;
}

.tool-call-id {
    font-family: monospace;
    color: #666;
    font-size: 0.85em;
}

.tool-response-bubble {
    background-color: #e3f2fd;
    border: 1px solid #2196f3;
    max-width: 90%;
}

.tool-response-bubble.pending {
    border-left: 4px solid #2196f3;
}

.tool-response-bubble.saved {
    background-color: #e8f5e9;
    border-color: #4caf50;
    border-left: 4px solid #4caf50;
}

.tool-response-bubble-header {
    color: #1565c0;
    margin-bottom: 10px;
    font-size: 0.95em;
}

.tool-response-args {
    background-color: rgba(255, 255, 255, 0.6);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 10px;
    font-size: 0.9em;
}

.tool-response-args-content {
    margin: 5px 0 0 0;
    font-family: 'Consolas', monospace;
    white-space: pre-wrap;
    font-size: 0.85em;
}

.tool-response-input-section {
    background-color: white;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #bbdefb;
}

.tool-response-bubble-inline {
    background-color: #e3f2fd;
    border: 1px solid #2196f3;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
}

.tool-response-bubble-inline.saved {
    background-color: #e8f5e9;
    border-color: #4caf50;
    border-left: 4px solid #4caf50;
}

.tool-response-label {
    font-size: 0.85em;
    font-weight: bold;
    color: #555;
    margin-bottom: 5px;
}

.tool-response-input {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    margin-bottom: 8px;
    resize: vertical;
}

.tool-response-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

.tool-response-save-btn {
    padding: 6px 12px;
    background-color: #2196f3;
}

.tool-response-status {
    font-size: 0.85em;
    color: #666;
}

.tool-response-status.saved {
    color: #2e7d32;
    font-weight: bold;
}

/* ==================== */
/* Error & Misc         */
/* ==================== */

.error-message {
    color: #f44336;
    font-size: 0.9em;
    margin-top: 5px;
    display: none;
}

.mobile-only {
    display: none;
}

/* ==================== */
/* Visibility Classes   */
/* ==================== */

/* Hidden class - use this instead of style.display in JS */
.hidden {
    display: none !important;
}

/* Chat container needs flex when visible */
.chat-container.active {
    display: flex;
}

/* ==================== */
/* Responsive           */
/* ==================== */

@media (max-width: 1024px) {
    /* Hide config sidebar by default on tablets */
    .config-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .config-sidebar.open {
        transform: translateX(0);
    }

    .config-toggle {
        display: flex;
    }
}

@media (max-width: 768px) {
    /* Session sidebar becomes drawer on mobile */
    .session-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .session-sidebar.open {
        transform: translateX(0);
    }

    /* Config sidebar also drawer on mobile */
    .config-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .config-sidebar.open {
        transform: translateX(0);
    }

    /* Legacy sidebar support */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-only {
        display: flex;
    }

    .config-toggle {
        display: flex;
    }

    .config-group-row {
        grid-template-columns: 1fr;
    }

    .param-row {
        grid-template-columns: 1fr 1fr;
    }

    /* Overlay when sidebars are open */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

@media (min-width: 769px) {
    .sidebar-header .sidebar-toggle {
        display: none;
    }
}

@media (min-width: 1025px) {
    /* Show config toggle only when sidebar is collapsed */
    .config-toggle {
        display: none;
    }

    .config-sidebar.collapsed + .main-content .config-toggle,
    .main-content .config-toggle {
        display: flex;
    }
}
