/**
 * Loaded after Bootstrap: fixes LTR-only rules so modals and inline checkboxes
 * behave correctly when html[dir="rtl"] (Arabic).
 *
 * Header layout: theme uses margin-left on .header for the sidebar in LTR, and
 * left/right inset in RTL — without resetting margin-left in RTL both apply and
 * the top bar shrinks to ~70% width. Theme .user-menu also uses
 * justify-content: center, which clusters items with empty bands on both sides.
 */

/* RTL + desktop: do not stack LTR sidebar margin on top of right inset (fixes narrow header bar). */
@media (min-width: 991.98px) {
	body.layout-mode-rtl .header {
		margin-left: 0 !important;
	}
	body.layout-mode-rtl.mini-sidebar .header {
		margin-left: 0 !important;
	}
	body.layout-mode-rtl.mini-sidebar.expand-menu .header {
		margin-left: 0 !important;
	}
}

/* One flex row: logo block + menu uses full header width (no float shrink-wrap). */
.header .main-header {
	display: flex;
	align-items: center;
	flex-wrap: nowrap;
	width: 100%;
	min-width: 0;
	box-sizing: border-box;
}

.header .main-header .header-left {
	float: none !important;
	flex: 0 0 auto;
}

/*
 * LTR: Arabic fix cleared RTL margin on .header only. English still picked up
 * theme .user-menu { justify-content: center } plus Bootstrap .nav { flex-wrap: wrap },
 * which clusters items and breaks margin-inline-end: auto on the search cell.
 * Horizontal layout also caps .main-header at ~1320px (~70% of a 1080p screen).
 */
@media (min-width: 992px) {
	.header .user-menu.nav {
		justify-content: flex-start !important;
		-webkit-box-pack: start !important;
		-ms-flex-pack: start !important;
		flex-wrap: nowrap !important;
	}
}

.header .user-menu.nav {
	flex: 1 1 auto !important;
	min-width: 0;
	max-width: none !important;
	row-gap: 0.35rem;
}

/* Flex spacer: pushes search to the content edge and actions to the opposite edge (mirrors in RTL). */
.header .user-menu.nav > li.header-toolbar-spacer {
	flex: 1 1 auto !important;
	min-width: 0 !important;
	max-width: none !important;
	align-self: stretch;
	list-style: none;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	pointer-events: none;
}

/* Global search: fixed max width; do not grow (growth breaks RTL alignment; spacer provides the gap). */
.header .user-menu .nav-searchinputs {
	flex: 0 1 auto !important;
	flex-grow: 0 !important;
	min-width: 0 !important;
	max-width: min(360px, 40vw) !important;
	margin-inline-end: 0 !important;
	margin-inline-start: 0 !important;
}
@media (min-width: 1200px) {
	.header .user-menu .nav-searchinputs {
		max-width: 400px !important;
	}
}

.header .user-menu .nav-searchinputs .top-nav-search {
	width: 100%;
	max-width: 100%;
}

.header .user-menu .nav-searchinputs .ai-global-search {
	width: 100%;
	max-width: 100%;
}

/* Arabic: theme style.css sets margin-left:auto on .nav-searchinputs — kills spacer layout; reset inside .header only. */
body.layout-mode-rtl .header .user-menu .nav-searchinputs {
	margin-right: 0 !important;
	margin-left: 0 !important;
	margin-inline-end: 0 !important;
	margin-inline-start: 0 !important;
}

@media (min-width: 992px) {
	body.layout-mode-rtl .header .user-menu.nav {
		column-gap: 0.65rem;
	}
}

body.layout-mode-rtl .header .user-menu.nav > li {
	margin-right: 0 !important;
	margin-left: 0 !important;
}

/* Module switcher + toolbar: readable secondary copy (was too faint .text-muted). */
.header-toolbar-hint {
	color: #5a6578 !important;
	font-weight: 500;
	font-size: 0.8125rem;
	line-height: 1.4;
}

.header-toolbar-caption {
	color: #5c636a !important;
	font-weight: 600;
	font-size: 0.6875rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	line-height: 1.3;
	margin-bottom: 0.2rem !important;
}

