/* The wiki's theme. A documentation layout after duckdb.org/docs: a slim top bar, a
   collapsible section sidebar, a reading column and an "On this page" rail, in black on
   neutral greys, with blue kept for links. Tokens first; components use tokens only. */

:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --bg-sunk: #efeff1;
  --ink: #18181b;
  --muted: #52525b;
  --faint: #8b8b94;
  --line: #e4e4e7;
  --accent: #3f3f46;
  --accent-soft: #eeeef0;
  --accent-ink: #ffffff;
  --link: #1d4ed8;
  --link-hover-bg: #eff2fb;
  --code-bg: #f4f4f5;
  --note: #1450b8;
  --tip: #1f7a4d;
  --warn: #a15c00;
  --shadow: 0 12px 40px rgba(20, 20, 20, .14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --top: 60px;
  --side: 272px;
  --rail: 224px;
  --measure: 46rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113; --bg-soft: #18181b; --bg-sunk: #202024; --ink: #ececef; --muted: #a1a1aa;
    --faint: #71717a; --line: #2a2a2f; --accent: #d4d4d8; --accent-soft: #26262b;
    --accent-ink: #111113; --link: #8fb0ff; --link-hover-bg: #1c2233; --code-bg: #1b1b1f;
    --note: #8db8ff; --tip: #6fd3a0; --warn: #f0b35a; --shadow: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111113; --bg-soft: #18181b; --bg-sunk: #202024; --ink: #ececef; --muted: #a1a1aa;
    --faint: #71717a; --line: #2a2a2f; --accent: #d4d4d8; --accent-soft: #26262b;
    --accent-ink: #111113; --link: #8fb0ff; --link-hover-bg: #1c2233; --code-bg: #1b1b1f;
  --note: #8db8ff; --tip: #6fd3a0; --warn: #f0b35a; --shadow: 0 12px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 6px 10px; z-index: 100; }
.skip:focus { left: 8px; }

/* Top bar */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30; height: var(--top);
  display: flex; align-items: center; gap: 10px; padding-inline: 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.brand img { display: block; border-radius: 7px; }
.brand-name { font-size: 17px; white-space: nowrap; }
.brand-tag {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px;
}
.topbar-spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); }
.menu-btn { display: none; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}
.search-btn {
  display: flex; align-items: center; gap: 8px; width: min(320px, 40vw); height: 38px; padding: 0 8px 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-soft); color: var(--muted);
  font: inherit; font-size: 14px; cursor: pointer; text-align: left;
}
.search-btn:hover { border-color: var(--faint); }
.search-label { flex: 1; }
kbd {
  font: 11px/1 var(--mono); color: var(--muted); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 3px 5px; background: var(--bg);
}

/* Three columns */
.layout {
  display: grid; grid-template-columns: var(--side) minmax(0, 1fr) var(--rail);
  max-width: 1440px; margin: 0 auto; min-height: calc(100vh - var(--top));
}
.sidebar {
  position: sticky; top: calc(var(--top) + env(safe-area-inset-top, 0px)); align-self: start;
  height: calc(100vh - var(--top)); overflow-y: auto; padding: 24px 16px 40px;
  border-right: 1px solid var(--line); font-size: 14.5px;
}
.sidenav { display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: block; padding: 5px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; line-height: 1.4;
}
.side-link:hover { background: var(--bg-soft); }
.side-link.active { background: var(--accent-soft); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.side-group { margin-top: 6px; }
.side-group > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; border-radius: 6px; font-weight: 650; color: var(--ink);
}
.side-group > summary::-webkit-details-marker { display: none; }
.side-group > summary::after {
  content: ""; width: 7px; height: 7px; border-right: 1.8px solid var(--faint); border-bottom: 1.8px solid var(--faint);
  transform: rotate(-45deg); transition: transform .15s;
}
.side-group[open] > summary::after { transform: rotate(45deg); }
.side-group > summary:hover { background: var(--bg-soft); }
.side-links { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 10px; padding-left: 8px; border-left: 1px solid var(--line); }

.content { min-width: 0; padding: 28px 48px 64px; }
.content > * { max-width: var(--measure); }
.breadcrumbs { font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--ink); text-decoration: underline; }
.breadcrumbs .sep { color: var(--faint); }
.page-title { font-size: clamp(30px, 4vw, 40px); line-height: 1.15; letter-spacing: -.025em; margin: 10px 0 10px; text-wrap: balance; }
.lead { font-size: 18.5px; line-height: 1.55; color: var(--muted); margin: 0 0 28px; }
.is-home .breadcrumbs { display: none; }
.is-home .page-title { font-size: clamp(34px, 5vw, 48px); margin-top: 16px; }
.is-home .page-title::after {
  content: ""; display: block; width: 48px; height: 3px; margin-top: 18px; background: var(--accent); border-radius: 2px;
}

