* {
    margin: 1;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    height: 100dvh; /* 使用动态视口高度，iOS 18+ 支持 */
    height: 100vh; /* 降级方案，兼容旧浏览器 */
    overflow: hidden;
    position: relative;
}

.page {
    height: 100dvh; /* 使用动态视口高度 */
    height: 100vh; /* 降级方案 */
    overflow: hidden;
}

/* 假的404页面（用于隐蔽入口） */
.fake-404-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    text-align: center;
    background: #f5f5f5;
}

.fake-404-container h1 {
    font-size: 120px;
    font-weight: bold;
    color: #ddd;
    margin: 0;
    line-height: 1;
}

.fake-404-container p {
    font-size: 18px;
    color: #666;
    margin: 20px 0 10px 0;
}

.fake-404-hint {
    font-size: 14px;
    color: #999;
    margin-top: 5px;
}

/* 登录页面 */
.login-container {
    max-width: 400px;
    margin: 100px auto;
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

@media (max-width: 768px) {
    .login-container {
        margin: 20px;
        padding: 30px 20px;
        max-width: 100%;
    }
}

.login-container h1 {
    text-align: center;
    margin-bottom: 15px;
}

.client-ip {
    text-align: center;
    color: #666;
    font-size: 12px;
    margin-bottom: 15px;
    padding: 5px;
    background: #f8f9fa;
    border-radius: 4px;
}

.tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 16px;
    touch-action: manipulation; /* 优化触摸响应 */
}

.tab.active {
    color: #007bff;
    border-bottom: 2px solid #007bff;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form input {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form button {
    padding: 12px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    touch-action: manipulation; /* 优化触摸响应 */
}

.form button:hover {
    background: #0056b3;
}

.error {
    color: red;
    margin-top: 10px;
    text-align: center;
}

.password-warning {
    color: #dc3545;
    font-size: 16px;
    margin-top: -5px;
    margin-bottom: 5px;
    padding: 5px 0;
    line-height: 1.4;
}

.form-hint {
    color: #666;
    font-size: 12px;
    margin-top: -5px;
    margin-bottom: 5px;
    padding: 5px 0;
    line-height: 1.4;
    text-align: center;
}

/* 主界面 */
.header {
    background: white;
    padding: 10px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    z-index: 100;
}

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

.header-title {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.header-left h2 {
    margin: 0;
    font-size: 12px;
}

.header-left .client-ip {
    display: none; /* 隐藏顶部 IP 显示，功能已移到输入框菜单 */
    margin: 0;
    text-align: left;
}

/* 汉堡菜单按钮 */
.menu-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    width: 40px;
    height: 40px;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    position: relative;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle span {
    display: block;
    width: 24px;
    height: 3px;
    background: #333;
    border-radius: 2px;
    transition: all 0.3s;
}

.menu-toggle:active {
    opacity: 0.7;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.menu-toggle:active {
    opacity: 0.7;
}

.header-actions {
    display: none; /* 隐藏顶部操作按钮，功能已移到输入框菜单 */
}

.header-actions select,
.header-actions button {
    padding: 8px 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.main-content {
    display: flex;
    height: calc(100vh - 60px);
    position: relative;
}

/* 侧边栏遮罩层（移动端） */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

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

.sidebar {
    width: 250px;
    background: white;
    border-right: 1px solid #eee;
    padding: 20px;
    overflow-y: auto;
    transition: transform 0.3s ease;
    position: relative;
    z-index: 999;
    height: 100%;
}

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

.sidebar-header h3 {
    margin: 0;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    font-size: 28px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
    border-radius: 4px;
}

.sidebar-close:hover {
    background: #f5f5f5;
}

.conversation-item {
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid #eee;
    transition: all 0.2s;
    position: relative;
}

.conversation-item:hover {
    background: #f5f5f5;
    border-color: #ddd;
}

.conversation-item.active {
    background: #e3f2fd;
    border-color: #2196f3;
}

.conversation-content {
    width: 100%;
    padding-right: 30px; /* 为三个点按钮留出空间 */
}

.conversation-menu-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    font-size: 20px;
    color: #666;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    line-height: 1;
    z-index: 10;
    opacity: 0; /* 默认隐藏 */
}

.conversation-item:hover .conversation-menu-btn {
    opacity: 1; /* 悬停时显示 */
}

.conversation-menu-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
}

.conversation-menu {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    min-width: 120px;
    z-index: 1000;
}

.conversation-menu-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    transition: background 0.2s;
}

