/* 
 * RTL (Right-to-Left) Styles for Arabic Language
 * Applied when LANGUAGE_CODE = 'ar'
 * Bootstrap RTL is loaded, these are custom overrides
 */

/* Text alignment fixes */
[dir="rtl"] .text-start {
    text-align: right !important;
}

[dir="rtl"] .text-end {
    text-align: left !important;
}

/* Sidebar positioning — owner layout only */
[dir="rtl"] .owner-layout #sidebar {
    right: 0;
    left: auto;
}

[dir="rtl"] .owner-layout #main-content {
    margin-right: 280px;
    margin-left: 0;
}

/* Authenticated dashboard: no sidebar, full-width layout */
[dir="rtl"] .content-wrapper {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .container-fluid {
    padding-right: 1.5rem;
    padding-left: 1.5rem;
}

/* Dropdown menus */
[dir="rtl"] .dropdown-menu {
    right: 0;
    left: auto;
}

/* Badge positioning */
[dir="rtl"] .badge {
    margin-left: 0;
    margin-right: 0.5rem;
}

/* Icons spacing */
[dir="rtl"] .bi {
    margin-left: 0.5rem;
    margin-right: 0;
}

[dir="rtl"] i.me-2 {
    margin-right: 0 !important;
    margin-left: 0.5rem !important;
}

[dir="rtl"] i.ms-2 {
    margin-left: 0 !important;
    margin-right: 0.5rem !important;
}

/* Form labels */
[dir="rtl"] label {
    text-align: right;
}

/* Breadcrumb */
[dir="rtl"] .breadcrumb-item + .breadcrumb-item::before {
    float: right;
    padding-right: 0;
    padding-left: 0.5rem;
    content: "/";
}

/* Navbar brand */
[dir="rtl"] .navbar-brand {
    margin-right: 0;
    margin-left: 1rem;
}

/* Card spacing */
[dir="rtl"] .card-body {
    text-align: right;
}

/* Tables */
[dir="rtl"] table {
    text-align: right;
}

[dir="rtl"] th,
[dir="rtl"] td {
    text-align: right;
}

/* List groups */
[dir="rtl"] .list-group-item {
    text-align: right;
}

/* Pagination */
[dir="rtl"] .pagination {
    direction: rtl;
}

/* Modal */
[dir="rtl"] .modal-header .btn-close {
    margin: 0 auto 0 0;
}

/* Offcanvas sidebar for mobile */
[dir="rtl"] .offcanvas-start {
    right: 0;
    left: auto;
    transform: translateX(100%);
}

[dir="rtl"] .offcanvas-start.show {
    transform: translateX(0);
}

/* Toast notifications */
[dir="rtl"] .toast {
    text-align: right;
}

/* Progress bars */
[dir="rtl"] .progress-bar {
    direction: ltr;
}

/* Input groups */
[dir="rtl"] .input-group > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-right: -1px;
    margin-left: 0;
}

/* Button groups */
[dir="rtl"] .btn-group > .btn:not(:last-child):not(.dropdown-toggle) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: 0.25rem;
    border-bottom-right-radius: 0.25rem;
}

/* Custom Dashboard Spacing */
[dir="rtl"] .dashboard-card {
    text-align: right;
}

[dir="rtl"] .stat-icon {
    float: left;
    margin-right: 0;
    margin-left: 1rem;
}

/* Planning workflow */
[dir="rtl"] .planning-step {
    text-align: right;
}

[dir="rtl"] .step-number {
    float: left;
}

/* Project cards */
[dir="rtl"] .project-card .project-meta {
    text-align: right;
}

/* Grant matching score */
[dir="rtl"] .match-score {
    float: left;
}

/* Document list */
[dir="rtl"] .document-icon {
    margin-right: 0;
    margin-left: 0.75rem;
}

/* Timeline */
[dir="rtl"] .timeline::before {
    right: 20px;
    left: auto;
}

[dir="rtl"] .timeline-item {
    padding-right: 50px;
    padding-left: 0;
}

[dir="rtl"] .timeline-marker {
    right: 11px;
    left: auto;
}

/* Responsive mobile adjustments */
@media (max-width: 991px) {
    [dir="rtl"] .owner-layout #main-content {
        margin-right: 0;
    }

    [dir="rtl"] .offcanvas-mobile {
        right: 0;
        left: auto;
    }
}

/* Font adjustments for Arabic */
[dir="rtl"] body {
    font-family: 'Segoe UI', Tahoma, 'Noto Sans Arabic', 'Arial', sans-serif;
}

