/**
 * RTL Fixes - إصلاحات شاملة للغة العربية
 * يطبق تلقائياً على جميع الشاشات الجديدة
 * 
 * آخر تحديث: ديسمبر 2025
 */

/* ==================== القوائم المنسدلة (Select Dropdowns) ==================== */

/* محاذاة النص لليمين */
[dir="rtl"] .form-select,
[dir="rtl"] select.form-select,
[dir="rtl"] select.form-control,
[dir="rtl"] select {
    text-align: right !important;
    direction: rtl !important;
    padding-right: 1rem !important;
    padding-left: 2.5rem !important;
    background-position: left 0.75rem center !important;
}

/* محاذاة الخيارات */
[dir="rtl"] .form-select option,
[dir="rtl"] select option,
[dir="rtl"] optgroup {
    text-align: right !important;
    direction: rtl !important;
    padding-right: 0.5rem !important;
}

/* إصلاح ارتفاع النص في القوائم */
.form-select,
select.form-select,
select.form-control,
select {
    line-height: 1.5 !important;
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
    min-height: 48px !important;
    vertical-align: middle !important;
    display: inline-block !important;
}

/* أحجام مختلفة */
.form-select-lg {
    padding-top: 0.875rem !important;
    padding-bottom: 0.875rem !important;
    min-height: 56px !important;
    font-size: 1.1rem !important;
}

.form-select-sm {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    min-height: 38px !important;
    font-size: 0.9rem !important;
}

/* إصلاح عرض النص المختار */
.form-select:not([multiple]):not([size]),
select:not([multiple]):not([size]) {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e") !important;
    background-size: 16px 12px !important;
}

[dir="rtl"] .form-select:not([multiple]):not([size]),
[dir="rtl"] select:not([multiple]):not([size]) {
    background-position: left 0.75rem center !important;
}

/* ==================== حقول الإدخال (Input Fields) ==================== */

/* محاذاة جميع أنواع الإدخال */
[dir="rtl"] .form-control,
[dir="rtl"] input.form-control,
[dir="rtl"] textarea.form-control,
[dir="rtl"] input[type="text"],
[dir="rtl"] input[type="email"],
[dir="rtl"] input[type="password"],
[dir="rtl"] input[type="number"],
[dir="rtl"] input[type="tel"],
[dir="rtl"] input[type="url"],
[dir="rtl"] input[type="search"],
[dir="rtl"] input[type="date"],
[dir="rtl"] input[type="time"],
[dir="rtl"] input[type="datetime-local"] {
    text-align: right !important;
    direction: rtl !important;
    padding-right: 0.75rem !important;
    padding-left: 0.75rem !important;
}

/* إصلاح Placeholder */
[dir="rtl"] ::placeholder {
    text-align: right !important;
    direction: rtl !important;
}

/* إصلاح Date Picker */
[dir="rtl"] input[type="date"]::-webkit-calendar-picker-indicator,
[dir="rtl"] input[type="time"]::-webkit-calendar-picker-indicator {
    margin-right: auto !important;
    margin-left: 0 !important;
}

/* ==================== تنسيق التقويم (Calendar Styling) ==================== */

/* توسيط اسم الشهر في رأس التقويم المنبثق */
input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer !important;
}

/* توسيط حقول التاريخ داخل الإدخال */
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-day-field,
input[type="date"]::-webkit-datetime-edit-year-field {
    text-align: center !important;
    padding: 0 4px !important;
}

/* تحسين عرض التقويم بشكل عام */
input[type="date"]::-webkit-datetime-edit-fields-wrapper {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 4px 8px !important;
}

input[type="date"]::-webkit-datetime-edit-text {
    text-align: center !important;
    padding: 0 2px !important;
}

/* RTL محدد للتقويم */
[dir="rtl"] input[type="date"]::-webkit-datetime-edit-fields-wrapper {
    justify-content: center !important;
    text-align: center !important;
}

[dir="rtl"] input[type="date"]::-webkit-datetime-edit-month-field,
[dir="rtl"] input[type="date"]::-webkit-datetime-edit-day-field,
[dir="rtl"] input[type="date"]::-webkit-datetime-edit-year-field {
    text-align: center !important;
}

/* توسيط اسم الشهر في هيدر التقويم المنبثق - كروم وايدج */
input[type="date"]::-webkit-inner-spin-button {
    display: none !important;
}

/* تنسيق إضافي للتقويم */
input[type="date"] {
    text-align: center !important;
    padding-left: 0.75rem !important;
    padding-right: 2.5rem !important;
}

[dir="rtl"] input[type="date"] {
    padding-right: 0.75rem !important;
    padding-left: 2.5rem !important;
}

/* ==================== العناوين والتسميات (Labels) ==================== */