html[dir="rtl"] .header-toolbar-caption {
	letter-spacing: 0;
	text-transform: none;
	font-size: 0.75rem;
}

.header-module-desc {
	color: #4a5568 !important;
	font-size: 0.8125rem !important;
	font-weight: 500;
	line-height: 1.35;
	margin-top: 0.15rem;
}

html[dir="rtl"] .header-module-desc {
	letter-spacing: 0;
}

/* Active module row: explicit primary surface so subtitles stay legible */
.header .dropdown-menu.header-module-switcher-menu .dropdown-item.active,
.header .dropdown-menu.header-module-switcher-menu span.dropdown-item.active {
	background-color: var(--bs-primary, #0B4DAD) !important;
	color: #fff !important;
}

.header .dropdown-menu.header-module-switcher-menu .dropdown-item.active .header-module-desc,
.header .dropdown-menu.header-module-switcher-menu span.dropdown-item.active .header-module-desc {
	color: rgba(255, 255, 255, 0.92) !important;
}

.header .dropdown-menu.header-module-switcher-menu .dropdown-item.active .ti-check.text-primary,
.header .dropdown-menu.header-module-switcher-menu span.dropdown-item.active .ti-check.text-primary {
	color: #fff !important;
}

/* Vertical sidebar: stretch inner bar full width (undo horizontal/box ~1320px cap) */
body:not(.menu-horizontal) .header .main-header {
	max-width: none !important;
	width: 100% !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
}

/*
 * LTR fixed header: style.css applies BOTH margin-left:252px (~15152) AND left:252px (~17546).
 * That double-counts the sidebar width — empty band under the bar + clipped right edge. Inset only.
 * (RTL keeps theme right/left insets + margin-left:0; do not change here.)
 */
@media (min-width: 991.98px) {
	body:not(.layout-mode-rtl):not(.menu-horizontal) .header {
		margin-left: 0 !important;
		left: 252px !important;
		right: 0 !important;
	}
	body:not(.layout-mode-rtl):not(.menu-horizontal).mini-sidebar .header {
		margin-left: 0 !important;
		left: 86px !important;
		right: 0 !important;
	}
	body:not(.layout-mode-rtl):not(.menu-horizontal).mini-sidebar.expand-menu .header {
		margin-left: 0 !important;
		left: 252px !important;
		right: 0 !important;
	}
}
@media (max-width: 991.96px) {
	body:not(.layout-mode-rtl):not(.menu-horizontal) .header {
		margin-left: 0 !important;
		left: 0 !important;
		right: 0 !important;
	}
}

/*
 * Theme "Box" width (data-width=box → body.layout-box-mode):
 * - .main-wrapper is max-width 1320px centered — header + page live inside it.
 * - .header gets max-width 1320px + margin:auto — in LTR that fights margin-left sidebar offset.
 * Arabic looked fine because RTL uses left/right insets on .header; English used margin-left + box
 * margin:auto, leaving empty band on the right. Fix: full-width wrapper + LTR inset like RTL.
 *
 * html[...] prefix matches theme specificity ([data-layout][data-width=box] …) so these always win.
 */
html[data-layout=default][data-width=box] body.layout-box-mode:not(.menu-horizontal) .main-wrapper,
html[data-layout=mini][data-width=box] body.layout-box-mode:not(.menu-horizontal) .main-wrapper,
body.layout-box-mode:not(.menu-horizontal) .main-wrapper {
	max-width: none !important;
	width: 100% !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
}

/* Drop box caps on the bar */
body.layout-box-mode:not(.menu-horizontal) .header {
	max-width: none !important;
	width: auto !important;
}

/*
 * LTR + box: theme sets margin:auto + max-width:1320px on .header — auto horizontal margins
 * center the capped bar so you get empty space on the right. Keep theme left:0/right:0 model;
 * replace margins with explicit values (no auto) so the bar fills viewport minus sidebar.
 */
@media (min-width: 991.98px) {
	html[data-layout=default][data-width=box] body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal) .header,
	html[data-layout=mini][data-width=box] body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal) .header,
	body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal) .header {
		left: 0 !important;
		right: 0 !important;
		max-width: none !important;
		width: auto !important;
		margin: 0 0 0 252px !important;
	}
	html[data-layout=default][data-width=box] body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal).mini-sidebar .header,
	html[data-layout=mini][data-width=box] body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal).mini-sidebar .header,
	body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal).mini-sidebar .header {
		margin: 0 0 0 86px !important;
		left: 0 !important;
		right: 0 !important;
	}
	html[data-layout=default][data-width=box] body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal).mini-sidebar.expand-menu .header,
	html[data-layout=mini][data-width=box] body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal).mini-sidebar.expand-menu .header,
	body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal).mini-sidebar.expand-menu .header {
		margin: 0 0 0 252px !important;
		left: 0 !important;
		right: 0 !important;
	}
}
@media (max-width: 991.96px) {
	body:not(.layout-mode-rtl).layout-box-mode:not(.menu-horizontal) .header {
		left: 0 !important;
		right: 0 !important;
		margin: 0 !important;
		max-width: none !important;
	}
}

