/* ============================================
   DocView - Modern Documentation Site Styles
   ============================================ */

/* CSS Variables */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fc;
  --bg-tertiary: #f0f2f7;
  --bg-sidebar: #fafbfe;
  --bg-code: #f4f5f9;
  --bg-code-block: #1e1e2e;
  --bg-hover: rgba(99, 102, 241, 0.06);
  --bg-active: rgba(99, 102, 241, 0.1);
  --bg-overlay: rgba(0, 0, 0, 0.4);

  --text-primary: #1a1a2e;
  --text-secondary: #4a4a6a;
  --text-tertiary: #8888a8;
  --text-code: #e06c75;
  --text-link: #6366f1;
  --text-link-hover: #4f46e5;

  --border-primary: #e8e9f0;
  --border-secondary: #f0f1f5;
  --border-focus: #6366f1;

  --accent: #6366f1;
  --accent-light: rgba(99, 102, 241, 0.12);
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --sidebar-width: 280px;
  --toc-width: 220px;
  --nav-height: 56px;

  --font-sans: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #161625;
  --bg-tertiary: #1c1c30;
  --bg-sidebar: #12121f;
  --bg-code: #1c1c30;
  --bg-code-block: #0a0a14;
  --bg-hover: rgba(99, 102, 241, 0.1);
  --bg-active: rgba(99, 102, 241, 0.15);
  --bg-overlay: rgba(0, 0, 0, 0.6);

  --text-primary: #e4e4f0;
  --text-secondary: #a0a0c0;
  --text-tertiary: #6a6a8a;
  --text-code: #f78c6c;
  --text-link: #818cf8;
  --text-link-hover: #a5b4fc;

  --border-primary: #2a2a40;
  --border-secondary: #222238;
  --border-focus: #818cf8;

  --accent: #818cf8;
  --accent-light: rgba(129, 140, 248, 0.15);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  overflow: hidden;
  height: 100vh;
  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); }

/* ---- Top Navigation ---- */
.top-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-height);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-primary);
  backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
  overflow: hidden;
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.nav-center { flex: 1; max-width: 480px; margin: 0 24px; min-width: 0; overflow: hidden; }

.sidebar-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: all var(--transition);
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text-primary); }
.logo-icon { display: flex; color: var(--accent); }
.logo-text { background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

/* Search Box */
.search-box {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 38px;
  background: var(--bg-secondary); border: 1px solid var(--border-primary);
  border-radius: var(--radius-md); transition: all var(--transition);
}
.search-box:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-light); background: var(--bg-primary); }
.search-icon { color: var(--text-tertiary); flex-shrink: 0; }
#searchInput {
  flex: 1; border: none; outline: none; background: transparent;
  font-family: var(--font-sans); font-size: 0.875rem; color: var(--text-primary);
  min-width: 0;
}
#searchInput::placeholder { color: var(--text-tertiary); }
.search-shortcut {
  display: inline-flex; align-items: center;
  padding: 2px 6px; font-size: 0.7rem; font-family: var(--font-sans);
  background: var(--bg-tertiary); border: 1px solid var(--border-primary);
  border-radius: 4px; color: var(--text-tertiary); white-space: nowrap;
}

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

/* ---- Search Overlay ---- */
.search-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg-overlay); backdrop-filter: blur(4px);
  display: none; align-items: flex-start; justify-content: center;
  padding-top: 80px;
  animation: fadeIn 0.15s ease;
}
.search-overlay.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.search-results-panel {
  width: 90%; max-width: 600px; max-height: 70vh;
  background: var(--bg-primary); border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; display: flex; flex-direction: column;
  animation: slideDown 0.2s ease;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.search-results-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border-primary);
}
.search-results-header h3 { font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); }
.close-search {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-tertiary); cursor: pointer;
  transition: all var(--transition);
}
.close-search:hover { background: var(--bg-hover); color: var(--text-primary); }

.search-results-list { overflow-y: auto; padding: 8px; }
.search-result-item {
  display: block; padding: 12px 16px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition); border: none; background: none;
  width: 100%; text-align: left; color: var(--text-primary);
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .result-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.search-result-item .result-path { font-size: 0.75rem; color: var(--text-tertiary); margin-bottom: 4px; }
.search-result-item .result-excerpt { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.5; }
.search-no-results { padding: 40px 20px; text-align: center; color: var(--text-tertiary); font-size: 0.9rem; }

/* ---- App Layout ---- */
.app-layout {
  display: flex; margin-top: var(--nav-height); height: calc(100vh - var(--nav-height));
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width); flex-shrink: 0;
  background: var(--bg-sidebar); border-right: 1px solid var(--border-primary);
  overflow-y: auto; overflow-x: hidden;
  transition: width var(--transition), background var(--transition), border-color var(--transition);
  scrollbar-width: thin; scrollbar-color: var(--border-primary) transparent;
}
.sidebar.collapsed { width: 0; border-right: none; }
.sidebar-nav { padding: 16px 12px; }

