:root {
  --brand: #d85935;
  --brand-hot: #ff5000;
  --brand-deep: #b84428;
  --brand-soft: #fff1eb;
  --brand-mist: #fff6f2;
  --ink: #141414;
  --ink-soft: #3a3a3a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-soft: #f3f4f6;
  --paper: #ffffff;
  --page: #f4f2f0;
  --sidebar: #111827;
  --sidebar-text: #e5e7eb;
  --sidebar-muted: #9ca3af;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 12px 40px rgba(17,24,39,.08);
  --radius: 10px;
  --sidebar-w: 280px;
  --topbar-h: 60px;
  --content-max: 920px;
  --gutter: clamp(14px, 3vw, 32px);
  --bp-sidebar: 1024px;
  --bp-compact: 640px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  direction: rtl;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Vazirmatn", "IBM Plex Sans", system-ui, sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.8;
  font-size: clamp(14px, 1.6vw, 15px);
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.sidebar-open {
  overflow: hidden;
}

.en, code, pre {
  font-family: "IBM Plex Sans", ui-monospace, monospace;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}

a { color: var(--brand-deep); text-decoration: none; }
a:hover { color: var(--brand-hot); text-decoration: underline; }

.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  top: 0;
  z-index: 9999;
  background: var(--brand);
  color: #fff;
  padding: 8px 16px;
}
.skip-link:focus {
  inset-inline-start: 16px;
  top: 16px;
}

/* ── 1. App shell ── */
.app {
  min-height: 100dvh;
  direction: rtl;
}

/* ── 2. Main column (topbar + content) ── */
.main {
  min-height: 100dvh;
  margin-inline-end: var(--sidebar-w);
  margin-inline-start: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── 3. Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--topbar-h);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px var(--gutter);
  padding-top: max(8px, env(safe-area-inset-top));
}

