/* 聊天页面专用样式 */

/* 聊天页面整体布局 */
.chat-page {
    background-color: #f5f5f5;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    /* 安全区域支持 */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

.chat-container {
    display: flex;
    height: calc(100vh - 64px);
    height: calc(var(--vh, 1vh) * 100 - 64px);
    background: #fff;
}

/* 左侧聊天列表 */
.chat-sidebar {
    width: 280px;
    background: #ffffff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
    gap: 12px;
}

.search-chat {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 8px 16px;
}

.search-chat i {
    color: #999;
    margin-right: 8px;
    font-size: 14px;
}

.chat-search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    background: transparent;
}

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

.action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #666;
    transition: all 0.3s;
}

.action-btn:hover {
    background: #f0f0f0;
    color: #333;
}

/* 聊天操作按钮 */
.chat-actions {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid #e0e0e0;
}

.chat-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    width: 100%;
    justify-content: flex-start;
}

.chat-action-btn:hover {
    background: #f8f9fa;
    border-color: #ff6b6b;
}

.match-btn {
    background: #ff6b6b;
    color: white;
    border-color: #ff6b6b;
}

.match-btn:hover {
    background: #ff5252;
}

.new-chat-btn {
    justify-content: space-between;
}

/* 聊天列表 */
.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s;
    margin-bottom: 4px;
}

.chat-item:hover {
    background: #f0f0f0;
}

.chat-item.active {
    background: #fff5f5;
    border-left: 3px solid #ff6b6b;
}

.chat-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-preview {
    font-size: 12px;
    color: #999;
}

/* 中间聊天区域 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    position: relative;
    overflow: hidden;
}

/* 聊天头部样式 */
.chat-header {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
    width: auto;
    height: auto;
}

.chat-settings-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    color: #666;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1000;
}

.chat-settings-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 60px 20px 20px 20px; /* 增加顶部padding为齿轮按钮留空间 */
    background: #ffffff;
    position: relative;
}

/* 消息样式 */
.message {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
    max-width: 80%;
    position: relative;
    animation: messageSlideIn 0.3s ease-out;
}

/* 消息主体容器（包含头像和内容） */
.message-main {
    display: flex;
    align-items: flex-start;
}

.message.system-message {
    justify-content: center;
    max-width: 100%;
}

.message.system-message .message-content {
    background: #f8f9fa;
    color: #666;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    text-align: center;
    border: 1px solid #e9ecef;
}

/* 连接状态 */
.connection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    margin: 20px auto;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    color: #856404;
    font-size: 14px;
    max-width: 200px;
}

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

.loading-dots span {
    width: 6px;
    height: 6px;
    background: #856404;
    border-radius: 50%;
    animation: loadingPulse 1.5s infinite ease-in-out;
}

.loading-dots span:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes loadingPulse {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.3);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

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

.message.user-message {
    align-self: flex-end;
    margin-left: auto;
}

.message-avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    margin-right: 12px;
}

.message.user-message .message-main {
    flex-direction: row-reverse;
}

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

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

.message-content {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
    max-width: 100%;
    border: none;
}

/* 新的消息块容器：用于将按钮放在气泡外（下方） */
.message-block {
    display: flex;
    flex-direction: column;
}

.message.user-message .message-content {
    background: #007bff;
    color: white;
    border: 1px solid #007bff;
}

.message-text {
    font-size: 16px; /* 调大文字 */
    line-height: 1.8; /* 增加行高更易读 */
    margin-bottom: 6px;
    word-wrap: break-word;
}

/* 引号高光样式：橙色 + 斜体，包括引号本身 */
.quote-highlight {
    color: #e39a16 !important;
    font-style: italic;
}

/* 流式消息样式 */
.message.streaming .message-text::after {
    content: '|';
    animation: blink 1s infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.message-time {
    font-size: 11px;
    color: #999;
    text-align: right;
}

/* 移除时间显示：时间节点不再渲染，保留选择器备用 */
.message-time { display: none; }

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    justify-content: flex-start; /* 统一靠左 */
    pointer-events: none; /* 隐藏时禁用点击 */
}

/* 让按钮与气泡左边对齐：
   AI消息：按钮在message-block内，默认与内容同起点
   用户消息：使用与内容相同的左内边距对齐 */
.message .message-block { align-items: flex-start; }
.message .message-actions { align-self: stretch; }
.message .message-content { padding-left: 16px; padding-right: 16px; }
.message.ai-message .message-actions { margin-left: 0; }
.message.user-message .message-actions { margin-left: 0; }

