/* ======================================================
   AI全栈学习手册 · 精品文档样式系统
   ====================================================== */

/* === CSS Variables === */
:root {
  --primary: #1677ff;
  --primary-light: #4096ff;
  --primary-dark: #0958d9;
  --secondary: #0958d9;
  --accent: #36cfc9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --bg: #f8fafc;
  --bg-secondary: #f1f5f9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-text-active: #f8fafc;
  --sidebar-hover: #334155;
  --sidebar-active: rgba(22,119,255,0.2);
  --sidebar-border: #334155;
  --sidebar-width: 280px;

  --header-height: 60px;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --surface: #1e293b;
  --surface-hover: #334155;
  --border: #334155;
  --border-light: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-border: #1e293b;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

/* === Reading Progress Bar === */
.reading-progress {
  position: fixed; top: 0; left: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary), var(--accent));
  width: 0%; z-index: 1000; transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
}

/* === Header === */
.header {
  position: fixed; top: 3px; left: 0; right: 0; height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  z-index: 100; backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}
.header-left { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.header-center { flex: 1; max-width: 520px; margin: 0 auto; }
.header-right { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }

.menu-toggle {
  width: 36px; height: 36px; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center; gap: 5px; padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.menu-toggle span {
  display: block; height: 2px; background: currentColor; border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s, width 0.2s;
}
.menu-toggle:hover { background: var(--bg-secondary); }
.sidebar-open .menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar-open .menu-toggle span:nth-child(2) { opacity: 0; }
.sidebar-open .menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { display: flex; align-items: center; flex-shrink: 0; }
.logo-text { font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.logo-badge {
  font-size: 11px; font-weight: 600; background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white; padding: 2px 7px; border-radius: 20px;
}

.search-trigger {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--bg-secondary);
  color: var(--text-muted); cursor: pointer; font-size: 14px;
  transition: all var(--transition);
}
.search-trigger:hover { border-color: var(--primary); color: var(--text-secondary); }
.search-trigger span { flex: 1; text-align: left; }
.search-trigger kbd {
  font-size: 11px; padding: 2px 6px; background: var(--border);
  border-radius: 4px; color: var(--text-muted); font-family: inherit;
}

.overall-progress { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.progress-label { color: var(--text-muted); white-space: nowrap; }
.progress-bar-mini { width: 80px; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill-mini { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 3px; transition: width 0.5s ease; }
.progress-pct { font-weight: 600; color: var(--primary); min-width: 32px; }

.theme-toggle {
  width: 36px; height: 36px; border: none; background: var(--bg-secondary);
  border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: all var(--transition);
}
.theme-toggle:hover { background: var(--border); }
.icon-sun { display: block; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* === Sidebar === */
.sidebar {
  position: fixed; top: calc(var(--header-height) + 3px); left: 0; bottom: 0;
  width: var(--sidebar-width); background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto; z-index: 90;
  transition: transform var(--transition);
  scrollbar-width: thin; scrollbar-color: #334155 transparent;
}
.sidebar-inner { padding: 16px 0; }
.sidebar-header { padding: 0 16px 16px; border-bottom: 1px solid var(--sidebar-border); margin-bottom: 8px; }
.course-meta-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; }
.overall-progress-sidebar { display: flex; align-items: center; gap: 8px; }
.progress-bar-sidebar { flex: 1; height: 4px; background: #334155; border-radius: 2px; overflow: hidden; }
.progress-fill-sidebar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width 0.5s ease; }
#progressTextSidebar { font-size: 12px; color: var(--sidebar-text); white-space: nowrap; }

.module-item { }
.module-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  cursor: pointer; color: var(--sidebar-text);
  transition: background var(--transition);
  user-select: none;
}
.module-header:hover { background: var(--sidebar-hover); }
.module-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.module-title { flex: 1; font-size: 13px; font-weight: 500; line-height: 1.4; }
.module-progress-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #334155; flex-shrink: 0;
  transition: background 0.2s;
}
.module-progress-dot.done { background: var(--success); }
.module-expand {
  color: var(--text-muted); transition: transform 0.25s ease; flex-shrink: 0;
}
.module-item.expanded .module-expand { transform: rotate(90deg); }
.module-item.expanded .module-header { background: var(--sidebar-hover); }

.section-list { display: none; }
.module-item.expanded .section-list { display: block; }
.section-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px 7px 46px; cursor: pointer;
  color: var(--sidebar-text); font-size: 13px; line-height: 1.4;
  transition: background var(--transition), color var(--transition);
  border-left: 2px solid transparent;
}
.section-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.section-item.active {
  background: var(--sidebar-active); color: var(--sidebar-text-active);
  border-left-color: var(--primary);
}
.section-check {
  width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid #475569;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.section-check.done { background: var(--success); border-color: var(--success); }
.section-check.done::after { content: '✓'; font-size: 9px; color: white; font-weight: 700; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 89; backdrop-filter: blur(2px);
}

/* === Page Layout === */
.page-wrapper {
  padding-top: calc(var(--header-height) + 3px);
  padding-left: var(--sidebar-width);
  min-height: 100vh;
  transition: padding-left var(--transition);
}
.main-content { padding: 40px 48px; max-width: 1200px; }

/* === Landing Page === */
.landing { max-width: 900px; }
.landing-hero {
  padding: 64px 0 56px;
  border-bottom: 1px solid var(--border);
}
.landing-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, rgba(22,119,255,.1), rgba(9,88,217,.1));
  border: 1px solid rgba(22,119,255,.3);
  color: var(--primary); font-size: 13px; font-weight: 500;
  padding: 5px 14px; border-radius: 20px; margin-bottom: 24px;
}
.landing-title {
  font-size: 52px; font-weight: 800; line-height: 1.15; margin-bottom: 20px;
  color: var(--text);
}
.gradient-text {
  background: linear-gradient(135deg, var(--primary), var(--secondary), var(--accent));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.landing-desc { font-size: 17px; color: var(--text-secondary); max-width: 600px; margin-bottom: 36px; line-height: 1.8; }
.landing-stats { display: flex; align-items: center; gap: 24px; margin-bottom: 36px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat strong { font-size: 26px; font-weight: 800; color: var(--primary); line-height: 1; }
.stat span { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-div { width: 1px; height: 32px; background: var(--border); }
.btn-start {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white; font-size: 16px; font-weight: 600; padding: 13px 32px;
  border: none; border-radius: var(--radius); cursor: pointer;
  transition: all var(--transition); box-shadow: 0 4px 16px rgba(22,119,255,.4);
}
.btn-start:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(22,119,255,.5); }

.landing-modules { padding: 48px 0; }
.landing-modules h2 { font-size: 24px; font-weight: 700; margin-bottom: 28px; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.module-card {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; cursor: pointer; transition: all var(--transition);
}
.module-card:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-2px); }
.module-card-icon { font-size: 28px; margin-bottom: 12px; }
.module-card-num { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 4px; }
.module-card-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.module-card-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.module-card-sections { margin-top: 12px; font-size: 12px; color: var(--text-muted); }

/* === Chapter View === */
.chapter-layout { display: flex; gap: 40px; align-items: flex-start; }
.chapter-main { flex: 1; min-width: 0; }
.toc-sidebar {
  width: 220px; flex-shrink: 0; position: sticky; top: calc(var(--header-height) + 24px);
  max-height: calc(100vh - var(--header-height) - 48px); overflow-y: auto;
}

.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; display: flex; align-items: center; gap: 6px; }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb-sep { color: var(--border); }

