/* ==========================================================================
   写作区专用样式（全量主题变量化）
   ========================================================================== */

/* ================= 默认主题：暗夜灰白 (Gray) ================= */
:root {
    --writer-bg: #1c1c1e;          /* 正文背景 */
    --writer-panel-bg: #161618;    /* 侧边栏背景 */
    --writer-text: #d1d1d6;        /* 正文文字 */
    --writer-text-secondary: #a1a1aa; /* 次要文字 */
    --writer-text-muted: #71717a;  /* 弱化文字 */
    --writer-border: #2c2c2e;      /* 边框线 */
    --writer-hover: #2a2a2c;       /* 悬停背景 */
    --writer-active: #6366f1;      /* 高亮色 */
    --writer-active-bg: rgba(99, 102, 241, 0.15);
    --writer-input-bg: rgba(0, 0, 0, 0.2); /* 输入框背景 */
}
/* 明亮白主题 */
body[data-w-theme="light"] {
    --writer-bg: #f9f9fb;
    --writer-panel-bg: #f2f2f7;
    --writer-text: #2c2c2e;
    --writer-text-secondary: #636366;
    --writer-text-muted: #8e8e93;
    --writer-border: #e5e5ea;
    --writer-hover: #e5e5ea;
    --writer-active: #4f46e5;
    --writer-active-bg: rgba(79, 70, 229, 0.1);
    --writer-input-bg: rgba(0, 0, 0, 0.04);
}
/* 羊皮纸主题 */
body[data-w-theme="parchment"] {
    --writer-bg: #f4ecd8;
    --writer-panel-bg: #ebdabf;
    --writer-text: #433422;
    --writer-text-secondary: #7a6550;
    --writer-text-muted: #a08b73;
    --writer-border: #dac6a8;
    --writer-hover: #e0cba8;
    --writer-active: #d97706;
    --writer-active-bg: rgba(217, 119, 6, 0.15);
    --writer-input-bg: rgba(0, 0, 0, 0.06);
}
/* 护眼绿主题 */
body[data-w-theme="green"] {
    --writer-bg: #c8e6c9;
    --writer-panel-bg: #b5d6b6;
    --writer-text: #1b3a2a;
    --writer-text-secondary: #3a5f48;
    --writer-text-muted: #5a8268;
    --writer-border: #9cc29d;
    --writer-hover: #aed4af;
    --writer-active: #059669;
    --writer-active-bg: rgba(5, 150, 105, 0.15);
    --writer-input-bg: rgba(0, 0, 0, 0.06);
}
/* 深海蓝主题 */
body[data-w-theme="blue"] {
    --writer-bg: #212b38;
    --writer-panel-bg: #1c2430;
    --writer-text: #a3b8cc;
    --writer-text-secondary: #7a93ab;
    --writer-text-muted: #526a82;
    --writer-border: #2d3b4e;
    --writer-hover: #2d3b4e;
    --writer-active: #3b82f6;
    --writer-active-bg: rgba(59, 130, 246, 0.15);
    --writer-input-bg: rgba(0, 0, 0, 0.25);
}

/* 统一定义选中文本的高亮颜色 */
.writer-editor-content ::selection { background: var(--writer-active-bg); color: var(--writer-active); }

