:root {
    --primary-color: #f97316;         /* 主色调：温暖的橙色 */
    --primary-hover: #ea580c;         /* 悬停加深：落日橙 */
    --primary-light: #fff7ed;         /* 极浅暖杏色（激活背景） */
    --primary-border: #ffedd5;        /* 浅暖橙边框 */
    --primary-gradient: #fafaf9; /* linear-gradient(135deg, #f97316, #fdba74); */
    --primary-shadow: rgba(249, 115, 22, 0.15);
    --primary-shadow-hover: rgba(249, 115, 22, 0.3);

    /* 基础背景色：极简暖白与浅沙灰 */
    --bg-main: #fafaf9;               /* 微微带暖的主背景 */
    --bg-sidebar: #ffffff;            /* 侧边栏纯白 */
    --bg-chat-user: #ffffff;
    --bg-chat-assistant: #ffffff;     /* AI 气泡纯白 */

    /* 文字颜色 */
    --text-dark: #1c1917;             /* 极深暖灰（比纯黑更柔和） */
    --text-muted: #44403c;            /* 中深暖灰 */
    --text-light: #78716c;            /* 浅石灰 */
    
    /* 辅助色 */
    --border-color: #e7e5e4;          /* 暖调边框线 */
    --danger-color: #ef4444;          /* 红色保留 */
    --danger-hover: #dc2626;
}

@font-face {
    font-family: zt;
    src: url('/zt.woff2');
}

* {
    font-family: zt, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-color: var(--bg-main);
    overflow: hidden;
}

/* 侧边栏及布局结构 */
.app-layout {
    display: flex;
    /* 1. 保留 100vh 作为不支持 dvh 的老旧设备回退方案 */
    height: 100vh; 
    /* 2. 使用 100dvh，它会根据工具栏的显示/隐藏动态调整，完美适配移动端 */
    height: 100dvh; 
    width: 100vw;
    padding-top: 0;
    position: relative;
}
/* 左侧栏样式 */
.sidebar-aside {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 16px;
    flex-shrink: 0;
    z-index: 10;
    transition: transform 0.3s ease;
}

.new-chat-btn,
.sidebar-console-link {
    width: 100%;
    padding: 12px;
    background: var(--primary-gradient);
    border: none;
    border-radius: 60px;
    color: var(--text-dark);
    font-size: 14px;
    font-weight: bold;
    line-height: 20px;
    text-decoration: none;
    cursor: pointer;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    margin-bottom: 20px;
}

.new-chat-btn:hover,
.sidebar-console-link:hover {
    background-color: #f1f5f9;
}

.sidebar-console-link {
    margin-bottom: 8px;
}