.topbar-start {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.menu-btn {
  display: none;
  flex-shrink: 0;
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.breadcrumb {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.breadcrumb strong { color: var(--ink); }

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand); color: var(--brand-deep); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-deep); color: #fff; }

/* ── 4. Content area ── */
.content {
  flex: 1;
  width: 100%;
  padding: var(--gutter);
  padding-bottom: max(72px, env(safe-area-inset-bottom));
}

.content-inner {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
}

/* ── 5. Sidebar (fixed right) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 23, 42, .45);
  opacity: 0;
  transition: opacity .2s ease;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.sidebar-backdrop.visible {
  opacity: 1;
}

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar) 0%, #0b1220 100%);
  color: var(--sidebar-text);
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  inset-inline-start: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  border-inline-start: 1px solid rgba(255,255,255,.08);
  transition: transform .25s ease;
  text-align: right;
  padding-block-end: env(safe-area-inset-bottom);
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-brand img { max-width: 100%; height: auto; display: block; margin-bottom: 8px; }
.sidebar-brand .kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--brand-hot);
  text-transform: uppercase;
}
.sidebar-brand h1 { margin: 4px 0 2px; font-size: 15px; font-weight: 700; line-height: 1.45; }
.sidebar-brand p { margin: 0; font-size: 11px; color: var(--sidebar-muted); line-height: 1.55; }

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-search input {
  width: 100%;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: #fff;
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  direction: rtl;
  text-align: right;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,.45); }
.sidebar-search input:focus { outline: 2px solid var(--brand); border-color: transparent; }

.nav-scroll {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px 0 16px;
  -webkit-overflow-scrolling: touch;
}

.nav-group { margin-bottom: 6px; }
.nav-group-title {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  color: var(--sidebar-muted);
  text-transform: uppercase;
}

.nav-link {
  display: block;
  padding: 7px 16px;
  font-size: 12.5px;
  color: var(--sidebar-text);
  border-inline-start: 3px solid transparent;
  transition: .15s ease;
  text-align: right;
}
.nav-link:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.nav-link.active {
  background: rgba(216,89,53,.15);
  color: #fff;
  border-inline-start-color: var(--brand-hot);
  font-weight: 600;
}
.nav-link small { display: block; color: var(--sidebar-muted); font-size: 10.5px; margin-top: 1px; line-height: 1.45; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 10px;
  color: var(--sidebar-muted);
  line-height: 1.55;
  flex-shrink: 0;
}

/* ── Sections & dashboard ── */
.doc-section {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  padding: clamp(18px, 3vw, 28px);
  scroll-margin-top: calc(var(--topbar-h) + 12px);
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.doc-section.hidden { display: none !important; }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.section-head h2 { margin: 0; font-size: clamp(18px, 2.5vw, 22px); line-height: 1.4; }
.section-meta { font-size: 12px; color: var(--muted); }

.hero {
  background:
    radial-gradient(900px 420px at 100% 0%, rgba(216,89,53,.11), transparent 55%),
    linear-gradient(180deg, #fff 0%, var(--brand-mist) 100%);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: clamp(20px, 4vw, 32px);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--brand-deep), var(--brand), var(--brand-hot));
}
.hero-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--brand-deep);
  background: var(--brand-soft);
  padding: 5px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.hero h2 { margin: 0 0 8px; font-size: clamp(22px, 4vw, 28px); line-height: 1.35; }
.hero p { margin: 0; color: var(--ink-soft); max-width: 65ch; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 20px 0;
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .num { font-size: clamp(20px, 4vw, 24px); font-weight: 800; color: var(--brand-deep); line-height: 1.2; }
.stat .label { font-size: 11px; color: var(--muted); margin-top: 2px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 14px;
}
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.card .link { font-size: 13px; font-weight: 700; color: var(--brand); }

.annex-block { margin-top: 22px; }
.annex-block > h3 { margin: 0 0 12px; font-size: 16px; }

/* ── Prose ── */
.prose { direction: rtl; text-align: right; overflow-wrap: anywhere; }
.prose h1 { font-size: clamp(22px, 3vw, 26px); margin: 0 0 14px; }
.prose h2 {
  font-size: clamp(17px, 2.5vw, 20px);
  margin: 24px 0 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}
.prose h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.prose h3 { font-size: 16px; margin: 20px 0 8px; color: var(--brand-deep); }
.prose h4 { font-size: 14px; margin: 16px 0 6px; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-inline-start: 22px; padding-inline-end: 0; }
.prose li { margin-bottom: 4px; }
.prose blockquote {
  margin: 14px 0;
  padding: 12px 14px;
  background: var(--brand-mist);
  border-inline-start: 4px solid var(--brand);
  border-radius: 8px 0 0 8px;
  color: var(--ink-soft);
}
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 14px 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 100%;
}
.prose table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 12.5px;
  display: table;
}
.prose table thead th {
  background: var(--sidebar);
  color: #fff;
  font-weight: 600;
  padding: 9px 11px;
  text-align: right;
  border: 1px solid rgba(255,255,255,.08);
  white-space: nowrap;
}
.prose table td {
  padding: 8px 11px;
  border: 1px solid var(--line);
  vertical-align: top;
  text-align: right;
}
.prose table tbody tr:nth-child(even) { background: #fafafa; }

.prose code {
  background: #f3f4f6;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: .88em;
  word-break: break-word;
}
.prose pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 14px 0;
  font-size: 11px;
  line-height: 1.55;
  max-width: 100%;
}
.prose pre code { background: transparent; padding: 0; color: inherit; white-space: pre; }

.mermaid-wrap {
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin: 16px 0;
  overflow-x: auto;
  direction: ltr;
  text-align: center;
  max-width: 100%;
}
.mermaid { min-height: 60px; max-width: 100%; }
.mermaid svg { max-width: 100% !important; height: auto !important; }
.mermaid-error { margin: 8px 0 0; }

.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--line-soft);
  color: var(--ink-soft);
  flex-shrink: 0;
}
.tag.brand { background: var(--brand-soft); color: var(--brand-deep); }

.back-top {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  inset-inline-start: max(16px, env(safe-area-inset-left));
  z-index: 60;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.back-top.visible { opacity: 1; pointer-events: auto; }

/* ── Tablet / mobile ── */
@media (max-width: 1024px) {
  :root { --sidebar-w: min(300px, 88vw); }

  .main { margin-inline-end: 0; }

  .sidebar {
    transform: translateX(100%);
    box-shadow: -8px 0 32px rgba(0,0,0,.18);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    pointer-events: none;
  }
  .sidebar-backdrop.visible { pointer-events: auto; }

  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
}

@media (min-width: 641px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; align-items: stretch; }
  .topbar-start { order: 1; width: 100%; }
  .topbar-actions {
    order: 2;
    width: 100%;
    justify-content: stretch;
  }
  .topbar-actions .btn { flex: 1; padding: 8px 10px; font-size: 12px; }
  .btn-text-short { display: none; }
  .hero p { max-width: none; }
  .section-head { flex-direction: column; align-items: stretch; }
  .prose table { min-width: 480px; font-size: 11.5px; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .sidebar-backdrop, .topbar, .back-top, .menu-btn { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .doc-section.hidden { display: block !important; }
  .doc-section { break-inside: avoid; box-shadow: none; border: 0; }
}
