/* ==================== 设置页面样式 ==================== */

#settings-page {
    display: flex !important;
    flex-direction: column;
    height: 100dvh !important;
    height: 100vh !important;
    background: #f5f5f5;
    overflow: hidden !important;
    min-height: 0;
    position: relative;
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.settings-section {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.settings-section h3 {
    margin: 0 0 20px 0;
    font-size: 18px;
    color: #333;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 10px;
}

.settings-item {
    margin-bottom: 20px;
}

.settings-item:last-child {
    margin-bottom: 0;
}

.settings-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    margin-bottom: 8px;
}

.settings-label:has(select) {
    flex-direction: column;
    align-items: flex-start;
    cursor: default;
}

.settings-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #1976d2;
}

.settings-select {
    width: 100%;
    max-width: 300px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    margin-top: 8px;
}

.settings-select:hover {
    border-color: #1976d2;
}

.settings-select:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

.settings-description {
    margin: 8px 0 0 0;
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

/* ==================== 文件管理页面样式 ==================== */

#files-page {
    display: flex !important; /* 确保覆盖 .page 的样式 */
    flex-direction: column;
    height: 100dvh !important; /* 使用动态视口高度，iOS 18+ 支持 */
    height: 100vh !important; /* 降级方案 */
    background: #f5f5f5;
    overflow: hidden !important; /* 防止整个页面滚动 */
    min-height: 0; /* 允许 flex 子元素收缩 */
    position: relative; /* 确保定位上下文 */
}

.files-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0; /* 防止头部被压缩 */
}

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

.back-btn {
    padding: 8px 15px;
    background: #f0f0f0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.back-btn:hover {
    background: #e0e0e0;
}

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

.upload-file-btn {
    padding: 8px 20px;
    background: #1976d2;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.upload-file-btn:hover {
    background: #1565c0;
}

.files-toolbar {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0; /* 防止工具栏被压缩 */
    align-items: center;
}

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

.file-filter-select,
.file-sort-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.files-list {
    flex: 1;
    overflow-y: auto !important; /* 确保滚动生效 */
    overflow-x: hidden;
    padding: 20px;
    min-height: 0 !important; /* 允许 flex 子元素收缩，确保滚动生效 */
    max-height: 100%; /* 限制最大高度 */
    -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
    position: relative; /* 确保滚动上下文 */
}

.file-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.file-item-icon {
    font-size: 32px;
}

.file-item-info {
    flex: 1;
}

.file-item-name {
    font-weight: 500;
    margin-bottom: 5px;
    color: #333;
}

.file-item-meta {
    font-size: 12px;
    color: #666;
}

.file-item-actions {
    display: flex;
    gap: 10px;
}

.file-item-btn {
    padding: 6px 12px;
    background: #f0f0f0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.file-item-btn:hover {
    background: #e0e0e0;
}

.file-item-btn-danger {
    background: #ffebee;
    color: #c62828;
}

.file-item-btn-danger:hover {
    background: #ffcdd2;
}

.file-item-btn-primary {
    background: #e3f2fd;
    color: #1976d2;
}

.file-item-btn-primary:hover {
    background: #bbdefb;
}

.files-loading,
.files-empty {
    text-align: center;
    padding: 40px;
    color: #666;
}

.files-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0; /* 防止分页器被压缩 */
}

.pagination-btn {
    padding: 8px 15px;
    background: #f0f0f0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.pagination-btn:hover:not(:disabled) {
    background: #e0e0e0;
}

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

.pagination-info {
    font-size: 14px;
    color: #666;
}

/* ==================== 文件选择器样式 ==================== */

.file-selector-area {
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    padding: 10px 15px;
}

.file-selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.file-selector-header span {
    font-size: 14px;
    font-weight: 500;
}

.file-manager-btn {
    padding: 4px 10px;
    background: #e3f2fd;
    color: #1976d2;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.file-manager-btn:hover {
    background: #bbdefb;
}

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

.selected-files-list {
    margin-bottom: 10px;
}

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

.selected-file-icon {
    font-size: 16px;
}

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

.selected-file-remove {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.selected-file-remove:hover {
    color: #c62828;
}

.selected-files-empty {
    text-align: center;
    padding: 10px;
    color: #999;
    font-size: 13px;
}

.open-file-selector-btn {
    width: 100%;
    padding: 8px;
    background: white;
    border: 1px dashed #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: #666;
}

.open-file-selector-btn:hover {
    background: #f5f5f5;
    border-color: #1976d2;
    color: #1976d2;
}

.file-selector-toggle-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 6px 8px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.file-selector-toggle-btn:hover,
.file-selector-toggle-btn.active {
    color: #1976d2;
    background: #f0f7ff;
    border-radius: 4px;
}

/* ==================== 文件选择器弹窗样式 ==================== */

.file-selector-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.file-selector-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.file-selector-modal-content {
    position: relative;
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

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

.file-selector-modal-header h3 {
    margin: 0;
    font-size: 18px;
}

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

.file-selector-modal-tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
}

.file-selector-tab {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    color: #666;
}

.file-selector-tab.active {
    color: #1976d2;
    border-bottom-color: #1976d2;
}

.file-selector-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.file-selector-tab-content {
    display: none;
}

.file-selector-tab-content.active {
    display: block;
}

.file-selector-library-list {
    max-height: 400px;
    overflow-y: auto;
}

.file-selector-library-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 5px;
}

