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

:root {
    /* 底色 */
    --bg-page: #f7f9fa;          /* 极浅灰蓝页面底 */
    --bg-panel: #ffffff;          /* 纯白面板 */
    --bg-subtle: #f1f4f6;        /* 次级浅灰 */
    --bg-hover: #eef2f5;         /* 悬停浅灰 */

    /* 主色：科技蓝 */
    --blue: #3b82f6;
    --blue-dark: #2563eb;
    --blue-light: #60a5fa;
    --blue-soft: #eff6ff;        /* 极浅蓝底 */

    /* 行动绿 */
    --green: #10b981;
    --green-dark: #059669;
    --green-soft: #ecfdf5;

    /* 文字 */
    --text: #1f2937;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;

    /* 边框 / 分隔 */
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    /* 状态色 */
    --error: #ef4444;
    --error-soft: #fef2f2;
    --success-soft: #ecfdf5;

    /* 轻阴影（替代毛玻璃） */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);

    --radius: 10px;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-page);
    color: var(--text);
    min-height: 100vh;
    padding: 0;                    /* 全屏展示 */
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* 全屏容器 */
.container {
    max-width: none;
    margin: 0;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== 顶栏 ===== */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: var(--text);
    text-decoration: none;
}
.logo:hover { color: var(--blue); }
.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s;
}
.back-link:hover { color: var(--blue); }

h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    margin: 20px 24px 4px;
}
.subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0 24px 16px;
}

/* ===== 工具栏 ===== */
.toolbar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 8px 16px;
    border-bottom: none;
    margin: 0 24px;
    box-shadow: var(--shadow-sm);
}
.tool-group {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--bg-subtle);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.tool-btn {
    min-width: 32px;
    height: 30px;
    padding: 0 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tool-btn:hover {
    background: var(--bg-panel);
    color: var(--blue);
    box-shadow: var(--shadow-sm);
}
.tool-btn.active-view {
    background: var(--blue-soft);
    color: var(--blue-dark);
    border-color: var(--blue-light);
    font-weight: 600;
}

.toolbar-right {
    margin-left: auto;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.tool-action {
    padding: 6px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.tool-action:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: var(--blue-soft);
}
.tool-action.primary {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.tool-action.primary:hover {
    background: var(--blue-dark);
    border-color: var(--blue-dark);
    color: #fff;
}

/* ===== AI 工具栏 ===== */
.ai-toolbar {
    display: none;
    gap: 6px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-top: none;
    padding: 8px 16px;
    flex-wrap: wrap;
    align-items: center;
    margin: 0 24px;
}
.ai-toolbar.show { display: flex; }
.ai-label {
    font-size: 0.75rem;
    color: var(--blue);
    font-weight: 700;
    margin-right: 6px;
}
.ai-btn {
    padding: 6px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.ai-btn:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: var(--blue-soft);
}
.ai-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-btn.chat-btn {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
    font-weight: 600;
}
.ai-btn.chat-btn:hover { background: var(--green-dark); }

/* ===== 搜索栏 ===== */
.search-bar {
    display: none;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-top: none;
    padding: 10px 16px;
    align-items: center;
    gap: 10px;
    margin: 0 24px;
}
.search-bar.show { display: flex; }
.search-bar input {
    flex: 1;
    padding: 8px 14px;
    background: var(--bg-page);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.875rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-bar input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    background: var(--bg-panel);
}
.search-bar button {
    padding: 8px 14px;
    background: var(--blue);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.search-bar button:hover { background: var(--blue-dark); }
.search-info {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ===== 主区域 ===== */
.main-wrap {
    display: flex;
    gap: 12px;
    padding: 0 24px 24px;
    flex: 1;
    min-height: 0;
    transition: gap 0.2s;
}
.editor-wrap {
    flex: 1;
    display: grid;
    grid-template-columns: 220px 1fr 1fr;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
    min-height: calc(100vh - 220px);
    box-shadow: var(--shadow);
}

/* 视图模式 */
.editor-wrap.mode-write { grid-template-columns: 220px 1fr 0; }
.editor-wrap.mode-write .editor-pane:last-child { display: none; }
.editor-wrap.mode-read { display: block; background: var(--bg-panel); }
.editor-wrap.mode-read .doc-pane { display: none !important; }
.editor-wrap.mode-read .editor-pane:first-child { display: none !important; }
.editor-wrap.mode-read .editor-pane:last-child {
    display: block;
    width: 100%;
    border: none;
}
.editor-wrap.mode-read #preview {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 48px 32px;
    font-size: 1.05rem;
    border: none;
}

/* ===== 文档列表 ===== */
.doc-pane {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-panel);
}
.doc-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    max-height: 220px;
}
.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 2px;
    gap: 6px;
}
.doc-item:hover { background: var(--bg-hover); color: var(--blue); }
.doc-item.active {
    background: var(--blue-soft);
    color: var(--blue-dark);
    border-left: 3px solid var(--blue);
    font-weight: 600;
}
.doc-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.doc-item-del {
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.doc-item:hover .doc-item-del { opacity: 1; }
.doc-item-del:hover { color: var(--error); }
.doc-actions { display: flex; gap: 6px; padding: 0 8px 8px; }
.doc-add, .doc-import {
    flex: 1;
    padding: 8px;
    background: var(--bg-panel);
    border: 1px dashed var(--border-strong);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}
.doc-add:hover, .doc-import:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: var(--blue-soft);
}

/* ===== 目录大纲 ===== */
.outline-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
    border-top: 1px solid var(--border);
}
.outline-item {
    display: block;
    padding: 6px 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border-left: 2px solid transparent;
    margin-bottom: 2px;
    word-break: break-all;
}
.outline-item:hover { background: var(--bg-hover); color: var(--blue); }
.outline-item.h1 { padding-left: 10px; font-weight: 700; color: var(--text); }
.outline-item.h2 { padding-left: 20px; }
.outline-item.h3 { padding-left: 30px; font-size: 0.78rem; }
.outline-item.h4 { padding-left: 40px; font-size: 0.75rem; }
.outline-empty {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
    padding: 20px 8px;
}

