/* ==========================================================================
   EReceipt Dashboard - Comprehensive RTL & Arabic Styling
   Google Font Cairo + Native Bootstrap 5 RTL Mirroring
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

html[dir="rtl"] body {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
    text-align: right;
    direction: rtl;
}

/* Typography adjustments for Arabic */
html[dir="rtl"] h1, html[dir="rtl"] h2, html[dir="rtl"] h3, 
html[dir="rtl"] h4, html[dir="rtl"] h5, html[dir="rtl"] h6,
html[dir="rtl"] .fw-bold, html[dir="rtl"] .fw-semibold {
    font-family: 'Cairo', sans-serif !important;
}

/* Sidebar in RTL */
html[dir="rtl"] #portal-sidebar {
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.05);
}

html[dir="rtl"] #portal-sidebar .sub-nav-link {
    border-left: none;
    border-right: 3px solid transparent;
}

html[dir="rtl"] #portal-sidebar .sub-nav-link.active {
    border-right-color: #3b82f6;
    border-left-color: transparent;
}

html[dir="rtl"] #portal-sidebar .nav-links .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

html[dir="rtl"] #portal-sidebar .nav-links .nav-link i {
    margin-left: 0.25rem;
    margin-right: 0;
}

/* Topbar in RTL */
html[dir="rtl"] #portal-topbar {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

html[dir="rtl"] .topbar-left,
html[dir="rtl"] .topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Dropdown menus align right in RTL */
html[dir="rtl"] .dropdown-menu {
    text-align: right;
}

html[dir="rtl"] .dropdown-menu-end {
    --bs-position: start;
    right: auto !important;
    left: 0 !important;
}

/* Badges & Pills */
html[dir="rtl"] .badge i,
html[dir="rtl"] .btn i {
    margin-left: 0.35rem;
    margin-right: 0;
}

/* Form controls & Input groups */
html[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;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: 0.375rem;
    border-bottom-left-radius: 0.375rem;
}

html[dir="rtl"] .input-group > :not(:last-child):not(.dropdown-menu) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: 0.375rem;
    border-bottom-right-radius: 0.375rem;
}

html[dir="rtl"] .form-select {
    background-position: left 0.75rem center;
    padding-left: 2.25rem;
    padding-right: 0.75rem;
}

/* Form switches */
html[dir="rtl"] .form-switch {
    padding-right: 2.5em;
    padding-left: 0;
}

html[dir="rtl"] .form-switch .form-check-input {
    float: right;
    margin-right: -2.5em;
    margin-left: 0;
    background-position: right center;
}

html[dir="rtl"] .form-check {
    padding-right: 1.5em;
    padding-left: 0;
}

html[dir="rtl"] .form-check .form-check-input {
    float: right;
    margin-right: -1.5em;
    margin-left: 0;
}

/* Modal close button in RTL */
html[dir="rtl"] .modal-header .btn-close {
    margin: -0.5rem auto -0.5rem -0.5rem;
}

/* Cards & KPI */
html[dir="rtl"] .kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

/* Table Alignments */
html[dir="rtl"] .table th,
html[dir="rtl"] .table td {
    text-align: right;
}

html[dir="rtl"] .table th.text-end,
html[dir="rtl"] .table td.text-end {
    text-align: left !important;
}

html[dir="rtl"] .table th.text-start,
html[dir="rtl"] .table td.text-start {
    text-align: right !important;
}

html[dir="rtl"] .table th.text-center,
html[dir="rtl"] .table td.text-center {
    text-align: center !important;
}

html[dir="rtl"] #portal-sidebar .sub-nav-links {
    padding: 0.25rem 0.75rem 0.25rem 0;
}

html[dir="rtl"] #portal-sidebar .sidebar-section-item.collapsed .section-chevron {
    transform: rotate(90deg);
}

/* ==========================================================================
   CRITICAL REQUIREMENT: EXCEPTION FOR INVOICE ITEMS
   "except invoice items (they remain as they are configured)"
   Preserve LTR / natural entered format for item names, codes, lines, & barcodes
   ========================================================================== */
.invoice-item-name,
.invoice-item-code,
.invoice-item-cell,
.invoice-line-desc,
.item-code-badge,
[data-preserve-item="true"],
#modal-items-tbody td:nth-child(2),
#modal-items-tbody td:nth-child(3),
#manual-lines-tbody td:nth-child(2),
#manual-lines-tbody td:nth-child(3),
#cn-lines-tbody td:nth-child(2),
#inv-modal-lines td:nth-child(2),
#inv-modal-lines td:nth-child(3),
#modal-create-lines-tbody td:nth-child(2),
#modal-create-lines-tbody td:nth-child(3),
#cn-modal-lines-tbody td:nth-child(2),
#cn-modal-lines-tbody td:nth-child(3) {
    direction: ltr !important;
    unicode-bidi: plaintext !important;
    text-align: start !important;
}

/* Numbers and Monospace codes (UUID, VAT IDs, Keys) */
.font-monospace {
    direction: ltr !important;
    unicode-bidi: bidi-override;
}

/* Live clock */
.live-clock-pill {
    direction: ltr;
}

/* Language toggle button style */
.btn-lang-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.825rem;
    font-weight: 600;
    padding: 0.25rem 0.65rem;
    border-radius: 9999px;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-lang-toggle:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
    color: #1e293b;
}

html[dir="rtl"] .btn-lang-toggle {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