.message.ai-message .message-actions { margin-left: 0; }

.message.user-message .message-actions {
    margin-left: 0;
}

.message:hover .message-actions {
    opacity: 1;
    pointer-events: auto;
}

.message-actions .action-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
    border-radius: 4px;
    min-width: 28px;
    flex-shrink: 0;
}

/* 输入区域 */
.chat-input-area {
    border-top: 1px solid #e0e0e0;
    background: #fff;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    display: block; /* 桌面端默认显示 */
    position: sticky;
    bottom: 0;
    z-index: 10;
}

/* 移除模型选择 UI 样式 */

.message-input-container {
    display: flex;
    align-items: center; /* 垂直居中 */
    gap: 12px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    padding: 14px 18px; /* 稍微增大内边距 */
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}

.message-input-container:focus-within {
    border-color: #007bff;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.15);
    background: #fafbfc;
}

.message-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px; /* 调大输入字体 */
    line-height: 1.6;
    resize: none;
    min-height: 24px;
    max-height: 160px; /* 允许更高多行 */
    font-family: inherit;
    transition: color 0.3s ease;
}

.message-input:focus {
    color: #333;
}

.send-btn {
    width: 40px; /* 略增大发送按钮 */
    height: 40px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: #0056b3;
    transform: scale(1.05);
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* 禁用输入框灰显 */
.message-input:disabled {
    color: #999;
}

/* 右侧设置面板 */
.chat-settings {
    width: 0;
    background: #ffffff;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    overflow: hidden;
}

.chat-settings.show {
    width: 320px;
}

.chat-settings.collapsed {
    width: 0;
    overflow: hidden;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #fff;
}

.settings-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

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

.settings-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #666;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.settings-btn:hover {
    background: #f0f0f0;
    color: #333;
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px; /* 减少左右padding确保有更多空间 */
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.setting-item {
    margin-bottom: 16px;
    min-width: 0; /* 允许内容收缩 */
}

/* 清理重复样式 - 使用下面统一的.setting-label样式 */

/* 强制对话高光设置在一行显示 - 针对包含toggle-switch的label */
.setting-label {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    min-width: 260px !important; /* 确保有足够宽度 */
    box-sizing: border-box;
    cursor: pointer;
}

.setting-label span:first-child {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* 如果文字太长则显示省略号 */
    font-size: 13px;
    font-weight: 500;
    color: #333;
}

.setting-label .toggle-switch {
    flex: 0 0 40px;
    margin-left: 8px;
}

.setting-item label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
}

.setting-input,
.setting-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    transition: border-color 0.3s;
}

.setting-input:focus,
.setting-select:focus {
    outline: none;
    border-color: #ff6b6b;
}

/* 切换开关 */
.toggle-switch {
    position: relative;
    width: 40px;
    height: 20px;
    flex-shrink: 0; /* 防止开关被压缩 */
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: #ff6b6b;
}

input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

/* 声优按钮 */
.voice-buttons {
    display: flex;
    gap: 8px;
}

.voice-btn {
    padding: 6px 12px;
    border: 1px solid #e0e0e0;
    background: #fff;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.voice-btn:hover {
    background: #f8f9fa;
}

.voice-btn.active {
    background: #ff6b6b;
    color: white;
    border-color: #ff6b6b;
}

/* 背景选择网格 */
.background-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.bg-btn {
    aspect-ratio: 3/2;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s;
    padding: 0;
    background: none;
}

.bg-btn:hover {
    border-color: #ff6b6b;
}

.bg-btn.active {
    border-color: #ff6b6b;
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.3);
}

.bg-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 会话管理按钮 */
.session-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.session-btn:hover {
    background: #f8f9fa;
}

.favorite-btn:hover {
    border-color: #ff6b6b;
    color: #ff6b6b;
}

.favorite-btn.favorited {
    background: #ff6b6b;
    color: white;
    border-color: #ff6b6b;
}

.favorite-btn.favorited:hover {
    background: #e55a5a;
}

.export-btn:hover {
    border-color: #28a745;
    color: #28a745;
}

.delete-btn:hover {
    border-color: #dc3545;
    color: #dc3545;
}

/* 动画 */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .chat-settings {
        width: 280px;
    }
}

