/* ═══════════════════════════════════════════════════════════════════════════
   arabic-font.css — S45.85
   Unified Arabic typography across the entire platform.

   Problem: pages inconsistently apply Arabic fonts. Some use Noto Kufi Arabic,
   some fall back to system fonts (Tahoma, Arial), and inline-styled elements
   sometimes override with Orbitron/Outfit which doesn't render Arabic well.

   Fix: when the document is in Arabic (lang="ar" or dir="rtl"), force every
   text element to use Noto Kufi Arabic with a clean fallback stack.

   Load order: must load LAST so its !important rules win the cascade.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Root font stack when Arabic ── */
html[lang="ar"],
html[lang="ar"] body,
[dir="rtl"],
[dir="rtl"] body {
    font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', 'Cairo',
                 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif !important;
    letter-spacing: 0;
}

/* ── 2. Override common decorative-font selectors that don't render Arabic well ── */
/* The platform uses Orbitron + Outfit for headings in English context — those fonts
   don't have Arabic glyphs, so browsers fall back to the system font (often Tahoma).
   This rule forces Noto Kufi Arabic everywhere in Arabic context. */
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4, [dir="rtl"] h5, [dir="rtl"] h6,
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3, html[lang="ar"] h4, html[lang="ar"] h5, html[lang="ar"] h6 {
    font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', system-ui, sans-serif !important;
    letter-spacing: 0 !important;
    line-height: 1.5;
}

/* ── 3. Body text + paragraphs ── */
[dir="rtl"] p, [dir="rtl"] span, [dir="rtl"] div, [dir="rtl"] a,
[dir="rtl"] li, [dir="rtl"] td, [dir="rtl"] th,
[dir="rtl"] label, [dir="rtl"] button,
html[lang="ar"] p, html[lang="ar"] span, html[lang="ar"] div, html[lang="ar"] a,
html[lang="ar"] li, html[lang="ar"] td, html[lang="ar"] th,
html[lang="ar"] label, html[lang="ar"] button {
    font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', system-ui, sans-serif !important;
}

/* ── 4. Form inputs ── */
[dir="rtl"] input, [dir="rtl"] textarea, [dir="rtl"] select,
html[lang="ar"] input, html[lang="ar"] textarea, html[lang="ar"] select {
    font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', system-ui, sans-serif !important;
}

/* ── 5. Refined line-height for Arabic — characters benefit from more breathing room ── */
[dir="rtl"] body,
html[lang="ar"] body {
    line-height: 1.7;
}

/* ── 6. Preserve monospace + code blocks (these should stay LTR with mono font) ── */
[dir="rtl"] code, [dir="rtl"] pre, [dir="rtl"] kbd, [dir="rtl"] samp,
html[lang="ar"] code, html[lang="ar"] pre, html[lang="ar"] kbd, html[lang="ar"] samp,
[dir="rtl"] .font-mono, [dir="rtl"] .lib-formula,
[dir="rtl"] [class*="mono"], [dir="rtl"] [style*="JetBrains"],
[dir="rtl"] [style*="font-mono"] {
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace !important;
    direction: ltr;
    unicode-bidi: embed;
}

/* ── 7. Preserve LTR-only sections (e.g. URLs, code snippets, English-only labels) ── */
[dir="rtl"] [dir="ltr"] {
    direction: ltr;
    unicode-bidi: embed;
}

/* ── 8. Tighter font-weight scale for Arabic (Kufi looks too heavy at 700+) ── */
[dir="rtl"] h1, html[lang="ar"] h1 { font-weight: 700 !important; }
[dir="rtl"] h2, html[lang="ar"] h2 { font-weight: 700 !important; }
[dir="rtl"] h3, html[lang="ar"] h3 { font-weight: 500 !important; }
[dir="rtl"] strong, [dir="rtl"] b,
html[lang="ar"] strong, html[lang="ar"] b { font-weight: 600 !important; }

