/* ===== NexaERP UI ===== */
html { font-size: var(--erp-font-size, 14px); }
/* Latin glyphs → chosen English font, Arabic glyphs → chosen Arabic font, in both LTR and RTL */
body.erp { font-family: var(--erp-font-en), var(--erp-font-ar), system-ui, 'Segoe UI', Tahoma, sans-serif; background: var(--erp-bg); }
body.erp .tooltip, body.erp .popover, body.erp input, body.erp select, body.erp textarea, body.erp button { font-family: inherit; }
:root, [data-bs-theme="light"] { --erp-bg: #f4f6f9; --erp-card: #fff; --erp-muted-bg: #f8fafc; --erp-border: #e5e7eb; }
[data-bs-theme="dark"] { --erp-bg: #0d1117; --erp-card: #161b22; --erp-muted-bg: #1c2330; --erp-border: #2b3340; }
[data-bs-theme="dark"] .text-bg-light { background: var(--erp-muted-bg) !important; color: inherit !important; }

/* Bootstrap primary overrides driven by theme vars */
.btn-primary { --bs-btn-bg: var(--erp-primary); --bs-btn-border-color: var(--erp-primary); --bs-btn-hover-bg: color-mix(in srgb, var(--erp-primary) 85%, #000); --bs-btn-hover-border-color: color-mix(in srgb, var(--erp-primary) 85%, #000); --bs-btn-active-bg: color-mix(in srgb, var(--erp-primary) 75%, #000); --bs-btn-disabled-bg: var(--erp-primary); --bs-btn-disabled-border-color: var(--erp-primary); }
.btn-outline-primary { --bs-btn-color: var(--erp-primary); --bs-btn-border-color: var(--erp-primary); --bs-btn-hover-bg: var(--erp-primary); --bs-btn-hover-border-color: var(--erp-primary); --bs-btn-active-bg: var(--erp-primary); }
.text-primary { color: var(--erp-primary) !important; }
.bg-primary, .text-bg-primary { background-color: var(--erp-primary) !important; }
.form-control:focus, .form-select:focus { border-color: color-mix(in srgb, var(--erp-primary) 60%, #fff); box-shadow: 0 0 0 .2rem rgba(var(--erp-primary-rgb), .15); }
.form-check-input:checked { background-color: var(--erp-primary); border-color: var(--erp-primary); }
.nav-pills .nav-link.active { background: var(--erp-primary); }
.page-link { color: var(--erp-primary); }

/* Layout */
#app { min-height: 100vh; }
.erp-sidebar { width: 260px; background: var(--erp-sidebar) !important; color: #cbd5e1; position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 1040; display: flex; flex-direction: column; }
@media (min-width: 992px) { .erp-sidebar { visibility: visible !important; transform: none !important; } }
.erp-main { margin-inline-start: 260px; min-height: 100vh; display: flex; flex-direction: column; }
@media (max-width: 991.98px) { .erp-main { margin-inline-start: 0; } .erp-sidebar.offcanvas-lg { width: 280px; } }
.erp-brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.07); }
.erp-brand-logo { max-height: 34px; max-width: 120px; object-fit: contain; background: #fff; border-radius: 6px; padding: 2px; }
.erp-brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--erp-primary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.erp-brand-name { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.erp-nav { overflow-y: auto; padding: .6rem .6rem 2rem; flex: 1; }
.erp-nav-link, .erp-nav-group { display: flex; align-items: center; gap: .7rem; width: 100%; padding: .55rem .75rem; color: #cbd5e1; text-decoration: none; border-radius: 8px; border: 0; background: none; font-size: .95rem; text-align: start; }
.erp-nav-link:hover, .erp-nav-group:hover { background: rgba(255,255,255,.06); color: #fff; }
.erp-nav-link.active { background: var(--erp-primary); color: #fff; }
.erp-nav-link.sub { padding-inline-start: 2.3rem; font-size: .9rem; }
.erp-nav-link.sub i { font-size: .85rem; opacity: .75; }
.erp-nav-group { margin-top: .25rem; font-weight: 500; }
.erp-caret { margin-inline-start: auto; transition: transform .2s; font-size: .75rem; }
.erp-nav-group.collapsed .erp-caret { transform: rotate(-90deg); }
[dir="rtl"] .erp-nav-group.collapsed .erp-caret { transform: rotate(90deg); }
.erp-topbar { position: sticky; top: 0; z-index: 1020; height: 60px; display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; background: var(--erp-card); border-bottom: 1px solid var(--erp-border); }
.erp-search { position: relative; align-items: center; width: min(420px, 40vw); }
.erp-search i { position: absolute; inset-inline-start: .75rem; opacity: .5; }
.erp-search input { padding-inline-start: 2.2rem; background: var(--erp-muted-bg); border-color: transparent; }
.erp-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--erp-primary); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.erp-content { padding: 1.5rem; flex: 1; }
@media (max-width: 575.98px) { .erp-content { padding: 1rem; } }
[data-bs-theme="dark"] .theme-dark-hide, [data-bs-theme="light"] .theme-light-hide { display: none; }

/* Components */
.erp-content a:not(.btn):not(.nav-link):not(.dropdown-item):not(.page-link) { text-decoration: none; }
.erp-content a:not(.btn):hover { text-decoration: underline; }
.erp-content .card a.card, .erp-content a.card:hover, .erp-content a.list-group-item:hover { text-decoration: none; }
.card { border-color: var(--erp-border); background: var(--erp-card); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: transparent; border-bottom-color: var(--erp-border); font-weight: 600; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.4rem; margin: 0; font-weight: 700; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--bs-secondary-color); font-weight: 600; background: var(--erp-muted-bg); white-space: nowrap; }
[dir="rtl"] .table thead th { letter-spacing: 0; text-transform: none; font-size: .85rem; }
.table-card { margin: 0; }
.table-card td, .table-card th { vertical-align: middle; }
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi { padding: 1.1rem 1.2rem; }
.kpi .label { font-size: .82rem; color: var(--bs-secondary-color); }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem; background: rgba(var(--erp-primary-rgb), .12); color: var(--erp-primary); }
.erp-blank { background: linear-gradient(135deg, color-mix(in srgb, var(--erp-primary) 18%, #fff), #f4f6f9 55%); min-height: 100vh; }
[data-bs-theme="dark"] .erp-blank { background: var(--erp-bg); }
.erp-auth-lang { position: absolute; top: 1rem; inset-inline-end: 1rem; }
.auth-card { max-width: 420px; margin: 9vh auto 2rem; }
.tree-indent { display: inline-block; }
.acc-group { font-weight: 600; }
.lines-table input, .lines-table select { min-width: 90px; }
.lines-table .w-desc { min-width: 220px; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 2.4rem; opacity: .4; display: block; margin-bottom: .5rem; }

/* Kanban */
.kanban { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.kanban-col { flex: 0 0 290px; background: var(--erp-muted-bg); border: 1px solid var(--erp-border); border-radius: 12px; display: flex; flex-direction: column; max-height: calc(100vh - 200px); }
.kanban-col-head { padding: .75rem .9rem; border-bottom: 3px solid var(--c, #999); display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.kanban-col-head small { font-weight: 400; color: var(--bs-secondary-color); }
.kanban-list { padding: .6rem; min-height: 80px; overflow-y: auto; flex: 1; }
.kanban-list.drag-over { background: rgba(var(--erp-primary-rgb), .07); }
.kanban-card { background: var(--erp-card); border: 1px solid var(--erp-border); border-radius: 10px; padding: .7rem .8rem; margin-bottom: .6rem; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.kanban-card.dragging { opacity: .45; }
.kanban-card a { color: inherit; text-decoration: none; font-weight: 600; }

/* Org chart */
.org { display: flex; justify-content: center; overflow-x: auto; padding: 1rem; }
.org ul { padding-top: 20px; position: relative; display: flex; justify-content: center; padding-inline-start: 0; }
.org li { list-style: none; text-align: center; position: relative; padding: 20px 6px 0; }
.org li::before, .org li::after { content: ''; position: absolute; top: 0; right: 50%; border-top: 2px solid var(--erp-border); width: 50%; height: 20px; }
.org li::after { right: auto; left: 50%; border-left: 2px solid var(--erp-border); }
.org li:only-child::after, .org li:only-child::before { display: none; }
.org li:only-child { padding-top: 0; }
.org li:first-child::before, .org li:last-child::after { border: 0 none; }
.org li:last-child::before { border-right: 2px solid var(--erp-border); border-radius: 0 6px 0 0; }
.org li:first-child::after { border-radius: 6px 0 0 0; }
.org ul ul::before { content: ''; position: absolute; top: 0; left: 50%; border-left: 2px solid var(--erp-border); width: 0; height: 20px; }
.org-node { display: inline-block; background: var(--erp-card); border: 1px solid var(--erp-border); border-top: 3px solid var(--erp-primary); border-radius: 10px; padding: .6rem .8rem; min-width: 150px; font-size: .85rem; }
.org-node .nm { font-weight: 600; }
.org-node .jt { color: var(--bs-secondary-color); font-size: .78rem; }
.org-dept { background: rgba(var(--erp-primary-rgb), .1); color: var(--erp-primary); font-size: .72rem; border-radius: 99px; padding: .1rem .5rem; display: inline-block; margin-top: .25rem; }

/* Module manager */
.module-card { border-inline-start: 4px solid var(--erp-primary); }
.module-card.off { border-inline-start-color: var(--bs-secondary-bg); opacity: .75; }
.form-switch .form-check-input { cursor: pointer; }

/* Template gallery */
.tpl-thumb { border: 1px solid var(--erp-border); border-radius: 10px; overflow: hidden; background: #fff; height: 260px; position: relative; }
.tpl-thumb iframe { width: 794px; height: 1123px; border: 0; transform: scale(.3); transform-origin: 0 0; pointer-events: none; position: absolute; top: 0; left: 0; }
.tpl-card.selected .tpl-thumb { outline: 3px solid var(--erp-primary); }

/* Signature pad */
.sig-pad { border: 2px dashed var(--erp-border); border-radius: 10px; background: #fff; touch-action: none; width: 100%; height: 180px; cursor: crosshair; }

@media print { .erp-sidebar, .erp-topbar, .no-print { display: none !important; } .erp-main { margin: 0 !important; } .erp-content { padding: 0; } }
.min-w-0 { min-width: 0; }
@media (max-width: 575.98px) {
  .kpi { padding: .85rem .9rem; }
  .kpi .value { font-size: 1.1rem; }
  .kpi .ic { display: none; }
  .page-head h1 { font-size: 1.2rem; }
}
