/* docs.css — Carnegie product documentation
 * Editorial dark theme matching public/index.html (landing).
 * Mobile-first (412px), scales up cleanly.
 *
 * Design principles in carnegie-design-principles skill apply:
 *   - flat surfaces, hairline dividers
 *   - one primary action per screen
 *   - 44pt tap targets, 16px input minimum
 *   - bottom-safe-area for any future bottom-fixed chrome
 */

:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #11141c;
  --surface-hi: #181c26;
  --text: #f4f4f7;
  --text-muted: rgba(244, 244, 247, 0.62);
  --text-faint: rgba(244, 244, 247, 0.38);
  --divider: rgba(255, 255, 255, 0.08);
  --divider-strong: rgba(255, 255, 255, 0.18);
  --accent: #c0a062;
  --accent-soft: rgba(192, 160, 98, 0.14);
  --accent-glow: rgba(192, 160, 98, 0.22);
  --code-bg: #0e1118;
  --code-border: rgba(255, 255, 255, 0.06);
  --topbar-h: 56px;
  --sidebar-w: 280px;
  --toc-w: 240px;
  --content-max: 760px;
  /* No --bottom-safe-area here: the /docs page does not inject the AIR
     annotation dock or the WhatsApp FAB, so no reserved bottom space is
     needed. Carnegie's design-principle #2 (bottom-safe-area ≥ 96px)
     applies to deployed partner pages, not the docs UI. */
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 400 16px/1.6 "DM Sans", ui-sans-serif, system-ui, -apple-system, "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; height: auto; display: block; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; top: -100px; left: 12px; padding: 12px 16px;
  background: var(--accent); color: #1a1407; border-radius: 8px; font-weight: 600;
  z-index: 1000;
}
.skip-link:focus { top: 12px; }

/* ── Top bar ─────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--divider);
}
.hamburger {
  width: 40px; height: 40px; padding: 8px;
  background: transparent; border: 0; cursor: pointer;
  display: inline-flex; flex-direction: column; gap: 4px;
  align-items: stretch; justify-content: center;
}
.hamburger span {
  display: block; height: 2px; background: var(--text); border-radius: 1px;
  transition: transform .2s ease, opacity .2s ease;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
}
.brand img { border-radius: 6px; }
.brand-text { display: inline-flex; flex-direction: column; line-height: 1; gap: 2px; }
.brand-text strong {
  font-family: "Playfair Display", "EB Garamond", Georgia, serif;
  font-weight: 700; font-size: 18px; letter-spacing: -0.01em;
}
.brand-text em {
  font-style: normal; font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-muted);
}
.topbar-spacer { flex: 1; }
.search-trigger {
  display: inline-flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 12px;
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--divider); border-radius: 999px;
  font: inherit; font-size: 14px; cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.search-trigger:hover { border-color: var(--divider-strong); color: var(--text); }
.search-trigger kbd {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px; padding: 2px 6px; background: rgba(255,255,255,0.06);
  border-radius: 4px; color: var(--text-faint);
}
.search-trigger span { display: none; }
.topbar-link {
  font-size: 14px; color: var(--text-muted); padding: 8px 10px;
  border-radius: 8px;
  white-space: nowrap;
}
.topbar-link:hover { color: var(--text); text-decoration: none; background: var(--surface); }

/* Hide ⌘K hint on mobile — no physical keyboard */
@media (max-width: 719px) {
  .search-trigger kbd { display: none; }
}

@media (min-width: 720px) {
  .topbar { padding: 0 24px; gap: 16px; }
  .search-trigger { width: 240px; justify-content: flex-start; }
  .search-trigger span { display: inline; flex: 1; text-align: left; }
}
@media (min-width: 1024px) {
  .hamburger { display: none; }
}

/* ── Layout ──────────────────────────────────────────────────────── */
.layout {
  display: block;
  position: relative;
}
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  width: 86vw; max-width: 320px;
  height: calc(100vh - var(--topbar-h));
  background: var(--bg);
  border-right: 1px solid var(--divider);
  overflow-y: auto;
  padding: 24px 0 32px;
  z-index: 40;
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.sidebar.is-open { transform: translateX(0); }
.sidebar-scrim {
  position: fixed; inset: var(--topbar-h) 0 0 0;
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
  z-index: 39;
}
.sidebar-scrim.is-visible { opacity: 1; pointer-events: auto; }

.sidebar-nav { padding: 0 12px; }
.sidebar-section { margin-bottom: 8px; }
.sidebar-section-title {
  font-family: "DM Sans", sans-serif;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-faint);
  padding: 16px 12px 8px;
  margin: 0;
}
.sidebar-list { list-style: none; margin: 0; padding: 0; }
.sidebar-link {
  display: block;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.4;
  border-radius: 8px;
  text-decoration: none;
  transition: color .12s ease, background .12s ease;
}
.sidebar-link:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.sidebar-link.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 500;
  position: relative;
}
.sidebar-link.is-active::before {
  content: '';
  position: absolute;
  left: -4px; top: 6px; bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; margin-top: 24px;
  border-top: 1px solid var(--divider);
  font-size: 12px;
  color: var(--text-faint);
}
.sidebar-footer a { color: var(--text-faint); }

