/* ============================================
   Research Hub — Claude Docs-inspired Theme
   Author: Yang Mingzhe
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Light theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f0f1f3;
  --bg-code: #f5f5f7;
  --bg-callout-info: #eef4ff;
  --bg-callout-warn: #fff8e6;
  --bg-callout-tip: #eefbf4;
  --bg-callout-critical: #fef2f2;
  --border-callout-info: #3b82f6;
  --border-callout-warn: #f59e0b;
  --border-callout-tip: #10b981;
  --border-callout-critical: #ef4444;
  --text-primary: #1a1a2e;
  --text-secondary: #4a4a6a;
  --text-tertiary: #8888a0;
  --text-link: #5046e5;
  --text-link-hover: #3730a3;
  --border-color: #e5e7eb;
  --border-light: #f0f0f0;
  --accent: #5046e5;
  --accent-light: #ede9fe;
  --accent-bg: rgba(80, 70, 229, 0.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', Georgia, serif;
  --content-width: 1060px;
  --sidebar-width: 240px;
  --toc-width: 0px;
  --header-height: 56px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #242440;
  --bg-code: #1e1e32;
  --bg-callout-info: #1a2332;
  --bg-callout-warn: #2a2418;
  --bg-callout-tip: #162420;
  --bg-callout-critical: #2a1a1a;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-tertiary: #6a6a80;
  --text-link: #818cf8;
  --text-link-hover: #a5b4fc;
  --border-color: #2a2a40;
  --border-light: #1f1f35;
  --accent: #818cf8;
  --accent-light: #2a2a50;
  --accent-bg: rgba(129, 140, 248, 0.08);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--text-link-hover); }

img { max-width: 100%; height: auto; }

/* --- Header --- */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 24px;
  transition: background var(--transition);
}
[data-theme="dark"] .site-header {
  background: rgba(15,15,26,0.85);
}

.header-inner {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  text-decoration: none;
}
.site-logo .logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}
.site-logo .logo-text-sub {
  font-weight: 400;
  color: var(--text-tertiary);
  margin-left: 2px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}
.header-nav a {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 6px 0;
}
.header-nav a:hover, .header-nav a.active { color: var(--text-primary); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1rem;
  transition: all var(--transition);
}
.theme-toggle:hover { color: var(--text-primary); border-color: var(--text-tertiary); }

/* --- Layout: Article --- */
.article-layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  padding-top: var(--header-height);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  border-right: 1px solid var(--border-color);
  padding: 20px 16px;
  background: var(--bg-primary);
  z-index: 100;
  transition: transform 0.3s ease, background var(--transition);
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.sidebar-section { margin-bottom: 24px; }
.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  padding: 0 12px;
  margin-bottom: 8px;
}

.sidebar-link {
  display: block;
  padding: 7px 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  line-height: 1.4;
}
.sidebar-link:hover { color: var(--text-primary); background: var(--bg-secondary); }
.sidebar-link.active {
  color: var(--accent);
  background: var(--accent-bg);
  font-weight: 600;
}
.sidebar-link.sub {
  padding-left: 28px;
  font-size: 0.8rem;
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.article-body {
  width: 100%;
  max-width: var(--content-width);
  padding: 48px 32px 120px;
}

.toc-sidebar {
  display: none !important;
}
.toc-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}
.toc-link {
  display: block;
  padding: 4px 0 4px 12px;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  border-left: 2px solid transparent;
  transition: all var(--transition);
  line-height: 1.5;
}
.toc-link:hover { color: var(--text-secondary); }
.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.toc-link.sub { padding-left: 24px; font-size: 0.75rem; }

/* --- Typography --- */
.article-body h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}
.article-body h2 {
  font-size: 1.45rem;
  font-weight: 700;
  margin-top: 56px;
  margin-bottom: 20px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
  letter-spacing: -0.01em;
}
.article-body h2:first-of-type { border-top: none; margin-top: 32px; }
.article-body h3 {
  font-size: 1.15rem;
  font-weight: 650;
  margin-top: 36px;
  margin-bottom: 14px;
}
.article-body h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.article-body p {
  margin-bottom: 18px;
  color: var(--text-primary);
}

.article-body strong { font-weight: 650; }

.article-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
}
.meta-author {
  display: flex;
  align-items: center;
  gap: 10px;
}
.meta-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
}
.meta-name { font-weight: 600; font-size: 0.9rem; }
.meta-role { font-size: 0.8rem; color: var(--text-tertiary); }
.meta-dot { color: var(--text-tertiary); }
.meta-date, .meta-read-time { font-size: 0.8rem; color: var(--text-tertiary); }

.subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.6;
}

/* --- Callouts --- */
.callout {
  padding: 16px 20px;
  border-radius: var(--radius-md);
  border-left: 4px solid;
  margin: 24px 0;
  font-size: 0.9rem;
  line-height: 1.6;
}
.callout-title {
  font-weight: 650;
  font-size: 0.85rem;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.callout.info { background: var(--bg-callout-info); border-color: var(--border-callout-info); }
.callout.warn { background: var(--bg-callout-warn); border-color: var(--border-callout-warn); }
.callout.tip { background: var(--bg-callout-tip); border-color: var(--border-callout-tip); }
.callout.critical { background: var(--bg-callout-critical); border-color: var(--border-callout-critical); }

/* --- Key Stats --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin: 28px 0;
}
.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-number {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  line-height: 1.3;
}

/* --- Tables --- */
.table-wrapper {
  overflow-x: auto;
  margin: 24px 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.article-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.article-body th {
  background: var(--bg-secondary);
  font-weight: 650;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.article-body td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
.article-body tr:last-child td { border-bottom: none; }
.article-body tr:hover td { background: var(--accent-bg); }

/* --- Code --- */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}
.article-body pre {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  overflow-x: auto;
  margin: 24px 0;
  font-size: 0.85rem;
  line-height: 1.6;
}
.article-body pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
}

/* --- Collapsible / Accordion --- */
.accordion {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin: 20px 0;
  overflow: hidden;
}
.accordion-item { border-bottom: 1px solid var(--border-color); }
.accordion-item:last-child { border-bottom: none; }
.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--bg-secondary);
  transition: background var(--transition);
  user-select: none;
}
.accordion-header:hover { background: var(--bg-tertiary); }
.accordion-arrow {
  transition: transform 0.3s ease;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}
