Arabic RTL Support for Django Admin

/* Set RTL direction for the entire admin */
html[lang="ar"],
html[dir="rtl"] {
    direction: rtl;
}

/* Fix for Jazzmin admin interface */
body {
    direction: rtl;
    text-align: right;
}

/* Sidebar adjustments for RTL */
.main-sidebar {
    right: 0;
    left: auto !important;
}

.main-sidebar .sidebar .nav-sidebar {
    padding-right: 0;
}

.main-sidebar .sidebar .user-panel .image {
    padding-right: 0.8rem;
    padding-left: 0;
}

.content-wrapper,
.main-footer {
    transition: none !important;
    transition: margin-right .3s ease-in-out !important;
    margin-right: 250px;
    margin-left: 0 !important;
}

.sidebar-mini.sidebar-collapse .content-wrapper {
    margin-right: 4.6rem;
    margin-left: 0 !important;
}

/* Navigation menu RTL fixes */
.nav-sidebar .nav-item>.nav-link {
    text-align: right;
}

.nav-sidebar .nav-item>.nav-link>.nav-icon {
    margin-left: 8px;
    margin-right: 0;
    float: right;
}

/* Form field adjustments */
.form-group label {
    text-align: right !important;
}

.form-control {
    text-align: right;
}

/* Table adjustments */
.table th,
.table td {
    text-align: right;
}

/* Breadcrumb RTL */
.breadcrumb {
    direction: rtl;
}

.breadcrumb-item+.breadcrumb-item::before {
    content: "\203A";
    float: right;
    padding-left: 0.5rem;
    padding-right: 0 !important;
}

.breadcrumb-item {
    padding-right: 0.5rem !important;
    padding-left: 0 !important;
}

/* Button adjustments */
.btn {
    text-align: center;
}

/* Dropdown menu RTL */
.dropdown-menu {
    right: 0;
    left: auto;
    text-align: right;
}

/* Pagination RTL */
.pagination {
    direction: rtl;
}

/* Search form RTL */
.input-group .form-control {
    text-align: right;
}

/* Admin header adjustments */
.main-header {
    transition: none !important;
    transition: margin-right .3s ease-in-out !important;
    margin-right: 250px;
    margin-left: 0 !important;
}

.sidebar-mini.sidebar-collapse .main-header {
    margin-right: 4.6rem;
    margin-left: 0 !important;
}

.main-header .navbar {
    direction: rtl;
}

.main-header .navbar-nav {
    padding-right: 0;
}

/* Content header RTL */
.content-header h1 {
    text-align: right;
}

/* Card adjustments */
.card-header {
    text-align: right;
}

.card-body {
    text-align: right;
}

/* Modal RTL support */
.modal-header {
    text-align: right;
}

.modal-body {
    text-align: right;
}

/* Alert messages RTL */
.alert {
    text-align: right;
}

/* Fix for form inline fields */
.form-inline .form-group {
    margin-left: 0;
    margin-right: 15px;
}

/* Admin list filters */
#changelist-filter {
    right: auto;
    left: 0;
}

/* #changelist {
    margin-right: 0;
    margin-left: 240px;
} */

/* Admin tabular inlines */
.tabular th,
.tabular td {
    text-align: right;
}

.card-body.p-0 .table thead > tr > th:first-child,
.card-body.p-0 .table tbody > tr > td:first-child {
    padding: 0.75rem !important;
    padding-right: 1.5rem !important;
}

/* Custom Theme Colors */
:root {
    --primary-color: rgb(151, 113, 36);      /* Primary color */
    --secondary-color: rgb(177, 177, 177);    /* Secondary color */
    --success-color: #28a745;      /* Green */
    --danger-color: #dc3545;       /* Red */
    --warning-color: #ffc107;      /* Yellow */
    --info-color: #17a2b8;         /* Cyan */
    --light-color: #f8f9fa;        /* Light gray */
    --dark-color: #343a40;         /* Dark gray */
}

/* Override Bootstrap primary colors */
.btn-primary {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.btn-primary:hover {
    opacity: 0.9;
}

.navbar-primary {
    background-color: var(--primary-color) !important;
}

.sidebar-dark-primary {
    background-color: var(--dark-color) !important;
}

.sidebar-dark-primary .nav-sidebar > .nav-item > .nav-link.active {
    background-color: var(--primary-color) !important;
    color: white !important;
}

/* Custom Arabic font support */
body,
.form-control,
.btn,
.table,
.nav-link {
    font-family: 'Tajawal', 'Cairo', 'Amiri', Arial, sans-serif;
}

/* Improve text readability */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Tajawal', 'Cairo', 'Amiri', Arial, sans-serif;
    font-weight: bold;
}

/* Fix for select2 dropdowns if used */
.select2-container--default .select2-selection--single {
    justify-content: space-between !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    position: relative;
}

.select2-dropdown {
    direction: rtl;
}

/* Django admin specific fixes */
.fieldBox {
    direction: rtl;
}

.form-row {
    direction: rtl;
}

.submit-row {
    text-align: left;
    direction: ltr;
}

.submit-row input {
    margin-left: 5px;
    margin-right: 0;
}

/* Object tools (add, change, delete buttons) */
.object-tools {
    float: left;
    direction: ltr;
}

.object-tools li {
    margin-right: 0;
    margin-left: 10px;
}