.conversation-menu-item:hover {
    background: #f5f5f5;
}

.conversation-menu-item:active {
    background: #e0e0e0;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* 确保flex子元素可以收缩 */
    min-width: 0; /* 确保flex子元素可以收缩，防止被内容撑开 */
    position: relative;
    overflow: hidden; /* 防止内容溢出 */
}

.messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden; /* 防止横向滚动 */
    background: #fafafa;
    min-width: 0; /* 允许收缩，防止被内容撑开 */
}

.message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

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

.message.assistant {
    align-items: flex-start;
}

.message-expand-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 12px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.message-expand-btn:hover {
    background: #0056b3;
}

.message-expand-btn:active {
    background: #004085;
}

.message-content {
    max-width: 90%;
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.5;
    min-width: 0; /* 允许收缩，防止被内容撑开 */
    overflow-wrap: break-word; /* 允许在单词内换行 */
}

.message.user .message-content {
    background: #007bff;
    color: white;
}

.message.assistant .message-content {
    background: white;
    border: 1px solid #ddd;
}

/* Markdown 样式 */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: bold;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.1em; }

.message-content p {
    margin: 0.5em 0;
}

.message-content ul,
.message-content ol {
    margin: 0.5em 0;
    padding-left: 2em;
}

.message-content li {
    margin: 0.25em 0;
}

.message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 0.5em 0;
    max-width: 100%; /* 限制最大宽度，防止撑开父容器 */
    min-width: 0; /* 允许收缩 */
    word-break: normal; /* 代码块不换行，使用横向滚动 */
    white-space: pre; /* 保持代码格式 */
}

.message-content pre code {
    background: none;
    padding: 0;
    white-space: pre; /* 保持代码格式 */
    word-break: normal; /* 代码不换行 */
    display: block; /* 确保代码块是块级元素 */
    overflow-x: auto; /* 允许横向滚动 */
    max-width: 100%; /* 限制最大宽度 */
}

.message-content blockquote {
    border-left: 3px solid #ddd;
    padding-left: 1em;
    margin: 0.5em 0;
    color: #666;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5em 0;
}

.message-content th,
.message-content td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

.message-content th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: bold;
}

.message-content a {
    color: #007bff;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 1em 0;
}

/* 用户消息中的 Markdown 样式（白色文字） */
.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message.user .message-content pre {
    background: rgba(255, 255, 255, 0.15);
}

.message.user .message-content pre code {
    color: white;
}

.message.user .message-content blockquote {
    border-left-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.9);
}

.message.user .message-content a {
    color: #fff;
    text-decoration: underline;
}

/* 消息元信息（时间戳和模型） */
.message-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

.message-meta {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
    display: flex;
    gap: 8px;
    align-items: center;
}

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

.message.assistant .message-meta {
    justify-content: flex-start;
}

.message-time {
    opacity: 0.8;
}

.message-model {
    opacity: 0.7;
    font-weight: 500;
}

.message-tokens {
    opacity: 0.7;
    font-size: 11px;
}

.message-cost {
    opacity: 0.7;
    font-size: 11px;
    color: #28a745;
    font-weight: 500;
}

/* 消息总结区域 */
.message-summary-area {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}

.message-summary-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.message-summary-btn {
    background: none;
    border: 1px solid #ddd;
    color: #666;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.message-summary-btn:hover {
    background: #f5f5f5;
    border-color: #999;
    color: #333;
}

