/* KNZ developer docs — brand tokens (docs/BRAND_KNZ.md): Emerald 900/700/500, Gold 600/300, Pearl, Mist. */
:root {
  --emerald-900: #062A20; --emerald-700: #0B4434; --emerald-500: #14694E; --emerald-black: #03231A;
  --gold-600: #C69536; --gold-300: #F5DC96; --mist: #E3ECE7; --pearl: #F6F7F4;
  --bg: #F6F7F4; --surface: #FFFFFF; --bg-2: #EEF3F0; --ink: #03231A; --ink-2: #2C3F39; --muted: #5A6B66;
  --line: #E0E8E4; --accent: #14694E; --accent-ink: #0B5A41; --code-inline: #EDF2EF;
  --code-bg: #08201A; --code-ink: #DCEFE7; --code-bar: #0C2C23;
  --bad: #A3271C; --ok: #14694E; --warn-bg: #FFF4E0; --warn-ink: #7A4B00;
  --f-head: Kufam, "IBM Plex Sans Arabic", system-ui, sans-serif;
  --f-ar: "IBM Plex Sans Arabic", Manrope, system-ui, sans-serif;
  --f-num: Manrope, "IBM Plex Sans Arabic", system-ui, sans-serif;
  --f-mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --top-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #03231A; --surface: #072E23; --bg-2: #0A3528; --ink: #F1F5F3; --ink-2: #CFDDD7; --muted: #A5BDB3;
    --line: #164A3B; --accent: #F5DC96; --accent-ink: #F5DC96; --code-inline: #0D3A2D;
    --code-bg: #021A13; --code-bar: #04241B; --bad: #F09080; --ok: #7FD8B0; --warn-bg: #3A2C12; --warn-ink: #FFD590;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--top-h) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: var(--f-ar); line-height: 1.7; font-size: 16px; -webkit-font-smoothing: antialiased; }
html[data-lang="en"] body { font-family: var(--f-num); }
html[data-lang="ar"] [lang="en"], html[data-lang="en"] [lang="ar"] { display: none !important; }
[hidden] { display: none !important; }
a { color: var(--accent-ink); }
h1, h2 { font-family: var(--f-head); font-weight: 800; line-height: 1.25; margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: clamp(1.3rem, 2.6vw, 1.6rem); }
h3 { margin: 22px 0 8px; font-size: 1.05rem; color: var(--accent-ink); }
h4 { margin: 14px 0 6px; font-size: .92rem; }
p, ol, ul { margin: 0; }
ol, ul { padding-inline-start: 22px; display: grid; gap: 6px; }
.skip { position: absolute; inset-inline-start: 8px; top: -60px; background: var(--gold-600); color: #03231A; padding: 8px 14px; border-radius: 10px; z-index: 50; font-weight: 700; }
.skip:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--gold-600); outline-offset: 2px; border-radius: 6px; }

/* ---------- top bar */
.top { position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-left)); background: var(--emerald-900); color: #fff; border-bottom: 1px solid rgba(245,220,150,.15); }
.brand { display: inline-flex; align-items: center; flex: none; }
.brand img { width: 124px; height: auto; display: block; }
.brand-tag { font: 700 .82rem var(--f-num); color: var(--gold-300); border: 1px solid rgba(245,220,150,.35); padding: 2px 10px; border-radius: 999px; }
html[data-lang="ar"] .brand-tag { font-family: var(--f-ar); }
.top-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }
.ghost { font: 600 .9rem var(--f-num); color: #fff; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px; min-height: 38px; padding: 0 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
html[data-lang="ar"] .ghost { font-family: var(--f-ar); }
.ghost:hover { background: rgba(255,255,255,.18); }
.toc-btn { display: none; }

/* ---------- layout */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 40px; max-width: 1240px; margin: 0 auto; padding: 0 24px; }
main { min-width: 0; padding-block: 28px 40px; max-width: 880px; }

/* ---------- sidebar */
.toc { position: sticky; top: var(--top-h); align-self: start; max-height: calc(100dvh - var(--top-h)); overflow-y: auto;
  padding: 22px 4px 32px; display: grid; gap: 1px; align-content: start; scrollbar-width: thin; }
