/* site.css — Agentic Systems research site.
   Dark/light themes via [data-theme]; sticky topbar/sidebar/content layout;
   component styles for hero, glossary terms, tabs, walkthroughs, message
   examples, comparison tables, Mermaid diagrams, and a responsive sidebar. */

/* ---- Theme tokens ---- */
:root {
  --maxw: 1180px;
  --measure: 70ch;
  --sidebar-w: 252px;
  --topbar-h: 56px;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --space: 1rem;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", "Fira Code", Consolas,
    "Liberation Mono", Menlo, monospace;

  /* Fluid type scale */
  --fs-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --fs-h1: clamp(1.9rem, 1.5rem + 1.6vw, 2.6rem);
  --fs-h2: clamp(1.35rem, 1.18rem + 0.7vw, 1.65rem);
  --fs-h3: clamp(1.12rem, 1.04rem + 0.35vw, 1.3rem);
  --fs-summary: clamp(1.05rem, 1rem + 0.35vw, 1.2rem);
}

html[data-theme="dark"] {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2230;
  --bg-code: #0a0d12;
  --fg: #e6edf3;
  --fg-muted: #9aa6b2;
  --fg-faint: #6b7681;
  --border: #2a313c;
  --border-soft: #20262f;
  --accent: #6cb6ff;
  --accent-strong: #8ecbff;
  --accent-soft: rgba(108, 182, 255, 0.16);
  --accent-faint: rgba(108, 182, 255, 0.08);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --hero-glow: radial-gradient(
    1100px 380px at 12% -10%,
    rgba(108, 182, 255, 0.16),
    transparent 60%
  );
  --selection: rgba(108, 182, 255, 0.3);
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-elev-2: #eef1f5;
  --bg-code: #f2f4f7;
  --fg: #1f2328;
  --fg-muted: #59636e;
  --fg-faint: #818b96;
  --border: #d0d7de;
  --border-soft: #e4e8ed;
  --accent: #0969da;
  --accent-strong: #0a5ec2;
  --accent-soft: rgba(9, 105, 218, 0.1);
  --accent-faint: rgba(9, 105, 218, 0.05);
  --shadow: 0 6px 24px rgba(140, 149, 159, 0.25);
  --shadow-sm: 0 1px 3px rgba(140, 149, 159, 0.2);
  --hero-glow: radial-gradient(
    1100px 380px at 12% -10%,
    rgba(9, 105, 218, 0.1),
    transparent 60%
  );
  --selection: rgba(9, 105, 218, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 1rem);
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

::selection {
  background: var(--selection);
}

a {
  color: var(--accent);
  text-decoration: none;
  text-decoration-color: var(--accent-soft);
  text-underline-offset: 0.18em;
  transition: color 0.12s ease, text-decoration-color 0.12s ease;
}
a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

img,
svg {
  max-width: 100%;
}

hr {
  height: 1px;
  margin: 2rem 0;
  border: 0;
  background: var(--border);
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  height: var(--topbar-h);
  padding: 0 1.1rem;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--fg);
  white-space: nowrap;
}
.topbar .brand::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 0 0 3px var(--accent-faint);
}
.topbar .brand:hover {
  text-decoration: none;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.nav-toggle:hover {
  border-color: var(--accent);
}

#search-box {
  flex: 1 1 auto;
  max-width: 460px;
  margin-left: auto;
  padding: 0.45rem 0.75rem;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
#search-box::placeholder {
  color: var(--fg-faint);
}
#search-box:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#theme-toggle {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  font-size: 1.05rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s ease, background 0.12s ease;
}
#theme-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-faint);
}

/* ---- Search results overlay ---- */
#search-results {
  position: fixed;
  top: calc(var(--topbar-h) + 6px);
  right: 1rem;
  z-index: 50;
  width: min(480px, calc(100vw - 2rem));
  max-height: 70vh;
  overflow-y: auto;
  padding: 0.4rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#search-results[hidden] {
  display: none;
}
#search-results .result {
  display: block;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--fg);
}
#search-results .result:hover {
  background: var(--accent-soft);
  text-decoration: none;
}
#search-results .result .r-title {
  font-weight: 600;
}
#search-results .result .r-section {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
}
#search-results .result .r-summary {
  font-size: 0.85rem;
  color: var(--fg-muted);
}
#search-results .empty {
  padding: 0.6rem;
  color: var(--fg-muted);
}