/* Fix for date/time widgets */
.datetime input {
    direction: ltr;
    text-align: left;
}

.timezonewarning {
    text-align: right;
}

/* Error list styling */
.errorlist {
    text-align: right;
}

/* Help text styling */
.help {
    text-align: right;
    font-size: 11px;
}

/* Custom styling for better Arabic support */
.module h2,
.module caption,
.inline-group h2 {
    text-align: right;
    background-position: right center;
    padding-right: 0;
    padding-left: 16px;
}

/* Logo styling for RTL layout */
.navbar-brand img {
    max-height: 40px;
    width: auto;
}

.login-logo img {
    max-height: 150px;
    width: auto;
    margin: 0 auto;
    display: block;
}

/* Ensure logo appears in sidebar */
.main-sidebar #jazzy-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.main-sidebar .brand-link img {
    max-height: unset !important;
    width: 75px !important;
    height: auto !important;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    opacity: 1 !important;
}

/* Actions dropdown */
.actions {
    direction: rtl;
}

.actions select {
    margin-left: 0;
    margin-right: 5px;
}

/* Change form tabs */
.nav-tabs {
    direction: rtl;
    padding: 0 !important;
}

.nav-tabs .nav-link {
    text-align: right;
}

/* Admin index page */
.dashboard .module {
    direction: rtl;
}

.dashboard .module table {
    direction: rtl;
}

/* Responsive adjustments */
@media (max-width: 991.98px) {
    /* Medium screens and below */
    body:not(.sidebar-mini-md):not(.sidebar-mini-xs):not(.layout-top-nav) .content-wrapper {
        margin-right: 0 !important;
        margin-left: 0 !important;
    }

    body:not(.sidebar-mini-md):not(.sidebar-mini-xs):not(.layout-top-nav) .main-header {
        margin-right: 0 !important;
        margin-left: 0 !important;
    }
    
    /* Sidebar overlay behavior for medium screens */
    .main-sidebar {
        position: fixed !important;
        z-index: 1038 !important;
        transition: transform 0.3s ease-in-out !important;
    }
    
    /* When sidebar is collapsed on medium screens */
    body.sidebar-collapse .main-sidebar {
        transform: translateX(250px) !important;
    }
    
    /* When sidebar is expanded on medium screens */
    body:not(.sidebar-collapse) .main-sidebar {
        transform: translateX(0) !important;
    }
    
    /* Add overlay when sidebar is open */
    body:not(.sidebar-collapse)::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1037;
        pointer-events: auto;
    }
    
    /* Ensure content is behind overlay */
    .content-wrapper,
    .main-header {
        z-index: 1036;
    }
}

@media (max-width: 768px) {
    /* Small screens */
    .main-sidebar {
        right: 0 !important;
        left: auto !important;
        position: fixed !important;
        z-index: 1038 !important;
        transform: translateX(250px) !important;
        transition: transform 0.3s ease-in-out !important;
    }
    
    /* When sidebar is expanded on small screens */
    body:not(.sidebar-collapse) .main-sidebar {
        transform: translateX(0) !important;
    }
    
    /* When sidebar is collapsed on small screens */
    body.sidebar-collapse .main-sidebar {
        transform: translateX(250px) !important;
    }

    .content-wrapper {
        margin-right: 0 !important;
        margin-left: 0 !important;
    }
    
    .main-header {
        margin-right: 0 !important;
        margin-left: 0 !important;
    }
    
    /* Add overlay when sidebar is open on small screens */
    body:not(.sidebar-collapse)::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1037;
        pointer-events: auto;
    }
}

/* Extra small screens */
@media (max-width: 576px) {
    .main-sidebar {
        width: 280px !important;
        transform: translateX(280px) !important;
    }
    
    body:not(.sidebar-collapse) .main-sidebar {
        transform: translateX(0) !important;
    }
    
    body.sidebar-collapse .main-sidebar {
        transform: translateX(280px) !important;
    }
}

/* Fix for sidebar toggle button */
.navbar-nav .nav-link[data-widget="pushmenu"] {
    cursor: pointer;
}

/* Ensure proper z-index for all elements */
.main-sidebar {
    z-index: 1038 !important;
}

.content-wrapper {
    z-index: 1036 !important;
}

.main-header {
    z-index: 1036 !important;
}

/* Custom styles for better Arabic UX */
.arabic-form .form-control {
    line-height: 1.8;
    padding: 10px;
}

.arabic-form label {
    font-weight: bold;
    margin-bottom: 8px;
    display: block;
    text-align: right !important;
}

/* Status badges RTL */
.badge {
    direction: ltr;
}

/* Fix for Django's admin collapse functionality */
.collapse-toggle {
    background-position: right center;
    padding-right: 0;
    padding-left: 20px;
}

/* File upload widget styling */
.file-upload {
    direction: rtl;
}

.file-upload .current {
    direction: ltr;
    text-align: left;
}

/* Override Jazzmin form grid layout */
.form-group .row label.col-sm-3 {
    flex: 0 0 33.333333% !important;
    max-width: 33.333333% !important;
}

.form-group .row .col-sm-7 {
    flex: 0 0 66.666667% !important;
    max-width: 66.666667% !important;
}

#jazzy-collapsible .collapsible-header:hover{
    background-color: var(--primary-color) !important;
}
