:root {
    --bg: #0f1420;
    --bg-soft: #151c2c;
    --panel: #1a2234;
    --panel-soft: #202a40;
    --line: #2b3650;
    --text: #e8edf7;
    --text-dim: #9aa7c0;
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.16);
    --danger: #ff6b6b;
    --ok: #4cd4a2;
    --radius: 10px;
    font-size: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 1.05rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
h4 { font-size: 0.92rem; }
p { margin: 0; }

.app-shell {
    display: grid;
    grid-template-columns: 250px 1fr;
    height: 100vh;
}

/* ---------------- 侧栏 ---------------- */

.sidebar {
    background: var(--bg-soft);
    border-right: 1px solid var(--line);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

.brand { display: flex; gap: 10px; align-items: center; }
.brand-mark {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #5b8cff, #9b6bff);
    border-radius: 10px;
    font-weight: 700;
    font-size: 1.1rem;
}
.brand p { color: var(--text-dim); font-size: 0.78rem; }

.sidebar-foot { margin-top: auto; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}
.section-head span { color: var(--text-dim); font-size: 0.78rem; }
.section-head .actions { display: flex; gap: 6px; align-items: center; margin-bottom: 0; }

.nav-list { display: flex; flex-direction: column; gap: 6px; }

.nav-item {
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.88rem;
    line-height: 1.45;
}
.nav-item span { color: var(--text-dim); font-size: 0.76rem; }
.nav-item:hover { background: var(--panel-soft); }
.nav-item.active { background: var(--accent-soft); border-color: var(--accent); }

/* ---------------- 主区 ---------------- */

.workspace { overflow: hidden; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 16px 18px; gap: 14px; }

.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.eyebrow {
    color: var(--accent);
    font-size: 0.74rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 2px;
}
.meta-line { color: var(--text-dim); font-size: 0.8rem; margin-top: 4px; }

.tab-switch { display: flex; gap: 6px; }
.tab-button {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text-dim);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.88rem;
}
.tab-button:hover { color: var(--text); }
.tab-button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

.tab-page { flex: 1; overflow: hidden; }

.content-grid {
    display: grid;
    grid-template-columns: 240px 1fr 330px;
    gap: 14px;
    min-height: 0;
}

.brainstorm-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 300px 1fr 420px;
    gap: 14px;
    min-height: 0;
}

