/* mig-reports — một stylesheet cho mọi trang. Màu chỉ khai báo ở token. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e2e1dc;
  --border-strong: #cfcdc6;
  --text: #1d1d1b;
  --text-2: #55534d;
  --text-3: #85827a;
  --accent: #2456c7;
  --accent-soft: #e8eefb;
  --code-bg: #f0efeb;
  --code-text: #3a3833;

  --ok: #1d7a45;       --ok-soft: #e3f3e9;
  --warn: #9a6100;     --warn-soft: #fbf0d9;
  --bad: #b42318;      --bad-soft: #fde7e4;
  --info: #3a5bb0;     --info-soft: #e7ecf9;
  --neutral: #5d5a52;  --neutral-soft: #ecebe6;

  --m-get: #1d7a45;   --m-post: #2456c7;  --m-put: #9a6100;
  --m-patch: #7a4ab8; --m-delete: #b42318; --m-other: #5d5a52;

  --shadow: 0 1px 2px rgba(20, 20, 15, .05), 0 1px 1px rgba(20, 20, 15, .03);
  --radius: 8px;
  --radius-sm: 5px;
  --topbar-h: 52px;
  --sidebar-w: 264px;
  --toc-w: 232px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1c1c1a; --surface-2: #232320; --border: #31302c; --border-strong: #45433d;
    --text: #ecebe6; --text-2: #b6b3aa; --text-3: #8a877e; --accent: #8fb0ff; --accent-soft: #1f2a44;
    --code-bg: #262622; --code-text: #e2dfd6;
    --ok: #5cc98a; --ok-soft: #173525; --warn: #e6b450; --warn-soft: #3a2d10; --bad: #ff8a7a; --bad-soft: #43201b;
    --info: #9db4ff; --info-soft: #1f2a44; --neutral: #b6b3aa; --neutral-soft: #2b2a26;
    --m-get: #5cc98a; --m-post: #8fb0ff; --m-put: #e6b450; --m-patch: #c4a2f5; --m-delete: #ff8a7a; --m-other: #b6b3aa;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1c1c1a; --surface-2: #232320; --border: #31302c; --border-strong: #45433d;
  --text: #ecebe6; --text-2: #b6b3aa; --text-3: #8a877e; --accent: #8fb0ff; --accent-soft: #1f2a44;
  --code-bg: #262622; --code-text: #e2dfd6;
  --ok: #5cc98a; --ok-soft: #173525; --warn: #e6b450; --warn-soft: #3a2d10; --bad: #ff8a7a; --bad-soft: #43201b;
  --info: #9db4ff; --info-soft: #1f2a44; --neutral: #b6b3aa; --neutral-soft: #2b2a26;
  --m-get: #5cc98a; --m-post: #8fb0ff; --m-put: #e6b450; --m-patch: #c4a2f5; --m-delete: #ff8a7a; --m-other: #b6b3aa;
  --shadow: none;
  color-scheme: dark;
}

/* ---------- nền ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 var(--font); overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
code, kbd, pre { font-family: var(--mono); font-size: .86em; }
.icon-btn svg, .filter svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--text-3); }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 6px 10px; }
.skip-link:focus { left: 8px; }
kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); }

.preview-ribbon {
  background: var(--warn-soft); color: var(--warn); text-align: center; font-size: 12.5px; font-weight: 600;
  padding: 4px 12px; border-bottom: 1px solid var(--border);
}

/* ---------- thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; color: var(--text); white-space: nowrap; font-size: 14.5px; }
.brand:hover { text-decoration: none; color: var(--accent); }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; font-size: 13.5px; color: var(--text-2); overflow: hidden; }
.crumbs > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs a { color: var(--text-2); }
.crumbs .sep { color: var(--text-3); flex: none; }
.crumbs [aria-current] { color: var(--text); font-weight: 600; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.menu-btn { display: none; }

/* ---------- bố cục ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
main { min-width: 0; padding: 24px 32px 32px; }
main:focus { outline: none; }

/* ---------- cột trái ---------- */
.sidebar {
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 14px 10px 24px; border-right: 1px solid var(--border); background: var(--surface);
  font-size: 13.5px;
}
.side-home { display: block; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text); font-weight: 600; }
.side-domain { margin-top: 10px; }
.side-domain summary {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 4px 10px; cursor: pointer; list-style: none; color: var(--text-3);
  font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.side-domain summary::-webkit-details-marker { display: none; }
.side-domain summary::before { content: "▸"; font-size: 10px; transition: transform .15s; }
.side-domain[open] summary::before { transform: rotate(90deg); }
.side-domain-link { color: inherit; flex: 1; }
.side-count { font-weight: 500; letter-spacing: 0; }
.side-domain ul { list-style: none; margin: 2px 0 0; padding: 0; }
.side-unit {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); line-height: 1.35;
}
.side-unit:hover, .side-home:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.side-unit.is-current, .side-home.is-current, .side-domain-link.is-current {
  background: var(--accent-soft); color: var(--text); font-weight: 600;
}
.side-unit .method { width: 52px; flex: none; text-align: center; }
.side-unit-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chip method ---------- */
.method {
  display: inline-block; font: 700 10.5px/1 var(--mono); letter-spacing: .02em;
  padding: 3px 5px; border-radius: 4px; border: 1px solid currentColor; color: var(--m-other);
  vertical-align: middle;
}
.method-get { color: var(--m-get); } .method-post { color: var(--m-post); } .method-put { color: var(--m-put); }
.method-patch { color: var(--m-patch); } .method-delete { color: var(--m-delete); }

