/* OpenProgram Docs — unified theme. One variable set, two palettes.
   Light: warm off-white, easy on the eyes. Dark: soft charcoal, not pure black. */

/* Inter (variable weight, latin subset) — same face as the web UI. Non-latin
   glyphs fall through to the system CJK fonts in the stack. */
@font-face {
  font-family: "Inter Var";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(fonts/inter-latin-wght-normal.woff2) format("woff2-variations");
}

:root {
  /* light (default) — matches the web UI palette (web/app/styles/base.css) */
  --bg:        #faf9f5;   /* --bg-primary */
  --bg-side:   #f5f4ed;   /* --bg-secondary */
  --bg-code:   #f0eee6;   /* --bg-tertiary */
  --bg-card:   #ffffff;
  --tx:        #3d3d3a;   /* --text-primary */
  --tx-soft:   #73726c;   /* --text-secondary */
  --tx-faint:  #9c9a91;
  --acc:       #b8651f;   /* --accent-orange (light) */
  --acc-soft:  #f3e6d6;
  --bd:        rgba(31, 30, 29, 0.12);   /* --border */
  --bd-soft:   rgba(31, 30, 29, 0.07);
  --sel:       #eedcc4;
  --shadow:    0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);

  --sans: "Inter Var", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", "Menlo", "Consolas",
          "PingFang SC", "Microsoft YaHei", monospace;

  --nav-w: 270px;
  --toc-w: 256px;
  --maxw:  820px;
}

html[data-theme="dark"] {
  /* matches the web UI dark palette (web/app/styles/base.css) */
  --bg:        #1f1f1e;   /* --bg-primary */
  --bg-side:   #171716;   /* --bg-secondary */
  --bg-code:   #252524;   /* --bg-tertiary */
  --bg-card:   #252524;
  --tx:        #c3c2b7;   /* --text-primary */
  --tx-soft:   #97958c;   /* --text-secondary */
  --tx-faint:  #6f6e66;
  --acc:       #d19a66;   /* --accent-orange (dark) */
  --acc-soft:  #35291d;
  --bd:        rgba(226, 225, 218, 0.12);   /* --border */
  --bd-soft:   rgba(226, 225, 218, 0.07);
  --sel:       #4a3a26;
  --shadow:    0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font: 15.5px/1.75 var(--sans);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--sel); }

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

/* ── top bar ── */
header.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 100;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--bd);
}
.topbar .brand {
  font-weight: 700; font-size: 15px; letter-spacing: .01em;
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
.topbar .brand .mark { width: 20px; height: 20px; border-radius: 5px; display: block; }
.topbar .spacer { flex: 1; }
.topbar .search-trigger {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--bg-side); border: 1px solid var(--bd); color: var(--tx-faint);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; min-width: 180px;
}
.topbar .search-trigger kbd {
  margin-left: auto; font: 11px var(--mono); background: var(--bg);
  border: 1px solid var(--bd); border-radius: 4px; padding: 1px 5px;
}
.topbar button.icon {
  background: none; border: 1px solid var(--bd); color: var(--tx-soft);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}
.topbar button.icon:hover { background: var(--bg-side); color: var(--tx); }
/* hamburger shows on all widths: wide = collapse the sidebar, narrow = drawer */

/* theme toggle: show the icon for the theme you'd switch TO */
#theme-toggle .ic-sun { display: none; }
html[data-theme="dark"] #theme-toggle .ic-sun { display: block; }
html[data-theme="dark"] #theme-toggle .ic-moon { display: none; }

/* language dropdown */
.lang-wrap { position: relative; }
.topbar button.lang-trigger {
  width: auto; padding: 0 10px; gap: 6px;
  font-size: 12.5px; font-weight: 600; font-family: var(--sans);
}
.lang-trigger .chev { transition: transform .15s ease; }
.lang-wrap.open .lang-trigger .chev { transform: rotate(180deg); }
.lang-menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 160px;
  background: var(--bg-card); border: 1px solid var(--bd); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; display: none; z-index: 200;
}
.lang-wrap.open .lang-menu { display: block; }
.lang-opt {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  gap: 18px; padding: 7px 10px; border: none; background: none; cursor: pointer;
  color: var(--tx); font: 600 13.5px var(--sans); border-radius: 7px; text-align: left;
}
.lang-opt:hover { background: var(--bd-soft); }
.lang-opt .check { visibility: hidden; color: var(--acc); flex: none; }
.lang-opt.active { color: var(--acc); }
.lang-opt.active .check { visibility: visible; }

