/* Main Chat Area Styles */

.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    overflow: hidden;
    touch-action: pan-y;
    /* 🔑 [v7.0 无动画] 禁用过渡，确保键盘适配瞬间响应 */
    transition: none !important;
    -webkit-transition: none !important;
}

.chat-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    /*  [统一高度] 强制高度 = 安全区 + 内容区，保证与侧边栏/设置面板底部边框对齐 */
    min-height: calc(var(--safe-top) + var(--header-content-height));
    /* 顶部 padding 处理安全区，添加 4px 底部间距让内容不贴边 */
    padding: var(--safe-top) 12px 4px 12px;
    box-sizing: border-box;
    /* Sidebar Match */
    background: var(--glass-bg) !important;
    border-bottom: 1px solid var(--glass-border);

    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    will-change: backdrop-filter;

    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 5000 !important;
    /* 🔐 [层级回归] 降低高度，允许模态框（80000+）覆盖 */
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.15);
}

@media (max-width: 768px) {
    .chat-header {
        background: var(--glass-bg) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
    }

    body:not(.light-theme) .chat-header {
        background: var(--glass-bg) !important;
        backdrop-filter: blur(25px) saturate(150%) !important;
        -webkit-backdrop-filter: blur(25px) saturate(150%) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
}

/* Light Theme Adaption */
/* Light Theme Adaption - Handled by var(--glass-bg) */

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    min-width: 0;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    flex-shrink: 0;
    z-index: 101;
    touch-action: manipulation;
    /*  [统一高度] 固定尺寸 40x40px，与右侧 header-controls 按钮一致 */
    width: 40px;
    height: 40px;
    padding: 0;
    /* display: flex 由媒体查询控制，同时启用居中布局 */
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
    }
}

.mobile-menu-btn ion-icon {
    pointer-events: none;
}

.current-char-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-right: 30px;
    /*  [紧凑布局] 限制最大高度，使用紧凑行高 */
    max-height: var(--header-content-height);
    justify-content: center;
    gap: 0;
}

.current-char-info #header-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    /*  [紧凑布局] 紧凑行高 */
    line-height: 1.3;
    font-size: 0.95rem;
}

.current-char-info #char-bio-text {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    /*  [紧凑布局] 紧凑行高 */
    line-height: 1.2;
    display: inline-block;
    vertical-align: bottom;
}

.status-indicator {
    display: none;
}

.header-controls button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    /*  [统一尺寸] 固定 40x40px，与所有顶部栏按钮一致 */
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-controls button:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Chat Messages */
.chat-messages {
    width: 100%;
    height: 100%;
    /* Take full space to let content scroll behind header/footer */
    /* [滚动条优化v5] 使用 scrollbar-gutter: stable 让滚动条空间始终存在 */
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    /* [滚动锚定] 防止删除/重新生成消息时页面跳动 */
    overflow-anchor: auto;

    /* [统一高度] padding-top = header 高度 + 16px 间隙 */
    padding-top: calc(var(--safe-top) + var(--header-content-height) + 16px);
    padding-right: 10px;
    padding-left: 16px;
    /* 🔑 动态底部留白，确保末条消息可滚到正确位置 */
    padding-bottom: calc(var(--chat-bottom-padding, 120px) + (var(--kb-height, 0px) * var(--multiplier, 1))) !important;
    scroll-padding-bottom: calc(var(--chat-scroll-padding-bottom, 120px) + env(safe-area-inset-bottom, 0px)) !important;

    display: flex;
    flex-direction: column;
    gap: 20px;
    -webkit-overflow-scrolling: touch;
    /* 🔧 [修复] 使用 auto 恢复原生橡皮筋效果，避免滑动到边界时抖动 */
    overscroll-behavior-y: auto;
    /* 🔑 [v8.2] 默认使用瞬间滚动，键盘适配时由 JS 控制 */
    scroll-behavior: auto !important;
    position: relative;
    background: transparent;
    /* 🔑 [v8.2] padding 变化禁用过渡，避免抖动 */
    /* 🔧 [修复] 只禁用 padding 相关的过渡，保留 transform 过渡用于回弹动画 */
    transition: padding-bottom 0s, padding-top 0s !important;
    -webkit-transition: padding-bottom 0s, padding-top 0s !important;
}

/* 🔧 [修复] 当内容不足以滚动时，标记状态（保留橡皮筋效果，但会自动复位） */
.chat-messages.scroll-disabled {
    /* 保留正常的滚动行为，JavaScript 会在松手后自动复位 */
}