/* ===== 编辑器 ===== */
.editor-pane {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    min-width: 0;
}
.editor-pane:last-child { border-right: none; }
.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
    flex-shrink: 0;
    gap: 8px;
}
.pane-stats { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }

/* 字数目标 */
.goal-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 400;
}
.goal-input {
    width: 60px;
    padding: 3px 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.72rem;
    font-family: inherit;
    outline: none;
}
.goal-input:focus { border-color: var(--blue); }
.goal-bar {
    width: 60px;
    height: 6px;
    background: var(--bg-subtle);
    border-radius: 3px;
    overflow: hidden;
}
.goal-fill {
    height: 100%;
    width: 0%;
    background: var(--blue);
    border-radius: 3px;
    transition: width 0.3s, background 0.3s;
}
.goal-fill.done { background: var(--green); }

#input {
    flex: 1;
    width: 100%;
    background: var(--bg-panel);
    border: none;
    color: var(--text);
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    line-height: 1.75;
    padding: 20px;
    resize: none;
    outline: none;
    tab-size: 2;
}
#input::placeholder { color: var(--text-muted); }

#preview {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    line-height: 1.8;
    font-size: 0.92rem;
    color: var(--text);
    background: var(--bg-panel);
    transition: background 0.2s, color 0.2s;
}
#preview.light { background: #ffffff; color: #2c3e50; }
#preview.light h1, #preview.light h2, #preview.light h3, #preview.light h4 { color: #1f2937; }
#preview.light h1 { border-bottom-color: var(--border); }
#preview.light code { background: #f3f4f6; color: #c0392b; }
#preview.light pre { background: #f9fafb; border-color: var(--border); }
#preview.light pre code { background: none; color: #2c3e50; }
#preview.light blockquote { border-left-color: var(--blue); background: #f9fafb; color: #6b7280; }
#preview.light a { color: var(--blue); }
#preview.light th, #preview.light td { border-color: var(--border); }
#preview.light th { background: #f9fafb; color: #1f2937; }
#preview.light hr { background: var(--border); }

