/* =====================================================================
   RTL overrides — Arabic-first refinements
   The bulk of layout is already direction-aware via CSS logical
   properties (inset-inline-*, margin-inline-*, padding-inline-*, etc).
   This file only adds Arabic typography polish + a few fixes that
   can't be expressed with logical properties.
   ===================================================================== */

html[dir="rtl"] body.sp-body,
body.rtl-layout {
  direction: rtl;
  font-family: var(--font-arabic);
  /* Slightly larger optical size for Arabic readability */
  letter-spacing: 0;
}

/* Refined Arabic typographic scale */
html[dir="rtl"] h1,
html[dir="rtl"] h2,
html[dir="rtl"] h3,
html[dir="rtl"] h4,
html[dir="rtl"] h5,
html[dir="rtl"] h6 {
  letter-spacing: 0;
  font-feature-settings: normal;
}
html[dir="rtl"] h1 { font-size: 1.875rem; }
html[dir="rtl"] h2 { font-size: 1.5rem; }

/* Inputs / buttons keep Cairo */
html[dir="rtl"] .btn,
html[dir="rtl"] .form-control,
html[dir="rtl"] .form-select,
html[dir="rtl"] .form-label,
html[dir="rtl"] .badge,
html[dir="rtl"] .nav-link,
html[dir="rtl"] .table {
  font-family: var(--font-arabic);
}

/* Numeric inputs: value aligned to the right in Arabic UI */
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[inputmode="numeric"]:not([type="hidden"]),
html[dir="rtl"] .ms-input-int {
  text-align: end;
  direction: ltr;
}

/* Marketing hero gradient text: switch to solid for better Arabic rendering */
html[dir="rtl"] .marketing-hero h1 {
  -webkit-text-fill-color: initial;
  background: none;
  color: var(--c-slate-900);
}

/* Sidebar: nav links naturally flip via dir=rtl; ensure text alignment */
html[dir="rtl"] .sidebar-nav .nav-link,
html[dir="rtl"] .sidebar-section { text-align: start; }

/* Brand: icon at inline-start (right), vertically centered with Arabic label */
html[dir="rtl"] .sidebar-brand,
.app-shell--rtl .sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  line-height: 1;
}

html[dir="rtl"] .sidebar-brand span,
.app-shell--rtl .sidebar-brand span {
  display: flex;
  align-items: center;
  line-height: 1.35;
  padding-block: 0.1rem;
}

html[dir="rtl"] .sidebar-brand i,
.app-shell--rtl .sidebar-brand i {
  flex-shrink: 0;
  align-self: center;
  margin: 0;
}

html[dir="rtl"] .platform-logo--sidebar .platform-logo__img,
.app-shell--rtl .platform-logo--sidebar .platform-logo__img {
  object-position: right center;
}

html[dir="rtl"] .site-logo,
.app-shell--rtl .site-logo {
  align-items: center;
}

html[dir="rtl"] .site-logo .fw-bold,
html[dir="rtl"] .site-logo span:not(.site-logo-mark),
.app-shell--rtl .site-logo .fw-bold,
.app-shell--rtl .site-logo span:not(.site-logo-mark) {
  display: flex;
  align-items: center;
  line-height: 1.35;
}

html[dir="rtl"] .site-logo-mark,
.app-shell--rtl .site-logo-mark {
  flex-shrink: 0;
}

/* Mobile sidebar: enter from the right in RTL */
@media (max-width: 991.98px) {
  html[dir="rtl"] .app-sidebar,
  .app-shell--rtl .app-sidebar {
    inset-inline-start: auto;
    inset-inline-end: 0;
    transform: translateX(100%);
  }
  html[dir="rtl"] .app-sidebar.show,
  .app-shell--rtl .app-sidebar.show {
    transform: translateX(0);
  }
}

/* Auth split: brand pane lives on the start (right) side in RTL.
   Grid order auto-flips with dir=rtl, so no extra rules needed. */

/* Tables: align headers naturally in RTL */
html[dir="rtl"] .table thead th,
html[dir="rtl"] .table tbody td { text-align: start; }

