/* ==================== 全局重置 ==================== */
/* 清除所有元素默认的外边距、内边距，并统一盒模型为 border-box */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ==================== 页面基础样式 ==================== */
/* 聊天页整体：楷体、米黄纸色背景，视口内居中且不允许页面滚动 */
body {
    font-family: 'STKaiti', 'KaiTi', '楷体', serif; /* 字体栈：华文楷体 → 楷体 → 楷体 → 衬线体 */
    background: #f5f0e8; /* 米黄纸色背景，与首页风格统一 */
    min-height: 100vh; /* 至少铺满视口高度 */
    display: flex; /* 弹性布局，用于居中聊天容器 */
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    overflow: hidden; /* 隐藏滚动条，滚动交给消息区域处理 */
}

/* ==================== 背景装饰 ==================== */
/* 背景噪点纹理：内联 SVG 生成灰度噪声，极低透明度叠加，不拦截交互 */
.bg-noise {
    position: fixed; /* 固定在视口 */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.05; /* 仅保留微弱纸张质感 */
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' /%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
}

/* ==================== 聊天容器 ==================== */
/* 聊天主面板：限制最大宽度与高度，内部按头部/消息/输入三段纵向排布 */
.chat-container {
    width: 100%;
    max-width: 480px; /* 模拟手机宽度，桌面端不会过宽 */
    height: 100vh; /* 移动端占满整屏 */
    max-height: 900px; /* 大屏上限制最大高度 */
    background: rgba(255, 255, 255, 0.95); /* 半透明白底 */
    display: flex;
    flex-direction: column; /* 头部、消息区、输入区纵向排列 */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1); /* 柔和投影，突出面板层次 */
    position: relative; /* 为返回按钮绝对定位提供参考 */
}

/* 桌面端（≥768px）：聊天面板改为 90vh 高并加上圆角，更像一个悬浮卡片 */
@media (min-width: 768px) {
    .chat-container {
        height: 90vh;
        border-radius: 16px;
    }
}

/* ==================== 头部区域 ==================== */
/* 聊天头部：绿色渐变背景，白色文字，裁剪溢出的装饰光斑 */
.chat-header {
    background: linear-gradient(135deg, #4a7c59 0%, #5a8c69 100%); /* 与主站按钮同系绿色 */
    padding: 20px;
    color: white;
    position: relative; /* 为 ::before 光斑定位 */
    overflow: hidden; /* 裁切超出头部的装饰 */
}

/* 头部右上角的金色径向光晕装饰，增强温润质感 */
.chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(212, 175, 55, 0.2) 0%, transparent 70%);
    border-radius: 50%;
}

/* 头部信息行：横向排列头像与标题，位于光斑之上 */
.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1; /* 高于装饰光斑 */
}

/* 头像容器：固定尺寸并居中内部 Logo（56px 让 Logo 更醒目） */
.avatar {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 头像图片：等比完整显示在头像容器内 */
.avatar-logo {
    width: 100%;
    height: 100%;
    object-fit: contain; /* 保持比例，不裁切 */
}

/* 头部主标题 */
.title h1 {
    font-size: 20px;
    font-weight: normal;
    letter-spacing: 0.2em; /* 宽字距，更显雅致 */
    margin-bottom: 4px;
}

/* 头部副标题（心灵伙伴）：小字号、略透明 */
.title p {
    font-size: 12px;
    opacity: 0.9;
    letter-spacing: 0.1em;
}

/* ==================== 消息区域 ==================== */
/* 消息列表：占据剩余高度并独立滚动，背景为米色渐变 */
.messages {
    flex: 1; /* 撑满头部与输入区之间的剩余空间 */
    overflow-y: auto; /* 消息过多时自身滚动 */
    padding: 20px;
    background: linear-gradient(to bottom, #faf8f5, #f5f0e8);
}

/* 自定义滚动条宽度（Chrome / Safari） */
.messages::-webkit-scrollbar {
    width: 6px;
}

/* 滚动条滑块：半透明棕色圆角条 */
.messages::-webkit-scrollbar-thumb {
    background: rgba(139, 69, 19, 0.3);
    border-radius: 3px;
}

/* 单条消息：底部留白，入场时淡入并轻微上移 */
.message {
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease; /* 引用 fadeIn 关键帧 */
}

/* 消息淡入动画：从透明+下方 10px 处淡入到位 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 用户消息：整体右对齐 */
.user-message {
    text-align: right;
}

/* 消息气泡通用样式：白底、圆角、轻微投影，支持 Markdown 内容换行 */
.message .content {
    display: inline-block;
    max-width: 100%;
    background: white;
    padding: 16px 20px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    line-height: 1.8; /* 行距宽松，便于阅读 */
    font-size: 18px;
    color: #3a3a3a;
    border: 1px solid rgba(139, 69, 19, 0.1);
    word-wrap: break-word; /* 长单词/链接换行 */
    overflow-wrap: break-word;
    text-align: left; /* 气泡内文字始终左对齐 */
}

/* 用户消息气泡：绿色渐变背景 + 白字，与机器人消息区分 */
.user-message .content {
    display: inline-block;
    background: linear-gradient(135deg, #4a7c59 0%, #5a8c69 100%);
    color: white;
    border: none;
    text-align: left;
}

/* 气泡内段落：去除默认外边距，由气泡统一控制间距 */
.message .content p {
    margin: 0;
}

/* ==================== 输入区域 ==================== */
/* 输入栏：横向排列输入框与发送按钮，顶部细分隔线 */
.input-container {
    display: flex;
    gap: 10px;
    padding: 16px;
    background: white;
    border-top: 1px solid rgba(139, 69, 19, 0.1);
}

/* 文本输入框：撑满剩余宽度，圆角药丸形，聚焦时有绿色描边与光晕 */
#userInput {
    flex: 1; /* 占据除按钮外的全部宽度 */
    padding: 12px 16px;
    border: 2px solid rgba(139, 69, 19, 0.2);
    border-radius: 24px;
    font-size: 18px;
    font-family: 'STKaiti', 'KaiTi', '楷体', serif; /* 与页面字体一致 */
    outline: none;
    transition: all 0.3s; /* 聚焦状态平滑过渡 */
    background: #faf8f5;
    color: #3a3a3a;
}

/* 输入框占位提示文字颜色 */
#userInput::placeholder {
    color: #999;
}

/* 输入框聚焦：边框转绿、背景变白并添加外发光 */
#userInput:focus {
    border-color: rgba(74, 124, 89, 0.6);
    background: white;
    box-shadow: 0 0 0 3px rgba(74, 124, 89, 0.1);
}