#preview h1, #preview h2, #preview h3, #preview h4 {
    color: var(--text);
    margin: 24px 0 12px;
    font-weight: 700;
    line-height: 1.3;
}
#preview h1 {
    font-size: 1.6rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}
#preview h2 { font-size: 1.3rem; }
#preview h3 { font-size: 1.1rem; }
#preview h4 { font-size: 1rem; }
#preview p { margin-bottom: 12px; color: var(--text); }
#preview ul, #preview ol { margin: 12px 0 12px 24px; }
#preview li { margin-bottom: 4px; }
#preview code {
    background: var(--blue-soft);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.85rem;
    color: var(--blue-dark);
}
#preview pre {
    background: var(--bg-subtle);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow-x: auto;
    margin-bottom: 12px;
}
#preview pre code { background: none; padding: 0; color: var(--text); }
#preview blockquote {
    border-left: 3px solid var(--blue);
    padding: 8px 16px;
    margin: 12px 0;
    color: var(--text-secondary);
    background: var(--blue-soft);
    border-radius: 0 8px 8px 0;
}
#preview a { color: var(--blue); text-decoration: none; }
#preview a:hover { text-decoration: underline; }
#preview table { border-collapse: collapse; width: 100%; margin: 12px 0; }
#preview th, #preview td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
#preview th { background: var(--bg-subtle); color: var(--text); font-weight: 600; }
#preview img { max-width: 100%; border-radius: 8px; }
#preview hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

/* ===== 双链 ===== */
.wiki-link {
    color: var(--blue);
    text-decoration: none;
    border-bottom: 1px dashed var(--blue-light);
    cursor: pointer;
    transition: background 0.15s, border-bottom-style 0.15s;
    padding: 0 2px;
}
.wiki-link:hover {
    background: var(--blue-soft);
    border-bottom-style: solid;
}
.wiki-link.missing {
    color: var(--error);
    border-bottom-color: var(--error);
}
.backlinks {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
}
#preview.light .backlinks { border-top-color: var(--border); }
.backlinks-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 10px;
}
.backlinks-list { display: flex; flex-wrap: wrap; gap: 8px; }
.backlink-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.backlink-item:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: var(--blue-soft);
}

/* ===== 搜索高亮与补全 ===== */
.search-highlight {
    background: #fef3c7;
    color: #92400e;
    padding: 1px 2px;
    border-radius: 3px;
}
.autocomplete {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: 2000;
    display: none;
    min-width: 200px;
}
.autocomplete.show { display: block; }
.autocomplete-item {
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover,
.autocomplete-item.active {
    background: var(--blue-soft);
    color: var(--blue-dark);
}
.autocomplete-empty {
    padding: 8px 14px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* ===== 状态提示 ===== */
.status {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    display: none;
}
.status.show { display: block; }
.status.success {
    background: var(--success-soft);
    border: 1px solid #a7f3d0;
    color: var(--green-dark);
}
.status.error {
    background: var(--error-soft);
    border: 1px solid #fecaca;
    color: var(--error);
}

/* ===== 页脚 ===== */
.footer {
    text-align: center;
    padding: 20px 24px;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
}
.footer a { color: var(--text-muted); text-decoration: none; }
.footer a:hover { color: var(--blue); }

.paste-hint {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--blue);
    color: #fff;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    display: none;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}
.paste-hint.show { display: block; }

/* ===== 写作助手侧边栏 ===== */
.chat-panel {
    width: 380px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: none;
    flex-direction: column;
    max-height: calc(100vh - 100px);
    position: sticky;
    top: 12px;
    box-shadow: var(--shadow-md);
}
.chat-panel.show { display: flex; }
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
    border-radius: var(--radius) var(--radius) 0 0;
}
.chat-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-header-actions { display: flex; gap: 4px; }
.chat-header-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}
.chat-header-btn:hover { color: var(--blue); background: var(--bg-hover); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 300px;
    max-height: calc(100vh - 360px);
    background: var(--bg-page);
}
.chat-msg {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.6;
    word-wrap: break-word;
    max-width: 90%;
}
.chat-msg.user {
    align-self: flex-end;
    background: var(--blue);
    color: #fff;
    border-bottom-right-radius: 3px;
}
.chat-msg.ai {
    align-self: flex-start;
    background: var(--bg-panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 3px;
    max-width: 95%;
    box-shadow: var(--shadow-sm);
}
.chat-msg.ai .msg-content { white-space: normal; word-break: break-word; }
.chat-msg.ai .msg-content p { margin-bottom: 8px; }
.chat-msg.ai .msg-content p:last-child { margin-bottom: 0; }
.chat-msg.ai .msg-content ul,
.chat-msg.ai .msg-content ol { margin: 8px 0 8px 20px; }
.chat-msg.ai .msg-content li { margin-bottom: 4px; }
.chat-msg.ai .msg-content code {
    background: var(--bg-subtle);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--blue-dark);
}
.chat-msg.ai .msg-content pre {
    background: var(--bg-subtle);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}
