/* CSS 变量 - 亮色主题 */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #fff;
    --bg-tertiary: #f8f9fa;
    --bg-code: #f6f8fa;
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #999;
    --border-color: #e0e0e0;
    --border-light: #eaecef;
    --sidebar-bg: #2c3e50;
    --sidebar-header-bg: #1a252f;
    --sidebar-hover: #34495e;
    --sidebar-text: #ecf0f1;
    --sidebar-muted: #95a5a6;
    --input-bg: #34495e;
    --input-focus-bg: #3d566e;
    --link-color: #0366d6;
    --blockquote-color: #6a737d;
    --blockquote-border: #dfe2e5;
    --code-inline-bg: rgba(27, 31, 35, 0.05);
    --table-border: #dfe2e5;
    --table-stripe: #f6f8fa;
    --hr-color: #e1e4e8;
    --modal-bg: #fff;
    --version-hover-bg: #f5f5f5;
    --toast-bg: #333;
    --resizer-color: #e0e0e0;
    --resizer-hover: #3498db;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --scrollbar-track: #e9edf3;
    --scrollbar-thumb: #b8c2cf;
    --scrollbar-thumb-hover: #9eaabc;
    --sidebar-scrollbar-track: #223244;
    --sidebar-scrollbar-thumb: #3f566d;
    --sidebar-scrollbar-thumb-hover: #4e6983;
}

/* CSS 变量 - 暗黑主题 */
[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #1a1a2e;
    --bg-code: #0f3460;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #707080;
    --border-color: #2a2a4a;
    --border-light: #2a2a4a;
    --sidebar-bg: #0f0f23;
    --sidebar-header-bg: #0a0a1a;
    --sidebar-hover: #1a1a3e;
    --sidebar-text: #e0e0e0;
    --sidebar-muted: #707080;
    --input-bg: #1a1a3e;
    --input-focus-bg: #252550;
    --link-color: #58a6ff;
    --blockquote-color: #8b949e;
    --blockquote-border: #3a3a5a;
    --code-inline-bg: rgba(200, 200, 255, 0.1);
    --table-border: #2a2a4a;
    --table-stripe: #1a1a3e;
    --hr-color: #2a2a4a;
    --modal-bg: #16213e;
    --version-hover-bg: #1a1a3e;
    --toast-bg: #2a2a4a;
    --resizer-color: #2a2a4a;
    --resizer-hover: #3498db;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --scrollbar-track: #1a2240;
    --scrollbar-thumb: #3a4a73;
    --scrollbar-thumb-hover: #4a5f91;
    --sidebar-scrollbar-track: #0d1327;
    --sidebar-scrollbar-thumb: #2b3a5f;
    --sidebar-scrollbar-thumb-hover: #3a4d7a;
}

/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
    border: 2px solid var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-corner {
    background: var(--scrollbar-track);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

/* 应用容器 */
.app-container {
    display: flex;
    flex-direction: row !important;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* 侧边栏 */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.2s ease;
}

.sidebar.is-collapsed {
    width: 72px;
}

.sidebar-header {
    padding: 20px;
    background-color: var(--sidebar-header-bg);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar-header-top {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
}

.sidebar-collapse-btn {
    width: 28px;
    height: 56px;
    align-self: center;
    margin-left: -14px;
    margin-right: -14px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    box-shadow: 0 4px 16px var(--shadow-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    z-index: 40;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
    color: var(--text-primary);
    border-color: rgba(52, 152, 219, 0.5);
    box-shadow: 0 6px 18px rgba(52, 152, 219, 0.22);
    transform: translateY(-1px);
}

.sidebar-header h1 {
    font-weight: 600;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 0;
}

.sidebar-new-btn {
    width: 100%;
    justify-content: center;
}

.sidebar-section-title {
    padding: 10px 15px 0;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    font-weight: 600;
}

.btn-full-width {
    width: 100%;
    justify-content: center;
}

.search-box {
    padding: 15px;
    border-bottom: 1px solid var(--sidebar-hover);
    position: relative;
}

.sidebar-search-toggle-btn {
    display: none;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid rgba(236, 240, 241, 0.16);
    background: rgba(236, 240, 241, 0.04);
    color: var(--sidebar-text);
    cursor: pointer;
}

.sidebar-search-toggle-btn:hover {
    background: rgba(52, 152, 219, 0.12);
    border-color: rgba(52, 152, 219, 0.35);
}

.search-box input {
    width: 100%;
    padding: 10px 35px 10px 15px;
    border: none;
    border-radius: 5px;
    background-color: var(--input-bg);
    color: var(--sidebar-text);
    font-size: 14px;
}

.search-box input::placeholder {
    color: var(--sidebar-muted);
}

.search-box input:focus {
    outline: none;
    background-color: var(--input-focus-bg);
}

.search-clear-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--sidebar-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 3px;
    transition: all 0.2s;
    line-height: 1;
}

.search-clear-btn:hover {
    color: var(--sidebar-text);
    background-color: var(--sidebar-hover);
}

.doc-filter-toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 12px 4px;
}

.doc-filter-btn {
    min-height: 30px;
    border: 1px solid rgba(236, 240, 241, 0.2);
    border-radius: 8px;
    background: rgba(236, 240, 241, 0.06);
    color: var(--sidebar-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.doc-filter-btn.active {
    color: var(--sidebar-text);
    border-color: rgba(52, 152, 219, 0.5);
    background: rgba(52, 152, 219, 0.2);
}

.doc-filter-btn:hover {
    color: var(--sidebar-text);
}

.doc-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    scrollbar-color: var(--sidebar-scrollbar-thumb) var(--sidebar-scrollbar-track);
}

.doc-list::-webkit-scrollbar-track {
    background: var(--sidebar-scrollbar-track);
}

.doc-list::-webkit-scrollbar-thumb {
    background: var(--sidebar-scrollbar-thumb);
    border-color: var(--sidebar-scrollbar-track);
}

.doc-list::-webkit-scrollbar-thumb:hover {
    background: var(--sidebar-scrollbar-thumb-hover);
}

.doc-item {
    padding: 12px 15px;
    margin-bottom: 5px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.doc-item:hover {
    background-color: var(--sidebar-hover);
}

.doc-item.active {
    background-color: #3498db;
}

.doc-item.active .doc-item-title,
.doc-item.active .doc-item-date,
.doc-item.active .doc-item-summary {
    color: #ffffff !important;
}

.doc-item.active .doc-item-tag {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.doc-item-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-item-topline {
    display: flex;
    align-items: center;
    gap: 6px;
}

.doc-item-date {
    font-size: 12px;
    color: var(--text-secondary);
}

.doc-favorite-btn {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.45);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    border-radius: 4px;
}

.doc-favorite-btn.active {
    color: #f1c40f;
}

.doc-favorite-btn:hover {
    color: #f1c40f;
}

.doc-item.active .doc-favorite-btn {
    color: rgba(255, 255, 255, 0.9);
}

.doc-item.active .doc-favorite-btn.active {
    color: #ffe58f;
}

/* 文档列表加载更多指示器 */
.doc-list-loader {
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.doc-list-loader span {
    display: inline-block;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* 主内容区 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    background: var(--bg-primary);
}

.workspace-header-stack {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 12px var(--shadow-color);
    z-index: 5;
}

.workspace-toolbar {
    border-bottom: 1px solid var(--border-light);
}

.workspace-toolbar .toolbar-left {
    align-items: center;
    gap: 8px;
}

.mobile-top-tools {
    display: none !important;
}

.mobile-brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.mobile-brand-logo {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    object-fit: contain;
}

.document-title-block {
    display: flex;
    align-items: center;
    min-width: 260px;
    flex: 1;
}

.workspace-toolbar .document-title-block {
    flex: 0 1 560px;
}

.title-input-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.workspace-toolbar .title-input {
    max-width: 560px;
    border-radius: 8px;
}

.workspace-ai-toolbar {
    border-bottom: none;
    background: var(--bg-secondary);
    padding-top: 10px;
    padding-bottom: 10px;
}

/* 工具栏 */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-left {
    flex: 1;
}

.title-input {
    flex: 1;
    max-width: 400px;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 16px;
    font-weight: 500;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.title-input:focus {
    outline: none;
    border-color: #3498db;
}

/* 保存状态提示 */
.save-status {
    font-size: 13px;
    padding: 4px 8px;
    border-radius: 3px;
    white-space: nowrap;
}

.workspace-toolbar .save-status {
    margin-left: 4px;
    align-self: center;
    margin-bottom: 0;
}

.save-status.unsaved {
    color: #e74c3c;
    background-color: #fdeaea;
}

.save-status.saved {
    color: #27ae60;
    background-color: #e8f8f0;
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.btn-primary {
    background-color: #3498db;
    color: #fff;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-success {
    background-color: #27ae60;
    color: #fff;
}

.btn-success:hover {
    background-color: #219a52;
}

.btn-danger {
    background-color: #e74c3c;
    color: #fff;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-ai {
    background-color: #9b59b6;
    color: #fff;
}

.btn-ai:hover {
    background-color: #8e44ad;
}

.btn-secondary {
    background-color: #95a5a6;
    color: #fff;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.doc-item:focus-visible {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

body.compact-doc-list .doc-item {
    padding: 9px 10px;
    margin-bottom: 6px;
}

body.compact-doc-list .doc-item-title {
    font-size: 13px;
}

body.compact-doc-list .doc-item-summary {
    -webkit-line-clamp: 1;
    margin-top: 2px;
}

/* 编辑器容器 */
.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    padding: 12px;
    gap: 0;
}

.editor-pane,
.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    box-shadow: 0 4px 14px var(--shadow-color);
}

.pane-header {
    padding: 10px 20px;
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-pane .pane-header,
.preview-pane .pane-header {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.char-count {
    font-size: 12px;
    color: var(--text-muted);
}

/* 编辑器操作按钮 */
.editor-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
    background-color: #6c757d;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.btn-small:hover {
    background-color: #5a6268;
}

/* CodeMirror 编辑器样式 */
.CodeMirror {
    flex: 1;
    height: auto !important;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.8;
    position: relative;
}

/* 拖拽上传样式 */
.CodeMirror.drag-over {
    background: var(--bg-tertiary) !important;
    border: 2px dashed #3498db !important;
    border-radius: 8px;
}

.CodeMirror.drag-over::before {
    content: '📎 松开鼠标上传文件';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(52, 152, 219, 0.95);
    color: #fff;
    padding: 16px 32px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.CodeMirror-gutters {
    background-color: var(--bg-tertiary);
    border-right: 1px solid var(--border-color);
}

.CodeMirror-linenumber {
    color: var(--text-muted);
}

#editor {
    flex: 1;
    width: 100%;
    border: none;
    resize: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.8;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

#editor:focus {
    outline: none;
}

#preview {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--bg-secondary);
}

/* 分隔线 */
.resizer {
    width: 12px;
    flex: 0 0 12px;
    margin: 0 8px;
    background-color: var(--resizer-color);
    cursor: col-resize;
    transition: background-color 0.2s;
    border-radius: 8px;
    position: relative;
    z-index: 5;
}

.resizer::before {
    content: '';
    position: absolute;
    left: 3px;
    right: 3px;
    top: 0;
    bottom: 0;
    border-radius: 8px;
    background: rgba(127, 140, 141, 0.28);
    pointer-events: none;
    cursor: col-resize;
}

.resizer:hover {
    background-color: var(--resizer-hover);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.18);
}

.resizer.is-dragging {
    background-color: var(--resizer-hover);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.25);
}

.resizer:hover::before {
    background: rgba(52, 152, 219, 0.55);
}

.resizer.is-dragging::before {
    background: rgba(52, 152, 219, 0.65);
}

/* Markdown 预览样式 */
.markdown-body {
    font-size: 15px;
    line-height: 1.8;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
}

.markdown-body h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.3em;
}

.markdown-body h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.3em;
}

.markdown-body h3 {
    font-size: 1.25em;
}

.markdown-body p {
    margin-bottom: 16px;
}

.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: var(--code-inline-bg);
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    color: var(--text-primary);
}

