/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

:root {
    /* 浅色模式控制 */
    --primary-color: #4a90d9;
    --primary-hover: #3a7bc8;
    --secondary-color: #f5f7fa;
    --background-color: #ffffff;
    --sidebar-bg: #f8f9fb;
    --border-color: #e8ecf1;
    --text-primary: #2c3e50;
    --text-secondary: #6b7c93;
    --text-muted: #9ba6b5;
    
    /* 个性化主题颜色 - 由用户选择的主题控制 */
    --theme-primary: #4a90d9;
    --theme-primary-hover: #3a7bc8;
    
    /* 消息气泡颜色 - 使用个性化主题颜色 */
    --user-message-bg: var(--theme-primary);
    --user-message-text: #ffffff;
    --user-message-theme-color: var(--theme-primary);  /* 保持向后兼容 */
    --assistant-message-bg: #f0f2f5;
    --assistant-message-text: #2c3e50;
    --input-bg: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --sidebar-width: 260px;
    --header-height: 60px;
    --input-area-height: 100px;

    /* 字号变量 */
    --font-size-small: 12px;
    --font-size-medium: 14px;
    --font-size-large: 16px;
    --font-size-xlarge: 18px;

    /* 当前字号（默认中号） */
    --current-font-size: var(--font-size-medium);

    /* 消息气泡变量 - 用于Shadow DOM */
    --msg-bg: #f0f2f5;
    --msg-radius: 12px;
    --msg-margin: 8px 0;
    --msg-padding: 12px 16px;
    --thought-height: 300px;
    --thought-bg: rgba(74, 144, 217, 0.05);
}

/* 主题色配置 - 简化的主题系统 */
/* 注意：主题颜色由JS动态应用，这里只保留基础变量 */

/* 字号配置 */
[data-font-size="small"] {
    --current-font-size: var(--font-size-small);
}

[data-font-size="medium"] {
    --current-font-size: var(--font-size-medium);
}

[data-font-size="large"] {
    --current-font-size: var(--font-size-large);
}

[data-font-size="xlarge"] {
    --current-font-size: var(--font-size-xlarge);
}

/* 深色主题变量 */
[data-theme="dark"] {
    --secondary-color: #1a1a2e;
    --background-color: #0f0f1a;
    --sidebar-bg: #16162a;
    --border-color: #2a2a4a;
    --text-primary: #e4e8f1;
    --text-secondary: #a0a8c0;
    --text-muted: #6b7280;
    --assistant-message-bg: #1e1e3a;
    --assistant-message-text: #e4e8f1;
    --input-bg: #1e1e3a;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: var(--current-font-size);
    overflow: hidden;
    overscroll-behavior: none;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    /* 移动端安全区域 */
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

#app {
    display: flex;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

/* 侧边栏样式 */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease;
    overflow: hidden;
    position: relative;
    height: 100vh;
    height: 100dvh;
}

.sidebar.collapsed {
    width: 70px;
}

.sidebar-header {
    padding: 12px 12px;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.brand-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 1px;
}

.sidebar.collapsed .sidebar-brand {
    display: flex;
    margin: 0 auto;
}

.sidebar.collapsed .brand-name {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    padding: 8px;
    border-bottom: none;
    justify-content: center;
}

.sidebar.collapsed .toggle-sidebar-btn {
    display: none;
}

.sidebar.collapsed .brand-logo {
    width: 40px;
    height: 40px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 12px;
    padding: 6px;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.sidebar.collapsed .brand-logo:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    transform: translateY(-1px);
}

.toggle-sidebar-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ba6b5;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: none;
}

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

.toggle-sidebar-btn:hover {
    color: #6b7c93;
    background-color: transparent;
    box-shadow: none;
    transform: none;
}

.sidebar.collapsed .toggle-sidebar-btn:hover {
    background-color: var(--theme-primary-hover);
}

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

.sidebar.collapsed .toggle-icon {
    transform: rotate(180deg);
}