.main {
  display: block;
  min-height: calc(100vh - var(--topbar-h));
  padding: 32px 20px 48px;
}

.article {
  max-width: var(--content-max);
  margin: 0 auto;
}

.toc { display: none; }

@media (min-width: 1024px) {
  .layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar {
    position: sticky;
    top: var(--topbar-h);
    transform: none;
    width: auto;
    max-width: none;
    height: calc(100vh - var(--topbar-h));
    background: transparent;
  }
  .sidebar-scrim { display: none; }
  .main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--toc-w);
    gap: 48px;
    padding: 48px 48px 64px;
    align-items: start;
  }
  .article {
    max-width: var(--content-max);
    margin: 0;
  }
  .toc {
    display: block;
    position: sticky;
    top: calc(var(--topbar-h) + 32px);
    max-height: calc(100vh - var(--topbar-h) - 64px);
    overflow-y: auto;
    font-size: 13px;
  }
  .toc-label {
    font-size: 11px; font-weight: 600;
    letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 12px;
  }
  .toc-list { list-style: none; margin: 0; padding: 0; }
  .toc-list li { margin: 0; }
  .toc-list a {
    display: block;
    padding: 6px 12px;
    color: var(--text-muted);
    border-left: 2px solid transparent;
    line-height: 1.4;
  }
  .toc-list a:hover { color: var(--text); text-decoration: none; }
  .toc-list a.is-active { color: var(--accent); border-left-color: var(--accent); }
  .toc-list .toc-h3 { padding-left: 24px; font-size: 12px; }
}

@media (min-width: 1440px) {
  :root { --content-max: 820px; }
  .main { padding: 64px 64px 64px; gap: 64px; }
}

/* ── Article typography ──────────────────────────────────────────── */
.article-eyebrow {
  font-family: "DM Sans", sans-serif;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.article h1 {
  font-family: "Playfair Display", "EB Garamond", Georgia, serif;
  font-weight: 700;
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.018em;
  margin: 0 0 16px;
  color: var(--text);
}
.article > p:first-of-type {
  font-size: 18px;
  line-height: 1.55;
  color: var(--text-muted);
  margin: 0 0 32px;
}
.article h2 {
  font-family: "Playfair Display", "EB Garamond", Georgia, serif;
  font-weight: 600;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 48px 0 16px;
  scroll-margin-top: calc(var(--topbar-h) + 24px);
}
.article h3 {
  font-family: "DM Sans", sans-serif;
  font-weight: 600;
  font-size: 18px;
  line-height: 1.3;
  margin: 32px 0 12px;
  scroll-margin-top: calc(var(--topbar-h) + 24px);
  color: var(--text);
}
.article p, .article li {
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
}
.article p { margin: 0 0 16px; }
.article ul, .article ol { margin: 0 0 20px; padding-left: 24px; }
.article li { margin-bottom: 8px; }
.article li > p { margin: 4px 0; }

.article strong { color: var(--text); font-weight: 600; }
.article em { color: var(--text); }

.article blockquote {
  margin: 24px 0;
  padding: 12px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 0 8px 8px 0;
}
.article blockquote p:last-child { margin-bottom: 0; }

.article hr {
  border: 0; border-top: 1px solid var(--divider);
  margin: 48px 0;
}

/* Inline code & code blocks */
.article code {
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  padding: 2px 6px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  color: var(--accent);
}
.article pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 10px;
  padding: 16px 20px;
  margin: 20px 0;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.55;
}
.article pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  font-size: inherit;
}

/* Tables */
.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 14.5px;
  display: block;
  overflow-x: auto;
}
.article table thead { background: var(--surface); }
.article th, .article td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--divider);
}
.article th { font-weight: 600; color: var(--text); }
.article td { color: var(--text-muted); }
.article td strong { color: var(--text); }

/* Callouts via blockquote with leading icon emoji handled by content */
.callout {
  display: block;
  margin: 24px 0;
  padding: 16px 20px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--divider);
}
.callout strong:first-child { display: block; margin-bottom: 6px; color: var(--text); }
.callout.tip { border-color: rgba(192, 160, 98, 0.4); background: var(--accent-soft); }
.callout.warn { border-color: rgba(243, 56, 59, 0.4); background: rgba(243, 56, 59, 0.08); }

