:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --green: #3fb950;
  --orange: #d29922;
  --red: #f85149;
  --code-bg: #1c2128;
  --code-text: #f0f6fc;
  --sidebar-width: 252px;
  /* category accent colors */
  --cat-core: #58a6ff;
  --cat-services: #3fb950;
  --cat-ansible: #58d7a6;
  --cat-gitlab: #e06c75;
  --cat-platform: #d29922;
  --cat-auth: #c678dd;
  --cat-tools: #e5c07b;
  --cat-workflow: #8b949e;
  --cat-config: #56d1e0;
  --cat-files: #d19a66;
}

/* ── Light mode ──────────────────────────────────────── */
html.light {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface2: #eaeef2;
  --border: #d0d7de;
  --text: #24292f;
  --text-muted: #57606a;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --green: #1a7f37;
  --orange: #9a6700;
  --red: #cf222e;
  --code-bg: #f6f8fa;
  --code-text: #24292f;
  --cat-core: #0969da;
  --cat-services: #1a7f37;
  --cat-ansible: #0d7377;
  --cat-gitlab: #c93545;
  --cat-platform: #9a6700;
  --cat-auth: #8250df;
  --cat-tools: #9a6700;
  --cat-workflow: #57606a;
  --cat-config: #0550ae;
  --cat-files: #b35900;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 15px;
}

/* ── Layout ─────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.site-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.2rem 1.25rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.site-title span {
  background: var(--accent);
  color: #0d1117;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.15em 0.45em;
  border-radius: 3px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-section {
  padding: 0.8rem 0 0.2rem;
}

.nav-label {
  display: block;
  padding: 0.25rem 1.25rem 0.2rem;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  font-weight: 600;
  opacity: 0.5;
}

.sidebar a {
  display: block;
  padding: 0.32rem 1.25rem 0.32rem 1.1rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.84rem;
  border-left: 2px solid transparent;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar a:hover {
  color: var(--text);
  background: var(--surface2);
  border-left-color: var(--border);
}

.sidebar a.active {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.07);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* ── Main content ─────────────────────────────────── */
.content {
  padding: 2.75rem 2.5rem 4rem;
  max-width: 900px;
  width: 100%;
}

/* ── Typography ──────────────────────────────────── */
h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.page-meta {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

h2 {
  font-size: 1.15rem;
  font-weight: 650;
  color: var(--text);
  margin: 2.25rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
  margin: 1.4rem 0 0.4rem;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}

h4 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 1.1rem 0 0.4rem;
}

p { margin-bottom: 0.85rem; }

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

strong { color: var(--text); font-weight: 600; }

ul, ol { padding-left: 1.4rem; margin-bottom: 0.85rem; }
li { margin-bottom: 0.3rem; line-height: 1.55; }

/* ── Definition lists (glossary) ────────────────── */
dl { margin-bottom: 0.5rem; }

dt {
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 1.1rem;
}

dd {
  margin-left: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding-left: 0;
  margin-bottom: 0.1rem;
  line-height: 1.55;
}

/* ── Code ─────────────────────────────────────────── */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 0.55rem 0 1rem;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Consolas, 'Courier New', monospace;
  font-size: 0.825rem;
  line-height: 1.65;
  color: var(--code-text);
  position: relative;
}

code {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Consolas, 'Courier New', monospace;
  font-size: 0.84em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  color: var(--code-text);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

.copy-btn {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  font-family: inherit;
}

pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); }
.copy-btn.copied { color: var(--green); }

/* ── Command explanation pattern ─────────────────── */
.cmd-note {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: -0.5rem;
  margin-bottom: 1.4rem;
  line-height: 1.5;
}

/* ── Callout boxes ───────────────────────────────── */
.note, .tip, .warn, .danger {
  padding: 0.8rem 1rem;
  margin: 1rem 0 1.1rem;
  border-radius: 0 6px 6px 0;
  font-size: 0.9rem;
  border-left: 3px solid;
}

.note  { background: rgba(88,166,255,0.07);  border-color: var(--accent);  }
.tip   { background: rgba(63,185,80,0.07);   border-color: var(--green);   }
.warn  { background: rgba(210,153,34,0.07);  border-color: var(--orange);  }
.danger{ background: rgba(248,81,73,0.07);   border-color: var(--red);     }

.note strong  { color: var(--accent); }
.tip strong   { color: var(--green); }
.warn strong  { color: var(--orange); }
.danger strong{ color: var(--red); }

/* ── Table of contents ───────────────────────────── */
.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 0.5rem 0 2rem;
  font-size: 0.875rem;
  display: inline-block;
  min-width: 220px;
}

.toc-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.toc ol, .toc ul { margin-bottom: 0; padding-left: 1.2rem; }
.toc li { margin-bottom: 0.22rem; }
.toc a { color: var(--text-muted); font-size: 0.85rem; }
.toc a:hover { color: var(--accent); text-decoration: none; }

/* ── Homepage cards ───────────────────────────────── */
.hero { margin-bottom: 2rem; }
.hero h1 { margin-bottom: 0.65rem; }
.hero p {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 560px;
  margin-bottom: 1.5rem;
}

.rule-of-thumb {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.4rem;
  margin: 1.5rem 0 2rem;
  font-size: 0.875rem;
}

.rule-of-thumb strong {
  display: block;
  margin-bottom: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.rule-of-thumb ul { margin: 0; padding-left: 1.2rem; }
.rule-of-thumb li {
  margin-bottom: 0.25rem;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.83rem;
  color: var(--code-text);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.8rem;
  margin: 0.5rem 0 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.05rem 1.15rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: block;
}

.card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(88,166,255,0.1);
  text-decoration: none;
}

