/**
 * MDH Scoped UI RTL, DBP Jawi (`ms-Arab-MY`), Arabic (`ar-SA`), Urdu (`ur-PK`),
 * Japanese (`ja-JP`), and Soft-Clay Language Switcher Styles.
 *
 * CRITICAL ARCHITECTURAL RULE:
 *   When `body.mdh-ui-rtl` is active (Jawi, Arabic, Urdu), ONLY the UI chrome
 *   (header, menus, sidebars, filter bars, metadata labels, modals, drawers)
 *   mirrors to RTL. Every original content body (Fatwa titles, snippets,
 *   verbatim rulings, articles, Q&A answers) remains locked to `dir="auto"` / LTR
 *   so Rumi Malay & English rulings NEVER flip backwards!
 */

/* ==========================================================================
   1. SCRIPT-SPECIFIC UI TYPOGRAPHY (DBP JAWI, ARABIC, URDU, JAPANESE)
   ========================================================================== */

/* Bahasa Melayu (Jawi) — Plus Jakarta Sans FIRST so Latin/English text & numbers NEVER switch font,
   falling back to Noto Naskh Arabic ONLY for Jawi/Arabic glyphs (چ ڠ U+06A0 ڤ ݢ U+0762 ۏ U+06CF ڽ U+06BD)! */
body.mdh-lang-ms-arab-my {
    --mdh-ui-font: 'Plus Jakarta Sans', 'Noto Naskh Arabic', sans-serif;
}

/* Arabic — Plus Jakarta Sans FIRST for Latin words/numbers, Noto Naskh Arabic for Arabic script */
body.mdh-lang-ar-sa {
    --mdh-ui-font: 'Plus Jakarta Sans', 'Noto Naskh Arabic', 'Noto Sans Arabic', sans-serif;
}

/* Urdu — Plus Jakarta Sans FIRST for Latin words/numbers, Noto Nastaliq Urdu for Urdu script */
body.mdh-lang-ur-pk {
    --mdh-ui-font: 'Plus Jakarta Sans', 'Noto Nastaliq Urdu', 'Noto Naskh Arabic', sans-serif;
}

/* Japanese — Plus Jakarta Sans FIRST for Latin words/numbers, Noto Sans JP for Kana/Kanji */
body.mdh-lang-ja-jp {
    --mdh-ui-font: 'Plus Jakarta Sans', 'Noto Sans JP', sans-serif;
}

body.mdh-ui-rtl .site-header,
body.mdh-ui-rtl .site-footer,
body.mdh-ui-rtl #secondary-left,
body.mdh-ui-rtl #secondary-right,
body.mdh-ui-rtl #mobile-drawer,
body.mdh-ui-rtl #mobile-right-drawer,
body.mdh-ui-rtl #mdh-bottom-nav,
body.mdh-ui-rtl .fh-hero-card,
body.mdh-ui-rtl .fh-rail,
body.mdh-ui-rtl .fh-sidebar-rail,
body.mdh-ui-rtl .fh-toolbar,
body.mdh-ui-rtl .fh-active-chips,
body.mdh-ui-rtl .fh-pagination,
body.mdh-ui-rtl .fh-single-nav,
body.mdh-ui-rtl .fh-reader-mode-bar,
body.mdh-ui-rtl .fh-meta-strip,
body.mdh-ui-rtl .fh-prov-summary,
body.mdh-ui-rtl .fh-source-actions,
body.mdh-ui-rtl .fh-side-card,
body.mdh-ui-rtl .fh-cd-popover,
body.mdh-ui-rtl .mdh-lang-popover,
body.mdh-lang-ja-jp .site-header,
body.mdh-lang-ja-jp .fh-hero-card,
body.mdh-lang-ja-jp .fh-sidebar-rail {
    font-family: var(--mdh-ui-font, 'Plus Jakarta Sans', sans-serif);
}

/* Preserve MDH brand serif/sans lockup & keep #tag pills strictly LTR so #tazkiyah never flips to tazkiyah# */
body.mdh-ui-rtl #sidebar-tag-cloud a,
body.mdh-ui-rtl .fh-kw-pill,
body.mdh-ui-rtl .entry-footer a[href*="/tag/"] {
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-flex;
    align-items: center;
}

