/* ============================================
   聊天组件统一样式库
   用于 main_dialogue.html 和 main_dialogue_liuyao.html
   ============================================ */

/* ============================================
   雷师傅头像组件
   ============================================ */
.leishifu-avatar {
    width: 128px;
    height: 128px;
    max-width: 50vw;
    max-height: 50vw;
    border-radius: 50%;
    background: #1c96f1;
    padding: 6px;
    box-shadow: 0 4px 12px rgba(28, 150, 241, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: inline-block;
}

.leishifu-avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(28, 150, 241, 0.4);
}

.leishifu-avatar-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.leishifu-avatar img {
    width: 108px;
    height: 108px;
    max-width: calc(50vw - 12px);
    max-height: calc(50vw - 12px);
    object-fit: cover;
    border-radius: 50%;
}

/* 小尺寸版本 - 用于消息气泡旁 */
.leishifu-avatar.small {
    width: 42px;
    height: 42px;
    padding: 0;
    box-shadow: none;
    background: transparent;
}

.leishifu-avatar.small img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border: 2px solid var(--primary);
    border-radius: 50%;
}

/* 大尺寸版本 - 用于空状态 */
.leishifu-avatar.large {
    width: 256px;
    height: 256px;
    max-width: 50vw;
    max-height: 50vw;
    padding: 12px;
}

.leishifu-avatar.large img {
    width: 216px;
    height: 216px;
    max-width: calc(50vw - 24px);
    max-height: calc(50vw - 24px);
}

/* ============================================
   消息包装器和头像
   ============================================ */
.message-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    margin-bottom: 16px;
}

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

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message-wrapper.user {
    justify-content: flex-end;
}

.message-wrapper.user .message-container {
    align-items: flex-end;
    flex-direction: row-reverse;
}

.message-wrapper.user .avatar {
    margin-left: 10px;
    margin-right: 0;
}

/* AI 消息：紧凑头部行（小头像 + 雷师傅）置于气泡上方，Claude 风格 */
.message-wrapper.ai {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.message-wrapper.ai .ai-header {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
}

.message-wrapper.ai .ai-header .ai-name {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    line-height: 1;
}

/* 头部行内的小头像覆盖默认 .avatar 尺寸 */
.message-wrapper.ai .ai-header .avatar.ai {
    width: 28px;
    height: 28px;
    margin-top: 0;
}

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    margin-top: 4px;
}

.avatar.ai {
    background: transparent;
    padding: 0;
    overflow: visible;
    box-shadow: none;
}

.avatar.ai img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: none;
}

/* ============================================
   消息容器和头部
   ============================================ */
.message-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 100%;
    min-width: 0;
}

/* AI 消息不显示头部信息（名称、时间） */
.message-wrapper.ai .message-header {
    display: none;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
}

.message-name {
    color: #374151;
    font-weight: 600;
    font-size: 14px;
}

.message-time {
    color: #9ca3af;
    font-size: 12px;
}

/* ============================================
   对话气泡系统
   ============================================ */
.msg {
    max-width: 100%;
    padding: 0;
    border-radius: 0;
    line-height: 1.8;
    /* 移除 white-space: pre-wrap，让渲染引擎生成的 HTML 正常渲染 */
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    font-size: 15px;
    transition: none;
    text-align: left;
    hyphens: auto;
    display: block;
    background: transparent;
}

/* 用户消息气泡 - 浅灰背景，右对齐，圆角 */
.message-wrapper.user .msg {
    background: #f5f5f5;
    color: #000000;
    border: none;
    border-radius: 18px;
    border-top-right-radius: 4px;
    padding: 2px 16px;
    max-width: 70%;
    align-self: auto;
    box-shadow: none;
    line-height: 1.6;
}