.chat-layout { display: flex; min-height: 0; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.panel.scroll { overflow-y: auto; }
.fill-column { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.editor-panel { min-width: 0; }
.editor-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; min-height: 0; }
.editor-columns.fill { flex: 1; }
.editor-columns.single { grid-template-columns: 1fr; }
.editor-columns.single .preview { display: none; }
.preview.chapter-preview { min-height: 260px; max-height: 480px; }

.empty-state {
    flex: 1;
    display: grid;
    place-items: center;
    color: var(--text-dim);
    text-align: center;
    line-height: 1.8;
}
.empty-state.hero h2 { font-size: 1.5rem; margin-bottom: 10px; color: var(--text); }
.empty-state.small { font-size: 0.86rem; padding: 20px; }

/* ---------------- 表单与按钮 ---------------- */

.form-stack { display: flex; flex-direction: column; gap: 10px; }
.form-stack.tight { gap: 6px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { color: var(--text-dim); font-size: 0.78rem; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field.grow { flex: 2; }

input, select, textarea {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 0.88rem;
    font-family: inherit;
    width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

textarea { resize: vertical; line-height: 1.7; }
.editor-textarea { min-height: 200px; }
.editor-textarea.short { min-height: 76px; }
.editor-textarea.tall { min-height: 260px; }
.editor-textarea.fill { flex: 1; min-height: 0; }

.button {
    background: var(--panel-soft);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 0.88rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}
.button:hover { border-color: var(--accent); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { filter: brightness(1.1); }
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); }
.button.danger:hover { border-color: var(--danger); }
.button.mini { padding: 4px 10px; font-size: 0.78rem; }
.button.small { padding: 6px 12px; font-size: 0.82rem; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.stack { flex-direction: column; align-items: stretch; }

.status-text { color: var(--text-dim); font-size: 0.8rem; min-height: 1.2em; margin-top: 6px; }
.status-text.error { color: var(--danger); }
.status-text.ok { color: var(--ok); }
.hint { color: var(--text-dim); font-size: 0.8rem; line-height: 1.6; margin-bottom: 10px; }

/* ---------------- Markdown 预览 ---------------- */

.preview {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-y: auto;
    font-size: 0.88rem;
    line-height: 1.8;
    min-height: 0;
}
.preview h1, .preview h2, .preview h3, .preview h4 { margin: 0.8em 0 0.4em; }
.preview p, .preview ul, .preview ol { margin: 0.5em 0; }
.preview table { border-collapse: collapse; width: 100%; margin: 0.6em 0; }
.preview th, .preview td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.preview code { background: var(--panel-soft); padding: 1px 5px; border-radius: 4px; }

.stream-box {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    margin-top: 10px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-dim);
    max-height: 240px;
    overflow-y: auto;
}
.stream-box.tall { max-height: 320px; }

/* ---------------- 头脑风暴 ---------------- */

.idea-grid { display: flex; flex-direction: column; gap: 10px; }

.idea-card {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    line-height: 1.6;
    width: 100%;
}
.idea-card:hover { border-color: var(--accent); }
.idea-card.active { background: var(--accent-soft); border-color: var(--accent); }
.idea-card h4 { margin-bottom: 4px; }
.idea-card .logline { color: var(--text-dim); font-size: 0.84rem; }
.idea-card .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.idea-card .tag, .idea-fields .tag {
    background: var(--panel-soft);
    border-radius: 20px;
    padding: 2px 9px;
    font-size: 0.74rem;
    color: var(--text-dim);
}
.idea-card .materialized-badge { color: var(--ok); font-size: 0.76rem; }

.idea-fields { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.idea-field { background: var(--bg-soft); border-radius: 8px; padding: 8px 10px; font-size: 0.85rem; line-height: 1.65; }
.idea-field b { color: var(--accent); font-weight: 600; margin-right: 6px; }

.chat-head { margin-top: 6px; }

/* ---------------- 对话 ---------------- */

.chat-log {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding: 4px 2px;
    min-height: 120px;
    max-height: 340px;
}
.chat-log.fill { flex: 1; max-height: none; }

.chat-message { display: flex; flex-direction: column; gap: 3px; max-width: 92%; }
.chat-message .bubble {
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.87rem;
    line-height: 1.75;
    word-break: break-word;
}
.chat-message.user { align-self: flex-end; align-items: flex-end; }
.chat-message.user .bubble { background: var(--accent); color: #fff; white-space: pre-wrap; }
.chat-message.assistant .bubble { background: var(--bg-soft); border: 1px solid var(--line); }
.chat-message .who { color: var(--text-dim); font-size: 0.72rem; }
.chat-message .bubble p { margin: 0.35em 0; }
.chat-message .bubble ul, .chat-message .bubble ol { margin: 0.35em 0; padding-left: 1.4em; }
.chat-message .bubble table { border-collapse: collapse; }
.chat-message .bubble th, .chat-message .bubble td { border: 1px solid var(--line); padding: 3px 7px; }

.chat-input-row { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.chat-input-row textarea { flex: 1; min-height: 60px; max-height: 160px; }

.model-select.inline { width: auto; padding: 4px 8px; font-size: 0.78rem; }

/* ---------------- 章节 ---------------- */

.chapter-groups { display: flex; flex-direction: column; gap: 4px; }
.chapter-groups .group-title { color: var(--text-dim); font-size: 0.8rem; margin: 8px 0 4px; }

.chapter-item {
    width: 100%;
    text-align: left;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1.5;
    margin-bottom: 6px;
}
.chapter-item span { color: var(--text-dim); font-size: 0.74rem; }
.chapter-item:hover { border-color: var(--accent); }
.chapter-item.active { background: var(--accent-soft); border-color: var(--accent); }

.draft-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.draft-card {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
}
.draft-card .draft-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.draft-card .draft-meta { color: var(--text-dim); font-size: 0.76rem; margin-top: 2px; }
.draft-card .snippet { color: var(--text-dim); font-size: 0.8rem; margin-top: 6px; line-height: 1.6; max-height: 3.2em; overflow: hidden; }
.draft-card .draft-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.compare-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare-slot { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-width: 0; }
.compare-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.compare-body {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 0.84rem;
    line-height: 1.75;
    max-height: 420px;
    overflow-y: auto;
}

/* ---------------- 弹窗 ---------------- */

.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 15, 0.72);
    display: grid;
    place-items: center;
    z-index: 50;
    padding: 24px;
}
.modal {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 18px;
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.materialize-list { display: flex; flex-direction: column; gap: 6px; }
.materialize-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-soft);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 0.85rem;
}
.materialize-item input[type='checkbox'] { width: auto; }
.materialize-item .doc-status { margin-left: auto; font-size: 0.76rem; color: var(--text-dim); }
.materialize-item .doc-status.working { color: var(--accent); }
.materialize-item .doc-status.done { color: var(--ok); }
.materialize-item .doc-status.error { color: var(--danger); }

.hidden { display: none !important; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1280px) {
    .content-grid { grid-template-columns: 220px 1fr 300px; }
    .brainstorm-grid { grid-template-columns: 260px 1fr 360px; }
}

@media (max-width: 1024px) {
    .app-shell { grid-template-columns: 210px 1fr; }
    .content-grid, .brainstorm-grid { grid-template-columns: 1fr; overflow-y: auto; }
    .panel { min-height: 220px; }
    .view { overflow-y: auto; }
    .tab-page { overflow: visible; }
}
