:root {
  --sidebar-w: 260px;
  --toc-w: 240px;
  --topbar-h: 56px;
  --c-primary: #3b82f6;
  --c-primary-light: #eff6ff;
  --c-bg: #ffffff;
  --c-bg-soft: #f8fafc;
  --c-bg-sidebar: #f1f5f9;
  --c-text: #1e293b;
  --c-text-soft: #64748b;
  --c-text-muted: #475569;
  --c-border: #e2e8f0;
  --c-border-light: #f1f5f9;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", Menlo, Monaco, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

/* ── Top Bar ───────────────────────────────── */

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  gap: 12px;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--c-text);
  font-weight: 700;
  font-size: 16px;
}
.logo svg { color: var(--c-primary); }
.logo-sub {
  font-weight: 400;
  color: var(--c-text-soft);
  font-size: 14px;
  margin-left: 4px;
}

.top-bar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.version-badge {
  font-size: 12px;
  color: var(--c-text-muted);
  background: var(--c-bg-soft);
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid var(--c-border);
}

/* ── Layout ───────────────────────────────── */

.layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ──────────────────────────────── */

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--c-bg-sidebar);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 4px; }

.search-box {
  display: flex;
  align-items: center;
  margin: 0 12px 16px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box:focus-within {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.1);
}

.search-icon {
  color: #8b949e;
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: var(--c-text);
  margin: 0 8px;
  min-width: 0;
}

#search-input::placeholder {
  color: #8b949e;
}

.search-shortcut {
  font-size: 12px;
  color: #8b949e;
  padding: 2px 6px;
  background: var(--c-bg-soft);
  border-radius: 4px;
  flex-shrink: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 40;
}

.nav-category {
  padding: 0 16px;
  margin-bottom: 16px;
}

.nav-category-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-text-muted);
  padding: 6px 8px;
  margin-bottom: 2px;
}

.nav-item {
  display: block;
  padding: 6px 12px;
  margin: 1px 8px;
  border-radius: 6px;
  color: var(--c-text-soft);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.5;
  transition: all 0.15s;
}
.nav-item:hover {
  background: rgba(0,0,0,0.04);
  color: var(--c-text);
}
.nav-item.active {
  background: var(--c-primary-light);
  color: var(--c-primary);
  font-weight: 500;
}

.nav-item .nav-ver {
  font-size: 11px;
  color: var(--c-text-muted);
  float: right;
  margin-top: 2px;
}
.nav-item.active .nav-ver {
  color: var(--c-primary);
  opacity: 0.7;
}

/* ── Main Content ─────────────────────────── */

main {
  flex: 1;
  margin-left: var(--sidebar-w);
  margin-right: var(--toc-w);
  min-width: 0;
  padding: 32px 48px 64px;
  max-width: 100%;
}

.loading {
  text-align: center;
  padding: 80px 0;
  color: var(--c-text-muted);
  font-size: 14px;
}

/* ── Index Page ───────────────────────────── */

.index-page {
  max-width: 800px;
}

.index-page h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.index-page .subtitle {
  color: var(--c-text-soft);
  font-size: 15px;
  margin-bottom: 32px;
}

.index-section {
  margin-bottom: 32px;
}

.index-section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
}

.index-card {
  display: block;
  padding: 16px 20px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  margin-bottom: 8px;
  text-decoration: none;
  color: var(--c-text);
  transition: all 0.2s;
}
.index-card:hover {
  border-color: var(--c-primary);
  box-shadow: 0 2px 8px rgba(59,130,246,0.08);
}

.index-card-title {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
}

.index-card-meta {
  font-size: 12px;
  color: var(--c-text-muted);
}

/* ── Article ──────────────────────────────── */

.article-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px 16px;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--c-border);
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.article-breadcrumb {
  width: 100%;
  font-size: 13px;
  color: var(--c-text-muted);
  margin-bottom: 4px;
}
.article-breadcrumb a {
  color: var(--c-text-muted);
  text-decoration: none;
}
.article-breadcrumb a:hover { color: var(--c-primary); }
.article-breadcrumb .sep { margin: 0 6px; }

