/* RTL (Right-to-Left) Styles for Persian Language */

/* Global RTL Adjustments */
[dir="rtl"] {
    text-align: right;
}

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

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

/* Navigation RTL */
[dir="rtl"] .navbar-brand {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .navbar-toggler {
    margin-left: 0;
    margin-right: auto;
}

/* Hero Section RTL */
[dir="rtl"] .hero-section .row {
    flex-direction: row-reverse;
}

[dir="rtl"] .hero-section .col-lg-6:first-child {
    text-align: right;
}

/* Search Form RTL */
[dir="rtl"] .search-form .input-group-text {
    border-left: 0;
    border-right: 1px solid #ced4da;
}

[dir="rtl"] .search-form .form-control {
    border-left: 1px solid #ced4da;
    border-right: 0;
}

[dir="rtl"] .search-form .form-control:focus {
    border-left-color: var(--primary-color);
    border-right-color: #ced4da;
}

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

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

[dir="rtl"] .featured-badge {
    left: 1rem;
    right: auto;
    margin-top: 0.25rem;
}

/* Extra top padding on card body in RTL when badge exists */
[dir="rtl"] .product-card .featured-badge ~ .card-body {
    padding-top: 3rem;
}

/* Product Meta RTL */
[dir="rtl"] .product-meta .badge {
    margin-left: 0;
    margin-right: 0.5rem;
}

/* Info Items RTL */
[dir="rtl"] .info-item {
    text-align: right;
}

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

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

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

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

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

/* Pagination RTL */
[dir="rtl"] .pagination {
    justify-content: center;
}

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

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

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

[dir="rtl"] .form-check-input {
    margin-left: 0;
    margin-right: 0.5rem;
}

/* Alerts RTL */
[dir="rtl"] .alert {
    border-right: 4px solid;
    border-left: none;
}

[dir="rtl"] .alert-success {
    border-right-color: var(--success-color);
}

[dir="rtl"] .alert-danger {
    border-right-color: var(--danger-color);
}

[dir="rtl"] .alert-info {
    border-right-color: var(--info-color);
}

/* Breadcrumb RTL */
[dir="rtl"] .breadcrumb {
    flex-direction: row-reverse;
}

[dir="rtl"] .breadcrumb-item + .breadcrumb-item::before {
    content: "\\";
    transform: scaleX(-1);
}

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

/* Hide default dropdown arrow completely */
[dir="rtl"] .dropdown-toggle::after {
    display: none !important;
    content: none !important;
}

/* Create custom arrow on the LEFT side */
[dir="rtl"] .dropdown-toggle {
    position: relative;
}

[dir="rtl"] .dropdown-toggle::before {
    content: "▼" !important;
    position: absolute !important;
    left: 8px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    font-size: 0.8em !important;
    color: inherit !important;
    pointer-events: none !important;
    z-index: 1 !important;
}

/* Fix dropdown arrow for navbar dropdowns */
[dir="rtl"] .navbar-nav .dropdown-toggle::after {
    display: none !important;
    content: none !important;
}

[dir="rtl"] .navbar-nav .dropdown-toggle::before {
    content: "▼" !important;
    position: absolute !important;
    left: 8px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    font-size: 0.8em !important;
    color: inherit !important;
    pointer-events: none !important;
    z-index: 1 !important;
}

/* Fix dropdown arrow spacing and positioning */
[dir="rtl"] .dropdown-toggle {
    padding-right: 0.5rem;
    padding-left: 2rem; /* More space for arrow on left */
    display: flex;
    align-items: center;
    flex-direction: row;
    position: relative;
}

/* Ensure dropdown items are properly aligned */
[dir="rtl"] .dropdown-item {
    text-align: right;
    padding-right: 1rem;
    padding-left: 1rem;
}

/* Fix dropdown menu positioning */
[dir="rtl"] .dropdown-menu {
    right: 0;
    left: auto;
    min-width: 10rem;
    padding: 0.5rem 0;
    margin: 0.125rem 0 0;
    text-align: right;
}

/* Fix dropdown menu arrow positioning */
[dir="rtl"] .dropdown-menu::before {
    right: 1rem;
    left: auto;
}

[dir="rtl"] .dropdown-menu::after {
    right: 1rem;
    left: auto;
}

/* Additional dropdown fixes for better spacing */
[dir="rtl"] .navbar-nav .dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Fix dropdown toggle with icons */
[dir="rtl"] .dropdown-toggle i {
    order: 2;
    margin-left: 0.5rem;
    margin-right: 0;
}

/* Ensure proper spacing for dropdown text */
[dir="rtl"] .dropdown-toggle span,
[dir="rtl"] .dropdown-toggle:not(:empty) {
    order: 3;
    margin-left: 0;
    margin-right: 0.5rem;
}

/* Fix dropdown menu item hover */
[dir="rtl"] .dropdown-item:hover,
[dir="rtl"] .dropdown-item:focus {
    background-color: #f8f9fa;
    color: #16181b;
}

/* Fix dropdown divider */
[dir="rtl"] .dropdown-divider {
    margin: 0.5rem 0;
    border-top: 1px solid #dee2e6;
}

/* Navigation RTL - Complete navbar overhaul for proper RTL */
[dir="rtl"] .navbar {
    direction: rtl !important;
}

[dir="rtl"] .navbar .container {
    flex-direction: row !important;
    justify-content: flex-start !important;
    position: relative !important;
}

/* Brand positioning - should be on the RIGHT in RTL */
[dir="rtl"] .navbar-brand {
    order: 1 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    text-align: right !important;
    float: right !important;
    position: absolute !important;
    right: 0 !important;
    left: auto !important;
}

/* Navigation menu - should flow from RIGHT to LEFT */
[dir="rtl"] .navbar-nav {
    flex-direction: row !important;
    order: 2 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-right: 200px !important; /* Make space for brand on right */
}

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

[dir="rtl"] .navbar-nav .nav-item:last-child {
    margin-right: 0 !important;
}

/* Toggler positioning */
[dir="rtl"] .navbar-toggler {
    order: 3 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Navbar collapse and links */
[dir="rtl"] .navbar-collapse {
    text-align: right;
    order: 1 !important;
}

[dir="rtl"] .navbar-nav .nav-link {
    text-align: right;
    padding-right: 0.5rem;
    padding-left: 0.5rem;
}

/* Override Bootstrap's me-auto class for RTL */
[dir="rtl"] .navbar-nav.me-auto {
    margin-left: 0 !important;
    margin-right: auto !important;
}

/* Ensure proper navbar structure */
[dir="rtl"] .navbar .container {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
}

/* Mobile navbar adjustments */
@media (max-width: 991.98px) {
    [dir="rtl"] .navbar-collapse {
        order: 4 !important;
        width: 100% !important;
    }
    
    [dir="rtl"] .navbar-nav {
        flex-direction: column !important;
        width: 100% !important;
    }
    
    [dir="rtl"] .navbar-nav .nav-item {
        margin-right: 0 !important;
        margin-bottom: 0.5rem !important;
    }
}

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

/* Admin Panel RTL */
[dir="rtl"] .sidebar {
    right: 0;
    left: auto;
}

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

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

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

/* Admin Content RTL */
[dir="rtl"] .admin-content {
    margin-right: 0;
    margin-left: auto;
}

/* Statistics Cards RTL */
[dir="rtl"] .stat-card .d-flex {
    flex-direction: row-reverse;
}

/* Footer RTL */
[dir="rtl"] footer .text-md-end {
    text-align: left !important;
}

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

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

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

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

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

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

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

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

/* Border RTL */
[dir="rtl"] .border-start { border-right: 1px solid #dee2e6 !important; border-left: none !important; }
[dir="rtl"] .border-end { border-left: 1px solid #dee2e6 !important; border-right: none !important; }

/* Custom RTL Font - IRANYekanX for Persian */
[dir="rtl"] body {
    font-family: 'IRANYekanX', 'Tahoma', 'Arial', sans-serif;
}

[dir="rtl"] .display-1,
[dir="rtl"] .display-2,
[dir="rtl"] .display-3,
[dir="rtl"] .display-4,
[dir="rtl"] .display-5,
[dir="rtl"] .display-6 {
    font-family: 'IRANYekanX', 'Tahoma', 'Arial', sans-serif;
}

/* Apply IRANYekanX to all RTL elements, excluding icons */
[dir="rtl"] *:not(.fas):not(.far):not(.fab):not(.fal):not(.fad):not(.fa):not([class*="fa-"]):not(.icon):not([class*="icon-"]):not(.material-icons):not([class*="glyphicon"]) {
    font-family: 'IRANYekanX', 'Tahoma', 'Arial', sans-serif !important;
}

/* Ensure icon fonts work properly in RTL */
[dir="rtl"] .fas,
[dir="rtl"] .far,
[dir="rtl"] .fab,
[dir="rtl"] .fal,
[dir="rtl"] .fad,
[dir="rtl"] .fa,
[dir="rtl"] [class*="fa-"],
[dir="rtl"] .icon,
[dir="rtl"] [class*="icon-"],
[dir="rtl"] .material-icons,
[dir="rtl"] [class*="glyphicon"] {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands", "Font Awesome 5 Free", "Font Awesome 5 Brands", "FontAwesome", sans-serif !important;
}

/* Additional icon font support */
[dir="rtl"] i[class*="fa"],
[dir="rtl"] span[class*="fa"],
[dir="rtl"] .btn i,
[dir="rtl"] .navbar-brand i,
[dir="rtl"] .card-header i,
[dir="rtl"] .list-group-item i {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands", "Font Awesome 5 Free", "Font Awesome 5 Brands", "FontAwesome", sans-serif !important;
}

/* Ensure icons maintain their size and alignment */
[dir="rtl"] .fas,
[dir="rtl"] .far,
[dir="rtl"] .fab,
[dir="rtl"] .fal,
[dir="rtl"] .fad,
[dir="rtl"] .fa,
[dir="rtl"] [class*="fa-"] {
    font-style: normal !important;
    font-variant: normal !important;
    text-rendering: auto !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* Handle Bootstrap icon classes */
[dir="rtl"] .bi,
[dir="rtl"] [class*="bi-"] {
    font-family: "bootstrap-icons", sans-serif !important;
}

/* Handle other common icon libraries */
[dir="rtl"] .iconify,
[dir="rtl"] [class*="iconify-"] {
    font-family: "iconify", sans-serif !important;
}

/* Ensure icons don't inherit text direction issues */
[dir="rtl"] i,
[dir="rtl"] .icon,
[dir="rtl"] [class*="fa-"],
[dir="rtl"] [class*="icon-"] {
    direction: ltr !important;
    unicode-bidi: normal !important;
}

/* Persian Number Formatting */
[dir="rtl"] .persian-numbers {
    font-family: 'Tahoma', 'Arial', sans-serif;
    direction: ltr;
    display: inline-block;
}

/* RTL Animation Adjustments */
[dir="rtl"] .fade-in-up {
    animation: fadeInUpRTL 0.6s ease-out;
}

@keyframes fadeInUpRTL {
    from {
        opacity: 0;
        transform: translateY(30px) scaleX(-1);
    }
    to {
        opacity: 1;
        transform: translateY(0) scaleX(-1);
    }
}

/* RTL Responsive Adjustments */
@media (max-width: 768px) {
    [dir="rtl"] .hero-section .row {
        flex-direction: column;
    }
    
    [dir="rtl"] .hero-section .col-lg-6:first-child {
        text-align: center;
    }
}

@media (max-width: 576px) {
    [dir="rtl"] .search-form {
        text-align: right;
    }
    
    [dir="rtl"] .product-card .card-body {
        text-align: right;
    }
}
/* Footer RTL */
[dir="rtl"] footer .container {
    text-align: center;
}

[dir="rtl"] footer .footer-links a {
    margin: 0 1rem;
}

[dir="rtl"] footer .footer-attribution {
    text-align: center;
}

/* Additional RTL navbar fixes */
[dir="rtl"] .navbar .container-fluid {
    flex-direction: row !important;
    justify-content: space-between !important;
}

[dir="rtl"] .navbar .navbar-nav:first-child {
    margin-left: 0 !important;
    margin-right: auto !important;
}

[dir="rtl"] .navbar .navbar-nav:last-child {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Force brand to be on the right side */
[dir="rtl"] .navbar-brand {
    float: right !important;
    margin-left: 0 !important;
    margin-right: 1rem !important;
    position: absolute !important;
    right: 15px !important;
    left: auto !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

/* CSS Updated */

/* Form selects: move caret/arrow to the LEFT in RTL */
[dir="rtl"] .form-select {
    background-position: left .75rem center !important;
    padding-left: 2.25rem !important;
    padding-right: .75rem !important;
    text-align: right;
}

/* Support for size variants */
[dir="rtl"] .form-select.form-select-sm {
    background-position: left .5rem center !important;
    padding-left: 2rem !important;
}

[dir="rtl"] .form-select.form-select-lg {
    background-position: left 1rem center !important;
    padding-left: 2.5rem !important;
}