.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* 用户卡片样式 */
.user-card {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 16px;
    margin: 8px 12px;
    background-color: var(--secondary-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.user-card:hover {
    background-color: var(--secondary-color);
    border-color: var(--primary-color);
}

.sidebar.collapsed .user-card {
    padding: 8px;
    justify-content: center;
    background-color: transparent;
    box-shadow: none;
    border-radius: 0;
    border: none;
    margin-top: auto;  /* 固定在底部 */
}

.sidebar.collapsed .user-card:hover {
    box-shadow: none;
    transform: none;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    font-size: 24px;
    overflow: hidden;
}

.user-avatar:hover {
    transform: scale(1.05);
    color: #667eea;
}

.sidebar.collapsed .user-avatar {
    width: 36px;
    height: 36px;
    background-color: transparent;
    font-size: 20px;
}

.sidebar.collapsed .user-avatar:hover {
    transform: scale(1.05);
    color: #667eea;
}

.avatar-icon {
    font-size: 20px;
}

.sidebar.collapsed .avatar-icon {
    font-size: 18px;
}

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

.sidebar.collapsed .user-info {
    display: none;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 4px;
    cursor: text;
    transition: background-color 0.2s ease;
}

.user-name:hover {
    background-color: var(--secondary-color);
}

.user-name:focus {
    outline: none;
    background-color: var(--secondary-color);
    box-shadow: 0 0 0 2px var(--primary-color);
}

.user-status {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}

/* 头像选择弹窗 */
.avatar-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.avatar-popup.show {
    display: flex !important;
}

.avatar-popup-content {
    background-color: var(--background-color);
    border-radius: 16px;
    padding: 24px;
    width: 95%;
    max-width: 480px;
    box-shadow: 0 20px 60px var(--shadow-color);
}

.avatar-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.avatar-popup-close {
    width: 32px;
    height: 32px;
    border: none;
    background-color: transparent;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.avatar-popup-close:hover {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.avatar-option {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--secondary-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    font-size: 26px;
    line-height: 1;
}

.avatar-option svg {
    width: 26px;
    height: 26px;
    stroke: var(--text-secondary);
    fill: none;
    stroke-width: 1.5;
}

.avatar-option:hover {
    background-color: var(--secondary-color);
    transform: scale(1.05);
}

.avatar-option.selected {
    border-color: var(--primary-color);
    background-color: rgba(74, 144, 217, 0.1);
}

/* 自定义头像上传按钮样式 */
.avatar-option[data-avatar="custom"] {
    background-color: var(--secondary-color);
    border: 2px dashed var(--border-color);
}

.avatar-option[data-avatar="custom"]:hover {
    border-color: var(--primary-color);
    background-color: rgba(74, 144, 217, 0.1);
}

.avatar-option[data-avatar="custom"] svg {
    width: 24px;
    height: 24px;
    stroke: var(--text-secondary);
    stroke-width: 1.5;
}

.avatar-option[data-avatar="custom"] svg {
    width: 28px;
    height: 28px;
    font-size: 28px;
    color: var(--text-secondary);
}

/* 头像提示文字 */
.avatar-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* 自定义头像图片样式 */
.avatar-custom-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.user-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background-color: #4ade80;
    border-radius: 50%;
}

.sidebar-section {
    padding: 12px;
    display: flex;
    flex-direction: column;
}

.sidebar-section:first-child {
    padding-bottom: 8px;
}

/* 第一个 section（新建对话）需要居中按钮 */
.sidebar-section:first-child {
    align-items: center;
}

/* 【新增】搜索框样式 */
.search-box {
    padding: 0 8px 8px;
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
    background-color: var(--background-color);
    outline: none;
    transition: border-color 0.2s ease;
}

.search-input:focus {
    border-color: var(--primary-color);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 8px;
    padding: 0 8px;
    white-space: nowrap;
}

.sidebar.collapsed .section-title {
    display: none;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--theme-primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    -webkit-appearance: none;
    appearance: none;
}

.new-chat-btn:hover {
    background-color: var(--theme-primary-hover);
}

.new-chat-btn:active {
    transform: scale(0.98);
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.btn-icon {
    font-size: 18px;
    font-weight: bold;
    flex-shrink: 0;
}

.btn-text {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.sidebar.collapsed .btn-text {
    display: none;
}

.sidebar.collapsed .new-chat-btn {
    display: none;
}

.chat-history-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-top: 8px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
    min-height: 0;
}

.chat-history-item {
    padding: 4px 12px;
    margin-bottom: 2px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease;
    box-sizing: border-box;
    min-height: 24px;
    height: 24px;
    line-height: 16px;
}

.chat-history-item:hover {
    background-color: rgba(74, 144, 217, 0.1);
}

.chat-history-item.active {
    background-color: rgba(74, 144, 217, 0.15);
    color: var(--primary-color);
}

.chat-history-icon {
    width: 16px;
    height: 16px;
    background-color: var(--secondary-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    flex-shrink: 0;
}

.chat-history-title {
    flex: 1;
    overflow: hidden;
    /* 【修改】限制最多显示12个汉字 */
    max-width: 180px;
    white-space: nowrap;
    text-overflow: clip;
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 4px;
    /* 【修改】改为pointer指针，提示可点击 */
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.chat-history-title:hover {
    background-color: var(--secondary-color);
}

.sidebar.collapsed .chat-history-icon {
    margin: 0 auto;
}

.sidebar.collapsed .chat-history-section {
    display: none;
}

.sidebar.collapsed .chat-history-item {
    padding: 10px;
    justify-content: center;
}

.sidebar.collapsed .chat-history-item span:not(.chat-history-icon),
.sidebar.collapsed .chat-history-actions {
    display: none;
}

/* 历史对话更多操作按钮 */
.chat-history-actions {
    flex-shrink: 0;
    opacity: 1;
    visibility: visible;
}

.chat-history-more-btn {
    width: 24px;
    height: 24px;
    border: none;
    background-color: transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-muted);
    opacity: 1;
    transition: all 0.2s ease;
}

.chat-history-more-btn:hover {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.chat-history-more-btn.active {
    background-color: var(--secondary-color);
    color: var(--primary-color);
}

/* 下拉菜单样式 */
.chat-history-dropdown {
    position: fixed;
    min-width: 140px;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow-color);
    padding: 6px;
    z-index: 5000;
    display: none;
}

.chat-history-dropdown.show {
    display: block;
}

.chat-history-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.chat-history-dropdown-item:hover {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.chat-history-dropdown-item.danger {
    color: #e74c3c;
}

.chat-history-dropdown-item.danger:hover {
    background-color: #fee2e2;
    color: #c0392b;
}

.chat-history-dropdown-item .item-icon {
    font-size: 14px;
    width: 16px;
    text-align: center;
}

.chat-history-dropdown-item .item-text {
    flex: 1;
}

/* 遮罩层用于关闭下拉菜单 */
.chat-history-dropdown-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99;
    display: none;
}

.chat-history-dropdown-backdrop.show {
    display: block;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    margin-top: auto;
    width: 100%;
    box-sizing: border-box;
    background-color: var(--sidebar-bg);
}

.settings-btn {
    width: 100%;
    padding: 10px 12px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.settings-btn:hover {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.settings-btn:active {
    background-color: rgba(74, 144, 217, 0.1);
}

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

.sidebar.collapsed .settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 8px;
    background-color: transparent;
    box-shadow: none;
    border: none;
}

.sidebar.collapsed .settings-btn:hover {
    background-color: transparent;
    box-shadow: none;
    transform: none;
}

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

.theme-toggle-btn {
    width: 100%;
    padding: 10px 12px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    margin-top: 8px;
}

.theme-toggle-btn:hover {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.theme-toggle-btn:active {
    background-color: rgba(74, 144, 217, 0.1);
}

.theme-toggle-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.sidebar.collapsed .theme-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 8px;
    background-color: transparent;
    box-shadow: none;
    border: none;
    margin-top: 8px;
}

.sidebar.collapsed .theme-toggle-btn:hover {
    background-color: transparent;
    box-shadow: none;
    transform: none;
}

.sidebar.collapsed .theme-toggle-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.sidebar.collapsed .theme-toggle-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.sidebar.collapsed .theme-text {
    display: none;
}

.theme-icon {
    font-size: 16px;
}

/* 关于按钮 */
.about-btn {
    width: 100%;
    padding: 10px 12px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    margin-top: 8px;
}

.about-btn:hover {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.about-btn:active {
    background-color: rgba(74, 144, 217, 0.1);
}

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

.sidebar.collapsed .about-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 8px;
    background-color: transparent;
    box-shadow: none;
    border: none;
    margin-top: 8px;
}

.sidebar.collapsed .about-btn:hover {
    background-color: transparent;
    box-shadow: none;
    transform: none;
}

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

.sidebar.collapsed .about-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* 关于弹窗 */
.about-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.about-popup.show {
    display: flex !important;
}

.about-popup-content {
    background-color: var(--background-color);
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 20px 60px var(--shadow-color);
}

.about-header-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.about-logo-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    display: block;
}

.about-name {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0;
}

.about-power {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 16px;
}

/* 主内容区域 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--background-color);
    min-width: 0;
    min-height: 0;
    height: 100%;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow: hidden;
    /* 确保能够正确计算高度 */
    box-sizing: border-box;
}

/* 头部样式 */
.header {
    height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: none;
    background-color: var(--background-color);
    flex-shrink: 0;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.menu-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: #fff;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #6b7c93;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.menu-btn:hover {
    background: #fff;
    color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    transform: translateY(-1px);
}

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

.menu-icon {
    font-size: 20px;
}

.action-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #6b7c93;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.action-btn:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    color: #667eea;
    transform: translateY(-1px);
}

/* 深色主题适配 */
[data-theme="dark"] .action-btn {
    background: #1e2432;
    color: #a0aec0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .action-btn:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.25);
    color: #667eea;
    background: #2d3748;
}

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

/* 遮罩层 */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* 聊天容器 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    min-height: 0;
    /* 确保中间区域能正确分配剩余空间 */
    height: 100%;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.welcome-logo {
    margin-bottom: 32px;
}

.welcome-logo-img {
    width: 100px;
    height: 100px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    opacity: 0.85;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
}

.logo-icon {
    display: none;
}

.welcome-tips {
    margin-bottom: 32px;
}

.welcome-tips p {
    font-size: 16px;
    color: var(--text-secondary);
    margin: 0;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    max-width: 600px;
    width: 100%;
}

.quick-action-btn {
    padding: 14px 12px;
    background-color: var(--secondary-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    text-align: center;
    min-width: 0;
    overflow: hidden;
}

.quick-action-btn:hover {
    background-color: rgba(74, 144, 217, 0.1);
    border-color: var(--primary-color);
}

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

.action-icon {
    font-size: 22px;
    flex-shrink: 0;
}

.action-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
    line-height: 1.3;
}

/* 消息容器 */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    padding-bottom: 80px;
    display: none;
    gap: 24px;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 0;
    /* 确保在消息容器内部滚动，而不是影响整个页面 */
    box-sizing: border-box;
    /* 强制开启硬件加速 */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    /* 【修复】允许垂直触摸滚动 */
    touch-action: pan-y;
}

.messages-container.has-messages {
    display: flex;
    /* 确保即使刚开始没有内容也有一定高度 */
    min-height: 100px;
}

/* 移动端消息容器滚动优化 */
@media (max-width: 768px) {
    /* 消息容器移动端样式已在 chat-container 中统一处理 */
}

.message {
    max-width: 1000px;
    margin: 0 auto 20px;
    display: flex;
    gap: 12px;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.message.assistant .message-avatar {
    background-color: #e8f4fd;
}

.message.user .message-avatar {
    background-color: var(--primary-color);
    color: white;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.6;
}

.message.assistant .message-content {
    background-color: var(--assistant-message-bg);
    color: var(--assistant-message-text);
    border-bottom-left-radius: 4px;
}

.message.user .message-content {
    background-color: var(--user-message-theme-color);
    color: var(--user-message-text);
    border-bottom-right-radius: 4px;
}

.message-content p {
    margin-bottom: 8px;
}

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

.message-content pre {
    background-color: #2d2d2d;
    color: #f8f8f2;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.message-content code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.message-content pre code {
    background-color: transparent;
    padding: 0;
}

/* 打字指示器 */
.typing-indicator {
    max-width: 1000px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

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

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

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

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

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

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
    }
    40% {
        transform: scale(1);
    }
}

.typing-text {
    font-size: 14px;
    color: var(--text-muted);
}

/* 输入区域 */
.input-area {
    padding: 16px 60px 24px;
    background-color: var(--background-color);
    border-top: none;
    flex-shrink: 0;
    max-width: 100%;
}

.input-container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--secondary-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 16px;
    transition: border-color 0.2s ease;
}

.input-container:focus-within {
    border-color: var(--primary-color);
}

.message-input {
    flex: 1;
    border: none;
    background-color: transparent;
    resize: none;
    font-size: 15px;
    line-height: 24px;
    max-height: 150px;
    outline: none;
    font-family: inherit;
    color: var(--text-primary);
    -webkit-appearance: none;
    appearance: none;
    padding: 0;
    min-height: 24px;
    display: flex;
    align-items: center;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.message-input:focus {
    outline: none;
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background-color: var(--theme-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--theme-primary-hover);
}

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

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

/* 文件上传按钮 */
.file-upload-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background-color: #fff;
    color: #6b7c93;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.file-upload-btn:hover {
    background-color: #f0f2f5;
    color: #667eea;
}

.file-upload-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* 深色主题适配 */
[data-theme="dark"] .file-upload-btn {
    background: #1e2432;
    color: #a0aec0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .file-upload-btn:hover {
    background: #2d3748;
    color: #667eea;
}

/* 文件预览区域 */
.file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: #f0f2f5;
    border-radius: 8px;
    max-width: 200px;
}