.markdown-body pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--bg-code);
    border-radius: 6px;
    margin-bottom: 16px;
}

.markdown-body pre code {
    padding: 0;
    background-color: transparent;
    font-size: 100%;
}

.markdown-body blockquote {
    padding: 0 1em;
    color: var(--blockquote-color);
    border-left: 0.25em solid var(--blockquote-border);
    margin-bottom: 16px;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 2em;
    margin-bottom: 16px;
}

.markdown-body li {
    margin-bottom: 4px;
}

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 16px;
}

.markdown-body table th,
.markdown-body table td {
    padding: 8px 13px;
    border: 1px solid var(--table-border);
}

.markdown-body table th {
    background-color: var(--table-stripe);
    font-weight: 600;
}

.markdown-body table tr:nth-child(2n) {
    background-color: var(--table-stripe);
}

.markdown-body img {
    max-width: 100%;
    height: auto;
}

.markdown-body a {
    color: var(--link-color);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--hr-color);
    border: 0;
}

/* 加载提示 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2300;
    color: #fff;
    gap: 15px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 消息提示 */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background-color: var(--toast-bg);
    color: #fff;
    border-radius: 5px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 2400;
}

.toast.show {
    opacity: 1;
}

.toast.success {
    background-color: #27ae60;
}

.toast.error {
    background-color: #e74c3c;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #95a5a6;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

/* 弹窗样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2200;
}

.modal-content {
    background-color: var(--modal-bg);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-content.modal-large {
    max-width: 800px;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.recycle-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.recycle-item {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.recycle-item-main {
    min-width: 0;
}

.recycle-item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recycle-item-meta {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.recycle-item-actions {
    display: inline-flex;
    gap: 8px;
}

.pref-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 12px;
}

.form-control {
    width: 100%;
    min-height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 14px;
}

/* 版本列表 */
.version-list {
    max-height: 400px;
    overflow-y: auto;
}

.version-item {
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.version-item:hover {
    background-color: var(--version-hover-bg);
    border-color: #3498db;
}

.version-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.version-item-date {
    font-size: 13px;
    color: var(--text-secondary);
}

.version-item-message {
    font-size: 14px;
    color: var(--text-primary);
}

.version-info {
    background-color: var(--bg-tertiary);
    padding: 10px 15px;
    border-radius: 5px;
    margin-bottom: 15px;
    font-size: 14px;
    color: var(--text-primary);
}

.version-content {
    background-color: var(--bg-code);
    padding: 15px;
    color: var(--text-primary);
    border-radius: 5px;
    overflow: auto;
    max-height: 300px;
    font-size: 13px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.version-empty {
    text-align: center;
    padding: 40px 20px;
    color: #95a5a6;
}

/* 暗黑模式 - CodeMirror 覆盖 */
[data-theme="dark"] .CodeMirror {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

[data-theme="dark"] .CodeMirror-gutters {
    background-color: var(--bg-tertiary);
    border-right: 1px solid var(--border-color);
}

[data-theme="dark"] .CodeMirror-cursor {
    border-left: 1px solid var(--text-primary);
}

[data-theme="dark"] .CodeMirror-selected {
    background: rgba(52, 152, 219, 0.3);
}

[data-theme="dark"] .CodeMirror-activeline-background {
    background: rgba(255, 255, 255, 0.05);
}

/* 暗黑模式 - highlight.js 覆盖 */
[data-theme="dark"] .hljs {
    background: var(--bg-code);
    color: #c9d1d9;
}

/* 暗黑模式 - 保存状态 */
[data-theme="dark"] .save-status.unsaved {
    color: #ff6b6b;
    background-color: rgba(231, 76, 60, 0.15);
}

[data-theme="dark"] .save-status.saved {
    color: #51cf66;
    background-color: rgba(39, 174, 96, 0.15);
}

/* 侧边栏底部 */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--sidebar-hover);
    padding: 12px 15px;
    position: relative;
}

.sidebar-footer-theme {
    background: rgba(255, 255, 255, 0.02);
    padding: 8px 10px;
}

.sidebar-footer-tools {
    margin-top: auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 10px;
}

.sidebar-footer-theme .sidebar-section-title,
.sidebar-footer-tools .sidebar-section-title {
    display: none;
}

.sidebar-footer-theme .theme-toggle {
    width: 100%;
    justify-content: center;
    padding: 5px 8px;
    border-radius: 12px;
}

.sidebar-footer-theme .theme-label {
    display: none;
}

.sidebar-footer-tools .btn {
    position: relative;
    min-height: 32px;
    padding: 5px 4px;
    font-size: 0;
    font-weight: 500;
    border: 1px solid rgba(236, 240, 241, 0.16);
    background: rgba(236, 240, 241, 0.04);
    color: transparent;
    overflow: visible;
}

.sidebar-footer-tools .btn:hover {
    border-color: rgba(52, 152, 219, 0.35);
    background: rgba(52, 152, 219, 0.1);
    color: transparent;
}

.sidebar-footer-tools .btn span {
    opacity: 0.72;
    font-size: 14px;
    color: var(--sidebar-muted);
    margin: 0;
}

.sidebar-footer-tools .btn:hover span {
    color: var(--sidebar-text);
}

.sidebar-footer-tools .btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    color: #fff;
    background: rgba(17, 24, 39, 0.9);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 30;
}

.sidebar-footer-tools .btn:hover::after,
.sidebar-footer-tools .btn:focus-visible::after {
    opacity: 1;
}

.sidebar-footer .sidebar-section-title {
    padding: 0;
    margin-bottom: 8px;
}

/* 主题切换按钮 */
.theme-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    border-radius: 20px;
    background-color: var(--input-bg);
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
    white-space: nowrap;
}

