/**
 * RTL/LTR Auto-Fix CSS
 * يستخدم CSS logical properties لدعم RTL/LTR تلقائياً
 */

/* ========== Margin ========== */
/* RTL: mr-4 = margin-right, ml-4 = margin-left */
/* LTR: mr-4 = margin-left, ml-4 = margin-right */
[dir="rtl"] .mr-64 {
  margin-right: 16rem !important;
  margin-left: 0 !important;
}

[dir="ltr"] .mr-64 {
  margin-left: 16rem !important;
  margin-right: 0 !important;
}

[dir="rtl"] .ml-64 {
  margin-left: 16rem !important;
  margin-right: 0 !important;
}

[dir="ltr"] .ml-64 {
  margin-right: 16rem !important;
  margin-left: 0 !important;
}

[dir="rtl"] .mr-4 {
  margin-right: 1rem !important;
  margin-left: 0 !important;
}

[dir="ltr"] .mr-4 {
  margin-left: 1rem !important;
  margin-right: 0 !important;
}

[dir="rtl"] .ml-4 {
  margin-left: 1rem !important;
  margin-right: 0 !important;
}

[dir="ltr"] .ml-4 {
  margin-right: 1rem !important;
  margin-left: 0 !important;
}

[dir="rtl"] .mr-3 {
  margin-right: 0.75rem !important;
  margin-left: 0 !important;
}

[dir="ltr"] .mr-3 {
  margin-left: 0.75rem !important;
  margin-right: 0 !important;
}

[dir="rtl"] .ml-3 {
  margin-left: 0.75rem !important;
  margin-right: 0 !important;
}

[dir="ltr"] .ml-3 {
  margin-right: 0.75rem !important;
  margin-left: 0 !important;
}

[dir="rtl"] .mr-2 {
  margin-right: 0.5rem !important;
  margin-left: 0 !important;
}

[dir="ltr"] .mr-2 {
  margin-left: 0.5rem !important;
  margin-right: 0 !important;
}

[dir="rtl"] .ml-2 {
  margin-left: 0.5rem !important;
  margin-right: 0 !important;
}

[dir="ltr"] .ml-2 {
  margin-right: 0.5rem !important;
  margin-left: 0 !important;
}

[dir="rtl"] .mr-1 {
  margin-right: 0.25rem !important;
  margin-left: 0 !important;
}

[dir="ltr"] .mr-1 {
  margin-left: 0.25rem !important;
  margin-right: 0 !important;
}

[dir="rtl"] .ml-1 {
  margin-left: 0.25rem !important;
  margin-right: 0 !important;
}

[dir="ltr"] .ml-1 {
  margin-right: 0.25rem !important;
  margin-left: 0 !important;
}

/* ========== Padding ========== */
/* RTL: pr-4 = padding-right, pl-4 = padding-left */
/* LTR: pr-4 = padding-left, pl-4 = padding-right */
[dir="rtl"] .pr-4 {
  padding-right: 1rem !important;
  padding-left: 0 !important;
}

[dir="ltr"] .pr-4 {
  padding-left: 1rem !important;
  padding-right: 0 !important;
}

[dir="rtl"] .pl-4 {
  padding-left: 1rem !important;
  padding-right: 0 !important;
}

[dir="ltr"] .pl-4 {
  padding-right: 1rem !important;
  padding-left: 0 !important;
}

[dir="rtl"] .pr-3 {
  padding-right: 0.75rem !important;
  padding-left: 0 !important;
}

[dir="ltr"] .pr-3 {
  padding-left: 0.75rem !important;
  padding-right: 0 !important;
}

[dir="rtl"] .pl-3 {
  padding-left: 0.75rem !important;
  padding-right: 0 !important;
}

[dir="ltr"] .pl-3 {
  padding-right: 0.75rem !important;
  padding-left: 0 !important;
}

[dir="rtl"] .pr-2 {
  padding-right: 0.5rem !important;
  padding-left: 0 !important;
}

[dir="ltr"] .pr-2 {
  padding-left: 0.5rem !important;
  padding-right: 0 !important;
}

[dir="rtl"] .pl-2 {
  padding-left: 0.5rem !important;
  padding-right: 0 !important;
}

[dir="ltr"] .pl-2 {
  padding-right: 0.5rem !important;
  padding-left: 0 !important;
}

/* ========== Text Alignment ========== */
/* RTL: text-right = align right, text-left = align left */
/* LTR: text-right = align left, text-left = align right */
[dir="rtl"] .text-right {
  text-align: right !important;
}

[dir="ltr"] .text-right {
  text-align: left !important;
}

[dir="rtl"] .text-left {
  text-align: left !important;
}

[dir="ltr"] .text-left {
  text-align: right !important;
}

/* ========== Flexbox ========== */
.flex-row-reverse {
  flex-direction: row-reverse;
}

[dir="rtl"] .flex-row {
  flex-direction: row-reverse;
}

[dir="ltr"] .flex-row-reverse {
  flex-direction: row;
}

/* ========== Border ========== */
/* RTL: border-r = border-right, border-l = border-left */
/* LTR: border-r = border-left, border-l = border-right */
[dir="rtl"] .border-r {
  border-right-width: 1px !important;
  border-left-width: 0 !important;
}

[dir="ltr"] .border-r {
  border-left-width: 1px !important;
  border-right-width: 0 !important;
}

[dir="rtl"] .border-l {
  border-left-width: 1px !important;
  border-right-width: 0 !important;
}

[dir="ltr"] .border-l {
  border-right-width: 1px !important;
  border-left-width: 0 !important;
}