.new-chat-btn:focus-visible,
.sidebar-console-link:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.history-list-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-heading {
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-heading .history-toggle-btn {
    flex: 1;
}

.history-refresh-btn {
    width: 32px;
    height: 32px;
    margin-bottom: 8px;
    padding: 7px;
    border: none;
    border-radius: 6px;
    color: var(--text-light);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-refresh-btn svg {
    width: 16px;
    height: 16px;
}

.history-refresh-btn:hover:not(:disabled) {
    color: var(--primary-color);
    background: var(--primary-light);
}

.history-refresh-btn:disabled {
    cursor: wait;
}

.history-refresh-btn.is-loading svg {
    animation: history-refresh-spin 0.8s linear infinite;
}

@keyframes history-refresh-spin {
    to { transform: rotate(360deg); }
}

.history-manage-btn {
    margin-bottom: 8px;
    padding: 7px 8px;
    border: none;
    border-radius: 6px;
    color: var(--text-light);
    background: transparent;
    font-size: 12px;
    cursor: pointer;
}

.history-manage-btn:hover {
    color: var(--primary-color);
    background: var(--primary-light);
}

.history-batch-toolbar {
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
}

.history-select-all {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.history-select-all input,
.history-select-checkbox {
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--primary-color);
    cursor: pointer;
    flex-shrink: 0;
}

.history-select-checkbox {
    display: none;
    margin-right: 8px;
}

.history-item.batch-mode .history-select-checkbox {
    display: block;
}

.history-item.batch-mode .history-icon,
.history-item.batch-mode .history-delete-btn,
.history-item.batch-mode .history-rename-btn {
    display: none;
}

.history-item.selected {
    background-color: var(--primary-light);
    border-color: var(--primary-border);
    color: var(--text-dark);
}

.history-batch-actions {
    display: flex;
    gap: 4px;
}

.history-batch-cancel,
.history-batch-delete {
    padding: 5px 7px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 12px;
    cursor: pointer;
}

.history-batch-cancel {
    color: var(--text-muted);
}

.history-batch-delete {
    color: #ffffff;
    background: var(--danger-color);
}

.history-batch-delete:hover:not(:disabled) {
    background: var(--danger-hover);
}

.history-batch-delete:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* 历史卡片设计 */
.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 60px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    border: 1px solid transparent;
    color: var(--text-muted);
    text-decoration: none; /* 新增：清除超链接下划线 */
}

.history-item:hover {
    background-color: #f1f5f9;
    color: var(--text-dark);
}

.history-item.active {
    background-color: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-border);
    font-weight: bold;
}

.history-icon {
    display: flex;
    align-items: center;
    margin-right: 10px;
    opacity: 0.7;
    flex-shrink: 0;
}

.history-title {
    flex: 1;
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 10px;
}

.history-delete-btn, .history-rename-btn {
    opacity: 0;
    background: none;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.history-delete-btn {
    color: var(--danger-color);
    font-size: 18px;
    line-height: 1;
}

.history-rename-btn {
    color: var(--text-light);
}

.history-rename-btn:hover {
    color: var(--primary-color);
}

.history-item:hover .history-delete-btn,
.history-item:hover .history-rename-btn {
    opacity: 1;
}

.no-history-tip, .history-loading {
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
    margin-top: 30px;
}

/* 右侧核心聊天区域 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-main);
    position: relative;
    height: 100%;
    overflow: hidden;
}

/* 手机端及标题栏 */
.chat-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    height: 52px;
}

.sidebar-toggle-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
}

.header-chat-title-container {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 60%;
    overflow: hidden;
}

.header-chat-title {
    font-size: 15px;
    font-weight: bold;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.header-action-btn:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.header-right-actions {
    display: flex;
    align-items: center;
}

.header-share-btn {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    background-color: transparent;
    border-radius: 60px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
}

.header-share-btn:hover {
    background-color: var(--primary-color);
    color: #ffffff;
}

.button-choice-header {
    padding: 6px 12px;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    background-color: transparent;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
}

.button-choice-header:hover {
    background-color: var(--primary-color);
    color: #ffffff;
}

/* 聊天滚动区 */
.chat-box-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.chat-box {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-bottom: 40px;
}

/* 欢迎页 */
.welcome-box {
    text-align: center;
    margin: auto;
    padding: 40px 20px;
    max-width: 500px;
    color: var(--text-muted);
}

.welcome-box h2 {
    color: var(--primary-color);
    margin-bottom: 12px;
}

.welcome-box p {
    font-size: 14px;
    line-height: 1.6;
}

/* 聊天气泡样式优化 */
.chat-user-bubble-container {
    display: flex;
    justify-content: flex-end;
}
.user-text-display {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.5;
}
.chat-user {
    max-width: 85%;
    min-width: 50px;
    background: var(--bg-chat-user);
    border-radius: 16px 16px 4px 16px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
}


.user-text-area {
    width: 100%;
    min-width: 250px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-bottom: 1px dashed #fff;
    color: #000;
    resize: vertical;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    font-family: inherit;
    border-radius: 4px 4px 0 0;
    padding: 4px;
}

.chat-content-markdown {
    align-self: flex-start;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    background-color: var(--bg-chat-assistant);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px 28px;
    font-family: "Times New Roman", "Songti SC", SimSun, "Noto Serif CJK SC", serif;
    font-size: 16px;
    line-height: 1.75;
    color: #333;
    overflow-wrap: anywhere;
}

.chat-content-markdown.is-collapsed,
.user-text-display.is-collapsed {
    max-height: 50px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 24px), transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 24px), transparent 100%);
}

