/**
 * RTL layout for Pashto / Dari (Phase 1)
 * Mirrors Porto Admin theme rules in assets/css/theme.css for:
 *   html.fixed + sidebar-left-xs + sidebar-left-collapsed + header-nav-menu
 *
 * English (dir=ltr) is unchanged. Load only when is_rtl() in inc/css.php.
 */

/* =============================================================================
   Fixed sidebar — move from left edge to right edge
   ============================================================================= */
html[dir="rtl"].fixed .sidebar-left {
    left: auto !important;
    right: 0;
}

/* Collapsed xs sidebar title hide offset */
html[dir="rtl"].sidebar-left-xs.sidebar-left-collapsed .sidebar-left .sidebar-title {
    margin-left: 0;
    margin-right: -200px;
}

/* =============================================================================
   Content area + page header — mirror fixed offsets (xs=200px, collapsed=73px)
   LTR: left offset + right:0  →  RTL: left:0 + right offset
   IMPORTANT: page-header is position:fixed — must set left:0 explicitly;
   otherwise left:auto + right:73px shrinks the bar to the sidebar edge.
   ============================================================================= */
html[dir="rtl"].fixed .page-header {
    left: 0 !important;
}

html[dir="rtl"].fixed.sidebar-left-xs .content-body {
    margin-left: 0 !important;
    margin-right: 200px;
}

html[dir="rtl"].fixed.sidebar-left-xs .page-header {
    left: 0 !important;
    right: 200px !important;
}

html[dir="rtl"].fixed.sidebar-left-collapsed .content-body {
    margin-left: 0 !important;
    margin-right: 73px;
}

html[dir="rtl"].fixed.sidebar-left-collapsed .page-header {
    left: 0 !important;
    right: 73px !important;
}

html[dir="rtl"].fixed.sidebar-left-xs.sidebar-left-collapsed .content-body {
    margin-left: 0 !important;
    margin-right: 73px;
}

html[dir="rtl"].fixed.sidebar-left-xs.sidebar-left-collapsed .page-header {
    left: 0 !important;
    right: 73px !important;
}

/* Apps launcher (has-top-menu, no sidebar offset) */
html[dir="rtl"].fixed.has-top-menu:not(.has-left-sidebar-half) .content-body {
    margin-right: 0 !important;
}

html[dir="rtl"].fixed.has-top-menu:not(.has-left-sidebar-half) .page-header {
    left: 0 !important;
    right: 0 !important;
}

/* Page header bar — title + green underline (theme floats h2 left) */
html[dir="rtl"] .page-header {
    border-left: none;
    border-right: 1px solid #3a3a3a;
}

html[dir="rtl"] .page-header h2 {
    float: right;
}

/* =============================================================================
   Top header — full viewport width (mirrors English: white bar over sidebar strip)
   Layout: [user | lang | … nav | logo] with logo on the right edge
   ============================================================================= */
html[dir="rtl"].fixed .header {
    left: 0 !important;
    right: 0 !important;
}

@media only screen and (min-width: 768px) {
    html[dir="rtl"] .header.header-nav-menu {
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
        direction: ltr;
        background-image: linear-gradient(#F6F6F6 0%, #FFFFFF 45%);
        border-bottom: 1px solid #e9e9e6;
        border-top: 3px solid #ededed;
        box-sizing: border-box;
    }

    /* Release full-width fixed layer; flex row-reverse puts this block on the right */
    html[dir="rtl"] .header .logo-container {
        position: relative !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        z-index: auto;
        flex: 1 1 auto;
        min-width: 0;
        width: auto !important;
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
        height: 60px;
        background: transparent;
        border: none;
    }

    html[dir="rtl"] .header .logo-container .logo {
        float: none !important;
        flex: 0 0 auto;
        margin: 0 !important;
    }

    html[dir="rtl"] .header.header-nav-menu .logo {
        padding: 0 15px 0 20px;
    }

    html[dir="rtl"] .header .header-nav {
        flex: 1 1 auto;
        min-width: 0;
    }

    html[dir="rtl"] .header .header-right {
        float: none !important;
        flex: 0 0 auto;
        height: 60px;
        position: relative !important;
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main {
        float: none !important;
        margin-top: 8px;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main nav > ul {
        direction: rtl;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main nav > ul > li {
        margin-left: 0;
        margin-right: 2px;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main nav > ul > li:first-child {
        margin-left: 0;
        margin-right: 10px;
    }

    html[dir="rtl"] .header.header-nav-menu .logo:after {
        right: auto;
        left: 0;
        border-right: none;
        border-left: 1px solid #e9e9e6;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main nav > ul > li > a.dropdown-toggle:after {
        float: left;
        margin-left: 0;
        margin-right: 4px;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main nav > ul > li.dropdown .dropdown-menu {
        text-align: right;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main nav > ul > li.dropdown .dropdown-menu li.dropdown-submenu > a:after {
        right: auto;
        left: 10px;
        border-color: transparent #ccc transparent transparent;
    }

    html[dir="rtl"] .header.header-nav-menu .header-nav-main nav > ul > li.dropdown .dropdown-menu li.dropdown-submenu > .dropdown-menu {
        margin-left: 0;
        margin-right: -1px;
    }

    /* Userbox: picture + name on the left cluster, caret on the outer edge */
    html[dir="rtl"] #userbox.userbox > a {
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
    }

    html[dir="rtl"] .userbox .profile-info {
        margin: -3px 10px 0 25px;
    }
}

@media only screen and (min-width: 768px) and (max-width: 991px) {
    html[dir="rtl"] .header.header-nav-menu .header-right {
        right: auto !important;
        left: auto !important;
    }
}

/* =============================================================================
   Left sidebar navigation
   ============================================================================= */
html[dir="rtl"] ul.nav-main > li.nav-active > a {
    box-shadow: -2px 0 0 #175f31 inset;
}

html[dir="rtl"] .sidebar-left ul.nav-main > li > a .fa,
html[dir="rtl"] .sidebar-left ul.nav-main > li > a .fas,
html[dir="rtl"] .sidebar-left ul.nav-main > li > a .bx {
    margin-right: 0;
    margin-left: 0.5rem;
}

html[dir="rtl"].sidebar-left-xs .sidebar-left ul.nav-main li .nav-children li a {
    padding-left: 0;
    padding-right: 52px;
}

html[dir="rtl"] .sidebar-left .sidebar-header .sidebar-toggle {
    left: auto;
    right: 0;
}

/* =============================================================================
   Language switcher + misc
   ============================================================================= */
html[dir="rtl"] .lang-switcher .btn-group .btn {
    font-family: inherit;
}

html[dir="rtl"] .lang-switcher.mr-2,
html[dir="rtl"] .lang-switcher.d-inline-flex.mr-2 {
    margin-right: 0 !important;
    margin-left: 0.5rem !important;
}

html[dir="rtl"] .shortcut-buttons-set li {
    text-align: center;
}

/* Form labels already handled by Bootstrap + html dir=rtl; keep icons sane */
html[dir="rtl"] .input-group-append {
    border-radius: 0;
}

html[dir="rtl"] .dashboard-card .icon-container {
    right: auto;
    left: 1rem;
}