[data-theme="dark"] .file-preview {
    background-color: #2d3748;
}

.file-name {
    font-size: 13px;
    color: #6b7c93;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

[data-theme="dark"] .file-name {
    color: #a0aec0;
}

.file-remove {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background-color: #e74c3c;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

.file-remove:hover {
    background-color: #c0392b;
}

.send-icon {
    font-size: 16px;
}

.stop-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background-color: #dc3545;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
}

.stop-btn:hover {
    background-color: #c82333;
}

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

.stop-icon {
    font-size: 16px;
}

/* 【新增】字数统计样式 */
.char-count {
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 8px;
    white-space: nowrap;
}

/* 【新增】快捷指令建议样式 */
.suggestions-container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 12px;
    background-color: var(--secondary-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.suggestions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background-color: rgba(74, 144, 217, 0.08);
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-secondary);
}

.suggestions-close {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.suggestions-close:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
}

.suggestion-item {
    padding: 6px 12px;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.suggestion-item:hover {
    background-color: rgba(74, 144, 217, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.suggestion-item .icon {
    font-size: 14px;
}

.footer-copyright {
    text-align: center;
    margin-top: 12px;
    font-size: 11px;
    color: var(--text-muted);
}

/* 辅助功能：视觉隐藏但屏幕阅读器可读 */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--background-color);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px var(--shadow-color);
    overflow: hidden;
}



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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    color: #9ba6ab;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.close-btn:hover {
    background: #f0f2f5;
    color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.modal-body {
    padding: 0;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 设置标签页样式 */
.settings-tabs {
    display: flex;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--secondary-color);
    gap: 8px;
}

.settings-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    background-color: transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.settings-tab:hover {
    background-color: rgba(74, 144, 217, 0.1);
    color: var(--primary-color);
}

.settings-tab.active {
    background-color: var(--background-color);
    color: var(--primary-color);
    box-shadow: 0 2px 8px var(--shadow-color);
}

.tab-icon {
    font-size: 16px;
}

.tab-text {
    display: none;
}

@media (min-width: 400px) {
    .tab-text {
        display: inline;
    }
}

/* 设置卡片样式 */
.settings-card {
    display: none;
    padding: 24px;
}

.settings-card.active {
    display: block;
}

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

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.setting-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color 0.2s ease;
    background-color: var(--background-color);
}