/* Prose */
.prose { font-size: 16.5px; }
.prose > :first-child { margin-top: 0; }
.prose h2, .prose h3, .prose h4 { position: relative; line-height: 1.3; letter-spacing: -.015em; text-wrap: balance; }
.prose h2 { font-size: 25px; margin: 44px 0 12px; padding-top: 20px; border-top: 1px solid var(--line); }
.prose h3 { font-size: 19.5px; margin: 30px 0 8px; }
.prose h4 { font-size: 16.5px; margin: 24px 0 6px; }
.anchor { margin-left: 8px; color: var(--faint); text-decoration: none; opacity: 0; font-weight: 400; }
.prose :is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 1; }
.prose p, .prose ul, .prose ol { margin: 0 0 16px; }
.prose ul, .prose ol { padding-left: 24px; }
.prose li { margin: 4px 0; }
.prose li > ul, .prose li > ol { margin: 4px 0 0; }
.prose li::marker { color: var(--faint); }
.prose a { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent); border-radius: 2px; }
.prose a:hover { background: var(--link-hover-bg); text-decoration-color: var(--link); }
.prose strong { font-weight: 650; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.prose code { font: .88em var(--mono); background: var(--code-bg); border: 1px solid var(--line); border-radius: 4px; padding: .08em .35em; }
.prose pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; overflow-x: auto; line-height: 1.5; }
.prose pre code { background: none; border: 0; padding: 0; font-size: 13.5px; }
.prose blockquote { margin: 0 0 16px; padding: 2px 0 2px 16px; border-left: 3px solid var(--line); color: var(--muted); }
.prose img { border-radius: 8px; border: 1px solid var(--line); }

.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--line); border-radius: 8px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 14.5px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.prose th, .prose td { text-align: left; vertical-align: top; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.prose th { background: var(--bg-soft); font-weight: 650; white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.pages-table td:first-child { white-space: nowrap; font-weight: 600; }

.callout { margin: 0 0 20px; padding: 12px 16px; border-radius: 8px; background: var(--bg-soft); border: 1px solid var(--line); border-left: 4px solid var(--note); }
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--note); margin: 0 0 4px !important; }
.callout-tip { border-left-color: var(--tip); } .callout-tip .callout-title { color: var(--tip); }
.callout-warning { border-left-color: var(--warn); } .callout-warning .callout-title { color: var(--warn); }
.callout-important { border-left-color: var(--ink); } .callout-important .callout-title { color: var(--ink); }

/* Home: section cards and the latest changes */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 12px; margin: 0 0 28px; }
.card {
  display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); text-decoration: none !important; background: var(--bg);
  transition: border-color .15s, background .15s;
}
.card:hover { border-color: var(--ink); background: var(--bg) !important; }
.card-title { font-weight: 700; font-size: 16.5px; display: flex; align-items: center; gap: 8px; }
.card-title::before { content: ""; width: 8px; height: 8px; background: var(--faint); border-radius: 50%; }
.card-desc { color: var(--muted); font-size: 14.5px; line-height: 1.5; }
.latest { border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px 4px; background: var(--bg-soft); margin-bottom: 20px; }
.latest-date { font-size: 13.5px; font-weight: 600; color: var(--muted); margin: 0 0 8px !important; }
.latest h3 { font-size: 15px; margin: 14px 0 4px; }

/* Changelog: dated entries read as patch notes */
.prose h2[id^="20"] { font-variant-numeric: tabular-nums; }

/* Pager and page meta */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; }
.pager-link { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--ink); }
.pager-link:hover { border-color: var(--ink); }
.pager-link.next { grid-column: 2; text-align: right; }
.pager-dir { font-size: 12.5px; color: var(--muted); }
.pager-title { font-weight: 650; }
.page-meta { margin-top: 28px; font-size: 13px; color: var(--faint); }

/* On this page */
.toc {
  position: sticky; top: calc(var(--top) + env(safe-area-inset-top, 0px)); align-self: start;
  max-height: calc(100vh - var(--top)); overflow-y: auto; padding: 32px 16px 32px 8px; font-size: 13.5px;
}
.toc-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc a { display: block; padding: 3px 10px; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.4; }
.toc .toc-l3 a { padding-left: 22px; }
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--ink); border-left-color: var(--accent); font-weight: 600; }

.site-footer { border-top: 1px solid var(--line); padding-block: 20px; padding-inline: 16px; text-align: center; font-size: 13px; color: var(--faint); }
.site-footer p { margin: 0; }
.site-footer p + p { margin-top: 6px; }

/* Search */
.search-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20, 20, 20, .45); padding: 10vh 16px 16px; }
.search-panel { max-width: 640px; margin: 0 auto; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.search-field { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); color: var(--muted); }
.search-field input { flex: 1; min-width: 0; height: 54px; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: 17px; }
.search-results { list-style: none; margin: 0; padding: 6px; max-height: 55vh; overflow-y: auto; }
.search-results:empty { display: none; }
.search-results a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.search-results li[aria-selected="true"] a, .search-results a:hover { background: var(--accent-soft); }
.sr-section { font-size: 12px; color: var(--muted); }
.sr-title { font-weight: 650; }
.sr-snippet { font-size: 13.5px; color: var(--muted); line-height: 1.45; margin-top: 2px; }
.sr-snippet mark { background: var(--bg-sunk); color: var(--ink); font-weight: 600; border-radius: 2px; }
.search-hint { margin: 0; padding: 10px 16px; font-size: 12.5px; color: var(--faint); border-top: 1px solid var(--line); }

/* Narrower screens: drop the rail, then turn the sidebar into a drawer */
@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--side) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .layout { display: block; }
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; top: calc(var(--top) + env(safe-area-inset-top, 0px)); left: 0; bottom: 0; z-index: 40;
    width: min(300px, 85vw); height: auto; background: var(--bg); transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(20, 20, 20, .35); }
  .content { padding: 20px 16px 48px; }
  .search-btn { width: auto; }
  .search-label, .search-kbd, .brand-tag { display: none; }
  .pager { grid-template-columns: 1fr; }
  .pager-link.next { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