.theme-toggle:hover {
    background-color: var(--input-focus-bg);
}

.theme-toggle .theme-icon {
    font-size: 16px;
    transition: transform 0.3s;
}

.theme-toggle .theme-label {
    font-size: 12px;
}

.theme-toggle.auto-mode {
    border: 1px solid rgba(52, 152, 219, 0.5);
}

/* 主题切换下拉菜单 */
.theme-menu {
    position: absolute;
    bottom: 100%;
    left: 12px;
    margin-bottom: 4px;
    background-color: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    min-width: 140px;
    box-shadow: 0 4px 12px var(--shadow-color);
    z-index: 100;
    display: none;
}

.theme-menu.show {
    display: block;
}

.theme-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    width: 100%;
    text-align: left;
    transition: background-color 0.2s;
}

.theme-menu-item:hover {
    background-color: var(--version-hover-bg);
}

.theme-menu-item.active {
    background-color: rgba(52, 152, 219, 0.15);
    color: #3498db;
}

/* 登录页面 */
.login-page {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding-bottom: 64px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.login-card {
    background: var(--bg-secondary);
    border-radius: 18px;
    padding: 36px 32px;
    width: 420px;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.login-logo-img {
    width: 100px;
    height: 100px;
    display: block;
    margin: 0 auto 12px;
    border-radius: 20px;
}

.sidebar-logo {
    height: 32px;
    flex-shrink: 0;
}

.sidebar-title-group {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-title {
    font-size: 1.2rem;
    line-height: 1.2;
    font-weight: 600;
}

.sub-title {
    font-size: 0.75rem;
    line-height: 1.2;
    font-weight: 400;
    opacity: 0.8;
}

/* 侧栏折叠态（仅桌面端） */
@media (min-width: 769px) {
    .sidebar.is-collapsed .sidebar-header {
        padding: 12px 8px;
        gap: 10px;
    }

    .sidebar.is-collapsed .sidebar-header-top {
        justify-content: center;
    }

    .sidebar.is-collapsed .sidebar-header h1 {
        width: 40px;
        margin: 0 auto;
        justify-content: center;
        gap: 0;
    }

    .sidebar.is-collapsed .sidebar-title-group,
    .sidebar.is-collapsed > .sidebar-section-title,
    .sidebar.is-collapsed .search-box input,
    .sidebar.is-collapsed .search-clear-btn,
    .sidebar.is-collapsed .doc-filter-toolbar,
    .sidebar.is-collapsed .doc-list,
    .sidebar.is-collapsed .sidebar-footer .sidebar-section-title {
        display: none !important;
    }

    .sidebar.is-collapsed .sidebar-search-toggle-btn {
        display: inline-flex;
    }

    .sidebar.is-collapsed .search-box {
        padding: 8px;
        display: flex;
        justify-content: center;
        border-bottom: 0;
    }

    .sidebar.is-collapsed .sidebar-logo {
        width: 40px;
        height: 40px;
        object-fit: contain;
        display: block;
    }

    .sidebar.is-collapsed + .sidebar-collapse-btn {
        transform: none;
    }

    .sidebar.is-collapsed .sidebar-new-btn {
        width: 40px;
        height: 34px;
        padding: 0;
        margin: 0 auto;
        border-radius: 8px;
        font-size: 18px;
        gap: 0;
    }

    .sidebar.is-collapsed .sidebar-footer-tools {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        padding: 8px 6px;
        margin-top: auto;
    }

    .sidebar.is-collapsed .sidebar-footer-tools .btn {
        width: 40px;
        min-height: 34px;
        padding: 4px;
        border-radius: 8px;
    }
}

@media (max-width: 768px) {
    #sidebarCollapseBtn {
        display: none;
    }
}

.login-header h2 {
    font-size: 24px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 15px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.login-input:focus {
    outline: none;
    border-color: #3498db;
}

.login-code-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.login-code-input {
    flex: 1;
    margin-top: 0;
}

.login-send-btn {
    min-width: 112px;
    justify-content: center;
}

.login-turnstile-wrap {
    margin-top: 2px;
    min-height: 66px;
}

.login-field-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.login-field-hint {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.login-btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border-radius: 10px;
    justify-content: center;
    text-align: center;
    font-weight: 600;
    letter-spacing: 2px;
}

.login-error {
    color: #e74c3c;
    font-size: 13px;
    text-align: center;
    min-height: 20px;
    line-height: 1.5;
}

.login-record-number {
    position: fixed;
    left: 50%;
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 20;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    max-width: calc(100vw - 24px);
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(179, 214, 255, 0.18);
    background: rgba(12, 26, 58, 0.35);
    box-shadow: none;
    backdrop-filter: blur(5px);
    text-align: center;
    font-size: 12px;
    letter-spacing: 0.2px;
    color: rgba(224, 238, 255, 0.68);
    white-space: nowrap;
}

.login-record-number a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.login-record-number .record-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.login-record-number .record-icon {
    width: 13px;
    height: 13px;
    flex: 0 0 auto;
    background: currentColor;
    opacity: 0.9;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 2l7 3v6c0 5-3.5 9.7-7 11-3.5-1.3-7-6-7-11V5l7-3z'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 2l7 3v6c0 5-3.5 9.7-7 11-3.5-1.3-7-6-7-11V5l7-3z'/%3E%3C/svg%3E") no-repeat center / contain;
}

.login-record-number a:hover,
.login-record-number a:focus-visible {
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
    border-bottom-color: currentColor;
}

@media (max-width: 768px) {
    .login-record-number {
        bottom: max(12px, env(safe-area-inset-bottom));
        min-height: 32px;
        padding: 5px 12px;
        font-size: 11px;
    }
}

.login-dev-code-notice {
    display: none;
    text-align: center;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px dashed #3b82f6;
    background: rgba(59, 130, 246, 0.08);
    color: #1d4ed8;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

[data-theme="dark"] .login-dev-code-notice {
    border-color: #60a5fa;
    background: rgba(96, 165, 250, 0.16);
    color: #bfdbfe;
}

/* 会话过期重登录弹窗 */
.reauth-modal {
    z-index: 1200;
}

.reauth-modal-content {
    max-width: 520px;
}

.reauth-tip {
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.reauth-form {
    gap: 12px;
}

.reauth-fallback-btn {
    width: 100%;
    justify-content: center;
    letter-spacing: 0;
    font-weight: 500;
}

/* 工具栏分隔线 */
.toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 8px;
}

/* 用户操作区 */
.user-actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.username-display {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 8px;
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    white-space: nowrap;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background-color: var(--bg-tertiary);
}

.user-actions .theme-toggle {
    border: none;
    background: none;
    padding: 6px;
    border-radius: 4px;
    gap: 0;
    min-width: 0;
}

.user-actions .theme-toggle .theme-icon {
    font-size: 18px;
}

.user-actions .theme-toggle .theme-label {
    display: none;
}

.user-actions .theme-toggle.auto-mode {
    border: none;
    box-shadow: inset 0 0 0 1px rgba(52, 152, 219, 0.45);
}

.user-actions .theme-toggle:hover {
    background-color: var(--bg-tertiary);
}

.user-actions .theme-menu {
    top: calc(100% + 8px);
    right: 0;
    left: auto;
    bottom: auto;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .login-card {
        width: calc(100vw - 28px);
        padding: 28px 18px;
        border-radius: 14px;
    }

    .login-code-row {
        flex-direction: column;
        align-items: stretch;
    }

    .login-send-btn {
        width: 100%;
    }

    .app-container {
        flex-direction: column !important;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
    }

    .editor-container {
        flex-direction: column;
    }

    .resizer {
        width: 100%;
        height: 5px;
        cursor: row-resize;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .toolbar-left,
    .toolbar-right {
        width: 100%;
        justify-content: flex-start;
    }

    .title-input {
        max-width: none;
    }
}

/**
 * 移动端优化样式
 *
 * 该部分定义了在移动设备上的响应式样式，
 * 包括侧边栏抽屉式设计、工具栏优化、触摸目标调整等
 */
@media (max-width: 768px) {
    /* 侧边栏抽屉式 */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        max-height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
        background: var(--bg-primary);
        border-right: 1px solid var(--border-color);
    }
    
    .sidebar.open {
        left: 0;
    }
    
    /* 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    /* 主容器调整 */
    .app-container {
        flex-direction: column !important;
        height: 100vh;
    }
    
    /* 工具栏优化 */
    .toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 12px;
    }
    
    .toolbar-left,
    .toolbar-right {
        width: auto;
        flex-shrink: 0;
    }
    
    /* 按钮最小触摸目标 */
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* 标题输入框 */
    .title-input {
        max-width: none;
        font-size: 16px; /* 防止iOS自动缩放 */
    }
    
    /* 编辑器容器 */
    .editor-container {
        flex-direction: column;
        height: calc(100vh - 120px);
        padding: 8px;
        gap: 8px;
    }
    
    /* 编辑器/预览切换 */
    .mobile-view-toggle {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 6px;
        padding: 6px 10px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
    }
    
    .mobile-view-toggle button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        min-height: 36px;
        padding: 0 12px;
        border: 1px solid var(--border-color);
        border-radius: 999px;
        background: var(--bg-tertiary);
        color: var(--text-secondary);
        cursor: pointer;
        font-size: 13px;
        line-height: 1;
        white-space: nowrap;
        transition: all 0.2s;
    }

    .mobile-view-toggle button[data-view] {
        min-width: 74px;
        font-weight: 600;
    }

    .mobile-view-toggle .mobile-doc-btn {
        width: 38px;
        min-width: 38px;
        padding: 0;
        font-size: 15px;
    }
    
    .mobile-view-toggle button.active {
        color: #fff;
        background: #3498db;
        border-color: #3498db;
    }
    
    /* 编辑器和预览切换显示 */
    .editor-wrapper,
    .preview {
        display: none;
        width: 100%;
        height: 100%;
    }
    
    .editor-wrapper.active,
    .preview.active {
        display: block;
    }
    
    /* 隐藏调整器 */
    .resizer {
        display: none;
    }
    
    /* 底部导航栏 */
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        z-index: 100;
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .mobile-bottom-nav button {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        font-size: 12px;
        cursor: pointer;
        min-height: 44px;
    }
    
    .mobile-bottom-nav button.active {
        color: var(--primary-color);
    }
    
    .mobile-bottom-nav button .icon {
        font-size: 20px;
    }
    
    /* 调整主内容区域高度 */
    .main-content {
        height: calc(100vh - 56px);
        padding-bottom: 56px;
    }
    
    /* 文档列表优化 */
    .doc-list {
        padding: 8px;
    }
    
    .doc-item {
        padding: 12px;
        margin-bottom: 8px;
    }
    
    /* 搜索框优化 */
    .search-box {
        padding: 8px;
    }
    
    .search-box input {
        font-size: 16px; /* 防止iOS自动缩放 */
    }
    
    /* 模态框优化 */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 20px auto;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* AI工具栏折叠 */
    .ai-toolbar {
        flex-wrap: wrap;
    }
    
    .ai-toolbar .dropdown {
        width: 100%;
        margin-bottom: 8px;
    }
}

/* 桌面端隐藏移动端元素 */
@media (min-width: 769px) {
    .mobile-view-toggle,
    .mobile-bottom-nav,
    .sidebar-overlay {
        display: none !important;
    }
    
    .editor-wrapper,
    .preview {
        display: block !important;
    }
}

/* 移动端更多菜单 */
.mobile-more-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
}

.mobile-more-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.mobile-more-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-radius: 16px 16px 0 0;
    max-height: 70vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.mobile-more-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.mobile-more-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-primary);
}