.setting-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.setting-input::placeholder {
    color: var(--text-muted);
}

/* 下拉菜单样式 */
.setting-input[type="select"] {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

.setting-tips {
    margin-top: 16px;
    padding: 12px 16px;
    background-color: var(--secondary-color);
    border-radius: 8px;
}

.setting-tips p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* 字号选择器样式 */
.font-size-options {
    display: flex;
    gap: 10px;
    padding: 4px;
    background-color: var(--secondary-color);
    border-radius: 10px;
}

.font-size-btn {
    flex: 1;
    padding: 10px 8px;
    border: none;
    background-color: transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.font-size-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.font-size-btn.active {
    background-color: var(--background-color);
    box-shadow: 0 2px 8px var(--shadow-color);
}

.size-preview {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
}

.size-preview.small {
    font-size: 12px;
}

.size-preview.medium {
    font-size: 16px;
}

.size-preview.large {
    font-size: 20px;
}

.size-preview.xlarge {
    font-size: 26px;
}

/* 主题色选择器样式 */
.theme-color-options {
    display: flex;
    gap: 12px;
    padding: 4px;
    background-color: var(--secondary-color);
    border-radius: 10px;
}

.theme-color-btn {
    flex: 1;
    aspect-ratio: 1;
    max-width: 60px;
    border: none;
    background-color: var(--color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.theme-color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.theme-color-btn.active {
    box-shadow: 0 0 0 3px var(--background-color), 0 0 0 5px var(--primary-color);
}

.color-check {
    font-size: 18px;
    color: white;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.theme-color-btn.active .color-check {
    opacity: 1;
}

/* 头像布局模式选择器样式 */
.avatar-layout-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 4px;
    background-color: var(--secondary-color);
    border-radius: 10px;
}

.avatar-layout-btn {
    padding: 10px 6px;
    border: none;
    background-color: transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.avatar-layout-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.avatar-layout-btn.active {
    background-color: var(--background-color);
    box-shadow: 0 2px 8px var(--shadow-color);
}

.avatar-layout-btn .layout-icon {
    font-size: 20px;
    line-height: 1;
}

.avatar-layout-btn .layout-text {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

.avatar-layout-btn .layout-desc {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    display: none;
}

@media (min-width: 400px) {
    .avatar-layout-btn .layout-desc {
        display: block;
    }
}

/* 头像布局模式 - 紧凑模式 */
.avatar-layout-btn[data-layout="compact"] .layout-icon {
    font-size: 14px;
}

.avatar-layout-btn[data-layout="minimal"] .layout-icon {
    font-size: 12px;
}

/* 移动端头像布局模式适配 */
@media (max-width: 768px) {
    .avatar-layout-options {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .avatar-layout-btn {
        padding: 8px 4px;
    }
    
    .avatar-layout-btn .layout-text {
        font-size: 12px;
    }
    
    .avatar-layout-btn .layout-desc {
        display: none;
    }
}


/* 紧凑头像布局样式 */
[data-avatar-layout="compact"] .avatar {
    width: 24px !important;
    height: 24px !important;
    font-size: 12px !important;
}

[data-avatar-layout="compact"] .avatar-img {
    width: 100%;
    height: 100%;
}

[data-avatar-layout="compact"] .message {
    gap: 6px;
}

/* 极简头像布局样式 */
[data-avatar-layout="minimal"] .avatar {
    width: 12px !important;
    height: 12px !important;
    border-radius: 3px !important;
    font-size: 0 !important;
}

[data-avatar-layout="minimal"] .message {
    gap: 4px;
    align-items: center;
}

[data-avatar-layout="minimal"] .message.assistant .avatar {
    background-color: var(--primary-color);
}

[data-avatar-layout="minimal"] .message.user .avatar {
    background-color: var(--user-message-bg);
}

.iframe-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* 【新增】分享弹窗样式 */
.share-modal-content {
    max-width: 420px;
}

.share-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 24px;
}

.share-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: transparent;
}

.share-option:hover {
    border-color: var(--theme-primary);
    background-color: rgba(74, 144, 217, 0.05);
}

.share-option:active {
    transform: scale(0.98);
}

.share-icon {
    font-size: 32px;
}

.share-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.share-desc {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* 移动端分享弹窗适配 */
@media (max-width: 480px) {
    .share-options {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 16px;
    }
    
    .share-option {
        padding: 16px 12px;
    }
    
    .share-icon {
        font-size: 28px;
    }
    
    .share-label {
        font-size: 14px;
    }
    
    .share-desc {
        font-size: 11px;
    }
}

.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary {
    background-color: var(--secondary-color);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background-color: #e8ecf1;
    color: var(--text-primary);
}

.btn-primary {
    background-color: var(--theme-primary);
    border: none;
    color: white;
}

.btn-primary:hover {
    background-color: var(--theme-primary-hover);
}

/* iframe嵌入容器样式 */
.iframe-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--background-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px var(--shadow-color);
}

.iframe-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: var(--secondary-color);
    border-bottom: 1px solid var(--border-color);
}

.iframe-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.close-iframe-btn {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: none;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    color: #9ba6ab;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.close-iframe-btn:hover {
    background: #fee2e2;
    color: #ef4444;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15);
}

#ifify-iframe {
    flex: 1;
    width: 100%;
    height: calc(100% - 48px);
    border: none;
    background-color: var(--background-color);
}

.iframe-actions {
    display: flex;
    justify-content: flex-start;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .menu-btn {
        display: flex;
        min-width: 44px;
        min-height: 44px;
    }

    /* 移动端头部按钮优化 - 移除特效 */
    .menu-btn,
    .action-btn {
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
    }

    .menu-btn:hover,
    .action-btn:hover {
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
        color: inherit !important;
    }

    .menu-btn svg,
    .action-btn svg {
        width: 20px;
        height: 20px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 75%;
        max-width: 320px;
        height: 100vh;
        height: 100dvh;
        padding-bottom: env(safe-area-inset-bottom);
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        border-right: none;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        width: 75%;
        max-width: 320px;
    }

    .sidebar-header {
        padding: 8px 16px;
        padding-top: calc(8px + env(safe-area-inset-top));
    }

    .sidebar-brand {
        gap: 10px;
    }

    .brand-logo {
        width: 32px;
        height: 32px;
    }

    .brand-name {
        font-size: 18px;
    }

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

    .sidebar.collapsed .sidebar-header {
        padding: 8px 16px;
        padding-top: calc(8px + env(safe-area-inset-top));
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        justify-content: center;
    }

    .sidebar.collapsed .brand-logo {
        width: 40px;
        height: 40px;
        border-radius: 12px;
    }

    .sidebar-footer {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
    }

    .header {
        padding: 0 16px;
        padding-top: calc(8px + env(safe-area-inset-top));
        box-sizing: border-box;
        height: auto;
        min-height: calc(var(--header-height) + 8px + env(safe-area-inset-top));
    }

    .header-title {
        font-size: 16px;
        max-width: 200px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .action-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .chat-container {
        /* 为固定输入框留出底部空间 */
        padding-bottom: 80px;
        height: auto;
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        /* 【修复】允许触摸滚动，不阻止消息容器的滚动 */
        overflow: visible;
    }
    
    .messages-container {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        /* 【修复】确保触摸事件不被阻止 */
        touch-action: pan-y;
        /* 强制开启硬件加速 */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        /* 【修改】底部留白改为60px */
        padding-bottom: 60px;
    }

    .input-area {
        padding: 12px 16px calc(8px + env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column;
        align-items: stretch;
        flex-shrink: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: var(--background-color);
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
        /* 【修复】确保输入框不影响滚动容器的触摸事件 */
        touch-action: pan-x;
    }

    .input-container {
        width: 100%;
        max-width: 100%;
        padding: 10px 14px;
        border-radius: 16px;
    }

    .message-input {
        font-size: 16px;
        min-height: 24px;
        padding: 4px 0;
    }

    .send-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .send-btn svg {
        width: 18px;
        height: 18px;
    }

    .stop-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .stop-btn .stop-icon {
        font-size: 14px;
    }

    /* 附件上传按钮 */
    .file-upload-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .file-upload-btn svg {
        width: 18px;
        height: 18px;
    }

    .message {
        max-width: 100%;
        margin: 0;
    }

    .message-content {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 14px;
    }

    .welcome-screen {
        padding: 20px 16px;
        padding-bottom: 100px;
        /* max-height: calc(100vh - 60px); */
        /* overflow-y: auto; */
        flex: 1; /* 保持 flex: 1 以确保垂直居中 */
        -webkit-overflow-scrolling: touch;
    }

    .welcome-logo-img {
        width: 80px;
        height: 80px;
    }

    .welcome-tips p {
        font-size: 14px;
    }

    .quick-actions {
        display: none;
    }

    .quick-action-btn {
        padding: 16px 12px;
        min-height: 80px;
        font-size: 12px;
    }

    .logo-icon {
        font-size: 48px;
    }

    .footer-copyright {
        font-size: 10px;
        /* 【修改】使用 max() 取较小值，减小安全区域影响 */
        padding-bottom: max(4px, env(safe-area-inset-bottom));
    }
    
    .sidebar.show .sidebar-content {
        display: flex !important;
    }
    
    .sidebar.show .user-card {
        display: flex !important;
    }
    
    /* 【新增】移动端边栏展开时覆盖 collapsed 类的隐藏效果 */
    .sidebar.show .btn-text,
    .sidebar.show .user-name,
    .sidebar.show .section-title,
    .sidebar.show .chat-history-title,
    .sidebar.show .brand-name,
    .sidebar.show .theme-text,
    .sidebar.show .user-info {
        opacity: 1 !important;
        visibility: visible !important;
        display: inline-block !important;
        max-width: 200px !important;
        white-space: nowrap !important;
    }
    
    /* 【修复】边栏展开时启用标题截断 */
    .sidebar.show .chat-history-title {
        overflow: hidden !important;
        max-width: 180px !important;
        text-overflow: clip !important;
        flex-shrink: 0 !important;
    }
    
    /* 【修复】确保聊天历史列表宽度不超出边栏 */
    .sidebar.show .chat-history {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .sidebar.show .chat-history-item {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }
    
    /* 【修复】边栏展开时历史对话的弹窗按钮一直显示并右对齐 */
    /* 使用 justify-content: space-between 让按钮自然右对齐 */
    .sidebar.show .chat-history-item {
        justify-content: space-between;
        padding-right: 12px;
    }
    
    .sidebar.show .chat-history-actions {
        flex-shrink: 0;
        margin-left: 8px;
    }
    
    .sidebar.show .user-card {
        display: flex;
        width: 100%;
        padding: 12px 16px;
        justify-content: flex-start;
        background-color: var(--secondary-color);
        border: 1px solid var(--border-color);
    }
    
    .sidebar.show .user-avatar {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }
    
    .sidebar.show .sidebar-content {
        display: flex;
        flex-direction: column;
        overflow: visible;
    }
    
    /* 确保边栏本身可滚动 */
    .sidebar {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* 移动端头像选择弹窗优化 */
    .avatar-popup-content {
        width: 85%;
        max-width: 320px;
        padding: 20px;
    }
    
    .avatar-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 6px;
    }
    
    .avatar-option {
        width: 40px;
        height: 40px;
        font-size: 22px;
        border-radius: 10px;
    }
    
    .avatar-option svg {
        width: 22px;
        height: 22px;
    }
    
    .avatar-option[data-avatar="custom"] svg {
        width: 24px;
        height: 24px;
        font-size: 24px;
    }
}

/* iOS Safari 安全区域支持 - 统一处理底部安全区域 */
@supports (padding: max(0px)) {
    .header {
        padding-top: max(0px, env(safe-area-inset-top));
    }

    .input-area {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* 思考过程动画 */
@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

@keyframes slideUp {
    from {
        opacity: 1;
        max-height: 500px;
    }
    to {
        opacity: 0;
        max-height: 0;
    }
}

/* 深色主题下的思考过程样式 */
[data-theme="dark"] .thought-header {
    background-color: rgba(91, 163, 240, 0.15);
}

[data-theme="dark"] .thought-header:hover {
    background-color: rgba(91, 163, 240, 0.2);
}

[data-theme="dark"] .thought-content {
    background-color: rgba(91, 163, 240, 0.1);
}

[data-theme="dark"] .thought-expand-hint {
    color: #6b7280;
}

[data-theme="dark"] .thought-expand-hint:hover {
    color: #5ba3f0;
}

/* 思考过程展开动画 */
.thought-section.expanded .thought-content {
    animation: slideDown 0.3s ease forwards;
}

.thought-section:not(.expanded) .thought-content {
    animation: slideUp 0.3s ease forwards;
}

/* 思考过程区域阴影效果 */
.thought-content {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* 思考过程渐变遮罩效果 */
.thought-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(transparent, rgba(255, 255, 255, 0.8));
    pointer-events: none;
}

[data-theme="dark"] .thought-content::after {
    background: linear-gradient(transparent, rgba(30, 30, 58, 0.8));
}

/* 拖拽上传样式 */
.input-container.drag-over {
    border-color: var(--theme-primary) !important;
    background-color: rgba(74, 144, 217, 0.08) !important;
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.2) !important;
}

.input-container.drag-over::before {
    content: '📁 释放以上传文件';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    font-weight: 500;
    color: var(--theme-primary);
    background-color: rgba(255, 255, 255, 0.95);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    pointer-events: none;
}

[data-theme="dark"] .input-container.drag-over::before {
    background-color: rgba(30, 30, 58, 0.95);
    color: var(--theme-primary);
}

/* 拖拽时的文件上传按钮动画 */
.file-upload-btn.drag-over-btn {
    background-color: var(--theme-primary) !important;
    color: white !important;
    transform: scale(1.1);
}

.file-upload-btn.drag-over-btn svg {
    stroke: white !important;
}

.connection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    background-color: var(--secondary-color);
    border-bottom: 1px solid var(--border-color);
}

.connection-status.connecting .connection-status-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #fbbf24;
    animation: pulse 1.5s infinite;
}

.connection-status.disconnected .connection-status-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ef4444;
}

.connection-status.reconnecting .connection-status-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #f97316;
    animation: pulse 0.5s infinite;
}

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

.file-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background-color: var(--secondary-color);
    border-radius: 8px;
    margin-bottom: 8px;
}

.file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-progress {
    width: 100%;
    height: 4px;
    background-color: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--theme-primary);
    transition: width 0.2s ease;
}

.file-remove {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-remove:hover {
    background-color: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}
