/* ========== 聊天消息样式 ========== */

/* 消息气泡 */
.message {
    display: flex;
    gap: var(--space-sm);
    max-width: 85%;
    animation: messageAppear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes messageAppear {
    0% { opacity: 0; transform: translateY(10px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

/* 头像 */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 2px solid var(--stroke);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 800;
    box-shadow: var(--shadow-soft);
}

.message.user .message-avatar {
    background: var(--sky);
    color: var(--stroke);
}

.message.assistant .message-avatar {
    background: var(--pink);
    color: var(--stroke);
}

/* 内容区 */
.message-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.message-bubble {
    padding: var(--space-md) var(--space-lg);
    border: 2px solid var(--stroke);
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.6;
    word-break: break-word;
    box-shadow: var(--shadow-soft);
}

.message.user .message-bubble {
    background: var(--sky-light);
    border-bottom-right-radius: var(--space-xs);
}

.message.assistant .message-bubble {
    background: var(--white);
    border-bottom-left-radius: var(--space-xs);
}

/* 消息中的图片 */
.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-md);
    border: 2px solid var(--stroke);
    margin-bottom: var(--space-sm);
    object-fit: cover;
}

/* Markdown 样式 */
.message-bubble p {
    margin-bottom: var(--space-sm);
}

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

.message-bubble pre {
    background: var(--bg);
    border: 2px solid var(--stroke);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    overflow-x: auto;
    margin: var(--space-sm) 0;
    font-size: 0.8rem;
}

.message-bubble code {
    background: var(--cream-light);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    border: 1px solid var(--peach);
}

.message-bubble pre code {
    background: transparent;
    padding: 0;
    border: none;
    font-size: inherit;
}

.message-bubble ul,
.message-bubble ol {
    margin: var(--space-sm) 0;
    padding-left: var(--space-xl);
}

.message-bubble li {
    margin-bottom: var(--space-xs);
}

.message-bubble blockquote {
    border-left: 3px solid var(--pink);
    padding-left: var(--space-md);
    margin: var(--space-sm) 0;
    color: var(--text-light);
    font-style: italic;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
    margin: var(--space-md) 0 var(--space-sm);
    font-weight: 800;
    color: var(--stroke);
}

.message-bubble h1 { font-size: 1.1rem; }
.message-bubble h2 { font-size: 1rem; }
.message-bubble h3 { font-size: 0.95rem; }
.message-bubble h4 { font-size: 0.9rem; }

.message-bubble table {
    border-collapse: collapse;
    margin: var(--space-sm) 0;
    font-size: 0.85rem;
    width: 100%;
}

.message-bubble th,
.message-bubble td {
    border: 2px solid var(--stroke);
    padding: var(--space-xs) var(--space-sm);
}

.message-bubble th {
    background: var(--cream);
    font-weight: 700;
}

.message-bubble tr:nth-child(even) {
    background: var(--bg);
}

.message-bubble a {
    color: var(--pink-dark);
    text-decoration: underline;
    text-decoration-style: wavy;
    text-underline-offset: 2px;
}

.message-bubble a:hover {
    color: var(--stroke);
}

.message-bubble hr {
    border: none;
    border-top: 2px dashed var(--peach);
    margin: var(--space-md) 0;
}

/* 时间戳 */
.message-time {
    font-size: 0.65rem;
    color: var(--text-light);
    padding: 0 var(--space-xs);
}

.message.user .message-time {
    text-align: right;
}

/* 加载中 */
.message.loading .message-bubble {
    background: var(--mint-light);
    min-width: 60px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--stroke);
    border-radius: var(--radius-full);
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* 错误消息 */
.message.error .message-bubble {
    background: #FFE5E5;
    border-color: #E74C3C;
    color: #C0392B;
    font-size: 0.85rem;
    line-height: 1.7;
}

.message.error .message-bubble br {
    display: block;
    content: "";
    margin-bottom: 4px;
}

/* 系统消息 */
.message.system {
    align-self: center;
    max-width: 90%;
}

.message.system .message-bubble {
    background: var(--cream);
    font-size: 0.8rem;
    color: var(--text-light);
    text-align: center;
    padding: var(--space-sm) var(--space-lg);
}