/* ---- Layout ---- */
.layout {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 2.5rem;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* ---- Sidebar ---- */
.sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 1.25rem);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 2rem);
  overflow-y: auto;
  padding-right: 0.5rem;
  font-size: 0.92rem;
}
.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sidebar .nav-section {
  margin-bottom: 1.1rem;
}
.sidebar .nav-section-title {
  display: block;
  margin: 0 0 0.35rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--fg-faint);
}
.sidebar li {
  margin: 0.1rem 0;
}
.sidebar .nav-pages a,
.sidebar .nav-extra a {
  position: relative;
  display: block;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  border-left: 2px solid transparent;
}
.sidebar a:hover {
  background: var(--accent-faint);
  color: var(--fg);
  text-decoration: none;
}
.sidebar a.active {
  color: var(--accent-strong);
  font-weight: 600;
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.sidebar .nav-extra {
  margin-top: 0.3rem;
}
.sidebar .nav-extra:first-of-type {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
}

/* ---- Content ---- */
.content {
  min-width: 0;
}
.content .doc {
  max-width: var(--measure);
}

.content h1,
.content h2,
.content h3,
.content h4 {
  line-height: 1.25;
  letter-spacing: -0.012em;
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.content h1 {
  margin: 0 0 0.4rem;
  font-size: var(--fs-h1);
  font-weight: 750;
}
.content h2 {
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.35rem;
  font-size: var(--fs-h2);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.content h3 {
  margin: 1.8rem 0 0.6rem;
  font-size: var(--fs-h3);
  font-weight: 650;
}
.content h4 {
  margin: 1.4rem 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--fg);
}

.content p,
.content li {
  max-width: var(--measure);
}
.content p {
  margin: 0 0 1rem;
}
.content ul,
.content ol {
  margin: 0 0 1rem;
  padding-left: 1.4rem;
}
.content li {
  margin: 0.3rem 0;
}
.content li::marker {
  color: var(--fg-faint);
}

.content strong {
  color: var(--fg);
  font-weight: 680;
}

blockquote {
  margin: 1.25rem 0;
  padding: 0.4rem 1.1rem;
  color: var(--fg-muted);
  background: var(--accent-faint);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
blockquote p:last-child {
  margin-bottom: 0;
}

/* ---- Page head / hero ---- */
.page-head {
  margin-bottom: 2rem;
}
.content p.summary {
  max-width: var(--measure);
  margin: 0.25rem 0 0;
  font-size: var(--fs-summary);
  line-height: 1.5;
  color: var(--fg-muted);
}

/* Working-note banner — research briefs carry a visible tier notice.
   Theme tokens keep it correct in both dark and light. */
.content p.brief-notice {
  max-width: var(--measure);
  margin: 0.9rem 0 0;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  color: var(--fg-muted);
  background: var(--accent-faint);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Landing hero — the overview page gets a stronger, framed treatment. */
.doc[data-section="overview"] .page-head {
  margin: -0.5rem 0 2.5rem;
  padding: 2.6rem 2rem 2.4rem;
  background: var(--hero-glow), var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.doc[data-section="overview"] .page-head h1 {
  max-width: 18ch;
  font-size: clamp(2.1rem, 1.6rem + 2.2vw, 3rem);
  background: linear-gradient(135deg, var(--fg), var(--accent-strong));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.doc[data-section="overview"] .page-head .summary {
  max-width: 60ch;
  margin-top: 0.7rem;
  font-size: clamp(1.1rem, 1rem + 0.5vw, 1.32rem);
  color: var(--fg-muted);
}

/* ---- Code blocks ---- */
pre {
  margin: 1.25rem 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.55;
  tab-size: 2;
}
pre code {
  padding: 0;
  background: none;
  border: 0;
  font-size: inherit;
}
code {
  font-family: var(--font-mono);
}
:not(pre) > code {
  padding: 0.12em 0.38em;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  font-size: 0.85em;
  color: var(--accent-strong);
}

/* ---- Tables / comparison matrices ---- */
.content table {
  display: block;
  width: 100%;
  margin: 1.5rem 0;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.92rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.25rem 0;
}
th,
td {
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border-soft);
  border-right: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: top;
}
th:last-child,
td:last-child {
  border-right: 0;
}
thead th {
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  border-bottom: 2px solid var(--border);
}
tbody tr:nth-child(even) {
  background: var(--accent-faint);
}
tbody tr:hover {
  background: var(--accent-soft);
}
tbody tr:last-child td {
  border-bottom: 0;
}

/* ---- Glossary term autolink ---- */
.glossary-term {
  color: inherit;
  border-bottom: 1px dashed var(--accent);
  text-decoration: none;
  transition: background 0.12s ease;
}
.glossary-term:hover {
  color: inherit;
  text-decoration: none;
  background: var(--accent-soft);
  border-bottom-style: solid;
  border-radius: 2px;
}

dl.glossary dt {
  font-weight: 700;
  margin-top: 1.3rem;
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
  color: var(--fg);
}
dl.glossary dt:target {
  color: var(--accent-strong);
}
dl.glossary dd {
  margin: 0.25rem 0 0.6rem 0;
  color: var(--fg-muted);
}
#glossary-filter {
  width: 100%;
  max-width: 420px;
  margin: 0.5rem 0 1.5rem 0;
  padding: 0.5rem 0.75rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#glossary-filter:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

ol.references {
  padding-left: 1.5rem;
}
ol.references li {
  margin: 0.5rem 0;
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
ol.references li:target {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}

/* ---- Tabs (message examples, transport variants) ---- */
.tabs {
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tabs .tab-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.4rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.tabs .tab-btn {
  cursor: pointer;
  padding: 0.35rem 0.85rem;
  color: var(--fg-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  transition: color 0.12s ease, background 0.12s ease;
}
.tabs .tab-btn:hover {
  color: var(--fg);
}
.tabs .tab-btn.active {
  color: var(--fg);
  background: var(--bg);
  border-color: var(--border);
}
.tabs .tab-panel {
  padding: 1rem;
}
.tabs .tab-panel[hidden] {
  display: none;
}

/* ---- Message example block ---- */
.message-example {
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.message-example .me-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
}
.message-example pre {
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: var(--bg-code);
}
.message-example .me-note {
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  color: var(--fg-muted);
  border-top: 1px dashed var(--border);
}

.copy-btn {
  cursor: pointer;
  padding: 0.25rem 0.65rem;
  font-size: 0.76rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s ease, color 0.12s ease;
}
.copy-btn:hover {
  border-color: var(--accent);
}
.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Step-through walkthrough ---- */
.walkthrough {
  margin: 1.75rem 0;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow-sm);
}
.walkthrough [data-step] {
  display: none;
}
.walkthrough [data-step].active {
  display: block;
}
.walkthrough .wt-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.walkthrough .wt-controls button {
  cursor: pointer;
  padding: 0.35rem 0.85rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  transition: border-color 0.12s ease;
}
.walkthrough .wt-controls button:hover:not(:disabled) {
  border-color: var(--accent);
}
.walkthrough .wt-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}
.walkthrough .wt-status {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

/* ---- Mermaid diagrams ---- */
/* Rendered as inline SVG; frame and center for a diagram-figure feel. */
.mermaid {
  margin: 1.75rem 0;
  padding: 1.25rem;
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
.mermaid svg {
  max-width: 100%;
  height: auto;
}
/* Pre-render fallback: the raw fenced source before mermaid swaps in the SVG. */
.mermaid:not([data-processed="true"]) {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--fg-faint);
  text-align: left;
  white-space: pre-wrap;
}

/* ---- Status badges on draft pages ---- */
.doc[data-status="draft"] h1::after {
  content: "draft";
  display: inline-block;
  margin-left: 0.6rem;
  padding: 0.12rem 0.55rem;
  font-size: 0.55em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bg);
  background: var(--fg-muted);
  border-radius: 999px;
  vertical-align: middle;
}

/* ---- Footer ---- */
.site-footer {
  flex-shrink: 0;
  margin-top: auto;
  padding: 1.5rem 1.25rem;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  max-width: var(--maxw);
  margin: 0 auto;
  font-size: 0.88rem;
  color: var(--fg-muted);
}
.footer-brand {
  font-weight: 700;
  color: var(--fg);
}
.footer-sep {
  color: var(--fg-faint);
}
.footer-links {
  display: flex;
  gap: 1rem;
  margin-left: auto;
}
.footer-links a {
  color: var(--fg-muted);
}
.footer-links a:hover {
  color: var(--accent);
}

/* ---- Responsive: collapsible sidebar ---- */
@media (max-width: 880px) {
  .nav-toggle {
    display: inline-flex;
  }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 35;
    width: min(82vw, 320px);
    max-height: calc(100vh - var(--topbar-h));
    height: calc(100vh - var(--topbar-h));
    padding: 1.25rem 1rem;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    visibility: hidden;
  }
  body.nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }
  /* Backdrop behind the open drawer. */
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 34;
    background: rgba(0, 0, 0, 0.4);
  }
  body.nav-open {
    overflow: hidden;
  }
  .doc[data-section="overview"] .page-head {
    padding: 1.8rem 1.3rem;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 0.5rem;
    padding: 0 0.75rem;
  }
  .topbar .brand {
    font-size: 1rem;
  }
  #search-box {
    max-width: none;
  }
  .layout {
    padding: 1.5rem 1rem 2.5rem;
  }
  .footer-links {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