.file-selector-library-item-main {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.file-selector-library-item:hover {
    background: #f5f5f5;
}

.file-selector-library-item.selected {
    background: #e3f2fd;
}

.file-selector-library-icon {
    font-size: 20px;
}

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

.file-selector-parse-btn {
    padding: 4px 8px;
    background: #e3f2fd;
    color: #1976d2;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    white-space: nowrap;
}

.file-selector-parse-btn:hover {
    background: #bbdefb;
}

.file-selector-loading,
.file-selector-empty,
.file-selector-error {
    text-align: center;
    padding: 40px;
    color: #666;
}

.file-selector-upload-area {
    text-align: center;
}

.file-selector-upload-label {
    display: block;
    cursor: pointer;
}

.file-selector-upload-box {
    padding: 40px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    background: #fafafa;
}

.file-selector-upload-box:hover {
    border-color: #1976d2;
    background: #f0f7ff;
}

.file-selector-upload-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.file-selector-upload-text {
    font-size: 16px;
    color: #333;
    margin-bottom: 5px;
}

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

.file-selector-upload-list {
    margin-top: 20px;
}

.file-selector-upload-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 4px;
    margin-bottom: 5px;
    font-size: 13px;
}

.file-selector-upload-status {
    color: #666;
    font-size: 12px;
}

.file-selector-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
}

.file-selector-btn-primary,
.file-selector-btn-secondary {
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.file-selector-btn-primary {
    background: #1976d2;
    color: white;
}

.file-selector-btn-primary:hover {
    background: #1565c0;
}

.file-selector-btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.file-selector-btn-secondary:hover {
    background: #e0e0e0;
}

/* 侧边栏菜单（在对话列表上方） */
.sidebar-menu {
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 10px;
}

.sidebar-menu-btn {
    width: 100%;
    padding: 10px 15px;
    background: #f8f9fa;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    color: #333;
    transition: background 0.2s;
}

.sidebar-menu-btn:hover {
    background: #e9ecef;
}

.sidebar-menu-btn:active {
    background: #dee2e6;
}

/* ==================== 解析进度模态框样式 ==================== */

.parsing-progress-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.5);
}

.parsing-progress-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* ==================== 对话导航页面样式 ==================== */

#conversations-browse-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f5f5f5;
}

/* 标签导航栏 */
.tags-navigation {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 15px;
    max-height: 200px;
    overflow-y: auto;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}

.tags-navigation.collapsed {
    max-height: 0;
    padding: 0 15px;
    overflow: hidden;
    opacity: 0;
    border-bottom: none;
}

.tags-navigation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.tags-navigation-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
}

.refresh-tags-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
    color: #666;
    transition: color 0.2s;
}

.refresh-tags-btn:hover {
    color: #333;
}

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f0f0f0;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
}

.tag-item:hover {
    background: #e0e0e0;
}

.tag-item.active {
    background: #007bff;
    color: white;
}

.tag-name {
    font-weight: 500;
}

.tag-count {
    font-size: 12px;
    opacity: 0.7;
}

.tags-empty {
    color: #999;
    font-size: 14px;
    text-align: center;
    padding: 20px;
}

/* 对话列表 */
.conversations-browse-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.conversations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.conversation-card {
    background: white;
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
}

.conversation-card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.conversation-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.conversation-card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-card-model {
    font-size: 12px;
    color: #666;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 10px;
}

.conversation-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.conversation-tag {
    font-size: 12px;
    color: #007bff;
    background: #e7f3ff;
    padding: 4px 8px;
    border-radius: 12px;
}

.conversation-card-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: #999;
}

.conversation-card-time {
    flex: 1;
}

.conversation-card-count {
    color: #666;
}

.conversation-card-summary-badge {
    color: #28a745;
    background: #d4edda;
    padding: 2px 6px;
    border-radius: 4px;
}

.conversations-loading,
.conversations-empty {
    text-align: center;
    padding: 40px;
    color: #999;
}

.parsing-progress-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.parsing-progress-header h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
}

.parsing-progress-body {
    padding: 20px;
}

.parsing-progress-info {
    margin-bottom: 20px;
}

.parsing-progress-text {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
}

.parsing-progress-details {
    font-size: 14px;
    color: #666;
}

.parsing-progress-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.parsing-progress-bar {
    flex: 1;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.parsing-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1976d2, #42a5f5);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.parsing-progress-percent {
    font-size: 14px;
    font-weight: 500;
    color: #1976d2;
    min-width: 45px;
    text-align: right;
}

.parsing-progress-footer {
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
}

.parsing-progress-cancel-btn {
    padding: 8px 20px;
    background: #f0f0f0;
    color: #333;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.parsing-progress-cancel-btn:hover {
    background: #e0e0e0;
}

/* ==================== 流式响应停止按钮样式 ==================== */

.message-stop-btn {
    padding: 4px 12px;
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: all 0.2s;
}

.message-stop-btn:hover {
    background: #ffcdd2;
    border-color: #e57373;
}

.message-stop-btn:active {
    background: #ef9a9a;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .file-selector-modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 100dvh; /* 使用动态视口高度 */
        max-height: 100vh; /* 降级方案 */
        border-radius: 0;
    }
    
    .files-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .files-toolbar {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .toggle-tags-nav-btn {
        display: inline-block;
    }
    
    .file-search-input {
        flex: 1;
        min-width: 0;
    }
    
    .parsing-progress-content {
        width: 95%;
    }
}

