/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-hover: #f3f4f6;
  --surface-active: #eef0f3;

  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --text: #111827;
  --text-secondary: #4b5563;
  --text-tertiary: #9ca3af;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-subtle: #eef2ff;
  --accent-text: #3730a3;

  --success-bg: #ecfdf5;
  --success-text: #047857;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --warning-bg: #fffbeb;
  --warning-text: #b45309;

  --topbar-h: 3rem;
  --nav-w: 14.5rem;
  --toc-w: 12rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12);
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  --transition: 150ms ease;
  --content-max: 42rem;
  --content-max-wide: 56rem;
  --font-ar: "IBM Plex Sans Arabic", "Inter", system-ui, sans-serif;
  --space-section: 1.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12;
    --surface: #151820;
    --surface-raised: #1a1e28;
    --surface-hover: #222733;
    --surface-active: #2a3040;
    --border: #2a3040;
    --border-strong: #3a4255;
    --text: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-tertiary: #6b7280;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-subtle: rgba(99, 102, 241, 0.12);
    --accent-text: #c7d2fe;
    --success-bg: rgba(16, 185, 129, 0.12);
    --success-text: #6ee7b7;
    --error-bg: rgba(239, 68, 68, 0.12);
    --error-text: #fca5a5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

html[lang="ar"] body {
  font-family: var(--font-ar);
  line-height: 1.75;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 0.75rem;
  z-index: 9999;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 500;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
  outline: none;
  box-shadow: var(--focus-ring);
}

.kbd {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.35rem;
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-tertiary);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
}

/* ── Shell layout ──────────────────────────────────────────── */
.shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--toc-w);
  flex: 1;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns var(--transition);
}

.shell[data-sidebar="closed"] .workspace {
  grid-template-columns: 0 minmax(0, 1fr) var(--toc-w);
}