/* Draw Mode: 禁用头像点击进入详情 */
#app-container.draw-mode-active .chat-messages .clickable-avatar {
    pointer-events: none;
    cursor: default;
}

#app-container.draw-mode-active #header-char-info {
    cursor: default !important;
}

/*  [滚动条优化v1] 滚动条样式 - 悬浮模式，不占用宽度 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
    /*  减小宽度，更精致 */
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
    /*  透明轨道，不遮挡内容 */
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.4);
    /*  半透明滑块 */
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.6);
}



/*  [编辑模式优化] 当消息处于编辑状态时，隐藏不相关的交互元素 */
.message-group.is-editing .message-actions,
.message-group.is-editing .suggest-questions-container,
.message-group.is-editing .gal-options-container {
    display: none !important;
}

.message-group {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    opacity: 1;
    transform: none;
    margin-bottom: 8px;
}

@media (max-width: 768px) {
    .message-group.bot {
        /* 🎨 [Gemini风格] AI消息全宽显示 */
        max-width: 100%;
    }

    .message-group.user {
        /* 保持用户消息的 90% 宽度 */
        max-width: 90%;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

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

.message-group.bot {
    /* 🎨 [布局优化v2] AI消息使用垂直布局 */
    flex-direction: column;
    gap: 6px;
    /* 🎨 [Gemini风格] 添加底部分割线分隔消息组 */
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 14px;
    margin-bottom: 14px;
}

/* 对话模式：只保留给按钮/选项区的 spacer（由 .chat-messages 的 padding-bottom 提供），最后一条消息不再额外 margin，避免底部多出一块空白 */
.message-group:last-child {
    margin-bottom: 0;
}

/*  [布局优化v2] AI消息头部行：头像 + 名称/时间 */
.message-group.bot .msg-header-row {
    display: flex;
    align-items: center;
    gap: 10px;
    /*  [边距统一v1] 头像行无额外 padding，使用父容器'的 0px */
    padding: 0;
}

/* 停止生成按钮样式 */
.msg-action-btn.stop {
    color: #ef4444;
    background: var(--surface-light);
    border: 1px solid var(--glass-border);
}

.msg-action-btn.stop:hover {
    color: #dc2626;
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/*  [布局优化v2] AI消息内容区：全宽显示 */
.message-group.bot .msg-content-fullwidth {
    width: 100%;
    max-width: 100%;
}

.msg-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    background: var(--surface-light);
    flex-shrink: 0;
    contain: size layout;
    display: block;
}

/* AI 占位头像图标 - 暗色模式白色图标 */
.msg-avatar-ai-fallback ion-icon {
    color: #fff;
}

.msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

/* Font Size Adaptations */
body.font-small {
    --chat-font-size: 0.85rem;
    --bubble-padding: 8px 12px;
    --chat-options-reserve: 116; /* 130 * 0.85/0.95，选项预留高度随字体缩放 */
}

body.font-standard {
    --chat-font-size: 0.95rem;
    --bubble-padding: 10px 15px;
    --chat-options-reserve: 130;
}

body.font-large {
    --chat-font-size: 1.1rem;
    --bubble-padding: 12px 18px;
    --chat-options-reserve: 150; /* 130 * 1.1/0.95 */
}

body.font-extra-large {
    --chat-font-size: 1.25rem;
    --bubble-padding: 14px 20px;
    --chat-options-reserve: 171; /* 130 * 1.25/0.95 */
}

.msg-bubble {
    display: block !important;
    max-width: 100% !important;
    padding: var(--bubble-padding, 10px 15px);
    border-radius: 18px;
    font-size: var(--chat-font-size, 0.95rem) !important;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: none;
    overflow: hidden;
    min-width: 2rem;
}

.msg-bubble .markdown-body,
.msg-bubble .markdown-body p,
.msg-bubble .markdown-body li,
.msg-bubble p,
.msg-bubble div,
.msg-bubble span {
    font-size: inherit !important;
}

.msg-bubble .msg-text.markdown-body {
    display: block !important;
    width: 100% !important;
    clear: both !important;
    margin-top: 8px !important;
}

.gal-option-btn {
    font-size: var(--chat-font-size, 1rem) !important;
    padding: 0.8em 2.5em 0.8em 1em !important;
    min-height: 0;
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
    max-width: 100%;
    white-space: normal !important;
    word-break: break-word !important;
}

.gal-option-btn .opt-type-tag {
    position: absolute;
    bottom: 0.3em;
    right: 0.5em;
    font-size: 0.6em !important;
    padding: 0.1em 0.3em;
}

.suggest-question-btn {
    font-size: calc(var(--chat-font-size, 0.95rem) * 0.9) !important;
    padding: 6px 12px;
}

.msg-bubble pre,
.msg-bubble code {
    font-size: 0.9em;
}

.message-group.bot .msg-bubble {
    /* 🎨 [Gemini风格] 全宽布局，去除气泡限制 */
    background: transparent;
    border-radius: 0;
    color: var(--text-primary);
    box-shadow: none;
    /* 全宽显示 */
    width: 100%;
    max-width: 100% !important;
    min-width: 0;
    /*  [边距统一v1] 移除左右 padding，让子元素各自控制边距 */
    padding: 0;
}

.message-group.bot .msg-content {
    width: 100%;
    max-width: 100%;
    align-items: flex-start;
}

.message-group.user .msg-bubble {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%) !important;
    color: white !important;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
    align-self: flex-end;
    text-align: left;
    width: fit-content;
    max-width: 90% !important;
    min-width: 2rem;
}

.message-group.user .msg-bubble,
.message-group.user .msg-bubble *:not(.edit-mode):not(.edit-textarea):not(.edit-actions):not(.edit-actions *):not(.btn-save-edit):not(.btn-cancel-edit) {
    color: white !important;
}

.msg-meta {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    margin: 0 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-group.user .msg-meta {
    justify-content: flex-end;
}

.message-group.user .msg-content {
    align-items: flex-end;
}

.msg-timestamp {
    font-size: 0.65rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Typing Indicator */
.typing-indicator-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 0;
    width: 100%;
    min-width: 100%;
    box-sizing: border-box;
}
.typing-indicator {
    display: flex;
    gap: 4px;
    background: transparent;
    width: fit-content;
    flex-shrink: 0;
}
.typing-retry-badge {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.85;
    white-space: nowrap;
    flex-shrink: 0;
}
.typing-indicator-meta {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    white-space: nowrap;
}
.typing-elapsed {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.9;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4ch; /* 固定显示宽度：覆盖 1/2/3 位秒数 + “秒” */
    padding: 0;
    border: none;
    background: transparent;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}
/* 打字气泡占满内容区宽度，以便重试次数靠右对齐 */
.msg-bubble.compact-loading .typing-indicator-wrapper {
    width: 100%;
}
.msg-bubble.compact-loading {
    width: 100%;
}

.typing-space-placeholder {
    width: 100%;
    overflow: hidden;
    pointer-events: none;
    opacity: 1;
    transition: height 0.18s ease, min-height 0.18s ease, opacity 0.14s ease;
}

.typing-space-placeholder.is-collapsing {
    opacity: 0.01;
}

.dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

@keyframes bounce {

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

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

/* Chat Input Area */
.chat-input-area {
    position: absolute;
    /* 🔑 [v7.0 键盘适配] 通过 CSS 变量控制位置，支持瞬间移动 */
    bottom: calc(var(--kb-height, 0px) * var(--multiplier, 1));
    left: 0;
    right: 0;
    /* [紧凑布局] 仿 QQ 风格，减少边距 */
    padding: 8px 12px 12px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    /* Sidebar Match */
    background: var(--glass-bg) !important;
    border-top: 1px solid var(--glass-border);
    backdrop-filter: blur(20px) saturate(160%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(160%) !important;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 6px;
    /* 🚀 性能优化：独立 GPU 分层 */
    transform: translateZ(0);
    will-change: transform, bottom;
    z-index: 1000;
    /* 🔑 [v7.0 无动画] 完全禁用过渡，实现瞬间移动 */
    transition: none !important;
    -webkit-transition: none !important;
}

/*  [编辑模式修复] 当有消息处于编辑状态时，隐藏主输入框 */
/* 原因：Android adjustResize 会压缩视口，bottom:0px 无法阻止整体上移 */
/* 解决：编辑模式时用户不需要主输入框，直接隐藏更合理 */
body.editing-message .chat-input-area {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-out;
}

@media (max-width: 768px) {
    .chat-input-area {
        background: var(--glass-bg) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.2) !important;
    }

    body:not(.light-theme) .chat-input-area {
        background: var(--glass-bg) !important;
        backdrop-filter: blur(25px) saturate(150%) !important;
        -webkit-backdrop-filter: blur(25px) saturate(150%) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
}

/* Light Theme Adaption for Input Area */
/* Light Theme Adaption for Input Area - Handled by var(--glass-bg) */

.input-action-bar {
    display: flex;
    justify-content: space-between;
    width: 80%;
    margin: 2px auto 8px auto;
    /* 🎨 [间距优化] 底部增加 8px 呼吸空间，避免按钮太贴近底部导航栏 */
    padding: 0 10px;
}

/* ==================== 绘画模式操作按钮 ==================== */
.draw-action-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    width: 80%;
    margin: 8px auto 8px auto;
    /* 🎨 [间距优化] 底部增加 8px 呼吸空间，与 input-action-bar 保持一致 */
    padding: 0 10px;
}

.draw-config-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    background: var(--surface-light);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.draw-config-btn ion-icon {
    font-size: 1.1rem;
    color: var(--primary-color);
}

.draw-config-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.draw-config-btn:hover ion-icon {
    color: #fff;
}

.draw-btn-text {
    font-weight: 600;
}

/* 绘图模式：参考图（图生图）预览 */
.draw-reference-preview {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
    padding: 4px;
    background: var(--surface-light);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
}

.draw-reference-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

.draw-reference-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.2s;
}

.draw-reference-clear:hover {
    color: var(--primary-color);
}

.draw-reference-clear ion-icon {
    font-size: 1.25rem;
}

/* 绘画配置模态框 */
.draw-config-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.draw-config-modal {
    background: var(--bg-color);
    border-radius: 16px;
    width: 90%;
    max-width: 360px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.draw-config-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--glass-border);
}

.draw-config-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.draw-config-modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.draw-config-modal-close:hover {
    background: var(--surface-light);
    color: var(--text-primary);
}

.draw-config-modal-body {
    padding: 12px;
    max-height: 60vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.draw-config-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 16px;
    background: var(--surface-light);
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.draw-config-option:hover {
    background: var(--surface-color);
    border-color: var(--primary-color);
}

.draw-config-option.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary-color);
}