/* Give Jawi & Urdu extra line-height inside pills, buttons, and dropdown options so 3-dot diacritics never clip */
body.mdh-lang-ms-arab-my .fh-cd-trigger,
body.mdh-lang-ms-arab-my .fh-cd-option,
body.mdh-lang-ms-arab-my .primary-nav-item,
body.mdh-lang-ms-arab-my .fh-facet-btn,
body.mdh-lang-ur-pk .fh-cd-trigger,
body.mdh-lang-ur-pk .fh-cd-option,
body.mdh-lang-ur-pk .primary-nav-item,
body.mdh-lang-ur-pk .fh-facet-btn {
    line-height: 1.75;
}

/* ==========================================================================
   2. SCOPED CONTAINER RTL MIRRORING (UI CHROME ONLY)
   ========================================================================== */
body.mdh-ui-rtl #masthead .header-inner,
body.mdh-ui-rtl #colophon,
body.mdh-ui-rtl #secondary-left,
body.mdh-ui-rtl #secondary-right,
body.mdh-ui-rtl #mobile-drawer .mdh-drawer-panel,
body.mdh-ui-rtl #mobile-right-drawer .mdh-drawer-panel,
body.mdh-ui-rtl #mdh-bottom-nav,
body.mdh-ui-rtl #mobile-search-sheet .mdh-sheet-panel,
body.mdh-ui-rtl #bookmarks-modal .mdh-sheet-panel,
body.mdh-ui-rtl #customizer-modal .mdh-sheet-panel,
body.mdh-ui-rtl #fcom-notifications-modal .mdh-sheet-panel,
body.mdh-ui-rtl .fh-hero-card,
body.mdh-ui-rtl .fh-rail,
body.mdh-ui-rtl .fh-toolbar,
body.mdh-ui-rtl .fh-active-chips,
body.mdh-ui-rtl .fh-pagination,
body.mdh-ui-rtl .fh-mobile-dock,
body.mdh-ui-rtl #fh-filter-sheet .fh-sheet-panel,
body.mdh-ui-rtl .fh-single-nav,
body.mdh-ui-rtl .fh-doc-badges,
body.mdh-ui-rtl .fh-meta-strip,
body.mdh-ui-rtl .fh-reader-mode-bar,
body.mdh-ui-rtl .fh-share-bar,
body.mdh-ui-rtl #fh-record-details-card,
body.mdh-ui-rtl .fh-cd-popover,
body.mdh-ui-rtl .fh-card-meta-top,
body.mdh-ui-rtl .fh-card-footer {
    direction: rtl;
}

/* STRICT CONTENT ISOLATION: Keep all original Fatwa titles, snippets, rulings, authorities, IDs & article bodies untouched! */
body.mdh-ui-rtl .fh-card-title,
body.mdh-ui-rtl .fh-card-snippet,
body.mdh-ui-rtl .fh-card-authority,
body.mdh-ui-rtl .fh-doc-title,
body.mdh-ui-rtl .fh-verbatim-body,
body.mdh-ui-rtl .fh-raw-pre,
body.mdh-ui-rtl .fh-q-body,
body.mdh-ui-rtl .fh-rel-title,
body.mdh-ui-rtl .fh-direct-url-link,
body.mdh-ui-rtl .fh-sha-hash,
body.mdh-ui-rtl code,
body.mdh-ui-rtl .fh-mono,
body.mdh-ui-rtl .entry-title,
body.mdh-ui-rtl .entry-content,
body.mdh-ui-rtl .site-title {
    direction: ltr;
    text-align: left;
    unicode-bidi: isolate;
}

/* Keep metadata VALUES in original script direction while metadata LABELS follow UI RTL */
body.mdh-ui-rtl .fh-meta-val:not(.fh-meta-link),
body.mdh-ui-rtl .fh-kv-val {
    direction: auto;
    unicode-bidi: plaintext;
}

/* Flip directional arrows inside UI navigation buttons when in RTL UI */
body.mdh-ui-rtl .fh-back-pill .ph-arrow-left,
body.mdh-ui-rtl .fh-read-btn .ph-arrow-right,
body.mdh-ui-rtl #fh-prev-page .ph-arrow-left,
body.mdh-ui-rtl #fh-next-page .ph-arrow-right {
    transform: scaleX(-1);
}

/* Fix search icon padding inside RTL header & fatwa search bars */
body.mdh-ui-rtl .fh-search-box .fh-search-icon {
    left: auto;
    right: 1rem;
}
body.mdh-ui-rtl .fh-search-box .fh-search-input {
    padding-left: 2.6rem;
    padding-right: 2.85rem;
}
body.mdh-ui-rtl .fh-search-box .fh-clear-btn {
    right: auto;
    left: 0.7rem;
}

