/* X-Harness Docs Portal — Warm Ivory Editorial × Apple Crispness */
:root {
  --bg: #FAFBF8;
  --bg-alt: #F1F4F1;
  --surface: #FFFFFF;
  --ink: #1D1D1F;
  --ink-muted: #5C6066;
  --ink-subtle: #82878F;
  --line: rgba(29, 29, 31, 0.085);
  --line-strong: rgba(29, 29, 31, 0.16);

  --accent: #0071E3;
  --accent-soft: #EEF5FF;
  --teal: #0F766E;
  --teal-soft: #EDF9F5;
  --amber: #C2571A;
  --amber-soft: #FFF5EC;
  --lavender: #6B46C1;
  --lavender-soft: #F4F0FF;
  --err: #C62828;
  --err-soft: #FEF1F1;

  --code-bg: #F3F5F2;
  --code-bar: rgba(29, 29, 31, 0.035);
  --code-ink: #1D1D1F;
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.045), 0 1px 2px rgba(0, 0, 0, 0.03);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #0B0C0E;
  --bg-alt: #14161A;
  --surface: #181A1F;
  --ink: #F5F5F7;
  --ink-muted: #A1A6AE;
  --ink-subtle: #787E88;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);

  --accent: #4DA3FF;
  --accent-soft: rgba(77, 163, 255, 0.14);
  --teal: #30D1B8;
  --teal-soft: rgba(48, 209, 184, 0.13);
  --amber: #FF9F43;
  --amber-soft: rgba(255, 159, 67, 0.14);
  --lavender: #B794F4;
  --lavender-soft: rgba(183, 148, 244, 0.14);
  --err: #FF6B6B;
  --err-soft: rgba(255, 107, 107, 0.14);

  --code-bg: #131519;
  --code-bar: rgba(255, 255, 255, 0.04);
  --code-ink: #E6EAF0;
  --shadow-card: 0 16px 38px rgba(0, 0, 0, 0.42);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.68;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

/* Sticky Topbar */
.docs-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 58px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.docs-topbar-inner {
  max-width: 1380px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.docs-top-left, .docs-top-right { display: flex; align-items: center; gap: 10px; }
.docs-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.95rem; letter-spacing: -0.02em; }
.docs-brand-mark { width: 26px; height: 26px; border-radius: 7px; overflow: hidden; display: inline-flex; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.14); }
.docs-slash { color: var(--ink-subtle); font-size: 0.9rem; }
.docs-crumb { font-weight: 600; font-size: 0.9rem; color: var(--accent); padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); }

.mobile-menu-btn {
  display: none;
  border: 0;
  background: var(--bg-alt);
  color: var(--ink);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  place-items: center;
}

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 0.83rem;
  min-width: 210px;
  transition: border-color 180ms ease, color 180ms ease;
}
.search-trigger:hover { border-color: var(--accent); color: var(--ink); }
.search-placeholder { flex: 1; text-align: left; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  color: var(--ink-muted);
}

.top-pill {
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--ink-muted);
  transition: background-color 160ms ease, color 160ms ease;
}
.top-pill:hover { background: var(--bg-alt); color: var(--ink); }
.theme-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 0;
  background: var(--bg-alt);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 600;
}
.theme-btn:hover { background: var(--line); }

/* 3-Column Docs Shell */
.docs-shell {
  max-width: 1380px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 216px;
  gap: 0;
  min-height: calc(100vh - 58px);
}

/* Left Sidebar */
.docs-sidebar {
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow-y: auto;
  padding: 26px 16px 24px 24px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
}
.side-group { margin-bottom: 22px; }
.side-group-lbl {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-subtle);
  padding: 0 11px 8px;
}
.side-link {
  display: block;
  padding: 7px 11px;
  border-radius: 9px;
  font-size: 0.885rem;
  font-weight: 500;
  color: var(--ink-muted);
  margin-bottom: 2px;
  transition: background-color 150ms ease, color 150ms ease;
}
.side-link:hover { background: var(--bg-alt); color: var(--ink); }
.side-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.side-back-card {
  display: block;
  padding: 13px 14px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  transition: transform 180ms ease, border-color 180ms ease;
}
.side-back-card:hover { transform: translateY(-1px); border-color: var(--accent); }
.side-back-lbl { display: block; font-size: 0.72rem; font-weight: 600; color: var(--teal); margin-bottom: 3px; }
.side-back-card strong { font-size: 0.84rem; color: var(--ink); line-height: 1.35; display: block; }

/* Main Article Column */
.docs-main {
  padding: 36px 48px 72px;
  min-width: 0;
}
.docs-article {
  max-width: 780px;
  margin: 0 auto;
}
.article-head {
  padding-bottom: 24px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}