.chat-msg.ai .msg-content pre code { background: none; padding: 0; }
.chat-msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.msg-action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.msg-action-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.chat-typing {
    align-self: flex-start;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 8px 12px;
    font-style: italic;
}

.chat-input-area {
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    background: var(--bg-panel);
    border-radius: 0 0 var(--radius) var(--radius);
}
.chat-context-info {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.chat-context-info .ctx-name {
    color: var(--blue);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}
.chat-input-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input-row textarea {
    flex: 1;
    background: var(--bg-page);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    padding: 10px 14px;
    resize: none;
    outline: none;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    overflow-y: auto;
}
.chat-input-row textarea:focus {
    border-color: var(--blue);
    background: var(--bg-panel);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}
.chat-input-row textarea::-webkit-scrollbar { width: 4px; }
.chat-input-row textarea::-webkit-scrollbar-track { background: transparent; }
.chat-input-row textarea::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
.chat-input-row textarea::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.chat-send-btn {
    width: 44px;
    height: 44px;
    background: var(--blue);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
    font-family: inherit;
}
.chat-send-btn:hover { background: var(--blue-dark); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-hints { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chat-hint-btn {
    padding: 4px 10px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.chat-hint-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }

/* ===== 弹窗 ===== */
.help-overlay,
.ai-settings-overlay,
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}
.help-overlay.show, .ai-settings-overlay.show { display: flex; }
.modal-overlay { z-index: 1001; }

.help-panel,
.ai-settings-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    max-width: 720px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.ai-settings-panel { max-width: 500px; }
.help-header,
.ai-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}
.help-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
    padding: 0 8px;
}
.help-close:hover { color: var(--text); }
.help-body,
.ai-settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

/* 帮助面板内部 */
.help-section { margin-bottom: 24px; }
.help-section:last-child { margin-bottom: 0; }
.help-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.help-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.help-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text);
    padding: 8px 10px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.help-item .icon-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    background: var(--blue-soft);
    border-radius: 6px;
    color: var(--blue-dark);
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 700;
}
.help-item code {
    background: var(--bg-subtle);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    color: var(--blue-dark);
    font-family: 'SF Mono', 'Consolas', monospace;
}
.help-item .desc { color: var(--text-muted); font-size: 0.8rem; }
.help-text p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.9;
    margin-bottom: 6px;
}
.help-text b { color: var(--blue-dark); }
.help-text code {
    background: var(--bg-subtle);
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--blue-dark);
    font-size: 0.8rem;
}

