/* ==========================================================================
   SkysoftSMS :: assets/css/nav.css
   Sidebar filter + buttons, header avatar, language menu, toast, and the profile page.
   Loaded after theme.css / polish.css; uses the theme's variables.
   ========================================================================== */

/* ---------- accessibility ---------- */
.sms-skip {
    position: fixed; left: .75rem; top: -60px; z-index: 2000;
    background: var(--blue, #844fc1); color: #fff; padding: .5rem .9rem; border-radius: 6px;
    text-decoration: none; font-weight: 600; transition: top .15s;
}
.sms-skip:focus { top: .75rem; color: #fff; }
.sidebar a:focus-visible,
.sidebar .nav-header:focus-visible,
.sidebar input:focus-visible,
.px-header button:focus-visible,
.px-header a:focus-visible { outline: 2px solid var(--blue, #844fc1); outline-offset: 2px; }
.px-brand .mobile-toggle:focus-visible { outline-color: #fff; }

/* ---------- sidebar: group headers are real buttons now ---------- */
.sidebar button.nav-header {
    width: 100%; border: 0; background: transparent; text-align: left;
    font: inherit; font-weight: 500; cursor: pointer; appearance: none; -webkit-appearance: none;
}
.sidebar .nav-header > span { display: inline-flex; align-items: center; min-width: 0; }
.sidebar .nav-header .arrow { flex: 0 0 auto; }
.sidebar .nav-item.active > .nav-header .arrow { transform: rotate(90deg); }
.sidebar .sub-menu a > span, .sidebar .direct-link > span { min-width: 0; overflow-wrap: anywhere; }
.sidebar .nav-hidden { display: none !important; }
.sidebar .nav-empty { padding: .8rem 1rem; margin: 0; color: var(--slate, #6c7293); font-size: .8rem; }

/* ---------- sidebar: filter box ---------- */
.sidebar .nav-filter {
    position: sticky; top: 0; z-index: 3;
    padding: .6rem .25rem .5rem; margin-bottom: .25rem;
    background: #fff;
}
.sidebar .nav-filter > i {
    position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
    margin-top: .05rem; font-size: .78rem; color: var(--ink-faint, #a3a8c0); pointer-events: none;
}
.sidebar .nav-filter input {
    width: 100%; box-sizing: border-box;
    padding: .5rem .75rem .5rem 2.1rem;
    border: 1px solid var(--line, #e6e9f2); border-radius: 6px;
    background: var(--butter-50, #f1f3f8); color: var(--ink, #2e3250);
    font: inherit; font-size: .82rem;
}
.sidebar .nav-filter input::placeholder { color: var(--ink-faint, #a3a8c0); }
.sidebar .nav-filter input:focus { outline: none; border-color: var(--blue, #844fc1); background: #fff; box-shadow: var(--ring, 0 0 0 3px rgba(132,79,193,.2)); }

/* ---------- header: avatar with photo ---------- */
.px-avatar.has-img, .profile-icon .px-avatar.has-img { background: #fff; padding: 0; overflow: hidden; }
.px-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
.profile-icon { gap: .4rem; }
.profile-icon .px-avatar { width: 28px; height: 28px; font-size: .8rem; }
.profile-icon .px-avatar img { border-radius: 50%; }

/* dropdown triggers are buttons now */
.px-actions button.lang-dropdown, .px-actions button.profile-icon {
    border: 0; font: inherit; color: inherit; cursor: pointer; appearance: none; -webkit-appearance: none;
}
.px-actions button.lang-dropdown { font-size: .8rem; }

/* profile menu header */
.profile-menu .pm-head { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem .6rem; min-width: 220px; }
.profile-menu .pm-head .px-avatar { width: 38px; height: 38px; }
.profile-menu .pm-head strong { display: block; font-size: .82rem; line-height: 1.2; color: var(--ink, #2e3250); }
.profile-menu .pm-head small { display: block; font-size: .7rem; color: var(--ink-muted, #6c7293); }
.profile-menu { min-width: 220px; }

/* language menu */
.lang-menu { min-width: 170px; }
.lang-menu a {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    width: 100%; box-sizing: border-box; padding: .5rem 1rem; text-decoration: none;
    color: var(--ink, #2e3250); font-size: .8rem; cursor: pointer;
}
.lang-menu a:hover, .lang-menu a:focus-visible { background: var(--blue-50, #f1eafa); color: var(--blue, #844fc1); }
.lang-menu a .tick { font-size: .7rem; color: var(--blue, #844fc1); visibility: hidden; }
.lang-menu a[aria-checked="true"] { font-weight: 600; }
.lang-menu a[aria-checked="true"] .tick { visibility: visible; }

/* ---------- toast ---------- */
.sms-toast {
    position: fixed; right: 1rem; bottom: 1rem; z-index: 3000; max-width: min(92vw, 360px);
    background: var(--graphite, #2e3250); color: #fff; padding: .7rem 1rem; border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: .82rem;
    opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s;
}
.sms-toast.show { opacity: 1; transform: none; }

/* ==========================================================================
   Profile page
   ========================================================================== */
.pf { max-width: 1020px; margin: 0 auto; }
.pf-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.pf-card { background: #fff; border: 1px solid var(--line, #e6e9f2); border-radius: 10px; box-shadow: var(--shadow-card, 0 2px 14px rgba(46,50,80,.07)); }
.pf-side { padding: 1.5rem 1.25rem; text-align: center; }
.pf-photo { position: relative; width: 132px; height: 132px; margin: 0 auto .9rem; }
.pf-photo .pf-avatar {
    width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
    background: var(--blue-50, #f1eafa); color: var(--blue, #844fc1);
    display: grid; place-items: center;
    font-family: var(--font-head, inherit); font-weight: 700; font-size: 3rem;
    border: 4px solid #fff; box-shadow: 0 0 0 1px var(--line, #e6e9f2), 0 6px 18px rgba(46,50,80,.12);
}
.pf-photo .pf-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pf-photo .pf-cam {
    position: absolute; right: 2px; bottom: 6px; width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid #fff; background: var(--blue, #844fc1); color: #fff; cursor: pointer;
    display: grid; place-items: center; font-size: .85rem;
}
.pf-photo .pf-cam:hover { background: var(--blue-600, #6a3fa0); }
.pf-name { font-family: var(--font-head, inherit); font-weight: 700; font-size: 1.1rem; margin: 0 0 .15rem; color: var(--ink, #2e3250); overflow-wrap: anywhere; }
.pf-sub { color: var(--ink-muted, #6c7293); font-size: .82rem; margin: 0 0 .6rem; overflow-wrap: anywhere; }
.pf-role { display: inline-block; padding: .2rem .7rem; border-radius: 999px; background: var(--blue-50, #f1eafa); color: var(--blue, #844fc1); font-weight: 600; font-size: .75rem; }
.pf-facts { list-style: none; margin: 1.1rem 0 0; padding: 1rem 0 0; border-top: 1px solid var(--line, #e6e9f2); text-align: left; font-size: .8rem; }
.pf-facts li { display: flex; justify-content: space-between; gap: .75rem; padding: .3rem 0; }
.pf-facts span:first-child { color: var(--ink-muted, #6c7293); flex: 0 0 auto; }
.pf-facts span:last-child { color: var(--ink, #2e3250); font-weight: 600; text-align: right; overflow-wrap: anywhere; }

.pf-photo-form { margin-top: 1rem; display: none; }
.pf-photo-form.show { display: block; }
.pf-drop {
    border: 2px dashed var(--line-strong, #d3d8e6); border-radius: 10px; padding: .9rem; font-size: .78rem; color: var(--ink-muted, #6c7293);
    cursor: pointer; transition: border-color .15s, background .15s;
}
.pf-drop.over { border-color: var(--blue, #844fc1); background: var(--blue-50, #f1eafa); }
.pf-photo-actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; margin-top: .6rem; }

.pf-main { padding: 0; overflow: hidden; }
.pf-tabs { display: flex; gap: .25rem; padding: .5rem .75rem 0; border-bottom: 1px solid var(--line, #e6e9f2); overflow-x: auto; }
.pf-tabs .nav-link {
    border: 0; background: transparent; padding: .7rem .9rem; font-weight: 600; font-size: .85rem; white-space: nowrap;
    color: var(--ink-muted, #6c7293); border-bottom: 3px solid transparent; border-radius: 0; margin-bottom: -1px;
}
.pf-tabs .nav-link:hover { color: var(--blue, #844fc1); }
.pf-tabs .nav-link.active { color: var(--blue, #844fc1); border-bottom-color: var(--blue, #844fc1); background: transparent; }
.pf-pane { padding: 1.4rem; }
.pf-pane h3 { font-size: 1rem; font-family: var(--font-head, inherit); font-weight: 700; margin: 0 0 1rem; }
.pf-dl { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: .1rem 1rem; margin: 0; }
.pf-dl dt { color: var(--ink-muted, #6c7293); font-weight: 600; font-size: .8rem; padding: .55rem 0; border-bottom: 1px solid var(--butter-50, #f1f3f8); }
.pf-dl dd { margin: 0; padding: .55rem 0; border-bottom: 1px solid var(--butter-50, #f1f3f8); overflow-wrap: anywhere; }
.pf-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.1rem; }
.pf-form .full { grid-column: 1 / -1; }
.pf-form label { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-muted, #6c7293); margin-bottom: .3rem; }
.pf-form .hint { display: block; margin-top: .25rem; font-size: .74rem; color: var(--ink-muted, #6c7293); }
.pf-form .form-control, .pf-form .form-select { font-size: .9rem; }
.pf-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.25rem; }
.pf-activity { list-style: none; margin: 0; padding: 0; }
.pf-activity li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--butter-50, #f1f3f8); font-size: .84rem; }
.pf-activity time { color: var(--ink-muted, #6c7293); white-space: nowrap; font-size: .78rem; }
.pf-muted { color: var(--ink-muted, #6c7293); }

@media (max-width: 900px) {
    .pf-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .pf-form { grid-template-columns: 1fr; }
    .pf-dl { grid-template-columns: 1fr; }
    .pf-dl dt { border-bottom: 0; padding-bottom: 0; }
    .pf-pane { padding: 1rem; }
}

/* ==========================================================================
   Right-to-left (Arabic). <html dir="rtl"> flips the header grid and text
   automatically; these rules mirror the fixed sidebar and the pieces that use left/right.
   ========================================================================== */
[dir="rtl"] body { text-align: right; }
[dir="rtl"] .sidebar { left: auto !important; right: 0 !important; box-shadow: -2px 0 18px rgba(46, 50, 80, .07) !important; }
[dir="rtl"] .main-content { margin-left: 0 !important; margin-right: var(--px-side) !important; }
[dir="rtl"] .sidebar-close { right: auto; left: 1rem; }
[dir="rtl"] .sidebar .sub-menu { padding-left: 0; margin-left: 0; padding-right: 1.5rem; margin-right: .8rem; border-left: 0 !important; border-right: 1px solid var(--line) !important; }
[dir="rtl"] .sidebar .nav-header .arrow { transform: rotate(180deg); }
[dir="rtl"] .sidebar .nav-item.active > .nav-header .arrow { transform: rotate(90deg); }
[dir="rtl"] .sidebar .nav-filter > i { left: auto; right: 1rem; }
[dir="rtl"] .sidebar .nav-filter input { padding: .5rem 2.1rem .5rem .75rem; }
[dir="rtl"] .lang-menu, [dir="rtl"] .profile-menu { right: auto; left: 0; text-align: right; }
[dir="rtl"] .lang-menu a { text-align: right; }
[dir="rtl"] .sms-toast { right: auto; left: 1rem; }
[dir="rtl"] .sms-skip { left: auto; right: .75rem; }
[dir="rtl"] .pf-facts span:last-child { text-align: left; }
[dir="rtl"] .pf-cam { right: auto; left: 2px; }
[dir="rtl"] .px-crumbs .fa-angle-right { transform: scaleX(-1); }
@media (max-width: 768px) {
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    [dir="rtl"] .sidebar.open { transform: translateX(0); }
    [dir="rtl"] .main-content { margin-right: 0 !important; }
    [dir="rtl"] .lang-menu, [dir="rtl"] .profile-menu { left: -10px; }
}

/* ==========================================================================
   Sidebar v3: icon tiles, soft active state, sticky search + logout,
   and a proper drawer (with a user card) on phones.
   ========================================================================== */
body .sidebar {
    display: flex; flex-direction: column;
    border-right: 1px solid var(--line, #e6e9f2);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin; scrollbar-color: #d3d8e6 transparent;
}
body .sidebar::-webkit-scrollbar { display: block; width: 6px; }
body .sidebar::-webkit-scrollbar-thumb { background: #d3d8e6; border-radius: 6px; }
body .sidebar::-webkit-scrollbar-track { background: transparent; }
body .sidebar > nav { flex: 1 0 auto; display: flex; flex-direction: column; padding: 0 .75rem 0; }
body .sidebar > nav > .nav-item:last-of-type { margin-bottom: 1rem; }

/* search box */
body .sidebar .nav-filter { padding: .85rem .1rem .6rem; margin: 0 0 .3rem; }
body .sidebar .nav-filter input { height: 38px; border-radius: 10px; font-size: .84rem; padding: 0 .75rem 0 2.2rem; }
body .sidebar .nav-filter > i { left: .95rem; }

/* group headers + dashboard link */
body .sidebar .nav-header,
body .sidebar .direct-link {
    min-height: 44px; padding: .35rem .55rem; border-radius: 10px;
    font-size: .875rem; font-weight: 600; color: var(--ink, #2e3250);
}
body .sidebar .direct-link { gap: .65rem; margin-bottom: .15rem; }
body .sidebar .nav-header > span > i:first-child,
body .sidebar .direct-link > i:first-child {
    width: 32px; height: 32px; flex: 0 0 32px;
    display: inline-grid; place-items: center;
    border-radius: 9px; font-size: .85rem;
    background: var(--butter-50, #f1f3f8); color: var(--slate, #6c7293);
    transition: background .15s, color .15s;
}
body .sidebar .nav-header > span > i:first-child { margin-right: .65rem; }
body .sidebar .nav-header:hover,
body .sidebar .direct-link:hover { background: var(--butter-50, #f4f5f9) !important; color: var(--ink, #2e3250); }
body .sidebar .nav-header:hover > span > i:first-child,
body .sidebar .direct-link:hover > i:first-child { background: #fff; color: var(--blue, #844fc1); box-shadow: 0 0 0 1px var(--line, #e6e9f2); }
body .sidebar .nav-item.active > .nav-header { background: transparent; color: var(--blue, #844fc1); }
body .sidebar .nav-item.active > .nav-header > span > i:first-child { background: var(--blue, #844fc1); color: #fff; box-shadow: none; }
body .sidebar .nav-header .arrow { font-size: .68rem; color: var(--ink-faint, #a3a8c0); margin-left: auto; }
body .sidebar .nav-item.active > .nav-header .arrow { color: var(--blue, #844fc1); }
body .sidebar .direct-link.current { background: var(--blue-50, #f1eafa) !important; color: var(--blue, #844fc1) !important; font-weight: 700; }
body .sidebar .direct-link.current > i:first-child { background: var(--blue, #844fc1); color: #fff; box-shadow: none; }

/* sub menu */
body .sidebar .sub-menu { margin: .1rem 0 .45rem 1.1rem; padding: .15rem 0 .15rem .7rem; border-left: 2px solid var(--line, #e6e9f2) !important; }
body .sidebar .sub-menu a { min-height: 38px; padding: .4rem .65rem; border-radius: 8px; font-size: .84rem; gap: .6rem; color: var(--slate, #6c7293); }
body .sidebar .sub-menu a > i { width: 16px; font-size: .74rem; text-align: center; }
body .sidebar .sub-menu a:hover { background: var(--butter-50, #f4f5f9) !important; color: var(--ink, #2e3250); }
body .sidebar .sub-menu a.current { background: var(--blue-50, #f1eafa) !important; color: var(--blue, #844fc1); font-weight: 600; }
body .sidebar .sub-menu a.current > i { color: var(--blue, #844fc1); }
body .sidebar .sub-menu a.current::before { content: ""; position: absolute; left: calc(-.7rem - 2px); top: 0; bottom: 0; width: 2px; background: var(--blue, #844fc1); border-radius: 2px; }
body .sidebar .sub-menu .sub-label { padding: .7rem .65rem .25rem; font-size: .66rem; letter-spacing: .06em; }

/* logout: always reachable at the bottom */
body .sidebar .direct-link.logout {
    position: sticky; bottom: 0; z-index: 2;
    margin: auto -.75rem 0; padding: .7rem 1.3rem calc(.7rem + env(safe-area-inset-bottom, 0px));
    border-radius: 0; border-top: 1px solid var(--line, #e6e9f2);
    background: #fff; box-shadow: 0 -10px 16px -14px rgba(46, 50, 80, .35);
}
body .sidebar .direct-link.logout > i:first-child { background: var(--danger-50, #fdecee); color: var(--danger, #d13449); }
body .sidebar .direct-link.logout:hover > i:first-child { background: #fff; box-shadow: 0 0 0 1px var(--danger-50, #fdecee); color: var(--danger, #d13449); }

/* drawer header (phones only) */
.sidebar-head { display: none; align-items: center; gap: .75rem; padding: .9rem 1rem; background: linear-gradient(135deg, var(--blue-50, #f1eafa), #fff); border-bottom: 1px solid var(--line, #e6e9f2); }
.sidebar-head .px-avatar { width: 42px; height: 42px; }
.sidebar-head-text { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; line-height: 1.25; }
.sidebar-head-text strong { font-family: var(--font-head, inherit); font-size: .9rem; color: var(--ink, #2e3250); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-head-text small { font-size: .74rem; color: var(--ink-muted, #6c7293); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-head .sidebar-close {
    position: static !important; display: inline-flex !important; flex: 0 0 36px;
    width: 36px; height: 36px; margin-left: auto;
    background: #fff !important; color: var(--ink, #2e3250) !important;
    border: 1px solid var(--line, #e6e9f2); box-shadow: 0 1px 2px rgba(46, 50, 80, .08);
}

/* ---------- phones and small tablets ---------- */
@media (max-width: 768px) {
    body .sidebar {
        width: min(320px, 88vw) !important; padding-top: 0 !important;
        border-radius: 0 18px 18px 0; border-right: 0;
        box-shadow: 8px 0 40px rgba(24, 20, 45, .28) !important;
        transition: transform .3s cubic-bezier(.4, 0, .2, 1), visibility 0s;
    }
    body .sidebar:not(.open) { visibility: hidden; transition: transform .3s cubic-bezier(.4, 0, .2, 1), visibility 0s linear .3s; }
    .sidebar-head { display: flex; }
    .sidebar-overlay { background: rgba(24, 20, 45, .5) !important; }
    body .sidebar .nav-header, body .sidebar .direct-link { min-height: 48px; }
    body .sidebar .sub-menu a { min-height: 44px; }
    html[dir="rtl"] body .sidebar { border-radius: 18px 0 0 18px; box-shadow: -8px 0 40px rgba(24, 20, 45, .28) !important; }

    /* header strip */
    .px-user-row { gap: .5rem; }
    .px-actions { min-width: 0; gap: .4rem; }
    .px-actions .px-branch select { max-width: 120px !important; }
    .px-actions .px-pill { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .px-brand .mobile-toggle { width: 40px; height: 40px; }
    .px-page-title { flex: 1 1 auto; min-width: 0; }
    .px-page-title h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .px-actions button.lang-dropdown, .px-actions button.profile-icon, .px-icon-btn { min-height: 36px; }
}
@media (max-width: 480px) {
    .px-actions .lang-dropdown .fa-chevron-down,
    .px-actions .profile-icon .fa-chevron-down,
    .px-actions .px-branch > i { display: none; }
    .px-user { display: none; }                      /* the avatar is in the account menu and the drawer */
    .px-user-row { justify-content: flex-end; }
    .px-actions .px-branch select { max-width: 96px !important; }
    .lang-menu, .profile-menu { right: 0 !important; }
    .lang-menu { min-width: 160px; }

    /* search collapses to a button and opens on tap */
    .px-search { width: 40px !important; flex: 0 0 40px !important; max-width: none; transition: width .2s ease; }
    .px-search input { width: 0; padding: 0; }
    .px-search.open { width: min(210px, 62vw) !important; flex: 0 1 min(210px, 62vw) !important; }
    .px-search.open input { padding: 0 .7rem; }
}
@media (max-width: 380px) {
    .px-brand { padding: 0 .5rem; }
    .px-brand .brand-mark { display: none; }          /* keep the menu button and header actions on one line */
    .px-user-row { padding: 0 .5rem; }
    .px-actions { gap: .3rem; }
    .px-actions .px-branch select { max-width: 84px !important; font-size: .75rem !important; }
}
@media (prefers-reduced-motion: reduce) {
    body .sidebar, body .sidebar:not(.open), .px-search { transition: none !important; }
}

/* ==========================================================================
   Navigation v4: calmer, more professional sidebar + a real mobile drawer.
   Appended last so it wins over theme.css / polish.css / the sections above.
   ========================================================================== */

/* ---------- sidebar, all sizes ---------- */
body .sidebar { background: #fff !important; font-family: 'Open Sans', system-ui, sans-serif; }
body .sidebar > nav { padding: 0 .8rem; }

body .sidebar .nav-filter { background: #fff; padding: .9rem 0 .7rem; }
body .sidebar .nav-filter input {
    height: 40px; border-radius: 10px; background: #f4f5f9; border: 1px solid transparent;
    transition: background .15s, border-color .15s, box-shadow .15s;
}
body .sidebar .nav-filter input:hover { border-color: var(--line, #e6e9f2); }

body .sidebar .nav-header,
body .sidebar .direct-link {
    position: relative; border-radius: 10px; letter-spacing: 0;
    transition: background .15s, color .15s;
}
body .sidebar .nav-item { margin-bottom: 2px; }

/* open group: soft tint + accent bar */
body .sidebar .nav-item.active > .nav-header { background: var(--blue-50, #f1eafa); color: var(--blue-600, #6a3fa0); }
body .sidebar .nav-item.active > .nav-header::before {
    content: ""; position: absolute; left: -.8rem; top: 9px; bottom: 9px; width: 4px;
    border-radius: 0 4px 4px 0; background: var(--blue, #844fc1);
}
body .sidebar .direct-link.current::before {
    content: ""; position: absolute; left: -.8rem; top: 9px; bottom: 9px; width: 4px;
    border-radius: 0 4px 4px 0; background: var(--blue, #844fc1);
}
body .sidebar .nav-header .arrow { transition: transform .2s ease, color .15s; }

/* sub menu: clean tree line, tidy rows */
body .sidebar .sub-menu { margin: .2rem 0 .5rem 1.35rem; padding: .1rem 0 .1rem .55rem; border-left: 1px solid var(--line, #e6e9f2) !important; }
body .sidebar .sub-menu a { position: relative; line-height: 1.3; transition: background .15s, color .15s; }
body .sidebar .sub-menu a.current::before { left: calc(-.55rem - 1px); width: 2px; top: 6px; bottom: 6px; }
body .sidebar .sub-menu .sub-label { color: var(--ink-faint, #a3a8c0); font-weight: 700; text-transform: uppercase; }

/* ---------- language block inside the menu (phones only) ---------- */
.sidebar .nav-lang { display: none; margin: .5rem 0 1rem; padding: .85rem; border: 1px solid var(--line, #e6e9f2); border-radius: 14px; background: #fafbfd; }
.sidebar .nav-lang-title { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted, #6c7293); }
.sidebar .nav-lang-title i { color: var(--blue, #844fc1); }
.sidebar .nav-lang-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.sidebar .nav-lang-opt {
    display: flex; align-items: center; justify-content: space-between; gap: .4rem; min-height: 40px;
    padding: .35rem .65rem; border-radius: 9px; background: #fff; border: 1px solid var(--line, #e6e9f2);
    color: var(--ink, #2e3250); font-size: .8rem; font-weight: 600; text-decoration: none; overflow: hidden;
}
.sidebar .nav-lang-opt span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .nav-lang-opt i { font-size: .68rem; visibility: hidden; color: #fff; }
.sidebar .nav-lang-opt:hover { border-color: var(--blue, #844fc1); color: var(--blue, #844fc1); }
.sidebar .nav-lang-opt.is-current { background: var(--blue, #844fc1); border-color: var(--blue, #844fc1); color: #fff; }
.sidebar .nav-lang-opt.is-current i { visibility: visible; }

/* ---------- tablets: keep the fixed sidebar but let the header breathe ---------- */
@media (max-width: 1100px) and (min-width: 769px) {
    :root { --px-side: 236px; }
    .px-search { width: 200px; flex-basis: 200px; }
}

/* ---------- phones and small tablets: full-height slide-in drawer ---------- */
@media (max-width: 768px) {
    body .sidebar {
        top: 0 !important; bottom: 0 !important; height: 100vh; height: 100dvh;
        width: min(330px, 88vw) !important; z-index: 1300 !important;
        border-radius: 0 20px 20px 0; padding-top: env(safe-area-inset-top, 0px) !important;
        box-shadow: 12px 0 48px rgba(24, 20, 45, .32) !important;
    }
    html[dir="rtl"] body .sidebar { border-radius: 20px 0 0 20px; }
    .sidebar-overlay {
        top: 0 !important; z-index: 1290 !important;
        background: rgba(24, 20, 45, .55) !important;
        -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
    }
    /* branded drawer header */
    .sidebar-head {
        display: flex; padding: 1rem 1rem .95rem;
        background: linear-gradient(135deg, #6a3fa0 0%, #844fc1 100%); border-bottom: 0;
    }
    .sidebar-head .px-avatar { width: 44px; height: 44px; background: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .25); }
    .sidebar-head-text strong { color: #fff; font-size: .95rem; }
    .sidebar-head-text small { color: rgba(255, 255, 255, .8); }
    .sidebar-head .sidebar-close { background: rgba(255, 255, 255, .18) !important; color: #fff !important; border: 0; box-shadow: none; width: 38px; height: 38px; flex-basis: 38px; }
    .sidebar-head .sidebar-close:hover { background: rgba(255, 255, 255, .3) !important; }

    body .sidebar > nav { padding: 0 .75rem; }
    body .sidebar .nav-item.active > .nav-header::before,
    body .sidebar .direct-link.current::before { left: -.75rem; }
    .sidebar .nav-lang { display: block; }

    body .sidebar .direct-link.logout { padding-bottom: calc(.8rem + env(safe-area-inset-bottom, 0px)); margin-left: -.75rem; margin-right: -.75rem; }

    /* header strip: nothing may push the page sideways */
    .px-header { max-width: 100vw; }
    .px-actions .px-pill { display: none; }
    .px-actions .px-branch select { max-width: 110px !important; }
    .px-page-row { gap: .5rem; }

    /* page content */
    .main-content { max-width: 100vw; overflow-x: hidden; }
    .main-content > .container-fluid { padding-left: .75rem !important; padding-right: .75rem !important; }
    .main-content .card-body { padding: .9rem; }
    .main-content .table-responsive, .main-content .dataTables_wrapper { -webkit-overflow-scrolling: touch; }
}
@media (max-width: 480px) {
    .px-header .px-actions .px-icon-btn,
    .px-header .px-actions button.lang-dropdown,
    .px-header .px-actions button.profile-icon { min-width: 38px; min-height: 38px; justify-content: center; }
    .px-header .px-actions .lang-dropdown .current-lang { display: inline; }
    .lang-menu { min-width: 190px; max-height: 70vh; overflow-y: auto; }
    .lang-menu a { padding: .7rem 1rem; font-size: .88rem; }
}
@media (max-width: 360px) {
    .px-actions .px-branch { display: none; }
    body .sidebar .nav-lang-list { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
    body .sidebar .nav-header .arrow { transition: none; }
}

/* ==========================================================================
   Navigation v5: header that never overruns, branch switcher in the drawer.
   - Phones: the branch dropdown used to share the header strip with the menu
     button and slid on top of it (menu unreachable), and was hidden outright
     at 360px and below. It now lives at the top of the drawer instead.
   - Small tablets (769-1000px, sidebar still fixed): the date and currency
     pills drop out so the action row stays inside the screen.
   ========================================================================== */

/* drawer copy of the branch switcher (phones only) */
.sidebar-branch { display: none; }

@media (max-width: 1000px) {
    .px-date { display: none; }
}
@media (max-width: 900px) {
    .px-actions .currency-symbol { display: none; }
    .px-actions .px-branch select { max-width: 120px !important; }
}

@media (max-width: 768px) {
    /* header: branch lives in the drawer */
    .px-actions .px-branch, .px-actions .px-pill { display: none !important; }

    .sidebar-branch { display: block; padding: .85rem .75rem 0; }
    .sidebar-branch .px-branch {
        display: flex !important; align-items: center; gap: .6rem !important;
        width: 100%; margin: 0;
        padding: .35rem .6rem .35rem .85rem; border-radius: 12px;
        background: var(--butter-50, #f4f5f9); border: 1px solid var(--line, #e6e9f2);
    }
    .sidebar-branch .px-branch > i { flex: 0 0 auto; color: var(--blue, #844fc1); }
    .sidebar-branch .px-branch select {
        flex: 1 1 auto; width: 100%; min-width: 0; max-width: none !important; min-height: 38px;
        border: 0 !important; border-radius: 8px !important; background-color: transparent !important;
        color: var(--ink, #2e3250); font-size: .88rem !important; font-weight: 600; cursor: pointer;
    }
    .sidebar-branch .px-pill {
        display: flex !important; align-items: center; gap: .5rem; min-height: 40px;
        padding: .4rem .85rem; border-radius: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
        background: var(--butter-50, #f4f5f9); border: 1px solid var(--line, #e6e9f2);
        color: var(--ink, #2e3250); font-size: .84rem; font-weight: 600;
    }
    .sidebar-branch .px-pill i { color: var(--blue, #844fc1); }
}

@media (max-width: 480px) {
    /* the logo mark gives up its space so the menu button never competes with the actions */
    .px-brand { padding: 0 .6rem; }
    .px-brand .brand-mark { display: none; }
    .px-user-row { padding: 0 .6rem; }
}

/* header menus on phones: anchor to the header edge, not to the small button, so they can never clip */
@media (max-width: 480px) {
    .px-header .theme-selector { position: static; }
    .px-header .theme-menu { top: calc(var(--px-h1) - 8px); right: .6rem; left: auto; }
    [dir="rtl"] .px-header .theme-menu { right: auto; left: .6rem; }
    /* the older "right: 0 !important" rule above ignores RTL: in Arabic the actions sit at the left edge */
    [dir="rtl"] .lang-menu, [dir="rtl"] .profile-menu { right: auto !important; left: 0 !important; }
}