[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, 
[dir="rtl"] h4, [dir="rtl"] h5, [dir="rtl"] h6 {
    font-weight: 600;
}

[dir="rtl"] .mg-navbar .ms-lg-3 {
    margin-left: 0 !important;
    margin-right: 1rem !important;
}

[dir="rtl"] .mg-hero,
[dir="rtl"] .mg-page-header,
[dir="rtl"] .section-header,
[dir="rtl"] .mg-card,
[dir="rtl"] .benefit-card,
[dir="rtl"] .workflow-step,
[dir="rtl"] .testimonial-card,
[dir="rtl"] .faq-item {
    text-align: right;
}

[dir="rtl"] .mg-hero .lead {
    margin-right: 0;
    margin-left: auto;
}

[dir="rtl"] .mg-hero .hero-badge {
    direction: rtl;
}

[dir="rtl"] .mg-hero .hero-stats {
    flex-direction: row-reverse;
}

[dir="rtl"] .benefit-card {
    flex-direction: row-reverse;
}

[dir="rtl"] .workflow-step .step-number {
    right: auto;
    left: 8px;
}

[dir="rtl"] .testimonial-card::before {
    left: auto;
    right: 1.5rem;
}

[dir="rtl"] .mg-footer .social-links a {
    margin-right: 0;
    margin-left: 0.5rem;
}

/* Public website RTL centering (navbar + hero) */
@media (min-width: 992px) {
    [dir="rtl"] body.mg-public .mg-navbar .container {
        position: relative;
    }

    [dir="rtl"] body.mg-public .mg-navbar .navbar-collapse {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        flex: 1 1 auto;
    }

    [dir="rtl"] body.mg-public .mg-navbar .navbar-nav {
        flex: 1 1 auto;
        justify-content: center;
        margin-right: 0 !important;
        margin-left: 0 !important;
    }

    [dir="rtl"] body.mg-public .mg-navbar .mg-nav-actions {
        margin-right: 1rem !important;
        margin-left: 0 !important;
        width: auto !important;
    }

    [dir="rtl"] body.mg-public .mg-hero .col-lg-6:first-child {
        text-align: center;
    }

    [dir="rtl"] body.mg-public .mg-hero h1,
    [dir="rtl"] body.mg-public .mg-hero .lead,
    [dir="rtl"] body.mg-public .mg-hero .hero-badge,
    [dir="rtl"] body.mg-public .mg-hero .hero-stats,
    [dir="rtl"] body.mg-public .mg-hero .d-flex {
        margin-right: auto;
        margin-left: auto;
    }

    [dir="rtl"] body.mg-public .mg-hero .d-flex,
    [dir="rtl"] body.mg-public .mg-hero .hero-stats {
        justify-content: center;
    }
}

@media (min-width: 1200px) {
    [dir="rtl"] body.mg-public .mg-navbar #publicNav {
        position: static;
    }

    [dir="rtl"] body.mg-public .mg-navbar #publicNav .navbar-nav {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        width: max-content;
        flex: 0 0 auto;
        justify-content: center;
        margin: 0 !important;
        z-index: 1;
    }

    [dir="rtl"] body.mg-public .mg-navbar #publicNav .mg-nav-actions {
        margin-right: auto !important;
        position: relative;
        z-index: 2;
    }
}

@media (max-width: 768px) {
    [dir="rtl"] .mg-hero .hero-stats {
        flex-direction: column;
    }
}

/* ── Workspace tables + Arabic stack (PROMPT 6) ── */
[dir="rtl"] .mg-app-layout main#main-content.main-content table.table:not(.table-borderless) thead th,
[dir="rtl"] .mg-app-layout main#main-content.main-content table.table:not(.table-borderless) tbody td,
[dir="rtl"] .owner-admin main#main-content table.table:not(.table-borderless) thead th,
[dir="rtl"] .owner-admin main#main-content table.table:not(.table-borderless) tbody td {
    text-align: right;
}

[dir="rtl"] table.data-table thead th,
[dir="rtl"] table.data-table tbody td {
    text-align: right;
}

[dir="rtl"] body.mg-app-shell .mg-app-layout {
    font-family: "Noto Sans Arabic", var(--font-primary), system-ui, sans-serif;
}

[dir="rtl"] #mg-page-tip-toast {
    left: auto !important;
    right: 0.75rem !important;
}

