/* ── Design tokens ─────────────────────────────────────────── */

:root {
  --bg: #ffffff;
  --bg-muted: #f6f7f9;
  --bg-sidebar: #f5f5f7;
  --bg-active: #e8f0fe;
  --bg-code: #f4f4f6;
  --border: #e6e6ea;
  --border-strong: #d0d0d5;
  --text: #1a1a1f;
  --text-muted: #5c5c66;
  --text-dim: #8a8a94;
  --link: #1e63d0;
  --link-hover: #164b9f;
  --accent: #2563eb;
  /* Prose cap. Wide enough for the troubleshooting/runbook tables (4-col,
     long "Common causes" text) without forcing horizontal scroll, narrow
     enough that paragraphs don't get unreadably long. */
  --max-content: 96ch;
  --sidebar-w: 272px;
  --toc-w: 224px;
  /* Inter for UI / body — humanist sans with optimised x-height for screen
     reading. JetBrains Mono for code — has clear l/I/1 + 0/O distinctions
     that github-mono lacks. Both gracefully fall back to system stacks if
     Google Fonts is unreachable. */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
}

/* Dark palette — tuned 2026-04-25 from feedback that the previous one was
   too uniform / low-contrast. Based on GitHub Dark High Contrast + Vercel
   docs: clear elevation steps (sidebar < bg < muted/code), brighter text
   (~16:1 contrast on bg), visible borders, vibrant blue links. */
:root[data-theme='dark'] {
  --bg: #0d0e11;
  --bg-muted: #181a1f;
  --bg-sidebar: #08090b;
  --bg-active: #1f3a66;
  --bg-code: #1a1c21;
  --border: #30333c;
  --border-strong: #44485a;
  --text: #f3f4f6;
  --text-muted: #b8bcc7;
  --text-dim: #828791;
  --link: #7cb6ff;
  --link-hover: #a8cdff;
  --accent: #60a5fa;
}

/* Honour OS preference when no explicit override is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0d0e11;
    --bg-muted: #181a1f;
    --bg-sidebar: #08090b;
    --bg-active: #1f3a66;
    --bg-code: #1a1c21;
    --border: #30333c;
    --border-strong: #44485a;
    --text: #f3f4f6;
    --text-muted: #b8bcc7;
    --text-dim: #828791;
    --link: #7cb6ff;
    --link-hover: #a8cdff;
    --accent: #60a5fa;
  }
}

/* ── Reset + base ──────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Inter ships with stylistic alternates that improve legibility:
       cv11 — single-storey 'a' (matches the rest of the glyph weight)
       ss01 — 'I' / 'l' / '1' contextual disambiguation
       cv02 — open '4'
     Browsers without Inter fall back silently. */
  font-feature-settings: 'cv11' 1, 'ss01' 1, 'cv02' 1;
}

/* Themed scrollbars — native scrollbars stay OS-light by default which
   reads as a glaring white stripe down the right side in dark mode. The
   `scrollbar-color` property covers Firefox; the WebKit pseudo-elements
   cover Chrome/Safari. Both fall back to native styling on browsers that
   don't support them, so nothing breaks. */
html {
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}
::-webkit-scrollbar-corner {
  background: transparent;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

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

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 16px 40px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}
.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand-tag {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.nav-group {
  margin-top: 18px;
}
.nav-group:first-child {
  margin-top: 0;
}

.nav-group-title {
  margin: 0 0 8px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  /* Section labels (GIỚI THIỆU / PRODUCT / NGHIỆP VỤ…) need to read as
     dividers, not as low-priority captions. Bold + near-black on light
     gives the at-a-glance grouping the dim grey was missing. */
  color: var(--text);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-list a {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 14.5px;
  color: var(--text-muted);
  line-height: 1.45;
}
.nav-list a:hover {
  background: var(--border);
  color: var(--text);
  text-decoration: none;
}
.nav-list a[aria-current='page'] {
  background: var(--bg-active);
  color: var(--link);
  font-weight: 600;
}
.nav-list .ext {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 11px;
}

/* Hierarchical numbering — `1.`, `2.`, `6.1.`, `6.2.` ... */
.nav-list .nav-num {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  flex-shrink: 0;
  min-width: 1.6em;
  /* Align with first line of multi-line titles, not centered vertically */
  line-height: 1.45;
}
.nav-list a[aria-current='page'] .nav-num {
  color: var(--link);
}
/* Indent depth-2 entries (e.g. status-matrix children, "6.1 ...") so
   the visual hierarchy matches the numbering. */
.nav-list li.nav-nested > a {
  padding-left: 22px;
  font-size: 13.5px;
}
.nav-list li.nav-nested > a .nav-num {
  min-width: 2.2em;
}

/* ── Main layout ───────────────────────────────────────────── */

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: 40px;
  padding: 20px 40px 80px;
  min-width: 0;
}

@media (max-width: 1080px) {
  .content {
    grid-template-columns: 1fr;
  }
  .toc-rail {
    display: none;
  }
}

.content-wrap {
  /* No outer cap — let tables, code blocks, and mermaid diagrams use the
     full grid cell. Prose paragraphs/lists are capped individually below
     so reading flow stays comfortable. */
  min-width: 0;
  margin: 0 auto;
  width: 100%;
}

/* Cap text-heavy elements only — keeps line length readable while still
   letting wide content (tables, diagrams, code) breathe. */
.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose dl {
  max-width: var(--max-content);
}

.content-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

.crumb {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
/* Sun icon shows when current theme is dark (so the click target reads as
   "switch to light"); moon shows in light mode. The previous version used
   a comma-separated list ending with `, @media (...)` which is invalid CSS
   — the `@media` block silently broke the whole selector and left both
   icons hidden in dark mode. Split into discrete rules to make it work. */
.theme-toggle .icon-sun {
  display: none;
}
.theme-toggle .icon-moon {
  display: inline-block;
}
:root[data-theme='dark'] .theme-toggle .icon-sun {
  display: inline-block;
}
:root[data-theme='dark'] .theme-toggle .icon-moon {
  display: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-toggle .icon-sun {
    display: inline-block;
  }
  :root:not([data-theme='light']) .theme-toggle .icon-moon {
    display: none;
  }
}

/* ── TOC rail ──────────────────────────────────────────────── */

.toc-rail {
  position: sticky;
  top: 24px;
  align-self: flex-start;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding-top: 40px;
}

.toc h4 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}
.toc li {
  margin: 0;
}
.toc a {
  display: block;
  padding: 4px 0 4px 12px;
  margin-left: -1px;
  border-left: 1px solid transparent;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}
.toc a:hover {
  color: var(--text);
  text-decoration: none;
  border-left-color: var(--border-strong);
}
.toc-l3 a {
  padding-left: 24px;
  font-size: 12.5px;
}

/* ── Prose / markdown typography ───────────────────────────── */

.prose {
  font-size: 15px;
  line-height: 1.7;
  word-wrap: break-word;
}

.prose > :first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  color: var(--text);
  line-height: 1.25;
  font-weight: 700;
  margin: 2em 0 0.8em;
  scroll-margin-top: 24px;
}
.prose h1 {
  font-size: 2em;
  margin-top: 0;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}