/* 思考链标题与文本 */
.think {
    align-self: flex-start;
    padding: 6px 12px;
    border-radius: 16px;
    background-color: #f1f5f9;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.think:hover {
    background-color: #e2e8f0;
}

.chat-think {
    align-self: flex-start;
    width: 90%;
    border-left: 3px solid #cbd5e1;
    background-color: #f8fafc;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
    padding: 8px 12px;
    border-radius: 0 8px 8px 0;
    resize: none;
    overflow: hidden;
    border-top: none; border-right: none; border-bottom: none;
    outline: none;
}

.tool-call-wrapper {
    align-items: flex-start;
}

.tool-call {
    width: min(100%, 760px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

.tool-call-summary {
    min-height: 42px;
    padding: 9px 11px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    user-select: none;
}

.tool-call-summary::-webkit-details-marker {
    display: none;
}

.tool-call-summary::marker {
    content: '';
}

.tool-call-summary:hover {
    background: #f8fafc;
}

.tool-call-icon {
    flex: 0 0 auto;
    color: #2563eb;
}

.tool-call-name {
    min-width: 0;
    flex: 0 0 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 600;
    color: var(--text-dark);
}

.tool-call-status {
    margin-left: auto;
    flex: 0 0 auto;
    color: #15803d;
    font-size: 12px;
}

.tool-call-chevron {
    flex: 0 0 auto;
    transition: transform 0.18s ease;
}

.tool-call-trace {
    min-width: 0;
    flex: 1 1 auto;
    padding-left: 4px;
    overflow: hidden;
    color: var(--text-muted);
    font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tool-call[open] .tool-call-chevron {
    transform: rotate(90deg);
}

.tool-call-body {
    border-top: 1px solid var(--border-color);
    background: #f8fafc;
}

.tool-call-field {
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
}

.tool-call-field:first-child {
    border-top: 0;
}

.tool-call-field-label {
    margin-bottom: 5px;
    color: var(--text-light);
    font-size: 11px;
    font-weight: 600;
}

.tool-call-field-content {
    max-height: 320px;
    margin: 0;
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--text-dark);
    font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.contentcalc {
    align-self: flex-start;
    font-size: 12px;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 15px;
}

.token-stats-item {
    font-size: 11px;
    color: var(--text-light);
}

/* 复制按钮 */
.action-bar {
    display: flex;
}

.copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.2s;
}

.copy-btn:hover {
    background-color: #f1f5f9;
    color: var(--text-dark);
}

.request-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
}

.request-settings-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.request-settings-btn:hover {
    color: var(--primary-color);
    background: var(--primary-light);
    border-color: var(--primary-border);
}

.request-settings-popover {
    display: none;
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    width: max-content;
    min-width: 208px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    z-index: 20;
}

.request-settings-popover.active {
    display: block;
}

.request-settings-popover label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 12px;
}

.max-tokens-presets {
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}

.max-tokens-label {
    margin-right: 3px;
    color: var(--text-light);
    font-size: 11px;
}

.max-tokens-option,
.max-tokens-back {
    padding: 5px 7px;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
    font-size: 12px;
}

.max-tokens-option:hover,
.max-tokens-option.active {
    color: var(--primary-color);
    background: var(--primary-light);
    border-color: var(--primary-border);
}

.max-tokens-custom {
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    color: var(--text-light);
    font-size: 11px;
}