.article-title {
  flex: 1;
  min-width: 200px;
  font-size: 28px;
  font-weight: 700;
  color: var(--c-text);
  line-height: 1.3;
  margin-bottom: 0;
  letter-spacing: -0.3px;
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--c-text-soft);
}

.version-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  background: var(--c-bg);
  font-size: 13px;
  color: var(--c-text-soft);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  flex-shrink: 0;
  align-self: flex-start;
}
.version-select:hover {
  border-color: var(--c-primary);
  box-shadow: 0 1px 4px rgba(59,130,246,0.12);
}
.version-select select {
  border: none;
  background: none;
  font-size: 13px;
  color: var(--c-primary);
  font-weight: 500;
  cursor: pointer;
  outline: none;
  font-family: var(--font-sans);
  padding-right: 2px;
}

.deprecated-banner {
  width: 100%;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.5;
}
.deprecated-banner a {
  color: #b45309;
  font-weight: 600;
  text-decoration: underline;
}

.article-body {
  max-width: 680px;
  margin: 0 auto;
}

.article-body h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 40px 0 16px;
  color: var(--c-text);
  letter-spacing: -0.2px;
}
.article-body h1:first-child { margin-top: 0; }

.article-body h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 36px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border-light);
  color: var(--c-text);
}

.article-body h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 28px 0 10px;
  color: var(--c-text);
}

.article-body h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--c-text);
}

.article-body h5 {
  font-size: 14px;
  font-weight: 600;
  margin: 20px 0 6px;
  color: var(--c-text);
}

.article-body h6 {
  font-size: 13px;
  font-weight: 600;
  margin: 16px 0 4px;
  color: var(--c-text-muted);
}

/* Headings containing bold */
.article-body h1 strong, .article-body h1 b,
.article-body h2 strong, .article-body h2 b,
.article-body h3 strong, .article-body h3 b,
.article-body h4 strong, .article-body h4 b,
.article-body h5 strong, .article-body h5 b,
.article-body h6 strong, .article-body h6 b {
  font-weight: inherit;
  color: inherit;
}

.article-body p {
  margin-bottom: 16px;
  text-align: justify;
  color: var(--c-text);
  line-height: 1.8;
}

/* Bold / Strong */
.article-body strong,
.article-body b {
  font-weight: 700;
  color: #0f172a;
  letter-spacing: 0.1px;
}

/* Italic / Em */
.article-body em,
.article-body i {
  font-style: italic;
  padding-right: 1px;
}

.article-body strong em,
.article-body em strong,
.article-body b i,
.article-body i b {
  font-weight: 700;
  font-style: italic;
  color: #0f172a;
}

/* Underline (Legal notices / emphasis) */
.article-body u {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.article-body strong u,
.article-body u strong,
.article-body b u,
.article-body u b {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
  color: #0f172a;
}

/* Strikethrough */
.article-body del,
.article-body s {
  text-decoration: line-through;
  color: var(--c-text-muted);
  opacity: 0.8;
}

/* Highlight */
.article-body mark {
  background: #fef08a;
  color: #1e293b;
  padding: 1px 4px;
  border-radius: 3px;
}

/* Links */
.article-body a {
  color: var(--c-primary);
  text-decoration: none;
  border-bottom: 1px dashed rgba(59, 130, 246, 0.4);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.article-body a:hover {
  color: #2563eb;
  border-bottom-style: solid;
  border-bottom-color: #2563eb;
}

.article-body a:active {
  color: #1d4ed8;
}

.article-body a strong,
.article-body a b {
  color: inherit;
}

/* Lists */
.article-body ol, .article-body ul {
  padding-left: 24px;
  margin-bottom: 16px;
}

.article-body li {
  margin-bottom: 6px;
  line-height: 1.7;
}

.article-body li > ol, .article-body li > ul {
  margin-top: 6px;
  margin-bottom: 0;
}

/* Task lists (GFM) */
.article-body input[type="checkbox"] {
  margin: 0 8px 0 0;
  vertical-align: middle;
  accent-color: var(--c-primary);
}

.article-body li:has(input[type="checkbox"]) {
  list-style-type: none;
  margin-left: -20px;
}

/* Blockquotes */
.article-body blockquote {
  margin: 18px 0;
  padding: 12px 18px;
  border-left: 4px solid var(--c-primary);
  background: var(--c-bg-soft);
  border-radius: 0 6px 6px 0;
  color: var(--c-text-soft);
  font-size: 14px;
  line-height: 1.7;
}
.article-body blockquote p:last-child { margin-bottom: 0; }
.article-body blockquote strong,
.article-body blockquote b {
  color: var(--c-text);
  font-weight: 700;
}

/* Horizontal Rule */
.article-body hr {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 32px 0;
}

/* Table */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 18px 0;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13.5px;
  line-height: 1.6;
  border: 1px solid var(--c-border);
  border-radius: 6px;
}

.table-wrapper table {
  margin: 0;
}

.article-body th, .article-body td {
  padding: 10px 14px;
  border: 1px solid var(--c-border);
  text-align: left;
  vertical-align: top;
}

.article-body th {
  background: var(--c-bg-soft);
  color: #0f172a;
  font-weight: 600;
  white-space: nowrap;
}

.article-body tbody tr:nth-child(even) {
  background: rgba(248, 250, 252, 0.7);
}

.article-body tbody tr:hover {
  background: #f1f5f9;
}

/* Code */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  color: #b91c1c;
}

