/* ============================================================
   DOCUMENTATION EXPLORER — Premium Design System
   Inspired by: GitBook, VS Code, Notion, Linear, Stripe Docs
   ============================================================ */

/* ── Google Fonts ────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── Design Tokens ───────────────────────────────────────── */
:root {
  /* Core palette */
  --bg-root:        #0a0e14;
  --bg-body:        #0d1117;
  --bg-sidebar:     #0d1117;
  --bg-surface:     #161b22;
  --bg-elevated:    #1c2128;
  --bg-hover:       #1c2128;
  --bg-active:      rgba(124, 58, 237, 0.12);
  --bg-glass:       rgba(22, 27, 34, 0.75);

  /* Borders */
  --border-primary:   #21262d;
  --border-secondary: #30363d;
  --border-accent:    rgba(124, 58, 237, 0.4);

  /* Text */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary:  #6e7681;
  --text-link:      #a78bfa;
  --text-on-accent: #ffffff;

  /* Accent */
  --accent:         #7c3aed;
  --accent-hover:   #8b5cf6;
  --accent-subtle:  rgba(124, 58, 237, 0.15);
  --accent-glow:    rgba(124, 58, 237, 0.25);

  /* Semantic */
  --success:   #3fb950;
  --warning:   #d29922;
  --danger:    #f85149;
  --info:      #58a6ff;

  /* Shadows */
  --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 30px rgba(0,0,0,0.5);
  --shadow-xl:  0 20px 60px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 20px rgba(124, 58, 237, 0.15);

  /* Layout */
  --sidebar-width:     280px;
  --navbar-height:     56px;
  --content-max-width: 860px;
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;

  /* Typography */
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Transitions */
  --transition-fast:   120ms ease;
  --transition-base:   200ms ease;
  --transition-slow:   350ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Light Theme ─────────────────────────────────────────── */
[data-theme="light"] {
  --bg-root:        #f8f9fa;
  --bg-body:        #ffffff;
  --bg-sidebar:     #f6f8fa;
  --bg-surface:     #f0f2f5;
  --bg-elevated:    #e8ebef;
  --bg-hover:       #eaecef;
  --bg-active:      rgba(124, 58, 237, 0.08);
  --bg-glass:       rgba(255, 255, 255, 0.85);

  --border-primary:   #d8dee4;
  --border-secondary: #d0d7de;
  --border-accent:    rgba(124, 58, 237, 0.3);

  --text-primary:   #1f2328;
  --text-secondary: #656d76;
  --text-tertiary:  #8c959f;
  --text-link:      #7c3aed;
  --text-on-accent: #ffffff;

  --accent:         #7c3aed;
  --accent-hover:   #6d28d9;
  --accent-subtle:  rgba(124, 58, 237, 0.08);
  --accent-glow:    rgba(124, 58, 237, 0.12);

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.12);
  --shadow-xl:  0 16px 48px rgba(0,0,0,0.15);
  --shadow-glow: 0 0 20px rgba(124, 58, 237, 0.08);
}

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

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

body {
  font-family: var(--font-sans);
  background: var(--bg-root);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
}

::selection {
  background: var(--accent);
  color: var(--text-on-accent);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ── Reading Progress Bar ────────────────────────────────── */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover), #c084fc);
  z-index: 9999;
  transition: width 60ms linear;
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ── App Layout ──────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top Navbar ──────────────────────────────────────────── */
#navbar {
  height: var(--navbar-height);
  background: var(--bg-glass);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 100;
  flex-shrink: 0;
  position: relative;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  line-height: 1;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #c084fc);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-glow);
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.logo-text span {
  color: var(--text-tertiary);
  font-weight: 400;
  margin-left: 3px;
  font-size: 13px;
}

/* Search trigger */
.search-trigger {
  flex: 1;
  max-width: 480px;
  min-width: 180px;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  color: var(--text-tertiary);
  font-size: 13px;
  font-family: var(--font-sans);
}

.search-trigger:hover {
  border-color: var(--border-secondary);
  background: var(--bg-elevated);
}

.search-trigger svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.6;
}

.search-trigger .search-placeholder {
  flex: 1;
  text-align: left;
}

.search-trigger kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border-secondary);
  border-radius: 4px;
  color: var(--text-tertiary);
  line-height: 1.3;
  flex-shrink: 0;
}

/* Navbar right */
.navbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-btn svg {
  width: 18px;
  height: 18px;
}