[dir="rtl"] .form-label,
[dir="rtl"] label {
    text-align: right !important;
    display: block !important;
    margin-bottom: 0.5rem !important;
}

[dir="rtl"] .form-text {
    text-align: right !important;
}

/* ==================== مجموعات الإدخال (Input Groups) ==================== */

[dir="rtl"] .input-group .form-select,
[dir="rtl"] .input-group select {
    border-radius: 0 10px 10px 0 !important;
}

[dir="rtl"] .input-group .form-control,
[dir="rtl"] .input-group input {
    border-radius: 0 10px 10px 0 !important;
}

[dir="rtl"] .input-group .btn {
    border-radius: 10px 0 0 10px !important;
}

[dir="rtl"] .input-group > :not(:last-child) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    border-top-right-radius: 10px !important;
    border-bottom-right-radius: 10px !important;
}

[dir="rtl"] .input-group > :not(:first-child) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-top-left-radius: 10px !important;
    border-bottom-left-radius: 10px !important;
}

/* ==================== الأزرار (Buttons) ==================== */

[dir="rtl"] .btn {
    text-align: center !important;
}

/* الأيقونات في الأزرار */
[dir="rtl"] .btn i,
[dir="rtl"] .btn svg {
    margin-left: 0.5rem !important;
    margin-right: 0 !important;
}

[dir="ltr"] .btn i,
[dir="ltr"] .btn svg {
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
}

/* مجموعات الأزرار */
[dir="rtl"] .btn-group {
    flex-direction: row-reverse !important;
}

[dir="rtl"] .btn-group > .btn:not(:last-child) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

[dir="rtl"] .btn-group > .btn:not(:first-child) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

/* ==================== المودال (Modal) ==================== */

[dir="rtl"] .modal-header {
    text-align: right !important;
}

[dir="rtl"] .modal-header .modal-title {
    margin-right: 0 !important;
    margin-left: auto !important;
}

[dir="rtl"] .modal-header .btn-close {
    margin: 0 auto 0 0 !important;
}

[dir="rtl"] .modal-body {
    text-align: right !important;
}

[dir="rtl"] .modal-footer {
    justify-content: flex-start !important;
}

[dir="rtl"] .modal-footer .btn {
    margin-left: 0.5rem !important;
    margin-right: 0 !important;
}

/* ==================== الجداول (Tables) ==================== */

[dir="rtl"] table {
    text-align: right !important;
}

[dir="rtl"] th,
[dir="rtl"] td {
    text-align: right !important;
}

[dir="rtl"] .table-responsive {
    direction: rtl !important;
}

/* ==================== القوائم (Lists) ==================== */

[dir="rtl"] .list-group-item {
    text-align: right !important;
}

[dir="rtl"] ul,
[dir="rtl"] ol {
    padding-right: 2rem !important;
    padding-left: 0 !important;
}

/* ==================== البطاقات (Cards) ==================== */

[dir="rtl"] .card-title,
[dir="rtl"] .card-text,
[dir="rtl"] .card-body {
    text-align: right !important;
}

[dir="rtl"] .card-header {
    text-align: right !important;
}

/* ==================== التنبيهات (Alerts) ==================== */

[dir="rtl"] .alert {
    text-align: right !important;
}

[dir="rtl"] .alert .btn-close {
    margin-left: auto !important;
    margin-right: -0.5rem !important;
}

/* ==================== القوائم المنسدلة (Dropdowns) ==================== */

[dir="rtl"] .dropdown-menu {
    text-align: right !important;
    right: 0 !important;
    left: auto !important;
}

[dir="rtl"] .dropdown-item {
    text-align: right !important;
}

[dir="rtl"] .dropdown-toggle::after {
    margin-right: 0.255em !important;
    margin-left: 0 !important;
}

/* ==================== التنقل (Navigation) ==================== */

[dir="rtl"] .nav-tabs,
[dir="rtl"] .nav-pills {
    flex-direction: row-reverse !important;
}

[dir="rtl"] .breadcrumb {
    flex-direction: row-reverse !important;
}

[dir="rtl"] .pagination {
    flex-direction: row-reverse !important;
}

/* ==================== Checkboxes و Radio Buttons ==================== */

[dir="rtl"] .form-check {
    padding-right: 1.5em !important;
    padding-left: 0 !important;
    text-align: right !important;
}

[dir="rtl"] .form-check-input {
    margin-right: -1.5em !important;
    margin-left: 0 !important;
    float: right !important;
}

[dir="rtl"] .form-check-label {
    padding-right: 0.5em !important;
}

/* ==================== Switches ==================== */

[dir="rtl"] .form-switch .form-check-input {
    background-position: right center !important;
}

