/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --bg:           #090D12;
  --bg-1:         #0D1219;
  --bg-2:         #111820;
  --bg-3:         #161F2A;
  --border:       rgba(255,255,255,0.06);
  --border-md:    rgba(255,255,255,0.10);
  --text:         #E2EAF4;
  --muted:        #8CA0B2;
  --subtle:       #6B8499;
  --blue:         #2E6ACC;
  --blue-light:   #7EB8F7;
  --blue-hover:   #3470C0;
  --green:        #52923C;
  --green-light:  #82CF8A;
  --font-body:    'Plus Jakarta Sans', system-ui, sans-serif;
  --font-display: 'Syne', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
  --nav-h:        120px;
  --sidebar-w:    272px;
}

html[data-theme="light"] {
  --bg:           #F0F4F8;
  --bg-1:         #FFFFFF;
  --bg-2:         #E8EEF5;
  --bg-3:         #DDE6EF;
  --border:       rgba(0,0,0,0.08);
  --border-md:    rgba(0,0,0,0.13);
  --text:         #0F1923;
  --muted:        #374B5E;
  --subtle:       #52697F;
  --blue:         #1A5CB8;
  --blue-light:   #1A5CB8;
  --blue-hover:   #144EA8;
  --green:        #38692A;
  --green-light:  #4A9A30;
}

html[data-theme="light"] .top-nav {
  background: rgba(240,244,248,0.92);
}

html[data-theme="light"] .mobile-menu {
  background: rgba(240,244,248,0.97);
}

html[data-theme="light"] .nav-page a:hover {
  background: rgba(0,0,0,0.04);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100vh;
}

/* ── Top navigation bar ──────────────────────────────────────────────────── */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 300;
  height: var(--nav-h);
  background: rgba(9,13,18,0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.top-nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

.top-nav-brand img {
  height: 100px;
  width: 100px;
  object-fit: contain;
}

.top-nav-brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.top-nav-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--blue) 12%, transparent);
  color: var(--blue-light);
  border: 1px solid color-mix(in srgb, var(--blue) 28%, transparent);
  border-radius: 4px;
  padding: 2px 6px;
}

.top-nav-links {
  display: flex;
  align-items: center;
  gap: 28px;
}

.top-nav-links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

.top-nav-links a:hover { color: var(--text); }
.top-nav-links a.active { color: var(--text); }

.top-nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  line-height: 0;
}

.top-nav-gh {
  display: flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

.top-nav-gh:hover { color: var(--text); }

.top-nav-cta {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-body);
  background: var(--blue);
  color: #fff;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s, transform 0.15s;
  white-space: nowrap;
}

.top-nav-cta:hover {
  background: var(--blue-hover);
  box-shadow: 0 4px 20px rgba(53,116,216,0.4);
  transform: translateY(-1px);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg);
  flex-shrink: 0;
  position: fixed;
  top: var(--nav-h);
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  border-right: 1px solid var(--border-md);
  overflow-y: auto;
}

.nav-sections {
  list-style: none;
  margin: 0;
  padding: 0.75rem 0 2rem;
  flex: 1;
}

.nav-section { margin-bottom: 0; }

.nav-section-title {
  display: block;
  padding: 0.75rem 1.25rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  user-select: none;
}

.nav-section.active .nav-section-title { color: var(--text); }

.nav-pages {
  list-style: none;
  margin: 0;
  padding: 0 0 0.25rem;
}

.nav-page a {
  display: block;
  padding: 0.32rem 1.25rem 0.32rem 1.5rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.45;
  border-left: 2px solid transparent;
  transition: color 0.1s, background 0.1s;
}

.nav-page a:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}

.nav-page.active > a {
  color: var(--blue-light);
  border-left-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 7%, transparent);
  font-weight: 500;
}

/* ── Content column ──────────────────────────────────────────────────────── */
main.content {
  margin-left: var(--sidebar-w);
  padding-top: var(--nav-h);
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  color: var(--text);
}

html[data-theme="light"] main.content { background: #fff; }

/* ── Page wrap: readable line length ─────────────────────────────────────── */
.page-wrap {
  padding: 2.5rem 3rem 5rem;
  max-width: 860px;
}

.page-wrap > #header,
.page-wrap > #content,
.page-wrap > #footnotes,
.page-wrap > #footer {
  width: auto;
  max-width: none;
  margin: 0;
  padding: 0;
}