.nav-btn .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--bg-body);
}

/* ── Main Layout (sidebar + content) ─────────────────────── */
#main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition-slow), width var(--transition-slow), min-width var(--transition-slow);
  z-index: 50;
  flex-shrink: 0;
}

/* Sidebar header with actions */
.sidebar-header {
  padding: 12px 12px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-tertiary);
}

.sidebar-actions {
  display: flex;
  gap: 2px;
}

.sidebar-action-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sidebar-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-action-btn svg {
  width: 14px;
  height: 14px;
}

/* Sidebar sections (Recent, Favorites, Explorer) */
.sidebar-section {
  flex-shrink: 0;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  cursor: pointer;
  user-select: none;
}

.sidebar-section-header:hover .sidebar-section-title {
  color: var(--text-secondary);
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  transition: color var(--transition-fast);
}

.sidebar-section-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  transition: transform var(--transition-base);
}

.sidebar-section.collapsed .sidebar-section-chevron {
  transform: rotate(-90deg);
}

.sidebar-section.collapsed .sidebar-section-body {
  display: none;
}

.sidebar-section-body {
  padding: 0 8px 6px;
}

/* Recent / Favorite items */
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-item .item-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.6;
}

.sidebar-item .item-remove {
  width: 16px;
  height: 16px;
  margin-left: auto;
  opacity: 0;
  color: var(--text-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition-fast);
}

.sidebar-item:hover .item-remove {
  opacity: 1;
}

.sidebar-item .item-remove:hover {
  color: var(--danger);
}

.sidebar-empty {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
}

/* Sidebar divider */
.sidebar-divider {
  height: 1px;
  background: var(--border-primary);
  margin: 4px 12px;
}

/* File Explorer tree */
#file-explorer {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
}

.tree-node {
  user-select: none;
}

.tree-row {
  display: flex;
  align-items: center;
  height: 30px;
  padding: 0 8px 0 0;
  cursor: pointer;
  transition: all var(--transition-fast);
  border-radius: 0;
  position: relative;
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 13px;
}

.tree-row:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tree-row.active {
  background: var(--bg-active);
  color: var(--accent-hover);
}

.tree-row.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.tree-indent {
  flex-shrink: 0;
}

.tree-chevron {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--transition-base);
}

.tree-chevron svg {
  width: 12px;
  height: 12px;
  opacity: 0.5;
}

.tree-chevron.expanded svg {
  transform: rotate(90deg);
}

.tree-chevron.hidden {
  visibility: hidden;
}

.tree-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 6px;
}

.tree-icon svg {
  width: 15px;
  height: 15px;
}

.tree-icon.folder { color: #e8a838; }
.tree-icon.folder.open { color: #e8a838; }
.tree-icon.file { color: var(--text-tertiary); }
.tree-icon.file-md { color: var(--text-tertiary); }
.tree-icon.file-md svg { opacity: 0.7; }

.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-children {
  overflow: hidden;
  transition: max-height var(--transition-slow);
}

.tree-children.collapsed {
  max-height: 0 !important;
}

/* ── Sidebar Resize Handle ───────────────────────────────── */
.sidebar-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 60;
  transition: background var(--transition-fast);
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.active {
  background: var(--accent);
}

/* ── Content Area ────────────────────────────────────────── */
#content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-body);
  min-width: 0;
}

/* Content header (breadcrumbs + actions) */
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
  gap: 12px;
  min-height: 42px;
  background: var(--bg-body);
}

/* Breadcrumbs */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-tertiary);
  overflow: hidden;
  flex: 1;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--transition-fast);
  color: var(--text-tertiary);
  background: none;
  border: none;
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
}

.breadcrumb-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.breadcrumb-item.current {
  color: var(--text-secondary);
  cursor: default;
}

.breadcrumb-item.current:hover {
  background: none;
}

.breadcrumb-sep {
  color: var(--text-tertiary);
  font-size: 11px;
  opacity: 0.5;
}

/* Content actions */
.content-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.content-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-sans);
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.content-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.content-action-btn svg {
  width: 14px;
  height: 14px;
}

.content-action-btn.active {
  color: var(--accent);
}

.reading-time-badge {
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-surface);
  border-radius: 100px;
  white-space: nowrap;
}

.reading-time-badge svg {
  width: 12px;
  height: 12px;
}