/* ── tabbar (top-level sections, below the topbar) ── */
nav.tabbar {
  position: fixed; top: 56px; left: 0; right: 0; height: 40px; z-index: 99;
  display: flex; align-items: stretch; gap: 2px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--bd);
  overflow-x: auto; white-space: nowrap; scrollbar-width: none;
}
nav.tabbar::-webkit-scrollbar { display: none; }
.tablink {
  color: var(--tx-soft); font-size: 13.5px; font-weight: 500;
  padding: 0 12px; display: inline-flex; align-items: center;
  border-bottom: 2px solid transparent;
}
.tablink:hover { color: var(--tx); }
/* active state must not change font-weight — bold text is wider and would
   shift the whole row on every tab switch */
.tablink.active { color: var(--acc); border-bottom-color: var(--acc); }

/* ── layout ── */
.layout { display: flex; padding-top: 96px; }

/* wide-screen sidebar collapse (toggled by the hamburger) */
html[data-nav-collapsed="1"] nav.sidebar { transform: translateX(-100%); }
html[data-nav-collapsed="1"] main.content { margin-left: 0; }

/* left nav */
nav.sidebar {
  position: fixed; top: 96px; bottom: 0; left: 0; width: var(--nav-w);
  overflow-y: auto; padding: 20px 14px 60px; border-right: 1px solid var(--bd);
  background: var(--bg-side); transition: transform .2s ease;
}
nav.sidebar .nav-filter {
  width: 100%; margin-bottom: 12px; padding: 7px 11px; font-size: 13px;
  background: var(--bg); border: 1px solid var(--bd); border-radius: 8px;
  color: var(--tx); outline: none;
}
nav.sidebar .nav-filter:focus { border-color: var(--acc); }
nav.sidebar .nav-filter::placeholder { color: var(--tx-faint); }
nav.sidebar details.group { margin: 1px 0; }
nav.sidebar summary.group-title {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; letter-spacing: 0;
  color: var(--tx); padding: 7px 8px; border-radius: 7px; margin: 1px 0;
}
nav.sidebar summary.group-title::-webkit-details-marker { display: none; }
nav.sidebar summary.group-title::before {
  content: "›"; font-size: 17px; line-height: 1; color: var(--tx-faint);
  transition: transform .15s; display: inline-block; width: 12px; text-align: center;
}
nav.sidebar details[open] > summary.group-title::before { transform: rotate(90deg); }
nav.sidebar summary.group-title:hover { background: var(--bd-soft); color: var(--tx); }
/* nested subgroup headers: a touch lighter than top-level */
nav.sidebar details.group details.group > summary.group-title {
  font-size: 13px; font-weight: 550; color: var(--tx-soft);
}
nav.sidebar .group-body { padding-left: 8px; margin-left: 9px; border-left: 1px solid var(--bd-soft); }
nav.sidebar details.group details.group { margin-left: 2px; }
nav.sidebar a.navlink {
  display: block; padding: 6px 9px 6px 22px; border-radius: 7px; font-size: 14px;
  color: var(--tx-soft); line-height: 1.45;
}
nav.sidebar a.navlink:hover { background: var(--bd-soft); color: var(--tx); text-decoration: none; }
nav.sidebar a.navlink.active { background: var(--acc-soft); color: var(--acc); font-weight: 600; }

/* main column */
main.content {
  margin-left: var(--nav-w); margin-right: var(--toc-w);
  flex: 1; min-width: 0; display: flex; justify-content: center;
  padding: 38px 48px 120px;
  transition: margin-left .2s ease;
}
article { width: 100%; max-width: var(--maxw); }