/* RTL: keep theme insets; strip box max-width + stray horizontal margins */
body.layout-mode-rtl.layout-box-mode:not(.menu-horizontal) .header {
	max-width: none !important;
	width: auto !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
}

/* Bootstrap uses margin-left:auto on .btn-close; in RTL that pins the X beside the title */
html[dir="rtl"] .modal .modal-header .btn-close,
[dir="rtl"] .modal-header .btn-close {
	margin-left: 0 !important;
	margin-right: 0 !important;
	margin-inline-start: auto !important;
	margin-inline-end: calc(-0.5 * var(--bs-modal-header-padding-x)) !important;
}

/* Flex-based form rows: undo physical float/padding from .form-check so RTL flex order works */
[dir="rtl"] .form-check.d-flex {
	padding-left: 0 !important;
	padding-right: 0 !important;
	min-height: 0;
}

[dir="rtl"] .form-check.d-flex .form-check-input {
	float: none !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
	margin-top: 0;
}

/* Package / edit-package permission tree: one full-width column, controls stay next to labels (LTR + RTL) */
.package-permissions-table {
	width: 100%;
	table-layout: fixed;
}

.package-permissions-table .package-perm-row {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 0.75rem;
	width: 100%;
	min-width: 0;
}

.package-permissions-table .package-perm-label {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.package-permissions-table .package-perm-controls {
	flex: 0 0 auto;
}

.package-permissions-table .package-perm-indent-1 {
	padding-inline-start: 1.25rem;
}

.package-permissions-table .package-perm-indent-2 {
	padding-inline-start: 2.5rem;
}

/* “Select all” — neutral caption, not a loud link-style accent */
.package-permissions-table .package-perm-select-hint {
	font-size: 0.8125rem;
	font-weight: 500;
	color: var(--bs-secondary-color, #6c757d);
	white-space: nowrap;
	line-height: 1.2;
}

/* Role permissions table: text-end is physical; in RTL align permission controls toward the label column */
[dir="rtl"] .role-permission-table td.text-end,
[dir="rtl"] .role-permission-table th.text-end {
	text-align: start !important;
}

/*
 * Page header: theme uses margin-inline-end:auto on .add-item without flex-grow, so title + breadcrumb
 * stay shrink-wrapped (~“70%” empty gap before actions). Grow the title column; push tools with auto margin.
 */
.page-header {
	width: 100%;
	box-sizing: border-box;
}
.page-header .add-item.d-flex {
	flex: 1 1 auto !important;
	min-width: 0 !important;
	margin-inline-end: 0 !important;
}
.page-header .table-top-head {
	margin-inline-start: auto !important;
}

/* RTL: stat cards on role/package detail pages — extra inline padding + gap (avoids “cramped” flex) */
html[dir="rtl"] .role-view-summary-row .card-body,
html[dir="rtl"] .package-view-summary-row .card-body {
	padding-inline: 1.25rem !important;
}

/*
 * System Configuration (and similar) inner settings nav: theme used margin-right only, so in RTL
 * the gap to the form landed on the wrong side and the nav felt misaligned. Use logical margin + clear
 * physical margins so the divider sits between sidebar and card in both directions.
 */
.settings-wrapper .settings-sidebar {
	margin-right: 0 !important;
	margin-left: 0 !important;
	margin-inline-end: 24px !important;
}
@media (max-width: 1199.96px) {
	.settings-wrapper .settings-sidebar {
		margin-inline-end: 15px !important;
	}
}
.settings-wrapper .settings-sidebar .sidebar-menu h4 {
	padding-bottom: 0.5rem;
	margin-bottom: 0.75rem !important;
}

/*
 * RTL: Bootstrap input-groups are authored as [control][addon] (e.g. date + calendar).
 * With html[dir="rtl"], plain flex keeps the addon on the physical left (wrong outer edge).
 * Row-reverse + rtl places the addon on the inline-end (right in RTL), matching English “icon on the trailing edge”.
 * Groups that already start with .input-group-text / .btn are left alone (:has() guards).
 * Scope excludes header search and similar toolbars.
 */
html[dir="rtl"] .page-wrapper .input-group:has(> .form-control:first-child),
html[dir="rtl"] .page-wrapper .input-group:has(> input:first-child),
html[dir="rtl"] .page-wrapper .input-group:has(> select.form-select:first-child),
html[dir="rtl"] .page-wrapper .input-group:has(> textarea:first-child),
html[dir="rtl"] .modal .input-group:has(> .form-control:first-child),
html[dir="rtl"] .modal .input-group:has(> input:first-child),
html[dir="rtl"] .modal .input-group:has(> select.form-select:first-child),
html[dir="rtl"] .modal .input-group:has(> textarea:first-child),
html[dir="rtl"] .offcanvas .input-group:has(> .form-control:first-child),
html[dir="rtl"] .offcanvas .input-group:has(> input:first-child),
html[dir="rtl"] .account-content .input-group:has(> .form-control:first-child),
html[dir="rtl"] .account-content .input-group:has(> input:first-child),
html[dir="rtl"] .account-content .input-group:has(> select.form-select:first-child),
html[dir="rtl"] .account-content .input-group:has(> textarea:first-child) {
	flex-direction: row-reverse;
	direction: rtl;
}

/* AI chat bar uses fixed LTR pill radii on [input][button] — do not mirror. */
html[dir="rtl"] .page-wrapper .ai-assistant-input .input-group:has(> .form-control:first-child),
html[dir="rtl"] .page-wrapper .ai-assistant-input .input-group:has(> input:first-child) {
	flex-direction: row;
	direction: ltr;
}

/* ISO / numeric dates stay LTR inside the field; align toward the addon (inline-end). */
html[dir="rtl"] .input-group > .date-picker,
html[dir="rtl"] .input-group > input.date-picker,
html[dir="rtl"] .input-group > .form-control.date-picker,
html[dir="rtl"] .input-group > .datepicker,
html[dir="rtl"] .input-group > input.flatpickr-input {
	direction: ltr;
	text-align: right;
	unicode-bidi: isolate;
}

/* Theme “icon inside field” date wrappers — flip absolute icon + padding (finance / reports). */
html[dir="rtl"] .input-blocks .input-groupicon .addonset {
	right: auto;
	left: 12px;
}
html[dir="rtl"] .input-groupicon.calender-input.income-date svg {
	left: auto;
	right: 10px;
}
html[dir="rtl"] .input-groupicon.calender-input.balance-sheet-date input {
	padding: 7px 30px 7px 12px;
}
html[dir="rtl"] .input-groupicon.calender-input.balance-sheet-date svg {
	left: auto;
	right: 10px;
}

/*
 * Header toolbar: theme .user-menu forces color:#fff on ALL .link-nav / .pos-nav .btn,
 * which makes outline-primary buttons unreadable (white on white).
 */
.header .user-menu.nav > li.link-nav .btn.btn-outline-primary,
.header .user-menu.nav > li.pos-nav .btn.btn-outline-primary {
	color: var(--bs-primary, #0B4DAD) !important;
	background-color: var(--bs-body-bg, #ffffff) !important;
	border-color: var(--bs-primary, #0B4DAD) !important;
	font-weight: 600;
}
.header .user-menu.nav > li.link-nav .btn.btn-outline-primary:hover,
.header .user-menu.nav > li.link-nav .btn.btn-outline-primary:focus-visible,
.header .user-menu.nav > li.pos-nav .btn.btn-outline-primary:hover,
.header .user-menu.nav > li.pos-nav .btn.btn-outline-primary:focus-visible {
	color: #ffffff !important;
	background-color: var(--bs-primary, #0B4DAD) !important;
}

.header .user-menu .header-context-trigger.btn-outline-primary {
	color: var(--bs-primary, #0B4DAD) !important;
	background-color: var(--bs-body-bg, #ffffff) !important;
	font-weight: 600;
}
.header .user-menu .header-context-trigger.btn-outline-primary:hover,
.header .user-menu .header-context-trigger.btn-outline-primary:focus-visible {
	color: #ffffff !important;
	background-color: var(--bs-primary, #0B4DAD) !important;
}

/* pos-nav divider: logical edge so RTL mirrors without extra rules */
.header .user-menu.nav > li.pos-nav {
	border-right: 0 !important;
	border-left: 0 !important;
	padding-right: 0 !important;
	padding-left: 0 !important;
	border-inline-end: 1px solid #e6eaed !important;
	padding-inline-end: 12px !important;
}

/* Header dropdowns: align copy to start in both LTR and RTL */
.header .header-toolbar-dropdown {
	text-align: start;
}

.header .header-toolbar-mega-dropdown {
	text-align: start;
}

.header .header-toolbar-mega-dropdown .section-header h6 {
	text-align: start;
}

/* Context panel: field labels easier to scan than default .text-muted */
.header-context-menu .header-context-row .small.text-muted,
.header-context-menu .header-context-row small.text-muted {
	color: var(--bs-secondary-color, #5c636a) !important;
	font-weight: 600;
	font-size: 0.6875rem;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	line-height: 1.25;
}

html[dir="rtl"] .header-context-menu .header-context-row .small.text-muted,
html[dir="rtl"] .header-context-menu .header-context-row small.text-muted {
	letter-spacing: 0;
}

/* Language menu: theme used physical margin on flag images */
.header .user-menu.nav > li.flag-nav .dropdown-menu.header-lang-dropdown .dropdown-item img {
	margin-right: 0 !important;
	margin-inline-end: 0.5rem !important;
}

/* Active language row: win over theme orange/white rules */
.header .user-menu.nav > li.flag-nav .dropdown-menu.header-lang-dropdown .dropdown-item.active {
	background-color: rgba(var(--bs-primary-rgb, 11, 77, 173), 0.12) !important;
	color: var(--bs-primary, #0B4DAD) !important;
}

.header .user-menu.nav > li.flag-nav .dropdown-menu.header-lang-dropdown .dropdown-item.active span {
	color: inherit !important;
}

.header .user-menu.nav > li.flag-nav .dropdown-menu.header-lang-dropdown .dropdown-item.active:hover {
	background-color: rgba(var(--bs-primary-rgb, 11, 77, 173), 0.18) !important;
	color: var(--bs-primary, #0B4DAD) !important;
}

/* Loaders & spinners — official brand blue */
div#global-loader .whirly-loader:not(:required) {
	border: 4px solid rgba(var(--bs-primary-rgb, 11, 77, 173), 0.2) !important;
	border-top-color: var(--bs-primary, #0B4DAD) !important;
	box-shadow: none !important;
}

.spinner-border,
.spinner-border-sm,
.spinner-grow,
.spinner-grow-sm {
	color: var(--bs-primary, #0B4DAD) !important;
}

.spinner-border.text-primary,
.spinner-grow.text-primary,
.notification-empty-icon.spinner-border {
	color: var(--bs-primary, #0B4DAD) !important;
}

.dataTables_processing {
	color: var(--bs-primary, #0B4DAD) !important;
	border-color: rgba(var(--bs-primary-rgb, 11, 77, 173), 0.15) !important;
}