.draw-config-option-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.draw-config-option-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.draw-config-option.active .draw-config-option-value {
    color: var(--primary-color);
}

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

/* 🎤 [语音识别] 录音状态样式*/
.action-btn.recording {
    color: #ef4444 !important;
    animation: pulse-recording 1s infinite;
}

@keyframes pulse-recording {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

/* Emoji Picker Styles - Premium Grounded Glass */
.emoji-picker-container {
    /* 
       🎭 终极方案：对标侧边栏最高规格磨砂感
       1. 提升 Alpha 至 0.9，彻底解决面板过小导致的“全透”感
       2. 使用 Fixed 定位到 Body 根部，规避嵌套滤镜 Bug
    */
    position: fixed;
    bottom: 110px;
    /* 位置相对于视口，需根据输入框高度适配 */
    left: 50%;
    transform: translateX(-50%) translateZ(0);

    /* Synced with Sidebar Variables for consistency */
    background: var(--glass-bg) !important;
    backdrop-filter: blur(25px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(25px) saturate(180%) !important;

    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.6);
    border-radius: 20px;
    display: none;
    /* 🚀 性能优化：GPU 渲染层 */
    transform: translateX(-50%) translateZ(0);
    will-change: transform, opacity;
    z-index: 200005 !important;
    width: 90vw;
    max-width: 420px;
    animation: emojiFadeIn 0.3s ease-out;
    pointer-events: auto;
}

/* 当显示时，强制使用 flex 以便内部对齐 */
.emoji-picker-container.active {
    display: flex !important;
}

body.light-theme .emoji-picker-container {
    background: var(--glass-bg) !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid var(--glass-border) !important;
}

@media (max-width: 768px) {
    .emoji-picker-container {
        bottom: 140px;
        /* Mobile Light Theme (Default) - Sidebar Ref */
        background: var(--glass-bg) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
    }

    body:not(.light-theme) .emoji-picker-container {
        /* Mobile Dark Theme - Synced with Sidebar Mobile (~0.7) or kept consistent with var */
        background: var(--glass-bg) !important;
        /* Slightly higher alpha for mobile readability but less than 0.9 */
        backdrop-filter: blur(20px) saturate(150%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(150%) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
}

/* Light Theme Adaption for Emoji Picker - Handled by var(--glass-bg) */

@keyframes emojiFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.emoji-list {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    /* 严格按照要求调整为 3px */
    max-height: 250px;
    overflow-y: auto !important;
    /* 确保可滚动 */
    padding: 4px;
    -webkit-overflow-scrolling: touch;
}

.emoji-item {
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    border-radius: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

.emoji-item:hover {
    background: var(--surface-hover);
    transform: scale(1.15) translateZ(0);
}

.emoji-item:active {
    transform: scale(0.95);
}

.action-btn:hover {
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.input-wrapper {
    display: flex;
    gap: 8px;
    /* 减少 gap */
    align-items: center;
    /* Sidebar Match */
    background: var(--glass-bg) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border-radius: 24px;
    /*  [紧凑布局] 调整 padding */
    padding: 6px 8px 6px 12px;
    border: 1px solid var(--glass-border) !important;
    transition: all 0.2s;
}

body.light-theme .input-wrapper {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

body.light-theme .input-wrapper:focus-within {
    background: rgba(0, 0, 0, 0.06);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.4;
    resize: none;
    max-height: 25vh;
    min-height: 16px;
    padding: 2px 0;
    outline: none;
    overflow-y: auto;
}

.btn-send {
    background: var(--primary-color);
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
    margin-bottom: 1px;
}

.btn-send:hover {
    transform: scale(1.1);
}

.btn-send:active {
    transform: scale(0.95);
}

/* 🎤 [语音识别] 发送按钮变成红色停止按钮 */
.btn-send.voice-stop-mode {
    background: #ef4444 !important;
    animation: pulse-stop 1.5s infinite;
}

.btn-send.voice-stop-mode .stop-icon {
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 2px;
}

@keyframes pulse-stop {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
}

/* 对话模式：AI 流式完成后才展开预留选项区，选项出现时用预留空间，不额外占位 */
.suggest-options-reserve {
    min-height: 0;
    overflow: hidden;
    transition: min-height 0.35s ease-out;
}
/* 流式开始时即展开按钮区占位（无 transition，便于首次跟随滚动一次到位） */
.suggest-options-reserve.reserve-visible-streaming {
    min-height: calc(var(--chat-options-reserve, 130) * 1px);
    transition: none;
}
.suggest-options-reserve.reserve-visible {
    min-height: calc(var(--chat-options-reserve, 130) * 1px);
}

/* Suggested Questions */
.suggest-questions-container {
    animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* Light Theme Shadow Removal */
body.light-theme .chat-header,
body.light-theme .chat-input-area {
    box-shadow: none !important;
    border-bottom-color: rgba(0, 0, 0, 0.1) !important;
    border-top-color: rgba(0, 0, 0, 0.1) !important;
}

/* Scroll to Bottom Button */
.scroll-bottom-btn {
    position: fixed;
    left: 0;
    top: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;

    background: var(--surface-light) !important;
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);

    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);

    z-index: 2000;
    opacity: 0;
    pointer-events: none;

    /* 位置通过 CSS 变量控制，由 JS 设置绝对坐标 */
    --btn-x: 0px;
    --btn-y: 0px;
    transform: translate(var(--btn-x), var(--btn-y)) scale(1) translateZ(0);
    will-change: transform, opacity;
    transition: opacity 0.15s ease;

    -webkit-user-select: none;
    user-select: none;
}

.scroll-bottom-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

.scroll-bottom-btn:hover:not(.dragging):not(.long-press-active) {
    background: var(--surface-hover);
    transform: translate(var(--btn-x), var(--btn-y)) scale(1.1) translateZ(0);
}

/* 拖拽状态 */
.scroll-bottom-btn.dragging {
    cursor: grabbing !important;
    transform: translate(var(--btn-x), var(--btn-y)) scale(1.15) translateZ(0);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    z-index: 2001;
}

/* 长按提示 */
.scroll-bottom-btn.long-press-active {
    transform: translate(var(--btn-x), var(--btn-y)) scale(1.1) translateZ(0);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* 边缘吸附动画 */
.scroll-bottom-btn.snapping {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.15s ease;
}

/* ==================== 键盘激活状态样式 ==================== */
/* 🔑 [v7.0] 当键盘打开时，确保所有相关元素禁用过渡动画 */
body.keyboard-active .chat-input-area,
body.keyboard-active .chat-messages,
body.keyboard-active .scroll-bottom-btn {
    /* 🔧 [修复] 只禁用 padding 相关的过渡，保留 transform 过渡用于回弹动画 */
    transition: padding-bottom 0s, padding-top 0s !important;
    -webkit-transition: padding-bottom 0s, padding-top 0s !important;
}

/* 🔑 [v8.2] 键盘激活时移除安全区域 padding，因为键盘已覆盖导航栏 */
body.keyboard-active .chat-input-area {
    padding-bottom: 12px !important;
}

.suggest-questions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.suggest-question-btn {
    display: flex !important;
    align-items: flex-start !important;
    /* Sidebar Match */
    background: var(--glass-bg) !important;
    backdrop-filter: blur(5px) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    font-size: calc(var(--chat-font-size, 0.95rem) * 0.95);
    text-align: left;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    gap: 0.6rem;
}

.suggest-question-btn::before {
    content: '→';
    flex-shrink: 0;
    font-size: inherit;
    color: var(--primary-color);
    opacity: 0.7;
    margin-top: 2px;
}

.suggest-question-btn:hover {
    background: var(--surface-hover) !important;
    border-color: var(--primary-color) !important;
    transform: translateX(5px);
}

.suggest-question-btn:active {
    transform: scale(0.98);
}

/* ==================== 离线模式样式 ==================== */
.offline-indicator {
    display: none;
    color: #ef4444;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 6px 0;
    flex: 1;
    text-align: center;
}

@keyframes pulse-offline {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* 离线模式下的 UI 变化 */
body.offline-mode .offline-indicator {
    display: block !important;
}

body.offline-mode #send-btn {
    display: none !important;
}

body.offline-mode .chat-input {
    display: none !important;
}

body.offline-mode .input-wrapper {
    border-color: rgba(239, 68, 68, 0.2) !important;
    background: rgba(239, 68, 68, 0.03) !important;
}

body.offline-mode .input-action-bar {
    display: none !important;
}

/* 离线模式下隐藏所有交互选项 */
body.offline-mode .gal-options-container,
body.offline-mode .gal-option-btn,
body.offline-mode .suggest-questions-container,
body.offline-mode .suggest-question-btn,
body.offline-mode .suggestion-options,
body.offline-mode .quick-replies {
    display: none !important;
}

/* ==================== 远程锁定增强样式 (Remote Locked) ==================== */

/* 锁定状态下，隐藏发送按钮 */
body.remote-locked-mode #send-btn {
    display: none !important;
}

/* 锁定状态下，输入框变为提示文本区域 */
body.remote-locked-mode #message-input {
    color: #ef4444 !important;
    text-align: center !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    font-weight: 500;
}

/* 锁定状态下，输入框容器变红 */
body.remote-locked-mode .input-wrapper {
    border-color: rgba(239, 68, 68, 0.3) !important;
    background: rgba(239, 68, 68, 0.05) !important;
}

/* 锁定状态下，底部操作栏完全隐藏 */
body.remote-locked-mode .input-action-bar {
    display: none !important;
}

/* 锁定状态下隐藏所有交互选项 */
body.remote-locked-mode .gal-options-container,
body.remote-locked-mode .gal-option-btn,
body.remote-locked-mode .suggest-questions-container,
body.remote-locked-mode .suggest-question-btn,
body.remote-locked-mode .suggestion-options,
body.remote-locked-mode .quick-replies,
body.remote-locked-mode .message-actions {
    display: none !important;
}

/* 离线模式 UI 限制：禁止修改和重发，保留复制 */
/* 🔧 [修复] 同时适用于断网模式和心跳断开模式 */
body.is-offline .msg-action-btn.regenerate,
body.is-offline .msg-action-btn.edit,
body.is-offline .msg-action-btn.delete,
body.offline-mode .msg-action-btn.regenerate,
body.offline-mode .msg-action-btn.edit,
body.offline-mode .msg-action-btn.delete {
    display: none !important;
}

/* 离线模式：隐藏全局新建与保存入口 */
body.is-offline #new-conversation-btn,
body.is-offline .sidebar-footer,
body.is-offline #action-image,
body.is-offline #action-voice,
body.is-offline #action-voice,
body.is-offline .suggest-questions-container,
body.is-offline #settings-btn {
    display: none !important;
}

/* 离线模式：禁止点击头部、头像打开编辑界面 */
body.is-offline #header-char-info,
body.is-offline .msg-avatar.clickable-avatar,
body.is-offline .user-avatar-small,
body.is-offline #sidebar-user-avatar-img,
body.is-offline #current-user-name,
body.is-offline #current-user-species,
body.is-offline #create-new-char {
    pointer-events: none !important;
    cursor: default !important;
    opacity: 0.6 !important;
}

/* 离线模式：设置面板与用户安全限制 */
/* 隐藏“当前模型”选择、重置按钮、清空缓存按钮以及用户安全设置入口 */
body.is-offline .setting-group:has(#model-select-trigger),
body.is-offline .settings-actions .btn-reset,
body.is-offline .settings-actions .btn-clear,
body.is-offline #toggle-security-btn,
body.is-offline #save-security-btn,
body.is-offline #publish-char-btn {
    display: none !important;
}

/* 离线模式：历史记录与交互锁定 */
body.is-offline .history-item-actions,
body.is-offline .history-item-title,
body.is-offline .gal-option-btn,
body.is-offline .suggest-question-btn {
    pointer-events: none !important;
    opacity: 0.6;
}

/* 离线模式：底部操作栏按钮 (保持清晰但变红) */
body.is-offline .input-action-bar .action-btn {
    pointer-events: none !important;
    color: #ef4444 !important;
    opacity: 0.9 !important;
}

/* 离线模式：侧边栏禁止排序 */
body.is-offline .character-item {
    pointer-events: auto !important;
    /* 允许选择角色切换查看 */
}

body.is-offline .character-list {
    user-select: none;
}

/* 📴 离线模式：主输入框状态展示 (警告红) */
body.is-offline .input-wrapper {
    background: #fff5f5 !important;
    /* 浅红色(浅色模式) */
    border: 1px solid #feb2b2 !important;
    backdrop-filter: none !important;
}

/* 🌙 暗色模式下的离线状态：深色背景 + 红色边框 */
body.is-offline:not(.light-theme) .input-wrapper {
    background: #1a1616 !important;
    /* 深灰色带点红 */
    border: 1px solid #dc2626 !important;
    /* 鲜红色边框 (粗细同步亮色模式) */
}

body.is-offline #message-input {
    background: transparent !important;
    color: #c53030 !important;
    /* 深红色文字(浅色模式) */
}

body.is-offline:not(.light-theme) #message-input {
    color: #ef4444 !important;
    /* 亮红色文字(暗色模式) */
}

