/* ========== Docs Layout ========== */
.docs-layout {
  display: flex;
  margin-top: 66px; /* nav height (64px) + scroll progress (2px) */
  min-height: calc(100vh - 66px);
}

/* ========== Sidebar ========== */
.sidebar {
  width: 260px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  padding: 24px 0;
  position: fixed;
  top: 66px;
  bottom: 0;
  overflow-y: auto;
  background: var(--bg);
  z-index: 10;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Sidebar search button */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 32px);
  margin: 0 16px 12px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.sidebar-search:hover {
  border-color: rgba(212, 160, 23, 0.3);
  color: var(--text-dim);
}

.sidebar-search svg { flex-shrink: 0; }

.sidebar-search kbd {
  margin-left: auto;
  font-size: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--mono);
}

.sidebar-group { margin-bottom: 8px; padding-bottom: 8px; }
.sidebar-group + .sidebar-group {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.sidebar-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 20px;
  margin-bottom: 6px;
  transition: color 0.2s;
}

.sidebar-group-title.active-group {
  color: var(--accent);
}

.sidebar a {
  display: block;
  padding: 6px 20px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: all 0.15s;
}

.sidebar a:hover {
  color: var(--text);
  background: var(--bg-card);
}

.sidebar a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: inset 3px 0 8px -3px rgba(212, 160, 23, 0.2);
}

/* ========== Content Area ========== */
.docs-content {
  flex: 1;
  margin-left: 260px;
  padding: 40px 48px 80px;
  max-width: 860px;
  min-height: calc(100vh - 66px);
}

/* Content fade-in transition */
.docs-content.loading { opacity: 0.3; transition: opacity 0.15s; }
.docs-content.loaded { opacity: 1; transition: opacity 0.3s ease-out; }

/* Stagger fade-in for headings and code blocks */
.docs-content.loaded h2,
.docs-content.loaded pre {
  animation: contentFadeIn 0.4s ease-out both;
}

.docs-content.loaded h2:nth-of-type(1) { animation-delay: 0.05s; }
.docs-content.loaded h2:nth-of-type(2) { animation-delay: 0.1s; }
.docs-content.loaded h2:nth-of-type(3) { animation-delay: 0.15s; }
.docs-content.loaded h2:nth-of-type(4) { animation-delay: 0.2s; }
.docs-content.loaded h2:nth-of-type(5) { animation-delay: 0.25s; }

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

/* ========== Nav Search Button ========== */
.nav-search-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.nav-search-btn:hover {
  border-color: rgba(212, 160, 23, 0.3);
  color: var(--text-dim);
}

.nav-search-btn svg { flex-shrink: 0; }

.nav-search-btn kbd {
  font-size: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--mono);
}

@media (max-width: 768px) {
  .nav-search-btn .nav-search-label,
  .nav-search-btn kbd { display: none; }
  .nav-search-btn { padding: 5px 8px; }
}

/* ========== Breadcrumb ========== */
.docs-breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
  letter-spacing: 0.02em;
}

.docs-breadcrumb .bc-sep {
  margin: 0 4px;
  color: var(--border);
}

/* ========== Markdown Rendering ========== */
.docs-content h1 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.docs-content h2 {
  font-size: 22px;
  font-weight: 700;
  margin-top: 40px;
  margin-bottom: 12px;
  color: var(--text);
  border-bottom: 1px solid rgba(212, 160, 23, 0.2);
  padding-bottom: 8px;
  scroll-margin-top: 80px;
  position: relative;
}

.docs-content h3 .heading-anchor,
.docs-content h2 .heading-anchor {
  color: var(--text-muted);
  text-decoration: none;
  margin-left: 6px;
  opacity: 0;
  transition: opacity 0.2s;
  font-weight: 400;
}

.docs-content h2:hover .heading-anchor,
.docs-content h3:hover .heading-anchor {
  opacity: 0.6;
}

.docs-content h2 .heading-anchor:hover,
.docs-content h3 .heading-anchor:hover {
  opacity: 1;
  color: var(--accent);
}

.docs-content h3 {
  font-size: 17px;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 8px;
  color: var(--text);
  scroll-margin-top: 80px;
}

.docs-content h4 {
  font-size: 14px;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 6px;
  color: var(--text-dim);
}