/* ── 9. Reset Orbitron/Rajdhani/decorative-font holdouts inside Arabic context ── */
[dir="rtl"] [style*="Orbitron"],
[dir="rtl"] [style*="Rajdhani"],
[dir="rtl"] [style*="font-display"],
[dir="rtl"] [class*="orbitron"],
[dir="rtl"] [class*="rajdhani"],
html[lang="ar"] [style*="Orbitron"],
html[lang="ar"] [style*="Rajdhani"],
html[lang="ar"] [style*="font-display"] {
    font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', sans-serif !important;
    letter-spacing: 0 !important;
}

/* ── 10. Smoother text rendering for Arabic ── */
[dir="rtl"] body, html[lang="ar"] body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ── 11. Breadcrumb separator direction (RTL) ──────────────────────────────
   Many pages hardcode a right-pointing "›" breadcrumb separator. In Arabic
   (RTL) that should point left. Every breadcrumb separator now carries the
   .bc-sep class; this one rule mirrors the glyph in RTL so it points the
   correct way, without editing each page's markup further. */
[dir="rtl"] .bc-sep,
html[lang="ar"] .bc-sep {
    display: inline-block;
    transform: scaleX(-1);
}

/* ── 12. Dropdown (select/option) styling + Arabic font ────────────────────
   Native <option> elements render with browser defaults (often a blue
   highlight and the system font). These rules bring the open dropdown list
   in line with the platform theme and enforce Tajawal in Arabic. Note:
   browsers limit how much <option> can be styled, but background, color and
   font-family are widely supported on desktop. */
[dir="rtl"] option, html[lang="ar"] option,
[dir="rtl"] select, html[lang="ar"] select {
    font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', system-ui, sans-serif !important;
}