body.is-offline #message-input::placeholder {
    color: #f87171 !important;
    opacity: 0.7;
}

body.is-offline .chat-input-area {
    pointer-events: none !important;
    opacity: 1 !important;
    filter: none !important;
    background: var(--surface-light) !important;
    /* 确保底部栏背景也不透明 */
}

/* 离线模式：全局隐藏模态框内的所有保存、重集、提交按钮，强制只留取消/关闭 */
body.is-offline .modal-footer button:not(.btn-cancel):not(.modal-close-btn),
body.is-offline .modal-footer .btn-save,
body.is-offline .modal-footer .save-btn,
body.is-offline .modal-footer .btn-primary,
body.is-offline .modal-footer .submit-btn,
body.is-offline .modal-footer #reset-gal-btn {
    display: none !important;
}

/* 📴 离线模式：禁用侧边栏角色排序、编辑与删除 */
body.is-offline .character-list {
    cursor: default !important;
}

body.is-offline .character-item {
    user-select: none !important;
    -webkit-user-drag: none !important;
    touch-action: pan-y !important;
    /* 🛑 [关键修复] 禁止任何拖拽行为，但保留点击 */
    -webkit-touch-callout: none !important;
}

/* 离线模式：隐藏历史记录删除按钮 */
body.is-offline .history-card-delete,
body.is-offline .history-card-delete ion-icon {
    display: none !important;
    pointer-events: none !important;
}

