/* Markdown Styles for Message Content */
.msg-bubble strong,
.msg-bubble b {
    font-weight: 700;
    color: var(--secondary-color);
    /* 青色，与重新生成按钮颜色一致 */
}

.msg-bubble em,
.msg-bubble i {
    font-style: italic;
    color: var(--secondary-color);
    /* 斜体字形有右侧外凸，补一点左右间距避免与相邻正体贴连/重叠 */
    margin-inline: 0.12em;
}

.msg-bubble code {
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    color: #e0e0e0;
}

/* IDE Style Code Block */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    background: #1e1e1e;
    border: 1px solid #333;
    max-width: 100%;
    width: 100%;
    /* 强制占满可用宽度 */
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #2d2d2d;
    border-bottom: 1px solid #333;
}

.code-block-lang {
    font-size: 0.75rem;
    color: #888;
    text-transform: uppercase;
    font-weight: 600;
}

.code-copy-btn {
    background: transparent;
    border: 1px solid #555;
    color: #aaa;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.code-copy-btn:hover {
    background: #444;
    color: #fff;
    border-color: #666;
}

.code-copy-btn.copied {
    background: #2ea043;
    border-color: #2ea043;
    color: #fff;
}

.msg-bubble pre {
    background: #1e1e1e;
    padding: 16px;
    margin: 0;
    overflow-x: auto !important;
    max-width: 100%;
    width: 100%;
    white-space: pre;
    -webkit-overflow-scrolling: touch;
}

/* 代码块滚动条美化 */
.msg-bubble pre::-webkit-scrollbar {
    height: 8px;
}

.msg-bubble pre::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.msg-bubble pre::-webkit-scrollbar-thumb:hover {
    background: #666;
}

.msg-bubble pre code {
    background: none;
    padding: 0;
    color: #d4d4d4;
    font-size: 0.85em;
    line-height: 1.6;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    white-space: pre;
    /* 保持原样以支持滚动 */
    display: inline-block;
    /* 关键：改为 inline-block 以允许宽度超过父容器并触发滚动条 */
    min-width: 100%;
}

.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    color: var(--text-primary);
}

.msg-bubble h1 {
    font-size: 1.5em;
}

.msg-bubble h2 {
    font-size: 1.3em;
}

.msg-bubble h3 {
    font-size: 1.1em;
}

.msg-bubble ul,
.msg-bubble ol {
    margin: 10px 0;
    padding-left: 20px;
}

.msg-bubble li {
    margin: 6px 0;
    line-height: 1.5;
}

.msg-bubble ol li {
    list-style-type: decimal;
}

.msg-bubble ul li {
    list-style-type: disc;
}

.msg-bubble blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
    font-style: italic;
}

.msg-bubble a {
    color: var(--secondary-color);
    text-decoration: underline;
}

.msg-bubble a:hover {
    color: var(--primary-color);
}

/* Markdown Body Container */
.markdown-body {
    line-height: 1.6;
}

.markdown-body p {
    margin: 0 0 8px 0;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

/* Clean up starred text (roleplay actions) */
.markdown-body em {
    color: var(--text-secondary);
    font-style: italic;
}

/* Markdown Table Styles */
.msg-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 0.9em;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow: hidden;
    /* For rounded corners */
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}

.msg-bubble th,
.msg-bubble td {
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: left;
}

.msg-bubble th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: var(--text-primary);
}

.msg-bubble tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* Light Theme Support */
body.light-theme .msg-bubble table {
    border-color: rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.5);
}

body.light-theme .msg-bubble th,
body.light-theme .msg-bubble td {
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-theme .msg-bubble th {
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme .msg-bubble tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}