/* ── Public marketing (sovereign home / nav) — AUDIT PROMPT 2 RTL pass ── */
[dir="rtl"] body.mg-public #navbar.mg-sovereign-navbar .navbar-links .nav-link {
    font-family: var(--font-arabic, "Noto Sans Arabic", system-ui, sans-serif);
}

[dir="rtl"] body.mg-public .hero.mg-hero-command .hero-headline,
[dir="rtl"] body.mg-public .hero.mg-hero-command .hero-subhead {
    text-align: right;
}

[dir="rtl"] body.mg-public .hero.mg-hero-command .btn-arrow::after {
    content: "←";
}

[dir="rtl"] body.mg-public .hero.mg-hero-command .float-card-1 {
    right: auto;
    left: -20px;
    top: -16px;
}

[dir="rtl"] body.mg-public .hero.mg-hero-command .float-card-2 {
    left: auto;
    right: -20px;
    bottom: 30px;
}

[dir="rtl"] body.mg-public .home-problem .section-label::before,
[dir="rtl"] body.mg-public .home-solution .section-label::before,
[dir="rtl"] body.mg-public .home-features .section-label::before,
[dir="rtl"] body.mg-public .home-ai-approach .section-label::before,
[dir="rtl"] body.mg-public .home-cta-banner .section-label::before {
    margin-right: 0;
    margin-left: 8px;
}

/* ── Public marketing: Arabic mobile readability (BUG 3) ── */
@media (max-width: 768px) {
    [dir="rtl"] body.mg-public {
        font-family: "Noto Sans Arabic", var(--font-body, "DM Sans"), system-ui, sans-serif;
        text-align: right;
        text-rendering: optimizeLegibility;
        -webkit-font-smoothing: antialiased;
    }

    [dir="rtl"] body.mg-public .container:not(.container-fluid) {
        direction: rtl;
        text-align: right;
    }

    [dir="rtl"] body.mg-public #navbar.mg-sovereign-navbar .container,
    [dir="rtl"] body.mg-public nav#navbar .container,
    [dir="rtl"] body.mg-public #navbar.mg-sovereign-navbar .container-fluid,
    [dir="rtl"] body.mg-public nav#navbar .container-fluid {
        direction: rtl;
    }

    [dir="rtl"] body.mg-public section.hero.mg-hero-command .hero-content {
        text-align: right;
        direction: rtl;
    }

    [dir="rtl"] body.mg-public section.hero.mg-hero-command .hero-ctas {
        flex-direction: row-reverse;
        justify-content: flex-end;
    }

    [dir="rtl"] body.mg-public .section-label {
        flex-direction: row-reverse;
    }

    [dir="rtl"] body.mg-public .home-feature-card,
    [dir="rtl"] body.mg-public .home-problem-card {
        text-align: right;
    }

    [dir="rtl"] body.mg-public #navbar .navbar-links .nav-link,
    [dir="rtl"] body.mg-public #mobile-menu .nav-link {
        font-family: "Noto Sans Arabic", var(--font-body, sans-serif);
    }

    /* Ensure Arabic glyph-capable font on small screens to avoid fallback '?' boxes. */
    [dir="rtl"] body.mg-public,
    [dir="rtl"] body.mg-public *:not(.bi):not([class*="icon"]) {
        font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
    }

    [dir="rtl"] body.mg-public section.hero.mg-hero-command .float-card {
        display: none;
    }

    [dir="rtl"] body.mg-public section.hero.mg-hero-command .btn-arrow::after {
        content: "\2190";
    }

    [dir="rtl"] body.mg-public section.hero.mg-hero-command .hero-headline,
    [dir="rtl"] body.mg-public section.hero.mg-hero-command .hero-subhead,
    [dir="rtl"] body.mg-public .home-section-h2,
    [dir="rtl"] body.mg-public .home-pillar-title {
        text-align: right;
        direction: rtl;
    }

    [dir="rtl"] body.mg-public footer.mg-footer-sovereign .mg-footer-sovereign-grid {
        direction: rtl;
        text-align: right;
    }

    [dir="rtl"] body.mg-public .home-problem-cards,
    [dir="rtl"] body.mg-public .home-features-grid,
    [dir="rtl"] body.mg-public .home-ai-approach-grid {
        direction: rtl;
    }

    [dir="rtl"] body.mg-public,
    [dir="rtl"] body.mg-public main,
    [dir="rtl"] body.mg-public section {
        max-width: 100%;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
}