/* right toc */
aside.toc {
  position: fixed; top: 96px; right: 0; width: var(--toc-w);
  max-height: calc(100vh - 96px - 48px);
  overflow-y: auto; padding: 38px 20px 24px; font-size: 13px;
}
aside.toc .toc-title {
  font-size: 12px; font-weight: 700;
  letter-spacing: .02em; color: var(--tx-soft); margin-bottom: 12px;
}
/* tree with a guide line down the left, like the sidebar */
aside.toc .toc-list { border-left: 1px solid var(--bd); }
aside.toc a {
  display: block; line-height: 1.45; color: var(--tx-soft);
  position: relative; border-left: 2px solid transparent; margin-left: -1px;
}
/* level 1 (h2): heavier, darker */
aside.toc a:not(.lvl-3) {
  padding: 6px 0 6px 16px; font-size: 13.5px; font-weight: 550; color: var(--tx-soft);
}
/* level 2 (h3): deeper indent + its own thinner guide branch */
aside.toc a.lvl-3 {
  padding: 4px 0 4px 30px; font-size: 12.5px; color: var(--tx-faint);
}
aside.toc a.lvl-3::before {
  content: ""; position: absolute; left: 16px; top: 0; bottom: 0;
  border-left: 1px solid var(--bd-soft);
}
aside.toc a:hover { color: var(--tx); text-decoration: none; }
aside.toc a.active { color: var(--acc); border-left-color: var(--acc); font-weight: 600; }

/* ── breadcrumb ── */
.breadcrumb { font-size: 13px; color: var(--tx-faint); margin-bottom: 18px; }
.breadcrumb .bc-sep { margin: 0 6px; opacity: .6; }
.breadcrumb .bc-current { color: var(--tx-soft); }

/* ── last-updated ── */
.page-updated { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--bd);
  font-size: 13px; color: var(--tx-faint); }

/* ── prev / next ── */
.prevnext { display: flex; gap: 14px; margin-top: 22px; }
.prevnext .pn-link {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px; border: 1px solid var(--bd); border-radius: 10px;
  color: var(--tx); transition: border-color .15s, background .15s;
}
.prevnext .pn-link:hover { border-color: var(--acc); background: var(--bg-side); text-decoration: none; }
.prevnext .pn-next { text-align: right; }
.prevnext .pn-dir { font-size: 12px; color: var(--tx-faint); }
.prevnext .pn-title { font-weight: 600; font-size: 14px; color: var(--acc); }

/* ── article typography ── */
article h1 { font-size: 32px; line-height: 1.22; margin: 0 0 4px; letter-spacing: -.022em; font-weight: 720; }
article h2 {
  font-size: 22px; margin: 44px 0 14px; padding-bottom: 8px;
  border-bottom: 1px solid var(--bd); letter-spacing: -.015em;
}
article h3 { font-size: 17.5px; margin: 30px 0 10px; letter-spacing: -.008em; }
article h4 { font-size: 15.5px; margin: 22px 0 8px; color: var(--tx-soft); }
article h2, article h3, article h4 { font-weight: 640; }
article h1, article h2, article h3, article h4 { scroll-margin-top: 116px; }
article .header-anchor {
  opacity: 0; margin-left: 8px; color: var(--tx-faint); font-weight: 400; text-decoration: none;
}
article h1:hover .header-anchor, article h2:hover .header-anchor,
article h3:hover .header-anchor { opacity: 1; }

article p { margin: 12px 0; }
article ul, article ol { margin: 12px 0; padding-left: 26px; }
article li { margin: 5px 0; }
article li::marker { color: var(--tx-faint); }

article code {
  font: 13px var(--mono); background: var(--bg-code); color: var(--acc);
  padding: 2px 6px; border-radius: 5px; border: 1px solid var(--bd-soft);
}
article pre {
  background: var(--bg-code); border: 1px solid var(--bd); border-radius: 10px;
  padding: 16px 18px; overflow-x: auto; margin: 16px 0; line-height: 1.6;
}
article pre code { background: none; border: none; color: var(--tx); padding: 0; font-size: 13px; }

