/* LoopIT documentation theme */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --text: #1f2328;
  --muted: #57606a;
  --border: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --sidebar-w: 270px;
  --content-w: 780px;
  --toc-w: 224px;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

/* dark palette: follow the OS unless the user picked a theme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --bg-soft: #161b22; --text: #e6edf3; --muted: #8b949e;
    --border: #30363d; --accent: #4493f8; --accent-soft: #16243c; --code-bg: #161b22;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --bg-soft: #161b22; --text: #e6edf3; --muted: #8b949e;
  --border: #30363d; --accent: #4493f8; --accent-soft: #16243c; --code-bg: #161b22;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ---- layout (injected by nav.html / foot.html) ---- */
.site { display: flex; align-items: flex-start; max-width: 1320px; margin: 0 auto; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 20px 16px 40px;
  background: var(--bg-soft);
}
.brand-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand .logo { width: 26px; height: 26px; flex: 0 0 26px; }
.brand .sub { display: block; font-weight: 400; font-size: .76rem; color: var(--muted); }
.theme-toggle {
  flex: 0 0 auto; width: 32px; height: 32px; border: 1px solid var(--border);
  background: var(--bg); color: var(--muted); border-radius: 7px; cursor: pointer;
  font-size: 1rem; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* mobile top bar + drawer backdrop (hidden on desktop) */
.topbar { display: none; }
.backdrop { display: none; }
.brand-sm { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.02rem; }
.brand-sm .logo { width: 24px; height: 24px; }
.menu-btn {
  width: 38px; height: 38px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); border-radius: 8px; font-size: 1.15rem; line-height: 1; cursor: pointer;
}
.menu-btn:hover { color: var(--accent); border-color: var(--accent); }

.sidebar nav { margin-top: 18px; }
.sidebar .nav-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 18px 8px 6px; font-weight: 600;
}
.sidebar a {
  display: block; padding: 6px 10px; margin: 1px 0; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: .92rem;
}
.sidebar a:hover { background: var(--accent-soft); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* search */
.search-wrap { position: relative; margin-top: 16px; }
.search-box {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--text); font-size: .88rem; font-family: var(--font);
}
.search-box:focus { outline: none; border-color: var(--accent); }
.search-results {
  display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto; padding: 4px;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: 7px 10px; border-radius: 6px; font-size: .86rem; }
.search-results a:hover { background: var(--accent-soft); text-decoration: none; }
.search-results a small { display: block; color: var(--muted); font-size: .74rem; }
.search-results .none { padding: 8px 10px; color: var(--muted); font-size: .85rem; }

.doc { flex: 1 1 auto; min-width: 0; display: flex; align-items: flex-start; }
.content { flex: 1 1 auto; min-width: 0; max-width: var(--content-w); padding: 38px 44px 80px; }

/* right-hand "on this page" rail (the moved pandoc #TOC) */
.toc-col {
  flex: 0 0 var(--toc-w); width: var(--toc-w); position: sticky; top: 0;
  align-self: flex-start; max-height: 100vh; overflow-y: auto; padding: 44px 16px 40px;
}
.toc-col:empty { display: none; }