#toc-search { font: inherit; font-size: .9rem; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 0 12px; margin-bottom: 10px; width: 100%; }
.toc-h { font: 800 .74rem var(--f-num); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 10px 4px; }
html[data-lang="ar"] .toc-h { font-family: var(--f-ar); letter-spacing: 0; text-transform: none; font-size: .8rem; }
.toc a { color: var(--ink-2); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: .92rem; border-inline-start: 2px solid transparent; line-height: 1.5; }
.toc a:hover { background: var(--surface); color: var(--ink); }
.toc a[aria-current="true"] { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 9%, transparent); border-inline-start-color: var(--gold-600); font-weight: 700; }

/* ---------- content */
.doc { padding-block: 30px; border-bottom: 1px solid var(--line); display: grid; gap: 14px; min-width: 0; scroll-margin-top: calc(var(--top-h) + 12px); }
.doc > * { min-width: 0; }
.hero-doc { padding-top: 8px; }
.eyebrow { font: 800 .8rem var(--f-num); color: var(--gold-600); letter-spacing: .06em; text-transform: uppercase; }
.lede { font-size: 1.1rem; color: var(--ink-2); max-width: 46em; }
.muted { color: var(--muted); font-size: .9rem; }
.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 14px; font-size: .92rem; }
.cards3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 6px; }
.card-link { display: grid; gap: 4px; padding: 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--muted); font-size: .9rem;
  transition: border-color .15s, transform .15s; }