.message-summary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.message-summary-content {
    background: #f9f9f9;
    padding: 12px;
    border-radius: 6px;
    margin-top: 8px;
    border-left: 3px solid #007bff;
}

.message-summary-content p {
    margin: 0.5em 0;
}

.message-summary-content p:first-child {
    margin-top: 0;
}

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

/* 折叠/展开按钮 */
.message-toggle {
    background: none;
    border: none;
    color: #999;
    font-size: 10px;
    cursor: pointer;
    padding: 2px 4px;
    margin-left: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
    vertical-align: middle;
    line-height: 1;
}

.message-toggle:hover {
    opacity: 1;
    color: #666;
}

.message-toggle:active {
    opacity: 0.8;
}

/* 折叠状态的消息内容 */
.message-content.collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    max-height: calc(1.5em * 3); /* 3行高度，line-height 1.5 */
}

.input-area {
    padding: 15px;
    padding-bottom: max(15px, env(safe-area-inset-bottom, 0px)); /* 适配安全区域 */
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    flex-shrink: 0; /* 防止输入区域被压缩 */
    position: relative;
    z-index: 10;
    margin-bottom: 0;
}

.input-area button {
    padding: 10px 20px;
    background: #1976d2;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.input-area button:hover:not(:disabled) {
    background: #1565c0;
}

.input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #ccc;
}

.input-area textarea {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    max-height: 200px;
    line-height: 1.5;
}

.input-area input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.input-area button {
    padding: 12px 24px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.input-menu-btn {
    background: none;
    border: none;
    font-size: 16px;
    color: #666;
    cursor: pointer;
    padding: 0;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
    line-height: 1;
    align-self: center;
    width: 20px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    position: relative;
    z-index: 11;
    user-select: none;
    -webkit-user-select: none;
}

.input-menu-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
}

.input-menu-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

.input-menu-btn:focus {
    outline: none;
}

.input-menu {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    min-width: 180px;
    max-width: 250px;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 10000 !important;
    position: fixed !important;
}

.input-menu-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    transition: background 0.2s;
}

.input-menu-item:hover {
    background: #f5f5f5;
}

.input-menu-item:active {
    background: #e0e0e0;
}

/* 输入菜单特殊样式 */
.input-menu-info {
    color: #666;
    font-size: 12px;
    cursor: default;
}

.input-menu-info:hover {
    background: none;
}

.input-menu-label {
    color: #666;
    font-size: 12px;
    font-weight: 500;
    cursor: default;
    padding: 6px 16px 4px 16px;
}

.input-menu-label:hover {
    background: none;
}

.input-menu-option {
    padding: 10px 16px;
    position: relative;
}

.input-menu-option.selected {
    background: #e3f2fd;
    color: #1976d2;
    font-weight: 600;
}

.input-menu-option.selected::before {
    content: '✓';
    position: absolute;
    left: 8px;
    color: #1976d2;
    font-weight: bold;
}

.input-menu-option.selected:hover {
    background: #bbdefb;
}

.input-menu-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 4px 0;
    border: none;
}

.input-menu-danger {
    color: #d32f2f;
}

.input-menu-danger:hover {
    background: #ffebee;
    color: #c62828;
}