.mobile-more-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-secondary);
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-more-list {
    padding: 8px 0;
}

.mobile-more-item {
    width: 100%;
    padding: 16px 20px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 52px;
}

.mobile-more-item:active {
    background: var(--bg-secondary);
}

/* ========== AI 工具栏 ========== */
.ai-model-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}
.model-select {
    padding: 3px 6px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    max-width: 180px;
    cursor: pointer;
}
.model-select:focus { outline: none; border-color: #3498db; }

.ai-toolbar {
    display: flex;
    gap: 6px;
    padding: 6px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.ai-tool-btn {
    padding: 4px 12px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.ai-tool-btn:hover {
    background: #3498db;
    color: #fff;
    border-color: #3498db;
}

.ai-tool-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 润色菜单 */
.polish-menu {
    position: absolute;
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 4px 0;
    min-width: 140px;
}

.polish-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.15s;
}

.polish-menu-item:hover {
    background: #3498db;
    color: #fff;
}

/* 问答面板 */
.ask-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.ask-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.ask-answer {
    min-height: 100px;
    max-height: 400px;
    overflow-y: auto;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
}

.ask-answer:empty::before {
    content: '回答将显示在这里...';
    color: var(--text-secondary);
}

/* 相关文档列表 */
.related-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 62vh;
    overflow-y: auto;
}

.related-item {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.related-item:hover {
    border-color: #3498db;
    background: rgba(74, 144, 226, 0.05);
}

.related-item-title {
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.related-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

#relatedModal .modal-content {
    max-width: 720px;
}

/* AI 标签展示 */
.ai-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
}

.ai-tag {
    display: inline-block;
    padding: 2px 10px;
    background: rgba(74, 144, 226, 0.1);
    color: #3498db;
    border-radius: 12px;
    font-size: 12px;
}

.ai-category {
    display: inline-block;
    padding: 2px 10px;
    background: rgba(82, 196, 26, 0.1);
    color: #52c41a;
    border-radius: 12px;
    font-size: 12px;
    margin-bottom: 8px;
}

.ai-summary-text {
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
}

/* AI Popover */
.ai-popover {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
    padding: 15px;
    width: 300px;
    z-index: 1000;
    font-size: 13px;
    pointer-events: auto; /* 允许点击 */
}

.ai-popover::before {
    content: '';
    position: absolute;
    top: 0;
    left: -20px;
    width: 20px;
    height: 100%;
}

.ai-popover h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: var(--text-primary);
}

