:root {
  --bg: #0a0e17;
  --bg-2: #0f1522;
  --card: #141b2e;
  --card-2: #1a2338;
  --border: #232e4a;
  --accent: #22d3ee;
  --accent-2: #34d399;
  --accent-3: #818cf8;
  --warning: #fbbf24;
  --danger: #f87171;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --glow: rgba(34, 211, 238, 0.35);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sidebar-w: 268px;
  --toc-w: 216px;
  --header-h: 62px;
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-2: #eef1f8;
  --card: #ffffff;
  --card-2: #f3f6fd;
  --border: #dfe5f1;
  --accent: #0891b2;
  --accent-2: #059669;
  --accent-3: #6366f1;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #0f172a;
  --muted: #64748b;
  --glow: rgba(8, 145, 178, 0.25);
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

code, kbd, pre { font-family: var(--mono); }

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

/* ---------- reading progress ---------- */
#progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  z-index: 220; transition: width 0.1s linear;
}

/* ---------- header ---------- */
header.top {
  position: sticky; top: 0; z-index: 200;
  height: var(--header-h);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  header.top { background: var(--bg); }
}
.top-inner {
  max-width: 1440px; margin: 0 auto; padding: 0 20px;
  height: 100%; display: flex; align-items: center; gap: 16px;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; letter-spacing: -0.2px;
  color: var(--text); text-decoration: none; flex-shrink: 0;
}
.logo:hover { text-decoration: none; }
.logo-badge {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  display: grid; place-items: center; font-size: 17px; color: #04121b;
  box-shadow: 0 0 16px var(--glow);
}
.logo .sep { color: var(--muted); font-weight: 400; }
.logo .sub { color: var(--muted); font-weight: 500; }

.top-search {
  position: relative; flex: 1; max-width: 420px; margin-left: auto;
}
.top-search input {
  width: 100%; height: 38px; padding: 0 14px 0 36px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color 0.2s;
}
.top-search input:focus { border-color: var(--accent); }
.top-search input::placeholder { color: var(--muted); }
.top-search .ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.search-results {
  position: absolute; top: 44px; left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 18px 46px rgba(0, 0, 0, 0.5);
  overflow: hidden; display: none; max-height: 62vh; overflow-y: auto;
}
.search-results.open { display: block; }
.search-results a {
  display: block; padding: 10px 14px; color: var(--text);
  border-bottom: 1px solid var(--border); font-size: 14px;
}
.search-results a:last-child { border-bottom: none; }
.search-results a:hover, .search-results a.sel { background: var(--card-2); text-decoration: none; }
.search-results .r-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.search-results .r-desc {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.search-results .r-sec { color: var(--accent); font-weight: 500; }
.search-results .empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }
mark { background: rgba(251, 191, 36, 0.28); color: inherit; border-radius: 3px; padding: 0 1px; }

.top-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  display: grid; place-items: center; font-size: 15px;
  transition: border-color 0.2s, color 0.2s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.lang-btn {
  height: 36px; padding: 0 13px; border-radius: 10px;
  background: var(--card); color: var(--accent);
  border: 1px solid var(--border); cursor: pointer;
  font-weight: 700; font-size: 12px; letter-spacing: 0.6px; font-family: inherit;
  transition: border-color 0.2s;
}
.lang-btn:hover { border-color: var(--accent); }
.side-toggle { display: none; }

/* ---------- layout ---------- */
.layout {
  max-width: 1440px; margin: 0 auto; padding: 0 20px;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 34px; align-items: start;
}

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto; padding: 26px 8px 40px 0;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.side-label {
  font-size: 11px; font-weight: 700; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--muted);
  padding: 0 10px; margin-bottom: 10px;
}
.side-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px;
  color: var(--muted); font-size: 14px; font-weight: 500;
  text-decoration: none; transition: background 0.15s, color 0.15s;
}
.side-link:hover { background: var(--card); color: var(--text); text-decoration: none; }
.side-link.active { background: var(--card); color: var(--accent); font-weight: 600; }
.side-link.active .sl-ic { filter: none; }
.side-link .sl-ic { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.side-link.home { border-bottom: 1px solid var(--border); border-radius: 0; margin-bottom: 10px; padding-bottom: 12px; }
.side-group {
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); padding: 16px 10px 6px; opacity: 0.8;
}