.card-num {
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 700;
  font-family: 'SF Mono', Consolas, monospace;
  margin-bottom: 0.35rem;
  letter-spacing: 0.04em;
}

.card h3 {
  font-size: 0.875rem;
  color: var(--text);
  margin: 0 0 0.3rem;
  font-weight: 600;
  font-family: inherit;
}

.card p {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.45;
}

/* ── Section divider ─────────────────────────────── */
.section-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ── Anchor offset ───────────────────────────────── */
[id] { scroll-margin-top: 1.5rem; }

/* ── Collection tree ─────────────────────────────── */
.file-tree {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--code-text);
  overflow-x: auto;
  white-space: pre;
  margin: 0.55rem 0 1rem;
  position: relative;
}

/* ── Reading progress bar ────────────────────────── */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  z-index: 1000;
  transition: width 0.08s linear;
  pointer-events: none;
}

/* ── Back to top ──────────────────────────────────── */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 2.2rem;
  height: 2.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s, color 0.15s, border-color 0.15s;
  z-index: 90;
  font-family: inherit;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-to-top.visible { opacity: 1; transform: translateY(0); }
.back-to-top:hover { color: var(--accent); border-color: var(--accent); }

/* ── Heading anchor links ─────────────────────────── */
.heading-anchor {
  margin-left: 0.35em;
  color: var(--border);
  font-size: 0.8em;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
  vertical-align: middle;
  font-weight: 400;
}
h2:hover .heading-anchor,
h3:hover .heading-anchor { opacity: 1; }
.heading-anchor:hover { color: var(--accent); opacity: 1; }

/* ── Theme toggle ─────────────────────────────────── */
.theme-toggle {
  position: fixed;
  bottom: 4.3rem;
  right: 1.5rem;
  width: 2.2rem;
  height: 2.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  z-index: 90;
  font-family: inherit;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }

/* ── Floating TOC (very wide screens only) ────────── */
.toc-float {
  position: fixed;
  top: 2rem;
  right: 1.5rem;
  width: 195px;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  font-size: 0.78rem;
  z-index: 50;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.toc-float::-webkit-scrollbar { width: 3px; }
.toc-float::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.toc-float strong { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); opacity: 0.6; }
.toc-float a.toc-active { color: var(--accent); font-weight: 500; }

/* ── Page nav (prev / next) ───────────────────────── */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.page-nav a {
  flex: 0 1 48%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1.1rem;
  text-decoration: none;
  color: var(--text-muted);
  transition: border-color 0.15s, transform 0.15s;
}
.page-nav a:hover { border-color: var(--accent); text-decoration: none; }
.page-nav-prev:hover { transform: translateX(-2px); }
.page-nav-next { text-align: right; margin-left: auto; }
.page-nav-next:hover { transform: translateX(2px); }
.page-nav-dir {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.2rem;
  font-weight: 600;
  color: var(--text-muted);
}
.page-nav-title {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}
.page-nav a:hover .page-nav-dir,
.page-nav a:hover .page-nav-title { color: var(--accent); }

/* ── Syntax highlighting override ─────────────────── */
.hljs { background: transparent !important; }
html.light pre { border-color: var(--border); }

/* ── Sidebar search ──────────────────────────────── */
.nav-search-wrap {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.nav-search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.32rem 0.6rem;
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.12s;
}

.nav-search:focus { border-color: var(--accent); }
.nav-search::placeholder { color: var(--text-muted); opacity: 0.55; }

/* ── Collapsible nav sections ────────────────────── */
.nav-label {
  cursor: pointer;
  user-select: none;
  display: flex !important;
  justify-content: space-between;
  align-items: center;
  padding-right: 1rem;
}

.nav-label::after {
  content: '▾';
  font-size: 0.62rem;
  opacity: 0.4;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.nav-section.collapsed .nav-label::after {
  transform: rotate(-90deg);
}

.nav-section.collapsed > a {
  display: none;
}

/* ── Print ───────────────────────────────────────── */
@media print {
  .sidebar, .menu-toggle, .overlay, .copy-btn, .nav-search-wrap,
  .back-to-top, .theme-toggle, .progress-bar, .toc-float, .page-nav { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; max-width: 100%; }
  body { background: #fff; color: #000; font-size: 12pt; line-height: 1.5; }
  a { color: #000; }
  pre, code { background: #f5f5f5; border: 1px solid #ccc; color: #000; }
  pre { page-break-inside: avoid; white-space: pre-wrap; word-break: break-all; }
  h1 { font-size: 18pt; } h2 { font-size: 14pt; } h3 { font-size: 11pt; }
  .note, .tip, .warn, .danger { border: 1px solid #ccc; background: #f9f9f9; }
  .toc { border: 1px solid #ccc; }
}

/* ── Mobile ─────────────────────────────────────── */
.menu-toggle {
  display: none;
  align-items: center;
  gap: 0.4rem;
  position: fixed;
  top: 0.85rem;
  left: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 200;
  font-size: 0.82rem;
  font-family: inherit;
  line-height: 1;
}

.menu-toggle:hover { color: var(--text); }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 98;
}

.overlay.show { display: block; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: var(--sidebar-width);
    z-index: 100;
    transition: left 0.22s ease;
    height: 100vh;
  }

  .sidebar.open { left: 0; }
  .menu-toggle { display: flex; }

  .content { padding: 3.5rem 1.2rem 3rem; }

  .card-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

@media (max-width: 480px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 1.45rem; }
}
