/* Pension Core: хөгжүүлэгчийн гарын авлага. Гадаад хамааралгүй; file:// -ээр шууд нээгдэнэ. */
:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #1d2327;
  --muted: #5d676e;
  --line: #dcd9d0;
  --accent: #0d6b62;
  --accent-soft: #e0efec;
  --warn: #a2510a;
  --warn-soft: #fbeedd;
  --code-bg: #f0eee8;
  --actor: #17313a;
  --actor-ink: #ffffff;
  --arrow: #33434b;
  --dim: #c4c9cc;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #12171a;
  --surface: #1a2125;
  --ink: #e6e9ea;
  --muted: #9aa5ab;
  --line: #2e383d;
  --accent: #58c2b4;
  --accent-soft: #17332f;
  --warn: #f0b36a;
  --warn-soft: #3a2a15;
  --code-bg: #222b30;
  --actor: #cfe6e2;
  --actor-ink: #10201d;
  --arrow: #c3ccd0;
  --dim: #47535a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171a; --surface: #1a2125; --ink: #e6e9ea; --muted: #9aa5ab; --line: #2e383d;
    --accent: #58c2b4; --accent-soft: #17332f; --warn: #f0b36a; --warn-soft: #3a2a15; --code-bg: #222b30;
    --actor: #cfe6e2; --actor-ink: #10201d; --arrow: #c3ccd0; --dim: #47535a;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code, pre, kbd { font-family: var(--mono); font-size: 0.875em; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
pre {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 16px; overflow-x: auto; line-height: 1.5; position: relative;
}
pre code { background: none; padding: 0; overflow-wrap: normal; }

