/* Tokens copied verbatim from r-knowledge-web/src/app/styles/globals.css */
:root {
  --paper: #fbfcfe;
  --panel: #ffffff;
  --mist: #eef2f8;
  --hairline: #dce3ec;
  --hairline-strong: #c3cedc;
  --ink: #1b2e4a;
  --ink-strong: #122036;
  --ink-muted: #5c6b82;

  --brand-blue: #0066ff;
  --primary: #0057eb;
  --primary-foreground: #ffffff;
  /* Decorative brand accent only. Never a fill behind text: fails contrast on --mist and on white. */
  --similarity: #11e3e3;
  --relation: #7700ff;

  --success-ink: #157f43;
  --warning-ink: #c2510c;

  --radius-sm: 3px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --font-display: 'Archivo', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --font-sans: 'IBM Plex Sans', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'IBM Plex Sans Thai', ui-monospace, monospace;

  --shadow-overlay: 0 8px 28px -8px rgba(18, 32, 54, 0.18);

  --measure: 74ch;
  --sidebar: 250px;
  /* Sticky topbar height. Anchor targets clear it via scroll-margin-top, and the sticky TOC sits
     below it and is capped against it. */
  --topbar-h: 53px;
}

html {
  scroll-behavior: smooth;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  color: var(--ink-strong);
  line-height: 1.25;
  letter-spacing: -0.01em;
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--mist);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.36em;
}
pre {
  font-family: var(--font-mono);
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
}
pre code {
  background: none;
  padding: 0;
}

/* ── Chrome ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(251, 252, 254, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.75rem;
}
.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink-strong);
  font-size: 15px;
  letter-spacing: -0.015em;
}
.wordmark span {
  color: var(--brand-blue);
}
.nav {
  display: flex;
  gap: 1.35rem;
  font-size: 14px;
}
.nav a {
  color: var(--ink-muted);
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
}
.nav a:hover {
  color: var(--ink);
  text-decoration: none;
}
.nav a.active {
  color: var(--ink-strong);
  border-bottom-color: var(--brand-blue);
  font-weight: 500;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}
.prose {
  max-width: var(--measure);
}

/* ── Hero ───────────────────────────────────────────────────────────── */
.hero {
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 2.25rem;
  margin-bottom: 2.25rem;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.7rem;
}
.hero h1 {
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  margin: 0 0 0.85rem;
}
.lede {
  font-size: 17px;
  color: var(--ink-muted);
  max-width: 68ch;
  margin: 0;
}

/* ── Stats ──────────────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--hairline);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 2rem 0;
}
.stat {
  background: var(--panel);
  padding: 1.1rem 1.25rem;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 1.65rem;
  color: var(--ink-strong);
  line-height: 1.1;
}
.stat-label {
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 0.3rem;
}

/* ── Panels ─────────────────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.65rem;
  margin: 1.5rem 0;
}
.panel > :first-child {
  margin-top: 0;
}
.panel > :last-child {
  margin-bottom: 0;
}
.panel-accent {
  border-left: 3px solid var(--similarity);
}

.note {
  background: var(--mist);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.1rem;
  font-size: 14px;
  color: var(--ink);
  margin: 1.25rem 0;
}
.note strong {
  color: var(--ink-strong);
}

/* ── Tables ─────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 1.25rem 0;
}
th,
td {
  text-align: left;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}
th {
  background: var(--mist);
  color: var(--ink-strong);
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.02em;
}
tbody tr:hover {
  background: var(--paper);
}
td.num,
th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
}

/* ── Chips ──────────────────────────────────────────────────────────── */
.chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  padding: 0.13rem 0.42rem;
  border-radius: var(--radius-sm);
  background: var(--mist);
  color: var(--ink-muted);
  border: 1px solid var(--hairline);
  white-space: nowrap;
}
.chip-product {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 28%, var(--hairline));
}
.chip-org {
  color: var(--relation);
  border-color: color-mix(in srgb, var(--relation) 28%, var(--hairline));
}

/* ── Document cards ─────────────────────────────────────────────────── */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 0.9rem;
  margin: 1.25rem 0 2.5rem;
}
.doc-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 1rem 1.15rem;
  color: inherit;
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease;
}
.doc-card:hover {
  border-color: var(--hairline-strong);
  box-shadow: var(--shadow-overlay);
  text-decoration: none;
}
.doc-card h3 {
  margin: 0 0 0.4rem;
  font-size: 15.5px;
  color: var(--ink-strong);
}
.doc-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
}
.doc-sections {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

/* ── Document page ──────────────────────────────────────────────────── */
.doc-layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
}
.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 1.5rem);
  /* Scrolls independently of the article: a long document's section list must not run off-screen. */
  max-height: calc(100vh - var(--topbar-h) - 3rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 13.5px;
  border-left: 1px solid var(--hairline);
  padding-left: 1rem;
  /* Scrollbar hidden by request; the list still scrolls by wheel, trackpad, and keyboard. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.toc::-webkit-scrollbar {
  display: none;
}
.toc-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.6rem;
}
.toc a {
  display: block;
  padding: 0.22rem 0;
  color: var(--ink-muted);
}
.toc a:hover {
  color: var(--primary);
  text-decoration: none;
}
.toc .toc-sub {
  padding-left: 0.8rem;
  font-size: 12.5px;
}

/* Anchor targets clear the sticky topbar, which would otherwise cover the heading jumped to. */
.doc-body h2,
.doc-body h3 {
  scroll-margin-top: calc(var(--topbar-h) + 1.5rem);
}
.doc-body h2 {
  font-size: 1.32rem;
  margin: 2.6rem 0 0.9rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--hairline);
}
.doc-body h3 {
  font-size: 1.02rem;
  margin: 1.9rem 0 0.55rem;
  color: var(--ink-strong);
}
.doc-body ul,
.doc-body ol {
  padding-left: 1.35rem;
  margin: 0.55rem 0;
}
.doc-body li {
  margin: 0.32rem 0;
}
.doc-body li::marker {
  color: var(--ink-muted);
}
.doc-body p {
  margin: 0.6rem 0;
}
.doc-body hr {
  border: 0;
  border-top: 1px solid var(--hairline);
  margin: 2.5rem 0 1.25rem;
}
.doc-body em {
  color: var(--ink-muted);
  font-size: 14px;
}

/* ── Pipeline diagram ───────────────────────────────────────────────── */
.stage {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 1.1rem;
  padding: 1.35rem 0;
  border-bottom: 1px solid var(--hairline);
}
.stage:last-child {
  border-bottom: 0;
}
.stage-num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--primary-foreground);
  background: var(--primary);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.stage-num.passive {
  background: var(--ink-muted);
}
.stage h3 {
  margin: 0.1rem 0 0.35rem;
  font-size: 1.05rem;
}
.stage-cmd {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-bottom: 0.5rem;
}
.stage p {
  margin: 0.45rem 0;
}

footer {
  border-top: 1px solid var(--hairline);
  margin-top: 4rem;
  padding: 1.5rem 0 0;
  font-size: 13px;
  color: var(--ink-muted);
}

@media (max-width: 860px) {
  .doc-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
  }
  .toc {
    position: static;
    /* Not sticky here, so it must flow with the page rather than stay capped and scrollable. */
    max-height: none;
    overflow-y: visible;
    border-left: 0;
    padding-left: 0;
    border-bottom: 1px solid var(--hairline);
    padding-bottom: 1rem;
  }
  .topbar-inner {
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
  }
}