/* ---- typography ---- */
h1, h2, h3, h4 { line-height: 1.25; font-weight: 650; scroll-margin-top: 20px; }
h1 { font-size: 2rem; margin: .2em 0 .6em; }
h2 { font-size: 1.45rem; margin: 1.8em 0 .5em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
h3 { font-size: 1.15rem; margin: 1.6em 0 .4em; }
h4 { font-size: 1rem; margin: 1.4em 0 .3em; color: var(--muted); }
#title-block-header .title { font-size: 2.1rem; margin-bottom: .1em; }
#title-block-header .author, #title-block-header .date { color: var(--muted); font-size: .9rem; margin: 0; }
p { margin: .7em 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { padding-left: 1.4em; }
li { margin: .25em 0; }
blockquote {
  margin: 1.1em 0; padding: .6em 1em; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0; color: var(--text);
}
blockquote p { margin: .3em 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
img, svg.diagram { max-width: 100%; }

/* ---- code ---- */
code {
  font-family: var(--mono); font-size: .88em; background: var(--code-bg);
  padding: .15em .4em; border-radius: 5px; border: 1px solid var(--border);
}
pre {
  position: relative; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; font-size: .86rem; line-height: 1.5;
}
pre code { background: none; border: none; padding: 0; font-size: inherit; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; font-family: var(--font); font-size: .72rem;
  padding: 3px 9px; border: 1px solid var(--border); background: var(--bg); color: var(--muted);
  border-radius: 6px; cursor: pointer; opacity: 0; transition: opacity .12s;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: #15803d; border-color: #15803d; }

/* dark-mode syntax tokens (tango is tuned for light backgrounds) */
:root[data-theme="dark"] .sourceCode { color: var(--text); }
:root[data-theme="dark"] .co { color: #8b949e; }
:root[data-theme="dark"] .kw, :root[data-theme="dark"] .cf { color: #ff7b72; }
:root[data-theme="dark"] .dt, :root[data-theme="dark"] .bu { color: #ffa657; }
:root[data-theme="dark"] .st, :root[data-theme="dark"] .ch, :root[data-theme="dark"] .vs { color: #a5d6ff; }
:root[data-theme="dark"] .dv, :root[data-theme="dark"] .bn, :root[data-theme="dark"] .fl { color: #79c0ff; }
:root[data-theme="dark"] .fu { color: #d2a8ff; }
:root[data-theme="dark"] .op, :root[data-theme="dark"] .at { color: #e6edf3; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sourceCode { color: var(--text); }
  :root:not([data-theme="light"]) .co { color: #8b949e; }
  :root:not([data-theme="light"]) .kw, :root:not([data-theme="light"]) .cf { color: #ff7b72; }
  :root:not([data-theme="light"]) .dt, :root:not([data-theme="light"]) .bu { color: #ffa657; }
  :root:not([data-theme="light"]) .st, :root:not([data-theme="light"]) .ch, :root:not([data-theme="light"]) .vs { color: #a5d6ff; }
  :root:not([data-theme="light"]) .dv, :root:not([data-theme="light"]) .bn, :root:not([data-theme="light"]) .fl { color: #79c0ff; }
  :root:not([data-theme="light"]) .fu { color: #d2a8ff; }
  :root:not([data-theme="light"]) .op, :root:not([data-theme="light"]) .at { color: #e6edf3; }
}

/* ---- tables ---- */
table { border-collapse: collapse; width: 100%; margin: 1.1em 0; font-size: .92rem; }
th, td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top; }
th { background: var(--bg-soft); font-weight: 600; }
tr:nth-child(even) td { background: var(--bg-soft); }

/* ---- right-rail TOC contents ---- */
#TOC { font-size: .85rem; }
#TOC::before {
  content: "On this page"; display: block; font-weight: 600; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px;
}
#TOC ul { list-style: none; padding-left: .9em; margin: 0; }
#TOC > ul { padding-left: 0; }
#TOC li { margin: .15em 0; }
#TOC a { color: var(--muted); display: block; padding: 1px 0; }
#TOC a:hover { color: var(--accent); text-decoration: none; }

/* ---- tabbed code (multi-language clients) ---- */
.tabs { margin: 1.1em 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tabs-bar { display: flex; background: var(--bg-soft); border-bottom: 1px solid var(--border); }
.tabs-bar button {
  border: none; background: none; padding: 8px 14px; cursor: pointer; font-family: var(--font);
  font-size: .85rem; color: var(--muted); border-bottom: 2px solid transparent;
}
.tabs-bar button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .tab-panel { display: none; }
.tabs .tab-panel.active { display: block; }
.tabs .tab-panel pre { margin: 0; border: none; border-radius: 0; }

.page-foot {
  margin-top: 4em; padding-top: 1.4em; border-top: 1px solid var(--border);
  color: var(--muted); font-size: .85rem;
}

/* ---- responsive ---- */
@media (max-width: 1100px) { .toc-col { display: none; } }
@media (max-width: 900px) {
  /* top bar with a hamburger; the sidebar becomes an off-canvas drawer */
  .topbar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30;
    background: var(--bg); border-bottom: 1px solid var(--border); padding: 8px 14px;
  }
  .topbar .brand-sm { margin-right: auto; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 280px; max-width: 84vw;
    z-index: 50; transform: translateX(-100%); transition: transform .22s ease;
    border-right: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .brand-row { display: none; }   /* the brand lives in the top bar on mobile */
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 45; }
  .doc { display: block; }
  .content { padding: 22px 18px 64px; max-width: none; }
}