.chapter-header { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.chapter-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--primary);
  background: rgba(22,119,255,.1); padding: 4px 12px; border-radius: 20px; margin-bottom: 12px;
}
.chapter-title { font-size: 32px; font-weight: 800; line-height: 1.25; margin-bottom: 12px; }
.chapter-meta { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--text-muted); }
.chapter-meta span { display: flex; align-items: center; gap: 4px; }

/* === Markdown Body === */
.markdown-body { line-height: 1.8; color: var(--text); }
.markdown-body h1 { font-size: 30px; font-weight: 800; margin: 40px 0 16px; color: var(--text); }
.markdown-body h2 {
  font-size: 22px; font-weight: 700; margin: 40px 0 14px; padding-bottom: 10px;
  border-bottom: 2px solid var(--border); color: var(--text);
}
.markdown-body h3 { font-size: 17px; font-weight: 600; margin: 28px 0 10px; color: var(--text); }
.markdown-body h4 { font-size: 15px; font-weight: 600; margin: 20px 0 8px; color: var(--text-secondary); }
.markdown-body p { margin-bottom: 16px; color: var(--text-secondary); }
.markdown-body strong { color: var(--text); font-weight: 600; }
.markdown-body em { color: var(--text-secondary); font-style: italic; }
.markdown-body a { color: var(--primary); text-decoration: none; border-bottom: 1px solid rgba(22,119,255,.3); transition: border-color 0.2s; }
.markdown-body a:hover { border-bottom-color: var(--primary); }
.markdown-body ul, .markdown-body ol { margin: 12px 0 16px 20px; }
.markdown-body li { margin-bottom: 6px; color: var(--text-secondary); }
.markdown-body li > strong { color: var(--text); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }

