/* ==========================================================================
   ERP Design System — RTL, mobile-first
   Logical properties (inline-start/end) keep the layout correct in RTL.
   ========================================================================== */
:root {
  --c-primary: #1f3b73;
  --c-primary-600: #274b91;
  --c-primary-50: #eef3fc;
  --c-accent: #0e9f6e;
  --c-warning: #d97706;
  --c-danger: #dc2626;
  --c-text: #1e2432;
  --c-muted: #667085;
  --c-border: #e4e7ec;
  --c-surface: #ffffff;
  --c-bg: #f5f7fb;
  --c-primary-text: var(--c-primary);
  --c-sidebar: #152a54;
  color-scheme: light;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --sidebar-w: 264px;
  --topbar-h: 60px;
  --font: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --bs-body-font-family: var(--font);
  --bs-primary: var(--c-primary);
  --bs-primary-rgb: 31, 59, 115;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.8;
  color: var(--c-text);
  background: var(--c-bg);
  margin: 0;
}
input, select, textarea, button { font-family: inherit; }
.ltr-input, [dir="ltr"] { direction: ltr; text-align: start; }
.num { font-variant-numeric: tabular-nums; }
.skip-link { position: absolute; inset-inline-start: -999px; top: 0; background: var(--c-surface); padding: .5rem 1rem; z-index: 2000; }
.skip-link:focus { inset-inline-start: 1rem; }
:focus-visible { outline: 3px solid rgba(39, 75, 145, .45); outline-offset: 2px; }

.btn-primary { --bs-btn-bg: var(--c-primary); --bs-btn-border-color: var(--c-primary); --bs-btn-hover-bg: var(--c-primary-600); --bs-btn-hover-border-color: var(--c-primary-600); --bs-btn-active-bg: var(--c-primary-600); }
.btn { border-radius: var(--radius-sm); }
.form-control, .form-select { border-radius: var(--radius-sm); border-color: var(--c-border); min-height: 42px; }
.form-control-sm, .form-select-sm { min-height: 34px; }
.form-label { font-weight: 500; font-size: .9rem; margin-bottom: .3rem; }
.required-mark { color: var(--c-danger); margin-inline-start: .25rem; }