/* Skeleton Loading */
.sidebar-loading { display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.skeleton-line {
  height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
}
.skeleton-line.short { width: 60%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Tree Items */
.tree-item { user-select: none; }
.tree-dir-header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.85rem; font-weight: 500;
  color: var(--text-secondary); transition: all var(--transition);
  border: none; background: none; width: 100%; text-align: left;
}
.tree-dir-header:hover { background: var(--bg-hover); color: var(--text-primary); }
.tree-dir-header .dir-icon {
  display: flex; flex-shrink: 0; transition: transform var(--transition);
}
.tree-dir-header.expanded .dir-icon { transform: rotate(90deg); }
.tree-dir-header .folder-icon { display: flex; flex-shrink: 0; color: var(--accent); }
.tree-dir-children { padding-left: 16px; overflow: hidden; }
.tree-dir-children.collapsed { display: none; }

.tree-file-link {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 14px; border-radius: var(--radius-sm);
  font-size: 0.84rem; color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition);
  text-decoration: none;
}
.tree-file-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.tree-file-link.active { background: var(--accent-light); color: var(--accent); font-weight: 500; }
.tree-file-link .file-icon { display: flex; flex-shrink: 0; opacity: 0.6; }
.tree-file-link.active .file-icon { opacity: 1; }

/* ---- Main Content ---- */
.main-content {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 0; min-width: 0;
  scroll-behavior: smooth;
}

/* Welcome Screen */
.welcome-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; padding: 40px; text-align: center;
  animation: fadeIn 0.5s ease;
}
.welcome-icon { color: var(--accent); opacity: 0.4; margin-bottom: 24px; }
.welcome-screen h1 {
  font-size: 1.8rem; font-weight: 700; margin-bottom: 12px;
  background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.welcome-screen p { color: var(--text-secondary); font-size: 1rem; max-width: 400px; line-height: 1.8; margin-bottom: 32px; }
.welcome-shortcuts { display: flex; gap: 32px; }
.shortcut-item { display: flex; align-items: center; gap: 8px; color: var(--text-tertiary); font-size: 0.85rem; }
.shortcut-item kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 26px; padding: 0 6px;
  font-family: var(--font-sans); font-size: 0.75rem;
  background: var(--bg-secondary); border: 1px solid var(--border-primary);
  border-radius: 5px; color: var(--text-secondary);
}

/* Document View */
.doc-view { max-width: 820px; margin: 0 auto; padding: 32px 48px 80px; animation: fadeIn 0.3s ease; }
.doc-breadcrumb {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-bottom: 24px; font-size: 0.8rem; color: var(--text-tertiary);
}
.doc-breadcrumb .crumb { transition: color var(--transition); }
.doc-breadcrumb .crumb:hover { color: var(--accent); }
.doc-breadcrumb .sep { opacity: 0.5; }

/* ---- Markdown Body ---- */
.doc-body { font-size: 0.95rem; line-height: 1.85; }
.doc-body h1 { font-size: 2rem; font-weight: 700; margin: 0 0 16px; padding-bottom: 12px; border-bottom: 2px solid var(--border-primary); }
.doc-body h2 { font-size: 1.5rem; font-weight: 600; margin: 48px 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border-secondary); }
.doc-body h3 { font-size: 1.2rem; font-weight: 600; margin: 36px 0 12px; }
.doc-body h4 { font-size: 1.05rem; font-weight: 600; margin: 28px 0 8px; }
.doc-body h1, .doc-body h2, .doc-body h3, .doc-body h4 { color: var(--text-primary); scroll-margin-top: calc(var(--nav-height) + 20px); }

.doc-body p { margin: 0 0 16px; color: var(--text-secondary); }
.doc-body strong { color: var(--text-primary); font-weight: 600; }
.doc-body ul, .doc-body ol { padding-left: 24px; margin: 0 0 16px; }
.doc-body li { margin: 4px 0; color: var(--text-secondary); }
.doc-body li::marker { color: var(--accent); }

.doc-body a { color: var(--text-link); text-decoration: underline; text-decoration-color: rgba(99,102,241,0.3); text-underline-offset: 3px; transition: all var(--transition); }
.doc-body a:hover { text-decoration-color: var(--text-link); }