/* 文件上传区域 */
.file-upload-area {
    background: #f9f9f9;
    border-top: 1px solid #ddd;
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.file-upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.file-upload-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.file-upload-close:hover {
    background: #e0e0e0;
}

.file-list {
    margin-bottom: 8px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 13px;
}

.file-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item-status {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    background: #f0f0f0;
    color: #666;
}

.file-item-status.parsing {
    background: #fff3cd;
    color: #856404;
}

.file-item-status.parsed {
    background: #d4edda;
    color: #155724;
}

.file-item-status.failed {
    background: #f8d7da;
    color: #721c24;
}

.file-item-delete {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-item-delete:hover {
    background: #f8d7da;
    border-radius: 3px;
}

.file-upload-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-upload-btn {
    display: inline-block;
    padding: 6px 12px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.file-upload-btn:hover {
    background: #0056b3;
}

.file-upload-hint {
    font-size: 11px;
    color: #666;
}

.file-upload-toggle-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.file-upload-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
}

.file-upload-toggle-btn.active {
    background: #007bff;
    color: white;
}

/* 文件选择器按钮（回形针） - 更小的尺寸 */
.file-selector-toggle-btn {
    background: none;
    border: none;
    font-size: 16px;
    color: #666;
    cursor: pointer;
    padding: 4px 6px;
    min-width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.file-selector-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
}

.file-selector-toggle-btn.active {
    background: #e3f2fd;
    color: #1976d2;
}

/* 消息附件显示 */
.message-attachments {
    margin-bottom: 8px;
    padding: 6px 8px;
    background: #f0f0f0;
    border-radius: 4px;
    font-size: 12px;
}

.message-attachment {
    display: inline-block;
    margin-right: 8px;
    padding: 2px 6px;
    background: #e3f2fd;
    color: #1976d2;
    border-radius: 3px;
    font-size: 11px;
}

/* 会话总结区域 */
.conversation-summary-area {
    background: #f9f9f9;
    border-bottom: 1px solid #007bff;
    padding: 2px;
    margin-bottom: 0;
    border-radius: 0;
    flex-shrink: 0; /* 防止被压缩 */
    max-height: 50vh; /* 限制整个区域的最大高度为视口高度的50% */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 防止整个区域溢出 */
}

.conversation-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
    gap: 12px;
}

.conversation-summary-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.conversation-summary-costs {
    font-size: 11px;
    color: #666;
    white-space: nowrap;
    text-align: right;
}

.conversation-summary-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.conversation-summary-toggle-btn {
    background: none;
    border: none;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    padding: 4px 2px;
    border-radius: 4px;
    transition: all 0.2s;
    line-height: 1;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-summary-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
}

.conversation-summary-toggle-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

.conversation-summary-area.collapsed .conversation-summary-toggle-btn {
    transform: rotate(-90deg);
}

.conversation-summary-header h4 {
    margin: 0;
    color: #333;
    font-size: 12px;
}

.conversation-summary-body {
    max-height: 45vh; /* 限制body的最大高度为视口高度的45% */
    display: flex;
    flex-direction: column;
}

/* 移动端优化：减少最大高度 */
@media (max-width: 768px) {
    .conversation-summary-area {
        max-height: 40vh; /* 移动端限制为40%视口高度 */
        padding: 2px;
    }

    .conversation-summary-body {
        max-height: 35vh; /* 移动端限制为35%视口高度 */
    }

    .conversation-summary-content {
        max-height: 30vh; /* 移动端限制为30%视口高度 */
    }
}

/* Webkit 浏览器滚动条样式（用于总结内容） */
.conversation-summary-content::-webkit-scrollbar {
    width: 8px;
}

.conversation-summary-content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.conversation-summary-content::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.conversation-summary-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.conversation-summary-area.collapsed .conversation-summary-body {
    display: none; /* 折叠时直接隐藏 */
}

.conversation-summary-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
}

.conversation-summary-actions .conversation-menu-btn {
    position: relative;
    opacity: 1;
    top: auto;
    right: auto;
}

.conversation-summary-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
    white-space: nowrap;
}

.conversation-summary-btn:hover {
    background: #0056b3;
}

.conversation-summary-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.conversation-summary-content {
    background: white;
    padding: 4px;
    border-radius: 6px;
    margin-bottom: 2px;
    border-left: 3px solid #007bff;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    /* 设置合理的最大高度以触发滚动 */
    max-height: 40vh; /* 限制content的最大高度为视口高度的40% */
    overflow-y: auto;
    overflow-x: hidden;
    /* 自定义滚动条样式 */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 #f1f5f9;
}

