/* MIP-006R-08 — Bilingual Public Portal (English | العربية) */
.mip-language-switcher {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    min-height: 38px;
    padding: .35rem .65rem;
    border: 1px solid rgba(0, 125, 66, .22);
    border-radius: 10px;
    background: #fff;
    white-space: nowrap;
}

.mip-language-option {
    border: 0;
    padding: .2rem .1rem;
    background: transparent;
    color: #667085;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.mip-language-option:hover,
.mip-language-option:focus-visible { color: #007d42; }
.mip-language-option.is-active { color: #007d42; font-weight: 800; }
.mip-language-divider { color: #98a2b3; }

html[dir="rtl"] body {
    direction: rtl;
    text-align: right;
    font-family: Tahoma, Arial, "Segoe UI", sans-serif;
}

html[dir="rtl"] .portal-shell { direction: rtl; }
html[dir="rtl"] .portal-sidebar { order: 2; }
html[dir="rtl"] .portal-main { order: 1; }
html[dir="rtl"] .brand-block,
html[dir="rtl"] .portal-header,
html[dir="rtl"] .header-left,
html[dir="rtl"] .header-actions,
html[dir="rtl"] .panel-heading,
html[dir="rtl"] .mip-section-heading,
html[dir="rtl"] .mip-detail-meta,
html[dir="rtl"] .portal-footer,
html[dir="rtl"] .mip-print-brand,
html[dir="rtl"] .mip-print-meta { direction: rtl; }

html[dir="rtl"] .nav-item,
html[dir="rtl"] .admin-link,
html[dir="rtl"] .signed-user,
html[dir="rtl"] .report-period,
html[dir="rtl"] .brand-copy,
html[dir="rtl"] .header-title-group,
html[dir="rtl"] .control-group,
html[dir="rtl"] .mip-kpi-card,
html[dir="rtl"] .dashboard-panel,
html[dir="rtl"] .report-banner { text-align: right; }

html[dir="rtl"] .nav-item { flex-direction: row; }
html[dir="rtl"] .mip-language-switcher { direction: ltr; }
html[dir="rtl"] .mip-language-option[lang="ar"] { font-family: Tahoma, Arial, sans-serif; }

/* Financial charts must keep chronological left-to-right plotting. */
html[dir="rtl"] canvas,
html[dir="rtl"] .mip-individual-chart-canvas,
html[dir="rtl"] .mip-chart-wrap { direction: ltr; }

html[dir="rtl"] table { direction: rtl; }
html[dir="rtl"] th,
html[dir="rtl"] td { text-align: right; }
html[dir="rtl"] th[data-sortable],
html[dir="rtl"] .numeric,
html[dir="rtl"] td.is-number { direction: ltr; unicode-bidi: isolate; }

html[dir="rtl"] input[type="search"],
html[dir="rtl"] select { text-align: right; }

@media (max-width: 900px) {
    .mip-language-switcher { order: -1; }
    html[dir="rtl"] .portal-sidebar { right: 0; left: auto; }
}

@media print {
    .mip-language-switcher { display: none !important; }
    html[dir="rtl"] .report-canvas,
    html[dir="rtl"] .mip-print-masthead,
    html[dir="rtl"] .mip-print-footer { direction: rtl; text-align: right; }
    html[dir="rtl"] canvas { direction: ltr; }
}

/* MIP-006R-08B — RTL desktop layout correction
   The portal shell is CSS Grid, so flexbox order cannot be used to swap columns. */
@media (min-width: 901px) {
    html[dir="rtl"] .portal-shell {
        direction: ltr;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 270px;
        grid-template-areas: "portal-main portal-sidebar";
    }

    html[dir="rtl"] .portal-main {
        grid-area: portal-main;
        min-width: 0;
        direction: rtl;
    }

    html[dir="rtl"] .portal-sidebar {
        grid-area: portal-sidebar;
        width: 270px;
        min-width: 270px;
        max-width: 270px;
        direction: rtl;
    }

    html[dir="rtl"] .portal-sidebar,
    html[dir="rtl"] .portal-main {
        order: initial;
    }
}

/* Keep controls readable and prevent the header from compressing. */
html[dir="rtl"] .portal-header {
    flex-direction: row-reverse;
}

html[dir="rtl"] .header-left,
html[dir="rtl"] .header-actions {
    flex-direction: row-reverse;
}

html[dir="rtl"] .header-actions {
    justify-content: flex-start;
}

html[dir="rtl"] .header-title-group,
html[dir="rtl"] .control-group {
    direction: rtl;
}

/* Keep financial cards and charts at their normal usable widths. */
html[dir="rtl"] .mip-kpi-grid,
html[dir="rtl"] .mip-individual-chart-grid {
    direction: rtl;
}

html[dir="rtl"] .mip-kpi-card,
html[dir="rtl"] .mip-individual-chart-card,
html[dir="rtl"] .dashboard-panel,
html[dir="rtl"] .report-banner {
    min-width: 0;
}

/* Sidebar icon and text alignment. */
html[dir="rtl"] .nav-item,
html[dir="rtl"] .admin-link {
    justify-content: flex-start;
}

html[dir="rtl"] .nav-icon {
    flex: 0 0 auto;
}

/* Mobile drawer must enter from the right in Arabic. */
@media (max-width: 900px) {
    html[dir="rtl"] .portal-shell {
        display: block;
        direction: rtl;
    }

    html[dir="rtl"] .portal-sidebar {
        right: -290px;
        left: auto;
        width: 270px;
        max-width: 270px;
        transition: right .22s ease;
    }

    html[dir="rtl"] .portal-sidebar.open {
        right: 0;
        left: auto;
    }

    html[dir="rtl"] .portal-header,
    html[dir="rtl"] .header-left,
    html[dir="rtl"] .header-actions {
        flex-direction: row;
    }
}

/* MIP-006R-08C — Sidebar language dropdown and text-only portal branding */
.brand-block.brand-block-text-only {
    position: relative;
    width: 100%;
    min-height: 92px;
    padding: 0 40px 22px 0;
    align-items: stretch;
}

.sidebar-portal-title {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    flex-direction: column;
    justify-content: center;
    text-decoration: none;
    color: #fff;
    line-height: 1.08;
}

.sidebar-portal-title strong,
.sidebar-portal-title span {
    display: block;
    width: 100%;
}

.sidebar-portal-title strong {
    font-size: clamp(15px, 1.15vw, 19px);
    font-weight: 800;
    letter-spacing: .07em;
}

.sidebar-portal-title span {
    margin-top: 7px;
    color: #cbd5dc;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .22em;
}

.brand-block-text-only .sidebar-close {
    position: absolute;
    top: 0;
    right: 0;
}

.sidebar-language-control {
    margin: 20px 0 4px;
}

.sidebar-language-control label {
    display: block;
    margin: 0 0 7px;
    color: #b9c5ce;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.05px;
    text-transform: uppercase;
}

.mip-language-select {
    width: 100%;
    height: 42px;
    padding: 0 36px 0 12px;
    border: 1px solid rgba(255,255,255,.17);
    border-radius: 9px;
    outline: none;
    color: #fff;
    background-color: rgba(255,255,255,.08);
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}

.mip-language-select:hover,
.mip-language-select:focus {
    border-color: rgba(217,173,69,.75);
    background-color: rgba(255,255,255,.12);
}

.mip-language-select option {
    color: #17212b;
    background: #fff;
}

/* The old horizontal header selector is no longer used. */
.portal-header .mip-language-switcher { display: none !important; }

html[dir="rtl"] .brand-block.brand-block-text-only {
    padding: 0 0 22px 40px;
}

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

html[dir="rtl"] .sidebar-portal-title strong {
    letter-spacing: 0;
}

html[dir="rtl"] .sidebar-portal-title span {
    letter-spacing: 0;
}

html[dir="rtl"] .brand-block-text-only .sidebar-close {
    right: auto;
    left: 0;
}

html[dir="rtl"] .sidebar-language-control,
html[dir="rtl"] .sidebar-language-control label {
    text-align: right;
}

html[dir="rtl"] .mip-language-select {
    direction: rtl;
    padding: 0 12px 0 36px;
    text-align: right;
}

@media (max-width: 900px) {
    .brand-block.brand-block-text-only {
        min-height: 78px;
    }

    .sidebar-portal-title strong {
        font-size: 16px;
    }
}

@media print {
    .sidebar-language-control { display: none !important; }
}