.max-tokens-back {
    padding: 1px 5px;
    font-size: 18px;
    line-height: 1;
}

.max-tokens-back:hover {
    color: var(--primary-color);
    background: var(--primary-light);
}

.max-tokens-custom input {
    width: 92px;
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    color: var(--text-dark);
    font-size: 12px;
}

/* 底部输入框区域 */
.bottom-area {
    background: linear-gradient(to top, var(--bg-main) 80%, rgba(247,249,251,0));
    padding: 10px 20px 20px 20px;
}

.model-compatibility-warning {
    max-width: 1100px;
    margin: 0 auto 12px;
    padding: 10px 14px;
    border: 1px solid var(--primary-border);
    border-radius: 8px;
    background-color: var(--primary-light);
    color: #9a3412;
    font-size: 13px;
    line-height: 1.5;
}

.input-wrap-box {
    max-width: 1100px;
    margin: 0 auto;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.04);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: border-color 0.15s, box-shadow 0.15s;
}

/* 拖拽文件悬停在输入框上时的高亮态 */
.input-wrap-box.drag-over {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-shadow), 0 4px 16px rgba(0,0,0,0.04);
}

.input-wrap-box .drag-overlay {
    display: none;
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background-color: var(--primary-light);
    border: 2px dashed var(--primary-color);
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 600;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
}

.input-wrap-box.drag-over .drag-overlay {
    display: flex;
}

.gpt-input {
    width: 100%;
    height: 70px;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    color: var(--text-dark);
    line-height: 1.5;
}

.control-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #f1f5f9;
    padding-top: 8px;
    margin-top: 4px;
}

.word-count {
    font-size: 12px;
    color: var(--text-light);
}

.button-gpt {
    padding: 8px 16px;
    background-color: var(--primary-color);
    color: #ffffff;
    border: none;
    border-radius: 60px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
}

.button-gpt:hover {
    background-color: var(--primary-hover);
}

.button-gpt:disabled {
    background-color: #cbd5e1 !important;
    cursor: not-allowed;
}

/* 弹窗设计 */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: #ffffff;
    margin: 12% auto;
    padding: 24px;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.modal-title {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.close {
    float: right;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-light);
}

.close:hover {
    color: var(--text-dark);
}


/* 弹窗中的标签列表 */
.ai-container div {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 10px 0;
}

.ai-container div li {
    list-style: none;
    border-radius: 20px;
    border: 1px solid #cbd5e1;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    background-color: #f8fafc;
    transition: all 0.2s;
}

.ai-container div li:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background-color: var(--primary-light);
    transform: translateY(-1px);
}

/* 文档式阅读排版。低优先级继承覆盖站点通用字体，保留 KaTeX 自身的字体规则。 */
:where(.chat-content-markdown *) {
    font-family: inherit;
}

.chat-content-markdown :is(h1, h2, h3, h4, h5, h6) {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: #333;
    font-weight: 700;
    line-height: 1.35;
    margin: 1em 0 0.65em;
}

.chat-content-markdown h1 { font-size: 1.6em; }
.chat-content-markdown h2 { font-size: 1.45em; }
.chat-content-markdown h3 { font-size: 1.3em; }
.chat-content-markdown h4 { font-size: 1.15em; }
.chat-content-markdown h5 { font-size: 1em; }
.chat-content-markdown h6 { font-size: 0.9em; color: #777; }

.chat-content-markdown :is(h1, h2) {
    padding-bottom: 0.3em;
    border-bottom: 1px solid #e5e5e5;
}

.chat-content-markdown > :first-child { margin-top: 0; }
.chat-content-markdown > :last-child { margin-bottom: 0; }

.chat-content-markdown p {
    margin: 0.85em 0;
}

.chat-content-markdown :is(ul, ol) {
    margin: 0.75em 0;
    padding-left: 2em;
}

.chat-content-markdown li + li {
    margin-top: 0.35em;
}

.chat-content-markdown li > :is(ul, ol, p) {
    margin-top: 0.4em;
    margin-bottom: 0.4em;
}

.chat-content-markdown strong {
    font-weight: 700;
}

.chat-content-markdown hr {
    height: 0;
    margin: 1.25em 0;
    border: 0;
    border-top: 1px solid #ddd;
}

.chat-content-markdown blockquote {
    margin: 1em 0;
    padding: 0 1em;
    border-left: 4px solid #ddd;
    color: #666;
}

.chat-content-markdown a {
    color: #4183c4;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-content-markdown img {
    max-width: 100%;
    height: auto;
}

.chat-content-markdown table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    margin: 1em 0;
    border-collapse: collapse;
    border-spacing: 0;
}