[dir="rtl"] .form-switch .form-check-input:checked {
    background-position: left center !important;
}

/* ==================== Badges ==================== */

[dir="rtl"] .badge {
    text-align: center !important;
}

/* ==================== Progress Bars ==================== */

[dir="rtl"] .progress {
    direction: ltr !important;
}

/* ==================== Tooltips و Popovers ==================== */

[dir="rtl"] .tooltip-inner {
    text-align: center !important;
}

[dir="rtl"] .popover-body {
    text-align: right !important;
}

[dir="rtl"] .popover-header {
    text-align: right !important;
}

/* ==================== Forms Floating Labels ==================== */

[dir="rtl"] .form-floating > .form-control,
[dir="rtl"] .form-floating > .form-select {
    text-align: right !important;
}

[dir="rtl"] .form-floating > label {
    right: 0 !important;
    left: auto !important;
    transform-origin: 100% 0 !important;
}

/* ==================== تحسينات للموبايل ==================== */

@media (max-width: 768px) {
    /* منع الزوم التلقائي في iOS */
    [dir="rtl"] .form-select,
    [dir="rtl"] select,
    [dir="rtl"] .form-control,
    [dir="rtl"] input,
    [dir="rtl"] textarea {
        font-size: 16px !important;
    }
    
    /* تحسين عرض الأزرار */
    [dir="rtl"] .btn {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* تحسين عرض المودال */
    [dir="rtl"] .modal-dialog {
        margin: 0.5rem !important;
    }
}

/* ==================== تحسينات عامة للأداء ==================== */

/* ضمان وراثة الخطوط */
select, 
input, 
textarea, 
button {
    font-family: inherit !important;
}

/* منع تداخل النصوص */
* {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
}

/* تحسين وضوح النصوص */
* {
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* تحسين Focus States */
.form-select:focus,
select:focus,
.form-control:focus,
input:focus,
textarea:focus {
    border-color: #667eea !important;
    box-shadow: 0 0 0 0.25rem rgba(102, 126, 234, 0.25) !important;
    outline: none !important;
    z-index: 3 !important;
}

/* ضمان عمل Box-sizing */
*,
*::before,
*::after {
    box-sizing: border-box !important;
}

/* منع مشاكل z-index */
.form-select,
select,
.form-control,
input,
textarea,
button {
    position: relative !important;
    z-index: 1 !important;
}

/* تحسين عرض النصوص الطويلة في القوائم */
select option {
    white-space: normal !important;
    word-wrap: break-word !important;
    padding: 0.5rem !important;
}

/* إزالة الأنماط الافتراضية للمتصفح */
select,
input,
textarea {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
}

/* إعادة إضافة السهم للقوائم المنسدلة فقط */
select:not([multiple]):not([size]),
.form-select:not([multiple]):not([size]) {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-size: 16px 12px !important;
}

/* ==================== إصلاحات خاصة بـ Bootstrap 5 ==================== */

/* إصلاح Accordion في RTL */
[dir="rtl"] .accordion-button {
    text-align: right !important;
}

[dir="rtl"] .accordion-button::after {
    margin-right: auto !important;
    margin-left: 0 !important;
}

/* إصلاح Offcanvas في RTL */
[dir="rtl"] .offcanvas-start {
    right: 0 !important;
    left: auto !important;
}

[dir="rtl"] .offcanvas-end {
    left: 0 !important;
    right: auto !important;
}

/* إصلاح Toast في RTL */
[dir="rtl"] .toast {
    text-align: right !important;
}

[dir="rtl"] .toast-header .btn-close {
    margin-left: auto !important;
    margin-right: -0.375rem !important;
}

/* ==================== تحسينات نهائية ==================== */

/* ضمان عمل التحديدات المتعددة */
select[multiple],
.form-select[multiple] {
    padding: 0.5rem !important;
}

select[multiple] option {
    padding: 0.5rem !important;
}

/* تحسين Disabled State */
.form-select:disabled,
select:disabled,
.form-control:disabled,
input:disabled,
textarea:disabled {
    background-color: #e9ecef !important;
    opacity: 0.6 !important;
}

/* تحسين Read-only State */
.form-select[readonly],
select[readonly],
.form-control[readonly],
input[readonly],
textarea[readonly] {
    background-color: #f8f9fa !important;
}

/* إصلاح Invalid State */
.form-select.is-invalid,
select.is-invalid,
.form-control.is-invalid,
input.is-invalid,
textarea.is-invalid {
    border-color: #dc3545 !important;
}

/* إصلاح Valid State */
.form-select.is-valid,
select.is-valid,
.form-control.is-valid,
input.is-valid,
textarea.is-valid {
    border-color: #198754 !important;
}
