/* ============================================================
   Chat — Chat bubbles, markdown rendering, tool cards
   ============================================================ */

/* ── Chat Messages (History View) ──────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.chat-bubble {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    max-width: 85%;
    position: relative;
}

.chat-bubble.human {
    background: var(--chat-human-bg);
    color: var(--chat-human-color);
    margin-left: auto;
    border-bottom-right-radius: 2px;
}

.chat-bubble.assistant {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 2px;
}

.chat-bubble .role-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.chat-bubble .message-text {
    word-break: break-word;
    line-height: 1.55;
}

.chat-bubble .message-text p {
    margin: 4px 0;
}

.chat-bubble .message-text p:first-child { margin-top: 0; }
.chat-bubble .message-text p:last-child  { margin-bottom: 0; }

.chat-bubble .message-text code {
    background: var(--code-inline-bg);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.chat-bubble .message-text pre {
    background: var(--bg-primary);
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid var(--border);
}

.chat-bubble .message-text pre code {
    background: none;
    padding: 0;
    font-size: 12px;
    line-height: 1.45;
}

.chat-bubble .message-text ul,
.chat-bubble .message-text ol {
    margin: 6px 0;
    padding-left: 20px;
}

.chat-bubble .message-text li {
    margin: 2px 0;
}

.chat-bubble .message-text h1,
.chat-bubble .message-text h2,
.chat-bubble .message-text h3 {
    margin: 10px 0 4px;
    font-size: 14px;
    font-weight: 600;
}

.chat-bubble .message-text blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 10px;
    margin: 6px 0;
    color: var(--text-secondary);
}

.chat-bubble .message-text table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
}

.chat-bubble .message-text th,
.chat-bubble .message-text td {
    border: 1px solid var(--border);
    padding: 4px 8px;
}

.chat-bubble .message-text th {
    background: var(--bg-secondary);
    font-weight: 600;
}

/* ── Markdown Body (rich rendering) ────────────────────────── */

.chat-bubble .message-text.markdown-body {
    white-space: normal;
}

.chat-bubble .message-text.markdown-body h1,
.chat-bubble .message-text.markdown-body h2,
.chat-bubble .message-text.markdown-body h3,
.chat-bubble .message-text.markdown-body h4 {
    margin: 12px 0 6px;
    font-weight: 600;
    line-height: 1.3;
}

.chat-bubble .message-text.markdown-body h1 { font-size: 1.3em; }
.chat-bubble .message-text.markdown-body h2 { font-size: 1.15em; }
.chat-bubble .message-text.markdown-body h3 { font-size: 1.05em; }
.chat-bubble .message-text.markdown-body h4 { font-size: 1em; }

.chat-bubble .message-text.markdown-body p {
    margin: 6px 0;
}

.chat-bubble .message-text.markdown-body code {
    background: var(--code-inline-bg);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.chat-bubble .message-text.markdown-body pre {
    background: var(--code-block-bg);
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.chat-bubble .message-text.markdown-body pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    line-height: 1.5;
}

.chat-bubble .message-text.markdown-body ul,
.chat-bubble .message-text.markdown-body ol {
    padding-left: 20px;
    margin: 6px 0;
}

.chat-bubble .message-text.markdown-body li {
    margin: 2px 0;
}

.chat-bubble .message-text.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 12px 0;
}

.chat-bubble .message-text.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 10px;
    margin: 8px 0;
    color: var(--text-secondary);
}

.chat-bubble .message-text.markdown-body a {
    color: var(--accent);
    text-decoration: none;
}

.chat-bubble .message-text.markdown-body a:hover {
    text-decoration: underline;
}

.chat-bubble .message-text.markdown-body table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.chat-bubble .message-text.markdown-body th,
.chat-bubble .message-text.markdown-body td {
    border: 1px solid var(--border);
    padding: 4px 8px;
    font-size: 0.9em;
}

.chat-bubble .message-text.markdown-body th {
    background: var(--table-header-bg);
}

/* ── Edit Button ───────────────────────────────────────────── */

.chat-bubble .edit-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-bubble:hover .edit-btn {
    opacity: 1;
}

.chat-bubble .edit-btn:hover {
    background: var(--accent-dim);
    color: var(--text-primary);
}

/* ── Live History Panel (right sidebar) ────────────────────── */

.live-history-panel {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
}

.live-history-panel .chat-bubble {
    font-size: 12px;
    padding: 8px 10px;
}

.live-history-panel .chat-bubble .role-label {
    font-size: 10px;
}

.live-history-panel .chat-bubble .message-text {
    font-size: 12px;
}

/* ── Tool Cards ────────────────────────────────────────────── */

.tool-card {
    margin-top: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    font-size: 12px;
}

.tool-card-summary {
    margin-top: 3px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.tool-card-description {
    color: var(--text-primary);
    font-size: 12px;
    margin-bottom: 4px;
}

/* AskUserQuestion prompt */
.tool-question {
    margin-top: 4px;
}

.tool-question-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.tool-question-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tool-question-option {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
}

.tool-question-option-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}

.tool-question-option-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.tool-card-command {
    margin: 3px 0 0;
    padding: 6px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
}

/* ── Tool Card Diff ────────────────────────────────────────── */

.tool-card-diff {
    margin-top: 4px;
    font-size: 11px;
}

.tool-card-diff > summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 11px;
    user-select: none;
    padding: 2px 0;
}

.tool-card-diff > summary:hover {
    color: var(--text-secondary);
}

.diff-content {
    margin-top: 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    font-family: var(--font-mono);
}

.diff-line {
    padding: 0 8px;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.4;
}

.diff-line.diff-del {
    background: var(--diff-del-bg);
    color: var(--diff-del-color);
}

.diff-line.diff-add {
    background: var(--diff-add-bg);
    color: var(--diff-add-color);
}

/* ── Tool Result Output Blocks ─────────────────────────────── */

.tool-result-content {
    margin: 0;
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-secondary);
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.tool-card-output {
    border-top: 1px solid var(--border);
    margin-top: 6px;
    padding-top: 4px;
}

.tool-output-inline {
    margin: 0;
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
    overflow-x: auto;
}

.tool-output-toggle {
    display: block;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 8px 4px;
    opacity: 0.8;
}

.tool-output-toggle:hover {
    opacity: 1;
    text-decoration: underline;
}

.tool-output-inline.tool-result-error {
    color: var(--error);
    opacity: 0.85;
}

/* Fallback standalone result block */
.tool-result-block {
    max-width: 85%;
    margin-bottom: 4px;
    margin-top: -12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
}

.tool-result-standalone {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