.article-body pre {
  margin: 16px 0;
  padding: 16px 20px;
  background: #1e293b;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.5;
}

.article-body pre code {
  background: none;
  padding: 0;
  color: #e2e8f0;
  font-size: 13px;
  border: none;
}

.article-footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--c-border);
  font-size: 13px;
  color: var(--c-text-muted);
}

/* ── TOC (Right Sidebar) ──────────────────── */

.toc {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--toc-w);
  padding: 32px 16px 32px 0;
  overflow-y: auto;
  font-size: 13px;
}

.toc::-webkit-scrollbar { width: 3px; }
.toc::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }

.toc-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-text-muted);
  padding: 0 12px;
  margin-bottom: 12px;
}

#toc-nav a {
  display: block;
  padding: 5px 12px;
  margin-bottom: 2px;
  color: var(--c-text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  line-height: 1.6;
  font-size: 13px;
  word-break: break-all;
  transition: all 0.15s;
}
#toc-nav a:hover {
  color: var(--c-text);
  background: var(--c-bg-soft);
}
#toc-nav a.active {
  color: var(--c-primary);
  border-left-color: var(--c-primary);
  background: var(--c-primary-light);
}

#toc-nav a.toc-h3 {
  padding-left: 24px;
  font-size: 12px;
  color: var(--c-text-muted);
}

/* ── Diff Link ────────────────────────────── */

.diff-link {
  color: var(--c-primary);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  transition: all 0.15s;
}
.diff-link:hover {
  border-color: var(--c-primary);
  background: var(--c-primary-light);
}

/* ── Print Button ─────────────────────────── */

.print-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: var(--c-bg);
  color: var(--c-text-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.print-btn:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
  background: var(--c-primary-light);
}

/* ── Diff View ────────────────────────────── */

.diff-header {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--c-border);
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
}

.diff-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.diff-arrow {
  color: var(--c-text-muted);
  font-size: 16px;
}