/* ==========================================================================
   3. SOFT-CLAY LANGUAGE SWITCHER POPOVER / BOTTOM SHEET & WORKSPACE PILL
   ========================================================================== */
.mdh-hdr-lang-btn {
    border: 1px solid rgba(255, 255, 255, 0.85);
}

.mdh-hdr-lang-btn:hover {
    border-color: rgba(53, 105, 85, 0.35);
    background: rgba(255, 255, 255, 0.96);
}

.mdh-lang-portal {
    position: fixed;
    inset: 0;
    z-index: 100020;
    pointer-events: none;
}

.mdh-lang-portal.fh-hidden {
    display: none !important;
}

.mdh-lang-portal.is-open {
    pointer-events: auto;
}

.mdh-lang-backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
}

.mdh-lang-popover {
    position: fixed;
    width: 310px;
    max-width: calc(100vw - 24px);
    max-height: min(460px, 78vh);
    display: flex;
    flex-direction: column;
    background: rgba(250, 252, 250, 0.98);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(53, 105, 85, 0.22);
    border-radius: 20px;
    box-shadow: 0 20px 44px -10px rgba(24, 42, 34, 0.22), 0 4px 12px rgba(24, 42, 34, 0.08), inset 0 1px 0 #FFFFFF;
    overflow: hidden;
    animation: mdhLangPopIn 0.16s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes mdhLangPopIn {
    from { opacity: 0; transform: translateY(-5px) scale(0.985); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.mdh-lang-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid rgba(42, 50, 46, 0.08);
    background: rgba(235, 243, 238, 0.6);
}

.mdh-lang-head-title {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #2B4C3F;
}

.mdh-lang-close {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.85);
    color: #4A5A52;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.mdh-lang-list {
    overflow-y: auto;
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mdh-lang-opt {
    width: 100%;
    border: none;
    background: transparent;
    padding: 0.52rem 0.68rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.13s ease;
}

.mdh-lang-opt:hover {
    background: rgba(53, 105, 85, 0.09);
}

.mdh-lang-opt.is-active {
    background: linear-gradient(135deg, #2E5E4B 0%, #3D7A62 100%);
    color: #FFFFFF;
    box-shadow: 0 4px 10px -2px rgba(46, 94, 75, 0.32);
}

.mdh-lang-opt-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.mdh-lang-badge {
    min-width: 34px;
    height: 24px;
    padding: 0 6px;
    border-radius: 7px;
    background: rgba(53, 105, 85, 0.11);
    color: #264E3E;
    font-size: 0.69rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mdh-lang-opt.is-active .mdh-lang-badge {
    background: rgba(255, 255, 255, 0.22);
    color: #FFFFFF;
}

.mdh-lang-names {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.mdh-lang-native {
    font-size: 0.83rem;
    font-weight: 700;
    color: #1E2823;
    line-height: 1.35;
}

.mdh-lang-opt.is-active .mdh-lang-native {
    color: #FFFFFF;
}

.mdh-lang-sub {
    font-size: 0.69rem;
    color: #64746C;
    line-height: 1.2;
}

.mdh-lang-opt.is-active .mdh-lang-sub {
    color: rgba(255, 255, 255, 0.82);
}

.mdh-lang-rtl-tag {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0.1rem 0.38rem;
    border-radius: 999px;
    background: rgba(217, 119, 6, 0.12);
    color: #B45309;
}

.mdh-lang-opt.is-active .mdh-lang-rtl-tag {
    background: rgba(255, 255, 255, 0.2);
    color: #FEF3C7;
}

@media (max-width: 639px) {
    .mdh-lang-backdrop {
        background: rgba(20, 32, 26, 0.42);
        backdrop-filter: blur(3px);
    }
    .mdh-lang-popover {
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 76vh;
        border-radius: 24px 24px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 12px);
    }
}

/* Admin Workspace Compact EN | BM Topbar Switcher Pill */
.mdh-adm-lang-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 5px 3px 8px;
    border-radius: 999px;
    background: rgba(232, 240, 235, 0.9);
    border: 1px solid rgba(53, 105, 85, 0.18);
    color: #35584B;
    font-size: 12px;
}

.mdh-adm-lang-btn {
    border: none;
    background: transparent;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    color: #485B52;
    cursor: pointer;
    transition: all 0.15s ease;
}

.mdh-adm-lang-btn:hover {
    color: #1E2E26;
}

.mdh-adm-lang-btn.is-active {
    background: #2E5E4B;
    color: #FFFFFF;
    box-shadow: 0 2px 6px rgba(46, 94, 75, 0.25);
}