/* AI 设置面板内部 */
.ai-form-group { margin-bottom: 16px; }
.ai-form-group label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}
.ai-form-group input,
.ai-form-group select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.ai-form-group input:focus,
.ai-form-group select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}
.ai-form-group .hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.6;
}
.ai-actions {
    display: flex;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-page);
    border-radius: 0 0 14px 14px;
}
.ai-actions .btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.ai-actions .btn-save { background: var(--blue); color: #fff; }
.ai-actions .btn-save:hover { background: var(--blue-dark); }
.ai-actions .btn-clear { background: var(--bg-subtle); color: var(--text-secondary); border: 1px solid var(--border); }
.ai-actions .btn-clear:hover { color: var(--blue); border-color: var(--blue); }

.privacy-note {
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--blue-soft);
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 10px 14px;
    line-height: 1.7;
    margin-bottom: 16px;
}

#historyList::-webkit-scrollbar { width: 6px; }
#historyList::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* 通用滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== 响应式 ===== */
@media (max-width: 1400px) { .chat-panel { width: 340px; } }
@media (max-width: 1100px) {
    .editor-wrap { grid-template-columns: 180px 1fr 1fr; }
    .chat-panel { width: 300px; }
}
@media (max-width: 900px) {
    .main-wrap { flex-direction: column; }
    .editor-wrap { grid-template-columns: 1fr; min-height: 0; }
    .doc-pane { display: none; }
    .editor-pane {
        border-right: none;
        border-bottom: 1px solid var(--border);
        min-height: 320px;
    }
    .editor-pane:last-child { border-bottom: none; }
    .toolbar-right { margin-left: 0; width: 100%; justify-content: flex-start; margin-top: 8px; }
    .toolbar, .ai-toolbar, .search-bar { margin: 0 12px; }
    .main-wrap { padding: 0 12px 12px; }
    h1, .subtitle { margin-left: 12px; margin-right: 12px; }
    .chat-panel {
        width: 100%;
        max-height: 70vh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        border-radius: 12px 12px 0 0;
        z-index: 500;
        box-shadow: var(--shadow-lg);
    }
    .chat-messages { max-height: 40vh; }
}
@media (max-width: 600px) {
    .tool-action { padding: 6px 10px; font-size: 0.72rem; }
    .goal-wrap { display: none; }
    .help-grid { grid-template-columns: 1fr; }
    .navbar { padding: 0 16px; }
}

/* ===== 打印样式 ===== */
@media print {
    body { background: white; color: black; padding: 0; }
    .navbar, h1, .subtitle, .toolbar, .ai-toolbar, .search-bar, .doc-pane,
    .editor-pane:first-child, .footer, .status, .paste-hint, .help-overlay,
    .ai-settings-overlay, .autocomplete, .chat-panel, .modal-overlay { display: none !important; }
    .editor-wrap { display: block; border: none; background: white; min-height: auto; }
    .editor-pane:last-child { display: block; border: none; }
    .pane-header { display: none; }
    #preview {
        background: white !important;
        color: black !important;
        padding: 20px;
        font-size: 12pt;
        line-height: 1.6;
    }
    #preview h1, #preview h2, #preview h3, #preview h4 {
        color: #111827 !important;
        page-break-after: avoid;
    }
    #preview code { background: #f3f4f6 !important; color: #c0392b !important; }
    #preview pre { background: #f9fafb !important; border: 1px solid #ddd !important; }
    #preview pre code { color: #2c3e50 !important; }
    #preview blockquote {
        border-left: 3px solid #3b82f6 !important;
        background: #f9fafb !important;
        color: #6b7280 !important;
    }
    #preview th, #preview td { border: 1px solid #ddd !important; }
    #preview th { background: #f9fafb !important; color: #111827 !important; }
    #preview a { color: #111827 !important; text-decoration: underline; }
}
/* ==========================================
   移动端专属 UI 样式 (App 体验)
   ========================================== */
/* 默认隐藏移动端组件 */
.mobile-header { display: none; }
.mobile-menu-overlay { display: none; }