/* ── Markdown Content ────────────────────────────────────── */
#content-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

#markdown-body {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 32px 40px 80px;
  animation: fadeInContent 0.3s ease;
}

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

/* ── Markdown Typography ─────────────────────────────────── */
#markdown-body h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-primary);
  color: var(--text-primary);
  line-height: 1.3;
}

#markdown-body h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin: 40px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-primary);
  color: var(--text-primary);
  line-height: 1.3;
}

#markdown-body h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 32px 0 8px;
  color: var(--text-primary);
  line-height: 1.4;
}

#markdown-body h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text-primary);
}

#markdown-body h5, #markdown-body h6 {
  font-size: 1rem;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--text-secondary);
}

#markdown-body p {
  margin: 0 0 16px;
  line-height: 1.7;
  color: var(--text-primary);
}

#markdown-body a {
  color: var(--text-link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all var(--transition-fast);
}

#markdown-body a:hover {
  border-bottom-color: var(--text-link);
}

#markdown-body strong {
  font-weight: 600;
  color: var(--text-primary);
}

#markdown-body em {
  font-style: italic;
}

/* Lists */
#markdown-body ul, #markdown-body ol {
  margin: 0 0 16px;
  padding-left: 24px;
}

#markdown-body li {
  margin: 4px 0;
  line-height: 1.7;
  color: var(--text-primary);
}

#markdown-body li::marker {
  color: var(--text-tertiary);
}

/* Task lists */
#markdown-body ul.contains-task-list {
  list-style: none;
  padding-left: 0;
}

#markdown-body .task-list-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 2px 0;
}

#markdown-body .task-list-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-secondary);
  border-radius: 4px;
  margin-top: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  position: relative;
}

#markdown-body .task-list-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

#markdown-body .task-list-item input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 10px;
  font-weight: 700;
}

/* Blockquotes */
#markdown-body blockquote {
  margin: 0 0 16px;
  padding: 12px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-subtle);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-secondary);
}

#markdown-body blockquote p:last-child {
  margin-bottom: 0;
}

/* Code — inline */
#markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  padding: 2px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  color: var(--text-link);
  word-break: break-word;
}

/* Code — blocks */
#markdown-body pre {
  margin: 0 0 16px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-root);
  border: 1px solid var(--border-primary);
  position: relative;
  group: code-block;
}

#markdown-body pre code {
  display: block;
  padding: 16px 20px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text-primary);
  tab-size: 4;
}

/* Copy button on code blocks */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition-fast);
  z-index: 5;
}

#markdown-body pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.code-copy-btn.copied {
  color: var(--success);
}

/* Code block language badge */
.code-lang-badge {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

#markdown-body pre:hover .code-lang-badge {
  opacity: 1;
}

/* Tables */
#markdown-body table {
  width: 100%;
  margin: 0 0 16px;
  border-collapse: collapse;
  border-spacing: 0;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-size: 14px;
}

#markdown-body thead {
  background: var(--bg-surface);
}

#markdown-body th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border-primary);
  font-size: 13px;
  white-space: nowrap;
}

#markdown-body td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-primary);
  color: var(--text-primary);
}

#markdown-body tbody tr:last-child td {
  border-bottom: none;
}

#markdown-body tbody tr:hover {
  background: var(--bg-hover);
}

/* Images */
#markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-primary);
  margin: 8px 0;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

#markdown-body img:hover {
  box-shadow: var(--shadow-lg);
}

/* Horizontal rules */
#markdown-body hr {
  margin: 32px 0;
  border: none;
  border-top: 1px solid var(--border-primary);
}

/* Heading anchors */
#markdown-body h1 .heading-anchor,
#markdown-body h2 .heading-anchor,
#markdown-body h3 .heading-anchor,
#markdown-body h4 .heading-anchor {
  opacity: 0;
  color: var(--text-tertiary);
  text-decoration: none;
  margin-left: 8px;
  font-size: 0.8em;
  transition: opacity var(--transition-fast);
}

#markdown-body h1:hover .heading-anchor,
#markdown-body h2:hover .heading-anchor,
#markdown-body h3:hover .heading-anchor,
#markdown-body h4:hover .heading-anchor {
  opacity: 1;
}

/* ── Document Navigation (Prev / Next) ───────────────────── */
.doc-navigation {
  display: flex;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border-primary);
}

.doc-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-base);
  font-family: var(--font-sans);
  text-align: left;
}

