/* ══════════════════════════════════════════════════════════════════════
   Terranoetis documentation — shared design system
   Single stylesheet for every docs page. No CDN dependencies.
   Light-first with dark variant; all text/background pairs meet WCAG 2.1 AA.
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --c-bg: #ffffff;
  --c-bg-subtle: #f6f8fa;
  --c-bg-raised: #ffffff;
  --c-border: #d8dee4;
  --c-text: #1f2328;         /* 15.0:1 on --c-bg */
  --c-text-muted: #59636e;   /*  5.9:1 on --c-bg */
  --c-link: #0b5cad;         /*  5.3:1 on --c-bg */
  --c-link-hover: #08427b;
  --c-accent: #0b5cad;
  --c-banner-bg: #1c2a3a;
  --c-banner-text: #e9eef4;
  --c-code-bg: #f6f8fa;
  --c-code-text: #1f2328;

  --c-ok-bg: #dafbe1;    --c-ok-text: #116329;    /* measured/verified */
  --c-inspect-bg: #ddf4ff; --c-inspect-text: #0a5379; /* inspection callout accent */
  --c-caution-bg: #fff8c5; --c-caution-text: #7a5e00; /* known limitation */
  --c-error-bg: #ffebe9;   --c-error-text: #a40e26;   /* failed gate / rejected */

  --sidebar-w: 19rem;
  --content-max: 62rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg: #0d1117;
    --c-bg-subtle: #161b22;
    --c-bg-raised: #161b22;
    --c-border: #3d444d;
    --c-text: #e6edf3;          /* 13.4:1 */
    --c-text-muted: #9198a1;    /*  5.4:1 */
    --c-link: #7cc0ff;          /*  7.5:1 */
    --c-link-hover: #a8d4ff;
    --c-accent: #7cc0ff;
    --c-banner-bg: #010409;
    --c-banner-text: #e6edf3;
    --c-code-bg: #161b22;
    --c-code-text: #e6edf3;

    --c-ok-bg: #0f2c1a;    --c-ok-text: #6ee39a;
    --c-inspect-bg: #0c2d45; --c-inspect-text: #7cc0ff;
    --c-caution-bg: #3d3300; --c-caution-text: #f0d96b;
    --c-error-bg: #461512;   --c-error-text: #ff908a;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--c-text);
  background: var(--c-bg);
}

/* ── Skip link (keyboard accessibility) ─────────────────────────────── */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--c-accent); color: #fff; padding: 0.5rem 1rem;
}
.skip-link:focus { left: 0; }

/* ── Site banner ────────────────────────────────────────────────────── */
.site-banner {
  position: sticky; top: 0; z-index: 50;
  /* Modern glass banner: translucent navy gradient over blurred content */
  background: linear-gradient(180deg, rgba(19, 30, 48, 0.92), rgba(13, 22, 36, 0.88));
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  backdrop-filter: blur(14px) saturate(1.5);
  color: var(--c-banner-text);
  border-bottom: 1px solid rgba(56, 189, 248, 0.28);
  box-shadow: 0 4px 24px rgba(2, 8, 23, 0.35);
}
.site-banner-inner {
  max-width: 88rem; margin: 0 auto; padding: 0.65rem 1.25rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: nowrap;
  /* Constant banner height across every page (32px content + 2×0.65rem padding). */
  min-height: 3.3rem;
}
/* Brand wordmark — single source of truth, identical on every page
   (matches the landing header: logo + Syncopate gradient TERRA/NOETIS). */