/* 发送按钮：绿色渐变、圆角药丸形，带投影 */
.send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #4a7c59 0%, #5a8c69 100%);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 18px;
    font-family: 'STKaiti', 'KaiTi', '楷体', serif;
    letter-spacing: 0.2em;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(74, 124, 89, 0.3);
}

/* 发送按钮悬停：上移并加深投影，模拟浮起效果 */
.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(74, 124, 89, 0.4);
}

/* 发送按钮按下：回到原位 */
.send-btn:active {
    transform: translateY(0);
}

/* 发送按钮禁用（如请求中）：降低透明度、禁用光标、取消位移 */
.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ==================== 加载气泡 ==================== */
/* “正在输入”气泡：淡绿底、圆角，内部横向排列三个跳动圆点 */
.loading-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(74, 124, 89, 0.1);
    border-radius: 16px;
}

/* 单个跳动圆点 */
.loading-bubble .bubble {
    width: 8px;
    height: 8px;
    background: rgba(74, 124, 89, 0.7);
    border-radius: 50%;
    animation: bubbleBounce 1.4s infinite ease-in-out both;
}

/* 三个圆点依次延迟，形成波浪式跳动节奏 */
.loading-bubble .bubble:nth-child(1) { animation-delay: -0.32s; }
.loading-bubble .bubble:nth-child(2) { animation-delay: -0.16s; }
.loading-bubble .bubble:nth-child(3) { animation-delay: 0s; }

/* 圆点跳动关键帧：在 40% 时放大到原尺寸并完全不透明 */
@keyframes bubbleBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==================== 返回按钮 ==================== */
/* 头部右上角的圆形返回按钮：半透明白底白边，层级高于装饰光斑 */
.back-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    z-index: 10; /* 确保可点击且位于最上层 */
    font-size: 18px;
}

/* 返回按钮悬停：背景变亮并轻微放大 */
.back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* ==================== Markdown 内容样式 ==================== */
/* 消息中的标题（h1~h3）：小字号棕色，与正文区分 */
.message .content h1,
.message .content h2,
.message .content h3 {
    font-size: 16px;
    margin: 12px 0 8px 0;
    color: rgba(139, 69, 19, 0.9);
}

/* 消息中的有序/无序列表 */
.message .content ul,
.message .content ol {
    margin: 8px 0;
    padding-left: 20px;
}

/* 列表项间距 */
.message .content li {
    margin: 4px 0;
}

/* 加粗文字：强调并加深颜色 */
.message .content strong {
    font-weight: bold;
    color: #3a3a3a;
}

/* 用户消息中的加粗文字：在绿底上使用白色 */
.user-message .content strong {
    color: white;
}

/* 行内代码：浅棕底、小字号圆角块 */
.message .content code {
    background: rgba(139, 69, 19, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

/* 代码块：浅灰底、圆角，超宽时横向滚动 */
.message .content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

/* 引用块：左侧棕色竖线 + 缩进 + 灰色文字 */
.message .content blockquote {
    border-left: 3px solid rgba(139, 69, 19, 0.8);
    padding-left: 12px;
    margin: 8px 0;
    color: #666;
}