/* WebKit浏览器（Chrome、Safari等）的滚动条样式 */
.conversation-summary-content::-webkit-scrollbar {
    width: 6px;
}

.conversation-summary-content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.conversation-summary-content::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.conversation-summary-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.conversation-summary-content p {
    margin: 0.5em 0;
}

.conversation-summary-content p:first-child {
    margin-top: 0;
}

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

.conversation-summary-time {
    font-size: 12px;
    color: #666;
    text-align: right;
    flex-shrink: 0; /* 防止被压缩，始终可见 */
    margin-top: auto; /* 推到底部 */
    padding-top: 1px; /* 与内容保持间距 */
    border-top: 1px solid #e0e0e0; /* 添加分隔线 */
}

/* 加载更多消息按钮 */
.load-more-messages {
    text-align: center;
    padding: 16px;
    margin: 16px 0;
}

.load-more-btn {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.2s;
}

.load-more-btn:hover {
    background: #e0e0e0;
    border-color: #007bff;
    color: #007bff;
}

.load-more-btn:active {
    background: #d0d0d0;
}

.undo-btn:hover {
    background: #5a6268 !important;
}

.undo-btn:disabled {
    background: #ccc !important;
    cursor: not-allowed !important;
}

.input-area button:hover {
    background: #0056b3;
}