.card-link b { color: var(--ink); font-size: 1rem; }
.card-link:hover { border-color: var(--gold-600); transform: translateY(-2px); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

code { font-family: var(--f-mono); font-size: .86em; background: var(--code-inline); padding: 1px 6px; border-radius: 6px; direction: ltr; unicode-bidi: isolate; overflow-wrap: normal; word-break: normal; white-space: nowrap; }
li, p { min-width: 0; }
td:last-child code { white-space: normal; }   /* a field list in a description wraps between its fields, never inside one */   /* grid items: a long code token scrolls in its box instead of widening the page */
/* a long token never breaks mid-word: in prose it scrolls inside its own box; in tables the table scrolls */
p code, li code, .note code { display: inline-block; max-width: 100%; overflow-x: auto; white-space: nowrap; vertical-align: bottom; scrollbar-width: thin; }

/* ---------- code blocks with tabs */
.code { border-radius: 14px; overflow: hidden; background: var(--code-bg); border: 1px solid rgba(255,255,255,.06); direction: ltr; min-width: 0; }
.code-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--code-bar); padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,.07); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs button { font: 600 .8rem var(--f-num); color: #9FBDB1; background: none; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: #fff; }
.tabs button[aria-selected="true"] { color: var(--gold-300); background: rgba(245,220,150,.1); }
.copy { font: 600 .78rem var(--f-num); color: #DCEFE7; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 5px 10px; cursor: pointer; flex: none; }
html[data-lang="ar"] .copy { font-family: var(--f-ar); }
.copy:hover { background: rgba(255,255,255,.16); }
.copy.done { color: #03231A; background: var(--gold-300); border-color: var(--gold-300); }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; color: var(--code-ink); text-align: left; tab-size: 2; }
.code pre code { background: none; padding: 0; color: inherit; font-size: .82rem; line-height: 1.65; white-space: pre; overflow-wrap: normal; }
.tk-s { color: #F5DC96; } .tk-c { color: #7E9C91; font-style: italic; } .tk-k { color: #8FD9B6; }

/* ---------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
td, th { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: start; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
thead th { background: var(--bg-2); font-size: .82rem; color: var(--muted); font-weight: 700; }
.kv td:first-child { white-space: nowrap; }
.kv.errors td:last-child code, .kv.endpoints code { margin: 2px; display: inline-block; }
.endpoints td:first-child { width: 80px; }
.endpoints td:nth-child(2) { white-space: nowrap; }
.fields td:first-child { white-space: nowrap; direction: ltr; }
.fields td:nth-child(2) { direction: ltr; max-width: 260px; color: var(--muted); }
.req { color: var(--bad); font-weight: 700; }
.event .fields td:nth-child(2) code, .event .fields td:first-child code { white-space: nowrap; overflow-wrap: normal; }
.toc-file { font-family: var(--f-num); font-size: .85rem !important; color: var(--muted) !important; margin-top: 10px; }

/* ---------- webhook events */
#events-table { display: grid; gap: 14px; }
.event { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.event header { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--ink-2); }
.ev-name { font-size: .92rem; font-weight: 700; color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 10%, transparent); padding: 3px 10px; }
.event .table-wrap { border: 0; border-radius: 0; }
.event details > summary { font-weight: 700; font-size: .9rem; color: var(--accent-ink); margin-bottom: 8px; }
.timeline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font: 700 .8rem var(--f-num); direction: ltr; }
.timeline span { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--emerald-700); color: #fff; }
.timeline i { font-style: normal; color: var(--muted); padding: 0 2px; }
.timeline i::before { content: "→ "; }
.timeline b { color: var(--bad); border: 1px solid currentColor; border-radius: 999px; padding: 2px 10px; }

/* ---------- signature tester */
.tester { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.tester label { display: grid; gap: 6px; font-size: .85rem; font-weight: 700; color: var(--ink-2); min-width: 0; }
.tester .wide { grid-column: 1 / -1; }
.tester input, .tester textarea { font: .84rem var(--f-mono); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0; resize: vertical; }
.tester .row { display: flex; gap: 8px; }
.btn-small { font: 700 .82rem var(--f-num); border: 0; border-radius: 10px; padding: 0 14px; background: var(--emerald-700); color: #fff; cursor: pointer; flex: none; }
html[data-lang="ar"] .btn-small { font-family: var(--f-ar); }
#t-out { font: 700 .82rem var(--f-mono); background: var(--code-bg); color: var(--gold-300); border-radius: 10px; padding: 10px 12px; white-space: nowrap; overflow-x: auto; display: block; }
.t-result { font-size: .9rem; margin: 0; }
.t-result .ok { color: var(--ok); } .t-result .bad { color: var(--bad); } .t-result .warn { color: var(--warn-ink); }

/* ---------- reference (rendered from openapi.json) */
#filter { font: inherit; font-size: .9rem; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 0 12px; width: min(320px, 100%); }
.group h3 { font-family: var(--f-num); }
.op { border: 1px solid var(--line); border-radius: 12px; margin: 8px 0; background: var(--surface); }
.op > summary { cursor: pointer; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; list-style: none; }
.op > summary::-webkit-details-marker { display: none; }
.op[open] > summary { border-bottom: 1px solid var(--line); }
.op > summary code { display: inline-block; max-width: 100%; overflow-x: auto; white-space: nowrap; vertical-align: bottom; background: none; padding: 0; font-weight: 600; }
.op-body { padding: 10px 14px 14px; overflow-x: auto; }
.sum { color: var(--muted); font-size: .88rem; }
.m { font: 800 .7rem var(--f-mono); padding: 3px 7px; border-radius: 6px; color: #fff; min-width: 56px; text-align: center; display: inline-block; }
.m-get { background: #1C6FB8; } .m-post { background: #1D7A46; } .m-put, .m-patch { background: #A0670F; } .m-delete { background: #A3271C; }
.tag { font-size: .72rem; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; color: var(--muted); direction: ltr; }
.tag.open { color: var(--accent-ink); border-color: var(--accent-ink); }
details > summary { cursor: pointer; }
.variants { display: grid; gap: 8px; }

.doc-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 24px; color: var(--muted); font-size: .88rem; }

/* ---------- small screens: the sidebar becomes a drawer */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px; gap: 0; }
  .toc-btn { display: inline-flex; }
  .toc { position: fixed; inset: var(--top-h) 0 auto 0; max-height: calc(100dvh - var(--top-h)); background: var(--bg); z-index: 15;
    padding: 16px; border-bottom: 1px solid var(--line); box-shadow: 0 24px 40px -20px rgba(3,35,26,.4); display: none; }
  .toc.open { display: grid; }
  main { padding-top: 12px; }
}
@media (max-width: 640px) {
  .cards3 { grid-template-columns: minmax(0, 1fr); }
  .tester { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none; }
  .brand img { width: 120px; }
  .brand-tag { display: none; }
  .top { gap: 8px; }
  .ghost { padding: 0 10px; font-size: .85rem; }
  .doc { padding-block: 24px; }
  td, th { padding: 8px 10px; }
  .kv td:first-child, .endpoints td:nth-child(2) { white-space: normal; }
  /* phones: each row stacks, so a long path or field list never pushes the description off screen */
  .kv tr { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: start; border-bottom: 1px solid var(--line); }
  .kv tr:last-child { border-bottom: 0; }
  .kv td, .kv th { border-bottom: 0; min-width: 0; }
  .kv td:nth-child(2) { overflow-x: auto; }
  .kv.endpoints td:nth-child(2) { direction: ltr; text-align: left; }   /* a long path scrolls from its start */
  html[dir="rtl"] .kv.endpoints td:nth-child(2) { text-align: right; }
  .kv td:nth-child(n+3), .kv th:nth-child(n+3) { grid-column: 1 / -1; padding-top: 0; }
}
