/* =====================================================================
   RTL (Right-to-Left) CSS Support for Arabic Language
   =====================================================================
   This file contains RTL-specific styles that complement Bootstrap RTL
   and ensure proper rendering for Arabic language content
   ===================================================================== */

/* RTL Document Root */
html[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

/* RTL Body */
html[dir="rtl"] body {
    font-family: 'Cairo', 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
    direction: rtl;
    text-align: right;
}

/* RTL Typography */
html[dir="rtl"] h1,
html[dir="rtl"] h2,
html[dir="rtl"] h3,
html[dir="rtl"] h4,
html[dir="rtl"] h5,
html[dir="rtl"] h6 {
    text-align: right;
}

html[dir="rtl"] p {
    text-align: right;
}

/* RTL Navigation */
html[dir="rtl"] .navbar-nav {
    flex-direction: row-reverse;
}

html[dir="rtl"] .navbar-nav .nav-item {
    margin-left: 0;
    margin-right: 1rem;
}

/* Public header navbar: move brand to the right and let nav fill remaining space */
html[dir="rtl"] .header-modern .navbar .container {
    flex-direction: row-reverse;
}

html[dir="rtl"] .header-modern .navbar .navbar-collapse {
    justify-content: space-between;
}

html[dir="rtl"] .header-modern .navbar .navbar-brand {
    margin-left: 0;
    margin-right: 0;
}

html[dir="rtl"] .header-modern .navbar .me-auto {
    margin-left: 0 !important;
    margin-right: auto !important;
}

html[dir="rtl"] .header-modern .navbar .ms-auto {
    margin-right: 0 !important;
    margin-left: auto !important;
}

html[dir="rtl"] .header-modern .navbar-toggler {
    margin-left: 0;
    margin-right: auto; /* keep toggler near the right edge in RTL */
}

/* Ensure header navbar spans full width in RTL */
    html[dir="rtl"] .header-modern .navbar .container {
        /*max-width: 100% !important;*/
        width: 100% !important;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Force explicit RTL direction within header/nav elements */
    html[dir="rtl"] .navbar {
        padding: 1rem 0;
        transition: all 0.2s ease;
        width: 100%;
    }

    /* Force explicit RTL direction within header/nav elements */
    html[dir="rtl"] .header-modern,
    html[dir="rtl"] .header-modern .navbar,
    html[dir="rtl"] .header-modern .navbar .navbar-collapse,
    html[dir="rtl"] .header-modern .navbar .navbar-nav {
        direction: rtl;
        text-align: right;
    }

/* Align nav links and dropdowns to RTL */
html[dir="rtl"] .header-modern .navbar .navbar-nav .nav-link {
    text-align: right;
}

html[dir="rtl"] .header-modern .dropdown-menu {
    right: 0;
    left: auto;
    text-align: right;
}

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

html[dir="rtl"] .dropdown-menu {
    text-align: right;
}

/* RTL Buttons */
html[dir="rtl"] .btn {
    text-align: center;
}

html[dir="rtl"] .btn i {
    margin-left: 0.5rem;
    margin-right: 0;
}

html[dir="rtl"] .btn i.fas.fa-arrow-left::before,
html[dir="rtl"] .btn i.fas.fa-arrow-right::before {
    transform: scaleX(-1);
}

/* RTL Forms */
html[dir="rtl"] .form-control {
    text-align: right;
}

html[dir="rtl"] .form-select {
    text-align: right;
    padding-right: 0.75rem;
    padding-left: 2.25rem;
}

html[dir="rtl"] .form-check {
    padding-left: 0;
    padding-right: 1.5em;
}

html[dir="rtl"] .form-check-input {
    margin-left: 0;
    margin-right: -1.5em;
}

html[dir="rtl"] .form-check-label {
    padding-right: 0.5rem;
}

html[dir="rtl"] .input-group > .form-control:not(:last-child),
html[dir="rtl"] .input-group > .form-select:not(:last-child) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: var(--bs-border-radius);
    border-bottom-right-radius: var(--bs-border-radius);
}

html[dir="rtl"] .input-group > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-left: 0;
    margin-right: -1px;
    border-top-left-radius: var(--bs-border-radius);
    border-bottom-left-radius: var(--bs-border-radius);
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

html[dir="rtl"] .input-group-text {
    border-left: 0;
    border-right: var(--bs-border-width) solid var(--bs-border-color);
}

/* RTL Tables */
html[dir="rtl"] .table {
    text-align: right;
}

html[dir="rtl"] .table th {
    text-align: right;
}

html[dir="rtl"] .table td {
    text-align: right;
}

/* RTL Cards */
html[dir="rtl"] .card {
    text-align: right;
}

html[dir="rtl"] .card-header {
    text-align: right;
}

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

html[dir="rtl"] .card-footer {
    text-align: right;
}

/* RTL Lists */
html[dir="rtl"] ul {
    padding-right: 1.5rem;
    padding-left: 0;
}

html[dir="rtl"] ol {
    padding-right: 1.5rem;
    padding-left: 0;
}

/* RTL Icons Alignment */
html[dir="rtl"] .fas,
html[dir="rtl"] .far,
html[dir="rtl"] .fab,
html[dir="rtl"] .fa {
    display: inline-block;
}

html[dir="rtl"] .me-1,
html[dir="rtl"] .me-2,
html[dir="rtl"] .me-3,
html[dir="rtl"] .me-4,
html[dir="rtl"] .me-5 {
    margin-left: initial !important;
    margin-right: initial !important;
}

html[dir="rtl"] .ms-1,
html[dir="rtl"] .ms-2,
html[dir="rtl"] .ms-3,
html[dir="rtl"] .ms-4,
html[dir="rtl"] .ms-5 {
    margin-right: initial !important;
    margin-left: initial !important;
}

/* RTL Utility Classes Override */
html[dir="rtl"] .text-start {
    text-align: right !important;
}

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

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

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

/* RTL Sidebar Adjustments */
html[dir="rtl"] .student-sidebar,
html[dir="rtl"] .admin-sidebar {
    left: auto;
    right: 0;
    border-left: 1px solid var(--sidebar-border);
    border-right: none;
}

html[dir="rtl"] .student-layout .main-content,
html[dir="rtl"] .admin-layout .main-content {
    margin-left: 0;
    margin-right: 280px;
}

html[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    border-left: 1px solid var(--sidebar-border);
    border-right: none;
}

/* RTL Sidebar Navigation */
html[dir="rtl"] .sidebar-nav .nav-link {
    padding-right: 1.25rem !important;
    padding-left: 0.875rem !important;
}

html[dir="rtl"] .sidebar-nav .nav-link i {
    margin-right: 0;
    margin-left: 0.75rem;
}

html[dir="rtl"] .sidebar-nav .nav-link:hover,
html[dir="rtl"] .sidebar-nav .nav-link.active {
    transform: translateX(-8px);
}

/* RTL Modal */
html[dir="rtl"] .modal-header {
    flex-direction: row-reverse;
}

html[dir="rtl"] .modal-header .btn-close {
    margin-left: 0;
    margin-right: auto;
}

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

html[dir="rtl"] .modal-footer > :not(:first-child) {
    margin-left: 0;
    margin-right: 0.25rem;
}

html[dir="rtl"] .modal-footer > :not(:last-child) {
    margin-right: 0;
    margin-left: 0.25rem;
}

/* RTL Alert */
html[dir="rtl"] .alert {
    text-align: right;
}

html[dir="rtl"] .alert-dismissible {
    padding-right: 3rem;
    padding-left: 1rem;
}

html[dir="rtl"] .alert-dismissible .btn-close {
    right: auto;
    left: 0;
}

/* RTL Breadcrumb */
html[dir="rtl"] .breadcrumb {
    padding-right: 0;
    padding-left: 0;
}

html[dir="rtl"] .breadcrumb-item + .breadcrumb-item::before {
    padding-left: 0;
    padding-right: var(--bs-breadcrumb-item-padding-x);
    float: right;
    content: var(--bs-breadcrumb-divider, "/");
}

/* RTL Pagination */
html[dir="rtl"] .pagination {
    padding-right: 0;
    padding-left: 0;
}

html[dir="rtl"] .page-link {
    margin-left: 0;
    margin-right: -1px;
}

/* RTL Dropdown */
html[dir="rtl"] .dropdown-toggle::after {
    margin-left: 0;
    margin-right: 0.5em;
}

html[dir="rtl"] .dropdown-menu {
    left: auto;
    right: 0;
    text-align: right;
}

html[dir="rtl"] .dropdown-item {
    text-align: right;
}

html[dir="rtl"] .dropdown-item i {
    margin-left: 0.5rem;
    margin-right: 0;
}

/* RTL Language Switcher */
html[dir="rtl"] .language-switcher .dropdown-toggle {
    text-align: center;
}

html[dir="rtl"] .language-switcher .dropdown-menu {
    text-align: right;
}

/* RTL Badge */
html[dir="rtl"] .badge {
    text-align: center;
}

/* RTL Exam Pages Specific */
html[dir="rtl"] .exam-header {
    text-align: right;
}

html[dir="rtl"] .exam-title {
    text-align: right;
}

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

html[dir="rtl"] .question-text {
    text-align: right;
}

html[dir="rtl"] .option-text {
    text-align: right;
}

html[dir="rtl"] .result-header {
    text-align: right;
}

html[dir="rtl"] .result-title {
    text-align: right;
}

/* RTL Floating Labels */
html[dir="rtl"] .form-floating > label {
    right: 0;
    left: auto;
    padding-right: 0.75rem;
    padding-left: 0;
}

html[dir="rtl"] .form-floating > .form-control:focus ~ label,
html[dir="rtl"] .form-floating > .form-control:not(:placeholder-shown) ~ label,
html[dir="rtl"] .form-floating > .form-select ~ label {
    transform: scale(0.85) translateY(-0.5rem) translateX(-0.15rem);
    right: 0;
    left: auto;
}

/* RTL Tooltips and Popovers */
html[dir="rtl"] .tooltip {
    text-align: right;
}

html[dir="rtl"] .popover {
    text-align: right;
}

/* RTL Progress Bars */
html[dir="rtl"] .progress {
    direction: ltr; /* Progress bars should remain LTR for visual consistency */
}

/* RTL Charts - Keep charts LTR for numerical consistency */
html[dir="rtl"] .chart-container {
    direction: ltr;
}

/* RTL Fixed Positioning */
html[dir="rtl"] .fixed-top {
    left: auto;
    right: 0;
}

html[dir="rtl"] .fixed-bottom {
    left: auto;
    right: 0;
}

/* RTL Float Utilities */
html[dir="rtl"] .float-start {
    float: right !important;
}

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

/* RTL Spacing Utilities - Swap margins */
    html[dir="rtl"] .me-1 {
        margin-right: 0.25rem !important;
        margin-left: 0.25rem !important;
    }
html[dir="rtl"] .me-2 { margin-right: 0.5rem !important; margin-left: 1rem !important; }
    html[dir="rtl"] .me-3 {
        margin-right: 0 !important;
        margin-left: 1rem !important;
    }
html[dir="rtl"] .me-4 { margin-right: 1.5rem !important; margin-left: 0 !important; }
html[dir="rtl"] .me-5 { margin-right: 3rem !important; margin-left: 0 !important; }

html[dir="rtl"] .ms-1 { margin-left: 0.25rem !important; margin-right: 0 !important; }
html[dir="rtl"] .ms-2 { margin-left: 0.5rem !important; margin-right: 0 !important; }
html[dir="rtl"] .ms-3 { margin-left: 1rem !important; margin-right: 0 !important; }
html[dir="rtl"] .ms-4 { margin-left: 1.5rem !important; margin-right: 0 !important; }
html[dir="rtl"] .ms-5 { margin-left: 3rem !important; margin-right: 0 !important; }

html[dir="rtl"] .pe-1 { padding-right: 0.25rem !important; padding-left: 0 !important; }
html[dir="rtl"] .pe-2 { padding-right: 0.5rem !important; padding-left: 0 !important; }
html[dir="rtl"] .pe-3 { padding-right: 1rem !important; padding-left: 0 !important; }
html[dir="rtl"] .pe-4 { padding-right: 1.5rem !important; padding-left: 0 !important; }
html[dir="rtl"] .pe-5 { padding-right: 3rem !important; padding-left: 0 !important; }

html[dir="rtl"] .ps-1 { padding-left: 0.25rem !important; padding-right: 0 !important; }
html[dir="rtl"] .ps-2 { padding-left: 0.5rem !important; padding-right: 0 !important; }
html[dir="rtl"] .ps-3 { padding-left: 1rem !important; padding-right: 0 !important; }
html[dir="rtl"] .ps-4 { padding-left: 1.5rem !important; padding-right: 0 !important; }
html[dir="rtl"] .ps-5 { padding-left: 3rem !important; padding-right: 0 !important; }

/* RTL Responsive Sidebar */
@media (max-width: 991.98px) {
    html[dir="rtl"] .student-sidebar,
    html[dir="rtl"] .admin-sidebar,
    html[dir="rtl"] .sidebar {
        transform: translateX(100%);
    }
    
    html[dir="rtl"] .sidebar.show {
        transform: translateX(0);
    }
    
    html[dir="rtl"] .student-layout .main-content,
    html[dir="rtl"] .admin-layout .main-content {
        margin-right: 0;
    }
}

/* RTL Specific Adjustments for Custom Components */
html[dir="rtl"] .brand-text {
    text-align: right;
}

html[dir="rtl"] .nav-link i {
    margin-left: 0.5rem;
    margin-right: 0;
}

html[dir="rtl"] .btn i {
    margin-left: 0.5rem;
    margin-right: 0;
}

html[dir="rtl"] .btn i:first-child {
    margin-left: 0;
    margin-right: 0.5rem;
}

/* RTL Footer */
html[dir="rtl"] .footer-links {
    text-align: right;
}

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

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

html[dir="rtl"] .contact-info .contact-item i {
    margin-left: 0.5rem;
    margin-right: 0;
}

/* RTL Social Links */
html[dir="rtl"] .social-links {
    flex-direction: row-reverse;
}

/* RTL Stats Cards */
html[dir="rtl"] .stat-card {
    text-align: center;
}

/* RTL Dashboard Cards */
html[dir="rtl"] .dashboard-stats {
    text-align: center;
}

/* RTL Table Actions */
html[dir="rtl"] .table-actions {
    text-align: right;
}

html[dir="rtl"] .table-actions .btn {
    margin-left: 0.25rem;
    margin-right: 0;
}

html[dir="rtl"] .table-actions .btn:last-child {
    margin-left: 0;
}

/* RTL Form Groups */
html[dir="rtl"] .form-group {
    text-align: right;
}

html[dir="rtl"] .form-label {
    text-align: right;
}

/* RTL Help Text */
html[dir="rtl"] .form-text {
    text-align: right;
}

/* RTL Validation Messages */
html[dir="rtl"] .invalid-feedback,
html[dir="rtl"] .valid-feedback {
    text-align: right;
}

/* RTL Custom Components - Sidebar Header */
html[dir="rtl"] .sidebar-header {
    text-align: right;
}

html[dir="rtl"] .sidebar-user {
    text-align: right;
}

html[dir="rtl"] .sidebar-footer {
    text-align: right;
}

/* RTL Top Bar */
html[dir="rtl"] .top-bar {
    text-align: right;
}

html[dir="rtl"] .top-bar h4 {
    text-align: right;
}

/* RTL Content Wrapper */
html[dir="rtl"] .content-wrapper {
    text-align: right;
}

/* RTL Exam Navigation */
html[dir="rtl"] .exam-actions {
    flex-direction: row-reverse;
}

html[dir="rtl"] .exam-actions .btn-prev,
html[dir="rtl"] .exam-actions .btn-next {
    order: reverse;
}

/* RTL Question Navigation */
html[dir="rtl"] .question-grid {
    direction: ltr; /* Keep question numbers in logical order */
}

/* RTL Option Items */
html[dir="rtl"] .option-item {
    flex-direction: row-reverse;
    text-align: right;
}

html[dir="rtl"] .option-letter {
    margin-left: 1rem;
    margin-right: 0;
}

/* RTL Score Display */
html[dir="rtl"] .score-display {
    flex-direction: row-reverse;
}

html[dir="rtl"] .result-status {
    text-align: right;
}

/* RTL Performance Sidebar */
html[dir="rtl"] .performance-sidebar {
    text-align: right;
}

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

/* RTL Action Buttons */
html[dir="rtl"] .action-buttons {
    text-align: right;
}

/* RTL Filter Row */
html[dir="rtl"] .filter-row {
    flex-direction: row-reverse;
    justify-content: flex-end;
}

/* RTL Counter Chips */
html[dir="rtl"] .counter-chip {
    text-align: center;
}

/* RTL Legend */
html[dir="rtl"] .legend {
    flex-direction: row-reverse;
    justify-content: flex-end;
}

/* RTL Progress Section */
html[dir="rtl"] .progress-section {
    text-align: right;
}

html[dir="rtl"] .progress-text {
    text-align: center; /* Center progress percentage */
}

/* RTL Exam Header Info */
html[dir="rtl"] .exam-stats {
    flex-direction: row-reverse;
}

html[dir="rtl"] .stat-item {
    text-align: center;
}

/* RTL Timer Container */
html[dir="rtl"] .timer-container {
    text-align: center; /* Keep timer centered */
}

/* RTL Navigation Sidebar */
html[dir="rtl"] .navigation-sidebar {
    text-align: right;
}

html[dir="rtl"] .nav-header {
    text-align: right;
}

html[dir="rtl"] .nav-footer {
    text-align: right;
}

html[dir="rtl"] .navigation-title {
    text-align: center; /* Keep title centered */
}

/* RTL Warning Modal */
html[dir="rtl"] .warning-content {
    text-align: right;
}

html[dir="rtl"] .warning-icon {
    text-align: center;
}

html[dir="rtl"] .warning-title {
    text-align: right;
}

html[dir="rtl"] .warning-text {
    text-align: right;
}

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

/* RTL Question Item */
html[dir="rtl"] .question-item {
    text-align: right;
}

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

html[dir="rtl"] .question-text {
    text-align: right;
}

/* RTL Options List */
html[dir="rtl"] .options-list {
    text-align: right;
}

/* RTL Explanation */
html[dir="rtl"] .explanation {
    text-align: right;
    border-right: 4px solid #1E3A8A;
    border-left: none;
}

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

html[dir="rtl"] .explanation-text {
    text-align: right;
}

/* RTL Correct Answer */
html[dir="rtl"] .correct-answer {
    flex-direction: row-reverse;
}

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

/* RTL Chapter Chips */
html[dir="rtl"] .chapters-chips {
    flex-direction: row-reverse;
    justify-content: flex-end;
}

/* RTL Empty States */
html[dir="rtl"] .empty-state {
    text-align: center;
}

/* RTL Loading States */
html[dir="rtl"] .loading-spinner {
    text-align: center;
}

/* RTL Search Inputs */
html[dir="rtl"] .search-input {
    text-align: right;
    padding-right: 2.5rem;
    padding-left: 0.75rem;
}

html[dir="rtl"] .search-input + .search-icon {
    right: auto;
    left: 0.75rem;
}

/* RTL Date Pickers */
html[dir="rtl"] .datepicker {
    direction: rtl;
    text-align: right;
}

/* RTL Custom Scrollbars */
html[dir="rtl"] ::-webkit-scrollbar {
    direction: rtl;
}

/* RTL Print Styles */
@media print {
    html[dir="rtl"] {
        direction: rtl;
    }
    
    html[dir="rtl"] body {
        direction: rtl;
        text-align: right;
    }
}

/* RTL Animation Adjustments */
html[dir="rtl"] @keyframes slideIn {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

html[dir="rtl"] @keyframes slideOut {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(100%);
    }
}

/* RTL Mobile Menu */
html[dir="rtl"] .mobile-menu {
    right: -100%;
    left: auto;
}

html[dir="rtl"] .mobile-menu.open {
    right: 0;
    left: auto;
}

/* RTL Overlay */
html[dir="rtl"] .sidebar-overlay {
    left: auto;
    right: 0;
}

/* RTL Toggle Button */
html[dir="rtl"] .sidebar-toggle {
    left: auto;
    right: 1rem;
}

/* Ensure Arabic text renders properly */
html[dir="rtl"] * {
    font-variant-ligatures: none;
}

html[dir="rtl"] body {
    font-feature-settings: "liga" off;
    -webkit-font-feature-settings: "liga" off;
    -moz-font-feature-settings: "liga" off;
}