.input-area button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 响应式设计 - 移动端 */
@media (max-width: 768px) {
    /* 头部调整 - 固定定位，确保始终可见 */
    .header {
        position: fixed !important;
        top: env(safe-area-inset-top, 0px) !important; /* 考虑顶部安全区域（刘海） */
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        padding: 10px 15px !important;
        padding-top: max(10px, calc(env(safe-area-inset-top, 0px) + 10px)) !important; /* 顶部内边距考虑安全区域 */
        flex-wrap: wrap;
        min-height: 60px;
        z-index: 1000 !important; /* 确保在内容之上 */
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
        background: white !important;
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-title {
        min-width: 0;
        overflow: hidden;
    }

    .header-left h2 {
        font-size: 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-left .client-ip {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .menu-toggle {
        display: flex !important;
        flex-shrink: 0;
        margin-right: 10px;
    }
    
    /* 确保汉堡菜单按钮可见 */
    .header-left {
        display: flex;
        align-items: center;
    }

    .header-actions {
        display: none; /* 隐藏顶部操作按钮，功能已移到输入框菜单 */
    }

    .header-actions select,
    .header-actions button {
        flex: 1;
        padding: 10px 12px;
        font-size: 13px;
        min-width: 0;
        touch-action: manipulation; /* 优化触摸响应 */
    }

    .header-actions select {
        flex: 2;
    }

    /* 侧边栏移动端样式 */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh; /* 使用动态视口高度 */
        height: 100vh; /* 降级方案 */
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        z-index: 999;
        padding-top: 20px;
    }

    .sidebar.active {
        transform: translateX(0);
    }
    
    /* 确保侧边栏在移动端可见 */
    .sidebar-header {
        padding-bottom: 10px;
        border-bottom: 1px solid #eee;
        margin-bottom: 15px;
    }

    .sidebar-close {
        display: block;
    }

    /* 主内容区域 */
    .main-content {
        /* 考虑头部高度和安全区域 */
        margin-top: calc(60px + env(safe-area-inset-top, 0px)) !important;
        height: calc(100dvh - 60px - env(safe-area-inset-top, 0px)) !important; /* 使用动态视口高度，减去头部高度和安全区域 */
        height: calc(100vh - 60px - env(safe-area-inset-top, 0px)) !important; /* 降级方案 */
        display: flex;
        flex-direction: column;
        overflow: visible; /* 允许固定定位的元素显示 */
        position: relative;
    }

    .chat-area {
        width: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow: visible; /* 允许输入区域显示 */
        position: relative;
        /* 确保有足够的顶部空间，不被头部遮挡 */
        padding-top: 0 !important;
    }

    /* 消息区域 */
    .messages {
        padding: 15px 12px;
        flex: 1;
        overflow-y: auto;
        min-height: 0;
        /* 使用 CSS 变量动态计算底部间距，考虑输入区域高度和安全区域 */
        /* 初始值较大，JavaScript 会动态调整 */
        padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
        /* 确保顶部内容可见 */
        padding-top: 10px !important;
    }

    .message-content {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 15px;
    }
    
    .message-meta {
        font-size: 10px;
        margin-top: 3px;
        padding: 0 4px;
    }

    /* 输入区域 - 移动端固定定位 */
    .input-area {
        padding: 12px !important;
        gap: 6px !important;
        /* 使用安全区域变量，确保不被 Home Indicator 遮挡 */
        padding-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 12px)) !important;
        position: fixed !important;
        bottom: env(safe-area-inset-bottom, 0px) !important; /* 考虑安全区域 */
        left: env(safe-area-inset-left, 0px) !important; /* 考虑左侧安全区域（横屏时） */
        right: env(safe-area-inset-right, 0px) !important; /* 考虑右侧安全区域（横屏时） */
        width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
        max-width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
        background: white !important;
        border-top: 1px solid #eee !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1) !important;
        z-index: 10000 !important;
        flex-shrink: 0 !important;
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        transform: none !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        height: auto !important;
        min-height: auto !important;
        /* 使用 CSS 变量存储输入区域高度，供消息区域使用 */
        --input-area-height: auto;
    }
    
    /* 竖屏时，适配安全区域 */
    @media (max-width: 768px) and (orientation: portrait) {
        .input-area {
            bottom: env(safe-area-inset-bottom, 0px) !important;
            padding-bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 12px)) !important;
        }
    }
    
    /* 横屏时，适配安全区域 */
    @media (max-width: 768px) and (orientation: landscape) {
        .input-area {
            bottom: env(safe-area-inset-bottom, 0px) !important;
            padding-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 8px)) !important;
        }
    }
    
    /* 确保输入区域在移动端可见 */
    .chat-area {
        /* 动态计算 padding-bottom，为固定输入区域留出空间 */
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
    }
    
    /* 确保输入框和按钮可见 */
    .input-area textarea,
    .input-area input,
    .input-area button {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: relative !important;
        z-index: 10001 !important;
    }

    .input-area textarea,
    .input-area input {
        padding: 14px !important;
        font-size: 16px !important; /* 防止iOS自动缩放 */
        -webkit-appearance: none !important; /* 移除iOS默认样式 */
        appearance: none !important; /* 标准属性 */
        border-radius: 8px !important;
        border: 1px solid #ddd !important;
        background: white !important;
        color: #333 !important;
        width: auto !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    .input-area button {
        padding: 14px 20px !important;
        font-size: 15px !important;
        min-width: 70px !important;
        touch-action: manipulation !important; /* 优化触摸响应 */
        -webkit-tap-highlight-color: transparent !important; /* 移除点击高亮 */
        background: #007bff !important;
        color: white !important;
        border: none !important;
        border-radius: 4px !important;
        cursor: pointer !important;
    }

    /* 对话项 */
    .conversation-item {
        padding: 14px;
        margin-bottom: 10px;
        touch-action: manipulation; /* 优化触摸响应 */
        -webkit-tap-highlight-color: rgba(0, 123, 255, 0.1); /* 触摸反馈 */
    }

    /* 消息区域优化 */
    .message {
        margin-bottom: 12px;
    }

    /* 滚动优化 */
    .messages {
        -webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
    }

    .sidebar {
        -webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
    }
}

