/* Local DE Coach — Docs UI v3
   Modern indigo/violet theme
   Conditional layout: no sidebar on cover page
*/

:root {
  --bg: #ffffff;
  --bg-subtle: #f8f9fc;
  --bg-sidebar: #fbfbfd;
  --bg-code: #f0f1f5;
  --bg-code-block: #0d1117;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f9fc;
  --border: #e5e7eb;
  --border-subtle: #f0f1f5;
  --text: #111827;
  --text-muted: #6b7280;
  --text-subtle: #9ca3af;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.08);
  --primary-lighter: rgba(99, 102, 241, 0.15);
  --accent: #8b5cf6;
  --accent-light: rgba(139, 92, 246, 0.1);
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --header-bg: rgba(255,255,255,0.85);
  --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 24px rgba(0,0,0,0.10);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --sidebar-w: 260px;
  --toc-w: 200px;
  --topbar-h: 60px;
  --max-content: 800px;
  --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --gradient-hero: linear-gradient(135deg, #312e81 0%, #6366f1 40%, #8b5cf6 100%);
}

[data-theme="dark"] {
  --bg: #0f0f17;
  --bg-subtle: #1a1a2e;
  --bg-sidebar: #0f0f17;
  --bg-code: #1e1e2e;
  --bg-code-block: #04040a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #252540;
  --border: #2a2a3e;
  --border-subtle: #222235;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --primary-light: rgba(129, 140, 248, 0.1);
  --primary-lighter: rgba(129, 140, 248, 0.2);
  --accent: #a78bfa;
  --accent-light: rgba(167, 139, 250, 0.15);
  --header-bg: rgba(15,15,23,0.85);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.7);
  --gradient-hero: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #5b21b6 100%);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Top bar ──────────────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex; align-items: center;
  padding: 0 24px;
  height: 100%;
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-center { flex: 1; display: flex; justify-content: center; padding: 0 24px; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.sidebar-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 8px; border-radius: var(--radius);
  display: none;
}
.sidebar-toggle:hover { background: var(--bg-subtle); color: var(--text); }

.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo-img {
  width: 32px; height: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.logo-text { font-weight: 700; font-size: 16px; letter-spacing: -0.3px; }
.logo-version {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--text-subtle);
  padding: 2px 8px; background: var(--bg-subtle); border-radius: 12px;
  font-weight: 500;
}

.search-box {
  width: 100%; max-width: 420px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: var(--primary); }
.search-box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 14px; font-family: inherit;
}
.search-box kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; padding: 2px 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-muted);
}

.topbar-link {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); text-decoration: none;
  padding: 8px 12px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  transition: all 0.15s;
}
.topbar-link:hover { background: var(--bg-subtle); color: var(--text); }

.theme-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 8px;
  border-radius: var(--radius); display: flex; align-items: center;
}
.theme-toggle:hover { background: var(--bg-subtle); color: var(--text); }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ─── Layout ───────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  padding-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
  width: 100%;
}

/* When on cover page, content takes full width (no sidebar) */
body.page-cover .layout {
  max-width: none;
}
body.page-cover .content {
  flex: 1;
  max-width: none;
  padding: 0;
}

/* Chapter pages: sidebar pinned left, content centered, TOC right */
body:not(.page-cover) .layout {
  align-items: flex-start;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 24px 12px;
  align-self: flex-start;
}

.sidebar-section { margin-bottom: 20px; }
.sidebar-section-title {
  font-size: 11px; font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 0 12px; margin-bottom: 6px;
}

.sidebar-link {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 12px;
  color: var(--text-muted); text-decoration: none;
  font-size: 14px; border-radius: var(--radius);
  border-left: 2px solid transparent;
  transition: all 0.15s;
  margin-bottom: 1px;
  line-height: 1.4;
}
.sidebar-link:hover { background: var(--bg-subtle); color: var(--text); }
.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 500;
}
.sidebar-link .chapter-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--text-subtle);
  flex-shrink: 0;
}
.sidebar-link.active .chapter-num { color: var(--primary); }

/* ─── Content (chapter pages) ─────────────────────────────────────────── */
.content {
  flex: 1;
  min-width: 0;
  padding: 48px 56px 96px;
  max-width: 760px;
}

body:not(.page-cover) .content {
  margin: 0 auto;
}