.docs-content p {
  margin-bottom: 14px;
  color: var(--text-dim);
  font-size: 15px;
}

.docs-content a { color: var(--accent); text-decoration: none; }
.docs-content a:hover { text-decoration: underline; }

.docs-content ul, .docs-content ol {
  margin-bottom: 14px;
  padding-left: 24px;
  color: var(--text-dim);
  font-size: 15px;
}

.docs-content li { margin-bottom: 4px; }
.docs-content strong { color: var(--text); }

.docs-content code {
  font-family: var(--mono);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--accent);
}

.docs-content pre {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
  position: relative;
  transition: border-color 0.3s;
}

.docs-content pre:hover {
  border-color: rgba(212, 160, 23, 0.25);
}

/* Code block header (language label + copy button) */
.code-block-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  font-size: 11px;
  font-family: var(--font);
  z-index: 2;
}

.code-lang {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.code-copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 2px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font);
  transition: all 0.2s;
  opacity: 0;
}

.docs-content pre:hover .code-copy-btn { opacity: 1; }

.code-copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(212, 160, 23, 0.08);
}

.code-copy-btn.copied {
  color: var(--green);
  border-color: var(--green);
  opacity: 1;
}

/* Code block with header needs top padding for the label */
.docs-content pre.has-header {
  padding-top: 32px;
}

.docs-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* highlight.js override — keep code block text readable */
.docs-content pre code.hljs {
  background: none;
  padding: 0;
}

.docs-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin-bottom: 14px;
  background: var(--accent-glow);
  border-radius: 0 6px 6px 0;
}

.docs-content blockquote p { margin-bottom: 0; }
.docs-content blockquote code { color: var(--text); background: rgba(255, 255, 255, 0.08); }

.docs-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 14px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.docs-content th {
  background: var(--bg-card);
  color: var(--text);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--accent);
}

.docs-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.docs-content tr:nth-child(even) td { background: rgba(255, 255, 255, 0.015); }
.docs-content tr:hover td { background: rgba(255, 255, 255, 0.04); }

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

.docs-content img {
  max-width: 100%;
  border-radius: 8px;
}

/* ========== Mobile Menu Button (hidden on desktop) ========== */
.docs-mobile-menu { display: none; }

/* ========== TOC (Table of Contents) ========== */
.docs-toc {
  position: fixed;
  top: 82px;
  right: max(16px, calc((100vw - 1400px) / 2));
  width: 200px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 12px;
  z-index: 10;
}

.docs-toc::-webkit-scrollbar { width: 2px; }
.docs-toc::-webkit-scrollbar-thumb { background: var(--border); }

.docs-toc-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.docs-toc a {
  display: block;
  padding: 3px 0 3px 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 1px solid var(--border);
  transition: all 0.15s;
  line-height: 1.5;
}

.docs-toc a:hover {
  color: var(--text-dim);
  border-left-color: var(--text-dim);
}

.docs-toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  border-left-width: 2px;
  font-weight: 600;
  background: var(--accent-glow);
  border-radius: 0 4px 4px 0;
  padding-left: 11px; /* compensate for 2px border */
}

.docs-toc a.toc-h3 { padding-left: 24px; }
.docs-toc a.toc-h3.active { padding-left: 23px; }

/* TOC progress indicator */
.docs-toc-progress {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 12px;
  padding-left: 12px;
  opacity: 0.7;
}

/* ========== Doc Navigation (prev/next) ========== */
.doc-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.doc-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.3s;
  max-width: 45%;
}

.doc-nav a:hover {
  border-color: rgba(212, 160, 23, 0.35);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.doc-nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

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

.doc-nav-group {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.doc-nav-group.cross-group {
  color: var(--accent);
  opacity: 1;
}

.doc-nav .next { margin-left: auto; text-align: right; }

/* ========== Loading Placeholder ========== */
.docs-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 0;
}

.docs-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Back to Top ========== */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

/* ========== Error Message ========== */
.docs-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 16px 20px;
  color: #fca5a5;
  font-size: 14px;
}

.docs-error code {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.15);
}

