/* ============================================================
   AI 小说创作系统 - 全局样式（支持亮/暗双主题）
   ============================================================ */

/* ---- 暗色主题（默认） ---- */
:root,
[data-theme="dark"] {
  --bg-deep:      #0a0a14;
  --bg-card:      #13131f;
  --bg-card2:     #1a1a2e;
  --bg-hover:     #1e1e30;
  --border:       #252538;
  --border-light: #2d2d4e;
  --text:         #e0e0f0;
  --text-muted:   #9090b8;
  --text-sub:     #a8a8cc;
  --primary:      #6366f1;
  --primary-dark: #4f46e5;
  --primary-bg:   rgba(99,102,241,.15);
  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --info:         #3b82f6;
  --scrollbar:    #2d2d4e;
  --stream-bg:    #060610;
  --stream-text:  #7eeea0;
  --topbar-bg:    #13131f;
  --sidebar-bg:   #0f0f1c;
  --shadow:       rgba(0,0,0,.5);
}

/* ---- 亮色主题 ---- */
[data-theme="light"] {
  --bg-deep:      #f0f2f8;
  --bg-card:      #ffffff;
  --bg-card2:     #f5f6fa;
  --bg-hover:     #eef0f8;
  --border:       #e2e4ef;
  --border-light: #cdd0e3;
  --text:         #1a1b2e;
  --text-muted:   #7878a0;
  --text-sub:     #5558a0;
  --primary:      #5254d4;
  --primary-dark: #4042c0;
  --primary-bg:   rgba(82,84,212,.1);
  --success:      #059669;
  --warning:      #d97706;
  --danger:       #dc2626;
  --info:         #2563eb;
  --scrollbar:    #cdd0e3;
  --stream-bg:    #f0f4f0;
  --stream-text:  #166534;
  --topbar-bg:    #ffffff;
  --sidebar-bg:   #ffffff;
  --shadow:       rgba(0,0,0,.1);
}

/* ============================================================
   基础
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-deep);
  color: var(--text);
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  min-height: 100vh;
  transition: background .25s, color .25s;
}

::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

/* ============================================================
   Layout
   ============================================================ */

:root { --sidebar-w: 240px; }

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .25s ease, background .25s, border-color .25s;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-icon {
  font-size: 20px;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-text {
  font-weight: 700; font-size: 15px;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text-muted); text-decoration: none;
  font-size: 13px; margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav-item:hover  { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; }
.nav-item i { font-size: 16px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin .25s ease;
}
.sidebar.collapsed ~ .main-content { margin-left: 0; }

.topbar {
  position: sticky; top: 0;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex; align-items: center; gap: 12px;
  z-index: 50;
  transition: background .25s, border-color .25s;
}
[data-theme="light"] .topbar { box-shadow: 0 1px 4px var(--shadow); }

.sidebar-toggle {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 4px; line-height: 1;
  transition: color .15s;
}
.sidebar-toggle:hover { color: var(--text); }

.topbar-title { font-size: 14px; font-weight: 600; color: var(--text); }

/* 主题切换按钮 */
.theme-toggle {
  margin-left: auto;
  background: var(--bg-card2);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 4px 12px;
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; font-size: 12px; color: var(--text-muted);
  transition: all .2s;
  white-space: nowrap;
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: inline; }
[data-theme="light"] .theme-toggle .icon-sun  { display: inline; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

.content-area { padding: 24px 20px; flex: 1; }

/* ============================================================
   Cards
   ============================================================ */

.page-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: background .25s, border-color .25s;
}
[data-theme="light"] .page-card { box-shadow: 0 1px 6px var(--shadow); }

.page-card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13px;
  color: var(--text);
  background: var(--bg-card2);
}

/* ============================================================
   Stats
   ============================================================ */

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  transition: all .2s;
}
.stat-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-number { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   Novel Cards
   ============================================================ */

.novel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column;
  transition: transform .2s, border-color .2s, box-shadow .2s, background .25s;
}
.novel-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 8px 24px var(--shadow);
}
.novel-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
  color: rgba(255,255,255,.92);
  letter-spacing: 2px;
  text-shadow: 0 2px 8px rgba(0,0,0,.3);
  overflow: hidden;
  flex-shrink: 0;
}
.novel-cover img {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .3s ease;
}
.novel-card:hover .novel-cover img {
  transform: scale(1.05);
}
.novel-info { padding: 8px 10px; flex: 1; min-width: 0; }
.novel-title {
  font-weight: 600; color: var(--text); font-size: 14px;
  margin: 0; line-height: 1.3; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.novel-meta { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); flex-wrap: wrap; }

