/* ========== 全局基础 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    font-size: 14px;
    line-height: 1.6;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
}
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-ghost {
    background: transparent;
    color: #555;
}
.btn-ghost:hover { background: rgba(0,0,0,0.05); color: #333; }
.btn-block { width: 100%; margin-top: 8px; padding: 11px; }

/* ========== 顶部栏 ========== */
.top-bar {
    height: 56px;
    background: #fff;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.logo {
    font-size: 17px;
    font-weight: 600;
    color: #1a1a2e;
}
.top-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.top-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.book-title {
    font-size: 16px;
    font-weight: 600;
}
.book-genre-tag {
    font-size: 12px;
    background: #f0f2ff;
    color: #667eea;
    padding: 2px 10px;
    border-radius: 12px;
}

/* ========== 页面容器 ========== */
.page-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

/* ========== 统计栏 ========== */
.stats-bar {
    display: flex;
    gap: 32px;
    background: #fff;
    padding: 20px 28px;
    border-radius: 12px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.stat-item {
    display: flex;
    flex-direction: column;
}
.stat-num {
    font-size: 28px;
    font-weight: 700;
    color: #667eea;
}
.stat-label {
    font-size: 13px;
    color: #999;
    margin-top: 2px;
}

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: #999;
}
.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}
.empty-title {
    font-size: 20px;
    font-weight: 600;
    color: #555;
    margin-bottom: 8px;
}
.empty-desc {
    font-size: 14px;
    color: #999;
}
.chapter-empty {
    text-align: center;
    padding: 20px 10px;
    color: #bbb;
    font-size: 13px;
}

/* ========== 书卡网格 ========== */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}
.book-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #eee;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    flex-direction: column;
    position: relative;
}
.book-card:hover {
    border-color: #c7d0f0;
    box-shadow: 0 10px 30px rgba(102,126,234,0.12);
    transform: translateY(-3px);
}

/* 删除按钮 */
.book-delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(0,0,0,0.4);
    color: #fff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
    z-index: 10;
    border: none;
    line-height: 1;
}
.book-card:hover .book-delete-btn {
    opacity: 1;
}
.book-delete-btn:hover {
    background: #f5222d;
    transform: scale(1.15);
}