body.is-offline .btn-edit-char,
body.is-offline .btn-delete-char {
    display: none !important;
}

/* 拦截 Sortable 内部可能触发的拖拽手柄 */
body.is-offline .character-item * {
    pointer-events: auto;
}

/* 针对侧边栏在离线模式下的高度修正：因为 footer 没了，让列表填满 */
body.is-offline .character-list {
    padding-bottom: env(safe-area-inset-bottom) !important;
}

/* ==================== 心跳断开离线模式 (offline-mode) 完整样式 ==================== */
/* 🔧 [重要] 确保心跳断开模式与断网模式 UI 完全一致 */

/* 离线模式：隐藏全局新建与保存入口 */
body.offline-mode #new-conversation-btn,
body.offline-mode .sidebar-footer,
body.offline-mode #action-image,
body.offline-mode #action-voice,
body.offline-mode #action-voice,
body.offline-mode .suggest-questions-container,
body.offline-mode #settings-btn {
    display: none !important;
}

/* 离线模式：禁止点击头部、头像打开编辑界面 */
body.offline-mode #header-char-info,
body.offline-mode .msg-avatar.clickable-avatar,
body.offline-mode .user-avatar-small,
body.offline-mode #sidebar-user-avatar-img,
body.offline-mode #current-user-name,
body.offline-mode #current-user-species,
body.offline-mode #create-new-char {
    pointer-events: none !important;
    cursor: default !important;
    opacity: 0.6 !important;
}