.page-wrap > #header { padding-bottom: 0; }
#header > h1:first-child { margin-top: 0; color: var(--blue-light); }
html[data-theme="light"] #header > h1:first-child { color: #ba3925; }
.page-wrap > #content { margin-top: 1.75rem; }
#content { margin-left: 0; margin-right: 0; }
#content h2 { margin-top: 2rem; margin-bottom: 0.5rem; }
#content h3 { margin-top: 1.5rem; }

/* Section h2 as visual anchors */
#content h2 {
  color: var(--text);
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border-md);
}
html[data-theme="light"] #content h2 {
  border-bottom-color: rgba(0,0,0,0.1);
}

/* HR */
#header hr, #content hr {
  border: none;
  border-top: 1px solid var(--border-md);
  margin: 1.25rem 0;
}

/* ── Asciidoctor overrides: comprehensive CSS-var resets ─────────────────── */
/* asciidoctor.css hardcodes rgba(0,0,0,.8+) on ~20 selectors.              */
/* layout.css loads after it, so same-or-higher specificity rules win.       */

/* Headings */
#content h1, #content h2, #content h3,
#content h4, #content h5, #content h6 { color: var(--text); }

/* Body text — paragraphs, lists, definition lists */
#content p, #content li, #content dt, #content dd,
#content .paragraph p,
#content .paragraph.lead > p,
#content #preamble .sectionbody > .paragraph p { color: var(--text); }

/* Links */
#content a { color: var(--blue-light); }
html[data-theme="light"] #content a { color: #2156a5; }

/* Heading anchor links */
#content h1 > a.link, #content h2 > a.link,
#content h3 > a.link, #content h4 > a.link,
#content h5 > a.link, #content h6 > a.link { color: var(--text); }
#content h2 > a.link:hover, #content h3 > a.link:hover { color: var(--blue-light); }

/* Inline code */
#content code { color: var(--text); }
#content :not(pre):not([class^=L])>code {
  background: var(--bg-1);
  border-color: var(--border-md);
}
html[data-theme="light"] #content code { color: rgba(0,0,0,.9); }
html[data-theme="light"] #content :not(pre):not([class^=L])>code {
  background: #f0f2f5;
  border-color: rgba(0,0,0,.12);
}

/* Pre / code blocks — darkest layer */
#content pre, #content pre code { color: var(--text); }
#content .listingblock>.content>pre,
#content pre.highlight,
#content pre {
  background: var(--bg);
  border-color: var(--border-md);
}
html[data-theme="light"] #content pre,
html[data-theme="light"] #content pre code { color: rgba(0,0,0,.9); }
html[data-theme="light"] #content .listingblock>.content>pre,
html[data-theme="light"] #content pre.highlight,
html[data-theme="light"] #content pre {
  background: #f7f7f8;
  border-color: rgba(0,0,0,.08);
}

/* Keyboard / menu shortcuts */
#content kbd {
  color: var(--text);
  background: var(--bg-3);
  border-color: var(--border-md);
  box-shadow: none;
}
#content .keyseq, #content .menuseq, #content .menuref { color: var(--text); }
html[data-theme="light"] #content kbd {
  color: rgba(0,0,0,.8);
  background: #f7f7f7;
  border-color: #ccc;
  box-shadow: 0 1px 0 rgba(0,0,0,.2), inset 0 0 0 .1em #fff;
}

/* Blockquotes and verse blocks */
#content blockquote, #content blockquote p,
#content .quoteblock blockquote, #content .quoteblock p,
#content .verseblock pre { color: var(--text); }
#content .quoteblock .attribution cite,
#content .verseblock .attribution cite { color: var(--muted); }
#content .quoteblock blockquote::before { color: var(--blue-light); }
html[data-theme="light"] #content .quoteblock blockquote::before { color: #7a2518; }
html[data-theme="light"] #content .quoteblock .attribution cite,
html[data-theme="light"] #content .verseblock .attribution cite { color: rgba(0,0,0,.6); }

/* Block titles (listing, image, example, etc.) */
#content .paragraph > .title,
#content .listingblock > .title, #content .literalblock > .title,
#content .imageblock > .title, #content .exampleblock > .title,
#content .audioblock > .title, #content .videoblock > .title,
#content .stemblock > .title, #content .openblock > .title,
#content table.tableblock > .title,
#content .ulist > .title, #content .olist > .title,
#content .dlist > .title, #content .qlist > .title,
#content .hdlist > .title, #content .quoteblock > .title,
#content .verseblock > .title, #content .admonitionblock > table > caption,
#toctitle { color: var(--blue-light); }
html[data-theme="light"] #content .paragraph > .title,
html[data-theme="light"] #content .listingblock > .title,
html[data-theme="light"] #toctitle { color: #7a2518; }