/* 封面 */
.book-cover {
    width: 100%;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 700;
    color: #fff;
}
.cover-blue   { background: linear-gradient(135deg, #667eea, #764ba2); }
.cover-green  { background: linear-gradient(135deg, #43e97b, #38f9d7); }
.cover-purple { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }
.cover-amber  { background: linear-gradient(135deg, #f6d365, #fda085); }
.cover-rose   { background: linear-gradient(135deg, #fa709a, #fee140); }
.cover-teal   { background: linear-gradient(135deg, #30cfd0, #330867); }
.cover-empty  {
    background: #f5f5f5;
    color: #ccc;
    font-size: 48px;
    font-weight: 300;
}

.book-info {
    padding: 14px 16px;
}
.book-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.book-desc {
    font-size: 12px;
    color: #999;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.5;
    min-height: 36px;
}
.book-meta {
    display: flex;
    gap: 8px;
    font-size: 11px;
    color: #888;
    flex-wrap: wrap;
}
.book-genre, .book-chapters, .book-words {
    background: #f5f6fa;
    padding: 2px 8px;
    border-radius: 4px;
}

/* 创建新书卡 */
.create-card {
    border: 2px dashed #ddd;
    background: transparent;
    justify-content: center;
    align-items: center;
    min-height: 240px;
}
.create-card:hover {
    border-color: #667eea;
    border-style: solid;
    background: #fafbff;
}

/* ========== 弹窗 ========== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}
.modal-box {
    background: #fff;
    border-radius: 14px;
    width: 440px;
    max-width: 90vw;
    max-height: 85vh;
    overflow: hidden;
    animation: modalIn 0.2s ease;
}
.modal-lg {
    width: 700px;
}
@keyframes modalIn {
    from { transform: translateY(20px) scale(0.97); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid #f0f0f0;
}
.modal-header h3 {
    font-size: 17px;
    font-weight: 600;
}
.modal-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    font-size: 20px;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.modal-close:hover {
    background: #f5f5f5;
    color: #333;
}
.modal-body {
    padding: 22px;
    max-height: 70vh;
    overflow-y: auto;
}

/* ========== 表单 ========== */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 13px;
    color: #555;
    margin-bottom: 6px;
    font-weight: 500;
}
.form-group input, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e8e8e8;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
    resize: vertical;
}
.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

/* 创建Tab */
.create-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: #f5f6fa;
    border-radius: 8px;
    padding: 3px;
}
.tab-btn {
    flex: 1;
    padding: 9px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}
.tab-btn.active {
    background: #fff;
    color: #667eea;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* ========== 方案选择卡片 ========== */
.plans-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}
.plan-card {
    border: 2px solid #eee;
    border-radius: 12px;
    padding: 18px;
    cursor: pointer;
    transition: all 0.2s;
}
.plan-card:hover {
    border-color: #667eea;
    box-shadow: 0 6px 20px rgba(102,126,234,0.1);
    transform: translateY(-2px);
}
.plan-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.plan-badge {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 10px;
    font-weight: 600;
}
.plan-style {
    font-size: 12px;
    color: #999;
}
.plan-title {
    font-size: 18px;
    margin-bottom: 8px;
}
.plan-desc {
    font-size: 13px;
    color: #666;
    margin-bottom: 12px;
    line-height: 1.6;
}
.plan-detail {
    font-size: 13px;
    color: #555;
    margin-bottom: 12px;
}
.detail-item {
    margin-bottom: 4px;
}
.plan-volumes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.vol-tag {
    font-size: 11px;
    background: #f0f2ff;
    color: #667eea;
    padding: 3px 10px;
    border-radius: 10px;
}

/* ========== 工作台布局 ========== */
.workspace-layout {
    display: flex;
    height: calc(100vh - 56px);
}
.sidebar {
    width: 240px;
    background: #fff;
    border-right: 1px solid #e8e8e8;
    overflow-y: auto;
    flex-shrink: 0;
}
.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid #f0f0f0;
}
.sidebar-title {
    font-size: 12px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    font-weight: 600;
}
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f7f8fc;
}

/* 章节目录 */
.chapter-list {
    max-height: 400px;
    overflow-y: auto;
}
.chapter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}
.chapter-item:hover {
    background: #f5f6fa;
}
.chapter-item.current {
    background: #eef0ff;
    color: #667eea;
    font-weight: 600;
}
.chapter-no {
    font-size: 11px;
    color: #999;
    width: 24px;
    flex-shrink: 0;
    text-align: center;
}
.chapter-item.current .chapter-no {
    color: #667eea;
}
.chapter-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chapter-status {
    font-size: 10px;
    color: #667eea;
}
.chapter-status.done {
    color: #52c41a;
}

/* 文档列表 */
.doc-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.doc-item {
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #555;
    transition: background 0.15s;
}
.doc-item:hover {
    background: #f5f6fa;
    color: #667eea;
}

/* ========== 对话流 ========== */
.chat-stream {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 欢迎卡片 */
.welcome-card {
    text-align: center;
    padding: 40px 20px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}
.welcome-icon {
    font-size: 48px;
    margin-bottom: 12px;
}
.welcome-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}
.welcome-desc {
    color: #888;
    font-size: 14px;
    margin-bottom: 20px;
}
.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}
.suggestion {
    background: #f0f2ff;
    color: #667eea;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.suggestion:hover {
    background: #667eea;
    color: #fff;
    transform: translateY(-1px);
}

/* 消息气泡 */
.stream-msg {
    display: flex;
    gap: 10px;
    max-width: 100%;
}
.stream-msg.user {
    flex-direction: row-reverse;
}
.stream-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}
.stream-msg.user .stream-avatar {
    background: linear-gradient(135deg, #43e97b, #38f9d7);
}
.stream-bubble {
    background: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.7;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    word-wrap: break-word;
}
.user-bubble {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}
.error-bubble {
    background: #fff2f0;
    color: #f5222d;
    border: 1px solid #ffccc7;
}

/* 思考指示器 */
.thinking {
    display: flex;
    align-items: center;
    color: #999;
    font-size: 13px;
    padding: 12px 16px;
}
.dots span {
    display: inline-block;
    animation: dotPulse 1.4s infinite;
    font-size: 18px;
    line-height: 1;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* ========== 章节预览区 ========== */
.chapter-preview-area {
    background: #fff;
    border-top: 2px solid #e8e8e8;
    max-height: 45vh;
    display: flex;
    flex-direction: column;
}
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #f0f0f0;
    background: #fafbff;
    font-weight: 600;
    font-size: 14px;
}
.preview-actions {
    display: flex;
    gap: 8px;
}
.preview-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 28px;
    line-height: 1.9;
    font-size: 15px;
}
.preview-content h3 {
    font-size: 20px;
    margin: 20px 0 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #667eea;
    color: #1a1a2e;
}
.preview-content h3:first-child {
    margin-top: 0;
}
.preview-content h4 {
    font-size: 16px;
    margin: 16px 0 10px;
    color: #333;
}
.preview-content p {
    margin-bottom: 14px;
    text-indent: 2em;
}
.preview-content strong {
    color: #667eea;
}

/* ========== 输入区 ========== */
.input-area {
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    background: #fff;
    border-top: 1px solid #e8e8e8;
    align-items: flex-end;
}
.input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid #e8e8e8;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    line-height: 1.6;
    max-height: 150px;
    min-height: 42px;
    transition: border-color 0.2s;
}
.input-area textarea:focus {
    outline: none;
    border-color: #667eea;
}
.btn-send {
    padding: 10px 24px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    height: 42px;
}
.btn-send:hover { opacity: 0.9; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== 文件查看 ========== */
.file-content {
    background: #f8f9fb;
    padding: 16px;
    border-radius: 8px;
    font-family: "SF Mono", "Consolas", "Microsoft YaHei", monospace;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 60vh;
    overflow-y: auto;
    color: #333;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .sidebar { width: 180px; }
    .book-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .stats-bar { gap: 16px; padding: 14px 18px; }
    .stat-num { font-size: 22px; }
}
