@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Noto+Sans+SC:wght@400;500;600;700&display=swap");

:root {
  --ink: #1a1d23;
  --muted: #6b7280;
  --line: #e5e2da;
  --bg: #f3f1ec;
  --paper: #fffcf7;
  --accent: #0f6e56;
  --accent-soft: #e6f4ef;
  --accent-2: #c45c26;
  --sidebar-w: 320px;
  --content-max: 1040px;
  --sidebar-bg: #f7f5f0;
  --sidebar-text: #2c3038;
  --shadow: 0 1px 0 rgba(26, 29, 35, 0.04);
  --font-sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-display: "Fraunces", "Noto Serif SC", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.7;
}

a { color: var(--accent); }

/* ——— App shell + left nav ——— */
.app-shell {
  display: flex;
  min-height: 100vh;
  height: 100%;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 22px 16px 32px;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  z-index: 40;
}

.sidebar-brand {
  padding: 4px 10px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.sidebar-logo {
  display: block;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.sidebar-logo:hover { color: var(--accent); }

.sidebar-sub {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.sidebar-section-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px 8px;
  margin-top: 4px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group {
  display: flex;
  flex-direction: column;
}

.nav-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.nav-row-child {
  margin-left: 0;
}

.nav-tri {
  flex-shrink: 0;
  width: 24px;
  height: 28px;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  line-height: 28px;
  text-align: center;
  border-radius: 6px;
  font-family: inherit;
}
.nav-tri:hover {
  color: var(--accent);
  background: rgba(15, 110, 86, 0.08);
}
.nav-tri-spacer {
  flex-shrink: 0;
  width: 24px;
  height: 28px;
}

.nav-group:not(.is-open) > .nav-children,
.nav-group:not(.is-open) > .page-toc,
.nav-sub:not(.is-open) > .page-toc {
  display: none !important;
}

.nav-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: rgba(15, 110, 86, 0.06);
  color: var(--accent);
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 600;
}

.nav-num {
  flex-shrink: 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  margin-top: 2px;
}

.nav-item.is-active .nav-num { color: var(--accent); }

.nav-text { min-width: 0; }

.nav-children {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 8px 26px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.nav-child {
  display: block;
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12.5px;
  line-height: 1.35;
}

.nav-child:hover {
  color: var(--accent);
  background: rgba(15, 110, 86, 0.06);
}
.nav-child.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.sidebar-toc {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 0 10px;
}

.toc-item {
  display: block;
  text-decoration: none;
  line-height: 1.4;
  border-left: 0;
}

.toc-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toc-section-row {
  display: flex;
  align-items: flex-start;
  gap: 2px;
}

.toc-section-row .toc-h2 {
  flex: 1;
  min-width: 0;
}

.toc-section:not(.is-open) > .toc-section-kids {
  display: none !important;
}

.toc-section-kids {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding-left: 26px;
}

.toc-section-kids .toc-section {
  width: 100%;
  gap: 6px;
}

.toc-section-kids .toc-section-row .toc-h2,
.toc-section-kids .toc-section-row .toc-h1 {
  font-size: 12.5px;
  padding: 7px 9px;
}

/* 本页大标题 / 分组标题 */
.toc-h1,
.toc-h2 {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  background: #fff;
  border: 1px solid var(--line);
}
.toc-h1:hover,
.toc-h2:hover {
  border-color: rgba(15, 110, 86, 0.35);
  color: var(--accent);
}
.toc-h1.is-active,
.toc-h2.is-active {
  background: var(--accent-soft);
  border-color: rgba(15, 110, 86, 0.35);
  color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* 内标签：小节标题做成标签样式 */
.toc-h3 {
  display: inline-flex;
  align-items: flex-start;
  width: fit-content;
  max-width: 100%;
  margin-left: 0;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: #3d5c52;
  background: #eef6f2;
  border: 1px solid #d5e8df;
}
.toc-h3:hover {
  background: #e2f1ea;
  color: var(--accent);
  border-color: #b9d9cb;
}
.toc-h3.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.page-toc {
  margin: 2px 0 8px 26px;
  padding: 2px 0 4px 8px;
  border-left: 1px solid var(--line);
}
.nav-children .page-toc,
.nav-sub .page-toc {
  margin-left: 26px;
}

.content-wrap {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  height: 100vh;
  background:
    linear-gradient(180deg, rgba(243, 241, 236, 0.9), rgba(243, 241, 236, 1)),
    radial-gradient(circle at 100% 0%, rgba(15, 110, 86, 0.06), transparent 40%);
}

.sidebar-backdrop {
  display: none;
}

.mobile-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--sidebar-bg);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.mobile-bar .mobile-brand {
  flex: 1;
  min-width: 0;
}

.mobile-bar .doc-template-link {
  flex-shrink: 0;
}

.doc-topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 14px 28px 0;
  position: sticky;
  top: 0;
  z-index: 26;
  background: linear-gradient(180deg, rgba(243, 241, 236, 0.96), rgba(243, 241, 236, 0.88));
  backdrop-filter: blur(8px);
}

.doc-template-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.doc-template-link:hover {
  background: var(--accent-soft);
  border-color: rgba(15, 110, 86, 0.35);
  color: var(--accent);
}

.doc-search {
  position: sticky;
  top: 44px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px 10px;
  background: rgba(243, 241, 236, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.doc-search input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%235c6570' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5'/%3E%3C/svg%3E") 12px 50% / 15px no-repeat,
    #fffcf7;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  outline: none;
}

.doc-search input:focus {
  border-color: rgba(15, 110, 86, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 110, 86, 0.1);
}

.doc-search-meta {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.menu-toggle {
  border: 0;
  background: rgba(15, 110, 86, 0.08);
  color: var(--accent);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

.mobile-brand {
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}

main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 48px 48px 96px;
  background: var(--paper);
  min-height: calc(100vh - 0px);
  box-shadow: var(--shadow);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.doc-title {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 12px;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 28px;
}

h1 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 40px 0 16px;
  font-weight: 700;
  scroll-margin-top: 24px;
}
h2 {
  font-size: 20px;
  margin: 32px 0 12px;
  font-weight: 650;
  scroll-margin-top: 24px;
}
h3 {
  font-size: 17px;
  margin: 24px 0 10px;
  font-weight: 650;
  scroll-margin-top: 24px;
}
h4 {
  font-size: 15px;
  margin: 20px 0 8px;
  font-weight: 600;
}

p { margin: 8px 0; font-size: 15px; color: var(--ink); }

blockquote {
  margin: 12px 0;
  padding: 10px 16px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 0 8px 8px 0;
}

ul { margin: 6px 0; padding-left: 22px; }
li { margin: 4px 0; }

pre {
  background: #f4f2ed;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

code { font-family: Consolas, "SF Mono", Menlo, monospace; }

.code-block {
  position: relative;
  margin: 12px 0 18px;
}

.code-block pre {
  margin: 0;
  padding-top: 42px;
}

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft, #3d4a5c);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(26, 29, 35, 0.06);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.code-copy:hover {
  border-color: var(--accent, #0f6e56);
  color: var(--accent-deep, #0a5542);
  background: var(--accent-soft, #e6f4ef);
}

.code-copy.is-copied {
  background: var(--accent, #0f6e56);
  border-color: var(--accent, #0f6e56);
  color: #fff;
}

.img-block {
  margin: 16px 0;
  text-align: center;
}
.img-block img {
  max-width: min(420px, 72%);
  max-height: 320px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: inline-block;
  vertical-align: middle;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(26, 29, 35, 0.08);
  cursor: zoom-in;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.img-block img:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 28px rgba(26, 29, 35, 0.12);
}

/* 图片点击放大灯箱 */
.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 23, 28, 0.72);
  backdrop-filter: blur(4px);
  cursor: zoom-out;
}
.img-lightbox.is-open {
  display: flex;
}
.img-lightbox img {
  max-width: min(96vw, 1200px);
  max-height: 92vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  cursor: default;
}
.img-lightbox-close {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #1a1d23;
  font-size: 22px;
  line-height: 40px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.img-lightbox-close:hover {
  background: #fff;
}

@media (max-width: 640px) {
  .img-block img {
    max-width: 88%;
    max-height: 240px;
  }
}

.callout {
  background: #fff5eb;
  border: 1px solid #f0d4b8;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
}

.ordered { margin: 6px 0; padding-left: 4px; }
.todo {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 6px 0;
}

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 28px 0;
}

.table-wrap, .grid-wrap, .callout-wrap { overflow: auto; margin: 16px 0; }
.table-text { white-space: pre-wrap; font-size: 13px; }

table.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.55;
  background: #fff;
  border: 1px solid #dee0e3;
  border-radius: 8px;
  overflow: hidden;
}
table.doc-table th,
table.doc-table td {
  border: 1px solid #dee0e3;
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}
table.doc-table th {
  background: #f5f6f7;
  font-weight: 650;
  color: var(--ink);
}
table.doc-table tr:nth-child(even) td {
  background: #fafafa;
}

.attach-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin: 12px 0 28px;
}
.attach-item {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
}
.attach-item:hover {
  border-color: rgba(15, 110, 86, 0.4);
  color: var(--accent);
}

/* Keep comparison bullets readable full-width */
main ul {
  max-width: 100%;
}
main ul > li {
  word-break: normal;
  overflow-wrap: anywhere;
}

.nav-home {
  display: inline-block;
  margin-bottom: 20px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}
.nav-home:hover { color: var(--accent); }

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.25);
    width: min(var(--sidebar-w), 86vw);
    z-index: 40;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 35;
  }
  .mobile-bar {
    display: flex;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .doc-topbar {
    display: none;
  }
  .doc-search {
    top: 52px;
    padding: 10px 16px;
  }
  .content-wrap { height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  main {
    max-width: none;
    border: 0;
    padding: 24px 16px calc(56px + env(safe-area-inset-bottom, 0px));
    box-shadow: none;
  }
  .doc-title { font-size: 26px; }
  .table-wrap,
  .doc-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  pre, pre code {
    font-size: 12px;
    word-break: break-word;
    white-space: pre-wrap;
  }
}

@media (max-width: 560px) {
  main {
    padding: 18px 14px calc(48px + env(safe-area-inset-bottom, 0px));
  }
  .doc-title { font-size: 22px; line-height: 1.35; }
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.05rem; }
  .img-block img {
    max-width: 100%;
    max-height: 220px;
  }
  .img-lightbox-close {
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
  }
}