/* Sidebar blocks */
#content .sidebarblock {
  background: var(--bg-1);
  border-color: var(--border-md);
}
#content .sidebarblock > .content > .title { color: var(--blue-light); }
html[data-theme="light"] #content .sidebarblock { background: #f3f3f2; border-color: rgba(0,0,0,.08); }
html[data-theme="light"] #content .sidebarblock > .content > .title { color: #7a2518; }

/* Tables */
#content table, #content table.tableblock {
  background: var(--bg-1);
  border-collapse: collapse;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  display: block;
}
#content table thead, #content table tfoot,
#content table.tableblock thead, #content table.tableblock tfoot {
  background: color-mix(in srgb, var(--blue) 10%, var(--bg-3));
}
/* All cell variants — asciidoctor uses multiple specificity levels */
#content table tr th, #content table tr td,
#content table thead tr th, #content table thead tr td,
#content table tfoot tr th, #content table tfoot tr td,
#content tbody tr th, #content tfoot tr th,
#content td, #content th,
#content .tableblock>tbody>tr>td,
#content .tableblock>thead>tr>th {
  border-color: var(--border-md);
  color: var(--text);
}
/* Nested p/li inside cells */
#content table p, #content table li,
#content tbody tr th p, #content tfoot tr th p { color: var(--text); }
#content tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--bg-3) 35%, transparent);
}
html[data-theme="light"] #content table,
html[data-theme="light"] #content table.tableblock { background: #fff; }
html[data-theme="light"] #content table thead,
html[data-theme="light"] #content table tfoot,
html[data-theme="light"] #content table.tableblock thead,
html[data-theme="light"] #content table.tableblock tfoot { background: #eef2f7; }
html[data-theme="light"] #content table tr th,
html[data-theme="light"] #content table tr td,
html[data-theme="light"] #content td,
html[data-theme="light"] #content th { color: rgba(0,0,0,.8); }
html[data-theme="light"] #content tbody tr:nth-child(even) { background: #f9fafb; }

/* Admonition blocks */
#content .admonitionblock > table { background: transparent; display: table; }
#content .admonitionblock td.content {
  background: var(--bg-1);
  border-color: var(--border-md);
  color: var(--text);
}
#content .admonitionblock td.content p { color: var(--text); }
html[data-theme="light"] #content .admonitionblock > table { background: transparent; }
html[data-theme="light"] #content .admonitionblock td.content {
  background: #fff;
  border-color: rgba(0,0,0,.08);
  color: inherit;
}

/* Header author/details */
#header .details, #header .details span { color: var(--muted); }
#header .details a { color: var(--blue-light); }

/* Footnotes */
#content #footnotes { color: var(--muted); }

/* ── Hamburger button ───────────────────────────────────────────────────── */
.top-nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-left: 8px;
  z-index: 301;
}

.top-nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.top-nav-hamburger.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.top-nav-hamburger.active span:nth-child(2) { opacity: 0; }
.top-nav-hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Mobile menu overlay ────────────────────────────────────────────────── */
.mobile-menu {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 299;
  background: rgba(9,13,18,0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.mobile-menu.open { display: flex; opacity: 1; }

.mobile-menu a {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 12px 24px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

.mobile-menu a:hover,
.mobile-menu a.active { color: var(--text); background: rgba(255,255,255,0.05); }

.mobile-menu .mobile-menu-cta {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-body);
  background: var(--blue);
  color: #fff;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .top-nav-links { display: none; }
  .top-nav-hamburger { display: flex; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  main.content { margin-left: 0; }
  .page-wrap { padding: 1.5rem 1.25rem 3rem; }
  .top-nav-badge { display: none; }
  .top-nav { height: 64px; }
  .top-nav-brand img { height: 48px; width: 48px; }
  .top-nav-cta { display: none; }
  #content { margin-left: 16px; margin-right: 16px; }
}

/* ── Theme toggle ─────────────────────────────────────────────────────────── */
.theme-btn {
  background: none;
  border: 1px solid var(--border-md);
  border-radius: 6px;
  padding: 7px 8px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  line-height: 0;
  transition: color 0.15s, background 0.15s;
}
.theme-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
html[data-theme="light"] .theme-btn:hover { background: rgba(0,0,0,0.05); }
.icon-sun  { display: none; }
.icon-moon { display: block; }
html[data-theme="light"] .icon-sun  { display: block; }
html[data-theme="light"] .icon-moon { display: none; }