/* Tables */
.markdown-body table {
  width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 14px;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
}
.markdown-body thead { background: linear-gradient(135deg, rgba(22,119,255,.08), rgba(9,88,217,.08)); }
.markdown-body th {
  padding: 12px 16px; text-align: left; font-weight: 600; font-size: 13px;
  color: var(--text); border-bottom: 1px solid var(--border);
}
.markdown-body td { padding: 11px 16px; border-bottom: 1px solid var(--border-light); color: var(--text-secondary); }
.markdown-body tr:last-child td { border-bottom: none; }
.markdown-body tr:hover td { background: var(--surface-hover); }

/* Code */
.markdown-body code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px; background: var(--bg-secondary); color: var(--primary);
  padding: 2px 7px; border-radius: 4px;
}
.markdown-body pre {
  background: #1e293b; border-radius: var(--radius); padding: 20px; margin: 16px 0;
  overflow-x: auto; position: relative;
  border: 1px solid #334155;
}
.markdown-body pre code {
  background: none; color: #e2e8f0; padding: 0; font-size: 13.5px; line-height: 1.7;
}

/* Blockquotes */
.markdown-body blockquote {
  border-left: 4px solid var(--primary); padding: 14px 20px;
  background: rgba(22,119,255,.06); border-radius: 0 var(--radius) var(--radius) 0;
  margin: 20px 0; color: var(--text-secondary);
}
.markdown-body blockquote p { margin: 0; }

/* TOC Sidebar */
.toc-header { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 12px; padding: 0 4px; }
.toc-list { }
.toc-item {
  display: block; font-size: 13px; color: var(--text-secondary);
  padding: 5px 8px; border-radius: var(--radius-sm);
  text-decoration: none; transition: all 0.15s;
  border-left: 2px solid transparent;
}
.toc-item:hover { color: var(--primary); background: rgba(22,119,255,.06); }
.toc-item.active { color: var(--primary); background: rgba(22,119,255,.08); border-left-color: var(--primary); }
.toc-item.h3 { padding-left: 20px; font-size: 12px; }

/* Chapter Nav Buttons */
.chapter-nav-btns {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 40px; padding-top: 18px;
  border-top: 1px solid var(--border); gap: 12px;
}
.nav-btn {
  display: flex; align-items: center; gap: 7px; padding: 7px 13px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-secondary); cursor: pointer;
  text-decoration: none; font-size: 13px; transition: all var(--transition); max-width: 210px;
}
.nav-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(22,119,255,.04); }
.nav-btn.next { text-align: right; flex-direction: row-reverse; margin-left: auto; }
.nav-btn-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); display: block; line-height: 1.3; }
.nav-btn-title { font-weight: 500; color: inherit; display: block; font-size: 12px; line-height: 1.4; margin-top: 1px; }