.site-banner a.brand {
  flex-shrink: 0;
  color: inherit; text-decoration: none;
  font-family: 'Syncopate', sans-serif !important;
  font-weight: 700 !important;
  font-size: 0.9rem !important;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.brand-logo { border-radius: 8px; margin-right: 8px; vertical-align: middle; box-shadow: 0 0 12px rgba(56, 189, 248, 0.45); }
.site-banner a.brand .terra {
  background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.site-banner a.brand .noetis {
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.site-banner .brand small { font-weight: 400; opacity: 0.85; margin-left: 0.5rem; }
.top-nav { display: flex; gap: 0.25rem; flex-wrap: nowrap; margin-left: auto; }
.top-nav a {
  color: var(--c-banner-text); text-decoration: none; font-size: 0.85rem;
  padding: 0.3rem 0.7rem; border-radius: 999px; white-space: nowrap;
  transition: background-color 0.18s ease, color 0.18s ease;
}
/* Bright sky-blue hover (brand palette) — beats the global dark-blue a:hover
   rule, which was invisible on the dark banner. */
.top-nav a:hover { color: #7dd3fc; background: rgba(56, 189, 248, 0.18); }
.top-nav a[aria-current="page"] { color: #7dd3fc; background: rgba(56, 189, 248, 0.22); box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.4); }
/* Demo tag chip: rounded box badge with inset ring + soft sky-blue glow pulse */
.top-nav a.nav-demo {
  border-radius: 8px;
  color: #e0f2fe;
  background: rgba(56, 189, 248, 0.16);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.55);
  font-weight: 600;
  animation: demo-glow 2.4s ease-in-out infinite;
}
.top-nav a.nav-demo:hover { color: #fff; background: rgba(56, 189, 248, 0.3); }
@keyframes demo-glow {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.55), 0 0 0 0 rgba(56, 189, 248, 0.35); }
  50%      { box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.8), 0 0 14px 2px rgba(56, 189, 248, 0.4); }
}
.top-nav a:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
/* Mid widths: tighten the nav so the 7-link docs bar stays on one line
   (keeps banner height identical to the landing page). */
@media (max-width: 1023px) {
  .site-banner-inner { gap: 0.75rem; }
  .top-nav a { font-size: 0.8rem; padding: 0.3rem 0.45rem; }
}
/* Mobile: allow the banner to wrap (height grows by design below 860px). */
@media (max-width: 860px) {
  .site-banner-inner { flex-wrap: wrap; }
  .top-nav { margin-left: 0; }
}

/* ── Layout ─────────────────────────────────────────────────────────── */
.layout { max-width: 88rem; margin: 0 auto; display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.sidebar {
  border-right: 1px solid var(--c-border);
  padding: 1.25rem 0.75rem 2rem 1.25rem;
  font-size: 0.875rem;
}
@media (max-width: 900px) { .sidebar { border-right: 0; border-bottom: 1px solid var(--c-border); } }
.sidebar h2 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--c-text-muted); margin: 1.25rem 0 0.35rem;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0.05rem 0; }
.sidebar a { color: var(--c-text); text-decoration: none; display: block;
  padding: 0.16rem 0.45rem; border-radius: 4px; }
.sidebar a:hover { background: var(--c-bg-subtle); text-decoration: underline; }
.sidebar a[aria-current="true"] {
  background: var(--c-bg-subtle); color: var(--c-link); font-weight: 600;
}
.sidebar a:focus-visible { outline: 2px solid var(--c-accent); }

main { padding: 1.5rem 2rem 4rem; min-width: 0; }
@media (max-width: 900px) { main { padding: 1rem 1rem 3rem; } }
.content { max-width: var(--content-max); }

/* ── Breadcrumbs + meta strip ───────────────────────────────────────── */
.breadcrumbs { font-size: 0.8rem; color: var(--c-text-muted); margin-bottom: 1rem; }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0; padding: 0; }
.breadcrumbs li + li::before { content: "›"; margin-right: 0.3rem; }
.breadcrumbs a { color: var(--c-link); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

.page-meta {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center;
  font-size: 0.78rem; color: var(--c-text-muted);
  border: 1px solid var(--c-border); border-radius: 6px;
  background: var(--c-bg-subtle); padding: 0.45rem 0.75rem; margin-bottom: 1.5rem;
}
.page-meta strong { color: var(--c-text); font-weight: 600; }

h1 { font-size: 1.85rem; line-height: 1.25; margin: 0 0 0.4rem; }
h2 { font-size: 1.35rem; margin: 2.2rem 0 0.6rem; border-bottom: 1px solid var(--c-border); padding-bottom: 0.25rem; }
h3 { font-size: 1.1rem; margin: 1.6rem 0 0.5rem; }
h4 { font-size: 0.98rem; margin: 1.2rem 0 0.4rem; }
p { margin: 0.6rem 0; }
.lede { font-size: 1.05rem; color: var(--c-text); margin-bottom: 1rem; }

a { color: var(--c-link); }
a:hover { color: var(--c-link-hover); }

/* ── Tags (honesty labels, statuses) ────────────────────────────────── */
.tag {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 0.08rem 0.5rem; border-radius: 999px; white-space: nowrap;
  font-family: var(--font-mono);
}
.tag-measured { background: var(--c-ok-bg); color: var(--c-ok-text); }
.tag-caution { background: var(--c-caution-bg); color: var(--c-caution-text); }
.tag-error { background: var(--c-error-bg); color: var(--c-error-text); }

/* ── Tables ─────────────────────────────────────────────────────────── */
table { border-collapse: collapse; width: 100%; margin: 0.8rem 0 1.4rem; font-size: 0.855rem; }
caption { caption-side: top; text-align: left; font-size: 0.8rem; color: var(--c-text-muted); padding: 0.25rem 0; }
th, td { border: 1px solid var(--c-border); padding: 0.4rem 0.55rem; text-align: left; vertical-align: top; }
th { background: var(--c-bg-subtle); font-weight: 600; }
tr:nth-child(even) td { background: color-mix(in srgb, var(--c-bg-subtle) 55%, var(--c-bg)); }
.table-scroll { overflow-x: auto; }

/* ── Code ───────────────────────────────────────────────────────────── */
code, kbd, samp { font-family: var(--font-mono); font-size: 0.83em; overflow-wrap: anywhere; }
main a { overflow-wrap: anywhere; }
code { background: var(--c-code-bg); color: var(--c-code-text); padding: 0.08em 0.35em; border-radius: 4px; border: 1px solid var(--c-border); }
pre { background: var(--c-code-bg); border: 1px solid var(--c-border); border-radius: 6px;
  padding: 0.8rem 1rem; overflow-x: auto; font-size: 0.82rem; line-height: 1.5; }
pre code { background: none; border: 0; padding: 0; font-size: inherit; }

/* file:line citation chip */
cite.src {
  font-style: normal; font-family: var(--font-mono); font-size: 0.8rem;
  color: var(--c-text-muted); white-space: normal; overflow-wrap: anywhere;
}
cite.src::before { content: "⌗ "; }

/* ── Equation blocks ────────────────────────────────────────────────── */
figure.equation {
  margin: 0.9rem 0; padding: 0.8rem 1rem;
  background: var(--c-bg-subtle); border-left: 3px solid var(--c-accent); border-radius: 0 6px 6px 0;
}
figure.equation .formula {
  font-family: var(--font-mono); font-size: 0.95rem; display: block; overflow-x: auto; white-space: pre;
}
figure.equation figcaption { font-size: 0.78rem; color: var(--c-text-muted); margin-top: 0.45rem; }

/* ── Callouts ───────────────────────────────────────────────────────── */
.callout { border: 1px solid var(--c-border); border-left-width: 4px; border-radius: 6px;
  padding: 0.7rem 0.95rem; margin: 1rem 0; font-size: 0.9rem; }
.callout h4, .callout .callout-title { margin: 0 0 0.3rem; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; }
.callout-verified { border-left-color: var(--c-ok-text); }
.callout-inspect { border-left-color: var(--c-inspect-text); }
.callout-caution { border-left-color: var(--c-caution-text); }
.callout-warning { border-left-color: var(--c-error-text); }

/* Verbatim code-quote blocks */
blockquote.verbatim {
  margin: 0.8rem 0; padding: 0.7rem 1rem; font-family: var(--font-mono); font-size: 0.8rem;
  background: var(--c-bg-subtle); border: 1px dashed var(--c-border); border-radius: 6px; white-space: pre-wrap;
}
blockquote.verbatim footer { font-family: var(--font-body); color: var(--c-text-muted); font-size: 0.75rem; margin-top: 0.4rem; }

/* ── Cards (landing grids) ──────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 0.9rem; margin: 1rem 0 1.6rem; }
.card {
  border: 1px solid var(--c-border); border-radius: 8px; padding: 0.9rem 1rem;
  background: var(--c-bg-raised); display: flex; flex-direction: column; gap: 0.35rem;
}
.card a { text-decoration: none; color: var(--c-text); font-weight: 600; }
.card a:hover { text-decoration: underline; }
.card p { margin: 0; font-size: 0.85rem; color: var(--c-text-muted); }
.card .tag { align-self: flex-start; }

/* ── Definition lists ───────────────────────────────────────────────── */
dl.metrics { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; font-size: 0.9rem; }
dl.metrics dt { font-weight: 600; }
dl.metrics dd { margin: 0; }

/* ── Footer ─────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--c-border); margin-top: 3rem; padding: 1rem 0 0;
  font-size: 0.8rem; color: var(--c-text-muted);
}
.site-footer a { color: var(--c-link); }

/* ── On-this-page nav ───────────────────────────────────────────────── */
.toc h2 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--c-text); border: 0; padding: 0; margin: 1.4rem 0 0.4rem; }
.toc ul { list-style: none; margin: 0 0 1.5rem; padding: 0; display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; font-size: 0.88rem; }