/* code-block copy button */
article pre { position: relative; }
article pre .copy-btn {
  position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity .15s;
  background: var(--bg-card); border: 1px solid var(--bd); color: var(--tx-soft);
  font-size: 12px; padding: 3px 9px; border-radius: 6px; cursor: pointer;
}
article pre:hover .copy-btn { opacity: 1; }
article pre .copy-btn:hover { color: var(--tx); border-color: var(--acc); }
article pre .copy-btn.copied { color: var(--acc); border-color: var(--acc); }

/* callouts */
.callout {
  margin: 16px 0; border: 1px solid var(--bd); border-left: 3px solid var(--cl-accent);
  border-radius: 0 8px 8px 0; background: var(--cl-bg); padding: 12px 16px;
}
.callout-head {
  display: flex; align-items: center; gap: 7px;
  font-weight: 650; font-size: 13.5px; color: var(--cl-accent); margin-bottom: 4px;
}
.callout-icon { display: inline-flex; align-items: center; }
.callout-body p { margin: 4px 0; }
.callout-body p:last-child { margin-bottom: 0; }
.callout-note      { --cl-accent: #3b82f6; --cl-bg: color-mix(in srgb, #3b82f6 8%, var(--bg)); }
.callout-tip       { --cl-accent: #2f9e6e; --cl-bg: color-mix(in srgb, #2f9e6e 8%, var(--bg)); }
.callout-important { --cl-accent: #8b5cf6; --cl-bg: color-mix(in srgb, #8b5cf6 8%, var(--bg)); }
.callout-warning   { --cl-accent: #d9920a; --cl-bg: color-mix(in srgb, #d9920a 10%, var(--bg)); }
.callout-caution   { --cl-accent: #e0533d; --cl-bg: color-mix(in srgb, #e0533d 9%, var(--bg)); }

article blockquote {
  margin: 16px 0; padding: 10px 18px; color: var(--tx-soft);
  background: var(--bg-side); border-left: 3px solid var(--acc); border-radius: 0 8px 8px 0;
}
article blockquote p { margin: 4px 0; }

article table { border-collapse: collapse; width: 100%; margin: 18px 0; font-size: 14px; }
article th, article td { border: 1px solid var(--bd); padding: 8px 12px; text-align: left; vertical-align: top; }
article th { background: var(--bg-side); font-weight: 650; }
article tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-side) 50%, transparent); }

article hr { border: none; border-top: 1px solid var(--bd); margin: 32px 0; }
article img { max-width: 100%; border-radius: 8px; }
article strong { color: var(--tx); font-weight: 650; }

/* page meta (status line right under h1) */
.page-meta { color: var(--tx-faint); font-size: 13.5px; margin-bottom: 24px; }
.page-meta kbd {
  font: 11px var(--mono); background: var(--bg-side); border: 1px solid var(--bd);
  border-radius: 4px; padding: 1px 5px;
}

/* landing page card grid */
/* landing page uses the full content width, not the 820px reading column */
article:has(.home-grid) { max-width: none; }
.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px; margin-top: 28px;
}
.home-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px 18px 16px; border: 1px solid var(--bd); border-radius: 12px;
  background: var(--bg-card); transition: border-color .15s, transform .15s;
}
.home-card:hover { border-color: var(--acc); transform: translateY(-2px); text-decoration: none; }
.home-card .hc-title { font-weight: 650; font-size: 15px; color: var(--tx); }
.home-card .hc-count { font-size: 12px; color: var(--tx-faint); font-family: var(--mono); }

/* embedded visualization (hand-written html via isolated iframe) */
.viz-frame {
  width: 100%; height: calc(100vh - 56px - 76px); min-height: 600px;
  border: 1px solid var(--bd); border-radius: 12px; background: var(--bg-card);
}
article:has(.viz-frame) { max-width: none; }

/* ── content fullscreen ──
   CSS overlay rather than the Fullscreen API: the shell keeps its own theme,
   scroll and SPA navigation, an iframe needs no allowfullscreen, and ESC stays
   ours. Sits in the content area's top-right gutter, never over the text. */
.fs-toggle {
  position: fixed; top: 104px; right: calc(var(--toc-w) + 14px); z-index: 95;
  width: 30px; height: 30px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-card); border: 1px solid var(--bd); color: var(--tx-faint);
  border-radius: 8px; opacity: .6;
  transition: opacity .15s, color .15s, border-color .15s;
}
.fs-toggle:hover { opacity: 1; color: var(--tx); border-color: var(--acc); }
.fs-toggle .ic-collapse { display: none; }