/* AI消息 - 无背景、无边框、无阴影，纯文本直接在页面上，豆包风格 */
.message-wrapper.ai .msg {
    background: transparent;
    color: var(--text-primary, #1f2937);
    border: none;
    box-shadow: none;
    max-width: 100%;
    align-self: auto;
    padding: 4px 0;
    line-height: 1.75;
    letter-spacing: 0;
    white-space: normal;
    font-size: 15px;
    /* AI 消息使用 normal，让 HTML 标签正常渲染换行 */
    word-break: normal;
    overflow-wrap: anywhere;
}

.msg:hover {
    box-shadow: none;
    transform: none;
}

/* ============================================
   Markdown 内容样式 - 对标豆包/通义千问风格
   优化点：
   1. 字号提升至 16px，行高 1.85，字间距 0.01em
   2. 段落间距 1.1em，首尾段落特殊处理
   3. 标题层级更清晰，h1/h2 显著区分
   4. 列表项目符号柔和化，缩进合理
   5. 引用块左侧条 + 浅色背景
   6. 代码样式精致化
   7. 加粗文字使用品牌色高亮
   ============================================ */

/* 一级标题 (H1) - 醒目，分割线 */
.msg h1 {
    font-size: 22px;
    margin-top: 1.6em;
    margin-bottom: 0.7em;
    font-weight: 700;
    color: #111827;
    line-height: 1.4;
    letter-spacing: 0.01em;
}

.msg h1.md-h1 {
    color: #111827;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 0.3em;
}

/* 二级标题 (H2) - 蓝色左条 + 主题色，豆包风格 */
.msg h2 {
    font-size: 18px;
    margin-top: 1.6em;
    margin-bottom: 0.6em;
    font-weight: 600;
    color: var(--primary);
    line-height: 1.5;
    padding-left: 12px;
    border-left: 4px solid var(--primary);
    letter-spacing: 0.01em;
}

.msg h2::before {
    content: '';
    /* CSS 伪元素已用 border-left 实现，不重复添加 */
}

/* 三级标题 (H3) - 豆包原生章节标题：深灰文字 + 极细品牌色左条 + 无下分隔线
   核心理念：靠加粗与上间距分章节，不用色块、不用分隔线，长文阅读最克制 */
.msg h3 {
    font-size: 16px;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    padding-left: 10px;
    padding-bottom: 0;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.5;
    border-left: 3px solid var(--primary);
    border-bottom: none;
    letter-spacing: 0;
}

.msg h3+p,
.msg h3+ul,
.msg h3+ol,
.msg h3+blockquote,
.msg h3+.md-record-list {
    margin-top: 0.5em;
}

.msg h4 {
    font-size: 15px;
    margin-top: 1em;
    margin-bottom: 0.4em;
    font-weight: 600;
    color: #374151;
    line-height: 1.5;
}

.msg h5,
.msg h6 {
    font-size: 14px;
    margin-top: 0.8em;
    margin-bottom: 0.3em;
    font-weight: 600;
    color: #4b5563;
    line-height: 1.4;
}

/* 标题前的标题元素（紧邻）应减少上边距 */
.msg h1:first-child,
.msg h2:first-child,
.msg h3:first-child,
.msg h4:first-child,
.msg h5:first-child,
.msg h6:first-child {
    margin-top: 0.2em;
}

.msg .section-title {
    color: var(--primary);
    border-left: 4px solid var(--primary);
    padding-left: 12px;
    border-bottom: none;
}

/* 段落 - 豆包原生：15px、行高 1.75、段距 0.8em */
.msg p {
    margin-top: 0;
    margin-bottom: 0.8em;
    line-height: 1.75;
    letter-spacing: 0;
    text-align: left;
    word-break: normal;
    overflow-wrap: break-word;
    color: #1f2937;
}

/* 第一个段落不需要上边距 */
.msg>p:first-child {
    margin-top: 0;
}

/* 最后一个段落不需要下边距 */
.msg>p:last-child {
    margin-bottom: 0;
}

/* 列表 - 豆包原生：行高 1.7，序号灰色，紧凑型 */
.msg ul,
.msg ol {
    margin-top: 0.4em;
    margin-bottom: 0.8em;
    padding-left: 0;
    list-style-position: inside;
    white-space: normal;
}

.msg li {
    margin: 0.3em 0;
    padding-left: 0;
    line-height: 1.7;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
    color: #1f2937;
    text-indent: 0;
}

.msg li:first-child {
    margin-top: 0.2em;
}

.msg li:last-child {
    margin-bottom: 0.2em;
}

/* 嵌套列表保留少量缩进以体现层级 */
.msg li>ul,
.msg li>ol {
    margin-top: 0.3em;
    margin-bottom: 0.3em;
    padding-left: 1.2em;
    list-style-position: outside;
}

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

.msg ul li::marker {
    color: #9ca3af;
    font-size: 0.85em;
}

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

.msg ol li::marker {
    color: #9ca3af;
    font-weight: 500;
}

/* 加粗文本 - 豆包风格：使用品牌色高亮，柔和不刺眼 */
.msg strong {
    font-weight: 600;
    color: var(--primary);
    background: linear-gradient(180deg, transparent 60%, rgba(30, 159, 255, 0.12) 60%);
    padding: 0 1px;
}

.msg em {
    font-style: italic;
    color: #4b5563;
}

/* 行内代码 - 浅色背景，圆角，柔和字体 */
.msg code {
    background: rgba(30, 159, 255, 0.08);
    padding: 2px 7px;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9em;
    color: #c7254e;
    word-break: break-all;
    margin: 0 2px;
}

/* 代码块 - 浅灰背景，圆角边框 */
.msg pre {
    background: #f6f8fa;
    padding: 16px 18px;
    border-radius: 10px;
    overflow-x: auto;
    margin-top: 1em;
    margin-bottom: 1.1em;
    border: 1px solid #e1e4e8;
    line-height: 1.7;
    font-size: 14px;
}

.msg pre code {
    background: none;
    padding: 0;
    color: #24292e;
    font-size: 13px;
    line-height: 1.7;
    word-break: normal;
}

/* 引用块 - 豆包原生：浅灰背景 + 灰色左条，弱化色彩，强调文本 */
.msg blockquote {
    border-left: 3px solid #d0d0d0;
    padding: 10px 14px;
    margin-top: 0.8em;
    margin-bottom: 0.8em;
    color: #4b5563;
    background: #f6f6f6;
    border-radius: 0 6px 6px 0;
    font-style: normal;
    line-height: 1.75;
}

/* 链接 - 豆包原生：品牌蓝、不带下划线，hover 显下划线 */
.msg a {
    color: var(--primary);
    text-decoration: none;
    transition: text-decoration 0.15s ease;
}

.msg a:hover {
    text-decoration: underline;
}

.msg blockquote p {
    text-indent: 0;
    margin: 0.4em 0;
    color: inherit;
}

.msg blockquote p:first-child {
    margin-top: 0;
}

.msg blockquote p:last-child {
    margin-bottom: 0;
}

/* 水平分割线 - 豆包风格：渐变中部 */
.msg hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, #d1d5db, transparent);
    margin-top: 1.8em;
    margin-bottom: 1.8em;
}

