/* ==========================================================================
   Kelid (کلید) · Documentation
   Shares the operations-console design system (neutral surfaces, thin
   borders, one accent, semantic colour only for state) used by the Admin
   dashboard and Customer console, adapted for long-form reading content
   with English/Persian (RTL) support.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f3f4f7;
  --surface-3: #eaecf1;
  --hover: #f3f4f7;
  --text: #171b26;
  --text-2: #4a5164;
  --text-3: #687083;
  --border: #e3e6ec;
  --border-strong: #cdd2dc;
  --accent: #3f4fdc;
  --accent-hover: #3241bd;
  --accent-soft: #eceefd;
  --accent-text: #3241bd;
  --ok: #11805a;
  --ok-soft: #e4f4ec;
  --warn: #9d5a00;
  --warn-soft: #fcf0d9;
  --bad: #c0362f;
  --bad-soft: #fbe8e6;
  --btn-primary: #171b26;
  --btn-primary-hover: #2c3142;
  --btn-primary-text: #fff;
  --overlay: rgba(15, 18, 28, 0.36);
  --shadow-pop: 0 10px 32px rgba(15, 18, 28, 0.14), 0 1px 3px rgba(15, 18, 28, 0.08);
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  --code-bg: #14161d;
  --code-text: #f2f2f2;
  --code-border: #262a35;

  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-fa: Vazirmatn, Inter, ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sb-w: 250px;
  --topbar-h: 52px;
  --radius: 8px;
  --radius-sm: 6px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}
:root[data-theme="dark"] {
  --bg: #0d0f14; --surface: #14171e; --surface-2: #191d26; --surface-3: #232836; --hover: #1b202a;
  --text: #e9ebf1; --text-2: #b0b7c6; --text-3: #8a92a6;
  --border: #252a36; --border-strong: #363d4f;
  --accent: #8592ff; --accent-hover: #a0aaff; --accent-soft: #1b2040; --accent-text: #a5afff;
  --ok: #43c08d; --ok-soft: #10261d; --warn: #e6a743; --warn-soft: #2a2010; --bad: #f2786f; --bad-soft: #301716;
  --btn-primary: #e9ebf1; --btn-primary-hover: #ffffff; --btn-primary-text: #0d0f14;
  --overlay: rgba(0, 0, 0, 0.55);
  --shadow-pop: 0 10px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --code-bg: #0a0b10; --code-text: #e9ebf1; --code-border: #262a35;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f14; --surface: #14171e; --surface-2: #191d26; --surface-3: #232836; --hover: #1b202a;
    --text: #e9ebf1; --text-2: #b0b7c6; --text-3: #8a92a6;
    --border: #252a36; --border-strong: #363d4f;
    --accent: #8592ff; --accent-hover: #a0aaff; --accent-soft: #1b2040; --accent-text: #a5afff;
    --ok: #43c08d; --ok-soft: #10261d; --warn: #e6a743; --warn-soft: #2a2010; --bad: #f2786f; --bad-soft: #301716;
    --btn-primary: #e9ebf1; --btn-primary-hover: #ffffff; --btn-primary-text: #0d0f14;
    --overlay: rgba(0, 0, 0, 0.55);
    --shadow-pop: 0 10px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
    --code-bg: #0a0b10; --code-text: #e9ebf1; --code-border: #262a35;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14px/1.6 var(--font); font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased;
}
body.lang-fa { font-family: var(--font-fa); }
[hidden] { display: none !important; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: fixed; left: 8px; top: -60px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 100; box-shadow: var(--shadow-pop); }
.skip-link:focus { top: 8px; }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[data-icon] { display: inline-flex; }

/* --------------------------------- Brand --------------------------------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--text); color: var(--bg); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.brand-mark .ico { width: 15px; height: 15px; }
.brand-text { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand-fa { font-family: "Vazirmatn", system-ui, sans-serif; font-weight: 600; letter-spacing: 0; line-height: 1.2; color: var(--text-3); border-inline-start: 1px solid var(--border); padding-inline-start: 7px; }
.brand-text small { color: var(--text-3); font-weight: 500; font-size: 11px; border-inline-start: 1px solid var(--border); padding-inline-start: 8px; }

/* -------------------------------- Shell -------------------------------- */
.shell { display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns 0.18s var(--ease); }
.shell.collapsed { --sb-w: 56px; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); z-index: 30; overflow: hidden; direction: ltr; }
.sb-head { height: var(--topbar-h); display: flex; align-items: center; padding: 0 14px; border-bottom: 1px solid var(--border); flex: none; }
.nav { flex: 1; overflow-y: auto; padding: 10px 8px 12px; scrollbar-width: thin; }
.nav-group { margin-bottom: 14px; }
.nav-group-label { padding: 6px 10px 4px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; }
.nav-item, .console-link { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 30px; padding: 5px 10px; border: 0; background: none; border-radius: 6px; color: var(--text-2); font-weight: 450; text-align: left; white-space: nowrap; position: relative; }
.nav-item:hover, .console-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-item.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 500; }
.nav-item .ico, .console-link .ico { opacity: 0.85; }
.sb-foot { padding: 8px; border-top: 1px solid var(--border); flex: none; display: grid; gap: 2px; }
.shell.collapsed .nav-label, .shell.collapsed .nav-group-label, .shell.collapsed .brand-text { display: none; }
.shell.collapsed .nav-item, .shell.collapsed .console-link { justify-content: center; padding: 0; }
.shell.collapsed .sb-head { padding: 0 15px; }
.shell.collapsed .nav-group { margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.shell.collapsed .nav-group:last-child { border-bottom: 0; }
.shell.collapsed .language-switcher { flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; }
.shell.collapsed .language-switcher a { padding: 3px 0; width: 100%; text-align: center; font-size: 10.5px; }
.shell.collapsed .language-switcher .lang-full { display: none; }
.shell.collapsed .language-switcher .lang-short { display: inline; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 20px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); direction: ltr; }
.crumb { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
#crumbGroup { color: var(--text-3); font-size: 12px; text-transform: capitalize; }
#crumbGroup:not(:empty)::after { content: "/"; margin-left: 8px; color: var(--border-strong); }
#crumbPage { font-weight: 600; font-size: 13.5px; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; }
.tb-spacer { flex: 1; }
.menu-btn { display: none; }
.search-trigger { display: flex; align-items: center; gap: 8px; height: 32px; min-width: 240px; padding: 0 8px 0 10px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 7px; color: var(--text-3); text-align: left; }
.search-trigger:hover { border-color: var(--text-3); }
.search-trigger .st-label { flex: 1; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
kbd { font: 500 10.5px var(--mono); padding: 1px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); color: var(--text-2); }
.icon-btn { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; border-radius: 6px; color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.language-switcher { display: flex; align-items: center; gap: 6px; padding: 6px 10px; font-size: 12px; }
.language-switcher a { text-decoration: none; color: var(--text-3); padding: 3px 7px; border-radius: 5px; }
.language-switcher a:hover { color: var(--text); background: var(--hover); text-decoration: none; }
.language-switcher a.active { color: var(--accent-text); background: var(--accent-soft); font-weight: 600; }
.language-switcher .lang-short { display: none; }
.side-scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 25; }
.view { padding: 32px 28px 72px; outline: none; min-width: 0; }

/* ------------------------------ Doc layout ------------------------------ */
.doc-layout { display: grid; grid-template-columns: minmax(0, 760px) 210px; gap: 56px; max-width: 1080px; margin: 0 auto; align-items: start; }
.breadcrumbs-mobile { display: none; }
.toc { position: sticky; top: calc(var(--topbar-h) + 24px); color: var(--text-3); font-size: 12.5px; border-left: 1px solid var(--border); padding-left: 18px; direction: ltr; }
.toc strong { color: var(--text); display: block; margin-bottom: 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.toc a { display: block; text-decoration: none; padding: 4px 0; color: var(--text-3); border-left: 2px solid transparent; margin-left: -1px; padding-left: 10px; }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc .level-3 { padding-left: 22px; }

/* -------------------------------- Article -------------------------------- */
.article { font-size: 15px; min-width: 0; }
.article h1 { font-size: 34px; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 14px; color: var(--text); }
.article h2 { font-size: 21px; font-weight: 600; line-height: 1.3; margin: 40px 0 14px; padding-top: 24px; border-top: 1px solid var(--border); scroll-margin-top: calc(var(--topbar-h) + 16px); }
.article h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.article h3 { font-size: 16px; font-weight: 600; margin: 26px 0 10px; scroll-margin-top: calc(var(--topbar-h) + 16px); }
.article p { color: var(--text-2); margin: 0 0 16px; line-height: 1.7; }
.article ul { padding-left: 22px; color: var(--text-2); margin: 0 0 16px; }
.article li { margin: 6px 0; }
.article a { color: var(--accent-text); font-weight: 500; }
.article blockquote { margin: 0 0 18px; padding: 10px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 7px 7px 0; color: var(--text); }
.article blockquote p { margin: 0; color: inherit; }
.article code, .model-card code, summary code, .monospace { direction: ltr; unicode-bidi: isolate; display: inline-block; font: 12.5px var(--mono); background: var(--surface-3); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; color: var(--text); }
.loading, .empty { color: var(--text-3); padding: 40px 0; }
.fallback-note { border: 1px solid var(--border); background: var(--accent-soft); color: var(--accent-text); border-radius: 7px; padding: 10px 12px; margin-bottom: 20px; direction: ltr; text-align: left; font-size: 13px; }

/* ------------------------------- Code blocks ------------------------------ */
.code-block { direction: ltr; text-align: left; unicode-bidi: isolate; background: var(--code-bg); color: var(--code-text); border: 1px solid var(--code-border); border-radius: var(--radius); overflow-x: auto; margin: 18px 0; }
.code-header { display: flex; direction: ltr; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--code-border); padding: 8px 12px; color: #9aa1b5; font: 500 11px var(--mono); }
.code-header .copy-code { position: static; background: rgba(255, 255, 255, 0.08); color: #fff; border: 0; border-radius: 5px; padding: 4px 9px; cursor: pointer; font-size: 11px; }
.code-header .copy-code:hover { background: rgba(255, 255, 255, 0.16); }
.code-block pre { direction: ltr; margin: 0; padding: 16px 18px; background: transparent; color: inherit; font: 12.5px/1.65 var(--mono); tab-size: 2; white-space: pre; }
.code-block pre code { direction: ltr; unicode-bidi: isolate; background: transparent; border: 0; color: inherit; padding: 0; font: inherit; }

/* ---------------------------------- Table ---------------------------------- */
.article table { width: 100%; border-collapse: collapse; margin: 8px 0 20px; font-size: 13.5px; }
.article th, .article td { border-bottom: 1px solid var(--border); padding: 9px 10px; text-align: left; vertical-align: top; }
.article th { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }
.article td code, .article th code { direction: ltr; unicode-bidi: isolate; }

/* ---------------------------------- Sections ---------------------------------- */
.models-section, .reference-section { grid-column: 1 / -1; max-width: 1080px; margin: 0 auto; }
.hidden { display: none !important; }
.section-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 22px; flex-wrap: wrap; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.section-head h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; margin: 6px 0 4px; }
.section-head p { color: var(--text-2); margin: 0; max-width: 60ch; }
.section-head .input { direction: ltr; text-align: left; }

/* ---------------------------------- Models ---------------------------------- */
.model-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.model-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; background: var(--surface); }
.model-head { display: flex; justify-content: space-between; gap: 14px; }
.model-head .provider { direction: ltr; color: var(--accent-text); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.model-card h3 { margin: 3px 0; font-size: 16px; font-weight: 600; }
.pill { font-size: 11px; color: var(--text-2); direction: ltr; background: var(--surface-3); border-radius: 5px; padding: 2px 8px; height: fit-content; white-space: nowrap; }
.model-card dl { display: flex; gap: 26px; border-top: 1px solid var(--border); margin-top: 14px; padding-top: 12px; }
.model-card dt { font-size: 11px; color: var(--text-3); margin-bottom: 2px; }
.model-card dd { margin: 0; direction: ltr; text-align: left; font-size: 12.5px; color: var(--text); }
.model-card .price { direction: ltr; text-align: left; color: var(--text-2); font-size: 12.5px; margin-top: 14px; font-weight: 500; }
.model-card .muted { color: var(--text-3); font-size: 12px; margin-top: 14px; }

/* ------------------------------- Reference ------------------------------- */
.reference-list details { border-bottom: 1px solid var(--border); padding: 14px 0; }
.reference-list summary { display: flex; align-items: center; gap: 12px; cursor: pointer; list-style: none; }
.reference-list summary::-webkit-details-marker { display: none; }
.reference-list summary span:last-child { color: var(--text-2); margin-left: auto; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.method { direction: ltr; font: 700 10.5px var(--mono); min-width: 46px; padding: 2px 0; }
.method.get { color: var(--ok); } .method.post { color: var(--accent-text); } .method.patch { color: var(--warn); } .method.delete { color: var(--bad); }
.reference-body { padding: 12px 0 0 58px; }
.reference-body p { color: var(--text-2); margin-bottom: 10px; }

/* --------------------------------- cmdk search --------------------------------- */
.cmdk { position: fixed; inset: 0; z-index: 70; display: grid; place-items: start center; padding-top: 14vh; opacity: 0; transition: opacity 0.14s; direction: ltr; }
.cmdk.open { opacity: 1; }
.cmdk .scrim { position: fixed; inset: 0; background: var(--overlay); }
.cmdk-box { position: relative; width: min(620px, calc(100vw - 24px)); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-pop); overflow: hidden; transform: translateY(6px); transition: transform 0.16s var(--ease); }
.cmdk.open .cmdk-box { transform: none; }
.cmdk-input { display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 50px; border-bottom: 1px solid var(--border); color: var(--text-3); flex: none; }
.cmdk-input input { flex: 1; border: 0; background: none; color: var(--text); font: inherit; font-size: 14px; outline: none; height: 100%; }
.cmdk-list { overflow-y: auto; padding: 6px; }
.cmdk-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 7px; text-align: left; color: var(--text); font-size: 13px; text-transform: capitalize; }
.cmdk-item:hover, .cmdk-item:focus-visible { background: var(--accent-soft); }
.cmdk-empty { padding: 30px 14px; text-align: center; color: var(--text-3); }
.cmdk-foot { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); background: var(--surface-2); color: var(--text-3); font-size: 11.5px; flex: none; }