.doc-body blockquote {
  margin: 0 0 16px; padding: 12px 20px;
  border-left: 3px solid var(--accent); background: var(--accent-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}
.doc-body blockquote p { margin-bottom: 0; }

.doc-body code {
  font-family: var(--font-mono); font-size: 0.85em;
  background: var(--bg-code); color: var(--text-code);
  padding: 2px 6px; border-radius: 4px;
}
.doc-body pre {
  margin: 0 0 20px; padding: 20px 24px;
  background: var(--bg-code-block); border-radius: var(--radius-md);
  overflow-x: auto; position: relative;
}
.doc-body pre code {
  background: transparent; color: #c9d1d9;
  padding: 0; font-size: 0.85rem; line-height: 1.6;
}

.doc-body table {
  width: 100%; border-collapse: collapse; margin: 0 0 20px;
  font-size: 0.9rem;
}
.doc-body thead th {
  text-align: left; padding: 10px 16px; font-weight: 600;
  background: var(--bg-tertiary); border-bottom: 2px solid var(--border-primary);
  color: var(--text-primary);
}
.doc-body tbody td {
  padding: 10px 16px; border-bottom: 1px solid var(--border-secondary);
  color: var(--text-secondary);
}
.doc-body tbody tr:hover { background: var(--bg-hover); }

.doc-body hr { border: none; height: 1px; background: var(--border-primary); margin: 32px 0; }
.doc-body img { max-width: 100%; border-radius: var(--radius-md); margin: 16px 0; }

/* Task list styling */
.doc-body ul li input[type="checkbox"] { margin-right: 8px; accent-color: var(--accent); }

/* ---- TOC Sidebar ---- */
.toc-sidebar {
  width: var(--toc-width); flex-shrink: 0;
  border-left: 1px solid var(--border-primary);
  overflow-y: auto; padding: 20px 16px;
  transition: all var(--transition);
}
.toc-header h4 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); margin-bottom: 12px; }
.toc-nav { display: flex; flex-direction: column; gap: 2px; }
.toc-link {
  display: block; font-size: 0.8rem; color: var(--text-tertiary);
  padding: 4px 12px; border-left: 2px solid transparent;
  text-decoration: none; transition: all var(--transition);
  line-height: 1.5; word-break: break-word;
}
.toc-link:hover { color: var(--text-primary); }
.toc-link.active { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.toc-link.toc-h3 { padding-left: 24px; font-size: 0.78rem; }
.toc-link.toc-h4 { padding-left: 36px; font-size: 0.76rem; }

/* ---- Mobile Overlay ---- */
.sidebar-overlay {
  position: fixed; inset: 0; z-index: 49;
  background: var(--bg-overlay); backdrop-filter: blur(4px);
  display: none; animation: fadeIn 0.2s ease;
}
.sidebar-overlay.active { display: block; }

/* ---- Scrollbar ---- */
.main-content::-webkit-scrollbar, .sidebar::-webkit-scrollbar, .toc-sidebar::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-track, .sidebar::-webkit-scrollbar-track, .toc-sidebar::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb, .toc-sidebar::-webkit-scrollbar-thumb { background: var(--border-primary); border-radius: 3px; }
.main-content::-webkit-scrollbar-thumb:hover, .sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }



/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .toc-sidebar { display: none; }
}
@media (max-width: 768px) {
  /* Nav adjustments */
  .top-nav { padding: 0 10px; height: 50px; }
  .nav-left { gap: 8px; }
  .nav-center { margin: 0 8px; min-width: 0; flex: 1; }
  .search-shortcut { display: none; }
  .search-box { height: 34px; padding: 0 10px; min-width: 0; }
  #searchInput { font-size: 0.82rem; min-width: 0; }
  .logo-text { font-size: 0.95rem; }

  /* Sidebar */
  .sidebar {
    position: fixed; left: 0; top: 50px; bottom: 0; z-index: 50;
    width: 280px; transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.15); }
  .sidebar.collapsed { transform: translateX(-100%); }

  /* Increase touch targets */
  .tree-dir-header { padding: 10px 12px; font-size: 0.9rem; min-height: 42px; }
  .tree-file-link { padding: 10px 12px 10px 18px; font-size: 0.88rem; min-height: 42px; }

  /* Main content */
  .app-layout { height: calc(100vh - 50px); margin-top: 50px; }
  .doc-view { padding: 20px 18px 40px; }
  .doc-body h1 { font-size: 1.6rem; }
  .doc-body h2 { font-size: 1.3rem; margin: 36px 0 12px; }
  .doc-body h3 { font-size: 1.1rem; margin: 28px 0 10px; }
  .doc-body pre { padding: 14px 16px; border-radius: var(--radius-sm); font-size: 0.8rem; }
  .doc-body pre code { font-size: 0.78rem; white-space: pre; word-break: normal; }
  .doc-body table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .doc-body thead th, .doc-body tbody td { padding: 8px 12px; white-space: nowrap; }
  .doc-body code { font-size: 0.8em; }

  /* Welcome screen */
  .welcome-screen { padding: 32px 24px; }
  .welcome-screen h1 { font-size: 1.4rem; }
  .welcome-screen p { font-size: 0.9rem; }
  .welcome-icon svg { width: 56px; height: 56px; }
  .welcome-shortcuts { flex-direction: column; gap: 12px; }

  /* Search overlay mobile */
  .search-overlay { padding-top: 60px; }
  .search-results-panel { width: 95%; max-height: 75vh; border-radius: var(--radius-md); }
}

@media (max-width: 380px) {
  .logo-text { display: none; }
  .nav-center { margin: 0 6px; }
  .top-nav { padding: 0 8px; }
}