/* Theme the option list to match the dark UI (and light mode below). */
select.form-input option,
.form-input option,
select option {
    background-color: #0d1117;
    color: #e6edf3;
    padding: 8px 12px;
}
/* Light theme: white list with dark text. */
[data-theme="light"] select.form-input option,
[data-theme="light"] .form-input option,
[data-theme="light"] select option {
    background-color: #ffffff;
    color: #1a2733;
}
/* Highlighted / selected option — use the brand green instead of default blue. */
select.form-input option:checked,
.form-input option:checked,
select option:checked,
select.form-input option:hover,
.form-input option:hover {
    background: linear-gradient(#00a862, #00a862);
    background-color: #00a862 !important;
    color: #ffffff !important;
}

/* ── 13. Custom dropdown component (custom-select.js) ──────────────────────
   Fully styleable replacement for native <select> option lists, which browsers
   (esp. macOS) refuse to theme. The native <select> stays in the DOM for form
   submission and is visually hidden; a styled button + menu sit on top. */
.cs-wrap { position: relative; display: block; width: 100%; }
.cs-wrap > select[data-cs] {
    position: absolute; width: 1px; height: 1px; opacity: 0;
    pointer-events: none; margin: 0; padding: 0; border: 0;
}
.cs-btn {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    gap: 10px; cursor: pointer; text-align: inherit;
    font-family: inherit; font-size: 14px; line-height: 1.4;
    color: var(--text-primary, #e8e8e8);
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-subtle, rgba(255,255,255,0.12));
    border-radius: var(--radius-sm, 10px);
    padding: 12px 16px; transition: border-color .15s, box-shadow .15s, background .15s;
}
.cs-btn:hover { border-color: rgba(0,255,136,0.35); }
.cs-wrap.cs-open .cs-btn {
    border-color: var(--accent-green, #00ff88);
    box-shadow: 0 0 0 3px rgba(0,255,136,0.10);
    background: rgba(0,255,136,0.02);
}
.cs-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-lbl.cs-placeholder { color: var(--text-dim, #64748b); }
.cs-caret { font-size: 11px; color: var(--text-dim, #94a3b8); transition: transform .18s; flex: 0 0 auto; }
.cs-wrap.cs-open .cs-caret { transform: rotate(180deg); color: var(--accent-green, #00ff88); }

.cs-menu {
    position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 4000;
    background: var(--bg-card, #0f1319);
    border: 1px solid var(--border-subtle, rgba(255,255,255,0.12));
    border-radius: 12px; padding: 6px;
    box-shadow: 0 18px 50px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
    max-height: 260px; overflow-y: auto;
    display: none; -webkit-overflow-scrolling: touch;
}
.cs-menu.cs-up { top: auto; bottom: calc(100% + 6px); }
.cs-wrap.cs-open .cs-menu { display: block; animation: csIn .14s ease; }
@keyframes csIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.cs-opt {
    padding: 10px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
    color: var(--text-primary, #e8e8e8);
    transition: background .12s, color .12s;
    white-space: normal; line-height: 1.45;
}
.cs-opt:hover { background: rgba(0,255,136,0.10); color: var(--accent-green, #00ff88); }
.cs-opt.cs-sel {
    background: var(--accent-green, #00a862);
    color: #06210f; font-weight: 700;
}
.cs-opt.cs-sel:hover { background: var(--accent-green, #00a862); color: #06210f; }
.cs-opt.cs-placeholder-opt { color: var(--text-dim, #64748b); }
.cs-opt.cs-disabled { opacity: .45; cursor: not-allowed; }

/* Custom scrollbar for the menu. */
.cs-menu::-webkit-scrollbar { width: 8px; }
.cs-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 8px; }

/* Light theme. */
[data-theme="light"] .cs-btn { background: rgba(0,0,0,0.02); color: #1a2733; border-color: rgba(0,0,0,0.12); }
[data-theme="light"] .cs-menu { background: #ffffff; border-color: #e2e8f0; box-shadow: 0 18px 50px rgba(0,0,0,0.12); }
[data-theme="light"] .cs-opt { color: #1a2733; }
[data-theme="light"] .cs-opt:hover { background: rgba(0,168,98,0.10); color: #00784a; }
[data-theme="light"] .cs-opt.cs-sel { background: #00a862; color: #ffffff; }
[data-theme="light"] .cs-menu::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); }

/* RTL: align caret/text correctly. */
[dir="rtl"] .cs-btn { text-align: right; }
[dir="rtl"] .cs-opt { text-align: right; }

/* Arabic font on the component. */
[dir="rtl"] .cs-btn, [dir="rtl"] .cs-opt, [dir="rtl"] .cs-lbl,
html[lang="ar"] .cs-btn, html[lang="ar"] .cs-opt, html[lang="ar"] .cs-lbl {
    font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Kufi Arabic', system-ui, sans-serif !important;
}

/* ── 14. Mobile header actions overflow fix ───────────────────────────────
   On narrow phones the header action row (theme, bell, AI, search, language,
   login/register, hamburger) was wider than the viewport, so items past the
   right edge were clipped by body{overflow-x:hidden} — the language switch and
   others "disappeared" in portrait but showed in landscape (more width).
   Fix: let the actions shrink to fit and keep everything reachable. */
@media (max-width: 640px) {
    .site-header .header-inner {
        gap: 4px;
        flex-wrap: nowrap;
    }
    .site-header .header-actions {
        gap: 2px !important;
        flex-wrap: nowrap;
        min-width: 0;              /* allow the row to shrink instead of overflow */
        margin-inline-start: auto; /* keep it pinned to the end edge */
    }
    /* Compact the icon buttons so more fit on a phone. */
    .site-header .header-actions .theme-toggle,
    .site-header .header-actions .hdr-msg-icon,
    .site-header .header-actions .hdr-ai-btn {
        width: 32px !important;
        height: 32px !important;
        padding: 0 !important;
        font-size: 14px !important;
        flex: 0 0 auto;
    }
    /* Keep the language switch visible and tidy. */
    .site-header .header-actions a.btn-ghost {
        padding: 5px 8px !important;
        font-size: 10px !important;
        white-space: nowrap;
        flex: 0 0 auto;
    }
    /* Logo shouldn't eat all the width. */
    .site-header .logo .site-logo-img { max-height: 44px !important; }
    /* Ensure the hamburger is always visible and last. */
    .site-header .header-actions .mobile-nav-btn {
        display: inline-flex !important;
        flex: 0 0 auto;
        order: 99;
    }
}
/* Very small phones: drop the least-essential icons (search, survey) but ALWAYS
   keep language, theme, notifications and the hamburger reachable. */
@media (max-width: 400px) {
    .site-header .header-actions #searchToggleBtn,
    .site-header .header-actions #svHeaderBtn { display: none !important; }
}
