/*
 * Hewa EDMS — RTL (Right-to-Left) Support
 * Applied when body has class "rtl" or html dir="rtl"
 * This is the SINGLE SOURCE OF TRUTH for all RTL styles.
 */

/* === Base Direction === */
[dir="rtl"],
body.rtl {
    direction: rtl;
    text-align: right;
}

/* === Top Navigation (NAVBAR) === */
body.rtl .topnav {
    direction: rtl !important;
}

body.rtl .topnav__brand {
    direction: rtl;
}

body.rtl .topnav__menu {
    direction: rtl;
}

body.rtl .topnav__right {
    direction: rtl;
    flex-direction: row-reverse;
}

body.rtl .topnav__menu-link,
body.rtl .topnav__dropdown-btn,
body.rtl .topnav__notification,
body.rtl .global-search,
body.rtl .global-search__input {
    direction: rtl;
}

body.rtl .global-search {
    flex-direction: row-reverse;
}

body.rtl .topnav__search {
    direction: rtl;
}

body.rtl .topnav__badge {
    left: 0;
    right: auto;
}

body.rtl .topnav__user {
    direction: rtl;
}

body.rtl .topnav__notification {
    margin-left: 0;
    margin-right: .25rem;
}

/* === Sidebar === */
body.rtl .sidebar {
    left: auto;
    right: 0;
    border-left: 1px solid var(--border, rgba(255, 255, 255, .06));
    border-right: none;
}

body.rtl .sidebar~.main-content {
    margin-left: 0;
    margin-right: var(--sidebar-width, 240px);
}

body.rtl .sidebar.collapsed~.main-content {
    margin-right: var(--sidebar-collapsed, 60px);
}

body.rtl .sidebar__link,
body.rtl .sidebar__section-title {
    text-align: right;
    flex-direction: row-reverse;
}

body.rtl .sidebar__link-icon {
    margin-right: 0;
    margin-left: .6rem;
}

body.rtl .sidebar__nav-link {
    padding-left: .75rem;
    padding-right: 1.1rem;
    flex-direction: row-reverse;
    border-left: none;
    border-right: 2px solid transparent;
}

body.rtl .sidebar__nav-link:hover {
    border-right-color: rgba(59, 130, 246, .4);
    border-left-color: transparent;
}

body.rtl .sidebar__nav-link.active {
    border-right-color: var(--accent);
    border-left-color: transparent;
}

body.rtl .sidebar__section-title {
    border-left: none;
    border-right: 2px solid var(--accent);
    background: linear-gradient(270deg, rgba(59, 130, 246, .08), transparent);
}

body.rtl .nav-main-tab-btn,
body.rtl .nav-sub-tab-btn,
body.rtl .nav-item-link,
body.rtl .nav-direct-link-a,
body.rtl .sidebar__dropdown-toggle,
body.rtl .admin-sidebar__back-link,
body.rtl .vendor-sidebar__back-link {
    direction: rtl;
    text-align: right;
}

body.rtl .nav-main-tab-btn,
body.rtl .nav-sub-tab-btn,
body.rtl .sidebar__dropdown-toggle {
    flex-direction: row-reverse;
}

body.rtl .nav-item-link,
body.rtl .nav-direct-link-a,
body.rtl .admin-sidebar__back-link,
body.rtl .vendor-sidebar__back-link {
    justify-content: flex-end;
}

body.rtl .sidebar-expand-btn {
    left: auto;
    right: var(--sidebar-width, 240px);
    transform: translateX(50%);
}

/* === Cards & Components === */
body.rtl .page-header {
    flex-direction: row-reverse;
}

body.rtl .stat-card {
    flex-direction: row-reverse;
}

body.rtl .stat-card__icon {
    margin-right: 0;
    margin-left: .75rem;
}

body.rtl .card__header {
    flex-direction: row-reverse;
}

body.rtl .card__title {
    text-align: right;
}

/* === Tables === */
body.rtl .data-table th,
body.rtl .data-table td {
    text-align: right;
}

body.rtl .data-table th:last-child,
body.rtl .data-table td:last-child {
    text-align: left;
}

/* === Forms === */
body.rtl .form-group {
    text-align: right;
}

body.rtl .form-label {
    text-align: right;
}

body.rtl .form-control {
    text-align: right;
}

body.rtl input[type="text"],
body.rtl input[type="email"],
body.rtl input[type="password"],
body.rtl input[type="number"],
body.rtl textarea,
body.rtl select {
    direction: rtl;
    text-align: right;
}

/* === Buttons === */
body.rtl .btn {
    flex-direction: row-reverse;
}

body.rtl .btn-group {
    flex-direction: row-reverse;
}

body.rtl .btn .icon,
body.rtl .btn span {
    margin-left: 0;
    margin-right: .25rem;
}

/* === Dropdowns === */
body.rtl .dropdown__menu {
    left: auto;
    right: 0;
}

body.rtl .dropdown__menu--right {
    right: auto;
    left: 0;
}

body.rtl .dropdown__item {
    text-align: right;
    flex-direction: row-reverse;
}

/* === Pagination === */
body.rtl .pagination,
body.rtl .card__footer {
    flex-direction: row-reverse;
}

/* === Notifications / Items === */
body.rtl .notif-item {
    flex-direction: row-reverse;
}

/* === Timeline === */
body.rtl .timeline::before {
    left: auto;
    right: 20px;
}

body.rtl .timeline__item {
    padding-left: 0;
    padding-right: 2.5rem;
}

body.rtl .timeline__dot {
    left: auto;
    right: 0;
}

body.rtl .breadcrumb {
    direction: rtl;
}

body.rtl .breadcrumb__item,
body.rtl .breadcrumb__current {
    text-align: right;
}

body.rtl .toast {
    direction: rtl;
}

/* === Grid Fixes === */
body.rtl [style*="grid-template-columns"] {
    direction: rtl;
}

/* === Margins & Paddings (RTL flip) === */
body.rtl .ml-auto {
    margin-left: 0;
    margin-right: auto;
}

body.rtl .mr-auto {
    margin-right: 0;
    margin-left: auto;
}

/* === Specific Adjustments === */
body.rtl .stat-cards {
    direction: rtl;
}

body.rtl .empty-state {
    text-align: center;
}

/* === Login Page RTL === */
body.rtl .login-card {
    direction: rtl;
    text-align: right;
}

/* === Scrollbar === */
body.rtl ::-webkit-scrollbar-track {
    direction: rtl;
}

/* === Chatbot === */
body.rtl #aiChatPanel {
    left: 1.5rem;
    right: auto;
}

body.rtl #aiChatBtn {
    left: 1.5rem;
    right: auto;
}

/* === Mobile Responsive RTL === */
@media (max-width: 1024px) {
    body.rtl .sidebar {
        transform: translateX(100%);
        left: auto;
        right: 0;
    }

    body.rtl .sidebar.sidebar--open {
        transform: translateX(0);
    }

    body.rtl .main-content {
        margin-right: 0 !important;
    }
}

/* === Print RTL === */
@media print {

    [dir="rtl"],
    body.rtl {
        direction: rtl;
        text-align: right;
    }
}