html[data-fs="1"] .fs-toggle { top: 12px; right: 14px; z-index: 160; opacity: 1; box-shadow: var(--shadow); }
html[data-fs="1"] .fs-toggle .ic-expand { display: none; }
html[data-fs="1"] .fs-toggle .ic-collapse { display: inline-flex; }

html[data-fs="1"] body { overflow: hidden; }
html[data-fs="1"] header.topbar,
html[data-fs="1"] nav.tabbar,
html[data-fs="1"] nav.sidebar,
html[data-fs="1"] aside.toc,
html[data-fs="1"] .breadcrumb,
html[data-fs="1"] .page-updated,
html[data-fs="1"] .prevnext { display: none; }
html[data-fs="1"] main.content {
  position: fixed; inset: 0; z-index: 150; margin: 0; overflow-y: auto;
  background: var(--bg); padding: 16px 24px 24px;
}
html[data-fs="1"] article { max-width: none; }
/* the h1 is the one block level with the floating exit button — keep it clear */
html[data-fs="1"] article > h1 { padding-right: 40px; }
html[data-fs="1"] .viz-frame { height: calc(100vh - 40px); }

/* ── search overlay ── */
.search-overlay {
  position: fixed; inset: 0; z-index: 200; display: none;
  background: rgba(0,0,0,.4); backdrop-filter: blur(2px);
  align-items: flex-start; justify-content: center; padding-top: 12vh;
}
.search-overlay.open { display: flex; }
.search-box {
  width: min(620px, 92vw); background: var(--bg-card); border: 1px solid var(--bd);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.search-box input {
  width: 100%; border: none; outline: none; background: none; color: var(--tx);
  font: 16px var(--sans); padding: 18px 20px; border-bottom: 1px solid var(--bd);
}
.search-results { max-height: 56vh; overflow-y: auto; }
.search-results a {
  display: block; padding: 11px 20px; border-bottom: 1px solid var(--bd-soft); color: var(--tx);
}
.search-results a:hover, .search-results a.sel { background: var(--bg-side); text-decoration: none; }
.search-results .r-title { font-weight: 600; font-size: 14px; }
.search-results .r-path { font: 11px var(--mono); color: var(--tx-faint); margin-top: 2px; }
.search-results .r-snippet { font-size: 12.5px; color: var(--tx-soft); margin-top: 3px; }
.search-results mark { background: var(--sel); color: var(--tx); border-radius: 3px; padding: 0 2px; }
.search-empty { padding: 24px 20px; color: var(--tx-faint); text-align: center; }

/* ── responsive ── */
.scrim { display: none; }
@media (max-width: 1100px) {
  aside.toc { display: none; }
  main.content { margin-right: 0; }
  .fs-toggle { right: 14px; }
}
@media (max-width: 860px) {
  .topbar button.hamburger { display: inline-flex; }
  .topbar .search-trigger { min-width: 0; }
  .topbar .search-trigger .label { display: none; }
  nav.sidebar {
    transform: translateX(-100%); transition: transform .22s ease; z-index: 90;
    box-shadow: var(--shadow);
  }
  nav.sidebar.open { transform: translateX(0); }
  /* padding-top clears the fullscreen button (ends at 100+30=130; chrome ends at 96) */
  main.content { margin-left: 0; padding: 38px 22px 100px; }
  .fs-toggle { top: 100px; right: 10px; }
  .scrim.show { display: block; position: fixed; inset: 56px 0 0; background: rgba(0,0,0,.35); z-index: 80; }
}

/* home page: no sidebar, content centered full-width */
.layout.no-side main.content { margin-left: 0; }

/* ── flat sidebar sections (OpenClaw-style, non-collapsible) ── */
.nav-sec { margin: 20px 0 4px; }
.nav-sec:first-of-type { margin-top: 8px; }
.nav-sec-title {
  font-size: 11.5px; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--tx-faint);
  padding: 0 9px; margin-bottom: 4px;
}