/* ========== Rounded Corners ========== */
.rounded-r-lg {
  border-start-end-radius: 0.5rem !important;
  border-end-end-radius: 0.5rem !important;
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.rounded-l-lg {
  border-start-start-radius: 0.5rem !important;
  border-end-start-radius: 0.5rem !important;
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
}

/* ========== Position ========== */
/* RTL: right-0 = right, left-0 = left */
/* LTR: right-0 = left, left-0 = right */
[dir="rtl"] .right-0 {
  right: 0 !important;
  left: auto !important;
}

[dir="ltr"] .right-0 {
  left: 0 !important;
  right: auto !important;
}

[dir="rtl"] .left-0 {
  left: 0 !important;
  right: auto !important;
}

[dir="ltr"] .left-0 {
  right: 0 !important;
  left: auto !important;
}

[dir="rtl"] .right-4 {
  right: 1rem !important;
  left: auto !important;
}

[dir="ltr"] .right-4 {
  left: 1rem !important;
  right: auto !important;
}

[dir="rtl"] .left-4 {
  left: 1rem !important;
  right: auto !important;
}

[dir="ltr"] .left-4 {
  right: 1rem !important;
  left: auto !important;
}

/* ========== Transform ========== */
[dir="rtl"] .transform {
  transform: scaleX(1);
}

/* ========== Icons (FontAwesome) ========== */
[dir="rtl"] .fa-chevron-right:before {
  content: "\f053"; /* chevron-left */
}

[dir="rtl"] .fa-chevron-left:before {
  content: "\f054"; /* chevron-right */
}

[dir="rtl"] .fa-arrow-right:before {
  content: "\f060"; /* arrow-left */
}

[dir="rtl"] .fa-arrow-left:before {
  content: "\f061"; /* arrow-right */
}

/* ========== Sidebar ========== */
/* تأكد من أن Sidebar fixed */
#sidebar {
  position: fixed !important;
  top: 0;
  bottom: 0;
  width: 16rem; /* 64 * 0.25rem */
  z-index: 40 !important;
}

/* تحديد موقع Sidebar حسب الاتجاه */
[dir="rtl"] #sidebar {
  right: 0 !important;
  left: auto !important;
}

[dir="ltr"] #sidebar {
  left: 0 !important;
  right: auto !important;
}

/* تحديد margin للمحتوى حسب الاتجاه */
[dir="rtl"] #content {
  margin-right: 16rem !important;
  margin-left: 0 !important;
}

[dir="ltr"] #content {
  margin-left: 16rem !important;
  margin-right: 0 !important;
}

/* إلغاء أي classes تتعارض */
[dir="rtl"] #content.mr-64 {
  margin-right: 16rem !important;
  margin-left: 0 !important;
}

[dir="ltr"] #content.mr-64 {
  margin-left: 16rem !important;
  margin-right: 0 !important;
}

/* عند إخفاء Sidebar */
[dir="rtl"] #sidebar.hidden + #content,
[dir="rtl"] #sidebar.hidden ~ #content {
  margin-right: 0 !important;
}

[dir="ltr"] #sidebar.hidden + #content,
[dir="ltr"] #sidebar.hidden ~ #content {
  margin-left: 0 !important;
}

/* Content positioning */
#content {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

/* ========== Utilities ========== */
.rtl-flip {
  transform: scaleX(-1);
}

[dir="rtl"] .ltr-only {
  display: none;
}

[dir="ltr"] .rtl-only {
  display: none;
}

/* ========== Animations ========== */
@keyframes slideInRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes slideInLeft {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

[dir="rtl"] .slide-in {
  animation: slideInLeft 0.3s ease-out;
}

[dir="ltr"] .slide-in {
  animation: slideInRight 0.3s ease-out;
}

/* ========== Space-X Utilities ========== */
/* Fix for .space-x-2 and similar utilities to work correctly in RTL/LTR */
.space-x-2 > :not([hidden]) ~ :not([hidden]) {
  --tw-space-x-reverse: 0;
}

/* RTL: Use margin-right (as user specified) */
[dir="rtl"] .space-x-2 > :not([hidden]) ~ :not([hidden]) {
  --tw-space-x-reverse: 1;
  margin-right: calc(0.5rem * var(--tw-space-x-reverse));
  margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
}

/* LTR: Use margin-left (as user specified) */
[dir="ltr"] .space-x-2 > :not([hidden]) ~ :not([hidden]) {
  --tw-space-x-reverse: 0;
  margin-left: calc(0.5rem * calc(1 + var(--tw-space-x-reverse)));
  margin-right: 0;
}

/* Fix for .space-x-3 */
.space-x-3 > :not([hidden]) ~ :not([hidden]) {
  --tw-space-x-reverse: 0;
}

/* RTL: Use margin-right (as user specified) */
[dir="rtl"] .space-x-3 > :not([hidden]) ~ :not([hidden]) {
  --tw-space-x-reverse: 0;
  margin-right: calc(0.75rem * var(--tw-space-x-reverse));
  margin-left: calc(0.75rem * calc(1 - var(--tw-space-x-reverse)));
}

/* LTR: Use margin-left (as user specified) */
[dir="ltr"] .space-x-3 > :not([hidden]) ~ :not([hidden]) {
  --tw-space-x-reverse: 0;
  margin-right: calc(0.75rem * var(--tw-space-x-reverse));
  margin-left: calc(0.75rem * calc(1 + var(--tw-space-x-reverse)));
}

/* Support for space-x-reverse class */
.space-x-reverse {
  --tw-space-x-reverse: 1;
}

[dir="rtl"] .space-x-reverse {
  --tw-space-x-reverse: 0;
}

[dir="ltr"] .space-x-reverse {
  --tw-space-x-reverse: 1;
}