.content h1 {
  font-family: 'Playfair Display', serif;
  font-size: 32px; font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
  line-height: 1.2;
  letter-spacing: -0.5px;
}
.content h2 {
  font-size: 22px; font-weight: 600;
  color: var(--text);
  margin: 36px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.content h3 {
  font-size: 17px; font-weight: 600;
  color: var(--text);
  margin: 24px 0 10px;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.content h4 {
  font-size: 15px; font-weight: 600;
  color: var(--text);
  margin: 18px 0 8px;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}

.content p {
  margin: 0 0 16px;
  color: var(--text);
  line-height: 1.7;
}

.content a {
  color: var(--primary); text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.content a:hover { border-bottom-color: var(--primary); }

.content ul, .content ol { margin: 0 0 16px; padding-left: 24px; }
.content li { margin: 4px 0; line-height: 1.7; }

.content strong { color: var(--text); font-weight: 600; }
.content em { color: var(--text-muted); font-style: italic; }

.content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  background: var(--bg-code);
  padding: 2px 6px; border-radius: 4px;
  color: var(--primary);
}

.content pre {
  background: var(--bg-code-block) !important;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin: 16px 0;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid var(--border);
}
.content pre code {
  background: none; padding: 0; color: #e6edf3;
  font-size: 13px;
}

.content blockquote {
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  margin: 16px 0;
  background: var(--primary-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
}
.content blockquote p:last-child { margin-bottom: 0; }

.content table {
  width: 100%; border-collapse: collapse;
  margin: 16px 0; font-size: 14px;
  display: block; overflow-x: auto;
  border-radius: var(--radius);
  overflow: hidden;
}
.content table th {
  background: var(--bg-subtle);
  font-weight: 600; text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.content table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text);
  vertical-align: top;
}
.content table tr:hover td { background: var(--bg-subtle); }
.content table tr:last-child td { border-bottom: none; }

.content hr {
  border: none; border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* ─── Cover page ──────────────────────────────────────────────────────── */
.cover { padding: 0; }

.cover-hero {
  position: relative;
  background: var(--gradient-hero);
  padding: 80px 48px 64px;
  margin: 0;
  overflow: hidden;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  width: 100%;
}
.cover-hero-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url('../img/hero-bg.png');
  background-size: cover;
  background-position: center;
  opacity: 0.15;
  mix-blend-mode: overlay;
}
.cover-hero-content {
  position: relative;
  z-index: 1;
  max-width: 720px;
}
.cover-kicker {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; letter-spacing: 3px;
  color: rgba(255,255,255,0.7); text-transform: uppercase;
  margin-bottom: 20px;
  font-weight: 500;
}
.cover-title {
  font-family: 'Playfair Display', serif;
  font-size: 64px; font-weight: 900;
  color: #ffffff; margin: 0 0 20px;
  line-height: 1.05;
  letter-spacing: -2px;
}
.cover-subtitle {
  font-size: 22px; color: rgba(255,255,255,0.85);
  max-width: 600px; margin: 0 0 24px;
  line-height: 1.4;
  font-weight: 400;
}
.cover-summary {
  font-size: 15px; color: rgba(255,255,255,0.65);
  max-width: 580px; margin: 0 0 32px;
  line-height: 1.7;
}

.cover-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  position: relative;
  z-index: 1;
  padding: 0 24px;
  margin-top: -40px;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
}
.cover-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transition: transform 0.2s;
}
.cover-stat:hover { transform: translateY(-4px); }
.cover-stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 28px; font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}
.cover-stat-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-top: 8px;
}

.cover-section {
  padding: 48px 24px;
  max-width: 960px;
  margin: 0 auto;
}
.cover-section h2 {
  font-family: 'Playfair Display', serif;
  font-size: 28px; font-weight: 700;
  color: var(--text);
  margin: 0 0 24px;
  border: none; padding: 0;
}

.cover-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin: 0;
}
.cover-feature {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all 0.2s;
}
.cover-feature:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.cover-feature-icon {
  width: 40px; height: 40px;
  background: var(--primary-light);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
}
.cover-feature h3 {
  font-size: 16px; margin: 0 0 8px;
  color: var(--text);
  border: none; padding: 0;
}
.cover-feature p {
  font-size: 14px; margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Chart container */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 24px 0;
}
.chart-title {
  font-size: 14px; font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}