/* ---------- content ---------- */
.content { min-width: 0; padding: 26px 0 70px; }

.crumbs {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--muted); margin-bottom: 14px;
}
.crumbs .cur { color: var(--text); font-weight: 600; }

.page-head { margin-bottom: 30px; }
.page-head .eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--accent); margin-bottom: 12px;
}
.page-head h1 {
  font-size: clamp(28px, 4vw, 38px); font-weight: 800;
  letter-spacing: -1px; line-height: 1.15; margin-bottom: 12px;
}
.page-head .lede { font-size: 17px; color: var(--muted); max-width: 78ch; }

.prose > h2 {
  font-size: 25px; font-weight: 700; letter-spacing: -0.5px;
  margin: 46px 0 14px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.prose > h2:first-child { margin-top: 8px; border-top: none; padding-top: 0; }
.prose > h3 { font-size: 19px; font-weight: 700; margin: 30px 0 10px; }
.prose > h4 { font-size: 16px; font-weight: 700; margin: 22px 0 8px; color: var(--text); }
.prose p { margin-bottom: 14px; color: var(--text); max-width: 82ch; }
.prose ul, .prose ol { margin: 0 0 16px 22px; color: var(--text); }
.prose li { margin-bottom: 7px; max-width: 78ch; }
.prose li::marker { color: var(--accent); }
.prose strong { font-weight: 650; }
.prose a { text-decoration: underline; text-underline-offset: 2px; }

.prose .mono, .prose code {
  background: var(--card-2); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 6px;
  font-size: 13px; color: var(--accent); white-space: nowrap;
}
.prose code.path { color: var(--accent-3); }
.prose pre {
  position: relative;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; margin: 0 0 18px;
  overflow-x: auto; font-size: 13px; line-height: 1.6; color: var(--accent-2);
}
.prose pre code { background: none; border: none; padding: 0; color: inherit; white-space: pre; font-size: 13px; }
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--card-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 7px;
  font-size: 11px; font-family: inherit; padding: 4px 9px; cursor: pointer;
  opacity: 0; transition: opacity 0.15s, color 0.15s;
}
.prose pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

.chip {
  display: inline-block; background: var(--card-2); border: 1px solid var(--border);
  padding: 1px 9px; border-radius: 7px;
  font-family: var(--mono); font-size: 12px; color: var(--accent);
  white-space: nowrap;
}

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto; margin: 0 0 20px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--card);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  background: var(--card-2); color: var(--muted);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--card-2); }
td code, .mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }

/* ---------- callouts ---------- */
.callout {
  display: flex; gap: 14px;
  border-radius: 12px; padding: 15px 17px; margin: 0 0 18px;
  font-size: 14px; line-height: 1.6;
  background: var(--card); border: 1px solid var(--border);
}
.callout .co-ic { font-size: 18px; line-height: 1.3; flex-shrink: 0; }
.callout .co-body > :first-child { margin-top: 0; }
.callout .co-body > :last-child { margin-bottom: 0; }
.callout p { margin-bottom: 8px; color: var(--text); }
.callout ul { margin-left: 20px; }
.callout.info { background: rgba(34, 211, 238, 0.07); border-color: rgba(34, 211, 238, 0.28); }
.callout.ok { background: rgba(52, 211, 153, 0.07); border-color: rgba(52, 211, 153, 0.28); }
.callout.warn { background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.3); }
.callout.danger { background: rgba(248, 113, 113, 0.08); border-color: rgba(248, 113, 113, 0.3); }

