:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev2: #1c2230;
  --border: #2a313c;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --accent: #4dd4ac;
  --accent-2: #6ea8fe;
  --warn: #f0b429;
  --danger: #f2597f;
  --radius: 12px;
  --maxw: 1180px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-elev: #ffffff;
  --bg-elev2: #eef1f5;
  --border: #d5dbe2;
  --text: #1c2128;
  --text-dim: #57606a;
  --accent: #1a8f6f;
  --accent-2: #2f6feb;
  --warn: #b7791f;
  --danger: #d63864;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

code { font-family: var(--mono); font-size: 0.88em; }
:not(pre) > code {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  padding: 0.08em 0.4em;
  border-radius: 6px;
  white-space: nowrap;
}
.accent { color: var(--accent); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; gap: 1.2rem;
  padding: 0.7rem 1.2rem;
}
.brand { display: flex; align-items: center; gap: 0.55rem; text-decoration: none; color: var(--text); }
.brand-mark { color: var(--accent); font-size: 1.3rem; }
.brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.05; }
.brand-sub { font-size: 0.68rem; font-weight: 500; color: var(--text-dim); letter-spacing: 0.06em; text-transform: uppercase; }
.topnav { display: flex; gap: 1.1rem; margin-left: auto; flex-wrap: wrap; }
.topnav a { color: var(--text-dim); text-decoration: none; font-size: 0.9rem; font-weight: 500; }
.topnav a:hover { color: var(--accent); }
.theme-toggle {
  background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer; font-size: 1rem;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---------- Layout ---------- */
.layout { max-width: var(--maxw); margin: 0 auto; display: flex; gap: 2rem; padding: 0 1.2rem; }
.sidebar { width: 240px; flex-shrink: 0; }
.toc { position: sticky; top: 76px; padding: 1.2rem 0; }
.toc-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); margin: 0 0 0.6rem; }
.toc ol { list-style: none; margin: 0; padding: 0; counter-reset: none; }
.toc li { margin: 0.15rem 0; }
.toc a { color: var(--text-dim); text-decoration: none; font-size: 0.86rem; display: block; padding: 0.28rem 0.6rem; border-left: 2px solid transparent; border-radius: 0 6px 6px 0; }
.toc a:hover, .toc a.active { color: var(--text); background: var(--bg-elev); border-left-color: var(--accent); }
.toc-note { font-size: 0.72rem; color: var(--text-dim); margin-top: 1.2rem; line-height: 1.4; }

.content { flex: 1; min-width: 0; padding-bottom: 4rem; }

/* ---------- Hero ---------- */
.hero { padding: 2.6rem 0 1.4rem; border-bottom: 1px solid var(--border); }
.hero h1 { font-size: 2.3rem; margin: 0 0 0.7rem; line-height: 1.15; }
.lede { font-size: 1.08rem; color: var(--text-dim); max-width: 62ch; }
.lede strong { color: var(--text); }
.pill-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.3rem; }
.pill { font-size: 0.78rem; padding: 0.3rem 0.7rem; border-radius: 20px; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim); }

/* ---------- Sections ---------- */
section { padding: 2.2rem 0; border-bottom: 1px solid var(--border); scroll-margin-top: 70px; }
section:last-of-type { border-bottom: none; }
h2 { font-size: 1.5rem; display: flex; align-items: center; gap: 0.7rem; margin: 0 0 1rem; }
h3 { font-size: 1.08rem; margin: 1.6rem 0 0.6rem; }
h4 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #06231a; font-size: 0.95rem; font-weight: 700; flex-shrink: 0;
}
:root[data-theme="light"] .num { color: #fff; }
p { margin: 0.6rem 0; }
.fineprint { font-size: 0.86rem; color: var(--text-dim); }

/* ---------- Diagram ---------- */
.diagram-figure { margin: 1.4rem 0 0; }
.diagram-scroll { overflow-x: auto; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem; }
#pipeline { width: 100%; min-width: 720px; height: auto; display: block; }
.node rect { fill: var(--bg-elev2); stroke: var(--border); stroke-width: 1.5; transition: stroke 0.15s, fill 0.15s; cursor: pointer; }
.node:hover rect, .node:focus rect, .node.selected rect { stroke: var(--accent); fill: color-mix(in srgb, var(--accent) 14%, var(--bg-elev2)); outline: none; }
.node { outline: none; }
.node-title { fill: var(--text); font-size: 14px; font-weight: 600; text-anchor: middle; font-family: var(--font); pointer-events: none; }
.node-sub { fill: var(--text-dim); font-size: 10.5px; text-anchor: middle; font-family: var(--font); pointer-events: none; }
.edges line { stroke: var(--text-dim); stroke-width: 1.6; opacity: 0.55; }
.arrowhead { fill: var(--text-dim); }
figcaption { margin-top: 0.8rem; }
.hint { font-size: 0.8rem; color: var(--text-dim); }
.node-detail {
  margin-top: 0.6rem; padding: 0.8rem 1rem; background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 8px; font-size: 0.9rem; color: var(--text);
}

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-top: 1rem; }
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.card h3 { margin: 0 0 0.5rem; font-size: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.tag { font-size: 0.66rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text-dim); padding: 0.12rem 0.5rem; border-radius: 12px; }
.repo-list { list-style: none; margin: 0; padding: 0; }
.repo-list li { padding: 0.3rem 0; border-top: 1px solid var(--border); font-size: 0.86rem; }
.repo-list li:first-child { border-top: none; }
.repo-list span { color: var(--text-dim); }