.chat-content-markdown :is(th, td) {
    padding: 6px 13px;
    border: 1px solid #ddd;
}

.chat-content-markdown th {
    font-weight: 700;
    background: #f6f8fa;
}

.chat-content-markdown tr:nth-child(even) {
    background: #fafafa;
}

.chat-content-markdown .katex {
    font-size: 1.1em;
    overflow-wrap: normal;
}

.chat-content-markdown .katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 1em 0;
    padding: 0.25em 0;
}

.chat-content-markdown .katex-error {
    white-space: pre-wrap;
}

.chat-content-markdown pre {
    margin: 1em 0;
    background-color: #f6f8fa;
    border-radius: 4px;
    padding: 14px 16px;
    overflow-x: auto;
    border: 1px solid #e7e7e7;
    line-height: 1.5;
    overflow-wrap: normal;
}

.chat-content-markdown code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    background-color: #f3f4f4;
    padding: 0.15em 0.35em;
    border-radius: 3px;
    font-size: 0.9em;
}

.chat-content-markdown pre code {
    background: none;
    padding: 0;
}

/* Loading 动画 */
.loading_svg {
    width: 24px;
    height: 24px;
    animation: rotate 2s linear infinite;
}

.loading_circle {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 4;
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes rotate { 100% { transform: rotate(360deg); } }
@keyframes dash {
    0% { stroke-dasharray: 1, 200; stroke-dashoffset: 0; }
    50% { stroke-dasharray: 89, 200; stroke-dashoffset: -35px; }
    100% { stroke-dasharray: 89, 200; stroke-dashoffset: -124px; }
}

/* 响应式媒体查询：移动端折叠逻辑 */
@media (max-width: 768px) {
    .sidebar-aside {
        position: fixed;
        left: 0;
        top: 60px;
        bottom: 0;
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    }

    .sidebar-aside.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0,0,0,0.4);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .sidebar-toggle-btn {
        display: block;
    }

    .chat-content-markdown {
        max-width: 100%;
        padding: 18px 16px;
    }

    .chat-content-markdown :is(ul, ol) {
        padding-left: 1.5em;
    }
}
/* --- 新增：历史记录折叠区样式 --- */
.history-toggle-btn {
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.2s;
    margin-bottom: 8px;
}

.history-toggle-btn:hover {
    background-color: #f1f5f9;
}

.history-toggle-icon {
    transition: transform 0.3s ease;
}

/* 历史列表默认隐藏，由 JS 控制展开 */
.history-list-container {
    display: none; 
}

/* --- 新增：消息编辑与删除样式 --- */
.chat-message-wrapper {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
}

.user-actions {
    justify-content: flex-end;
    margin-top: 4px;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}
.chat-message-wrapper:hover .user-actions {
    opacity: 1;
}

/* AI 回复的编辑框 */
.assistant-edit-area {
    width: 100%;
    min-height: 100px;
    border: 1px solid var(--primary-color);
    border-radius: 8px;
    padding: 12px;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--text-dark);
    background-color: #fcfcfd;
    outline: none;
    resize: vertical;
    font-family: inherit;
    margin-bottom: 8px;
}