/* ---------- card grids ---------- */
.grid { display: grid; gap: 16px; margin: 0 0 22px; }
.grid.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.g3 { grid-template-columns: repeat(auto-fit, minmax(232px, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--accent); transform: translateY(-3px); text-decoration: none; }
.card .c-ic { font-size: 22px; margin-bottom: 12px; display: block; }
.card h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.card p { font-size: 14px; color: var(--muted); margin: 0; }
.card .c-num {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: rgba(34, 211, 238, 0.14); color: var(--accent);
  font-size: 13px; font-weight: 700; margin-bottom: 12px;
}
.card ul { margin: 10px 0 0 18px; }
.card li { font-size: 13.5px; color: var(--muted); margin-bottom: 5px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 0 0 24px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; text-align: center;
}
.stat .num {
  font-size: 26px; font-weight: 800; letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-3));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.stat .lab { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* ---------- flow diagram ---------- */
.flow {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 12px; align-items: stretch; margin: 0 0 22px;
}
.flow-col { display: flex; flex-direction: column; gap: 10px; }
.flow-node {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 15px;
  display: flex; gap: 12px; align-items: flex-start;
}
.flow-node .fi { font-size: 19px; line-height: 1.3; flex-shrink: 0; }
.flow-node b { font-size: 14px; font-weight: 650; display: block; }
.flow-node .fm { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.flow-node .fm .mono { color: var(--accent); }
.flow-arrow {
  display: grid; place-items: center;
  color: var(--accent); font-size: 20px; font-weight: 700;
  align-self: center;
}
.flow-node.core { border-color: rgba(34, 211, 238, 0.35); background: var(--card-2); }
.flow-node.srv { border-color: rgba(52, 211, 153, 0.32); }
.flow-node.app { border-color: rgba(251, 191, 36, 0.32); }
.flow-node .tagline { font-size: 11px; color: var(--muted); margin-top: 6px; }
.flow-col .flow-head {
  font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--muted); padding-left: 4px;
}
@media (max-width: 900px) {
  .flow { grid-template-columns: 1fr; }
  .flow-arrow { transform: rotate(90deg); padding: 2px 0; }
}

/* ---------- sequence list ---------- */
.seq { list-style: none; margin: 0 0 20px; counter-reset: seq; }
.seq li {
  position: relative; padding: 0 0 18px 44px; counter-increment: seq;
  border-left: 2px solid var(--border); margin-left: 14px;
}
.seq li:last-child { border-left-color: transparent; padding-bottom: 0; }
.seq li::before {
  content: counter(seq); position: absolute; left: -15px; top: 0;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--card-2); border: 1px solid var(--border);
  color: var(--accent); font-size: 13px; font-weight: 700;
  display: grid; place-items: center; font-family: var(--mono);
}
.seq li b { display: block; font-size: 14.5px; margin-bottom: 3px; }
.seq li p { font-size: 14px; color: var(--muted); margin: 0; }

/* ---------- steps ---------- */
.steps { counter-reset: st; margin-bottom: 22px; }
.step {
  position: relative; padding: 0 0 22px 46px;
  border-left: 2px solid var(--border); margin-left: 15px;
}
.step:last-child { border-left-color: transparent; padding-bottom: 0; }
.step::before {
  counter-increment: st; content: counter(st);
  position: absolute; left: -16px; top: 0;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #04121b; font-weight: 800; font-size: 14px;
  display: grid; place-items: center;
}
.step h3 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.step h4 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; }
.step p { margin-bottom: 10px; }
.step > :last-child { margin-bottom: 0; }