.ai-popover p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.ai-popover .ai-tag {
    cursor: pointer;
    transition: all 0.2s;
}

.ai-popover .ai-tag:hover {
    background: rgba(52, 152, 219, 0.2);
    transform: translateY(-1px);
}

.ai-popover .ai-tag:active {
    transform: translateY(0);
}

/* modal-small */
.modal-small {
    max-width: 420px;
}

/* 确认弹窗样式 */
.confirm-message {
    font-size: 15px;
    color: var(--text-primary);
    margin-bottom: 20px;
    line-height: 1.5;
}

/* ========== 操作日志浮窗 ========== */
.op-log-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 900;
    display: flex;
    flex-direction: column;
    width: 340px;
    height: 30vh;
    min-height: 200px;
    max-height: 40vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px var(--shadow-color);
    overflow: hidden;
    font-size: 12px;
    min-width: 240px;
    transition: all 0.3s ease;
}

.op-log-panel:hover {
    box-shadow: 0 8px 24px var(--shadow-color);
}

.op-log-panel:focus-within {
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3);
}

.op-log-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
    border-radius: 8px 8px 0 0;
    position: sticky;
    top: 0;
    z-index: 1;
}

.op-log-header:active {
    cursor: grabbing;
}

.op-log-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.op-log-queue-info {
    display: flex;
    gap: 10px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
}

.op-log-queue-info span {
    white-space: nowrap;
}

.op-log-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.op-log-control-btn {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.op-log-control-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.op-log-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 10px;
    min-height: 100px;
    line-height: 1.4;
    overscroll-behavior: contain;
}

.op-log-body:empty::before {
    content: '暂无日志';
    color: var(--text-muted);
    font-size: 11px;
}

.op-log-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 3px 0;
    line-height: 1.4;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
    font-size: 11px;
    word-break: break-word;
    transition: background-color 0.2s;
}

.op-log-item:hover {
    background-color: rgba(52, 152, 219, 0.05);
}

.op-log-item:last-child {
    border-bottom: none;
}

.op-log-item .op-log-icon {
    flex-shrink: 0;
    font-size: 11px;
    width: 16px;
    text-align: center;
}

.op-log-item .op-log-time {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 10px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    letter-spacing: -0.5px;
}

