/* RTL Support CSS Framework (externalized for CSP) */

/* Apply only when document is RTL */
body[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

/* Flip horizontal margins and paddings */
body[dir="rtl"] .container,
body[dir="rtl"] .navbar-content,
body[dir="rtl"] .page-header,
body[dir="rtl"] .auth-card,
body[dir="rtl"] .profile-card,
body[dir="rtl"] .module-card,
body[dir="rtl"] .billing-overview,
body[dir="rtl"] .api-keys-section {
  direction: rtl;
}

/* Navigation adjustments */
body[dir="rtl"] .navbar-nav { flex-direction: row-reverse; }
body[dir="rtl"] .navbar-actions { flex-direction: row-reverse; }
body[dir="rtl"] .nav-link { text-align: right; }

/* Dropdown menus */
body[dir="rtl"] .dropdown-menu {
  left: 0 !important;
  right: auto !important;
  text-align: right;
}
body[dir="rtl"] .language-menu {
  left: 0 !important;
  right: auto !important;
}

/* Form elements */
body[dir="rtl"] .form-input,
body[dir="rtl"] .form-label,
body[dir="rtl"] .form-group { text-align: right; }

/* Buttons */
body[dir="rtl"] .btn-primary,
body[dir="rtl"] .btn-secondary,
body[dir="rtl"] .btn-outline { text-align: center; }

/* Cards and content */
body[dir="rtl"] .profile-header,
body[dir="rtl"] .profile-stats,
body[dir="rtl"] .module-info,
body[dir="rtl"] .key-header,
body[dir="rtl"] .key-actions,
body[dir="rtl"] .plan-header,
body[dir="rtl"] .plan-actions,
body[dir="rtl"] .result-header { flex-direction: row-reverse; }

body[dir="rtl"] .profile-info { text-align: right; }

/* Tables */
body[dir="rtl"] .history-table { direction: rtl; }
body[dir="rtl"] .history-table th,
body[dir="rtl"] .history-table td { text-align: right; }

/* Language selector specific */
body[dir="rtl"] .language-toggle,
body[dir="rtl"] .language-item { flex-direction: row-reverse; }
body[dir="rtl"] .current-indicator { margin-right: auto; margin-left: 0; }

/* Icons and arrows */
body[dir="rtl"] .dropdown-arrow { transform: scaleX(-1); }

/* File upload areas */
body[dir="rtl"] .file-upload-area { text-align: right; }
body[dir="rtl"] .comparison-container { direction: rtl; }

/* Breadcrumbs */
body[dir="rtl"] .breadcrumb { flex-direction: row-reverse; }
body[dir="rtl"] .breadcrumb-item::before {
  content: "\\";
  transform: scaleX(-1);
}

/* Pagination */
body[dir="rtl"] .pagination { flex-direction: row-reverse; }

/* Alerts and messages */
body[dir="rtl"] .message { text-align: right; }

/* Grid layouts */
body[dir="rtl"] .billing-overview { direction: rtl; }
body[dir="rtl"] .overview-card { text-align: right; }

/* Specific Arabic font improvements */
body[lang="ar"] {
  font-family: 'Segoe UI', 'Tahoma', 'Arial', 'Helvetica Neue', sans-serif;
  line-height: 1.6;
}
body[lang="ar"] .navbar-logo,
body[lang="ar"] .logo {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
/* Fix for Arabic numerals */
body[lang="ar"] .credits-badge,
body[lang="ar"] .stat-value,
body[lang="ar"] .amount,
body[lang="ar"] .value {
  font-family: 'Inter', monospace;
  direction: ltr;
  display: inline-block;
}
/* Adjust spacing for Arabic text */
body[lang="ar"] h1,
body[lang="ar"] h2,
body[lang="ar"] h3 { margin-bottom: 1.2em; }
body[lang="ar"] p { margin-bottom: 1em; line-height: 1.8; }
/* Fix input alignment */
body[lang="ar"] input[type="email"],
body[lang="ar"] input[type="password"],
body[lang="ar"] input[type="text"] {
  text-align: right;
  padding-right: 16px;
  padding-left: 16px;
}
/* Fix placeholder text */
body[lang="ar"] input::placeholder { text-align: right; }

/* Language-specific font optimizations */
body[lang="zh"] {
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;
}
body[lang="ja"] {
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic', 'Meiryo', sans-serif;
}
body[lang="ko"] {
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Nanum Gothic', sans-serif;
}
body[lang="hi"] {
  font-family: 'Noto Sans Devanagari', 'Mangal', 'Devanagari Sangam MN', sans-serif;
}
body[lang="ru"] {
  font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
}

/* Smooth transitions for direction changes */
.container,
.navbar-content,
.auth-card,
.profile-card,
.module-card { transition: all 0.3s ease; }

/* Fix for mixed content (LTR in RTL) */
.ltr-content {
  direction: ltr;
  text-align: left;
  display: inline-block;
}

/* Code blocks and technical content should remain LTR */
code,
pre,
.api-key,
.key-value,
.transcription-text {
  direction: ltr;
  text-align: left;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

/* Email addresses and URLs */
.email,
.url,
input[type="email"],
input[type="url"] { direction: ltr; text-align: left; }

/* Numbers and currency */
.number,
.currency,
.credits,
.amount { direction: ltr; display: inline-block; }