/* ---------- details / FAQ ---------- */
details.faq {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 0 18px; margin-bottom: 10px;
}
details.faq[open] { border-color: rgba(34, 211, 238, 0.35); }
details.faq summary {
  cursor: pointer; font-weight: 600; font-size: 15px; padding: 14px 0;
  list-style: none; display: flex; align-items: flex-start; gap: 10px;
}
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::before {
  content: '+'; color: var(--accent); font-weight: 700; font-size: 19px;
  line-height: 1.25; flex-shrink: 0; width: 14px;
}
details.faq[open] summary::before { content: '\2212'; }
details.faq .faq-body {
  padding: 0 0 16px 24px; font-size: 14.5px; color: var(--muted);
}
details.faq .faq-body p { color: var(--muted); margin-bottom: 10px; }
details.faq .faq-body > :last-child { margin-bottom: 0; }
details.faq .faq-body code { color: var(--accent); }

/* ---------- SVG diagrams ---------- */
.figure {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; margin: 0 0 20px;
}
.figure svg, .figure img { width: 100%; height: auto; display: block; }
.figure figcaption {
  font-size: 13px; color: var(--muted); text-align: center; margin-top: 14px;
}

/* ---------- prev / next ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 46px; padding-top: 26px; border-top: 1px solid var(--border); }
.pager a {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 15px 17px; color: inherit; text-decoration: none;
  transition: border-color 0.2s;
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager .dir { font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.pager .t { font-weight: 600; font-size: 15px; margin-top: 4px; }
.pager .next { text-align: right; }
.pager .empty { visibility: hidden; }

/* ---------- right TOC ---------- */
.toc {
  position: sticky; top: var(--header-h);
  max-height: calc(100vh - var(--header-h)); overflow-y: auto;
  padding: 26px 0 40px; font-size: 13px;
}
.toc-label {
  font-size: 11px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
.toc a {
  display: block; padding: 5px 0 5px 12px;
  color: var(--muted); text-decoration: none;
  border-left: 2px solid var(--border); line-height: 1.45;
  transition: color 0.15s, border-color 0.15s;
}
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.lvl-3 { padding-left: 26px; font-size: 12.5px; opacity: 0.85; }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }
.toc a:hover + a.active { }
.toc .meta { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); }
.toc .meta a { border-left: none; padding-left: 0; font-size: 12.5px; }
.toc .meta .row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
.toc .meta .k { color: var(--muted); }
.toc .meta .v { font-family: var(--mono); font-size: 11.5px; color: var(--accent); text-align: right; }

/* ---------- edit / feedback ---------- */
.feedback {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 26px; padding: 14px 18px;
  background: var(--card-2); border: 1px dashed var(--border); border-radius: 12px;
  font-size: 13.5px; color: var(--muted);
}

/* ---------- footer ---------- */
footer.bottom {
  border-top: 1px solid var(--border); background: var(--bg-2);
  padding: 26px 0; margin-top: 20px;
}
.foot-inner {
  max-width: 1440px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  font-size: 13.5px; color: var(--muted);
}
.foot-links { display: flex; gap: 20px; flex-wrap: wrap; }
.foot-links a { color: var(--muted); }
.foot-links a:hover { color: var(--accent); }

/* ---------- scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1240px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 28px; }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .side-toggle { display: grid; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    width: 282px; max-height: none; z-index: 190;
    background: var(--bg-2); border-right: 1px solid var(--border);
    padding: 20px 12px; transform: translateX(-100%);
    transition: transform 0.22s ease; overflow-y: auto;
  }
  .sidebar.open { transform: none; }
  .scrim {
    position: fixed; inset: var(--header-h) 0 0; background: rgba(0, 0, 0, 0.55);
    z-index: 180; display: none;
  }
  .scrim.open { display: block; }
  .top-search { max-width: none; }
  .logo .sub, .logo .sep { display: none; }
  .pager { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  body { font-size: 15.5px; }
  .top-search input { font-size: 13px; }
  .content { padding-top: 18px; }
  .prose > h2 { font-size: 22px; }
  .step { padding-left: 34px; }
  .step::before { left: -14px; width: 27px; height: 27px; font-size: 13px; }
  .th, .nowrap { white-space: normal; }
}

@media print {
  header.top, .sidebar, .toc, .pager, #progress, footer.bottom, .copy-btn { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; }
}