/* ---------- Callouts ---------- */
.callout { border-radius: var(--radius); padding: 0.9rem 1.1rem; margin: 1.3rem 0; font-size: 0.92rem; border: 1px solid var(--border); border-left-width: 4px; background: var(--bg-elev); }
.callout-info { border-left-color: var(--accent-2); }
.callout-warn { border-left-color: var(--warn); }

/* ---------- Steps ---------- */
.steps { list-style: none; counter-reset: step; margin: 1rem 0 0; padding: 0; }
.steps li { position: relative; padding: 0 0 1.2rem 2.6rem; counter-increment: step; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%; background: var(--bg-elev2); border: 1px solid var(--accent);
  color: var(--accent); font-weight: 700; font-size: 0.82rem; display: flex; align-items: center; justify-content: center;
}
.steps li::after { content: ""; position: absolute; left: 13.5px; top: 28px; bottom: 0; width: 1px; background: var(--border); }
.steps li:last-child::after { display: none; }
.step-k { font-weight: 600; color: var(--text); }
.steps p { margin: 0.25rem 0 0; font-size: 0.9rem; color: var(--text-dim); }

/* ---------- Kargo flow ---------- */
.kargo-flow { display: flex; align-items: stretch; gap: 0.6rem; margin: 1.2rem 0; flex-wrap: wrap; }
.kargo-box { flex: 1; min-width: 200px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.kargo-box p { font-size: 0.85rem; color: var(--text-dim); margin: 0.3rem 0 0; }
.kargo-arrow { display: flex; align-items: center; color: var(--accent); font-size: 1.4rem; }
.badge { font-size: 0.68rem; padding: 0.1rem 0.45rem; border-radius: 10px; font-weight: 600; }
.badge-ok { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.badge-manual { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; margin: 1rem 0; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-elev2); font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* ---------- Code blocks ---------- */
pre.code { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; overflow-x: auto; font-size: 0.84rem; line-height: 1.55; }
pre.code code { color: var(--text); }

/* ---------- Checklist ---------- */
.checklist { list-style: none; margin: 1rem 0 0; padding: 0; }
.checklist li { position: relative; padding: 0.3rem 0 0.3rem 1.9rem; font-size: 0.9rem; }
.checklist li::before { content: "✓"; position: absolute; left: 0; top: 0.3rem; color: var(--accent); font-weight: 700; }

/* ---------- Risks ---------- */
.risk { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1rem 0; background: var(--bg-elev); border-left-width: 4px; }
.risk-high { border-left-color: var(--danger); }
.risk-med { border-left-color: var(--warn); }
.risk-low { border-left-color: var(--text-dim); }
.risk-head { font-weight: 600; margin-bottom: 0.4rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.sev { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.12rem 0.5rem; border-radius: 10px; font-weight: 700; }
.risk-high .sev { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }
.risk-med .sev { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.risk-low .sev { background: var(--bg-elev2); color: var(--text-dim); }
.risk p { font-size: 0.9rem; margin: 0.4rem 0 0; }
.reco { color: var(--text); }
.reco strong { color: var(--accent); }

/* ---------- Footer ---------- */
.page-footer { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.page-footer p { font-size: 0.82rem; color: var(--text-dim); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .topnav { display: none; }
  .hero h1 { font-size: 1.8rem; }
}