.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  padding: 22px 16px 28px; border-right: 1px solid var(--line); background: var(--surface);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 2px; }
.sidebar nav { margin-top: 18px; }
.sidebar .group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 8px 6px; }
.sidebar a {
  display: block; padding: 5px 8px; border-radius: 6px; color: var(--ink);
  text-decoration: none; font-size: 14px; line-height: 1.35;
}
.sidebar a:hover { background: var(--accent-soft); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.theme-toggle {
  margin-top: 20px; width: 100%; padding: 7px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; font-size: 13px;
}

main { padding: 36px 44px 96px; max-width: 1080px; width: 100%; }
section { margin-bottom: 64px; }
h1 { font-size: 34px; line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 10px; text-wrap: balance; }
h2 { font-size: 25px; letter-spacing: -0.01em; margin: 0 0 12px; padding-top: 8px; text-wrap: balance; }
h3 { font-size: 18px; margin: 30px 0 8px; }
p, li { max-width: 72ch; }
.lead { font-size: 18px; color: var(--muted); max-width: 66ch; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); font-weight: 600; margin-bottom: 6px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin: 18px 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.card h4 { margin: 0 0 4px; font-size: 15px; }
.card p { margin: 0; font-size: 14px; color: var(--muted); }
.card code { font-size: 12px; }

.note { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 16px 0; max-width: 76ch; }
.note.warn { border-color: var(--warn); background: var(--warn-soft); }
.note p { margin: 0; }

.table-wrap { overflow-x: auto; margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Дарааллын диаграм */
.seq { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin: 16px 0 28px; overflow: hidden; }
.seq-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.seq-head strong { font-size: 14px; margin-right: auto; }
.seq-head button {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 6px;
  padding: 5px 11px; font: inherit; font-size: 13px; cursor: pointer;
}
.seq-head button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.seq-head button:disabled { opacity: 0.4; cursor: default; }
.seq-head .count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: center; }
.seq-canvas { overflow-x: auto; padding: 8px 6px 0; }
.seq-canvas svg { display: block; width: 100%; height: auto; }
.seq-explain { border-top: 1px solid var(--line); padding: 12px 16px 14px; min-height: 86px; font-size: 14.5px; }
.seq-explain .step-no { font-size: 12px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.seq-explain p { margin: 2px 0 0; max-width: 90ch; }
.seq-explain .ledger { display: inline-block; margin-top: 6px; font: 13px var(--mono); background: var(--code-bg); padding: 3px 8px; border-radius: 6px; }

svg .actor-box { fill: var(--actor); }
svg .actor-text { fill: var(--actor-ink); font-family: var(--sans); font-weight: 600; font-size: 12.5px; }
svg .actor-box.k-client { fill: var(--accent); }
svg .actor-box.k-external { fill: var(--warn); }
svg .actor-box.k-db, svg .actor-box.k-infra { fill: var(--surface); stroke: var(--arrow); stroke-width: 1.5; }
svg .actor-text.k-db, svg .actor-text.k-infra { fill: var(--ink); }
svg .actor-text.k-client, svg .actor-text.k-external { fill: #fff; }
svg .lifeline { stroke: var(--dim); stroke-width: 1.5; stroke-dasharray: 4 5; }
svg .msg line, svg .msg path { stroke: var(--arrow); stroke-width: 1.6; fill: none; }
svg .msg polygon { fill: var(--arrow); }
svg .msg text { fill: var(--ink); font: 12.5px var(--sans); paint-order: stroke; stroke: var(--surface); stroke-width: 5px; stroke-linejoin: round; }
svg .msg .num { fill: var(--accent); font-weight: 700; }
svg .msg.async line, svg .msg.async path { stroke-dasharray: 6 4; }
svg .msg.future { opacity: 0.16; }
svg .msg.current line, svg .msg.current path { stroke: var(--accent); stroke-width: 2.4; }
svg .msg.current polygon { fill: var(--accent); }
svg .msg.current text { font-weight: 600; }
svg .msg { cursor: pointer; }
svg .msg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Шөнийн ажлын цагийн шугам */
.timeline { margin: 16px 0; border-left: 2px solid var(--line); padding-left: 0; list-style: none; }
.timeline li { position: relative; padding: 4px 0 10px 22px; max-width: none; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline time { font: 600 13px var(--mono); color: var(--accent); margin-right: 10px; }
.timeline code { font-size: 12.5px; }
.timeline span { display: block; font-size: 14px; color: var(--muted); }

.copy {
  position: absolute; top: 8px; right: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); border-radius: 6px; padding: 2px 8px; font: 12px var(--sans); cursor: pointer;
}
.copy:hover { color: var(--accent); border-color: var(--accent); }

footer { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 16px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 2px 6px; }
  .sidebar .group { width: 100%; margin: 10px 8px 2px; }
  main { padding: 24px 18px 72px; }
  h1 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* ---------------------------------------------------------------- өгөгдлөөс зурагдах хуудсууд */
:root { --tag: #ecebe5; }
:root[data-theme="dark"] { --tag: #263036; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tag: #263036; } }

#view:focus { outline: none; }
.sidebar input[type="search"], .filter input[type="search"] {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; font-size: 14px;
}
.sidebar input[type="search"] { margin-top: 14px; }
.sidebar input:focus-visible, .filter input:focus-visible, .chip:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar nav a { display: flex; gap: 8px; align-items: baseline; }
.sidebar nav a code { background: none; padding: 0; font-size: 12.5px; color: var(--accent); min-width: 6.5em; }
.sidebar nav a span { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kbd-hint { font-size: 12px; color: var(--muted); margin: 6px 2px 0; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--bg); }

.eyebrow a { color: inherit; text-decoration: none; }
.eyebrow a:hover { text-decoration: underline; }
.h1code { font-size: 0.8em; margin-right: 6px; }
.hint { color: var(--muted); font-size: 14px; }
.pre-line { white-space: pre-line; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 22px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat b { display: block; font-size: 30px; line-height: 1.1; letter-spacing: -0.02em; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }

a.card { text-decoration: none; color: inherit; display: block; transition: border-color 0.15s, transform 0.15s; }
a.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.flow-card h4 { color: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--tag); color: var(--muted); white-space: nowrap; }
.tag.area { font-family: var(--mono); color: var(--accent); background: var(--accent-soft); }
.tag.a-admin, .tag.a-employer, .tag.a-member, .tag.a-partner, .tag.a-system { color: var(--ink); }

.filter { display: grid; gap: 10px; margin: 18px 0 8px; max-width: 760px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px;
  padding: 4px 12px; font: 13px var(--sans); cursor: pointer; text-decoration: none;
}
.chip:hover, .chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.deps { display: grid; gap: 8px; margin: 14px 0 6px; }
.deps > div { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.deps .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); width: 7.5em; }
.deps .chip { font-family: var(--mono); font-size: 12.5px; }

.layers { display: grid; gap: 10px; margin: 16px 0; }
.layer { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.layer > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin-top: 8px; }
.module-tile { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; text-decoration: none; color: var(--ink); background: var(--bg); }
.module-tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.module-tile strong { font-family: var(--mono); font-size: 14px; color: var(--accent); display: block; }
.module-tile span { font-size: 13px; display: block; }
.module-tile small { font-size: 11.5px; color: var(--muted); }

.http { display: inline-flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.method { font: 700 11px var(--mono); padding: 2px 6px; border-radius: 4px; color: #fff; background: #5d676e; letter-spacing: 0.03em; }
.m-get { background: #1f6f9c; } .m-post { background: #1d7a4c; } .m-put, .m-patch { background: #9a6a12; } .m-delete { background: #a23a2e; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 8px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; background: var(--actor); }
.legend .sw.k-client { background: var(--accent); } .legend .sw.k-external { background: var(--warn); }
.legend .sw.k-infra { background: var(--surface); border: 1.5px solid var(--arrow); }
.legend .ln { width: 22px; border-top: 2px solid var(--arrow); display: inline-block; }
.legend .ln.dashed { border-top-style: dashed; }

.step .step-no { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; text-transform: none; letter-spacing: 0; font-size: 14.5px; }
.step .step-no b { color: var(--ink); font-size: 15px; }
.step .step-no span { color: var(--muted); font-weight: 400; font-size: 13px; }
.step p { margin: 4px 0 8px; max-width: 92ch; }
.meta { display: grid; grid-template-columns: 6.5em minmax(0, 1fr); gap: 4px 10px; margin: 0; font-size: 13.5px; }
.meta dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 2px; }
.meta dd { margin: 0; min-width: 0; }
.meta .file { color: var(--muted); background: none; padding: 0; }
.ledger { display: inline-block; font: 13px var(--mono); background: var(--code-bg); padding: 2px 8px; border-radius: 6px; }
.steps { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.steps li { max-width: none; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 8px; padding: 10px 14px; cursor: pointer; }
.steps li.current { border-left-color: var(--accent); background: var(--accent-soft); }

.stage { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 14px; margin: 26px 0; }
.stage-no { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
:root[data-theme="dark"] .stage-no { color: #10201d; }
.stage h3 { margin-top: 4px; }

.screen { margin: 26px 0; }
.screen h3 { margin-bottom: 2px; }
.screen > p { margin-top: 0; color: var(--muted); }
.convention { margin: 26px 0; }
.perm-list { display: flex; flex-wrap: wrap; gap: 6px; max-width: none; }
.results { list-style: none; padding: 0; display: grid; gap: 8px; }
.results li { max-width: none; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.results a { font-family: var(--mono); font-size: 14px; }
td code { white-space: normal; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

.http { flex-wrap: nowrap; }
.http code { white-space: nowrap; overflow-wrap: normal; }
.calls td:nth-child(2) code { white-space: nowrap; overflow-wrap: normal; }
.calls td:nth-child(3) { min-width: 320px; }
.auth { padding-left: 20px; }
.auth li { max-width: 86ch; margin: 3px 0; overflow-wrap: anywhere; }
td:first-child > code { white-space: nowrap; overflow-wrap: normal; }

/* Токены хуудас */
.cards.three { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.card.big { padding: 18px; }
.card.big .no { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; margin-bottom: 10px; }
:root[data-theme="dark"] .card.big .no { color: #10201d; }
.card.big h4 { font-size: 16px; }
.jwt-tool textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: 13px/1.5 var(--mono); resize: vertical;
}
.jwt-tool textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.jwt-out { margin-top: 12px; }
.checks { list-style: none; padding: 0; margin: 0 0 6px; display: grid; gap: 4px; }
.checks li { max-width: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 14px; overflow-wrap: anywhere; }
.checks .ok b { color: var(--accent); }
.checks .bad b, p.bad { color: #b3261e; }
:root[data-theme="dark"] .checks .bad b, :root[data-theme="dark"] p.bad { color: #ff8a80; }
.jwt-out h4 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
ol li { margin: 4px 0; }

/* Жижиг дэлгэц: цэс товчоор нээгдэнэ */
.menu-toggle { display: none; }
@media (max-width: 860px) {
  .sidebar { padding: 14px 16px; }
  .menu-toggle {
    display: block; width: 100%; margin-top: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 14px;
  }
  .sidebar nav, .sidebar .theme-toggle, .sidebar .kbd-hint { display: none; }
  .sidebar.open nav { display: block; }
  .sidebar.open .theme-toggle { display: block; }
  .sidebar nav a { display: flex; }
  .stage { grid-template-columns: 1fr; }
  .meta { grid-template-columns: 1fr; }
  .meta dt { padding-top: 6px; }
}

@media (max-width: 860px) {
  .cards, .cards.three, .two-col, .stats { grid-template-columns: minmax(0, 1fr); }
  .seq-head strong { width: 100%; }
}

/* Алдаа ба шалтгаан */
.problem { margin: 18px 0; padding: 14px 16px; border: 1px solid var(--border, #d9dde3); border-radius: 8px; max-width: 900px; }
.problem h3 { margin: 0 0 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 1rem; }
.problem .status { font: 600 12px/1 ui-monospace, monospace; padding: 4px 7px; border-radius: 4px; background: #e8ebef; color: #1f2933; }
.problem .status.s4 { background: #fde9c8; color: #6b3d00; }
.problem .status.s5 { background: #f9d1d1; color: #7a1010; }
.problem .status.s2 { background: #d5efdc; color: #0f4d24; }
.problem dl { display: grid; grid-template-columns: 92px 1fr; gap: 6px 12px; margin: 0; }
.problem dt { font-weight: 600; opacity: .75; }
.problem dd { margin: 0; }
.problem .see a { display: inline-block; margin: 0 12px 2px 0; }
@media (max-width: 640px) { .problem dl { grid-template-columns: 1fr; } }

/* Үүрэг ба хандалтын түвшин */
.role-perms { margin: 8px 0; max-width: 900px; }
.role-perms summary { cursor: pointer; }
.role-perms .chip { display: inline-block; margin: 3px 4px 3px 0; font: 12px/1.6 ui-monospace, monospace; }