/* 离线模式：设置面板与用户安全限制 */
body.offline-mode .setting-group:has(#model-select-trigger),
body.offline-mode .settings-actions .btn-reset,
body.offline-mode .settings-actions .btn-clear,
body.offline-mode #toggle-security-btn,
body.offline-mode #save-security-btn,
body.offline-mode #publish-char-btn {
    display: none !important;
}

/* 离线模式：历史记录与交互锁定 */
body.offline-mode .history-item-actions,
body.offline-mode .history-item-title,
body.offline-mode .gal-option-btn,
body.offline-mode .suggest-question-btn {
    pointer-events: none !important;
    opacity: 0.6;
}

/* 离线模式：侧边栏禁止排序 */
body.offline-mode .character-item {
    pointer-events: auto !important;
}

body.offline-mode .character-list {
    user-select: none;
    cursor: default !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
}

body.offline-mode .character-item {
    user-select: none !important;
    -webkit-user-drag: none !important;
    touch-action: pan-y !important;
    -webkit-touch-callout: none !important;
}

/* 离线模式：全局隐藏模态框保存按钮 */
body.offline-mode .modal-footer button:not(.btn-cancel):not(.modal-close-btn),
body.offline-mode .modal-footer .btn-save,
body.offline-mode .modal-footer .save-btn,
body.offline-mode .modal-footer .btn-primary,
body.offline-mode .modal-footer .submit-btn,
body.offline-mode .modal-footer #reset-gal-btn {
    display: none !important;
}