/* 响应式设计 - 平板 */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }

    .header-actions {
        gap: 8px;
    }

    .header-actions select,
    .header-actions button {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* 响应式设计 - 大屏幕优化 */
@media (min-width: 1440px) {
    .sidebar {
        width: 300px;
    }

    .message-content {
        max-width: 65%;
    }
}

/* 管理员面板样式 */
.admin-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.admin-panel > div {
    background: #fff;
    margin: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 40px); /* 使用动态视口高度 */
    max-height: calc(100vh - 40px); /* 降级方案 */
    overflow: hidden;
    min-height: 0; /* 允许 flex 子元素收缩 */
}

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

.admin-header h2 {
    margin: 0;
    font-size: 20px;
}

.admin-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.admin-close:hover {
    color: #333;
}

.admin-tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
    padding: 0 20px;
    gap: 0;
}

.admin-tab {
    padding: 12px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.2s;
}

.admin-tab:hover {
    color: #333;
    background: #f5f5f5;
}

.admin-tab.active {
    color: #007bff;
    border-bottom-color: #007bff;
    font-weight: 500;
}

.admin-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    min-height: 0; /* 允许 flex 子元素收缩，确保滚动生效 */
    -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
}

.admin-section {
    display: none;
    height: 100%; /* 确保占满父容器高度 */
}

.admin-section.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* 允许收缩 */
}

.admin-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.admin-section-header h3 {
    margin: 0;
    font-size: 18px;
}

.btn-primary, .btn-secondary {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0; /* 允许收缩，确保滚动生效 */
    -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
}

.admin-item {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 16px;
    background: #f9f9f9;
}

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

.admin-item-title {
    font-weight: 500;
    font-size: 16px;
}

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

.admin-item-actions button {
    padding: 4px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-approve {
    background: #28a745;
    color: white;
}

.btn-approve:hover {
    background: #218838;
}

.btn-reject {
    background: #dc3545;
    color: white;
}

.btn-reject:hover {
    background: #c82333;
}

.btn-disable {
    background: #ffc107;
    color: #333;
}

.btn-disable:hover {
    background: #e0a800;
}

.btn-enable {
    background: #28a745;
    color: white;
}

.btn-enable:hover {
    background: #218838;
}

.admin-item-details {
    font-size: 13px;
    color: #666;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.admin-item-details span {
    display: inline-block;
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.status-pending {
    background: #ffc107;
    color: #333;
}

.status-active {
    background: #28a745;
    color: white;
}

.status-suspended {
    background: #dc3545;
    color: white;
}

.status-disabled {
    background: #6c757d;
    color: white;
}

.status-expired {
    background: #6c757d;
    color: white;
}

/* 生成邀请码对话框 */
.invite-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    min-width: 400px;
    max-width: 90%;
}

.invite-dialog h3 {
    margin: 0 0 20px 0;
}

.invite-dialog form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.invite-dialog input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.invite-dialog .form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.invite-dialog .form-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.invite-dialog .form-actions .btn-cancel {
    background: #6c757d;
    color: white;
}

.invite-dialog .form-actions .btn-submit {
    background: #007bff;
    color: white;
}

.invite-code-result {
    margin-top: 16px;
    padding: 12px;
    background: #e7f3ff;
    border: 1px solid #b3d9ff;
    border-radius: 4px;
}

.invite-code-result .code {
    font-family: monospace;
    font-size: 18px;
    font-weight: bold;
    color: #007bff;
    margin: 8px 0;
}

.invite-code-result .hint {
    font-size: 12px;
    color: #666;
    margin-top: 8px;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .admin-panel > div {
        margin: 0;
        border-radius: 0;
        max-height: 100dvh; /* 使用动态视口高度 */
        max-height: 100vh; /* 降级方案 */
    }
    
    .admin-tabs {
        flex-wrap: wrap;
        padding: 0 10px;
    }
    
    .admin-tab {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .admin-content {
        padding: 12px;
    }
    
    .invite-dialog {
        min-width: 90%;
        padding: 20px;
    }
}

