:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dfe4ea;
  --border-strong: #c7d0da;
  --text: #16202c;
  --text-dim: #5b6876;
  --text-faint: #8b97a4;
  --accent: #0d7d8c;
  --accent-soft: #e2f2f4;
  --warn: #9a5b00;
  --warn-soft: #fdf3e2;
  --danger: #b3261e;
  --code-bg: #f2f4f7;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 16px rgba(16, 32, 48, .05);
  --sidebar-w: 288px;
  --toc-w: 232px;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0e1520;
  --surface: #151d2a;
  --surface-2: #1b2534;
  --border: #253040;
  --border-strong: #35435a;
  --text: #e4e9f0;
  --text-dim: #9fadbe;
  --text-faint: #71808f;
  --accent: #4bc5d6;
  --accent-soft: #12333a;
  --warn: #e0a54a;
  --warn-soft: #2e2413;
  --danger: #ef7d74;
  --code-bg: #0c121b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 18px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- khung ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), #2a4a78);
  color: #fff; font-weight: 700; font-size: 15px;
  display: grid; place-items: center; flex: none;
}
.brand-text { min-width: 0; }
.brand-title { font-weight: 650; font-size: 14px; letter-spacing: .1px; }
.brand-sub { font-size: 11.5px; color: var(--text-faint); }

.search-box { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 13.5px;
}
.search-box input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.search-hint { font-size: 11px; color: var(--text-faint); margin-top: 6px; }

.nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.nav-group { margin-bottom: 4px; }
.nav-group-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint); padding: 12px 10px 6px;
}
.nav-item {
  display: block; padding: 8px 11px; border-radius: 8px;
  color: var(--text); font-size: 13.5px; line-height: 1.35;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ni-sub { display: block; font-size: 11.5px; color: var(--text-faint); font-weight: 400; margin-top: 2px; }
.nav-item.active .ni-sub { color: var(--text-dim); }
.nav-badge {
  font-size: 10px; padding: 1px 6px; border-radius: 99px;
  background: var(--warn-soft); color: var(--warn); margin-left: 6px; vertical-align: 1px;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px 14px; display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--text-faint);
}
.btn-ghost {
  border: 1px solid var(--border-strong); background: transparent; color: var(--text-dim);
  border-radius: 7px; padding: 4px 9px; font: inherit; font-size: 12px; cursor: pointer;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---------- nội dung ---------- */
.main { flex: 1; min-width: 0; display: flex; justify-content: center; }
.main-inner { flex: 1; min-width: 0; max-width: 1100px; display: flex; gap: 28px; padding: 0 28px; }

.topbar {
  display: none;
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 9px 14px; align-items: center; gap: 10px;
}

.content { flex: 1; min-width: 0; padding: 30px 0 80px; }

.doc-head { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 26px; }
.doc-head h1 { margin: 0 0 6px; font-size: 27px; line-height: 1.25; letter-spacing: -.2px; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 12px; color: var(--text-faint); }
.doc-meta code { font-size: 11.5px; }

.toc {
  width: var(--toc-w); flex: 0 0 var(--toc-w);
  position: sticky; top: 0; align-self: flex-start;
  max-height: 100vh; overflow-y: auto; padding: 34px 0 40px;
}
.toc-title {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 8px;
}
.toc a {
  display: block; padding: 3.5px 10px; font-size: 12.5px; line-height: 1.4;
  color: var(--text-dim); border-left: 2px solid var(--border);
  overflow-wrap: anywhere;
}
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.lv3 { padding-left: 22px; font-size: 12px; }
.toc a.current { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* ---------- markdown ---------- */
.md h2 {
  font-size: 20px; margin: 38px 0 12px; padding-top: 8px; letter-spacing: -.15px;
  border-top: 1px solid var(--border); padding-top: 26px;
}
.md h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.md h3 { font-size: 15.5px; margin: 26px 0 8px; }
.md h4 { font-size: 14px; margin: 20px 0 6px; color: var(--text-dim); }
.md p { margin: 0 0 13px; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 22px; }
.md li { margin-bottom: 5px; }
.md li > ul, .md li > ol { margin-top: 5px; margin-bottom: 4px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 26px 0; }
.md strong { font-weight: 650; }

.md code {
  background: var(--code-bg); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .87em;
}
.md pre.code {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; overflow-x: auto; margin: 0 0 16px; position: relative;
}
.md pre.code code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.55; }
.md pre.code[data-lang]::before {
  content: attr(data-lang);
  position: absolute; top: 0; right: 0;
  font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint); background: var(--surface-2);
  padding: 2px 8px; border-radius: 0 9px 0 8px; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border);
}