/* Prev/Next pager */
.article-pager {
  display: grid; gap: 16px; grid-template-columns: 1fr;
  margin-top: 64px;
}
@media (min-width: 600px) { .article-pager { grid-template-columns: 1fr 1fr; } }
.pager-link {
  display: block;
  padding: 16px 18px;
  border: 1px solid var(--divider);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s ease, background .15s ease;
}
.pager-link:hover { border-color: var(--accent); background: var(--surface); text-decoration: none; }
.pager-link em {
  display: block; font-style: normal;
  font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 4px; font-weight: 600;
}
.pager-link strong { font-weight: 500; font-size: 15px; color: var(--text); }
.pager-link.next { text-align: right; }

/* Article footer (feedback + meta) */
.article-foot {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--text-faint);
  font-size: 13px;
}
.article-foot-feedback {
  display: inline-flex; align-items: center; gap: 10px;
}
.article-foot-question {
  color: var(--text-muted);
}
.foot-vote {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--divider);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.foot-vote:hover { color: var(--text); border-color: var(--divider-strong); }
.foot-vote.is-active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.article-foot-thanks {
  flex-basis: 100%;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
}
.article-foot-meta {
  color: var(--text-faint);
}

/* Skeleton */
.article-skeleton { display: block; animation: pulse 1.6s ease-in-out infinite; }
.sk { background: var(--surface); border-radius: 6px; margin-bottom: 16px; }
.sk-eyebrow { height: 12px; width: 120px; }
.sk-h1 { height: 40px; width: 70%; }
.sk-p { height: 16px; width: 100%; }
.sk-p.short { width: 50%; }
@keyframes pulse { 0%,100%{opacity:.4} 50%{opacity:.7} }

/* Article shows after load */
.article[aria-busy="false"] .article-skeleton { display: none; }

/* 404 / error */
.article-error {
  text-align: center; padding: 64px 0;
}
.article-error h1 {
  font-family: "Playfair Display", serif;
  font-size: 64px; margin-bottom: 12px;
}
.article-error p { color: var(--text-muted); margin-bottom: 24px; }
.article-error a {
  display: inline-block; padding: 12px 24px;
  background: var(--accent); color: #1a1407;
  border-radius: 999px; font-weight: 600;
}
.article-error a:hover { text-decoration: none; background: #d4b274; }

/* ── Search overlay ──────────────────────────────────────────────── */
.search-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 10, 16, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  align-items: start;
  justify-items: center;
  padding: 10vh 16px 16px;
}
.search-overlay[hidden] { display: none; }
.search-panel {
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border: 1px solid var(--divider-strong);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  overflow: hidden;
  font-family: "DM Sans", sans-serif;
}
.search-input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--divider);
  color: var(--text-muted);
}
.search-input-wrap input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  font: inherit;
  /* MUST be 16px+ to prevent iOS Safari zoom on focus */
  font-size: 16px;
  color: var(--text);
  padding: 8px 0;
  min-height: 28px;
}
.search-input-wrap input::placeholder { color: var(--text-faint); }
.search-input-wrap kbd {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px; padding: 2px 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px; color: var(--text-faint);
}

.search-results {
  max-height: 60vh; overflow-y: auto;
  padding: 8px;
}
.search-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
}
.search-result {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
}
.search-result:hover, .search-result.is-active {
  background: var(--surface-hi);
  text-decoration: none;
}
.search-result-title { font-weight: 500; font-size: 14px; }
.search-result-section {
  font-size: 11px; color: var(--text-faint);
  letter-spacing: 0.1em; text-transform: uppercase;
  margin-top: 2px;
}
.search-result-snippet {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}
.search-result mark {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
}

/* Mobile-only — close hamburger animation when open */
.hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* Lock body scroll when overlay open */
body.is-search-open, body.is-sidebar-open { overflow: hidden; }

/* ── Diagram images: tap to zoom (added 2026-05-25) ─────────────────────── */
.article-content img {
  border-radius: 8px;
  border: 1px solid var(--border, #1e293b);
  background: #0b1220;
  cursor: zoom-in;
  transition: opacity 120ms ease;
}
.article-content img:hover { opacity: 0.92; }
.article-content figure { margin: 16px 0; }
.article-content figure figcaption {
  font-size: 12px;
  color: var(--text-dim, #94a3b8);
  text-align: center;
  margin-top: 8px;
  font-style: italic;
}

/* Lightbox overlay */
.img-lightbox {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
  padding: 24px;
  animation: lightbox-in 160ms ease;
}
.img-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  cursor: zoom-out;
}
.img-lightbox-close {
  position: absolute;
  top: 16px; right: 20px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.8);
  color: #e2e8f0;
  border: 1px solid #334155;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.img-lightbox-close:hover { background: #1e293b; }
@keyframes lightbox-in { from { opacity: 0 } to { opacity: 1 } }
body.is-lightbox-open { overflow: hidden; }