.accordion-item.open .accordion-arrow { transform: rotate(180deg); }
.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 20px;
  font-size: 0.9rem;
  line-height: 1.7;
}
.accordion-item.open .accordion-content {
  max-height: 2000px;
  padding: 16px 20px;
}

/* --- Flow Chart (CSS) --- */
.flow-chart {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 28px 0;
  overflow-x: auto;
  padding: 16px 0;
}
.flow-step {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 0.82rem;
  font-weight: 500;
  text-align: center;
  min-width: 120px;
  white-space: nowrap;
  position: relative;
  transition: all var(--transition);
}
.flow-step:hover { border-color: var(--accent); background: var(--accent-bg); }
.flow-step.active { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); font-weight: 700; }
.flow-arrow {
  color: var(--text-tertiary);
  font-size: 1.2rem;
  flex-shrink: 0;
  padding: 0 4px;
}

/* --- Vertical Flow --- */
.flow-vertical {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 28px 0;
  max-width: 500px;
}
.flow-vertical .flow-step {
  width: 100%;
  text-align: left;
}
.flow-vertical .flow-arrow {
  text-align: center;
  padding: 4px 0;
  transform: rotate(90deg);
}

/* --- Comparison Cards --- */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
}
.compare-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
}
.compare-card h4 {
  margin-top: 0;
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--text-primary);
}
.compare-card ul {
  list-style: none;
  padding: 0;
}
.compare-card li {
  padding: 4px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  position: relative;
  padding-left: 18px;
}
.compare-card li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: bold;
}

/* --- Timeline --- */
.timeline {
  position: relative;
  margin: 32px 0;
  padding-left: 28px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border-color);
}
.timeline-item {
  position: relative;
  padding-bottom: 28px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute;
  left: -24px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.timeline-label {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 4px;
}
.timeline-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 6px;
}
.timeline-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* --- Radar Chart placeholder --- */
.chart-container {
  margin: 28px 0;
  padding: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  text-align: center;
}
.chart-container canvas {
  max-width: 100%;
  max-height: 360px;
}

/* --- Tooltip --- */
.term {
  border-bottom: 1px dashed var(--text-tertiary);
  cursor: help;
  position: relative;
}
.term:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  white-space: nowrap;
  max-width: 300px;
  white-space: normal;
  z-index: 100;
  box-shadow: var(--shadow-md);
  line-height: 1.4;
}

/* --- Lists --- */
.article-body ul, .article-body ol {
  margin: 12px 0 18px;
  padding-left: 24px;
}
.article-body li {
  margin-bottom: 6px;
  font-size: 0.95rem;
}
.article-body li::marker { color: var(--text-tertiary); }

/* --- Blockquote --- */
.article-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 12px 20px;
  margin: 24px 0;
  background: var(--accent-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-style: italic;
}
.article-body blockquote p { margin-bottom: 0; }

/* --- Reading Progress --- */
.reading-progress {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  z-index: 1001;
  transition: width 0.1s linear;
}

/* --- Back to Top --- */
.back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  border: none;
  font-size: 1.1rem;
  box-shadow: var(--shadow-md);
  z-index: 100;
}
.back-to-top.visible { opacity: 1; transform: translateY(0); }
.back-to-top:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

/* --- Homepage specific --- */
.home-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(var(--header-height) + 48px) 32px 80px;
}
.home-hero {
  text-align: center;
  padding: 48px 0 56px;
}
.home-hero h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
}
.home-hero .subtitle {
  max-width: 560px;
  margin: 0 auto 32px;
  font-size: 1.05rem;
}
.home-hero .author-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 50px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.article-list { margin-top: 16px; }
.article-card {
  display: flex;
  gap: 24px;
  padding: 28px 0;
  border-bottom: 1px solid var(--border-color);
  transition: all var(--transition);
}
.article-card:first-child { border-top: 1px solid var(--border-color); }
.article-card:hover { padding-left: 8px; }
.article-card-body { flex: 1; }
.article-card-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}
.article-card h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.article-card h3 a { color: var(--text-primary); }
.article-card h3 a:hover { color: var(--accent); }
.article-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 10px;
}
.article-card-meta {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  display: flex;
  gap: 12px;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
  .toc-sidebar { display: none; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .article-body { padding: 32px 20px 80px; }
  .home-layout { padding: 32px 20px 60px; padding-top: calc(var(--header-height) + 32px); }
  .home-hero h1 { font-size: 1.8rem; }
  .compare-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .flow-chart { flex-direction: column; align-items: stretch; }
  .flow-arrow { transform: rotate(90deg); text-align: center; }
}
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr; }
  .article-card { flex-direction: column; gap: 12px; }
}

/* --- Print --- */
@media print {
  .site-header, .sidebar, .toc-sidebar, .back-to-top, .reading-progress, .theme-toggle { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .article-body { max-width: 100%; padding: 0; }
  body { font-size: 11pt; }
}