/* Misc Bootstrap utilities that don't auto-flip */
html[dir="rtl"] .text-end { text-align: start !important; }
html[dir="rtl"] .text-start { text-align: end !important; }
html[dir="rtl"] .float-end { float: left !important; }
html[dir="rtl"] .float-start { float: right !important; }

/* Bootstrap icons (Bootstrap Icons font) should NOT mirror in RTL.
   Brand marks stay flex-centered so the glyph sits in the middle of the tile. */
html[dir="rtl"] .bi:not(.sidebar-brand i):not(.site-logo-mark i):not(.site-logo-mark .bi):not(.kpi-label__icon .bi):not(.kpi-label > i) {
  direction: ltr;
  display: inline-block;
}

html[dir="rtl"] .sidebar-brand i.bi,
.app-shell--rtl .sidebar-brand i.bi,
html[dir="rtl"] .site-logo-mark,
.app-shell--rtl .site-logo-mark,
html[dir="rtl"] .site-logo-mark .bi,
.app-shell--rtl .site-logo-mark .bi {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  direction: ltr;
}

html[dir="rtl"] .sidebar-brand i.bi::before,
.app-shell--rtl .sidebar-brand i.bi::before,
html[dir="rtl"] .site-logo-mark .bi::before,
.app-shell--rtl .site-logo-mark .bi::before {
  display: block;
  margin: 0;
  line-height: 1;
  transform: none;
}

/* Bilingual text helper class for places we want secondary font */
.bilingual-secondary { font-family: var(--font-sans); }

/* Numbers/code in Arabic UI should remain LTR (Western numerals look better aligned) */
html[dir="rtl"] code,
html[dir="rtl"] .badge,
html[dir="rtl"] time {
  direction: ltr;
  unicode-bidi: isolate;
}

/* KPI / stat cards — align label row and numeric value to inline-start (right in RTL) */
html[dir="rtl"] .kpi,
html[dir="rtl"] .kpi-card,
.app-shell--rtl .kpi,
.app-shell--rtl .kpi-card {
  align-items: flex-start;
}

html[dir="rtl"] .kpi-label,
.app-shell--rtl .kpi-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  justify-content: flex-start;
  gap: 0.5rem;
}

html[dir="rtl"] .kpi-label__icon,
html[dir="rtl"] .kpi-label > i,
.app-shell--rtl .kpi-label__icon,
.app-shell--rtl .kpi-label > i {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  align-self: center;
  direction: ltr;
}

html[dir="rtl"] .kpi-label__icon i.bi::before,
html[dir="rtl"] .kpi-label > i.bi::before,
.app-shell--rtl .kpi-label__icon i.bi::before,
.app-shell--rtl .kpi-label > i.bi::before {
  display: block;
  margin: 0;
  line-height: 1;
}

html[dir="rtl"] .kpi-label__text,
.app-shell--rtl .kpi-label__text {
  line-height: 1.4;
}

html[dir="rtl"] .kpi-value,
html[dir="rtl"] .kpi-card .kpi-value,
.app-shell--rtl .kpi-value,
.app-shell--rtl .kpi-card .kpi-value {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: end;
  align-self: stretch;
  width: 100%;
}

html[dir="rtl"] .ms-kpi-card .ms-kpi-label,
.app-shell--rtl .ms-kpi-card .ms-kpi-label {
  text-transform: none;
  letter-spacing: 0;
  text-align: start;
}

html[dir="rtl"] .ms-kpi-card .ms-kpi-value,
.app-shell--rtl .ms-kpi-card .ms-kpi-value {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}

html[dir="rtl"] .ms-timeline-arrow.bi-arrow-right::before,
.app-shell--rtl .ms-timeline-arrow.bi-arrow-right::before {
  transform: scaleX(-1);
}

html[dir="rtl"] .ms-evidence-files .list-group-item,
.app-shell--rtl .ms-evidence-files .list-group-item {
  flex-direction: row-reverse;
}