@media (max-width: 768px) {
    /* 移动端隐藏桌面端导航栏 */
    .header {
        display: none;
    }
    
    /* 移动端页面布局重置 */
    body {
        padding-top: 0; /* 移除桌面端的导航栏padding */
    }
    
    .chat-container {
        flex-direction: column;
        height: 100vh;
        width: 100%;
        position: relative;
    }
    
    /* 移动端隐藏聊天侧边栏，使用顶部导航 */
    .chat-sidebar {
        display: none;
    }
    
    /* 移动端聊天头部导航 */
    .chat-mobile-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 7px 10px;
        background: #fff;
        border-bottom: 1px solid #e0e0e0;
        height: 60px;
        flex-shrink: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .chat-mobile-nav-left {
        display: flex;
        flex: 0 0 46px;
        align-items: center;
        justify-content: flex-start;
    }
    
    .chat-back-btn {
        width: 46px;
        height: 46px;
        padding: 0;
        border: none;
        background: none;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 12px;
        color: #333;
        cursor: pointer;
        transition: background-color 0.2s;
        /* 确保移动端可点击 */
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
        position: relative;
        z-index: 10;
    }
    
    .chat-back-btn:hover {
        background: #f5f5f5;
    }

    .chat-mobile-brand-logo {
        display: block;
        width: 42px;
        height: 42px;
        object-fit: contain;
        transform: translateY(3px);
    }
    
    .chat-mobile-title {
        display: flex;
        flex-direction: column;
        align-items: center;
        flex: 1;
        text-align: center;
    }
    
    .chat-character-name {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0;
        max-width: 200px; /* 限制最大宽度 */
        white-space: nowrap; /* 不换行 */
        overflow: hidden; /* 隐藏溢出内容 */
        text-overflow: ellipsis; /* 显示省略号 */
    }
    
    .chat-session-label {
        display: none; /* 隐藏会话标签 */
    }

    /* 搜索模式：整个导航栏变成搜索栏 */
    .chat-mobile-search { 
        display: none; 
        padding: 10px 12px; 
        align-items: center; 
        gap: 10px; 
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        background: #fff;
        z-index: 1000;
        height: 64px;
        box-sizing: border-box;
    }
    .chat-mobile-search.show { 
        display: flex !important; 
    }

    /* 搜索模式下隐藏原导航内容 */
    .chat-mobile-header.search-mode .chat-mobile-back-btn,
    .chat-mobile-header.search-mode .chat-mobile-title,
    .chat-mobile-header.search-mode .chat-mobile-nav-right {
        opacity: 0;
        visibility: hidden;
    }

    .mobile-search-back-btn { 
        width: 36px; 
        height: 36px; 
        border: none; 
        background: none; 
        border-radius: 8px; 
        color: #666; 
        font-size: 16px; 
        display: inline-flex; 
        align-items: center; 
        justify-content: center; 
        cursor: pointer;
    }
    .mobile-search-back-btn:hover { background: #f5f5f5; color: #333; }

    .mobile-header-search-box { 
        flex: 1; 
        display: flex; 
        align-items: center; 
        gap: 8px; 
        background: #f1f3f5; 
        border-radius: 12px; 
        padding: 10px 12px; 
    }
    .mobile-header-search-box i { color: #6c757d; font-size: 16px; }
    #mobileHeaderSearchInput { 
        flex: 1; 
        border: none; 
        outline: none; 
        background: transparent; 
        font-size: 16px; 
        color: #333; 
    }
    
    .chat-mobile-nav-right {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        gap: 8px;
        margin-left: auto;
    }

    .mobile-chat-user-menu {
        order: 20;
    }

    .mobile-chat-user-menu .user-dropdown {
        top: calc(100% + 8px);
        right: -4px;
        margin-top: 0;
    }
    
    .chat-settings-btn {
        display: none; /* 移动端隐藏原有设置按钮 */
    }
    
    .chat-mobile-settings-btn {
        width: 32px;
        height: 32px;
        border: none;
        background: none;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
        color: #666;
        cursor: pointer;
        transition: all 0.2s;
        font-size: 14px;
        /* 确保移动端可点击 */
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
        position: relative;
        z-index: 10;
    }
    
    .chat-mobile-settings-btn:hover {
        background: #f5f5f5;
        color: #333;
    }
    
    .chat-user-avatar {
        width: 42px;
        height: 42px;
        border: none;
        background: none;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        cursor: pointer;
    }
    
    .chat-user-avatar img {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        border: 1px solid #e5dda0;
        background: #fbfae9;
        object-fit: contain;
        padding: 2px;
    }
    
    .chat-list {
        display: flex;
        padding: 6px 12px;
        gap: 8px;
        align-items: center;
    }
    
    .chat-item {
        flex-shrink: 0;
        min-width: 160px;
        padding: 8px 12px;
        border-radius: 8px;
    }
    
    .chat-item .chat-avatar img {
        width: 28px;
        height: 28px;
    }
    
    .chat-item .chat-name {
        font-size: 13px;
        font-weight: 500;
    }
    
    .chat-item .chat-preview {
        font-size: 11px;
        margin-top: 2px;
    }
    
    /* 主聊天区域优化 */
    .chat-main {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        height: calc(var(--vh, 1vh) * 100);
        /* 为固定底部输入区域预留空间 */
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
        margin-top: 56px; /* 为固定导航栏留出空间 */
    }
    
    .chat-header {
        display: none; /* 移动端隐藏原有聊天头部，使用移动端专用导航 */
    }
    
    /* 消息区域优化 - 参考竞品设计 */
    .chat-messages {
        flex: 1;
        padding: 16px;
        overflow-y: auto;
        min-height: 0;
        background: #f8f9fa;
    }

    /* 为避免底部固定输入栏遮挡最后一条气泡，增加底部内边距
       具体值会在JS中根据输入栏高度动态调整，这里提供保守默认值 */
    .chat-messages {
        padding-bottom: calc(120px + env(safe-area-inset-bottom));
    }

    /* 移动端：仅保留气泡本体，移除外层容器视觉层 */
    .message.ai-message .message-content,
    .message.user-message .message-content {
        background: transparent;
        box-shadow: none;
        border: none;
        padding: 0;
    }
    
    .message {
        max-width: 100%;
        margin-bottom: 20px;
        display: flex;
        align-items: flex-start;
        gap: 12px;
    }
    
    .message.user-message {
        flex-direction: row-reverse;
        margin-left: 20%;
    }
    
    .message.ai-message {
        margin-right: 20%;
    }
    
    .message-avatar {
        flex-shrink: 0;
    }
    
    .message-avatar img {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        border: 2px solid #fff;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .message-block {
        flex: 1;
        min-width: 0;
    }
    
    .message-text {
        background: #fff;
        padding: 12px 16px;
        border-radius: 18px;
        font-size: 16px; /* 与桌面端保持一致 */
        line-height: 1.8; /* 与桌面端保持一致 */
        font-weight: 400; /* 添加字体粗细，与桌面端一致 */
        color: #333;
        box-shadow: none; /* 移动端与桌面区分：移除阴影 */
        border: 1px solid #eee; /* 以浅边框代替阴影层次 */
        margin-bottom: 2px; /* 让操作按钮更贴近气泡 */
        word-wrap: break-word;
    }
    
    .user-message .message-text {
        background: #007bff;
        color: #fff;
        border: none; /* 深色气泡不需要边框 */
        border-bottom-right-radius: 6px;
    }
    
    .ai-message .message-text {
        background: #fff;
        color: #333;
        border-color: #e6e6e6; /* AI气泡使用更浅的边框 */
        border-bottom-left-radius: 6px;
    }
    
    .message-actions {
        margin-top: 2px; /* 更贴近气泡 */
        gap: 4px; /* 缩小按钮间距 */
        opacity: 0; /* 默认透明隐藏 */
        transition: opacity 0.3s ease-in-out; /* 淡入淡出动画 */
        display: flex; /* 保留布局空间 */
        pointer-events: none; /* 隐藏时禁用点击 */
    }

    /* 移动端：点击行显示操作按钮 */
    .message.show-actions .message-actions {
        opacity: 1; /* 淡入显示 */
        pointer-events: auto; /* 恢复点击功能 */
    }
    
    
    .message-actions button {
        font-size: 10px;
        width: 20px;
        height: 20px;
        min-height: 20px;
        min-width: 20px;
        padding: 0;
        background: rgba(0,0,0,0.05);
        border: none;
        border-radius: 4px;
        color: #666;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    
    /* 输入区域优化 - 参考竞品设计 */
    .chat-input-area {
        padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
        background: #fff;
        border-top: 1px solid #e0e0e0;
        flex-shrink: 0;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 999;
        transition: transform 0.3s ease, box-shadow 0.3s ease;
        /* 恢复显示输入区域（移动端也显示） */
    }
    
    /* 键盘焦点状态 */
    .chat-input-area.keyboard-active {
        box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
    }
    
    /* 键盘弹出状态 */
    .chat-input-area.keyboard-visible {
        position: fixed !important;
        bottom: 0 !important;
        z-index: 1000 !important;
        transform: translateY(0);
    }
    
    .message-input-container {
        display: flex;
        align-items: flex-end;
        gap: 12px;
        background: #f8f9fa;
        border-radius: 24px;
        padding: 6px;
        border: 1px solid #e0e0e0;
        transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
    }
    
    .message-input-container:focus-within {
        border-color: #007bff;
        background: #fff;
        box-shadow: 0 2px 8px rgba(0, 123, 255, 0.15);
    }
    
    .message-input {
        flex: 1;
        font-size: 16px; /* 与桌面端保持一致 */
        font-weight: 400; /* 添加字体粗细 */
        padding: 10px 16px;
        min-height: 36px;
        max-height: 120px;
        border: none;
        background: transparent;
        border-radius: 18px;
        resize: none;
        outline: none;
        color: #333;
        line-height: 1.6; /* 与桌面端保持一致 */
        transition: color 0.3s ease;
    }
    
    .message-input:focus {
        color: #333;
    }
    
    .message-input::placeholder {
        color: #999;
        font-size: 16px; /* 与输入文字保持一致 */
    }
    
    .send-btn {
        width: 36px;
        height: 36px;
        border-radius: 18px;
        font-size: 14px;
        flex-shrink: 0;
        background: #007bff;
        color: #fff;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background-color 0.2s;
    }
    
    .send-btn:hover {
        background: #0056b3;
    }
    
    .send-btn:disabled {
        background: #ccc;
        cursor: not-allowed;
    }
    
    /* 语音按钮样式已删除 */
    
    /* 设置面板在移动端完全隐藏 */
    .chat-settings {
        display: none !important;
    }
    
    /* 移动端角色选择界面 */
    .mobile-character-overlay {
        position: fixed;
        top: 56px; /* 从导航栏下方开始 */
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 999; /* 低于导航栏 */
        visibility: hidden;
        /* 移除背景遮罩和淡入淡出效果 */
        /* 确保移动端可点击 */
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        /* 隐藏时不拦截事件，避免影响顶部导航等交互 */
        pointer-events: none;
    }
    
    .mobile-character-overlay.show {
        visibility: visible;
        /* 仅在显示时启用交互 */
        pointer-events: auto;
    }
    
    .mobile-character-panel {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: #fff;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        box-shadow: 2px 0 8px rgba(0,0,0,0.15); /* 添加右侧阴影 */
    }
    
    .mobile-character-overlay.show .mobile-character-panel {
        transform: translateX(0);
    }
    
    /* 当需要立即显示角色选择时，隐藏聊天主界面 */
    body.show-character-select .chat-main,
    body.show-character-select .chat-sidebar {
        display: none !important;
    }
    
    /* 移动端导航栏按钮组 */
    .chat-mode-buttons,
    .character-mode-buttons {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .mobile-char-search-btn {
        width: 40px;
        height: 40px;
        border: none;
        background: none;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        color: #333;
        cursor: pointer;
        transition: background-color 0.2s;
        font-size: 16px;
    }
    
    .mobile-char-search-btn:hover {
        background: #f5f5f5;
    }
    
    .mobile-character-content {
        flex: 1;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        height: calc(100vh - 56px); /* 减去导航栏高度 */
    }
    
    .mobile-character-search {
        padding: 16px 20px;
        background: #f8f9fa;
        border-bottom: 1px solid #e0e0e0;
        flex-shrink: 0;
        display: none; /* 默认隐藏搜索框 */
        transition: all 0.3s ease;
    }
    
    .mobile-character-search.show {
        display: block;
    }
    
    .mobile-search-input-container {
        position: relative;
        display: flex;
        align-items: center;
    }
    
    .mobile-search-input-container i {
        position: absolute;
        left: 12px;
        color: #999;
        font-size: 14px;
        z-index: 1;
    }
    
    .mobile-character-search-input {
        width: 100%;
        padding: 12px 16px 12px 40px;
        border: 1px solid #e0e0e0;
        border-radius: 24px;
        font-size: 15px;
        background: #fff;
        color: #333;
        outline: none;
        transition: all 0.2s;
    }
    
    .mobile-character-search-input:focus {
        border-color: #007bff;
        box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    }
    
    .mobile-character-search-input::placeholder {
        color: #999;
    }
    
    .mobile-character-list {
        flex: 1;
        padding: 8px 0;
        overflow-y: auto;
    }
    
    .mobile-character-item {
        display: flex;
        align-items: center;
        padding: 12px 20px;
        border-bottom: 1px solid #f5f5f5;
        cursor: pointer;
        transition: background-color 0.2s;
        min-height: 72px;
    }
    
    .mobile-character-item:hover {
        background: #f8f9fa;
    }
    
    .mobile-character-item:last-child {
        border-bottom: none;
    }
    
    .mobile-character-item.active {
        background: #e3f2fd;
        border-left: 4px solid #007bff;
    }
    
    .mobile-character-avatar {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        margin-right: 12px;
        flex-shrink: 0;
        object-fit: cover;
        border: 2px solid #fff;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .mobile-character-info {
        flex: 1;
        min-width: 0;
    }
    
    .mobile-character-name {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0 0 4px 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .mobile-character-preview {
        font-size: 13px;
        color: #666;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.3;
    }
    
    .mobile-character-time {
        font-size: 11px;
        color: #999;
        margin-top: 2px;
        white-space: nowrap;
    }
    
    .mobile-character-meta {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 4px;
        flex-shrink: 0;
        margin-left: 8px;
    }
    
    .mobile-character-meta .mobile-character-time {
        text-align: right;
        margin-top: 0;
    }
    
    .mobile-add-character {
        padding: 16px 20px;
        border-top: 1px solid #e0e0e0;
        background: #f8f9fa;
        flex-shrink: 0;
    }
    
    .mobile-add-character-btn {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 14px 20px;
        border: 2px dashed #ccc;
        border-radius: 12px;
        background: transparent;
        color: #666;
        font-size: 15px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s;
        /* 确保移动端可点击 */
        -webkit-tap-highlight-color: rgba(0,123,255,0.1);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
        position: relative;
        z-index: 10;
    }
    
    .mobile-add-character-btn:hover {
        border-color: #007bff;
        color: #007bff;
        background: rgba(0, 123, 255, 0.05);
    }
    
    .mobile-add-character-btn i {
        font-size: 16px;
    }

    /* 移动端满屏设置面板 */
    .mobile-settings-overlay {
        position: fixed;
        top: 56px; /* 从导航栏下方开始 */
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1002; /* 高于聊天输入区，低于导航栏 */
        visibility: hidden;
        /* 移除背景遮罩和淡入淡出效果 */
        /* 确保移动端可点击 */
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        /* 隐藏时不拦截事件 */
        pointer-events: none;
    }
    
    .mobile-settings-overlay.show {
        visibility: visible !important;
        display: block !important;
        /* 确保安全区域适配 */
        top: calc(56px + env(safe-area-inset-top));
        padding-bottom: env(safe-area-inset-bottom);
        /* 显示时允许交互 */
        pointer-events: auto;
    }
    
    .mobile-settings-panel {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: #fff;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        box-shadow: -2px 0 8px rgba(0,0,0,0.15); /* 添加左侧阴影 */
    }
    
    .mobile-settings-overlay.show .mobile-settings-panel {
        transform: translateX(0);
    }
    
    .mobile-settings-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        border-bottom: 1px solid #e0e0e0;
        background: #fff;
        flex-shrink: 0;
        height: 56px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    
    .mobile-settings-header h2 {
        font-size: 18px;
        font-weight: 600;
        color: #333;
        margin: 0;
    }
    
    .mobile-settings-close {
        width: 36px;
        height: 36px;
        border: none;
        background: none;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        color: #666;
        cursor: pointer;
        transition: all 0.2s;
        font-size: 16px;
    }
    
    .mobile-settings-close:hover {
        background: #f5f5f5;
        color: #333;
    }
    
    .mobile-settings-content {
        flex: 1;
        overflow-y: auto;
        padding: 0;
    }
    
    .mobile-setting-group {
        margin-bottom: 24px;
    }
    
    .mobile-setting-group-title {
        font-size: 14px;
        font-weight: 600;
        color: #666;
        margin: 0 0 12px 0;
        padding: 0 20px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .mobile-setting-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        border-bottom: 1px solid #f5f5f5;
        cursor: pointer;
        transition: background-color 0.2s;
        min-height: 60px;
    }
    
    .mobile-setting-item:hover {
        background: #f8f9fa;
    }
    
    .mobile-setting-item:last-child {
        border-bottom: none;
    }
    
    .mobile-setting-label {
        display: flex;
        align-items: center;
        gap: 12px;
        flex: 1;
    }
    
    .mobile-setting-label i {
        font-size: 16px;
        color: #666;
        width: 20px;
        text-align: center;
    }
    
    .mobile-setting-label span {
        font-size: 16px;
        color: #333;
        font-weight: 500;
    }
    
    /* 移动端切换开关 */
    .mobile-toggle-switch {
        position: relative;
        width: 50px;
        height: 28px;
        flex-shrink: 0;
    }
    
    .mobile-toggle-switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }
    
    .mobile-toggle-slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #ccc;
        transition: 0.3s;
        border-radius: 28px;
    }
    
    .mobile-toggle-slider:before {
        position: absolute;
        content: "";
        height: 22px;
        width: 22px;
        left: 3px;
        bottom: 3px;
        background-color: white;
        transition: 0.3s;
        border-radius: 50%;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }
    
    .mobile-toggle-switch input:checked + .mobile-toggle-slider {
        background-color: #ff6b6b;
    }
    
    .mobile-toggle-switch input:checked + .mobile-toggle-slider:before {
        transform: translateX(22px);
    }
    
    /* 移动端会话标题输入框 */
    .mobile-session-input {
        width: 100%;
        padding: 12px 16px;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        font-size: 16px;
        background: #f8f9fa;
        color: #333;
        outline: none;
        transition: all 0.2s;
    }
    
    .mobile-session-input:focus {
        border-color: #007bff;
        background: #fff;
        box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    }
    
    .mobile-session-input::placeholder {
        color: #999;
    }
    
    /* 移动端设置选择框 */
    .mobile-setting-select {
        width: 100%;
        padding: 12px 16px;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        font-size: 16px;
        background: #f8f9fa;
        color: #333;
        outline: none;
        transition: all 0.2s;
        appearance: none;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
        background-position: right 12px center;
        background-repeat: no-repeat;
        background-size: 16px;
        padding-right: 40px;
    }
    
    .mobile-setting-select:focus {
        border-color: #007bff;
        background-color: #fff;
        box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    }
    
    /* 移动端设置输入框 */
    .mobile-setting-input {
        width: 100%;
        padding: 12px 16px;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        font-size: 16px;
        background: #f8f9fa;
        color: #333;
        outline: none;
        transition: all 0.2s;
    }
    
    .mobile-setting-input:focus {
        border-color: #007bff;
        background: #fff;
        box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    }
    
    .mobile-setting-input::placeholder {
        color: #999;
    }
    
    /* 移动端固定删除会话按钮区域 */
    .mobile-delete-session-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid #e0e0e0;
        padding: 16px;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
        z-index: 1000;
        display: none; /* 默认隐藏 */
    }
    
    /* 当设置面板显示时，显示删除按钮 */
    .mobile-settings-overlay.show .mobile-delete-session-footer {
        display: block;
    }
    
    /* 为设置内容添加底部间距，避免被固定按钮遮挡 */
    .mobile-settings-overlay.show .mobile-settings-content {
        padding-bottom: 100px; /* 为固定按钮留出空间 */
    }
    
    .mobile-delete-session-btn {
        width: 100%;
        padding: 16px;
        background: #fff;
        color: #666;
        border: 1px solid #e0e0e0;
        border-radius: 12px;
        font-size: 16px;
        font-weight: 400;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        transition: all 0.2s;
        cursor: pointer;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    .mobile-delete-session-btn:hover {
        background: #f8f9fa;
        border-color: #d0d0d0;
        transform: translateY(-1px);
        box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    }
    
    .mobile-delete-session-btn:active {
        transform: translateY(0);
        background: #f0f0f0;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    .mobile-delete-session-btn i {
        font-size: 18px;
    }
    
    .settings-header {
        padding: 16px;
        border-bottom: 1px solid #e0e0e0;
    }
    
    .settings-header h3 {
        font-size: 16px;
        margin: 0;
    }
    
    .settings-content {
        padding: 16px;
    }
    
    .setting-item {
        padding: 12px 0;
        border-bottom: 1px solid #f5f5f5;
    }
    
    .setting-label {
        font-size: 14px;
    }
    
    /* 操作按钮优化 */
    .chat-actions {
        padding: 8px 12px;
        gap: 8px;
    }
    
    .action-btn {
        padding: 8px 12px;
        font-size: 12px;
        min-width: auto;
    }
}

@media (max-width: 480px) {
    /* 小屏手机优化 */
    .chat-sidebar {
        height: 48px;
    }
    
    .chat-list {
        padding: 4px 8px;
        gap: 6px;
    }
    
    .chat-item {
        min-width: 140px;
        padding: 6px 10px;
    }
    
    .chat-item .chat-avatar img {
        width: 24px;
        height: 24px;
    }
    
    .chat-item .chat-name {
        font-size: 12px;
    }
    
    .chat-item .chat-preview {
        font-size: 10px;
    }
    
    /* 消息区域小屏优化 */
    .chat-messages {
        padding: 10px 12px;
    }
    
    .message {
        margin-bottom: 12px;
    }
    
    .message-avatar img {
        width: 24px;
        height: 24px;
    }
    
    .message-text {
        font-size: 16px; /* 与桌面端保持一致 */
        font-weight: 400; /* 添加字体粗细，与桌面端一致 */
        line-height: 1.8; /* 与桌面端保持一致 */
        padding: 8px 12px;
    }
    
    .message-actions {
        margin-top: 2px; /* 更贴近气泡 */
        gap: 4px;
        opacity: 0; /* 默认透明隐藏 */
        transition: opacity 0.3s ease-in-out; /* 淡入淡出动画 */
        display: flex; /* 保留布局空间 */
        pointer-events: none; /* 隐藏时禁用点击 */
    }

    .message.show-actions .message-actions {
        opacity: 1; /* 淡入显示 */
        pointer-events: auto; /* 恢复点击功能 */
    }
    
    .message-actions button {
        font-size: 9px;
        width: 18px;
        height: 18px;
        min-height: 18px;
        min-width: 18px;
        padding: 0;
        background: rgba(0,0,0,0.05);
        border: none;
        border-radius: 3px;
        color: #666;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    
    /* 输入区域小屏优化 */
    .chat-input-area {
        padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    }
    
    .message-input {
        font-size: 16px; /* 与桌面端保持一致 */
        font-weight: 400; /* 添加字体粗细 */
        line-height: 1.6; /* 与桌面端保持一致 */
        padding: 10px 14px;
        min-height: 40px;
        border-radius: 20px;
    }
    
    .send-btn {
        width: 40px;
        height: 40px;
        border-radius: 20px;
        font-size: 14px;
    }
    
    /* 设置面板小屏优化 */
    .chat-settings.show {
        width: 100% !important;
    }
    
    .settings-header {
        padding: 12px;
    }
    
    .settings-header h3 {
        font-size: 15px;
    }
    
    .settings-content {
        padding: 12px;
    }
    
    .setting-item {
        padding: 10px 0;
    }
    
    .setting-label {
        font-size: 13px;
    }
    
    .toggle-switch {
        transform: scale(0.9);
    }
    
    /* 操作按钮小屏优化 */
    .chat-actions {
        padding: 6px 8px;
        gap: 6px;
    }
    
    .action-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    /* 编辑模态框小屏优化 */
    .edit-modal .modal-content {
        margin: 20px;
        max-height: calc(100vh - 40px);
    }
    
    .edit-textarea {
        min-height: 120px;
        font-size: 14px;
    }
    
    .edit-actions {
        gap: 8px;
    }
    
    .edit-actions .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar,
.chat-list::-webkit-scrollbar,
.settings-content::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-list::-webkit-scrollbar-track,
.settings-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-list::-webkit-scrollbar-thumb,
.settings-content::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-list::-webkit-scrollbar-thumb:hover,
.settings-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* 编辑消息模态框样式 */
.edit-modal {
    max-width: 600px !important;
    width: 90% !important;
}

.edit-textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    font-family: inherit;
    background: #fff;
}

.edit-textarea:focus {
    outline: none;
    border-color: #ff6b6b;
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.1);
}

.edit-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

.edit-actions .btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.edit-actions .btn-secondary {
    background: #f5f5f5;
    color: #666;
}

.edit-actions .btn-secondary:hover {
    background: #e0e0e0;
}

.edit-actions .btn-primary {
    background: #ff6b6b;
    color: white;
}

.edit-actions .btn-primary:hover {
    background: #ff5252;
}