.shell[data-sidebar="closed"] .nav-panel {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.shell[data-toc="closed"] .workspace {
  grid-template-columns: var(--nav-w) minmax(0, 1fr) 0;
}

.shell[data-toc="closed"] .toc-panel {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.shell[data-sidebar="closed"][data-toc="closed"] .workspace {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}

.shell[data-sidebar="closed"][data-toc="open"] .workspace {
  grid-template-columns: 0 minmax(0, 1fr) var(--toc-w);
}

/* ── Top bar ───────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-h);
  flex-shrink: 0;
  padding: 0 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  min-width: 0;
}

.topbar__start,
.topbar__end {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
  min-width: 0;
}

.topbar__end {
  margin-inline-start: auto;
}

/* ── Language selector ─────────────────────────────────────── */
.lang-switcher {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.125rem;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lang-switcher--single {
  padding: 0.25rem 0.625rem;
}

.lang-switcher__current {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.lang-switcher__btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25;
  padding: 0.3125rem 0.625rem;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

.lang-switcher__btn:hover:not(.is-active) {
  color: var(--text);
  background: var(--surface);
}

.lang-switcher__btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.lang-switcher__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.lang-switcher__toggle {
  display: none;
  align-items: center;
  gap: 0.3125rem;
  flex-shrink: 0;
  appearance: none;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-secondary);
  padding: 0.3125rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-hover);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.lang-switcher__toggle:hover {
  color: var(--text);
  background: var(--surface-active);
  border-color: var(--border-strong);
}

.lang-switcher__toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.lang-switcher__toggle-icon {
  font-size: 0.875rem;
  line-height: 1;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.875rem;
}

.topbar__mark {
  display: grid;
  place-items: center;
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 0.375rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.topbar__brand-text {
  display: none;
}

.topbar__workspace {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  background: var(--surface-hover);
}

.topbar__release {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.0625rem;
  line-height: 1.2;
  text-align: end;
}

.topbar__release-updated {
  display: none;
  font-size: 0.625rem;
  color: var(--text-tertiary);
  opacity: 0.9;
}

.topbar__release-version {
  font-family: var(--mono);
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.topbar__feedback {
  flex-shrink: 0;
  appearance: none;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.topbar__feedback-short {
  display: none;
}

.topbar__feedback-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.topbar__feedback:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.topbar__feedback:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.site-footer {
  flex-shrink: 0;
  padding: 0.375rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.site-footer__text {
  margin: 0;
  font-size: 0.625rem;
  line-height: 1.4;
  color: var(--text-tertiary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Feedback modal ──────────────────────────────────────────── */
.feedback-modal {
  width: min(26rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.feedback-modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.feedback-modal__form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
}

.feedback-modal__header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.feedback-modal--issue .feedback-modal__header {
  background: linear-gradient(to bottom, var(--error-bg), var(--surface));
}

.feedback-modal--suggestion .feedback-modal__header {
  background: linear-gradient(to bottom, var(--accent-subtle), var(--surface));
}

.feedback-modal__title {
  margin: 0 0 0.625rem;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.feedback-modal__notice {
  margin: 0;
  padding: 0.4375rem 0.625rem;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-secondary);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
}

.feedback-modal__body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.125rem 1.25rem 1.25rem;
  overflow: auto;
}

.feedback-field {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4375rem;
}

.feedback-field--message {
  gap: 0.5rem;
}

.feedback-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.feedback-field__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.feedback-field__input,
.feedback-field__textarea {
  width: 100%;
  padding: 0.5625rem 0.6875rem;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), background var(--transition);
}

.feedback-field__input--readonly {
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 0.8125rem;
  cursor: default;
}

.feedback-field__textarea {
  resize: vertical;
  min-height: 7rem;
}

.feedback-field__input:focus,
.feedback-field__textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--focus-ring);
}

.feedback-modal__error {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--error-text);
  background: var(--error-bg);
  padding: 0.5625rem 0.6875rem;
  border-radius: var(--radius);
}

.feedback-modal__success {
  margin: 0;
  padding: 1.125rem 1.25rem;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--success-text);
  background: var(--success-bg);
  border-top: 1px solid var(--border);
}

.feedback-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem 1.125rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.feedback-modal__btn {
  appearance: none;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.feedback-modal__btn--ghost {
  color: var(--text-secondary);
  background: transparent;
  border-color: var(--border);
}

.feedback-modal__btn--ghost:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.feedback-modal__btn--primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.feedback-modal--issue .feedback-modal__btn--primary {
  background: var(--error-text);
  border-color: var(--error-text);
}

.feedback-modal--issue .feedback-modal__btn--primary:hover {
  filter: brightness(1.08);
}

.feedback-modal--suggestion .feedback-modal__btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.feedback-modal__btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.command-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  max-width: 28rem;
  margin: 0 auto;
  padding: 0.375rem 0.75rem;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-tertiary);
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.command-trigger:hover {
  background: var(--surface-active);
  border-color: var(--border-strong);
}

.command-trigger span:not(.kbd) {
  flex: 1;
  text-align: left;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ── Navigation panel ──────────────────────────────────────── */
.nav-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.nav-panel__actions {
  display: none;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-panel__action {
  appearance: none;
  width: 100%;
  padding: 0.5625rem 0.75rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: start;
  color: var(--text);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.nav-panel__action:hover {
  background: var(--surface-active);
  border-color: var(--border-strong);
}

.nav-panel__action:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.nav-panel__section {
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.nav-panel__section--grow {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-bottom: none;
}

.nav-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.nav-panel__title {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.nav-panel__count {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.field {
  position: relative;
  display: block;
}

.field--compact { margin-bottom: 0.5rem; }

.field__icon {
  position: absolute;
  left: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.field__input {
  width: 100%;
  padding: 0.4375rem 0.625rem 0.4375rem 1.875rem;
  font-family: inherit;
  font-size: 0.8125rem;
  color: var(--text);
  background: var(--surface-hover);
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: border-color var(--transition), background var(--transition);
}

.field__input::placeholder { color: var(--text-tertiary); }

.field__input:hover { background: var(--surface-active); }

.field__input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* Client list */
.client-list,
.module-tree,
.toc-list,
.command-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

.client-list {
  max-height: 9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.client-item { margin: 0; }

.client-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4375rem 0.5rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: left;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.client-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.client-btn[aria-current="true"] {
  background: var(--accent-subtle);
  color: var(--accent-text);
}

.client-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.client-btn__abbr {
  display: grid;
  place-items: center;
  width: 1.625rem;
  height: 1.625rem;
  flex-shrink: 0;
  border-radius: 0.3125rem;
  background: var(--surface-hover);
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
}

.client-btn[aria-current="true"] .client-btn__abbr {
  background: var(--accent);
  color: #fff;
}

.client-btn__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Module tree */
.module-tree {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.module-item { margin: 0; }

.module-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.4375rem 0.625rem;
  font-size: 0.8125rem;
  text-decoration: none;
  color: var(--text-secondary);
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  border: none;
  background: transparent;
  font-family: inherit;
  text-align: start;
  cursor: pointer;
  position: relative;
}

.module-link--active {
  background: var(--accent-subtle);
  color: var(--accent-text);
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--accent);
}

html[dir="rtl"] .module-link--active {
  box-shadow: inset -3px 0 0 var(--accent);
}

.module-link--active .module-link__badge {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.module-link:hover:not(.module-link--disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.module-link[aria-current="page"] {
  background: var(--accent-subtle);
  color: var(--accent-text);
  font-weight: 500;
}

.module-link--disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.module-link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.module-link__badge {
  flex-shrink: 0;
  min-width: 1.75rem;
  padding: 0.125rem 0.375rem;
  font-family: var(--mono);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--text-tertiary);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.module-link[aria-current="page"] .module-link__badge {
  color: var(--accent-text);
  border-color: var(--accent-subtle);
  background: var(--surface);
}

.module-link__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-link__status {
  flex-shrink: 0;
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--border-strong);
}

.module-link__status--live {
  background: #10b981;
}

.module-link__status--empty {
  background: var(--border);
}

/* ── Canvas (main content) ───────────────────────────────── */
.canvas {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem 2rem 3rem;
}

.canvas--prose .doc-body {
  max-width: var(--content-max);
}

.canvas--wide .doc-body {
  max-width: var(--content-max-wide);
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0 0 1.25rem;
  padding: 0;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.breadcrumb li {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.breadcrumb li + li::before {
  content: "/";
  color: var(--border-strong);
  margin-right: 0.125rem;
}

.breadcrumb a {
  color: var(--text-tertiary);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumb [aria-current="page"] {
  color: var(--text-secondary);
  font-weight: 500;
}

.doc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  max-width: calc(var(--content-max) + 4rem);
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

/* Page header card */
.page-header {
  max-width: var(--content-max-wide);
  margin-bottom: var(--space-section);
}

.canvas--prose .page-header {
  max-width: var(--content-max);
}

.page-header__card {
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.page-header__row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.625rem;
  margin-bottom: 0.75rem;
}

.page-header__module-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding: 0.1875rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-text);
  background: var(--accent-subtle);
  border-radius: 999px;
}

.page-header__type {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
}

.page-header__status {
  margin-inline-start: auto;
}

.page-header__client {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.25;
  color: var(--text);
}

html[lang="ar"] .page-header__client {
  letter-spacing: 0;
  line-height: 1.4;
}

.page-header__module-title {
  margin: 0.375rem 0 0;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.4;
}

.page-header__question {
  margin: 0.375rem 0 0;
  font-size: 0.875rem;
  color: var(--text-tertiary);
  line-height: 1.5;
  font-style: normal;
}

.page-header__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.35;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text-secondary);
  transition: background var(--transition), border-color var(--transition);
}

.meta-badge--live {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: transparent;
}

.meta-badge--source {
  max-width: 100%;
  border-radius: var(--radius);
  white-space: normal;
  text-align: start;
}

.doc-header__type {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent-text);
  letter-spacing: 0.01em;
}

.doc-header__title {
  margin: 0;
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.doc-header__question {
  margin: 0.375rem 0 0;
  font-size: 0.875rem;
  color: var(--text-tertiary);
  font-style: italic;
}

.doc-header__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.375rem;
  flex-shrink: 0;
}

.doc-header__updated {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: 999px;
  background: var(--accent-subtle);
  color: var(--accent-text);
}

.status-badge::before {
  content: "";
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s ease infinite;
}

.status-badge.is-ready {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-badge.is-ready::before {
  animation: none;
}

.status-badge.is-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.status-badge.is-error::before {
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Document body */
.doc-body {
  max-width: var(--content-max);
}

.content-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-section);
}

.section-card {
  padding: 1.25rem 1.375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.section-card:hover {
  box-shadow: var(--shadow-md);
}

.section-card > h2 {
  margin-top: 0 !important;
  padding-top: 0 !important;
  font-size: 1.0625rem;
}

.section-card > h2:first-child {
  margin-bottom: 0.75rem;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--border);
}

/* Terminology layout */
.term-categories {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.term-category__title {
  margin: 0 0 1rem !important;
  padding: 0 !important;
  font-size: 1.125rem !important;
  font-weight: 600;
  color: var(--text);
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}

.term-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.term-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin: 0;
  border: none;
}

.term-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.term-table th {
  padding: 0.625rem 0.875rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: start;
  color: var(--text-tertiary);
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.term-table td {
  padding: 0.75rem 0.875rem;
  text-align: start;
  vertical-align: top;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  line-height: 1.55;
  word-break: break-word;
}

html[lang="ar"] .term-table td {
  line-height: 1.7;
}

.term-table tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.015);
}

@media (prefers-color-scheme: dark) {
  .term-table tbody tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
  }
}

.term-table tbody tr {
  transition: background var(--transition);
}

.term-table tbody tr:hover td {
  background: var(--accent-subtle);
  color: var(--text);
}

.term-table tbody tr:last-child td {
  border-bottom: none;
}

.term-table--bilingual th,
.term-table--bilingual td {
  width: 50%;
}

html[lang="ar"] .term-table--bilingual td:first-child {
  font-weight: 500;
  color: var(--text);
}

html[lang="en"] .term-table--bilingual td:first-child {
  font-weight: 500;
  color: var(--text);
}

.term-table--abbrev th,
.term-table--abbrev td {
  font-size: 0.8125rem;
}

.term-table-wrap--compact {
  max-width: 36rem;
}

.doc-body--error {
  padding: 1.5rem;
  background: var(--error-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-lg);
  color: var(--error-text);
}

.doc-body--error code {
  font-family: var(--mono);
  font-size: 0.8125rem;
}

/* Markdown typography */
.markdown-body h1 { display: none; }

.markdown-body h2 {
  margin: 2rem 0 0.625rem;
  padding-top: 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}

html[lang="ar"] .markdown-body p,
html[lang="ar"] .markdown-body li {
  line-height: 1.75;
}

html[lang="ar"] .markdown-body h2 {
  letter-spacing: 0;
  line-height: 1.45;
}

.markdown-body h2:first-child { margin-top: 0; }

.markdown-body p {
  margin: 0 0 0.875rem;
  color: var(--text-secondary);
}

.markdown-body strong {
  color: var(--text);
  font-weight: 600;
}

.markdown-body ul {
  margin: 0 0 0.875rem;
  padding-inline-start: 1.25rem;
  color: var(--text-secondary);
}

.markdown-body li + li { margin-top: 0.25rem; }

.markdown-body a.module-xref {
  color: var(--accent-text);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent-text) 35%, transparent);
  font-weight: 500;
  transition: color var(--transition), border-color var(--transition);
}

.markdown-body a.module-xref:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

.markdown-body a.module-xref:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-bottom-color: transparent;
}

.markdown-body a.module-xref--unavailable {
  border-bottom-style: dashed;
  opacity: 0.85;
}

.markdown-body a.resource-xref {
  color: var(--accent-text);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent-text) 35%, transparent);
  font-weight: 500;
  transition: color var(--transition), border-color var(--transition);
}

.markdown-body a.resource-xref:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

.markdown-body a.resource-xref:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-bottom-color: transparent;
}

.markdown-body a.resource-xref--unavailable {
  border-bottom-style: dashed;
  opacity: 0.85;
  cursor: not-allowed;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.markdown-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.markdown-table-wrap > table {
  width: auto;
  min-width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 0.875rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.markdown-body th,
.markdown-body td {
  padding: 0.5rem 0.75rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
}

.markdown-body th {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  background: var(--surface-hover);
}

.markdown-body tr:last-child td { border-bottom: none; }

.markdown-body h2#metadata {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Mobile section nav ────────────────────────────────────── */
.mobile-section-nav {
  display: none;
  max-width: var(--content-max-wide);
  margin: 0 0 1rem;
}

.mobile-section-nav__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  list-style: none;
  transition: border-color var(--transition), background var(--transition);
}

.mobile-section-nav__summary::-webkit-details-marker {
  display: none;
}

.mobile-section-nav__summary::after {
  content: "";
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-inline-end: 2px solid var(--text-tertiary);
  border-bottom: 2px solid var(--text-tertiary);
  transform: rotate(45deg);
  transition: transform var(--transition);
}

html[dir="rtl"] .mobile-section-nav__summary::after {
  transform: rotate(-135deg);
}

.mobile-section-nav[open] .mobile-section-nav__summary::after {
  transform: rotate(-135deg);
}

html[dir="rtl"] .mobile-section-nav[open] .mobile-section-nav__summary::after {
  transform: rotate(45deg);
}

.mobile-section-nav__summary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.mobile-section-nav__summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.mobile-section-nav__panel {
  margin-top: 0.375rem;
  padding: 0.375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.mobile-section-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 12rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.mobile-section-nav__list .toc-link {
  border-inline-start-width: 2px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

html[dir="rtl"] .mobile-section-nav__list .toc-link {
  border-radius: var(--radius) 0 0 var(--radius);
}

/* ── TOC panel ─────────────────────────────────────────────── */
.toc-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.toc-panel__header {
  padding: 0.75rem 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.toc-panel__title {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.toc-panel nav {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 0.625rem;
}

.toc-link {
  display: block;
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-tertiary);
  text-decoration: none;
  border-inline-start: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

html[lang="ar"] .toc-link,
html[dir="rtl"] .toc-link {
  line-height: 1.6;
}

html[dir="rtl"] .toc-link {
  border-radius: var(--radius) 0 0 var(--radius);
}

.toc-link:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.toc-link.is-active {
  color: var(--accent-text);
  border-inline-start-color: var(--accent);
  background: var(--accent-subtle);
  font-weight: 500;
}

.toc-link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.toc-panel__footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--surface-hover);
}

.toc-panel__label {
  margin: 0 0 0.25rem;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.toc-panel__source {
  margin: 0;
  font-size: 0.6875rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

/* ── Command palette ───────────────────────────────────────── */
.command-palette {
  width: min(32rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100vh - 4rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.command-palette::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.command-palette__inner {
  display: flex;
  flex-direction: column;
}

.command-palette__search {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-tertiary);
}

.command-palette__search input {
  flex: 1;
  padding: 0;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: transparent;
  border: none;
}

.command-palette__search input:focus { outline: none; }

.command-results {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  max-height: 18rem;
  padding: 0.375rem;
}

.command-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  font-family: inherit;
  font-size: 0.8125rem;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.command-item:hover,
.command-item.is-selected {
  background: var(--surface-hover);
}

.command-item:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.command-item__type {
  flex-shrink: 0;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  width: 3.5rem;
}

.command-item__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.command-item__meta {
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: var(--text-tertiary);
}

.command-palette__hint {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border);
  background: var(--surface-hover);
}

.command-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}

/* ── Backdrop (mobile) ───────────────────────────────────────── */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.4);
}

.backdrop.is-visible {
  display: block;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (min-width: 640px) {
  .topbar__brand-text { display: inline; }
}

@media (min-width: 900px) {
  .topbar__release-updated {
    display: block;
  }
}

@media (max-width: 768px) {
  .topbar {
    gap: 0.375rem;
    padding: 0 0.5rem;
  }

  .topbar__start {
    flex-shrink: 1;
    min-width: 0;
  }

  .topbar__end {
    gap: 0.25rem;
  }

  .topbar__brand-text {
    display: none;
  }

  .topbar__feedback-group {
    display: none;
  }

  .lang-switcher--desktop {
    display: none;
  }

  .lang-switcher__toggle {
    display: inline-flex;
  }

  .nav-panel__actions {
    display: flex;
  }

  .topbar__release-version {
    font-size: 0.5625rem;
  }

  .feedback-field-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1024px) {
  .workspace,
  .shell[data-toc="open"] .workspace,
  .shell[data-toc="closed"] .workspace,
  .shell[data-sidebar="closed"] .workspace,
  .shell[data-sidebar="closed"][data-toc="closed"] .workspace,
  .shell[data-sidebar="closed"][data-toc="open"] .workspace {
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
  }

  .topbar__toc-toggle {
    display: none;
  }

  .toc-panel {
    display: none;
  }

  .mobile-section-nav:not([hidden]) {
    display: block;
  }

  .canvas--prose .mobile-section-nav:not([hidden]) {
    max-width: var(--content-max);
  }
}

@media (max-width: 768px) {
  .workspace,
  .shell[data-sidebar="closed"] .workspace,
  .shell[data-toc="closed"] .workspace,
  .shell[data-sidebar="closed"][data-toc="closed"] .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .nav-panel {
    position: fixed;
    top: var(--topbar-h);
    inset-inline-start: 0;
    bottom: 0;
    width: min(var(--nav-w), 85vw);
    z-index: 95;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform var(--transition), opacity var(--transition);
  }

  html[dir="rtl"] .nav-panel {
    transform: translateX(100%);
  }

  .shell[data-sidebar="open"] .nav-panel {
    transform: translateX(0);
    visibility: visible;
    opacity: 1;
  }

  .shell[data-sidebar="closed"] .nav-panel {
    transform: translateX(-100%);
  }

  html[dir="rtl"] .shell[data-sidebar="closed"] .nav-panel {
    transform: translateX(100%);
  }

  .shell[data-sidebar="open"] .backdrop.is-visible {
    display: block;
  }

  .canvas {
    padding: 1rem 1.25rem 2.5rem;
  }

  .page-header__card {
    padding: 1rem 1.125rem;
  }

  .page-header__client {
    font-size: 1.3125rem;
  }

  .doc-header {
    flex-direction: column;
    gap: 0.75rem;
  }

  .doc-header__meta {
    flex-direction: row;
    align-items: center;
  }

  .command-trigger span:not(.kbd) {
    display: none;
  }

  .command-trigger {
    max-width: 2.5rem;
    padding: 0.375rem;
    justify-content: center;
  }

  .term-table-wrap {
    margin-inline: calc(-1 * 0.25rem);
    border-radius: var(--radius);
  }

  .term-table th,
  .term-table td {
    padding: 0.625rem 0.625rem;
    font-size: 0.8125rem;
  }

  .page-header__badges {
    gap: 0.375rem;
  }

  .command-trigger .kbd { display: none; }
}

@media (max-width: 480px) {
  .topbar__workspace { display: none; }
  .doc-header__title { font-size: 1.375rem; }
}