.prose h2 {
  font-size: 1.45em;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--border);
}
.prose h3 {
  font-size: 1.2em;
}
.prose h4 {
  font-size: 1em;
}

.prose p {
  margin: 0 0 1em;
}

.prose ul,
.prose ol {
  margin: 0 0 1em;
  padding-left: 1.5em;
}
.prose li {
  margin: 0.25em 0;
}
.prose li > p {
  margin: 0.4em 0;
}

.prose blockquote {
  margin: 1em 0;
  padding: 0.4em 1em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
  background: var(--bg-muted);
  border-radius: 0 6px 6px 0;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}
.prose pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 1.2em 0;
  line-height: 1.5;
}
.prose pre code {
  background: transparent;
  padding: 0;
  font-size: 13px;
}

/* Override the bundled hljs theme's base text color in dark mode so
   property names / identifiers / punctuation (everything that doesn't
   match a more-specific token class) stays readable on `--bg-code`.
   atom-one-dark's default `#abb2bf` reads as muted grey; bumping to
   near-white restores the contrast users expect from the rest of the page. */
:root[data-theme='dark'] .hljs {
  color: #e6edf3;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .hljs {
    color: #e6edf3;
  }
}

.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 1.2em 0;
  font-size: 13.5px;
  /* Tables earn more width than prose paragraphs — runbook + matrix
     pages have 4-5 cols of long text. Break out of the .content-wrap
     cap so the columns can breathe; horizontal scroll still kicks in
     on narrow viewports. */
  max-width: none;
  width: 100%;
}
.prose thead {
  background: var(--bg-muted);
}
.prose th,
.prose td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.prose th {
  font-weight: 600;
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* GFM task list render <input type="checkbox" disabled> — browser mặc định
   fade hết cả checked & unchecked, gây nhầm lẫn "đã làm vs chưa". Override:
   checked = filled accent + check sáng, item-text giữ full color (không
   strike-through để tránh nhầm "deprecated"); unchecked = border rỗng + text
   muted để contrast rõ với checked. */
.prose input[type='checkbox'] {
  margin-right: 8px;
  appearance: none;
  -webkit-appearance: none;
  width: 1.05em;
  height: 1.05em;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg);
  display: inline-block;
  vertical-align: -0.18em;
  position: relative;
  cursor: default;
  opacity: 1;
  transition: background-color 0.12s, border-color 0.12s;
}

.prose input[type='checkbox']:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.prose input[type='checkbox']:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 46%;
  width: 0.32em;
  height: 0.6em;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -55%) rotate(45deg);
}

.prose input[type='checkbox']:disabled {
  /* GFM marks all task-list checkboxes disabled — we want them readable, not greyed */
  opacity: 1;
}

/* Task-list item: highlight done (✅), dim pending so the visual contrast
   matches the semantics. `li:has()` is widely supported in modern engines. */
.prose li:has(> input[type='checkbox']:checked) {
  color: var(--text);
}

.prose li:has(> input[type='checkbox']:not(:checked)) {
  color: var(--text-muted);
}

/* Anchor affordance on hover — copy link target on click via JS */
.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  position: relative;
}
.prose h1 > a.hash-link,
.prose h2 > a.hash-link,
.prose h3 > a.hash-link,
.prose h4 > a.hash-link {
  display: inline-block;
  margin-left: 0.25em;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.15s;
  font-weight: 400;
}
.prose h1:hover > a.hash-link,
.prose h2:hover > a.hash-link,
.prose h3:hover > a.hash-link,
.prose h4:hover > a.hash-link {
  opacity: 1;
}

/* ── Mobile ────────────────────────────────────────────────── */

.sidebar-toggle {
  display: none;
}

@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 82vw);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
  }
  body.nav-open .sidebar {
    transform: translateX(0);
  }
  body.nav-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 30;
  }
  .sidebar-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 50;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }
  .content {
    padding: 56px 20px 60px;
  }
}