/* ========== Mobile Sidebar ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 49;
  opacity: 0;
  transition: opacity 0.3s;
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

/* ========== Responsive ========== */
@media (max-width: 1200px) {
  .docs-toc { display: none; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
    z-index: 50;
    width: 280px;
    min-width: 280px;
  }

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

  .docs-content {
    margin-left: 0;
    padding: 24px 24px 80px;
    max-width: 100%;
    overflow-x: hidden;
    overflow-wrap: break-word;
    word-wrap: break-word;
  }

  .docs-content h1 { font-size: 26px; }
  .docs-content h2 { font-size: 19px; margin-top: 32px; }
  .docs-content h3 { font-size: 15px; margin-top: 24px; }

  .docs-content pre {
    padding: 14px 12px;
    border-radius: 8px;
    font-size: 12px;
    border: 1px solid rgba(255,255,255,0.08);
  }
  .docs-content pre.has-header { padding-top: 28px; }
  .docs-content pre code { font-size: 12px; }

  .docs-content table { font-size: 12px; display: block; overflow-x: auto; }
  .docs-content th, .docs-content td { padding: 6px 8px; }

  .docs-content blockquote { padding: 6px 12px; }

  .doc-nav { flex-direction: column; }
  .doc-nav a { max-width: 100%; padding: 14px 20px; }

  .code-block-header { font-size: 10px; padding: 3px 8px; }
  .code-copy-btn { opacity: 1; font-size: 10px; padding: 2px 8px; }

  /* Mobile sidebar toggle hint */
  .docs-mobile-menu {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    top: 72px;
    left: 16px;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
    z-index: 40;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  .docs-mobile-menu:hover {
    border-color: rgba(212, 160, 23, 0.3);
    color: var(--text);
  }
  .docs-mobile-menu svg { flex-shrink: 0; }
  .docs-mobile-menu::after {
    content: ' ▸';
    font-size: 0.8em;
    transition: transform 0.2s;
  }

  .docs-content { padding-top: 56px; }
}

/* ========== Responsive: Mobile (480px) ========== */
@media (max-width: 480px) {
  .docs-content {
    padding: 56px 20px 60px;
  }

  .docs-content h1 { font-size: 22px; }
  .docs-content h2 { font-size: 17px; margin-top: 28px; }
  .docs-content h3 { font-size: 14px; }
  .docs-content p { font-size: 14px; }
  .docs-content ul, .docs-content ol { font-size: 14px; }

  .docs-content pre {
    padding: 10px 8px;
    border-radius: 4px;
  }
  .docs-content pre code { font-size: 11px; line-height: 1.5; }

  .docs-content code { font-size: 12px; }

  .docs-content table { font-size: 11px; display: block; overflow-x: auto; }
  .docs-content th, .docs-content td { padding: 5px 6px; }

  .sidebar { width: 260px; min-width: 260px; }

  .search-overlay.visible { padding-top: 10vh; }
  .search-modal { border-radius: 8px; }
  .search-input { font-size: 14px; }
  .search-footer { display: none; }

  .back-to-top { width: 36px; height: 36px; bottom: 16px; right: 16px; }
}

/* ========== Search Modal (Cmd+K) ========== */
.search-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  backdrop-filter: blur(4px);
}

.search-overlay.visible { display: flex; align-items: flex-start; justify-content: center; padding-top: 20vh; }

.search-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 520px;
  max-width: 90vw;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

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

.search-input-wrap svg { color: var(--text-muted); flex-shrink: 0; }

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

.search-input::placeholder { color: var(--text-muted); }

.search-kbd {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
}

.search-results {
  max-height: 340px;
  overflow-y: auto;
  padding: 6px;
}

.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.search-result-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.search-result-item:hover,
.search-result-item.active {
  background: var(--bg-card);
}

.search-result-item.active {
  outline: 1px solid rgba(212, 160, 23, 0.3);
  border-left: 2px solid var(--accent);
}

.search-result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.search-result-group {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.search-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

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

.search-footer kbd {
  font-size: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--mono);
}

/* ========== Chinese Typography ========== */
:lang(zh) .docs-content p,
:lang(zh-CN) .docs-content p,
:lang(zh) .docs-content li,
:lang(zh-CN) .docs-content li {
  line-height: 1.9;
}
:lang(zh) .docs-content,
:lang(zh-CN) .docs-content {
  line-height: 1.85;
}