/* ---------- badge ---------- */
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .82em; font-weight: 650;
  line-height: 1.5; white-space: nowrap; background: var(--neutral-soft); color: var(--neutral);
}
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.gate-pass { background: var(--ok-soft); color: var(--ok); }
.gate-fail { background: var(--bad-soft); color: var(--bad); }
.gate-pending-sonar { background: var(--warn-soft); color: var(--warn); }

/* ---------- đầu trang ---------- */
.page-head, .unit-head { margin-bottom: 20px; }
.page-head h1 { margin: 2px 0 6px; font-size: 26px; line-height: 1.25; }
.lead { color: var(--text-2); margin: 0 0 16px; max-width: 72ch; }
.unit-kicker { margin: 0 0 4px; color: var(--text-3); font-size: 13px; }
.unit-title { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 0 0 10px; font-size: 21px; line-height: 1.3; }
.unit-title .method { font-size: 12px; padding: 4px 7px; }
.unit-target { font-family: var(--mono); font-weight: 600; overflow-wrap: break-word; min-width: 0; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0 0 16px; font-size: 13.5px; }
.meta-row > div { display: flex; align-items: center; gap: 6px; }
.meta-row dt { color: var(--text-3); }
.meta-row dd { margin: 0; }
.version-pick select {
  font: inherit; font-size: 13px; padding: 3px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); max-width: 100%;
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 0; max-width: 720px; }
.stats > div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.stats dt { color: var(--text-3); font-size: 12.5px; }
.stats dd { margin: 0; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- tab ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; margin-bottom: -1px;
  color: var(--text-2); font-weight: 600; font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); text-decoration: none; background: var(--surface-2); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-icon { font-family: var(--mono); opacity: .8; }
.tab-count { font-size: 11.5px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--text-3); }

