/* AI 消息 Markdown 渲染（Trae Chat 风格） */

.chat-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 14px;
}

.chat-area:empty::before {
    content: "输入调试问题，AI 将以对话方式协助分析";
    padding: 12px 4px;
}

.msg {
    margin-bottom: 0;
    max-width: 100%;
    border-radius: 10px;
    line-height: 1.55;
    font-size: 13px;
    word-break: break-word;
}

.msg.user {
    align-self: flex-end;
    max-width: 88%;
    padding: 10px 14px;
    background: #0e639c;
    color: #f3f9ff;
    border: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.msg.user p {
    margin: 0;
}

.msg.ai {
    align-self: stretch;
    padding: 2px 0;
    background: transparent;
    color: #d4d4d4;
    border: none;
}

.msg.ai-loading {
    align-self: flex-start;
    padding: 8px 12px;
    background: #2a2a2b;
    border: 1px solid #3a3a3c;
    border-radius: 10px;
}

.loading-dots { color: #4ec9b0; }

/* ── Markdown 根容器 ── */
.ai-md {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.ai-md-h2 {
    margin: 4px 0 2px;
    font-size: 15px;
    font-weight: 600;
    color: #e8e8e8;
}

.ai-md-h3 {
    margin: 2px 0;
    font-size: 14px;
    font-weight: 600;
    color: #e0e0e0;
}

.ai-md-p {
    margin: 0;
    color: #c8c8c8;
    line-height: 1.65;
}

.ai-md-strong {
    color: #e8e8e8;
    font-weight: 600;
}

.ai-md-code {
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(110, 118, 129, 0.25);
    color: #ce9178;
    word-break: break-all;
}

.ai-md-list {
    margin: 4px 0 4px 4px;
    padding-left: 18px;
    color: #c8c8c8;
}

.ai-md-list li {
    margin: 4px 0;
    line-height: 1.6;
}

.ai-md-list li::marker {
    color: #6a9955;
}

/* ── 分析分段卡片（### 1. 归因 等）── */
.ai-md-section {
    background: #252526;
    border: 1px solid #3c3c3c;
    border-radius: 10px;
    overflow: hidden;
}

.ai-md-section__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: linear-gradient(180deg, #2d2d30 0%, #282829 100%);
    border-bottom: 1px solid #3a3a3c;
}

.ai-md-section__badge {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 6px;
    background: rgba(14, 99, 156, 0.35);
    color: #9cdcfe;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
}

.ai-md-section__title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #e8e8e8;
    line-height: 1.4;
}

.ai-md-section__body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-md-section__body .ai-md-p:last-child,
.ai-md-section__body .ai-md-list:last-child,
.ai-md-section__body .ai-md-pre-wrap:last-child {
    margin-bottom: 0;
}

/* ── 代码块（只读展示）── */
.ai-md-pre-wrap {
    border: 1px solid #3a3a3c;
    border-radius: 8px;
    overflow: hidden;
    background: #1a1a1b;
}

.ai-md-pre-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: #2d2d30;
    border-bottom: 1px solid #3a3a3c;
}

.ai-md-pre-label {
    font-size: 11px;
    color: #858585;
    letter-spacing: 0.02em;
}

.ai-md-copy {
    padding: 2px 8px;
    font-size: 11px;
    color: #ccc;
    background: #3c3c3c;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    cursor: pointer;
}

.ai-md-copy:hover {
    background: #4a4a4a;
    color: #fff;
}

.ai-md-pre {
    margin: 0;
    padding: 10px 12px;
    overflow-x: auto;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.55;
    color: #d4d4d4;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-md-pre code {
    font-family: inherit;
}

/* ── 风险警示 ── */
.ai-md-callout {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
}

.ai-md-callout--warn {
    background: rgba(204, 120, 50, 0.12);
    border: 1px solid rgba(204, 120, 50, 0.35);
    color: #e8c4a8;
}

/* ── 流式光标 ── */
.ai-md-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: #4ec9b0;
    animation: ai-md-blink 1s step-end infinite;
}

@keyframes ai-md-blink {
    50% { opacity: 0; }
}