/* ---------------------------------- Toast ---------------------------------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 6px); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 12.5px; box-shadow: var(--shadow-pop); opacity: 0; transition: opacity 0.16s, transform 0.16s; z-index: 80; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------- RTL content --------------------------------- */
.lang-fa .article, .lang-fa .toc, .lang-fa #crumbGroup, .lang-fa #crumbPage {
  direction: rtl; text-align: right;
}
.lang-fa .article ul { padding-left: 0; padding-right: 22px; }
.lang-fa .article blockquote { border-left: 0; border-right: 3px solid var(--accent); border-radius: 7px 0 0 7px; }
.lang-fa .article th, .lang-fa .article td { text-align: right; }
.lang-fa .toc { border-left: 0; border-right: 1px solid var(--border); padding-left: 0; padding-right: 18px; }
.lang-fa .toc a { border-left: 0; margin-left: 0; border-right: 2px solid transparent; margin-right: -1px; padding-left: 0; padding-right: 10px; }
.lang-fa .toc .level-3 { padding-right: 22px; padding-left: 0; }
.lang-fa .doc-layout { grid-template-columns: 210px minmax(0, 760px); }
.lang-fa .toc { grid-column: 1; }
.lang-fa .article { grid-column: 2; }
.lang-fa #crumbGroup::after { content: ""; }
.lang-fa #crumbGroup::before { content: "/"; margin-inline-end: 8px; color: var(--border-strong); }

/* -------------------------------- Responsive -------------------------------- */
@media (max-width: 1100px) {
  .doc-layout, .lang-fa .doc-layout { grid-template-columns: minmax(0, 1fr); max-width: 720px; }
  .toc, .lang-fa .toc { display: none; }
}
@media (max-width: 900px) {
  .shell, .shell.collapsed { grid-template-columns: minmax(0, 1fr); --sb-w: 260px; }
  .sidebar { position: fixed; left: 0; top: 0; width: var(--sb-w); transform: translateX(-100%); transition: transform 0.2s var(--ease); box-shadow: var(--shadow-pop); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.collapsed .nav-label, .shell.collapsed .nav-group-label, .shell.collapsed .brand-text { display: revert; }
  .shell.collapsed .nav-item, .shell.collapsed .console-link { justify-content: flex-start; padding: 5px 10px; }
  #collapseBtn { display: none; }
  .menu-btn { display: inline-flex; }
  .view { padding: 20px 16px 56px; }
  .topbar { padding: 0 14px; }
  .search-trigger { min-width: 0; width: 32px; padding: 0; justify-content: center; }
  .search-trigger .st-label, .search-trigger kbd { display: none; }
  .article h1 { font-size: 27px; }
  .model-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