.banner { border-radius: var(--radius); padding: 10px 14px; margin: 0 0 18px; font-size: 14px; }
.banner-warn { background: var(--warn-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.banner a { font-weight: 600; margin-left: 6px; }

/* ---------- tài liệu + mục lục ---------- */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w); gap: 32px; align-items: start; }
.toc-box { grid-column: 2; grid-row: 1; position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100vh - var(--topbar-h) - 32px); overflow-y: auto; font-size: 13px; }
.toc summary { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); cursor: pointer; list-style: none; padding: 4px 0 8px; }
.toc summary::-webkit-details-marker { display: none; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc li a { display: block; padding: 3px 0 3px 12px; margin-left: -1px; border-left: 2px solid transparent; color: var(--text-2); line-height: 1.4; }
.toc li.lv3 a {
  padding-left: 24px; font-size: 12.5px;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.toc li a:hover { color: var(--text); text-decoration: none; }
.toc li a.is-active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

.doc {
  grid-column: 1; grid-row: 1; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px 32px 28px;
}
.doc > h1 { font-size: 15px; font-weight: 600; color: var(--text-3); margin: 14px 0 8px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.doc h2 { font-size: 19px; line-height: 1.35; margin: 34px 0 10px; padding-top: 4px; }
.doc h3 { font-size: 16px; line-height: 1.4; margin: 24px 0 8px; }
.doc h4 { font-size: 14.5px; margin: 18px 0 6px; }
.doc h2, .doc h3, .doc h4 { position: relative; }
.doc p, .doc ul, .doc ol { margin: 8px 0; }
.doc ul, .doc ol { padding-left: 22px; }
.doc li { margin: 3px 0; }
.doc li > strong:first-child { color: var(--text); }
.doc strong { font-weight: 650; }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
.doc blockquote { margin: 10px 0; padding: 4px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.anchor { margin-left: 6px; color: var(--text-3); opacity: 0; font-weight: 400; font-size: .85em; }
.doc :is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 1; text-decoration: none; }
.dead-link { border-bottom: 1px dashed var(--text-3); }

/* code */
.doc code, code.plain {
  background: var(--code-bg); color: var(--code-text); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere;
}
.doc pre { background: var(--code-bg); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; line-height: 1.5; }
.doc pre code { background: none; padding: 0; overflow-wrap: normal; }
.doc code.cite {
  cursor: copy; color: var(--info); background: var(--info-soft);
  border: 1px solid color-mix(in srgb, var(--info) 22%, transparent);
}
.doc code.cite:hover { border-color: var(--info); }
.doc code.cite.copied { color: var(--ok); background: var(--ok-soft); }
.doc a.xref { font-weight: 600; text-decoration: underline dotted; text-underline-offset: 2px; }

/* bảng */
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.doc .table-wrap { margin: 12px 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; line-height: 1.5; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 650; color: var(--text-2); white-space: nowrap; font-size: 12.5px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.doc td { min-width: 90px; }
.doc td:first-child { min-width: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* khối nổi bật do JS gắn */
.summary-box {
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--radius); padding: 2px 18px 10px; margin: 18px 0 8px;
}
.summary-box > h2 { margin-top: 14px; }
.card {
  border: 1px solid var(--border); border-left: 4px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 2px 16px 10px; margin: 14px 0; background: var(--surface);
}
.card > h3 { margin-top: 12px; }
.card.lvl-bad { border-left-color: var(--bad); }
.card.lvl-warn { border-left-color: var(--warn); }
.card.lvl-info { border-left-color: var(--info); }
.flow-block { border-top: 3px solid var(--accent); margin-top: 28px; padding-top: 2px; }
.flow-block > h2 { margin-top: 14px; }
.notice {
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--radius); padding: 4px 16px; margin: 16px 0;
}
.notice h1 { font-size: 14px; margin: 8px 0 0; color: var(--text-2); }
.notice-title, .notice-foot { font-weight: 650; font-size: 13px; color: var(--warn); margin: 8px 0; }

/* sơ đồ */
.diagram { margin: 12px 0 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.diagram-tools { display: flex; gap: 6px; justify-content: flex-end; padding: 6px 8px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.diagram-tools button {
  font: inherit; font-size: 12.5px; padding: 3px 10px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
}
.diagram-tools button:hover { color: var(--text); }
.diagram-view { overflow: auto; padding: 14px; text-align: center; max-height: 80vh; }
.diagram-view svg { height: auto; max-width: none; }
.diagram-src { margin: 0; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.diagram-error { color: var(--bad); font-size: 13px; padding: 8px 14px 0; }
.diagram.is-full { position: fixed; inset: 0; z-index: 60; margin: 0; border-radius: 0; display: flex; flex-direction: column; }
.diagram.is-full .diagram-view { flex: 1; max-height: none; }

/* ---------- trang tổng quan ---------- */
.filter-bar { display: flex; align-items: center; gap: 12px; margin: 20px 0 6px; flex-wrap: wrap; }
.filter {
  display: flex; align-items: center; gap: 8px; flex: 1; max-width: 520px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); padding: 0 10px; color: var(--text-3);
}
.filter:focus-within { border-color: var(--accent); }
.filter input { flex: 1; border: 0; outline: 0; background: none; font: inherit; color: var(--text); padding: 8px 0; min-width: 0; }
.domain-block { margin-top: 26px; }
.domain-title { font-size: 17px; margin: 0 0 8px; display: flex; align-items: baseline; gap: 10px; }
.domain-title .muted { font-size: 13px; font-weight: 500; }
.unit-table td { vertical-align: middle; }
.entry-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.entry-link .method { width: 52px; text-align: center; flex: none; }
.entry-target { font-family: var(--mono); font-size: 12.5px; overflow-wrap: break-word; }
.code-cell code, .findings { white-space: nowrap; }
.links { white-space: nowrap; }
.links a + a { margin-left: 10px; }
.history-table tr.is-latest td { background: color-mix(in srgb, var(--ok-soft) 45%, transparent); }

/* ---------- cuối trang ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0 0; }
.pager-link {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: 13.5px;
}
.pager-link:hover { border-color: var(--accent); text-decoration: none; }
.pager-link.next { justify-content: flex-end; text-align: right; grid-column: 2; }
.pager-dir { width: 100%; color: var(--text-3); font-size: 12px; }
.sources { margin-top: 22px; font-size: 13px; color: var(--text-2); }
.sources-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 0 0 6px; }
.sources ul { list-style: none; padding: 0; margin: 0 0 6px; }
.sources li { margin: 3px 0; overflow-wrap: anywhere; }
.src-label { font-weight: 600; color: var(--text); }
.site-footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px;
  margin-top: 36px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-3);
}

/* ---------- màn hẹp ---------- */
@media (max-width: 1180px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .toc-box { grid-column: 1; grid-row: 1; position: static; max-height: none; }
  .doc { grid-row: 2; }
  .toc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 14px; }
  .toc summary { padding: 4px 0; }
  .toc summary::before { content: "▸ "; }
  .toc[open] summary::before { content: "▾ "; }
  .toc ol { margin-bottom: 6px; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-grid; }
  .sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; height: 100vh; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.18);
  }
  body.menu-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); }
  main { padding: 16px 16px 24px; }
  .doc { padding: 4px 16px 20px; }
  .brand { display: none; }
  .unit-title { font-size: 17px; }
  .tab { padding: 8px 10px; font-size: 13.5px; }
  .tab-icon { display: none; }
  .kbd-hint { display: none; }
  .pager { grid-template-columns: 1fr; }
  .pager-link.next { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .topbar, .sidebar, .toc-box, .pager, .preview-ribbon, .diagram-tools { display: none !important; }
  .layout, .doc-layout { display: block; }
  .doc { border: 0; box-shadow: none; padding: 0; }
}