@media (max-width: 768px) {
    /* 1. 隐藏桌面端臃肿的工具栏 */
    #topToolbar, .ai-toolbar { display: none !important; }
    
    /* 2. 显示极简头部 */
    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
        background: #ffffff;
        border-bottom: 1px solid #e5e7eb;
        position: fixed;
        top: 0; left: 0; right: 0;
        z-index: 1000;
    }
    .mobile-title { font-weight: 800; color: #0a3d2e; font-size: 1.1rem; }
    .mobile-icon-btn { background: none; border: none; font-size: 1.4rem; color: #4b5563; cursor: pointer; padding: 5px; }
    
    /* 3. 调整主容器间距，给固定头部留出空间 */
    .container { padding: 60px 10px 10px 10px; }
    
    /* 4. 编辑区全屏，隐藏左侧文档列表 */
    .main-wrap { display: block; }
    .editor-wrap { display: flex; flex-direction: column; min-height: calc(100vh - 80px); background: transparent; border: none; }
    .doc-pane { display: none !important; } /* 手机端隐藏文档列表 */
    
    /* 输入和预览上下平分屏幕 */
    .editor-pane {
        flex: 1;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        background: #fff;
        margin-bottom: 10px;
        min-height: 40vh;
    }
    .editor-pane .pane-header { display: none; } /* 隐藏冗余的标题栏 */
    #input, #preview { border-radius: 8px; }
    
    /* 5. 聊天框变成全屏覆盖 */
    .chat-panel {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100% !important;
        height: 100vh;
        z-index: 2000;
        border-radius: 0;
        border: none;
        display: none; /* 默认隐藏，由 JS 控制显示 */
        transform: translateY(100%); /* 初始在屏幕外 */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .chat-panel.show { 
        display: flex; 
        transform: translateY(0); /* 滑入屏幕 */
    }
    .chat-header { border-radius: 0; }
    .chat-messages { max-height: calc(100vh - 120px); padding-bottom: 80px; }
    
    /* 6. 移动端底部抽屉菜单 */
    .mobile-menu-overlay {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 3000;
        align-items: flex-end; /* 靠底对齐 */
        backdrop-filter: blur(2px);
    }
    .mobile-menu-overlay.show { display: flex; }
    
    .mobile-menu-content {
        background: #ffffff;
        width: 100%;
        border-radius: 20px 20px 0 0;
        padding: 20px;
        animation: slideUp 0.3s ease-out;
    }
    @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
    
    .mobile-menu-header { font-size: 1.1rem; font-weight: 700; margin-bottom: 15px; text-align: center; color: #374151; }
    .mobile-menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 15px; }
    .mobile-menu-item {
        padding: 15px 10px;
        background: #f3f4f6;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        font-size: 0.95rem;
        font-weight: 600;
        color: #1f2937;
        text-align: left;
        cursor: pointer;
        display: flex;
        align-items: center;
    }
    .mobile-menu-item:active { background: #e5e7eb; }
    
    .mobile-menu-close {
        width: 100%;
        padding: 15px;
        background: #ffffff;
        border: 1px solid #d1d5db;
        border-radius: 10px;
        font-size: 1rem;
        font-weight: 600;
        color: #4b5563;
        cursor: pointer;
    }
    
    /* 7. 调大移动端字体和行距，提升阅读体验 */
    #input { font-size: 1rem; padding: 15px; }
    #preview { font-size: 1rem; padding: 15px; }
}
/* ==========================================
   固定顶部工具栏
   ========================================== */
/* 1. 基础工具栏固定在顶部 */
#topToolbar {
    position: sticky !important;
    top: 0;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* 2. AI 工具栏紧贴在它下面 */
#aiToolbar {
    position: sticky !important;
    top: 56px; /* 基础工具栏的高度，根据实际高度微调，一般是 50-60px */
    z-index: 999;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* 手机端隐藏掉基础工具栏，所以手机端不用管 */
@media (max-width: 768px) {
    #topToolbar, #aiToolbar {
        position: static !important; /* 手机端恢复默认，因为用了极简菜单 */
    }
}