/* 离线模式：隐藏历史记录删除按钮 */
body.offline-mode .history-card-delete,
body.offline-mode .history-card-delete ion-icon {
    display: none !important;
    pointer-events: none !important;
}

body.offline-mode .btn-edit-char,
body.offline-mode .btn-delete-char {
    display: none !important;
}

/* 拦截 Sortable 内部可能触发的拖拽手柄 */
body.offline-mode .character-item * {
    pointer-events: auto;
}

/* ==================== 图片懒加载样式 ==================== */

/* 懒加载占位符：与对话区域等宽，加载中动画也全宽 */
.lazy-image-placeholder {
    width: 100%;
    box-sizing: border-box;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(6, 182, 212, 0.1) 100%);
    border: 1px dashed rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 8px 0;
}

.lazy-image-placeholder:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(6, 182, 212, 0.2) 100%);
    border-color: rgba(99, 102, 241, 0.5);
    transform: scale(1.01);
}

.lazy-image-placeholder:active {
    transform: scale(0.98);
}

/* 占位符内的图标动画 */
.lazy-image-placeholder ion-icon {
    animation: lazyImagePulse 2s ease-in-out infinite;
}

@keyframes lazyImagePulse {
    0%, 100% {
        opacity: 0.5;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

/* 加载中的旋转动画 */
.lazy-image-placeholder .loading-spinner {
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* 已加载的图片 */
.lazy-image.just-loaded {
    animation: lazyImageFadeIn 0.3s ease-out;
}

@keyframes lazyImageFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 角色设定预览框 - 暗色模式 */
.prompt-preview-box {
    background: rgba(0, 0, 0, 0.2);
}

/* 错误报告框 - 暗色模式 */
.error-debug-box {
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.error-debug-box .error-debug-text,
.error-debug-box .error-debug-value {
    color: #fff;
    padding-left: 12px;
}

.error-debug-raw-footer {
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.error-debug-box .error-debug-pre {
    color: #94a3b8;
    padding-left: 12px;
    margin: 0;
    font-size: 0.85rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* 开场白空状态卡片 - 暗色模式 */
.empty-state-first-msg-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 24px;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.empty-state-first-msg-label {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 12px;
}

.empty-state-first-msg-text {
    font-size: 1.05rem;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
}

.empty-state-first-msg-hint {
    margin-top: 20px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.4);
}

/* 懒加载占位符标签 - 暗色模式 */
.lazy-image-placeholder-label {
    background: rgba(0, 0, 0, 0.6);
    color: white;
}

/* Light Theme Adaptations */
body.light-theme .lazy-image-placeholder {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(6, 182, 212, 0.08) 100%);
    border-color: rgba(99, 102, 241, 0.25);
}

body.light-theme .lazy-image-placeholder:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(6, 182, 212, 0.15) 100%);
}