.article-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.article-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.doc-src-link {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-subtle);
}
.doc-src-link:hover { color: var(--accent); }
.article-head h1 {
  margin: 0 0 10px;
  font-size: clamp(1.85rem, 3vw, 2.35rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.12;
}
.article-lead {
  margin: 0;
  font-size: 1.03rem;
  color: var(--ink-muted);
  line-height: 1.55;
}

/* Article Typography */
.article-body h2 {
  position: relative;
  margin: 42px 0 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 1.36rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  scroll-margin-top: 76px;
}
.article-body h2:first-child { margin-top: 8px; border-top: 0; padding-top: 0; }
.article-body h3 {
  position: relative;
  margin: 28px 0 10px;
  font-size: 1.08rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  scroll-margin-top: 76px;
}
.article-body h4 { margin: 20px 0 8px; font-size: 0.98rem; font-weight: 600; scroll-margin-top: 76px; }
.anchor-link {
  position: absolute;
  left: -22px;
  color: var(--accent);
  opacity: 0;
  font-weight: 500;
  transition: opacity 150ms ease;
}
.article-body h2:hover .anchor-link,
.article-body h3:hover .anchor-link { opacity: 0.8; }

.article-body p { margin: 0 0 15px; color: var(--ink); }
.article-body ul, .article-body ol { margin: 0 0 18px; padding-left: 22px; }
.article-body li { margin-bottom: 7px; }
.article-body a { color: var(--accent); font-weight: 500; }
.article-body a:hover { text-decoration: underline; text-underline-offset: 3px; }
.ext-arrow { font-size: 0.8em; opacity: 0.72; }
.article-body hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }

.article-body code {
  font-family: var(--font-mono);
  font-size: 0.845em;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--code-ink);
  overflow-wrap: anywhere;
}

