/* 基础变量与重置 */
:root {
    --bg-darker: #09090b;
    --bg-dark: #18181b;
    --bg-card: #27272a;
    --bg-card-hover: #3f3f46;
    
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --success: #10b981;
    --danger: #ef4444;
    
    --border: #3f3f46;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: 'Inter', 'Noto Sans SC', sans-serif;
    background-color: var(--bg-darker);
    color: var(--text-main);
    line-height: 1.6;
    overflow: hidden; /* 防止全局滚动，改为局部滚动 */
}

/* 布局结构 */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ========== 左侧边栏 ========== */
.sidebar {
    width: 260px;
    background-color: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    flex-shrink: 0;
}

.brand {
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
}
.brand h2 { font-size: 1.2rem; font-weight: 600; letter-spacing: 0.5px; }
.brand .logo-icon { color: var(--primary); font-size: 1.3rem; }
.brand .version { font-size: 0.7rem; background: var(--border); padding: 2px 6px; border-radius: 4px; color: var(--text-muted); }

.nav-section-title {
    padding: 0 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
    letter-spacing: 1px;
}

.steps-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.step-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.8rem 1.5rem;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.95rem;
}

.step-btn:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.step-btn.active {
    background-color: rgba(139, 92, 246, 0.15); /* primary 带透明度 */
    color: var(--primary);
    border-right: 3px solid var(--primary);
}

.step-num { font-size: 0.8rem; opacity: 0.7; font-family: monospace; }
.step-text { flex: 1; }
.status-icon { font-size: 0.9rem; }
.status-icon.pending { color: var(--border); }
.status-icon.locked { color: var(--bg-card-hover); }

.step-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
}

/* ========== 中间主工作区 ========== */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background-color: var(--bg-darker);
}

/* 顶部栏 */
.topbar {
    padding: 2rem 3rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.topbar h1 { font-size: 1.8rem; font-weight: 600; margin-bottom: 0.5rem; }
.topbar p { color: var(--text-muted); font-size: 0.95rem; }

/* 工作区域内视图切换 */
.workspace {
    padding: 2rem 3rem;
    flex: 1;
}

.step-view {
    display: none;
    gap: 2rem;
    animation: fadeIn 0.3s ease-out;
}
.step-view.active {
    display: flex; /* 对于步骤1默认用flex并排表单和结果 */
    flex-wrap: wrap;
    align-items: flex-start;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 面板卡片 */
.form-card, .result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    flex: 1;
    min-width: 300px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.full-width {
    flex: 100% !important;
}

.form-card h3, .result-card h3 {
    font-size: 1.1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.icon-btn-highlight {
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.3);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.icon-btn-highlight:hover {
    background: var(--primary);
    color: white;
}

.text-primary { color: var(--primary); }
.text-success { color: var(--success); }

/* 表单输入 */
.input-group { margin-bottom: 1.2rem; }
.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.input-group input, .input-group textarea, .main-editor {
    width: 100%;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}
.input-group input:focus, .input-group textarea:focus, .main-editor:focus {
    outline: none;
    border-color: var(--primary);
}
.input-group textarea { resize: vertical; min-height: 80px; }

/* 按钮 */
.generate-btn {
    width: 100%;
    padding: 0.9rem;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}
.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(139, 92, 246, 0.4);
}

.action-btn.outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}
.action-btn.outline:hover {
    background: var(--bg-card);
    border-color: var(--text-muted);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.icon-btn:hover { color: var(--text-main); }

/* 结果区展示 */
.result-content {
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    min-height: 200px;
    font-size: 0.95rem;
    line-height: 1.8;
}
.placeholder-text {
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.6;
}

.hidden-editor { display: none; } /* 暂且隐藏，复杂交互后续实现 */
.main-editor { min-height: 300px; }

.result-actions {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
}
.nav-next-btn {
    background: var(--success);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    transition: opacity 0.2s;
    display: none; /* 默认隐藏，有结果后显示 */
}
.nav-next-btn:hover { opacity: 0.9; }

/* 提示栏 */
.info-banner {
    width: 100%;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-size: 0.9rem;
}

/* Modal 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal.active { display: flex; }

.modal-content {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.modal-header {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { font-size: 1.1rem; }
.close-btn { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; }
.close-btn:hover { color: var(--danger); }
.modal-body { padding: 1.5rem; }
.modal-footer {
    padding: 1.2rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}
/* 人物卡网格布局 */
.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    width: 100%;
    margin-top: 1.5rem;
}

.char-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border-top: 4px solid var(--primary);
}

.char-card h4 { font-size: 1.2rem; margin-bottom: 0.5rem; color: var(--primary); }
.char-info { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.8rem; }
.char-detail { font-size: 0.85rem; background: var(--bg-darker); padding: 0.8rem; border-radius: 6px; margin-bottom: 0.5rem; }
.char-detail b { color: var(--text-main); display: block; margin-bottom: 2px; }

/* 微观写作台布局 */
.writing-desk-container {
    display: flex;
    height: calc(100vh - 120px);
    gap: 1.5rem;
    width: 100%;
}
/* 章节侧边栏 */
.chapter-sidebar {
    width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chapter-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    font-weight: 500;
}
.chapter-header button {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
}
.chapter-header button:hover { color: var(--primary); }
.chapter-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}
.chapter-item {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: background 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chapter-item:hover { background: var(--bg-hover); }
.chapter-item .delete-chapter {
    opacity: 0;
    transition: opacity 0.2s;
    color: var(--text-muted);
    padding: 4px;
}
.chapter-item:hover .delete-chapter {
    opacity: 1;
}
.chapter-item .delete-chapter:hover {
    color: var(--danger);
}
.chapter-item.active {
    background: rgba(168, 85, 247, 0.1);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

.writing-editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.writing-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-weight: 500;
    display: flex;
    justify-content: space-between;
}
.badge {
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
}
.writing-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 1.05rem;
    line-height: 1.8;
}
.writing-content p { margin-bottom: 1em; }
.ai-msg { color: var(--text-main); }
.user-msg { color: var(--primary); margin: 1em 0; padding-left: 10px; border-left: 3px solid var(--primary); }
.status-msg { color: var(--success); font-size: 0.9rem; margin: 1em 0; opacity: 0.8; font-style: italic;}

.writing-input-area {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 1rem;
    background: var(--bg-darker);
}
.writing-input-area textarea {
    flex: 1;
    background: transparent;
    border: none;
    resize: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
}
.small-btn {
    width: auto;
    padding: 0 1.5rem;
}
.writing-tools-panel {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.panel-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
}
.panel-section h4 { font-size: 0.95rem; margin-bottom: 0.5rem; color: var(--text-main); }
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.action-tag {
    background: var(--bg-darker);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}
.action-tag:hover { border-color: var(--text-main); color: var(--text-main); }
.action-tag.active { border-left: 3px solid var(--primary); }
.action-tag.passive { border-left: 3px solid var(--success); }
.action-tag.dark { border-left: 3px solid var(--danger); }
.action-tag.neutral { border-left: 3px solid var(--text-muted); }