.md blockquote {
  margin: 0 0 16px; padding: 12px 16px;
  background: var(--warn-soft); border-left: 3px solid var(--warn);
  border-radius: 0 9px 9px 0;
}
.md blockquote > :last-child { margin-bottom: 0; }

.table-wrap {
  overflow-x: auto; margin: 0 0 18px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md th, .md td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.md th { background: var(--surface-2); font-weight: 650; font-size: 12px; white-space: nowrap; }
.md tbody tr:last-child td { border-bottom: 0; }
.md tbody tr:hover td { background: var(--surface-2); }
.md td code, .md th code { white-space: nowrap; }

.anchor {
  opacity: 0; margin-left: 8px; color: var(--text-faint);
  font-weight: 400; text-decoration: none; font-size: .8em;
}
h2:hover .anchor, h3:hover .anchor { opacity: 1; }
:target { scroll-margin-top: 20px; }

/* ---------- trang chủ ---------- */
.home-hero { padding: 46px 0 8px; }
.home-hero h1 { font-size: 30px; margin: 0 0 8px; letter-spacing: -.3px; }
.home-hero p { color: var(--text-dim); margin: 0 0 8px; max-width: 62ch; }
.home-group { margin-top: 34px; }
.home-group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); margin: 0 0 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  display: block; padding: 16px 18px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.card-title { font-weight: 650; margin-bottom: 4px; font-size: 14.5px; }
.card-sub { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }
.card-meta { font-size: 11px; color: var(--text-faint); margin-top: 10px; }

/* ---------- tìm kiếm ---------- */
.results { padding: 30px 0 70px; }
.results h1 { font-size: 20px; margin: 0 0 4px; }
.results .count { color: var(--text-faint); font-size: 12.5px; margin-bottom: 20px; }
.result {
  display: block; padding: 13px 16px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.result:hover { border-color: var(--accent); text-decoration: none; }
.result-crumb { font-size: 11px; color: var(--text-faint); margin-bottom: 3px; }
.result-title { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.result-snippet { font-size: 12.5px; color: var(--text-dim); line-height: 1.55; }
mark { background: var(--accent-soft); color: var(--accent); padding: 0 2px; border-radius: 3px; font-weight: 600; }

.empty { color: var(--text-faint); font-size: 13.5px; padding: 20px 0; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .toc { display: none; }
  .main-inner { max-width: 860px; }
}

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed; z-index: 40; top: 0; left: 0; height: 100vh;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow); width: 86vw; max-width: 320px; flex-basis: auto;
  }
  .sidebar.open { transform: none; }
  .scrim {
    position: fixed; inset: 0; z-index: 35; background: rgba(4, 10, 18, .45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .main-inner { padding: 0 16px; }
  .content { padding: 20px 0 60px; }
  .doc-head h1, .home-hero h1 { font-size: 22px; }
  .md h2 { font-size: 18px; }
  .home-hero { padding: 26px 0 0; }
}

@media print {
  .sidebar, .toc, .topbar, .anchor, .scrim { display: none !important; }
  .main-inner { padding: 0; max-width: none; }
  body { background: #fff; }
  .md pre.code, .table-wrap { break-inside: avoid; }
  .md h2 { break-after: avoid; }
}
