/* RTL (Right-to-Left) Support for Arabic */

/* Apply RTL-specific styles when dir="rtl" is set on html element */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

/* ==========================================
   CRITICAL: EXCLUDE HEADER AND FOOTER FROM RTL
   ========================================== */

/* Force header container to always be LTR */
html[dir="rtl"] header {
  direction: ltr !important;
}

/* Prevent Tailwind's automatic RTL transforms in header */
html[dir="rtl"] header > * {
  --tw-space-x-reverse: 0 !important;
}

/* Keep header text content LTR */
html[dir="rtl"] header a,
html[dir="rtl"] header span,
html[dir="rtl"] header p,
html[dir="rtl"] header h1,
html[dir="rtl"] header h2,
html[dir="rtl"] header h3,
html[dir="rtl"] header li {
  direction: ltr !important;
}

/* Keep header form elements LTR */
html[dir="rtl"] header input,
html[dir="rtl"] header textarea,
html[dir="rtl"] header select,
html[dir="rtl"] header button {
  direction: ltr !important;
  text-align: left !important;
}

/* Keep header placeholders LTR */
html[dir="rtl"] header ::-moz-placeholder {
  text-align: left !important;
}
html[dir="rtl"] header ::placeholder {
  text-align: left !important;
}

/* Prevent logo and icon flip in header */
html[dir="rtl"] header img,
html[dir="rtl"] header svg {
  transform: none !important;
}

/* Prevent icon rotation in header */
html[dir="rtl"] header .rotate-180 {
  transform: none !important;
}

/* ==========================================
   FOOTER: Allow RTL text but keep layout stable
   ========================================== */

/* Prevent footer grid/flex from reversing */
html[dir="rtl"] footer .grid,
html[dir="rtl"] footer .flex {
  direction: ltr !important;
}

/* But allow text direction to be RTL */
html[dir="rtl"] footer p,
html[dir="rtl"] footer h1,
html[dir="rtl"] footer h2,
html[dir="rtl"] footer h3,
html[dir="rtl"] footer li,
html[dir="rtl"] footer a,
html[dir="rtl"] footer span {
  direction: rtl !important;
}

/* Prevent logo and icon flip in footer */
html[dir="rtl"] footer img,
html[dir="rtl"] footer svg {
  transform: none !important;
}

/* ==========================================
   PREVENT ALL ICONS/SVGS FROM FLIPPING
   ========================================== */

/* Prevent automatic SVG flipping in RTL except those explicitly marked */
html[dir="rtl"] svg:not(.rtl-rotate) {
  transform: none !important;
}

/* Prevent all images from flipping */
html[dir="rtl"] img {
  transform: none !important;
}

/* Override text alignment for RTL */
[dir="rtl"] .text-left {
  text-align: right !important;
}

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

/* Float overrides for RTL */
[dir="rtl"] .float-left {
  float: right !important;
}

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

/* Margin overrides for RTL - swap left/right margins */
[dir="rtl"] .ml-auto {
  margin-left: 0 !important;
  margin-right: auto !important;
}

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

/* Padding overrides for specific cases */
[dir="rtl"] .pl-10 {
  padding-left: 0.5rem !important;
  padding-right: 2.5rem !important;
}

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

/* Border radius swap for RTL */
[dir="rtl"] .rounded-l {
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
  border-top-right-radius: 0.375rem !important;
  border-bottom-right-radius: 0.375rem !important;
}

[dir="rtl"] .rounded-r {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
  border-top-left-radius: 0.375rem !important;
  border-bottom-left-radius: 0.375rem !important;
}

/* Flexbox direction overrides */
[dir="rtl"] .flex-row-reverse {
  flex-direction: row !important;
}

/* Transform overrides for arrows and icons */
[dir="rtl"] .rotate-180 {
  transform: rotate(180deg);
}

/* Ensure buttons and links respect RTL */
[dir="rtl"] button,
[dir="rtl"] a {
  text-align: inherit;
}

/* Forms in RTL */
[dir="rtl"] input[type="text"],
[dir="rtl"] input[type="email"],
[dir="rtl"] input[type="password"],
[dir="rtl"] input[type="search"],
[dir="rtl"] textarea,
[dir="rtl"] select {
  text-align: right;
  direction: rtl;
}

/* Adjust placeholder text for RTL */
[dir="rtl"] ::-moz-placeholder {
  text-align: right;
}
[dir="rtl"] ::placeholder {
  text-align: right;
}

/* Fix for absolute positioning in RTL */
[dir="rtl"] .absolute.left-2 {
  left: auto !important;
  right: 0.5rem !important;
}

[dir="rtl"] .absolute.right-2 {
  right: auto !important;
  left: 0.5rem !important;
}

/* Ensure grid layouts work properly in RTL */
[dir="rtl"] .grid {
  direction: rtl;
}

/* Navigation breadcrumbs */
[dir="rtl"] nav svg {
  transform: rotate(180deg);
}

/* Slideover specific RTL adjustments */
[dir="rtl"] .slideover-menu {
  border-right: none;
  border-left: 1px solid #e5e7eb;
}

/* Dropdown menus */
[dir="rtl"] .dropdown-menu {
  left: auto;
  right: 0;
}

/* Modal positioning */
[dir="rtl"] .modal {
  text-align: right;
}

/* Card layouts */
[dir="rtl"] .card {
  text-align: right;
}

/* List items */
[dir="rtl"] li {
  text-align: right;
}

/* Tables */
[dir="rtl"] table {
  direction: rtl;
}

[dir="rtl"] th,
[dir="rtl"] td {
  text-align: right;
}