.doc-nav-btn:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.doc-nav-btn.next {
  text-align: right;
}

.doc-nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
}

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

/* ── Welcome Screen ──────────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  padding: 40px;
  text-align: center;
  animation: fadeInContent 0.4s ease;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--accent), #c084fc);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: 24px;
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.3);
}

.welcome-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 32px;
  max-width: 400px;
}

.welcome-projects {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 700px;
}

.welcome-project-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: left;
}

.welcome-project-card:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}

.welcome-project-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.welcome-project-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.welcome-project-count {
  font-size: 12px;
  color: var(--text-tertiary);
}

.welcome-hint {
  margin-top: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-tertiary);
  padding: 8px 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
}

.welcome-hint kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-secondary);
  border-radius: 4px;
  color: var(--text-secondary);
}

/* ── Command Palette (Search Modal) ──────────────────────── */
.command-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: min(20vh, 160px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.command-palette-overlay.open {
  opacity: 1;
  visibility: visible;
}

.command-palette {
  width: 560px;
  max-width: 90vw;
  max-height: 480px;
  background: var(--bg-surface);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.96) translateY(-8px);
  transition: transform var(--transition-base);
}

.command-palette-overlay.open .command-palette {
  transform: scale(1) translateY(0);
}

.command-palette-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-primary);
}

.command-palette-input-wrap svg {
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.command-palette-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text-primary);
}

.command-palette-input::placeholder {
  color: var(--text-tertiary);
}

.command-palette-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.command-palette-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
}

.command-palette-group-title {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
}

.command-palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.command-palette-item:hover,
.command-palette-item.selected {
  background: var(--bg-active);
}

.command-palette-item-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
  font-size: 14px;
}

.command-palette-item-text {
  flex: 1;
  min-width: 0;
}

.command-palette-item-name {
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.command-palette-item-name mark {
  background: var(--accent-subtle);
  color: var(--accent-hover);
  border-radius: 2px;
  padding: 0 1px;
}

.command-palette-item-path {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.command-palette-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.command-palette-footer kbd {
  font-family: var(--font-sans);
  font-size: 10px;
  padding: 1px 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-secondary);
  border-radius: 3px;
  margin: 0 2px;
}

/* ── Toast Notifications ─────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--text-primary);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}

.toast.leaving {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(12px) scale(0.96); }
}

.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toast-icon svg {
  width: 100%;
  height: 100%;
}

/* ── Mobile Overlay ──────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar-toggle {
    display: flex;
  }

  #sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
    background: var(--bg-body);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .sidebar-resize-handle {
    display: none;
  }

  #markdown-body {
    padding: 24px 20px 60px;
  }

  .content-header {
    padding: 8px 16px;
  }

  .welcome-projects {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .logo-text span {
    display: none;
  }

  .search-trigger {
    min-width: 120px;
  }

  .search-trigger .search-placeholder {
    display: none;
  }

  .content-actions .content-action-text {
    display: none;
  }

  .doc-navigation {
    flex-direction: column;
  }

  .doc-nav-btn.next {
    text-align: left;
  }

  #markdown-body {
    padding: 20px 16px 60px;
  }

  #markdown-body h1 { font-size: 1.5rem; }
  #markdown-body h2 { font-size: 1.25rem; }
  #markdown-body h3 { font-size: 1.1rem; }

  #markdown-body pre code {
    font-size: 12px;
    padding: 12px 14px;
  }
}

/* ── Loading State ───────────────────────────────────────── */
.loading-skeleton {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.15; }
}

.skeleton-line {
  height: 16px;
  background: var(--bg-surface);
  border-radius: 4px;
  margin-bottom: 12px;
}

.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 70%; }
.skeleton-line.long { width: 90%; }
.skeleton-line.title { height: 28px; width: 55%; margin-bottom: 20px; }

/* ── Mermaid diagram containers ──────────────────────────── */
.mermaid {
  display: flex;
  justify-content: center;
  padding: 20px;
  margin: 16px 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ── Print styles ────────────────────────────────────────── */
@media print {
  #navbar, #sidebar, .sidebar-overlay,
  .content-actions, .doc-navigation,
  #reading-progress, .command-palette-overlay,
  .toast-container {
    display: none !important;
  }

  #content-area {
    overflow: visible !important;
  }

  #markdown-body {
    max-width: none;
    padding: 0;
  }
}