/* Code Blocks */
.doc-code {
  margin: 18px 0 22px;
  border-radius: 14px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  overflow: hidden;
}
.doc-code-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 14px;
  background: var(--code-bar);
  border-bottom: 1px solid var(--line);
}
.doc-code-lang { font-family: var(--font-mono); font-size: 0.74rem; color: var(--ink-subtle); text-transform: lowercase; }
.doc-copy-btn {
  border: 0;
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.doc-copy-btn:hover { color: var(--accent); }
.doc-code pre {
  margin: 0;
  padding: 15px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.62;
  color: var(--code-ink);
}
.doc-code pre code { background: transparent; padding: 0; font-size: inherit; overflow-wrap: normal; }

/* Callouts & Quotes */
.doc-callout {
  margin: 20px 0 22px;
  padding: 15px 18px;
  border-radius: 14px;
  border-left: 3.5px solid var(--accent);
  background: var(--accent-soft);
}
.callout-tip { border-left-color: var(--teal); background: var(--teal-soft); }
.callout-important { border-left-color: var(--lavender); background: var(--lavender-soft); }
.callout-warning { border-left-color: var(--amber); background: var(--amber-soft); }
.callout-caution { border-left-color: var(--err); background: var(--err-soft); }
.callout-title {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  color: var(--ink);
}
.callout-body p:last-child { margin-bottom: 0; }
.doc-quote {
  margin: 18px 0;
  padding: 14px 18px;
  border-left: 3px solid var(--line-strong);
  background: var(--surface);
  border-radius: 0 12px 12px 0;
  color: var(--ink-muted);
}
.doc-quote p:last-child { margin-bottom: 0; }

/* Tables */
.doc-table-wrap {
  margin: 18px 0 24px;
  overflow-x: auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
.doc-table th, .doc-table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.doc-table tr:last-child td { border-bottom: 0; }
.doc-table th {
  font-size: 0.79rem;
  font-weight: 650;
  color: var(--ink-muted);
  background: var(--bg-alt);
}

/* Figures */
.doc-fig {
  margin: 22px 0 26px;
  padding: 14px;
  border-radius: 16px;
  background: #FFFFFF;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.doc-fig img { width: 100%; height: auto; border-radius: 8px; }
.doc-fig figcaption {
  margin-top: 10px;
  font-size: 0.82rem;
  color: #5C6066;
  text-align: center;
}

/* Feature & Navigation Pastel Cards (RoboAgentLab-inspired scannability) */
.doc-card-grid { display: grid; gap: 14px; margin: 18px 0 24px; }
.doc-card-grid.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.doc-card-grid.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.doc-feature-card, .doc-nav-card {
  padding: 18px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.doc-nav-card {
  color: var(--ink) !important;
  text-decoration: none !important;
  transition: transform 180ms ease, border-color 180ms ease;
}
.doc-nav-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.doc-feature-card.tone-sky, .doc-nav-card.tone-sky { background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface) 44%); }
.doc-feature-card.tone-mint, .doc-nav-card.tone-mint { background: linear-gradient(180deg, var(--teal-soft) 0%, var(--surface) 44%); }
.doc-feature-card.tone-amber, .doc-nav-card.tone-amber { background: linear-gradient(180deg, var(--amber-soft) 0%, var(--surface) 44%); }
.doc-pill {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 650;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-muted);
}
.doc-feature-card h3, .doc-nav-card h3 { margin: 4px 0 2px !important; font-size: 1rem !important; }
.doc-feature-card p, .doc-nav-card p { margin: 0; font-size: 0.87rem; color: var(--ink-muted); line-height: 1.52; }
.doc-mini-code { margin-top: auto !important; padding-top: 8px; }
.doc-mini-code code { display: block; font-size: 0.76rem; overflow-x: auto; padding: 7px 9px; }

/* Visual Flow Card (replaces Mermaid diagram cleanly without CDN) */
.doc-flow-card {
  margin: 20px 0 26px;
  padding: 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.doc-flow-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 0.83rem;
  color: var(--ink-muted);
}
.doc-flow-badge {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 999px;
}
.doc-flow-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.doc-flow-step { padding: 14px 15px; border-radius: 13px; border: 1px solid var(--line); }
.doc-flow-step.tone-sky { background: var(--accent-soft); }
.doc-flow-step.tone-lavender { background: var(--lavender-soft); }
.doc-flow-step.tone-mint { background: var(--teal-soft); }
.doc-flow-step.tone-amber { background: var(--amber-soft); }
.doc-flow-num { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; color: var(--ink-muted); margin-bottom: 4px; }
.doc-flow-step h4 { margin: 0 0 6px !important; font-size: 0.94rem; }
.doc-flow-step p { margin: 0 0 6px; font-size: 0.835rem; color: var(--ink); line-height: 1.48; }
.doc-flow-step p:last-child { margin-bottom: 0; }

/* Prev / Next Pager */
.docs-pager {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.pager-btn {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 160ms ease, transform 160ms ease;
}
.pager-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.pager-next { grid-column: 2; text-align: right; }
.pager-dir { font-size: 0.76rem; color: var(--ink-subtle); }
.pager-btn strong { font-size: 0.92rem; color: var(--accent); }

/* Right TOC */
.docs-toc {
  padding: 28px 20px 24px 12px;
}
.toc-inner {
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 106px);
  overflow-y: auto;
}
.toc-heading {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-subtle);
  margin-bottom: 10px;
}
.toc-links { display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.toc-link {
  padding: 5px 0 5px 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  font-size: 0.81rem;
  line-height: 1.38;
  color: var(--ink-muted);
  transition: color 140ms ease, border-color 140ms ease;
}
.toc-link.lvl-3 { padding-left: 22px; font-size: 0.78rem; }
.toc-link:hover { color: var(--ink); }
.toc-link.is-active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

/* Search Modal */
.search-modal[hidden] { display: none; }
.search-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: start center;
  padding: 10vh 16px 24px;
}
.search-dialog {
  width: min(620px, 100%);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 28px 72px rgba(0, 0, 0, 0.32);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.search-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-muted);
}
#search-input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.98rem;
  font-family: inherit;
}
.search-results {
  max-height: 54vh;
  overflow-y: auto;
  padding: 8px;
}
.search-item {
  display: block;
  padding: 10px 12px;
  border-radius: 11px;
  transition: background-color 120ms ease;
}
.search-item:hover, .search-item.is-selected { background: var(--accent-soft); }
.search-item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.search-item-title { font-weight: 600; font-size: 0.9rem; color: var(--ink); }
.search-item-page { font-family: var(--font-mono); font-size: 0.72rem; color: var(--accent); }
.search-item-snip { font-size: 0.81rem; color: var(--ink-muted); margin-top: 3px; line-height: 1.4; }
.search-item mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.search-empty { padding: 28px 16px; text-align: center; font-size: 0.88rem; color: var(--ink-muted); }
.search-foot {
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-alt);
  display: flex;
  gap: 18px;
  font-size: 0.75rem;
  color: var(--ink-subtle);
}

.sidebar-backdrop { display: none; }

@media (max-width: 1120px) {
  .docs-shell { grid-template-columns: 236px minmax(0, 1fr); }
  .docs-toc { display: none; }
  .docs-main { padding: 32px 32px 64px; }
}
@media (max-width: 820px) {
  .docs-topbar-inner { padding: 0 14px; gap: 8px; }
  .docs-top-left, .docs-top-right { gap: 7px; }
  .docs-brand { white-space: nowrap; font-size: 0.9rem; }
  .docs-crumb { font-size: 0.82rem; padding: 3px 8px; }
  .mobile-menu-btn { display: grid; }
  .top-pill { display: none; }
  .search-trigger { min-width: 0; padding: 7px 9px; }
  .search-placeholder, .search-trigger kbd { display: none; }
  .docs-shell { grid-template-columns: 1fr; }
  .docs-sidebar {
    position: fixed;
    left: 0;
    top: 58px;
    width: 272px;
    background: var(--bg);
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 220ms ease;
    box-shadow: 12px 0 36px rgba(0, 0, 0, 0.18);
  }
  .docs-sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-open {
    display: block;
    position: fixed;
    inset: 58px 0 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.36);
  }
  .docs-main { padding: 24px 18px 56px; }
  .doc-card-grid.two-col, .doc-card-grid.three-col, .doc-flow-grid, .docs-pager { grid-template-columns: 1fr; }
  .pager-next { grid-column: auto; text-align: left; }
}