/* ============================================================
   Novel Header Card
   ============================================================ */

.novel-header-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: background .25s, border-color .25s;
}
[data-theme="light"] .novel-header-card { box-shadow: 0 1px 6px var(--shadow); }

.novel-cover-sm {
  width: 72px; height: 72px; border-radius: 10px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  color: rgba(255,255,255,.92);
  overflow: hidden;
  text-align: center; line-height: 1.3;
}
.model-switcher { min-width: 180px; }

/* ============================================================
   Tabs
   ============================================================ */

.novel-tabs .nav-link {
  color: var(--text-muted); border: none;
  border-bottom: 2px solid transparent; border-radius: 0;
  padding: 8px 16px; font-size: 13px;
  transition: color .15s;
}
.novel-tabs .nav-link.active { color: var(--primary); background: none; border-bottom-color: var(--primary); }
.novel-tabs .nav-link:hover  { color: var(--text); background: none; }

/* ============================================================
   Novel meta tags（小说头部信息条）
   ============================================================ */

.novel-meta-tags {
  font-size: 12px;
  color: var(--text-sub);
}
.novel-meta-tags span { display: inline-flex; align-items: center; gap: 2px; }
[data-theme="light"] .novel-meta-tags { color: #5558a0; }

/* ============================================================
   Chapter List（新版列表，每章一行）
   ============================================================ */

/* 表头 */
.chapter-list-header {
  display: grid;
  grid-template-columns: 72px 1fr 90px 70px 170px;
  gap: 0 12px;
  padding: 8px 16px;
  background: var(--bg-card2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}

/* 每章行 */
.chapter-list-row {
  display: grid;
  grid-template-columns: 72px 1fr 90px 70px 170px;
  gap: 0 12px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
  min-height: 52px;
}
.chapter-list-row:last-child { border-bottom: none; }
.chapter-list-row:hover      { background: var(--bg-hover); }

/* 已完成行左侧高亮条 */
.chapter-list-row[data-status="completed"] {
  border-left: 3px solid var(--success);
  padding-left: 13px;
}
.chapter-list-row[data-status="writing"] {
  border-left: 3px solid var(--warning);
  padding-left: 13px;
}
.chapter-list-row[data-status="outlined"] {
  border-left: 3px solid var(--info);
  padding-left: 13px;
}
.chapter-list-row[data-status="pending"] {
  border-left: 3px solid var(--border-light);
  padding-left: 13px;
}

/* 章节号 */
.ch-number {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 标题 */
.ch-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 大纲概要（第二行，缩略） */
.ch-outline {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 字数 */
.ch-words       { font-size: 12px; color: var(--text-sub); font-variant-numeric: tabular-nums; }
.ch-words-empty { font-size: 12px; color: var(--border-light); }

/* 状态文字 */
.ch-status-text { font-size: 11px; color: var(--text-muted); }

/* grid 列对齐 */
.col-num    { }
.col-title  { overflow: hidden; }
.col-status { display: flex; align-items: center; }
.col-words  { display: flex; align-items: center; }
.col-action { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }

/* 移动端：隐藏字数列，缩减大纲 */
@media (max-width: 640px) {
  .chapter-list-header,
  .chapter-list-row {
    grid-template-columns: 60px 1fr 80px 110px;
  }
  .col-words,
  .chapter-list-header .col-words { display: none; }
  .ch-outline { display: none; }
}

/* ============================================================
   大纲流式输出框
   ============================================================ */

.outline-stream-box {
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 12px; line-height: 1.7;
  color: var(--stream-text);
  background: var(--stream-bg);
  padding: 12px 14px;
  min-height: 120px; max-height: 280px;
  overflow-y: auto;
  white-space: pre-wrap; word-break: break-all;
  transition: background .25s, color .25s;
}
/* 写作实时流式框（自动写作面板） */
.write-stream-box {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 13px;
  line-height: 1.9;
  color: var(--text);
  background: var(--bg-card2);
  padding: 14px 16px;
  min-height: 100px;
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  border-top: 1px solid var(--border);
}

/* 深度思考过程展示区域 */
.write-thinking-wrap {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.write-thinking-summary {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card2);
  border-bottom: 1px solid var(--border);
  user-select: none;
  transition: background .2s;
}
.write-thinking-summary:hover {
  background: rgba(99,102,241,.08);
  color: var(--text);
}
.write-thinking-box {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: rgba(168,180,200,.85);
  background: rgba(0,0,0,.2);
  padding: 12px 16px;
  min-height: 40px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
[data-theme="light"] .write-thinking-box {
  color: rgba(80,90,110,.85);
  background: rgba(0,0,0,.03);
}
.write-thinking-wrap[open] .write-thinking-summary {
  border-bottom: 1px solid var(--border);
}

.outline-stream-cursor {
  display: inline-block; width: 8px; height: 14px;
  background: var(--primary); vertical-align: text-bottom;
  animation: blink .7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.outline-batch-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px; font-size: 12px;
  border-radius: 4px; margin: 2px 0;
}
.outline-batch-item.success { background: rgba(16,185,129,.12);  color: var(--success); }
.outline-batch-item.error   { background: rgba(239,68,68,.1);    color: var(--danger);  }
.outline-batch-item.warning { background: rgba(245,158,11,.12);  color: var(--warning); }
[data-theme="light"] .outline-batch-item.success { background: #d1fae5; }
[data-theme="light"] .outline-batch-item.error   { background: #fee2e2; }
[data-theme="light"] .outline-batch-item.warning { background: #fef3c7; }

.token-badge {
  display: inline-flex; gap: 10px; font-size: 11px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px;
}

/* ============================================================
   Create Form
   ============================================================ */

.form-section {
  margin-bottom: 24px; padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.form-section:last-of-type { border-bottom: none; }
.form-section-title {
  font-weight: 600; font-size: 12px;
  color: var(--primary); margin-bottom: 16px;
  text-transform: uppercase; letter-spacing: .5px;
}

/* ============================================================
   Settings
   ============================================================ */

.model-item { padding: 14px 16px; }
.model-item:hover { background: var(--bg-hover) !important; }

/* ============================================================
   Chapter page
   ============================================================ */

.chapter-content {
  line-height: 2; font-size: 15px;
  color: var(--text);
  white-space: pre-wrap; word-break: break-all;
}
.chapter-content-preview {
  line-height: 1.9; font-size: 14px;
  color: var(--text);
  white-space: pre-wrap; word-break: break-all;
  min-height: 200px; max-height: 60vh; overflow-y: auto;
}
.chapter-editor {
  min-height: max(500px, calc(100vh - 280px));
  height: max(500px, calc(100vh - 280px));
  line-height: 2;
  font-size: 15px;
  resize: vertical;
}

.setting-item {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; height: 100%;
}
.setting-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.setting-value { font-size: 13px; color: var(--text); line-height: 1.7; }

/* ============================================================
   Empty state
   ============================================================ */

.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon  { font-size: 48px; margin-bottom: 16px; opacity: .3; color: var(--text-muted); }
.empty-state h5, .empty-state h6 { color: var(--text); }
.empty-state p { color: var(--text-muted); }

/* ============================================================
   Bootstrap overrides
   ============================================================ */

.form-control, .form-select {
  background: var(--bg-card2);
  border-color: var(--border-light);
  color: var(--text);
  font-size: 13px;
  transition: background .2s, border-color .2s, color .2s;
}
.form-control:focus, .form-select:focus {
  background: var(--bg-card2);
  border-color: var(--primary);
  color: var(--text);
  box-shadow: 0 0 0 .2rem rgba(99,102,241,.2);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled     { background: var(--bg-deep); color: var(--text-muted); }
.form-label  { color: var(--text-muted); font-size: 12px; font-weight: 500; margin-bottom: 6px; }
.form-text   { font-size: 11px; color: var(--text-muted); }
.form-check-input:checked  { background-color: var(--primary); border-color: var(--primary); }
.form-check-input:not(:checked) { background-color: var(--bg-card2); border-color: var(--border-light); }

/* Alert */
.alert-success { background: rgba(16,185,129,.15); border-color: rgba(16,185,129,.4); color: #6ee7b7; }
.alert-danger  { background: rgba(239,68,68,.12);  border-color: rgba(239,68,68,.4);  color: #fca5a5; }
[data-theme="light"] .alert-success { background: #d1fae5; border-color: #6ee7b7; color: #065f46; }
[data-theme="light"] .alert-danger  { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.alert-sm { padding: 8px 12px; font-size: 13px; }

/* Table */
.table { --bs-table-color: var(--text); --bs-table-bg: transparent; --bs-table-border-color: var(--border); }
.table-dark { --bs-table-bg: transparent; --bs-table-hover-bg: var(--bg-hover); --bs-table-color: var(--text); }
[data-theme="light"] .table-dark { --bs-table-striped-bg: var(--bg-card2); }

/* Badge */
.badge { font-size: 10px; font-weight: 500; padding: 3px 7px; }
.bg-secondary { background-color: var(--border-light) !important; color: var(--text-muted) !important; }
[data-theme="light"] .bg-secondary { background-color: #e2e4ef !important; color: #5558a0 !important; }

/* text-muted 暗色模式提亮（覆盖 Bootstrap 默认的 #6c757d） */
[data-theme="dark"] .text-muted { color: var(--text-muted) !important; }

/* Novel page - 亮色模式文字颜色 */
.novel-header-card h4 {
  color: var(--text) !important;
}
.novel-meta-tags span {
  color: var(--text) !important;
}
.novel-meta-tags span i {
  color: var(--text-muted) !important;
}

/* 全书故事大纲区域 - 暗色模式文字白色 */
#story-outline-content,
#story-outline-content div,
#story-outline-content h6 {
  color: var(--text) !important;
}
#story-outline-content .text-muted {
  color: var(--text-muted) !important;
}

/* Breadcrumb */
.breadcrumb { background: none; margin: 0; padding: 0; font-size: 12px; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }
.breadcrumb-item a { color: var(--text-muted); }
.breadcrumb-item a:hover { color: var(--primary); }

/* Modal */
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  color: var(--text);
}
.modal-header, .modal-footer { border-color: var(--border); }
.btn-close-white { filter: none; }
[data-theme="light"] .btn-close { filter: none; }
[data-theme="dark"]  .btn-close { filter: invert(1) grayscale(1); }

/* Progress */
.progress { background: var(--bg-card2); }

/* List group */
.list-group-item { background: transparent; border-color: var(--border); color: var(--text); }

/* Buttons */
.btn-primary   { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--bg-card2); border-color: var(--border-light); color: var(--text); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-light); color: var(--text); }
.btn-outline-primary { border-color: var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-outline-secondary { border-color: var(--border-light); color: var(--text-muted); }
.btn-outline-secondary:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-light); }
.btn-outline-info    { border-color: var(--info); color: var(--info); }
.btn-outline-info:hover    { background: var(--info); color: #fff; }
.btn-outline-danger  { border-color: var(--danger); color: var(--danger); }
.btn-outline-danger:hover  { background: var(--danger); color: #fff; }
.btn-outline-warning { border-color: var(--warning); color: var(--warning); }
.btn-outline-warning:hover { background: var(--warning); color: #fff; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 4px; }

/* Spinner */
.spinner-border { border-color: var(--primary); border-right-color: transparent; }
.spinner-border.text-info { border-color: var(--info); border-right-color: transparent; }

/* Dropdown */
.dropdown-menu {
  background: var(--bg-card);
  border-color: var(--border);
  box-shadow: 0 8px 24px var(--shadow);
}
.dropdown-item { color: var(--text); }
.dropdown-item:hover { background: var(--bg-hover); color: var(--text); }

/* ============================================================
   Progress bars
   ============================================================ */

.write-progress-wrap .progress-bar { background: var(--primary); }

/* ============================================================
   Responsive
   ============================================================ */

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,.45);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  .sidebar      { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.mobile-open { transform: none; }
  .main-content { margin-left: 0 !important; }
  .content-area { padding: 16px 12px; }
  .novel-cover-sm { display: none; }
  .theme-toggle span.label { display: none; }
}