/* ---------- App shell ---------- */
.app { min-height: 100dvh; }
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0;
  width: var(--sidebar-w); max-width: 86vw;
  background: var(--c-sidebar); color: #d8e1f3;
  transform: translateX(100%); /* RTL: off-canvas to the right */
  transition: transform .2s ease;
  z-index: 1040; overflow-y: auto; overscroll-behavior: contain;
}
.sidebar.open { transform: none; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1030; }
.sidebar-brand { display: flex; gap: .75rem; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #3b6fd6, #0e9f6e); color: #fff; font-size: 1.1rem; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.4; }
.brand-text small { color: #9fb1d6; font-size: .75rem; }
.nav-menu { padding: .5rem .5rem 2rem; }
.nav-group { padding-block: .25rem; }
.nav-title { font-size: .72rem; color: #8ea1c9; padding: .75rem .75rem .25rem; letter-spacing: .02em; }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; margin-block: 2px; border-radius: var(--radius-sm); color: #d8e1f3; text-decoration: none; font-size: .92rem; }
.nav-item i { width: 20px; text-align: center; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(59,111,214,.28); color: #fff; }
.badge-count { margin-inline-start: auto; background: var(--c-danger); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .45rem; font-weight: 600; }

.main-area { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1020;
  height: var(--topbar-h); display: flex; align-items: center; gap: .5rem;
  padding-inline: .75rem; background: var(--c-surface); border-bottom: 1px solid var(--c-border);
}
.topbar-title { font-size: 1.05rem; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: .25rem; flex-shrink: 0; }
.company-switch { max-width: 160px; }
.icon-btn { position: relative; display: inline-flex; align-items: center; gap: .4rem; justify-content: center; min-width: 40px; height: 40px; padding-inline: .5rem; border: 0; border-radius: 10px; background: transparent; color: var(--c-text); text-decoration: none; font-size: 1.1rem; }
.icon-btn:hover { background: var(--c-primary-50); }
.user-btn span { font-size: .9rem; max-width: 11rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-dot { position: absolute; top: 6px; inset-inline-end: 6px; min-width: 16px; height: 16px; border-radius: 999px; background: var(--c-danger); color: #fff; font-size: .65rem; display: grid; place-items: center; padding-inline: 3px; }
.content { flex: 1; padding: 1rem .75rem 2rem; width: 100%; max-width: 1400px; margin-inline: auto; }

@media (min-width: 992px) {
  .sidebar { transform: none; }
  .sidebar-backdrop { display: none; }
  .main-area { margin-inline-start: var(--sidebar-w); }
  #sidebar-toggle { display: none; }
  .content { padding: 1.5rem 1.75rem 3rem; }
  .company-switch { max-width: 240px; }
}

/* ---------- Surfaces ---------- */
.card-x { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-x + .card-x { margin-top: 1rem; }
.card-x-header { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; padding: .85rem 1rem; border-bottom: 1px solid var(--c-border); }
.card-x-header h2, .card-x-header h3 { font-size: 1rem; margin: 0; font-weight: 600; }
.card-x-body { padding: 1rem; }
.page-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.page-toolbar .grow { flex: 1 1 220px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { padding: 1rem; }
.stat .v { font-size: 1.6rem; font-weight: 700; }
.stat .l { color: var(--c-muted); font-size: .85rem; }
.page-loading { display: flex; gap: .75rem; align-items: center; justify-content: center; padding: 3rem; color: var(--c-muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--c-border); border-top-color: var(--c-primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--c-muted); }
.empty-state i { font-size: 2rem; opacity: .5; display: block; margin-bottom: .5rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .6rem; border-radius: 999px; font-size: .78rem; background: var(--c-primary-50); color: var(--c-primary-text); white-space: nowrap; }
.chip.success { background: #e7f7ef; color: #0b7a55; }
.chip.warning { background: #fff5e6; color: #b45309; }
.chip.danger { background: #fdecec; color: #b91c1c; }
.chip.muted { background: #f1f3f7; color: var(--c-muted); }
.form-error { background: #fdecec; color: #b91c1c; border-radius: var(--radius-sm); padding: .6rem .8rem; font-size: .9rem; }

/* ---------- Data table: cards on mobile, table on desktop (no horizontal page scroll) ---------- */
.dt { width: 100%; }
.dt-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.dt-table thead { display: none; }
.dt-table tr { display: block; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: .6rem .8rem; margin-bottom: .6rem; }
.dt-table td { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; border: 0; font-size: .92rem; }
.dt-table td::before { content: attr(data-label); color: var(--c-muted); font-size: .8rem; flex-shrink: 0; }
.dt-table td.dt-actions { justify-content: flex-end; padding-top: .5rem; }
.dt-table td.dt-actions::before { content: none; }
.dt-row-link { cursor: pointer; }
@media (min-width: 768px) {
  .dt-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); }
  .dt-table thead { display: table-header-group; }
  .dt-table tr { display: table-row; border: 0; padding: 0; margin: 0; background: none; }
  .dt-table th { background: #f8fafc; font-weight: 600; font-size: .85rem; color: var(--c-muted); padding: .7rem .9rem; border-bottom: 1px solid var(--c-border); text-align: start; white-space: nowrap; }
  .dt-table td { display: table-cell; padding: .65rem .9rem; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
  .dt-table td::before { content: none; }
  .dt-table tbody tr:last-child td { border-bottom: 0; }
  .dt-table tbody tr:hover td { background: #fafbff; }
}
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .75rem 0; font-size: .88rem; color: var(--c-muted); }
.pager .btn-group .btn { min-width: 40px; }

/* ---------- Toasts ---------- */
.toast-host { position: fixed; bottom: 1rem; inset-inline: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 2000; pointer-events: none; align-items: center; }
.toast-x { pointer-events: auto; background: #111827; color: #fff; padding: .7rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); max-width: 480px; width: 100%; display: flex; gap: .6rem; align-items: flex-start; font-size: .92rem; animation: toast-in .18s ease-out; }
.toast-x.success { background: #0b7a55; }
.toast-x.error { background: #b91c1c; }
.toast-x.warning { background: #b45309; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Auth ---------- */
.auth-body { background: radial-gradient(circle at 20% 10%, #dbe6fb 0, transparent 40%), var(--c-bg); }
.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 480px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 16px; box-shadow: var(--shadow); padding: 1.5rem; }
.auth-brand { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.auth-brand small { display: block; color: var(--c-muted); font-size: .8rem; }
.auth-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 1rem; }

/* ---------- Tree (companies / org chart) ---------- */
.tree { list-style: none; padding-inline-start: 0; margin: 0; }
.tree .tree { padding-inline-start: 1.25rem; border-inline-start: 1px dashed var(--c-border); margin-inline-start: .6rem; }
.tree-node { display: flex; align-items: center; gap: .5rem; padding: .35rem .5rem; border-radius: var(--radius-sm); }
.tree-node:hover { background: var(--c-primary-50); }
.tree-node .actions { margin-inline-start: auto; display: flex; gap: .25rem; }

/* ---------- Form renderer ---------- */
.frm { --frm-gap: 1rem; }
.frm-field { margin-bottom: var(--frm-gap); }
.frm-field .form-text { font-size: .8rem; }
.frm-field.is-hidden { display: none; }
.frm-invalid .form-control, .frm-invalid .form-select { border-color: var(--c-danger); }
.frm-error { color: var(--c-danger); font-size: .8rem; margin-top: .2rem; }
.frm-panel { border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1rem; margin-bottom: var(--frm-gap); }
.frm-panel > legend { font-size: .95rem; font-weight: 600; float: none; width: auto; padding-inline: .4rem; margin: 0; }
.frm-heading { font-size: 1.1rem; font-weight: 700; margin: .5rem 0 1rem; }
.frm-grid { width: 100%; }
.frm-grid-toolbar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.frm-grid-rows { display: flex; flex-direction: column; gap: .5rem; }
.frm-grid-row { border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: .6rem; background: #fcfdff; }
.frm-grid-row .row { --bs-gutter-y: .5rem; }
.frm-grid-row-head { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--c-muted); margin-bottom: .25rem; }
.frm-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; padding-top: .5rem; border-top: 1px solid var(--c-border); margin-top: 1rem; position: sticky; bottom: 0; background: var(--c-surface); padding-bottom: .5rem; }
.frm-richtext { min-height: 140px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: .6rem .8rem; background: #fff; overflow-y: auto; }
.frm-richtext-bar { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: .25rem; }
.frm-signature { width: 100%; max-width: 480px; height: 180px; border: 1px dashed var(--c-border); border-radius: var(--radius-sm); background: #fff; touch-action: none; display: block; }
.frm-rating button { border: 0; background: none; font-size: 1.4rem; color: #cbd5e1; padding: 0 .1rem; }
.frm-rating button.on { color: #f59e0b; }
.frm-files { list-style: none; padding: 0; margin: .4rem 0 0; font-size: .85rem; }
.frm-files li { display: flex; gap: .5rem; align-items: center; }
.frm-tabs .nav-link { font-size: .9rem; }
.frm-wizard-steps { display: flex; gap: .5rem; overflow-x: auto; margin-bottom: 1rem; padding-bottom: .25rem; }
.frm-wizard-steps .step { flex-shrink: 0; padding: .3rem .8rem; border-radius: 999px; background: #f1f3f7; font-size: .82rem; }
.frm-wizard-steps .step.active { background: var(--c-primary); color: #fff; }
.frm-multiselect { position: relative; }
.frm-multiselect .ms-chips { display: flex; flex-wrap: wrap; gap: .25rem; padding: .35rem; min-height: 42px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); background: #fff; cursor: text; }
.frm-multiselect .ms-chips input { border: 0; outline: 0; flex: 1; min-width: 80px; }
.frm-multiselect .ms-list { position: absolute; inset-inline: 0; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--c-border); border-radius: var(--radius-sm); box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.frm-multiselect .ms-list button { display: block; width: 100%; text-align: start; border: 0; background: none; padding: .4rem .7rem; }
.frm-multiselect .ms-list button:hover, .frm-multiselect .ms-list button.selected { background: var(--c-primary-50); }

/* ---------- Form builder ---------- */
/* minmax(0, 1fr): ستون بوم با محتوای پهن (گرید/جدول) بزرگ نمی‌شود و پنل ویژگی‌ها را از صفحه بیرون نمی‌برد. */
.fb { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.fb-canvas { min-width: 0; overflow-x: auto; }
.fb-palette, .fb-props { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: .75rem; }
.fb-palette-group { margin-bottom: .75rem; }
.fb-palette-group h4 { font-size: .78rem; color: var(--c-muted); margin: .25rem 0 .4rem; }
.fb-palette-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .35rem; }
.fb-palette-item { display: flex; gap: .4rem; align-items: center; padding: .4rem .5rem; border: 1px solid var(--c-border); border-radius: var(--radius-sm); background: #fff; font-size: .8rem; cursor: grab; user-select: none; text-align: start; }
.fb-palette-item:hover { border-color: var(--c-primary); color: var(--c-primary-text); }
.fb-canvas { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1rem; min-height: 420px; }
.fb-drop { min-height: 48px; border: 2px dashed transparent; border-radius: var(--radius-sm); padding: .25rem; transition: border-color .1s; }
.fb-drop.empty { border-color: var(--c-border); display: flex; align-items: center; justify-content: center; color: var(--c-muted); font-size: .85rem; }
.fb-drop.drag-over { border-color: var(--c-primary); background: var(--c-primary-50); }
.fb-el { position: relative; border: 1px solid transparent; border-radius: var(--radius-sm); padding: .5rem; margin-bottom: .4rem; background: #fff; }
.fb-el:hover { border-color: #c7d2fe; }
.fb-el.selected { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(31,59,115,.12); }
.fb-el-bar { display: flex; align-items: center; gap: .25rem; font-size: .75rem; color: var(--c-muted); margin-bottom: .25rem; }
.fb-el-bar .type { background: #f1f3f7; border-radius: 6px; padding: 0 .4rem; }
.fb-el-bar .key { direction: ltr; }
.fb-el-bar .tools { margin-inline-start: auto; display: flex; gap: .15rem; }
.fb-el-bar .tools button { border: 0; background: none; color: var(--c-muted); width: 28px; height: 28px; border-radius: 6px; }
.fb-el-bar .tools button:hover { background: var(--c-primary-50); color: var(--c-primary-text); }
.fb-el-preview { pointer-events: none; }
.fb-cols { display: grid; gap: .5rem; grid-template-columns: 1fr; }
.fb-col { border: 1px dashed #d0d5dd; border-radius: var(--radius-sm); padding: .25rem; }
.fb-json { width: 100%; min-height: 60vh; font-family: ui-monospace, Consolas, monospace; font-size: .82rem; direction: ltr; }
.code-editor { width: 100%; min-height: 50vh; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; direction: ltr; tab-size: 4; white-space: pre; }
@media (min-width: 768px) { .fb-cols { grid-template-columns: repeat(var(--cols, 2), 1fr); } }
@media (min-width: 1200px) {
  .fb { grid-template-columns: 250px minmax(0, 1fr) 320px; align-items: start; }
  .fb-palette, .fb-props { position: sticky; top: calc(var(--topbar-h) + 1rem); max-height: calc(100dvh - var(--topbar-h) - 2rem); overflow-y: auto; }
}

/* ---------- BPMN designer ---------- */
.bpmn-layout { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.bpmn-canvas { height: 60vh; min-height: 380px; background: #fff; border: 1px solid var(--c-border); border-radius: var(--radius); direction: ltr; overflow: hidden; }
.bpmn-props { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1rem; }
.bpmn-viewer { height: 420px; direction: ltr; background: #fff; border: 1px solid var(--c-border); border-radius: var(--radius); }
.bpmn-viewer .djs-container .visited:not(.djs-connection) .djs-visual > :nth-child(1) { fill: #dcfce7 !important; stroke: #16a34a !important; }
.bpmn-viewer .djs-container .active .djs-visual > :nth-child(1) { fill: #fee2e2 !important; stroke: #dc2626 !important; stroke-width: 3px !important; }
@media (min-width: 1200px) {
  .bpmn-layout { grid-template-columns: 1fr 340px; }
  .bpmn-canvas { height: calc(100dvh - var(--topbar-h) - 9rem); }
}

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding-inline-start: 1.5rem; padding-bottom: .9rem; border-inline-start: 2px solid var(--c-border); margin-inline-start: .4rem; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -7px; top: .45rem; width: 12px; height: 12px; border-radius: 50%; background: var(--c-primary); }
.timeline .t-meta { color: var(--c-muted); font-size: .8rem; }

/* ---------- Misc ---------- */
.kv { display: grid; grid-template-columns: minmax(110px, 35%) 1fr; gap: .35rem 1rem; font-size: .92rem; }
.kv dt { color: var(--c-muted); font-weight: 400; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .5rem 1rem; }
.modal-content { border-radius: var(--radius); }
.modal-fullscreen-sm-down .modal-content { border-radius: 0; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ───── منابع انسانی ───── */
.stat-card { background: var(--c-surface, #fff); border: 1px solid var(--c-border, #e5e7eb); border-radius: .75rem; padding: .9rem 1rem; height: 100%; }
.tab-body { min-height: 8rem; }

@media print {
  .sidebar, .topbar, .no-print, #toast-host, .sidebar-backdrop { display: none !important; }
  .main, .content, main { margin: 0 !important; padding: 0 !important; }
  .card-x { break-inside: avoid; box-shadow: none !important; border: 1px solid #999 !important; }
  body { background: #fff !important; }
}

/* ───── داشبورد نیروی انسانی (نمودارهای سبک HTML) ───── */
.viz { --series-1: #2a78d6; --series-2: #eb6834; --viz-grid: #e8eaee; --viz-track: #f1f3f7; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
.kpi { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: .75rem; padding: .8rem 1rem; display: flex; flex-direction: column; gap: .15rem; text-decoration: none; color: inherit; }
a.kpi:hover { border-color: var(--c-primary); }
.kpi .kpi-label { color: var(--c-muted); font-size: .8rem; }
.kpi .kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.3; }
.kpi .kpi-note { color: var(--c-muted); font-size: .75rem; }
.kpi.attention .kpi-value { color: var(--c-warning); }
.hbar-list { display: flex; flex-direction: column; gap: .55rem; }
.hbar { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; align-items: center; gap: .6rem; font-size: .85rem; }
.hbar-track { height: 12px; background: var(--viz-track); border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-value { font-variant-numeric: tabular-nums; color: var(--c-text); }
.vbar-chart { position: relative; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; align-items: end; height: 180px; padding-top: .5rem; border-bottom: 1px solid var(--viz-grid); }
.vbar-group { display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 100%; cursor: default; }
.vbar { width: min(14px, 40%); border-radius: 4px 4px 0 0; min-height: 0; }
.vbar.s1 { background: var(--series-1); }
.vbar.s2 { background: var(--series-2); }
.vbar-group:hover .vbar, .vbar-group:focus-visible .vbar { filter: brightness(0.9); }
.vbar-axis { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; font-size: .68rem; color: var(--c-muted); text-align: center; margin-top: .25rem; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .8rem; color: var(--c-muted); margin-bottom: .5rem; }
.viz-legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: .35rem; vertical-align: middle; }
.viz-tip { position: absolute; pointer-events: none; background: #111827; color: #fff; font-size: .78rem; padding: .35rem .55rem; border-radius: .4rem; white-space: nowrap; transform: translate(50%, -110%); z-index: 5; }
@media (max-width: 575.98px) { .vbar-axis span:nth-child(even) { visibility: hidden; } }

/* ───── مکاتبات اداری ───── */
.letter-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 2; }
.letter-body-input { line-height: 1.9; min-height: 16rem; }
.referral-tree { list-style: none; margin: 0; padding-inline-start: 1.1rem; border-inline-start: 2px solid var(--c-border); }
.referral-tree.root { padding-inline-start: 0; border: 0; }
.referral-node { padding: .35rem 0 .35rem .25rem; display: flex; flex-direction: column; gap: .2rem; }
.sticky-actions { position: sticky; bottom: 0; background: var(--c-surface); padding: .6rem 0; border-top: 1px solid var(--c-border); z-index: 5; }

.letter-sheet { background: #fff; color: #111; max-width: 21cm; margin: 0 auto; padding: 1.2cm 1.5cm; border: 1px solid var(--c-border); border-radius: .5rem; display: flex; flex-direction: column; gap: 1rem; min-height: 26cm; position: relative; }
.letter-sheet.is-draft::before { content: "پیش‌نویس"; position: absolute; inset: 40% 0 auto; text-align: center; font-size: 5rem; color: rgba(200, 0, 0, .08); transform: rotate(-20deg); pointer-events: none; }
.letter-head { display: grid; grid-template-columns: 1fr 2fr 1fr; align-items: start; gap: 1rem; border-bottom: 2px solid #333; padding-bottom: .6rem; }
.letter-logo img { max-height: 70px; max-width: 100%; }
.letter-org { text-align: center; }
.letter-classification { display: inline-block; margin-top: .3rem; border: 1px solid #b00; color: #b00; padding: 0 .6rem; font-weight: 700; }
.letter-meta { display: grid; grid-template-columns: auto 1fr; gap: .1rem .4rem; margin: 0; font-size: .9rem; }
.letter-meta dt { font-weight: 400; color: #555; }
.letter-meta dd { margin: 0; font-weight: 700; }
.letter-content { flex: 1; }
.letter-signatures { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2rem; }
.letter-signature { text-align: center; min-width: 160px; }
.letter-signature img { max-height: 90px; max-width: 200px; display: block; margin: 0 auto .3rem; }
.letter-signature-empty { height: 70px; }
.letter-cc ul { margin: 0; padding-inline-start: 1.2rem; font-size: .9rem; }
.letter-foot { border-top: 1px solid #999; padding-top: .4rem; font-size: .8rem; text-align: center; color: #444; }
@media (max-width: 576px) {
  .letter-sheet { padding: .8rem; min-height: 0; }
  .letter-head { grid-template-columns: 1fr; text-align: center; }
  .letter-meta { justify-content: center; }
}
@media print {
  .letter-sheet { border: 0; border-radius: 0; padding: 0; max-width: none; min-height: 0; }
  @page { size: A4; margin: 1.5cm; }
}

/* ───── زنجیره تأمین ───── */
.compare-table td.best-price { background: rgba(25, 135, 84, .12); font-weight: 700; }

/* ---------- SaaS: اشتراک، پلن‌ها و برندینگ ---------- */
.usage-track { height: .5rem; background: var(--c-primary-50); border-radius: 999px; overflow: hidden; }
.usage-fill { height: 100%; background: var(--c-primary); border-radius: inherit; transition: width .3s ease; }
.usage-fill.warning { background: var(--c-warning); }
.usage-fill.danger { background: var(--c-danger); }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 1rem; }
.plan-card { display: flex; flex-direction: column; gap: .5rem; border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1rem; background: var(--c-surface); min-width: 0; }
.plan-card.current { border-color: var(--c-primary); box-shadow: 0 0 0 2px var(--c-primary-50); }
.plan-card header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.plan-card h3 { font-size: 1.05rem; margin: 0; }
.plan-price { font-size: 1.2rem; font-weight: 700; }
.plan-price small { font-size: .8rem; font-weight: 400; color: var(--c-muted); }
.plan-features { list-style: none; padding: 0; margin: 0 0 .5rem; font-size: .88rem; }
.plan-features li::before { content: "\2713"; color: var(--c-accent); margin-inline-end: .4rem; }
.plan-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: .5rem; }
.plan-option { border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: .5rem .75rem; cursor: pointer; display: flex; flex-direction: column; font-size: .85rem; }
.plan-option:has(input:checked) { border-color: var(--c-primary); background: var(--c-primary-50); }
.plan-option input { position: absolute; opacity: 0; pointer-events: none; }
.brand-logo-preview { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; min-height: 48px; }
.brand-logo-preview img { max-height: 48px; max-width: 160px; object-fit: contain; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; background: #fff; }
.subscription-banner { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; padding: .5rem 1rem; font-size: .88rem; background: #fff7e6; color: #7a4a00; border-bottom: 1px solid #f5d9a6; }
.subscription-banner.danger { background: #fdecec; color: #8a1c1c; border-color: #f3c2c2; }
.subscription-banner a { font-weight: 700; color: inherit; }
.sandbox-pay { max-width: 520px; margin-inline: auto; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 1rem; }
.template-card { display: flex; flex-direction: column; gap: .5rem; border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1rem; background: var(--c-surface); min-width: 0; }
.template-card header { display: flex; gap: .75rem; align-items: center; }
.template-card h3 { font-size: 1rem; margin: 0; }
.template-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--c-primary-50); color: var(--c-primary-text); font-size: 1.1rem; flex-shrink: 0; }
.domain-verify { border: 1px dashed var(--c-border); border-radius: var(--radius-sm); padding: .75rem; font-size: .88rem; overflow-wrap: anywhere; }
.domain-verify code { direction: ltr; unicode-bidi: embed; }
.recovery-codes { background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: .75rem; font-size: 1rem; line-height: 2; margin: 0; text-align: left; }
.secret-key { font-family: ui-monospace, monospace; background: var(--c-bg); border: 1px dashed var(--c-border); border-radius: var(--radius-sm); padding: .4rem .6rem; margin-top: .35rem; overflow-wrap: anywhere; text-align: left; }

/* ---------- Jalali date picker ---------- */
.jdp { position: relative; flex-wrap: nowrap; }
.jdp .jdp-input { text-align: right; font-feature-settings: "tnum"; min-width: 0; }
.jdp .jdp-input::placeholder { color: #b0b7c3; }
.jdp .jdp-btn { border-color: var(--bs-border-color, #dee2e6); color: var(--c-muted); }
.jdp-popup {
  position: fixed; z-index: 2000; width: 300px; max-width: calc(100vw - 16px);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(16, 24, 40, .18); padding: .6rem; direction: rtl; font-size: .85rem; line-height: 1.5;
}
.jdp-head { display: flex; align-items: center; gap: .3rem; margin-bottom: .4rem; }
.jdp-head .form-select { padding-inline: .5rem 1.6rem; font-size: .82rem; }
.jdp-head .jdp-month { flex: 1.3; }
.jdp-head .jdp-year { flex: 1; }
.jdp-nav { width: 30px; height: 30px; padding: 0; flex: none; }
.jdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.jdp-wd { text-align: center; color: var(--c-muted); font-size: .75rem; padding: .15rem 0; }
.jdp-day {
  border: 0; background: none; border-radius: 8px; height: 34px; font-size: .85rem; color: var(--c-text);
  font-feature-settings: "tnum"; cursor: pointer;
}
.jdp-day:hover:not(:disabled) { background: var(--c-primary-50); color: var(--c-primary-text); }
.jdp-day:focus-visible { outline: 2px solid var(--c-primary); outline-offset: -2px; }
.jdp-day.is-today { box-shadow: inset 0 0 0 1px var(--c-primary); font-weight: 700; }
.jdp-day.is-selected, .jdp-day.is-selected:hover { background: var(--c-primary); color: #fff; }
.jdp-day:disabled { color: #c9ced6; cursor: not-allowed; }
.jdp-fri { color: var(--c-danger); }
.jdp-day.jdp-fri.is-selected { color: #fff; }
.jdp-footer { display: flex; align-items: center; gap: .35rem; border-top: 1px solid var(--c-border); margin-top: .45rem; padding-top: .45rem; }
.jdp-footer .jdp-time { width: 7rem; direction: ltr; }
.jdp-footer .btn-link { text-decoration: none; padding-inline: .35rem; }
.frm-invalid .jdp-input { border-color: var(--c-danger); }

/* ---------- Code editor (Monaco, offline) ---------- */
.code-editor-x { border: 1px solid var(--c-border); border-radius: var(--radius-sm); overflow: hidden; background: #fff; direction: ltr; text-align: left; }
.code-editor-x.is-invalid { border-color: var(--c-danger); }
.code-toolbar { display: flex; align-items: center; gap: .25rem; padding: .2rem .4rem; background: #f7f8fa; border-bottom: 1px solid var(--c-border); }
.code-toolbar .code-lang { font-size: .75rem; color: var(--c-muted); font-weight: 600; margin-inline-end: auto; }
.code-toolbar .btn { padding: .1rem .45rem; font-size: .78rem; }
.code-host { position: relative; min-height: 60px; }
.code-editor-x.compact .code-host { min-height: 38px; }
.code-fallback { width: 100%; height: 100%; min-height: inherit; border: 0; resize: vertical; padding: .5rem; font-family: Consolas, ui-monospace, monospace; font-size: .85rem; tab-size: 4; white-space: pre; direction: ltr; outline: none; }
.code-editor-x.is-fullscreen { position: fixed; inset: 0; z-index: 2100; border-radius: 0; display: flex; flex-direction: column; }
.code-editor-x.is-fullscreen .code-host { flex: 1; height: auto !important; }
body.code-fullscreen-open { overflow: hidden; }

/* ---------- Employer signature block ---------- */
.sig-block { display: flex; justify-content: space-between; gap: 2rem; margin-top: 1.5rem; flex-wrap: wrap; }
.sig-cell { text-align: center; min-width: 180px; flex: 1; }
.sig-caption { font-weight: 700; margin-bottom: .25rem; }
.sig-img { max-height: 90px; max-width: 220px; object-fit: contain; display: block; margin: 0 auto; }
.sig-placeholder { height: 90px; display: flex; align-items: center; justify-content: center; color: var(--c-muted); font-size: .8rem; }
.sig-name { font-weight: 600; }
.sig-title { color: var(--c-muted); font-size: .85rem; }
.sig-preview { max-height: 60px; max-width: 160px; object-fit: contain; background: #fff; border: 1px dashed var(--c-border); border-radius: 6px; padding: 2px; }
@media print { .sig-block { break-inside: avoid; } }

/* ==========================================================================
   برندینگ سازمان: shell.js فقط --brand را تنظیم می‌کند و بقیه‌ی رنگ‌ها اینجا (جدا برای هر پوسته) مشتق می‌شوند.
   ========================================================================== */
:root[data-branded] {
  --c-primary: var(--brand);
  --c-primary-600: color-mix(in srgb, var(--brand) 85%, #000);
  --c-primary-50: color-mix(in srgb, var(--brand) 8%, #fff);
  --bs-primary: var(--brand);
  --bs-primary-rgb: var(--brand-rgb);
}

/* ==========================================================================
   حالت تاریک — data-bs-theme="dark" روی <html> (پیش از رسم صفحه توسط theme-init.js تنظیم می‌شود).
   برگه‌ی نامه، بوم BPMN و کادر امضا عمداً سفید می‌مانند (سند چاپی/نمودار).
   ========================================================================== */
[data-bs-theme="dark"] {
  color-scheme: dark;
  --c-primary: #3f6fd1;
  --c-primary-600: #4d7ddd;
  --c-primary-50: #1d2a45;
  --c-primary-text: #8fb4ff;
  --c-accent: #34d399;
  --c-warning: #f59e0b;
  --c-danger: #f87171;
  --c-text: #e6e9f0;
  --c-muted: #98a2b3;
  --c-border: #2c3445;
  --c-surface: #171c28;
  --c-bg: #0f131c;
  --c-sidebar: #0c111b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 4px 16px rgba(0, 0, 0, .5);
  --bs-primary-rgb: 143, 180, 255;
  --bs-body-bg: #171c28;
  --bs-body-bg-rgb: 23, 28, 40;
  --bs-body-color: #e6e9f0;
  --bs-body-color-rgb: 230, 233, 240;
  --bs-secondary-color: rgba(230, 233, 240, .7);
  --bs-secondary-bg: #232a3a;
  --bs-tertiary-bg: #1c2231;
  --bs-border-color: #2c3445;
  --bs-border-color-translucent: rgba(255, 255, 255, .12);
  --bs-emphasis-color: #fff;
}
:root[data-branded][data-bs-theme="dark"] {
  --c-primary: color-mix(in srgb, var(--brand) 78%, #fff);
  --c-primary-600: color-mix(in srgb, var(--brand) 66%, #fff);
  --c-primary-50: color-mix(in srgb, var(--brand) 28%, #141a26);
  --c-primary-text: color-mix(in srgb, var(--brand) 40%, #fff);
  --bs-primary-rgb: var(--brand-rgb-light);
}
[data-bs-theme="dark"] .sidebar { border-inline-end: 1px solid var(--c-border); }
[data-bs-theme="dark"] .chip.success { background: #10321f; color: #6ee7b7; }
[data-bs-theme="dark"] .chip.warning { background: #3a2a0c; color: #fbbf24; }
[data-bs-theme="dark"] .chip.danger, [data-bs-theme="dark"] .form-error { background: #3b1717; color: #fca5a5; }
[data-bs-theme="dark"] .chip.muted, [data-bs-theme="dark"] .frm-wizard-steps .step:not(.active), [data-bs-theme="dark"] .fb-el-bar .type { background: #232a3a; }
[data-bs-theme="dark"] .dt-table th, [data-bs-theme="dark"] .code-toolbar { background: #1c2231; }
[data-bs-theme="dark"] .dt-table tbody tr:hover td { background: #1b2130; }
[data-bs-theme="dark"] .auth-body { background: radial-gradient(circle at 20% 10%, #1a2742 0, transparent 40%), var(--c-bg); }
[data-bs-theme="dark"] .frm-grid-row,
[data-bs-theme="dark"] .frm-richtext,
[data-bs-theme="dark"] .frm-multiselect .ms-chips,
[data-bs-theme="dark"] .frm-multiselect .ms-list,
[data-bs-theme="dark"] .fb-palette-item,
[data-bs-theme="dark"] .fb-el,
[data-bs-theme="dark"] .code-editor-x { background: #121722; color: var(--c-text); }
[data-bs-theme="dark"] .frm-multiselect .ms-chips input, [data-bs-theme="dark"] .frm-multiselect .ms-list button { background: transparent; color: inherit; }
[data-bs-theme="dark"] .fb-el:hover { border-color: #3b4a6b; }
[data-bs-theme="dark"] .fb-el.selected { box-shadow: 0 0 0 3px rgba(143, 180, 255, .2); }
[data-bs-theme="dark"] .fb-col { border-color: var(--c-border); }
[data-bs-theme="dark"] .frm-rating button { color: #475569; }
[data-bs-theme="dark"] .viz { --viz-grid: #2c3445; --viz-track: #232a3a; --series-1: #5b9bef; --series-2: #f08a5d; }
[data-bs-theme="dark"] .subscription-banner { background: #3a2a0c; color: #fcd68a; border-color: #5a4212; }
[data-bs-theme="dark"] .subscription-banner.danger { background: #3b1717; color: #fca5a5; border-color: #5c2323; }
[data-bs-theme="dark"] .jdp .jdp-input::placeholder { color: #5b6577; }
[data-bs-theme="dark"] .jdp-day:disabled { color: #4a5364; }
[data-bs-theme="dark"] .compare-table td.best-price { background: rgba(52, 211, 153, .16); }
[data-bs-theme="dark"] :focus-visible { outline-color: rgba(143, 180, 255, .6); }
/* کلاس‌های روشن Bootstrap که در کد صفحه‌ها به‌کار رفته‌اند */
[data-bs-theme="dark"] .bg-light, [data-bs-theme="dark"] .bg-white { background-color: var(--bs-tertiary-bg) !important; color: var(--c-text); }
[data-bs-theme="dark"] .text-dark { color: var(--c-text) !important; }
[data-bs-theme="dark"] .btn-light { --bs-btn-bg: #232a3a; --bs-btn-border-color: #2c3445; --bs-btn-color: var(--c-text); --bs-btn-hover-bg: #2c3445; --bs-btn-hover-border-color: #3b4a6b; --bs-btn-hover-color: #fff; --bs-btn-active-bg: #2c3445; --bs-btn-active-color: #fff; }
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: var(--c-primary-text); --bs-btn-border-color: var(--c-primary-text); --bs-btn-hover-bg: var(--c-primary); --bs-btn-hover-border-color: var(--c-primary); --bs-btn-active-bg: var(--c-primary); --bs-btn-active-border-color: var(--c-primary); }
[data-bs-theme="dark"] .table-light { --bs-table-bg: #1c2231; --bs-table-color: var(--c-text); --bs-table-border-color: var(--c-border); }
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select { background-color: #121722; }
[data-bs-theme="dark"] .form-control:disabled, [data-bs-theme="dark"] .form-select:disabled, [data-bs-theme="dark"] .form-control[readonly] { background-color: #1c2231; }
[data-bs-theme="dark"] .bpmn-props .form-control { background-color: #121722; }

/* ---------- دکمه‌ی پوسته و نصب برنامه ---------- */
.theme-toggle .fa-sun { display: none; }
[data-bs-theme="dark"] .theme-toggle .fa-sun { display: inline-block; }
[data-bs-theme="dark"] .theme-toggle .fa-moon { display: none; }
.auth-tools { position: fixed; top: .75rem; inset-inline-end: .75rem; display: flex; gap: .25rem; }