/* 用户气泡编辑状态 */
.user-text-area:not([readonly]) {
    background-color: rgba(255, 255, 255, 0.2);
    border-bottom: 1px dashed #fff;
}

/* 侧边栏 Logo 样式 */
.sidebar-logo {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0 20px 0;
    border-bottom: 1px solid #edf2f7;
    margin-bottom: 20px;
}

.sidebar-logo-img {
    max-width: 100%;
    height: auto;
    max-height: 40px;
    object-fit: contain;
}

/* 侧边栏底部整合区域 */
.sidebar-footer {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid #edf2f7;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 用户信息及登录模块 */
.user-section {
    display: flex;
    flex-direction: column;
}

.login-link {
    display: block;
    text-align: center;
    padding: 8px;
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: bold;
    transition: all 0.2s;
}

.login-link:hover {
    background-color: #f1f5f9;
    color: var(--text-dark);
}

.user-container {
    display: flex;
    flex-direction: column;
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 8px 10px;
}

.user-name {
    font-size: 13.5px;
    font-weight: bold;
    color: var(--text-muted);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.user-menu {
    display: flex;
    justify-content: space-around;
    border-top: 1px dashed var(--border-color);
    padding-top: 6px;
    margin-top: 4px;
}

.user-menu-item {
    font-size: 11px;
    color: var(--text-light);
    text-decoration: none;
    transition: color 0.2s;
}

.user-menu-item:hover {
    color: var(--primary-color);
}

.user-menu-item.logout:hover {
    color: var(--danger-color);
}

/* 侧边栏模型选择按钮样式 */
.button-choice-sidebar {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    background-color: transparent;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.button-choice-sidebar:hover {
    background-color: var(--primary-color);
    color: #ffffff;
}

/* 移动端顶距覆盖 */
@media (max-width: 768px) {
    .sidebar-aside {
        top: 0 !important;
    }
    .sidebar-overlay {
        top: 0 !important;
    }
}


/* 暂存附件展示区域 */
.pending-files-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.03);
    border-top: 1px solid var(--border-color, #e5e5e5);
    border-bottom: 1px solid var(--border-color, #e5e5e5);
}
.pending-file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-color, #e5e5e5);
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 13px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.pending-file-chip .remove-btn {
    cursor: pointer;
    color: var(--danger-color, #ff4d4f);
    font-weight: bold;
    margin-left: 4px;
}

/* 渲染后的对话中附件卡片样式 */
.file-attachment-card {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: #f1f3f5;
    border: 1px solid #dee2e6;
    padding: 10px 16px;
    border-radius: 8px;
    margin: 6px 0;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    max-width: 100%;
    text-align: left;
}
.file-attachment-card:hover {
    background: #e9ecef;
    transform: translateY(-1px);
}
.file-attachment-card:active {
    transform: translateY(0);
}
.file-attachment-icon {
    font-size: 24px;
}
.file-attachment-info {
    display: flex;
    flex-direction: column;
}
.file-attachment-name {
    font-weight: 600;
    font-size: 14px;
    color: #212529;
    word-break: break-all;
}
.file-attachment-size {
    font-size: 11px;
    color: #6c757d;
    margin-top: 2px;
}

/* --- 新增：渲染后的图片附件气泡卡片样式 --- */
.image-attachment-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-chat-user, #ffffff);
    border: 1px solid var(--border-color, #e7e5e4);
    border-radius: 12px;
    padding: 6px;
    max-width: 280px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.chat-uploaded-image {
    width: 100%;
    max-height: 200px;
    border-radius: 8px;
    object-fit: cover;
    cursor: zoom-in;
    transition: transform 0.2s ease, opacity 0.2s;
}

.chat-uploaded-image:hover {
    transform: scale(1.02);
    opacity: 0.95;
}

.image-attachment-info {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--text-light, #78716c);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
}