.op-log-item .op-log-msg {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.op-log-item.op-log-info { color: var(--text-primary); }
.op-log-item.op-log-success { color: #27ae60; }

.op-log-panel.minimized {
    width: 260px;
    min-height: 0;
    height: auto;
    max-height: none;
}

.op-log-panel.minimized .op-log-header {
    border-bottom: none;
    border-radius: 8px;
}

.op-log-panel.minimized .op-log-body,
.op-log-panel.minimized .task-queue-list {
    display: none;
}
.op-log-item.op-log-error { color: #e74c3c; }
.op-log-item.op-log-warn { color: #f39c12; }
.op-log-item.op-log-loading { color: #3498db; }

/* 不同日志类型的样式增强 */
.op-log-item.op-log-success {
    font-weight: 500;
    background-color: rgba(39, 174, 96, 0.05);
}

.op-log-item.op-log-error {
    font-weight: 500;
    background-color: rgba(231, 76, 60, 0.05);
}

.op-log-item.op-log-warn {
    font-weight: 500;
    background-color: rgba(243, 156, 18, 0.05);
}

.op-log-item.op-log-loading {
    font-weight: 500;
    background-color: rgba(52, 152, 219, 0.05);
}

/* 日志中的 loading 动画 */
.op-log-item.op-log-loading::after {
    content: '';
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border: 1.5px solid #3498db;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 4px;
}

/* 内联确认区 */
.op-log-confirm {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    border-radius: 0 0 8px 8px;
}

.op-log-confirm-msg {
    flex: 1;
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 500;
}

.op-log-confirm-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-xs {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 6px;
}

/* 文档列表中的标签和摘要 */
.doc-item-summary {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 3px;
}

.doc-item-tag {
    font-size: 10px;
    padding: 0 6px;
    background: rgba(74, 144, 226, 0.1);
    color: #3498db;
    border-radius: 8px;
    line-height: 18px;
}

/* ========== 任务队列样式 ========== */
.task-queue-list {
    border-top: 1px solid var(--border-light);
    max-height: 60px;
    overflow-y: auto;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.task-queue-list:empty {
    display: none;
}

.task-queue-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    margin-bottom: 1px;
    border-radius: 3px;
    font-size: 10px;
    transition: all 0.2s;
    cursor: default;
}

.task-queue-item:hover {
    background-color: var(--bg-tertiary);
}

.task-queue-item.running {
    background-color: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.task-queue-index {
    flex-shrink: 0;
    width: 14px;
    text-align: center;
    color: var(--text-muted);
}

.task-queue-type {
    flex: 1;
    min-width: 0;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-queue-id {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 9px;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-queue-status {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 9px;
}

/* 暗黑主题下的任务队列样式 */
[data-theme="dark"] .task-queue-item.running {
    background-color: rgba(52, 152, 219, 0.2);
    color: #58a6ff;
}

/* 暗黑主题下的日志样式 */
[data-theme="dark"] .op-log-item {
    border-bottom-color: var(--border-light);
}

[data-theme="dark"] .op-log-item:hover {
    background-color: rgba(52, 152, 219, 0.1);
}

[data-theme="dark"] .op-log-item.op-log-success {
    background-color: rgba(39, 174, 96, 0.1);
}

[data-theme="dark"] .op-log-item.op-log-error {
    background-color: rgba(231, 76, 60, 0.1);
}

[data-theme="dark"] .op-log-item.op-log-warn {
    background-color: rgba(243, 156, 18, 0.1);
}

[data-theme="dark"] .op-log-item.op-log-loading {
    background-color: rgba(52, 152, 219, 0.1);
}

[data-theme="dark"] .task-queue-item:hover {
    background-color: var(--bg-tertiary);
}

[data-theme="dark"] .task-queue-index {
    color: var(--text-muted);
}

[data-theme="dark"] .task-queue-type {
    color: var(--text-primary);
}

[data-theme="dark"] .task-queue-id {
    color: var(--text-muted);
}

[data-theme="dark"] .task-queue-status {
    color: var(--text-muted);
}

/* ========== 搜索结果样式 ========== */

/* 搜索统计 */
.search-stats {
    padding: 8px 15px;
    font-size: 12px;
    color: var(--sidebar-muted);
    border-bottom: 1px solid var(--sidebar-hover);
    background: var(--sidebar-header-bg);
}

/* 搜索结果项 */
.doc-item.search-result .doc-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

/* 相关度分数 */
.relevance-score {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--sidebar-hover);
    color: var(--sidebar-muted);
}

.relevance-score.high {
    background: rgba(39, 174, 96, 0.2);
    color: #27ae60;
}

.relevance-score.medium {
    background: rgba(243, 156, 18, 0.2);
    color: #f39c12;
}

.relevance-score.low {
    background: rgba(149, 165, 166, 0.2);
    color: #95a5a6;
}

/* 搜索高亮 - 增强版 */
.doc-item mark,
.search-snippet mark {
    background: linear-gradient(120deg, rgba(255, 214, 0, 0.4) 0%, rgba(243, 156, 18, 0.4) 100%);
    color: inherit;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 500;
    box-shadow: 0 0 0 1px rgba(243, 156, 18, 0.2);
    transition: all 0.2s ease;
}

.doc-item mark:hover,
.search-snippet mark:hover {
    background: linear-gradient(120deg, rgba(255, 214, 0, 0.6) 0%, rgba(243, 156, 18, 0.6) 100%);
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.3);
}

[data-theme="dark"] .doc-item mark,
[data-theme="dark"] .search-snippet mark {
    background: linear-gradient(120deg, rgba(255, 214, 0, 0.3) 0%, rgba(243, 156, 18, 0.5) 100%);
    box-shadow: 0 0 0 1px rgba(243, 156, 18, 0.3);
}

[data-theme="dark"] .doc-item mark:hover,
[data-theme="dark"] .search-snippet mark:hover {
    background: linear-gradient(120deg, rgba(255, 214, 0, 0.4) 0%, rgba(243, 156, 18, 0.6) 100%);
    box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.4);
}

/* 多关键词高亮 - 不同颜色 */
.doc-item mark.highlight-1,
.search-snippet mark.highlight-1 {
    background: linear-gradient(120deg, rgba(255, 214, 0, 0.4) 0%, rgba(243, 156, 18, 0.4) 100%);
}

.doc-item mark.highlight-2,
.search-snippet mark.highlight-2 {
    background: linear-gradient(120deg, rgba(52, 152, 219, 0.4) 0%, rgba(41, 128, 185, 0.4) 100%);
    box-shadow: 0 0 0 1px rgba(52, 152, 219, 0.2);
}

.doc-item mark.highlight-3,
.search-snippet mark.highlight-3 {
    background: linear-gradient(120deg, rgba(155, 89, 182, 0.4) 0%, rgba(142, 68, 173, 0.4) 100%);
    box-shadow: 0 0 0 1px rgba(155, 89, 182, 0.2);
}

.doc-item mark.highlight-4,
.search-snippet mark.highlight-4 {
    background: linear-gradient(120deg, rgba(46, 204, 113, 0.4) 0%, rgba(39, 174, 96, 0.4) 100%);
    box-shadow: 0 0 0 1px rgba(46, 204, 113, 0.2);
}

/* 搜索摘要片段 */
.search-snippet {
    font-size: 12px;
    color: var(--sidebar-muted);
    line-height: 1.5;
    margin-top: 4px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* 匹配的标签高亮 */
.doc-item-tag.matched {
    background: rgba(52, 152, 219, 0.3);
    border-color: #3498db;
}

[data-theme="dark"] .doc-item-tag.matched {
    background: rgba(52, 152, 219, 0.4);
}

/* 空搜索结果 */
.empty-state small {
    display: block;
    margin-top: 8px;
}

/* ========== AI 聊天窗口样式 ========== */

/* 聊天弹窗 */
.chat-modal .chat-content {
    width: 600px;
    max-width: 90vw;
    height: 70vh;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    padding: 0;
    border-radius: 16px;
    overflow: hidden;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--modal-bg);
    border-bottom: 1px solid var(--border-color);
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-clear-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.chat-clear-btn:hover {
    opacity: 1;
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 欢迎消息 */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

.chat-welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.chat-welcome-text {
    font-size: 14px;
    line-height: 1.6;
    max-width: 300px;
}

/* 消息气泡 */
.chat-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: chatFadeIn 0.3s ease;
}

@keyframes chatFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-message.user .chat-avatar {
    background: #3498db;
}

.chat-message.assistant .chat-avatar {
    background: #9b59b6;
}

.chat-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.chat-message.user .chat-bubble {
    background: #3498db;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.chat-message.assistant .chat-bubble .markdown-body {
    font-size: 14px;
}

.chat-message.assistant .chat-bubble .markdown-body p:first-child {
    margin-top: 0;
}

.chat-message.assistant .chat-bubble .markdown-body p:last-child {
    margin-bottom: 0;
}

.chat-assistant-actions {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
}

.ask-sources-wrap {
    margin-top: 12px;
    border-top: 1px dashed var(--border-color);
    padding-top: 10px;
}

.ask-sources-title {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.ask-source-item {
    width: 100%;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px;
    margin-bottom: 6px;
    text-align: left;
    cursor: pointer;
}

.ask-source-item:hover {
    border-color: rgba(52, 152, 219, 0.5);
}

.ask-source-index {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: rgba(52, 152, 219, 0.14);
    color: #3498db;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ask-source-main {
    min-width: 0;
}

.ask-source-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.ask-source-meta {
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-secondary);
}

.ask-source-snippet {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.chat-apply-btn {
    border: 1px solid var(--border-light);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 14px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-apply-btn:hover {
    border-color: #3498db;
    color: #3498db;
}

.chat-apply-btn:disabled {
    cursor: default;
    opacity: 0.8;
    color: #27ae60;
    border-color: rgba(39, 174, 96, 0.45);
}

/* 加载动画 */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.chat-typing span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: chatTyping 1.4s infinite ease-in-out both;
}

.chat-typing span:nth-child(1) { animation-delay: -0.32s; }
.chat-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes chatTyping {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* 输入区域 */
.chat-input-area {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    background: var(--modal-bg);
    border-top: 1px solid var(--border-color);
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 14px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
    border-color: #3498db;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: #3498db;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: #2980b9;
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* 暗色模式适配 */
[data-theme="dark"] .chat-messages {
    background: var(--bg-primary);
}

[data-theme="dark"] .chat-message.assistant .chat-bubble {
    background: var(--bg-tertiary);
}

/* ========== Mobile UX Optimization (2026-02) ========== */
@media (max-width: 768px) {
    :root {
        --mobile-bottom-nav-height: 62px;
    }

    .app-container {
        height: 100dvh;
    }

    .workspace-header-stack {
        position: sticky;
        top: 0;
        z-index: 40;
    }

    .toolbar {
        padding: 10px 12px;
        gap: 10px;
        flex-wrap: wrap;
        overflow-x: visible;
    }

    .workspace-toolbar {
        position: relative;
    }

    .workspace-toolbar .toolbar-left {
        width: 100%;
        display: grid;
        grid-template-columns: 32px minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 8px;
        row-gap: 0;
        padding-right: 126px;
    }

    .workspace-toolbar .mobile-top-tools {
        display: flex !important;
        align-items: center;
        justify-content: flex-start;
        gap: 0;
        width: auto;
        max-width: none;
        min-width: 0;
        grid-column: 1;
        grid-row: 1;
        overflow: hidden;
    }

    .workspace-toolbar .mobile-brand-badge {
        flex: 0 0 auto;
        width: 32px;
        height: 32px;
        border-radius: 9px;
        justify-content: center;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
    }

    .workspace-toolbar .mobile-brand-text {
        display: none;
    }

    .workspace-toolbar .mobile-top-tools .mobile-doc-btn {
        flex: 0 0 auto;
        min-height: 34px;
        min-width: 84px;
        padding: 0 10px;
        border-radius: 10px;
        font-size: 13px;
        font-weight: 600;
        white-space: nowrap;
    }

    .document-title-block,
    .workspace-toolbar .document-title-block {
        width: 100%;
        grid-column: 2;
        grid-row: 1;
        flex: none;
        min-width: 0;
    }

    .workspace-toolbar .title-input {
        max-width: none;
        width: 100%;
        min-height: 42px;
        font-size: 16px;
        border-radius: 10px;
    }

    .workspace-toolbar .save-status {
        grid-column: 3;
        grid-row: 1;
        margin-left: 0;
        align-self: center;
        justify-self: start;
        font-size: 12px;
        padding: 2px 6px;
        font-weight: 600;
    }

    .workspace-toolbar .toolbar-right {
        position: absolute;
        top: 7px;
        right: 8px;
        z-index: 3;
        order: 0;
        width: auto;
        display: block;
    }

    .toolbar-divider {
        display: none;
    }

    .workspace-toolbar .toolbar-right > .btn {
        display: none;
    }

    .workspace-toolbar #saveBtn {
        display: none;
    }

    .workspace-toolbar #historyBtn {
        display: none;
    }

    .workspace-toolbar #deleteBtn {
        display: none;
    }

    .user-actions {
        margin-left: auto;
    }

    .workspace-toolbar .user-actions {
        position: static;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        margin-left: 0;
    }

    .username-display {
        max-width: 38vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .workspace-toolbar .user-actions .username-display {
        display: none;
    }

    .workspace-toolbar .user-actions .btn-icon,
    .workspace-toolbar .user-actions .theme-toggle {
        min-width: 32px;
        min-height: 32px;
        padding: 4px;
        border-radius: 9px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
    }

    .workspace-toolbar .user-actions .theme-toggle.auto-mode {
        box-shadow: none;
        border-color: rgba(52, 152, 219, 0.45);
    }

    .workspace-toolbar .user-actions #userPrefsBtn {
        display: none;
    }

    .workspace-ai-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        padding: 4px 8px 6px;
        overflow: visible;
    }

    .ai-tool-btn {
        min-height: 34px;
        padding: 0 10px;
        flex: 0 0 auto;
        border-radius: 999px;
        font-size: 13px;
    }

    .ai-model-label {
        order: 3;
        flex: 1 1 100%;
        margin-left: 0;
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    .model-select {
        min-height: 34px;
        font-size: 14px;
        width: 100%;
        max-width: none;
    }

    .mobile-view-toggle {
        order: 2;
        display: flex;
        position: static;
        align-items: center;
        justify-content: flex-start;
        gap: 6px;
        padding: 0;
        background: transparent;
        border-bottom: none;
        flex: 0 0 auto;
    }

    .mobile-view-toggle button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 34px;
        padding: 0 12px;
        border-radius: 999px;
        border: 1px solid var(--border-color);
        background: var(--bg-tertiary);
        font-size: 13px;
        font-weight: 700;
        line-height: 1;
        white-space: nowrap;
    }

    .mobile-view-toggle button[data-view] {
        flex: 0 0 auto;
        min-width: 80px;
        min-height: 34px;
        padding: 0 12px;
        font-size: 14px;
    }

    .mobile-view-toggle button.active {
        color: #fff;
        background: #3498db;
        border-color: #3498db;
    }

    .main-content {
        height: calc(100dvh - var(--mobile-bottom-nav-height) - env(safe-area-inset-bottom));
        padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    }

    .editor-container {
        height: 100%;
        min-height: 0;
        padding: 8px;
        gap: 8px;
    }

    .editor-pane,
    .preview-pane {
        display: none;
        min-height: 0;
        border-radius: 10px;
    }

    .editor-pane.active,
    .preview-pane.active {
        display: flex;
    }

    .pane-header {
        padding: 10px 12px;
    }

    .CodeMirror {
        font-size: 16px;
    }

    #preview {
        padding: 14px;
    }

    .sidebar {
        width: min(86vw, 340px);
        left: calc(-1 * min(86vw, 340px));
        z-index: 1200;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-overlay {
        z-index: 1100;
        backdrop-filter: blur(2px);
    }

    .sidebar-header {
        padding: 16px 14px;
        gap: 12px;
    }

    .search-box {
        padding: 10px 12px;
    }

    .doc-filter-toolbar {
        padding: 8px 10px 4px;
    }

    .search-box input {
        min-height: 42px;
        border-radius: 10px;
        font-size: 16px;
    }

    .doc-list {
        padding: 10px;
    }

    .doc-item {
        padding: 12px;
        margin-bottom: 8px;
        border-radius: 10px;
    }

    .doc-item-title {
        font-size: 15px;
    }

    .doc-item-date {
        font-size: 12px;
    }

    .doc-favorite-btn {
        font-size: 16px;
    }

    .mobile-bottom-nav {
        height: var(--mobile-bottom-nav-height);
        padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
        backdrop-filter: blur(10px);
        box-shadow: 0 -6px 18px var(--shadow-color);
        z-index: 1300;
    }

    .mobile-bottom-nav button {
        border-radius: 10px;
        min-height: 46px;
    }

    .mobile-bottom-nav button .icon {
        font-size: 18px;
    }

    .mobile-bottom-nav button:active {
        background: var(--bg-tertiary);
    }

    body.modal-open .mobile-bottom-nav {
        transform: translateY(120%);
        pointer-events: none;
    }

    body.login-mode .mobile-bottom-nav {
        display: none !important;
    }

    .mobile-more-content {
        border-radius: 20px 20px 0 0;
        max-height: 78vh;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .mobile-more-header {
        position: sticky;
        top: 0;
        z-index: 1;
        padding: 14px 16px;
        background: var(--bg-primary);
    }

    .mobile-more-close {
        width: 40px;
        height: 40px;
    }

    .mobile-more-item {
        padding: 14px 16px;
        min-height: 50px;
        font-size: 15px;
    }

    .modal {
        align-items: flex-end;
        padding: 10px;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 20px);
        margin: 0;
        border-radius: 16px 16px 12px 12px;
    }

    #relatedModal .modal-content {
        max-height: calc(100dvh - 8px);
    }

    #relatedModal .related-list {
        max-height: calc(100dvh - 170px);
    }

    .modal-header {
        padding: 12px 14px;
    }

    .modal-body {
        padding: 12px 14px;
    }

    .recycle-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .recycle-item-actions {
        width: 100%;
    }

    .recycle-item-actions .btn {
        flex: 1 1 0;
        justify-content: center;
    }

    .modal-actions {
        display: flex;
        flex-wrap: wrap;
    }

    .modal-actions .btn {
        flex: 1 1 calc(50% - 6px);
        min-height: 40px;
        justify-content: center;
    }

    .chat-modal {
        align-items: stretch;
        padding: 0;
    }

    .chat-modal .chat-content {
        width: 100%;
        max-width: 100%;
        height: calc(100dvh - env(safe-area-inset-bottom));
        max-height: none;
        border-radius: 0;
    }

    .chat-messages {
        padding: 14px;
        gap: 12px;
    }

    .chat-message {
        max-width: 94%;
    }

    .chat-input-area {
        gap: 10px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        position: sticky;
        bottom: 0;
    }

    .chat-input {
        font-size: 16px;
        min-height: 42px;
        max-height: 96px;
    }

    .chat-send-btn {
        width: 42px;
        height: 42px;
    }

    .markdown-body table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .login-page {
        min-height: 100dvh;
        padding: 14px;
    }

    .login-card {
        width: 100%;
        max-width: 430px;
        margin: 0 auto;
        padding: 24px 16px;
    }

    .login-header {
        margin-bottom: 22px;
    }

    .login-logo-img {
        width: 82px;
        height: 82px;
        border-radius: 16px;
    }

    .login-input,
    .login-btn,
    .login-send-btn {
        min-height: 44px;
    }

    .reauth-modal .modal-content {
        max-height: calc(100dvh - 20px);
    }
}

@media (min-width: 769px) {
    .workspace-toolbar .mobile-top-tools {
        display: none !important;
    }
}

@media (max-width: 560px) {
    .workspace-toolbar .toolbar-left {
        padding-right: 118px;
    }

    .workspace-toolbar .mobile-top-tools {
        max-width: calc(100% - 118px);
    }

    .username-display {
        display: none;
    }

    .ai-model-label {
        width: auto;
        margin-left: 0;
        justify-content: flex-start;
    }

    .model-select {
        width: 100%;
        max-width: none;
    }

    .mobile-view-toggle button[data-view] {
        font-size: 14px;
        min-width: 76px;
        min-height: 34px;
        padding: 0 10px;
    }

    .chat-header h3 {
        font-size: 15px;
    }

    .search-snippet {
        font-size: 11px;
    }
}

@media (max-width: 430px) {
    :root {
        --mobile-bottom-nav-height: 58px;
    }

    .toolbar {
        padding: 8px 10px;
        gap: 8px;
    }

    .workspace-toolbar .toolbar-left {
        padding-right: 114px;
    }

    .workspace-toolbar .mobile-top-tools {
        max-width: calc(100% - 114px);
        gap: 6px;
    }

    .workspace-toolbar .mobile-brand-badge {
        width: 30px;
        height: 30px;
    }

    .workspace-toolbar .mobile-top-tools .mobile-doc-btn {
        min-height: 32px;
        padding: 0 8px;
        font-size: 12px;
        min-width: 78px;
    }

    .workspace-toolbar .save-status {
        font-size: 11px;
        padding: 2px 6px;
    }

    .workspace-ai-toolbar {
        padding: 4px 8px 6px;
        gap: 5px;
    }

    .ai-tool-btn {
        min-height: 32px;
        padding: 0 9px;
        font-size: 12px;
    }

    .model-select {
        width: 100%;
        min-height: 33px;
        font-size: 13px;
    }

    .mobile-view-toggle {
        gap: 6px;
        padding: 0;
    }

    .mobile-view-toggle button[data-view] {
        min-height: 32px;
        min-width: 72px;
        padding: 0 10px;
        font-size: 13px;
    }

    .mobile-bottom-nav button {
        font-size: 11px;
        gap: 2px;
    }

    .mobile-bottom-nav button .icon {
        font-size: 17px;
    }

    .mobile-more-item {
        font-size: 14px;
        padding: 12px 14px;
        min-height: 48px;
    }

    .modal-header h3 {
        font-size: 16px;
    }

    .chat-header h3 {
        font-size: 14px;
    }

    .chat-avatar {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .chat-bubble {
        font-size: 13px;
        padding: 10px 12px;
    }

    .chat-message.assistant .chat-bubble .markdown-body {
        font-size: 13px;
    }

    .chat-input-area {
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    }

    .chat-input {
        min-height: 40px;
        font-size: 15px;
    }

    .chat-send-btn {
        width: 40px;
        height: 40px;
    }

    .login-card {
        padding: 20px 14px;
    }

    .login-logo-img {
        width: 72px;
        height: 72px;
    }
}

@media (max-width: 390px) {
    .char-count {
        display: none;
    }

    .workspace-ai-toolbar {
        padding: 6px;
    }

    .ai-model-label {
        width: auto;
    }

    .model-select {
        width: 100%;
    }

    .sidebar {
        width: 88vw;
        left: -88vw;
    }

    .main-title {
        font-size: 1.05rem;
    }

    .sub-title {
        font-size: 0.7rem;
    }

    .doc-item {
        padding: 10px;
    }

    .doc-item-title {
        font-size: 14px;
    }

    .mobile-bottom-nav button span:last-child {
        font-size: 10px;
    }

    .modal-actions .btn {
        flex-basis: 100%;
    }
}

@media (max-width: 360px) {
    .sidebar {
        width: 90vw;
        left: -90vw;
    }

    .sub-title {
        display: none;
    }

    .mobile-bottom-nav button span:last-child {
        display: none;
    }

    .mobile-bottom-nav button .icon {
        font-size: 20px;
    }

    .chat-message {
        max-width: 98%;
    }
}

/* iPhone 15 Pro Max (430 x 932 @3x) targeted tuning */
@media only screen and (device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait) {
    :root {
        --mobile-bottom-nav-height: 62px;
    }

    .toolbar {
        padding: 10px 12px;
        gap: 10px;
    }

    .workspace-toolbar .toolbar-left {
        padding-right: 122px;
    }

    .workspace-toolbar .mobile-top-tools {
        max-width: calc(100% - 122px);
    }

    .workspace-toolbar .title-input {
        min-height: 44px;
        font-size: 16px;
    }

    .workspace-ai-toolbar {
        padding: 5px 9px 7px;
        gap: 6px;
    }

    .ai-tool-btn {
        min-height: 34px;
        font-size: 13px;
    }

    .model-select {
        width: 100%;
        min-height: 34px;
        font-size: 14px;
    }

    .sidebar {
        width: min(82vw, 340px);
        left: calc(-1 * min(82vw, 340px));
    }

    .mobile-view-toggle {
        gap: 6px;
        padding: 0;
    }

    .mobile-view-toggle button[data-view] {
        min-height: 34px;
        min-width: 76px;
        font-size: 13px;
        padding: 0 10px;
    }

    .mobile-bottom-nav {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .mobile-bottom-nav button {
        font-size: 12px;
        gap: 3px;
    }

    .mobile-bottom-nav button .icon {
        font-size: 18px;
    }

    .mobile-more-item {
        min-height: 50px;
        font-size: 15px;
    }

    .chat-header h3 {
        font-size: 15px;
    }

    .chat-bubble {
        font-size: 14px;
        padding: 11px 14px;
    }

    .chat-message.assistant .chat-bubble .markdown-body {
        font-size: 14px;
    }

    .chat-input {
        min-height: 42px;
        font-size: 16px;
    }

    .login-card {
        max-width: 408px;
        padding: 24px 18px;
    }
}

@media only screen and (device-width: 932px) and (device-height: 430px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape) {
    .mobile-bottom-nav {
        height: 56px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }

    .workspace-header-stack {
        position: relative;
    }
}