.chart-canvas-wrap {
  position: relative;
  height: 300px;
}

/* Quick start on cover */
.cover-quickstart {
  background: var(--bg-code-block);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin: 16px 0;
}
.cover-quickstart pre {
  background: none !important;
  border: none;
  padding: 0;
  margin: 0;
}
.cover-quickstart code {
  color: #e6edf3;
  background: none;
  font-size: 14px;
}

/* Chapter cards on cover */
.cover-chapters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 0;
}
.cover-chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  display: flex; flex-direction: column;
}
.cover-chapter-card:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.cover-chapter-card .num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: var(--primary);
  font-weight: 600;
}
.cover-chapter-card .title {
  font-size: 14px; font-weight: 500;
  color: var(--text);
  margin-top: 4px;
}

/* ─── TOC ─────────────────────────────────────────────────────────────── */
.toc {
  width: var(--toc-w);
  flex-shrink: 0;
  padding: 48px 20px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  align-self: flex-start;
}
.toc-title {
  font-size: 11px; font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.toc-link {
  display: block; padding: 4px 0 4px 12px;
  color: var(--text-muted); text-decoration: none;
  font-size: 13px; border-left: 2px solid var(--border-subtle);
  transition: all 0.15s;
  line-height: 1.4;
}
.toc-link:hover { color: var(--text); }
.toc-link.active {
  color: var(--primary); border-left-color: var(--primary);
  font-weight: 500;
}
.toc-link.level-3 { padding-left: 24px; font-size: 12px; }

/* ─── Search results ──────────────────────────────────────────────────── */
.search-results {
  position: fixed; top: calc(var(--topbar-h) + 8px);
  left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: 200;
  max-height: 440px; overflow-y: auto;
}
.search-result {
  display: block; padding: 12px 16px;
  color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--border-subtle);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--primary-light); }
.search-result-title { font-weight: 500; font-size: 14px; color: var(--primary); }
.search-result-snippet {
  font-size: 12px; color: var(--text-muted);
  margin-top: 4px; line-height: 1.5;
}
.search-result mark {
  background: var(--primary-lighter); color: var(--primary);
  padding: 1px 3px; border-radius: 2px;
}

/* ─── Loading ─────────────────────────────────────────────────────────── */
.loading {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 400px;
  color: var(--text-muted);
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Pagination ──────────────────────────────────────────────────────── */
.pagination {
  display: flex; justify-content: space-between;
  margin-top: 64px; padding-top: 24px;
  border-top: 1px solid var(--border);
  gap: 16px;
}
.pagination-link {
  text-decoration: none; color: var(--text-muted);
  padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: all 0.15s; max-width: 48%;
  display: block;
}
.pagination-link:hover {
  border-color: var(--primary); color: var(--primary);
  background: var(--primary-light);
}
.pagination-label { font-size: 12px; color: var(--text-subtle); }
.pagination-title { font-size: 14px; font-weight: 500; margin-top: 4px; }
.pagination-next { text-align: right; }

/* ─── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .toc { display: none; }
  .content { max-width: none; padding: 32px 32px 80px; }
  .cover-section { padding: 32px; }
}
@media (max-width: 1024px) {
  .content { padding: 24px 24px 64px; }
  .cover-hero { padding: 48px 24px 48px; }
  .cover-title { font-size: 40px; }
  .cover-stats { grid-template-columns: repeat(2, 1fr); padding: 0 24px; }
  .cover-section { padding: 24px; }
  .topbar-center { display: none; }
}
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }
  .logo-text, .logo-version { display: none; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h);
    z-index: 90; transform: translateX(-100%);
    transition: transform 0.2s;
    width: 260px;
    box-shadow: var(--shadow-xl);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 20px 16px 64px; }
  .content h1 { font-size: 24px; }
  .content h2 { font-size: 18px; }
  .cover-title { font-size: 32px; }
  .cover-subtitle { font-size: 16px; }
  .cover-stats { grid-template-columns: 1fr; }
  .cover-features { grid-template-columns: 1fr; }
  .cover-chapters { grid-template-columns: 1fr; }
  .topbar-link span { display: none; }
  .topbar-inner { padding: 0 12px; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }
