/**
 * RTL layout — Arabic. Loaded after Bootstrap RTL when dir="rtl".
 * Prefer logical properties; html[dir=rtl] already establishes bidi for most content.
 */

/* Shell: sidebar on the right for RTL */
[dir="rtl"] .tv-app {
  flex-direction: row-reverse;
}

/* Sidebar positioning - ensure it's on the right in RTL */
[dir="rtl"] .tv-sidebar {
  order: 1;
  border-right: none;
  border-left: 1px solid var(--tv-border);
  left: auto;
  right: 0;
}

/* Main column margin uses margin-inline-start in design-system.css — works for RTL */

/* Guest (unauthenticated) layout — no sidebar offset in either direction */
[dir="rtl"] .tv-main--guest {
  margin-inline: 0 !important;
  width: 100% !important;
}

/* Divider between sidebar and main */
[dir="rtl"] .tv-sidebar {
  border-right: none;
  border-left: 1px solid var(--tv-border);
}

html[data-theme="dark"][dir="rtl"] .tv-sidebar {
  box-shadow: -4px 0 40px rgba(0, 0, 0, 0.35);
}

html[data-theme="light"][dir="rtl"] .tv-sidebar {
  box-shadow: -1px 0 0 rgba(15, 23, 42, 0.06);
}

/* Submenu rows: indent + bullet on inline-start */
[dir="rtl"] .tv-sidebar-submenu .tv-sidebar-link {
  padding-block: 0.4375rem;
  padding-inline-start: 2.125rem;
  padding-inline-end: 0.875rem;
}

[dir="rtl"] .tv-sidebar-submenu .tv-sidebar-link::before {
  left: auto;
  right: auto;
  inset-inline-start: 0.875rem;
  inset-inline-end: auto;
}

/* Sidebar toggle arrow: flip chevron direction in RTL */
[dir="rtl"] .tv-sidebar-link--toggle .ms-auto {
  transform: scaleX(-1);
}

/* Sidebar user section: avatar on inline-start, text flows naturally */
[dir="rtl"] .tv-sidebar-user {
  flex-direction: row-reverse;
}

/* Sidebar footer logout button */
[dir="rtl"] .tv-btn-sidebar-logout {
  flex-direction: row-reverse;
}

[dir="rtl"] .tv-btn-sidebar-logout svg {
  margin-left: 0;
  margin-right: 0.5rem;
}

/* Language switcher (classic flex only; segmented uses grid + logical thumb) */
[dir="rtl"] .tv-lang-switch:not(.tv-lang-switch--segmented) {
  flex-direction: row-reverse;
}

/* Breadcrumb separators in RTL */
[dir="rtl"] .tv-breadcrumb__item:not(:last-child)::after {
  transform: rotate(225deg);
}

/* Confirm dialog icon margin */
[dir="rtl"] .tv-confirm-dialog__icon {
  margin: 0 auto 1rem;
}

/* Toast row: leading edge = close in RTL */
[dir="rtl"] .tv-toast__inner {
  flex-direction: row-reverse;
}

/* Form field error messages */
[dir="rtl"] .form-text,
[dir="rtl"] .invalid-feedback {
  text-align: start;
}

/* Stat card trend indicators */
[dir="rtl"] .tv-stat-card__trend {
  flex-direction: row-reverse;
}

/* Page header actions */
[dir="rtl"] .tv-page-header .d-flex.gap-2 {
  flex-direction: row-reverse;
}

/* Card body padding remains logical */
[dir="rtl"] .tv-card-body {
  padding: var(--tv-space-6);
}

/* Empty state */
[dir="rtl"] .tv-empty-state {
  text-align: center;
}

/* Top bar */
[dir="rtl"] .tv-search svg {
  order: 2;
}

[dir="rtl"] .tv-search input {
  text-align: right;
}

[dir="rtl"] .tv-topbar__left {
  flex-direction: row-reverse;
}

[dir="rtl"] .tv-topbar__actions {
  flex-direction: row-reverse;
}

/* Mobile drawer: slide from physical right (inline-end in RTL) */
@media (max-width: 991.98px) {
  [dir="rtl"] .tv-sidebar {
    left: auto;
    right: 0;
    transform: translateX(100%);
  }

  [dir="rtl"] .tv-sidebar.tv-sidebar--open {
    transform: translateX(0);
  }
}

/* Typed values stay readable */
[dir="rtl"] input[type="number"],
[dir="rtl"] input[type="email"],
[dir="rtl"] input[type="tel"] {
  direction: ltr;
  text-align: start;
}

/* Tables — align start/end; mixed numerics */
[dir="rtl"] .tv-theme main table th,
[dir="rtl"] .tv-theme main table td {
  text-align: start;
}

[dir="rtl"] .tv-theme main table .text-end {
  text-align: end !important;
}

[dir="rtl"] table .tv-num {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: end !important;
}

/* DataTables */
[dir="rtl"] .dataTables_wrapper {
  direction: rtl;
}

[dir="rtl"] .dataTables_scrollHead table,
[dir="rtl"] .dataTables_scrollBody table {
  direction: rtl;
}

[dir="rtl"] .tv-dt-toolbar-inner.tv-dt-toolbar-inner--react {
  direction: rtl;
}

[dir="rtl"] .tv-dt-toolbar .dt-buttons {
  flex-direction: row-reverse;
}

[dir="rtl"] .dataTables_filter input {
  text-align: right;
}

[dir="rtl"] input.tv-dt-col-filter {
  text-align: right;
}

[dir="rtl"] .tv-ltr-isolate,
[dir="rtl"] .tv-num,
[dir="rtl"] .font-monospace.tv-ltr-isolate {
  direction: ltr;
  unicode-bidi: isolate;
}

[dir="rtl"] .tv-filter-bar .form-label,
[dir="rtl"] .tv-report-filter-panel .form-label {
  text-align: start;
}