/* Completion button */
.completion-btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 14px;
  background: transparent; border: 1px solid var(--border); border-radius: 20px;
  cursor: pointer; font-size: 12px; font-weight: 500;
  color: var(--text-muted); transition: all var(--transition); white-space: nowrap; flex-shrink: 0;
}
.completion-btn:hover { border-color: var(--success); color: var(--success); background: rgba(16,185,129,.06); }
.completion-btn.done { background: rgba(16,185,129,.1); border-color: var(--success); color: var(--success); }

/* === Search Modal === */
.search-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  align-items: flex-start; justify-content: center; padding-top: 80px;
}
.search-overlay.active { display: flex; }
.search-modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 600px;
  box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--border);
}
.search-input-wrap {
  display: flex; align-items: center; gap: 12px; padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.search-input {
  flex: 1; border: none; outline: none; font-size: 16px;
  background: transparent; color: var(--text);
}
.search-close {
  font-size: 11px; padding: 3px 8px; background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted);
  cursor: pointer; font-family: inherit;
}
.search-results { max-height: 440px; overflow-y: auto; padding: 8px; }
.search-hint { padding: 24px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }
.search-result-item {
  padding: 12px 16px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--transition); margin-bottom: 2px;
}
.search-result-item:hover, .search-result-item.selected { background: var(--bg-secondary); }
.search-result-module { font-size: 11px; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 3px; }
.search-result-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.search-result-preview { font-size: 13px; color: var(--text-muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-result-preview mark { background: rgba(22,119,255,.2); color: var(--primary); border-radius: 2px; padding: 0 2px; }
.search-no-result { padding: 32px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* === Back to Top === */
.back-to-top {
  position: fixed; bottom: 28px; right: 28px; width: 44px; height: 44px;
  background: var(--primary); color: white; border: none; border-radius: 50%;
  cursor: pointer; box-shadow: 0 4px 16px rgba(22,119,255,.4);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: all var(--transition);
  z-index: 50;
}
.back-to-top.visible { opacity: 1; pointer-events: all; }
.back-to-top:hover { transform: translateY(-3px); }

/* === Callout Boxes === */
.callout {
  border-radius: var(--radius); padding: 16px 20px; margin: 20px 0;
  border-left: 4px solid;
}
.callout-tip { background: rgba(16,185,129,.06); border-color: var(--success); }
.callout-warning { background: rgba(245,158,11,.06); border-color: var(--warning); }
.callout-danger { background: rgba(239,68,68,.06); border-color: var(--danger); }
.callout-info { background: rgba(6,182,212,.06); border-color: var(--accent); }
.callout-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }

/* === Tag Pills === */
.tag { display: inline-block; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 20px; margin: 2px; }
.tag-primary { background: rgba(22,119,255,.1); color: var(--primary); }

/* === Mermaid 图表 === */
.mermaid-wrap {
  margin: 24px 0; padding: 20px 16px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-x: auto; text-align: center;
}
.mermaid-wrap svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.mermaid-fallback { text-align: left !important; font-size: 12px; color: var(--text-secondary); margin: 0; padding: 8px 12px; white-space: pre; overflow-x: auto; background: transparent; border: none; }
[data-theme="dark"] .mermaid-wrap { background: #1e293b; }
.tag-success { background: rgba(16,185,129,.1); color: var(--success); }
.tag-warning { background: rgba(245,158,11,.1); color: var(--warning); }

/* === Responsive === */
@media (max-width: 1200px) {
  .toc-sidebar { display: none; }
}
@media (max-width: 768px) {
  :root { --sidebar-width: 280px; }
  .sidebar { transform: translateX(-100%); }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-overlay { display: block; }
  .page-wrapper { padding-left: 0; }
  .main-content { padding: 24px 20px; }
  .landing-title { font-size: 36px; }
  .landing-stats { gap: 16px; flex-wrap: wrap; }
  .progress-label, .overall-progress { display: none; }
  .header-center { display: none; }
}
@media (max-width: 480px) {
  .module-grid { grid-template-columns: 1fr; }
  .chapter-nav-btns { flex-wrap: wrap; gap: 8px; }
  .nav-btn { max-width: 100%; }
  .nav-btn.next { margin-left: 0; }
  .completion-btn { order: -1; width: 100%; justify-content: center; }
}