/* ============ 作品列表 ============ */
.writer-list-wrap { padding: 24px 32px 60px; max-width: 1400px; margin: 0 auto; }
.writer-list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.writer-list-title { font-size: 18px; font-weight: 600; color: #e4e4e7; }
.writer-list-actions { display: flex; align-items: center; gap: 8px; }
.writer-search-box { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; background: #161616; border: 1px solid #232329; border-radius: 8px; min-width: 220px; }
.writer-search-box i { color: #71717a; font-size: 12px; }
.writer-search-box input { flex: 1; background: transparent; border: none; outline: none; color: #e4e4e7; font-size: 12.5px; font-family: inherit; }
.writer-btn-primary { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; background: linear-gradient(135deg, #6366f1, #4f46e5); border: none; border-radius: 8px; color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.writer-btn-primary:hover { filter: brightness(1.1); }
.writer-books-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; align-content: flex-start; min-height: 200px; }
.writer-book-card { position: relative; display: flex; flex-direction: column; background: #161616; border: 1px solid #232329; border-radius: 12px; overflow: hidden; cursor: pointer; transition: all 0.2s; padding: 16px; min-height: 160px; }
.writer-book-card:hover { border-color: #3a3a44; transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.writer-book-title { font-size: 15px; font-weight: 600; color: #e4e4e7; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.writer-book-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11.5px; color: #71717a; margin-top: auto; }
.writer-book-meta span { display: inline-flex; align-items: center; gap: 4px; }
.writer-book-desc { font-size: 12px; color: #a1a1aa; line-height: 1.5; display: -webkit-box;  -webkit-box-orient: vertical; margin-bottom: 8px; overflow: hidden; }
.writer-book-actions { position: absolute; top: 8px; right: 8px; display: none; gap: 4px; }
.writer-book-card:hover .writer-book-actions { display: flex; }
.writer-book-action-btn { width: 26px; height: 26px; border: none; border-radius: 6px; background: rgba(0,0,0,0.5); color: #a1a1aa; cursor: pointer; font-size: 12px; display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
.writer-book-action-btn:hover { background: #6366f1; color: #fff; }
.writer-book-action-btn.danger:hover { background: #ef4444; }
.writer-empty { grid-column: 1 / -1; text-align: center; padding: 80px 20px; color: #52525b; font-size: 13px; }
.writer-empty i { font-size: 40px; display: block; margin-bottom: 14px; opacity: 0.4; }

/* ============ 写作台覆盖层 ============ */
.writer-workbench { position: fixed; inset: 0; z-index: 500000; background: var(--writer-bg); display: none; flex-direction: column; color: var(--writer-text); transition: background 0.3s, color 0.3s; }
.writer-workbench.show { display: flex; }
.writer-wb-header { height: 48px; padding: 0 16px; display: flex; align-items: center; gap: 12px; background: var(--writer-panel-bg); border-bottom: 1px solid var(--writer-border); flex-shrink: 0; transition: background 0.3s, border-color 0.3s; }
.writer-wb-header .header-left, .writer-wb-header .header-right { display: flex; align-items: center; gap: 8px; }
.writer-wb-back { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; background: transparent; border: 1px solid var(--writer-border); border-radius: 6px; color: var(--writer-text-secondary); font-size: 12.5px; cursor: pointer; transition: all 0.15s; font-family: inherit; }
.writer-wb-back:hover { background: var(--writer-hover); color: var(--writer-text); }
.writer-icon-btn { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; background: transparent; border: none; border-radius: 6px; color: var(--writer-text-secondary); cursor: pointer; transition: all 0.15s; }
.writer-icon-btn:hover { background: var(--writer-hover); color: var(--writer-text); }
.writer-icon-btn.active { background: var(--writer-active-bg); color: var(--writer-active); }
.writer-wb-breadcrumb { flex: 1; text-align: center; font-size: 13px; color: var(--writer-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.writer-wb-breadcrumb strong { color: var(--writer-text); font-weight: 500; }
.writer-wb-save-status { font-size: 12px; color: var(--writer-text-muted); display: inline-flex; align-items: center; gap: 4px; }
.writer-wb-save-status.saved { color: #10b981; }

/* 主题选择菜单 */
.writer-theme-menu {
    position: absolute;
    top: calc(100% + 6px); /* 紧贴在按钮下方 */
    right: 0;              /* 右对齐，不会漂移 */
    min-width: 160px;      /* 保证有足够的宽度 */
    background: var(--writer-panel-bg);
    border: 1px solid var(--writer-border);
    border-radius: 8px;
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 1000;
    white-space: nowrap;   /* ★ 核心修复：强制文字水平排列，禁止换行 */
}
.writer-theme-menu.show { display: flex; }

.writer-theme-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--writer-text);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.writer-theme-item:hover { background: var(--writer-hover); }
.writer-theme-item.active { background: var(--writer-active-bg); color: var(--writer-active); font-weight: 600; }
.writer-theme-item .color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(128, 128, 128, 0.3);
    flex-shrink: 0;
}

/* ============ 主体三栏 ============ */
.writer-wb-body { flex: 1; display: flex; min-height: 0; overflow: hidden; }
.writer-wb-tree { width: 260px; flex-shrink: 0; background: var(--writer-panel-bg); border-right: 1px solid var(--writer-border); display: flex; flex-direction: column; overflow: hidden; transition: width 0.25s ease, opacity 0.25s, background 0.3s, border-color 0.3s; }
.writer-wb-tree.collapsed { width: 0; opacity: 0; border-right: none; }
.writer-wb-tree-head { height: 40px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--writer-border); font-size: 12.5px; color: var(--writer-text-secondary); flex-shrink: 0; }
.writer-tree-add-btn { width: 24px; height: 24px; border: none; background: transparent; color: var(--writer-text-muted); border-radius: 5px; cursor: pointer; transition: all 0.15s; }
.writer-tree-add-btn:hover { background: var(--writer-hover); color: var(--writer-text); }
.writer-tree-progress { padding: 8px 12px; border-bottom: 1px solid var(--writer-border); font-size: 11.5px; color: var(--writer-text-muted); flex-shrink: 0; display: flex; justify-content: space-between; }
.writer-tree-progress strong { color: var(--writer-active); font-weight: 600; }
.writer-tree-list { flex: 1; overflow-y: auto; padding: 8px 6px; }
.writer-tree-list::-webkit-scrollbar { width: 6px; }
.writer-tree-list::-webkit-scrollbar-thumb { background: var(--writer-border); border-radius: 3px; }

.writer-volume-item { display: flex; align-items: center; height: 30px; padding: 0 8px; border-radius: 6px; color: var(--writer-text-secondary); font-size: 12.5px; font-weight: 500; cursor: pointer; transition: background 0.1s; position: relative; }
.writer-volume-item:hover { background: var(--writer-hover); }
.writer-volume-arrow { width: 16px; font-size: 9px; color: var(--writer-text-muted); transition: transform 0.15s; }
.writer-volume-item.expanded .writer-volume-arrow { transform: rotate(90deg); }
.writer-volume-name { flex: 1; margin-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.writer-volume-count { font-size: 10px; color: var(--writer-text-muted); }
.writer-volume-actions { display: none; gap: 2px; margin-left: 4px; }
.writer-volume-item:hover .writer-volume-actions { display: flex; }
.writer-volume-actions button { width: 20px; height: 20px; border: none; background: transparent; color: var(--writer-text-muted); cursor: pointer; border-radius: 4px; font-size: 10px; }
.writer-volume-actions button:hover { background: rgba(128,128,128,0.2); color: var(--writer-text); }

.writer-chapter-item.drag-over { border-top: 2px solid var(--writer-active); margin-top: -2px; }
.writer-chapter-item { display: flex; align-items: center; height: 28px; padding: 0 8px 0 28px; border-radius: 6px; color: var(--writer-text-secondary); font-size: 12px; cursor: pointer; transition: background 0.1s; position: relative; }
.writer-chapter-item:hover { background: var(--writer-hover); color: var(--writer-text); }
.writer-chapter-item.active { background: var(--writer-active-bg); color: var(--writer-active); font-weight: 500; }
.writer-chapter-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.writer-chapter-status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--writer-text-muted); margin-right: 6px; flex-shrink: 0; }
.writer-chapter-status-dot.done { background: #10b981; }
.writer-chapter-status-dot.draft { background: #fbbf24; }
.writer-chapter-actions { display: none; gap: 2px; }
.writer-chapter-item:hover .writer-chapter-actions { display: flex; }
.writer-chapter-actions button { width: 18px; height: 18px; border: none; background: transparent; color: var(--writer-text-muted); cursor: pointer; border-radius: 3px; font-size: 9px; }
.writer-chapter-actions button:hover { background: rgba(128,128,128,0.2); color: var(--writer-text); }
.writer-tree-empty { text-align: center; padding: 24px 12px; color: var(--writer-text-muted); font-size: 11.5px; }

/* 中栏：正文 */
.writer-wb-editor { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--writer-bg); overflow: hidden; position: relative; transition: background 0.3s; }
.writer-wb-editor-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--writer-text-muted); font-size: 13px; gap: 12px; }
.writer-wb-editor-empty i { font-size: 44px; opacity: 0.4; }

/* 悬浮工具栏 */
.writer-float-toolbar { position: fixed; z-index: 1000; display: none; align-items: center; gap: 4px; background: var(--writer-panel-bg); border: 1px solid var(--writer-border); border-radius: 8px; padding: 4px 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.3); transform: translate(-50%, -100%); }
.writer-float-toolbar.show { display: flex; }
.writer-float-toolbar button { height: 28px; padding: 0 8px; border: none; background: transparent; color: var(--writer-text); border-radius: 4px; cursor: pointer; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; transition: all 0.15s; white-space: nowrap; }
.writer-float-toolbar button:hover { background: var(--writer-hover); }
.writer-float-toolbar .divider { width: 1px; height: 16px; background: var(--writer-border); margin: 0 4px; }

.writer-chapter-title-input { height: 64px; padding: 0 40px; border: none; background: transparent; color: var(--writer-text); font-size: 22px; font-weight: 600; outline: none; font-family: inherit; flex-shrink: 0; width: 100%; box-sizing: border-box; }
.writer-chapter-title-input::placeholder { color: var(--writer-text-muted); }
.writer-editor-scroll { flex: 1; overflow-y: auto; padding: 10px 0 100px; }
.writer-editor-scroll::-webkit-scrollbar { width: 8px; }
.writer-editor-scroll::-webkit-scrollbar-thumb { background: var(--writer-border); border-radius: 4px; }
.writer-editor-content { max-width: 820px; margin: 0 auto; padding: 0 40px; font-size: 16px; line-height: 1.9; color: var(--writer-text); outline: none; min-height: 400px; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; transition: color 0.3s; }
.writer-editor-content:empty::before { content: attr(data-placeholder); color: var(--writer-text-muted); pointer-events: none; }
.writer-editor-content p { margin: 0 0 1em 0; text-indent: 2em; }
.writer-editor-content h1, .writer-editor-content h2, .writer-editor-content h3 { text-indent: 0; color: var(--writer-text); margin: 1.5em 0 0.8em; }
.writer-editor-content blockquote { text-indent: 0; border-left: 3px solid var(--writer-active); padding-left: 12px; color: var(--writer-text-secondary); margin: 1em 0; font-style: italic; }

.writer-wb-editor-bottom { height: 44px; padding: 0 20px; display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--writer-border); background: var(--writer-panel-bg); flex-shrink: 0; transition: background 0.3s, border-color 0.3s; }
.writer-chapter-nav-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; background: transparent; border: 1px solid var(--writer-border); border-radius: 6px; color: var(--writer-text-secondary); font-size: 12px; cursor: pointer; transition: all 0.15s; font-family: inherit; }
.writer-chapter-nav-btn:hover:not(:disabled) { background: var(--writer-hover); color: var(--writer-text); }
.writer-chapter-nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.writer-wb-editor-bottom .spacer { flex: 1; }
.writer-wb-word-count { font-size: 12px; color: var(--writer-text-muted); font-family: 'SF Mono', Monaco, monospace; }

/* 右栏：细纲 */
.writer-wb-outline { width: 300px; flex-shrink: 0; background: var(--writer-panel-bg); border-left: 1px solid var(--writer-border); display: flex; flex-direction: column; overflow: hidden; transition: width 0.25s ease, opacity 0.25s, background 0.3s, border-color 0.3s; }
.writer-wb-outline.collapsed { width: 0; opacity: 0; border-left: none; }
.writer-wb-outline-head { height: 40px; padding: 0 12px; display: flex; align-items: center; border-bottom: 1px solid var(--writer-border); font-size: 12.5px; color: var(--writer-text-secondary); font-weight: 500; flex-shrink: 0; }
.writer-outline-scroll { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }
.writer-outline-scroll::-webkit-scrollbar { width: 6px; }
.writer-outline-scroll::-webkit-scrollbar-thumb { background: var(--writer-border); border-radius: 3px; }
.writer-outline-section-label { font-size: 11.5px; color: var(--writer-text-muted); font-weight: 500; margin-bottom: 6px; display: flex; justify-content: space-between; }
.writer-outline-textarea { width: 100%; min-height: 120px; background: var(--writer-input-bg); border: 1px solid var(--writer-border); border-radius: 6px; padding: 10px 12px; color: var(--writer-text); font-size: 12.5px; line-height: 1.7; outline: none; resize: vertical; font-family: inherit; box-sizing: border-box; transition: background 0.3s, border-color 0.3s; }
.writer-outline-textarea:focus { border-color: var(--writer-active); }
.writer-outline-preview { background: var(--writer-input-bg); border: 1px solid var(--writer-border); border-radius: 6px; padding: 10px 12px; color: var(--writer-text-muted); font-size: 12px; line-height: 1.7; max-height: 160px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; transition: background 0.3s, border-color 0.3s; }
.writer-outline-preview.empty { font-style: italic; }

/* 专注模式 */
body.writer-focus-mode .writer-wb-tree,
body.writer-focus-mode .writer-wb-outline { display: none !important; }
body.writer-focus-mode .writer-wb-editor { max-width: 900px; margin: 0 auto; border-left: 1px solid var(--writer-border); border-right: 1px solid var(--writer-border); }

/* AI 打字机效果闪烁光标 */
@keyframes writer-cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.writer-ai-cursor { display: inline-block; width: 2px; height: 18px; background: var(--writer-active); vertical-align: middle; animation: writer-cursor-blink 1s step-end infinite; margin-left: 2px; }


/* ================= 左侧 Tab 切换 ================= */
.writer-tree-tabs {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    width: 100%;
    border-bottom: 1px solid var(--writer-border);
    background: var(--writer-panel-bg);
    flex-shrink: 0;
}

.w-tab {
    flex: 1;
    text-align: center;
    padding: 10px 0;
    font-size: 12.5px;
    color: var(--writer-text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    user-select: none;
}

.w-tab:hover {
    color: var(--writer-text);
}

.w-tab.active {
    color: var(--writer-active);
    font-weight: 600;
    border-bottom-color: var(--writer-active);
}


/* ================= 统一写作台滚动条样式 ================= */
/* 覆盖所有滚动区域：正文、左侧树、右侧细纲/预览 */
.writer-workbench ::-webkit-scrollbar {
    width: 6px !important;
    height: 6px !important;
}

.writer-workbench ::-webkit-scrollbar-track {
    background: transparent !important;
}

.writer-workbench ::-webkit-scrollbar-thumb {
    /* 使用半透明灰色，在深色/浅色主题下都自然 */
    background: rgba(128, 128, 128, 0.3) !important;
    border-radius: 3px !important;
    transition: background 0.2s !important;
}

.writer-workbench ::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.6) !important;
}


/* ================= 强制允许写作台内文字选中复制 ================= */

/* 覆盖原稿预览区、正文编辑区、细纲预览区的选择限制 */
.writer-workbench .writer-preview-text,
.writer-workbench .writer-outline-preview,
.writer-workbench .writer-editor-content,
.writer-workbench #canvasPreviewContent {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    cursor: text;
}

/* 允许选中的文字显示系统高亮色 */
.writer-workbench ::selection {
    background: var(--writer-active-bg) !important;
    color: var(--writer-active) !important;
}


/* ================= 自动续写弹窗 ================= */
.writer-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    z-index: 10000; display: none; align-items: center; justify-content: center;
}
.writer-modal-overlay.show { display: flex; }
.writer-modal-dialog {
    background: var(--writer-panel-bg); border: 1px solid var(--writer-border);
    border-radius: 12px; width: 700px; max-width: 90vw; height: 80vh; max-height: 800px;
    display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    color: var(--writer-text); animation: wModalFadeIn 0.2s ease;
}
@keyframes wModalFadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.writer-modal-header {
    padding: 16px 20px; border-bottom: 1px solid var(--writer-border);
    display: flex; justify-content: space-between; align-items: center; font-size: 15px; font-weight: 600;
}
.writer-modal-body {
    flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 12px; overflow: hidden;
}
.writer-modal-body label { font-size: 13px; font-weight: 500; color: var(--writer-text-secondary); flex-shrink: 0; }
.writer-modal-body textarea {
    flex: 1; min-height: 80px; background: var(--writer-input-bg); border: 1px solid var(--writer-border);
    border-radius: 6px; padding: 12px; color: var(--writer-text); font-family: inherit;
    font-size: 13px; line-height: 1.6; outline: none; resize: none;
}
.writer-modal-body textarea:focus { border-color: var(--writer-active); }
.writer-modal-footer {
    padding: 16px 20px; border-top: 1px solid var(--writer-border);
    display: flex; justify-content: flex-end; gap: 12px;
}
.writer-modal-btn {
    height: 34px; padding: 0 18px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: none;
}
.writer-modal-btn.cancel { background: var(--writer-border); color: var(--writer-text); }
.writer-modal-btn.primary { background: var(--writer-active); color: #fff; }