/* 表格 - 豆包风格：圆角+斑马纹+列对齐+水平滚动+响应式 */
.msg .table-wrapper {
    width: 100%;
    margin: 1.2em 0 1.3em;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    background: #ffffff;
}

.msg .markdown-table,
.msg table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-size: 14px;
    table-layout: auto;
}

.msg .markdown-table thead,
.msg table thead {
    background: linear-gradient(180deg, #f3f6fa 0%, #eef2f7 100%);
}

.msg .markdown-table th,
.msg table th {
    padding: 12px 16px;
    font-weight: 600;
    color: #1f2937;
    text-align: left;
    line-height: 1.5;
    border-bottom: 2px solid var(--primary);
    white-space: nowrap;
    background: transparent;
}

.msg .markdown-table th[style*="text-align:center"],
.msg table th[style*="text-align:center"] {
    text-align: center;
}

.msg .markdown-table th[style*="text-align:right"],
.msg table th[style*="text-align:right"] {
    text-align: right;
}

.msg .markdown-table td,
.msg table td {
    padding: 11px 16px;
    color: #1f2937;
    line-height: 1.65;
    border-bottom: 1px solid #eef0f3;
    word-break: break-word;
    vertical-align: top;
}

.msg .markdown-table td[style*="text-align:center"],
.msg table td[style*="text-align:center"] {
    text-align: center;
}

.msg .markdown-table td[style*="text-align:right"],
.msg table td[style*="text-align:right"] {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.msg .markdown-table tbody tr,
.msg table tbody tr {
    transition: background-color 0.18s ease;
}

.msg .markdown-table tbody tr:nth-child(even),
.msg table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.msg .markdown-table tbody tr:hover,
.msg table tbody tr:hover {
    background: rgba(30, 159, 255, 0.05);
}

.msg .markdown-table tbody tr:last-child td,
.msg table tbody tr:last-child td {
    border-bottom: none;
}

/* 表格单元格内的粗体/代码样式 */
.msg .markdown-table strong,
.msg table strong {
    color: var(--primary);
    font-weight: 600;
}

.msg .markdown-table code,
.msg table code {
    background: rgba(30, 159, 255, 0.08);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    color: #c7254e;
}

/* 窄屏：表格横向滚动，避免内容挤压 */
@media (max-width: 767px) {
    .msg .table-wrapper {
        margin: 1em 0;
        border-radius: 8px;
        /* 横向溢出滚动 */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .msg .markdown-table,
    .msg table {
        min-width: 100%;
        font-size: 13px;
    }

    .msg .markdown-table th,
    .msg .markdown-table td,
    .msg table th,
    .msg table td {
        padding: 9px 12px;
        white-space: nowrap;
    }

    /* 手机端：阻止 nowrap，让单元格自然换行 */
    .msg .markdown-table td,
    .msg table td {
        white-space: normal;
    }
}

/* ============================================
   定义列表（替代 markdown 表格）
   每条记录使用 <dl class="md-record"><dt><dd>...</dl>，
   多条记录由 .md-record-list 包裹。
   视觉对标 main_qa_hexagram 最佳排版：
     - 不使用卡片背景 / 边框 / 左条，避免长文中产生"块状感"
     - 仅靠 加粗主色键名 + 冒号 + 正文 形成轻量层级
     - 与正文段落同字号、同行距、同颜色，融入整段
   ============================================ */
.msg .md-record-list {
    margin: 0.6em 0 1.1em;
    display: flex;
    flex-direction: column;
    gap: 0.3em;
}

.msg .md-record {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    display: block;
    line-height: 1.75;
    color: #1f2937;
    font-size: 15px;
    text-align: left;
}

.msg .md-record-key {
    display: inline;
    margin: 0;
    font-weight: 600;
    color: var(--primary);
    font-size: inherit;
    background: linear-gradient(180deg, transparent 60%, rgba(30, 159, 255, 0.12) 60%);
    padding: 0 1px;
}

.msg .md-record-key::after {
    content: '：';
    color: #1f2937;
    margin-left: 0;
    font-weight: 400;
    background: transparent;
}

.msg .md-record-val {
    display: inline;
    margin: 0;
    color: inherit;
    font-size: inherit;
    word-break: normal;
    overflow-wrap: break-word;
}

/* 在同一行显示一对键值后，下一对自动换行（用 ::after 触发块级断行） */
.msg .md-record-val::after {
    content: '';
    display: block;
}

.msg .md-record-val strong {
    color: var(--primary);
    background: linear-gradient(180deg, transparent 60%, rgba(30, 159, 255, 0.12) 60%);
    padding: 0 1px;
}

/* 仅表头无数据的情况：以无背景的标签条呈现，避免突兀 */
.msg .md-record-list--headers-only {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4em 0.8em;
    padding: 0;
    background: transparent;
    border: none;
    margin: 0.4em 0 1em;
}

.msg .md-tag {
    display: inline;
    padding: 0;
    background: transparent;
    color: var(--primary);
    border-radius: 0;
    font-size: inherit;
    font-weight: 600;
}

.msg .md-tag+.md-tag::before {
    content: ' · ';
    color: #9ca3af;
    margin: 0 0.15em;
    font-weight: 400;
}

/* 窄屏：保持纯文本流式排版，不再做特殊网格 */
@media (max-width: 767px) {
    .msg .md-record {
        font-size: 15px;
        line-height: 1.8;
    }
}

/* ============================================
   消息操作按钮组
   ============================================ */
.message-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.message-wrapper:hover .message-actions {
    opacity: 0.7;
}

.message-wrapper:hover .message-actions:hover {
    opacity: 1;
}

.action-btn {
    padding: 4px 6px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.action-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.action-btn.active.like {
    color: #10b981;
}

.action-btn.active.dislike {
    color: #ef4444;
}

.feedback-divider {
    width: 1px;
    height: 16px;
    background: #e5e7eb;
    margin: 0 4px;
}

/* ============================================
   打字指示器（思考中动画）
   ============================================ */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
}

.typing-text {
    font-size: 15px;
    color: #6b7280;
    font-style: italic;
}

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

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingBounce {

    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: scale(0.8);
    }

    30% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* 六爻页面使用的思考动画 */
.thinking-animation {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    animation: messageSlideIn 0.3s ease-out;
    max-width: fit-content;
}

.thinking-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.thinking-text {
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 2px;
}

.thinking-dots {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    background: var(--bg-light);
    border-radius: 12px;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.thinking-dots .dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: thinkingBounce 1.4s infinite ease-in-out both;
}

.thinking-dots .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dots .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.thinking-dots .dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes thinkingBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* ============================================
   打字光标动画
   ============================================ */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--primary);
    margin-left: 2px;
    animation: cursorBlink 1s step-end infinite;
    vertical-align: text-bottom;
}

@keyframes cursorBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* ============================================
   纠错反馈面板
   ============================================ */
.correction-panel {
    margin-top: 10px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.correction-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.correction-title {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.correction-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 4px;
}

.correction-close svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

.correction-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    color: #374151;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s ease;
    font-family: inherit;
}

.correction-textarea:focus {
    border-color: var(--primary);
}

.correction-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.correction-btn {
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.correction-btn-cancel {
    background: #f3f4f6;
    color: #6b7280;
    border-color: #e5e7eb;
}

.correction-btn-cancel:hover {
    background: #e5e7eb;
}

.correction-btn-submit {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.correction-btn-submit:hover {
    box-shadow: 0 4px 12px rgba(30, 159, 255, 0.25);
    transform: translateY(-1px);
}

.correction-btn-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ============================================
   Toast 提示
   ============================================ */
.feedback-toast,
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
    color: white;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.feedback-toast.show,
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   回到顶部按钮
   ============================================ */
.back-to-top {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-normal);
    z-index: 100;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.back-to-top svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
    fill: none;
    stroke-width: 2;
}

/* ============================================
   重置动画
   ============================================ */
@keyframes fadeOutMessage {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.message-wrapper.resetting {
    animation: fadeOutMessage 0.3s ease-out forwards;
}

@keyframes resetFlash {
    0% {
        background-color: transparent;
    }

    30% {
        background-color: #f6ffed;
    }

    100% {
        background-color: transparent;
    }
}

.chat-scroll.reset-complete {
    animation: resetFlash 0.8s ease-out;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   响应式设计 - 平板
   ============================================ */
@media (max-width: 1023px) {
    .message-wrapper {
        gap: 12px;
    }

    .avatar {
        width: 46px;
        height: 46px;
    }

    .msg {
        padding: 12px 16px;
    }
}

/* ============================================
   响应式设计 - 手机
   ============================================ */
@media (max-width: 767px) {
    .message-wrapper {
        gap: 10px;
    }

    .avatar {
        width: 42px;
        height: 42px;
        border-radius: 10px;
    }

    .avatar svg {
        width: 18px;
        height: 18px;
    }

    .msg {
        max-width: 85%;
        font-size: 15px;
        line-height: 1.75;
        padding: 12px 14px;
    }

    .message-wrapper.ai .msg {
        font-size: 15px;
        line-height: 1.75;
        padding: 4px 0;
    }

    .message-wrapper.user .msg {
        max-width: 70%;
    }

    .message-container {
        max-width: 85%;
    }

    .message-header {
        gap: 6px;
    }

    .message-name {
        font-size: 13px;
    }

    .message-time {
        font-size: 11px;
    }

    /* 移动端：标题字号缩小 */
    .msg h1 {
        font-size: 19px;
        margin-top: 1.3em;
        margin-bottom: 0.6em;
    }

    .msg h2 {
        font-size: 16px;
        margin-top: 1.3em;
        margin-bottom: 0.5em;
        padding-left: 10px;
    }

    .msg h3 {
        font-size: 15px;
        margin-top: 1.1em;
    }

    /* 移动端：段落间距 */
    .msg p {
        margin-bottom: 0.9em;
        line-height: 1.75;
    }

    .msg ul,
    .msg ol {
        padding-left: 0;
    }

    /* 移动端始终显示操作按钮 */
    .message-actions {
        opacity: 1;
    }

    .back-to-top {
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        right: 12px;
        width: 36px;
        height: 36px;
    }
}

/* ============================================
   响应式设计 - 小屏手机
   ============================================ */
@media (max-width: 767px) {
    .msg {
        max-width: 95%;
        font-size: 14px;
        padding: 10px 14px;
    }

    .message-wrapper.ai .msg {
        font-size: 14px;
        line-height: 1.7;
    }

    .message-container {
        max-width: 95%;
    }

    .avatar {
        width: 38px;
        height: 38px;
        border-radius: 8px;
    }

    .avatar svg {
        width: 16px;
        height: 16px;
    }

    .message-header {
        gap: 4px;
    }

    .message-name {
        font-size: 12px;
    }

    .message-time {
        font-size: 10px;
    }

    .action-btn svg {
        width: 14px;
        height: 14px;
    }

    /* 小屏：标题字号进一步缩小 */
    .msg h1 {
        font-size: 18px;
    }

    .msg h2 {
        font-size: 15px;
        padding-left: 8px;
        border-left-width: 3px;
    }

    .msg h3 {
        font-size: 14px;
    }
}

/* ============================================
   iPhone 刘海屏安全区域适配
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
    .back-to-top {
        bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    }
}