.diff-stats {
  max-width: 960px;
  margin: 0 auto 16px;
  display: flex;
  gap: 12px;
  font-size: 13px;
  font-weight: 500;
}
.diff-stats-added { color: #16a34a; }
.diff-stats-removed { color: #dc2626; }
.diff-stats-unchanged { color: var(--c-text-muted); }

.diff-view {
  max-width: 960px;
  margin: 0 auto;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  overflow: hidden;
}

.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  table-layout: fixed;
}

.diff-table td {
  padding: 0 12px;
  vertical-align: top;
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-num {
  width: 48px;
  min-width: 48px;
  text-align: right;
  color: var(--c-text-muted);
  font-size: 12px;
  padding: 0 8px;
  user-select: none;
  border-right: 1px solid var(--c-border);
}

.diff-sign {
  width: 20px;
  min-width: 20px;
  text-align: center;
  font-weight: 600;
  user-select: none;
}

.diff-text {
  padding: 0 12px;
}

.diff-added {
  background: #f0fdf4;
}
.diff-added .diff-sign { color: #16a34a; }
.diff-added .diff-num { background: #dcfce7; }

.diff-removed {
  background: #fef2f2;
}
.diff-removed .diff-sign { color: #dc2626; }
.diff-removed .diff-num { background: #fee2e2; }

.diff-context {
  background: var(--c-bg);
}

/* ── Error ────────────────────────────────── */

.error-page {
  text-align: center;
  padding: 80px 20px;
}
.error-page h2 {
  font-size: 20px;
  color: var(--c-text);
  margin-bottom: 8px;
}
.error-page p {
  color: var(--c-text-soft);
  font-size: 14px;
}
.error-page a {
  color: var(--c-primary);
  text-decoration: none;
}
.error-page a:hover { text-decoration: underline; }

/* ── Responsive ───────────────────────────── */

@media (max-width: 1200px) {
  .toc { display: none; }
  main { margin-right: 0; }
}

@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 16px rgba(0,0,0,0.1);
  }
  .sidebar.open + .sidebar-overlay { display: block; }

  main {
    margin-left: 0;
    padding: 20px 16px 48px;
  }

  .article-title { font-size: 22px; }
  .index-page h1 { font-size: 22px; }
  .article-body h2 { font-size: 18px; }
}

/* ── Print ────────────────────────────────── */

@media print {
  .top-bar,
  .sidebar,
  .sidebar-overlay,
  .toc,
  .sidebar-toggle,
  .version-select,
  .diff-link,
  .print-btn,
  .diff-controls,
  .diff-stats { display: none !important; }

  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
    line-height: 1.6;
  }

  .layout { display: block; }

  main {
    margin: 0;
    padding: 0;
    max-width: 100%;
  }

  .article-header {
    max-width: 100%;
    border-bottom: 2px solid #000;
    padding-bottom: 16px;
    margin-bottom: 24px;
  }

  .article-breadcrumb { display: none; }

  .article-title {
    font-size: 20pt;
    margin-bottom: 8px;
  }

  .article-meta {
    font-size: 10pt;
    color: #555;
  }

  .article-body {
    max-width: 100%;
  }

  .article-body h1 { font-size: 16pt; }
  .article-body h2 { font-size: 14pt; }
  .article-body h3 { font-size: 12pt; }
  .article-body h4, .article-body h5, .article-body h6 { font-size: 11pt; }

  .article-body strong,
  .article-body b {
    font-weight: 700;
    color: #000;
  }

  .article-body u {
    text-decoration: underline;
  }

  .article-body del {
    text-decoration: line-through;
  }

  .article-body mark {
    background: none;
    font-weight: 700;
  }

  .article-body pre {
    background: #f5f5f5;
    border: 1px solid #ddd;
    white-space: pre-wrap;
  }

  .article-body a {
    color: #000;
    text-decoration: underline;
  }

  .article-body blockquote {
    border-left-color: #333;
    background: none;
  }

  .article-body table {
    border: 1px solid #000;
  }

  .article-body th,
  .article-body td {
    border: 1px solid #000;
  }

  .diff-view {
    max-width: 100%;
    border: 1px solid #000;
  }

  .diff-added { background: #e8f5e9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .diff-removed { background: #ffebee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  h2, h3 { page-break-after: avoid; }
  tr { page-break-inside: avoid; }
}

/* ===== Embed mode (WebView in app) ===== */
body.embed-app .top-bar,
body.embed-app .sidebar,
body.embed-app .toc,
body.embed-app .sidebar-overlay {
  display: none !important;
}

body.embed-app .layout {
  display: block;
}

body.embed-app #content {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 16px;
  border: none;
  box-shadow: none;
  min-height: 100vh;
  box-sizing: border-box;
}

body.embed-app .article-body {
  max-width: 100%;
}

body.embed-app .article-breadcrumb,
body.embed-app .article-title,
body.embed-app .article-meta span,
body.embed-app .diff-link,
body.embed-app .print-btn,
body.embed-app .copy-btn {
  display: none !important;
}

body.embed-app .article-header {
  display: flex;
  flex-direction: column;
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 16px;
}

body.embed-app .version-select {
  align-self: flex-end;
  margin-bottom: 8px;
}

body.embed-app .deprecated-banner {
  width: 100%;
  float: none;
  margin-bottom: 12px;
}

body.embed-app .article-meta {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}