/* ── Narrow-screen refinements ──────────────────────────────────────── */
@media (max-width: 640px) {
  .tag { white-space: normal; }
  dl.metrics { grid-template-columns: 1fr; gap: 0.15rem; }
  dl.metrics dt { margin-top: 0.6rem; }
  .page-meta span { overflow-wrap: anywhere; }
  h1 { font-size: 1.5rem; }
  table { font-size: 0.82rem; }
}

/* ── Print ──────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .top-nav, .skip-link { display: none; }
  .layout { grid-template-columns: 1fr; }
  body { font-size: 11pt; }
  a::after { content: " (" attr("href") ")"; font-size: 0.75em; color: #555; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .top-nav a.nav-demo, .gh-star-wrapper { animation: none; } }

/* ── Narrative pages (Markdown-generated) ───────────────────────────── */
.prose { line-height: 1.7; }
.prose h2 { font-size: 1.35rem; margin: 2rem 0 0.75rem; }
.prose h3, .prose h4 { margin: 1.5rem 0 0.5rem; }
.prose p { margin: 0.75rem 0; }
.prose ul, .prose ol { margin: 0.75rem 0; padding-left: 1.5rem; }
.prose li { margin: 0.3rem 0; }
.prose code { background: var(--c-code-bg); color: var(--c-code-text); padding: 0.1rem 0.35rem; border-radius: 4px; font-family: var(--font-mono); font-size: 0.875em; }
.prose pre { background: var(--c-code-bg); border: 1px solid var(--c-border); border-radius: 8px; padding: 0.9rem 1.1rem; overflow-x: auto; margin: 1rem 0; }
.prose pre.mermaid { background: none; border: 0; border-radius: 0; padding: 0; overflow-x: auto; text-align: center; }
.prose pre.mermaid svg { max-width: 100%; height: auto; }
/* Diagram viewer: drag to pan, wheel/buttons to zoom, fullscreen expand */
.diagram-viewer {
  position: relative; overflow: hidden; margin: 1rem 0;
  border: 1px solid var(--c-border); border-radius: 8px;
  background: var(--c-bg-raised); cursor: grab; touch-action: none;
}
.diagram-viewer.grabbing { cursor: grabbing; }
.diagram-viewer > svg { display: block; margin: 0 auto; padding: 0.75rem; max-width: 100%; height: auto; }
.diagram-viewer:fullscreen { background: var(--c-bg); }
.diagram-toolbar {
  position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; z-index: 5;
  opacity: 0.85; transition: opacity 0.15s ease;
}
.diagram-viewer:hover .diagram-toolbar, .diagram-viewer:focus-within .diagram-toolbar { opacity: 1; }
.diagram-toolbar button {
  font: inherit; font-size: 0.78rem; line-height: 1; padding: 0.3rem 0.55rem;
  border: 1px solid var(--c-border); border-radius: 6px;
  background: var(--c-bg-raised); color: var(--c-text); cursor: pointer;
}
.diagram-toolbar button:hover { background: var(--c-bg-subtle); border-color: var(--c-link); }
.diagram-toolbar button:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 1px; }
.prose pre code { background: none; padding: 0; font-size: 0.85rem; line-height: 1.55; }
.prose blockquote { border-left: 3px solid var(--c-accent); margin: 1rem 0; padding: 0.25rem 1rem; color: var(--c-text-muted); }
.prose table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: 0.9rem; }
.prose th, .prose td { border: 1px solid var(--c-border); padding: 0.45rem 0.7rem; text-align: left; }
.prose thead th { background: var(--c-bg-subtle); }
.prose a { color: var(--c-link); }
.prose hr { border: 0; border-top: 1px solid var(--c-border); margin: 2rem 0; }
