/* بابيلون ERP — هوية هادئة وبسيطة. كل الألوان والمسافات رموز في :root. */
:root {
  --accent: #3b5bdb; --accent-600: #2f4ac0; --accent-soft: #e8edff; --on-accent: #fff;
  --bg: #f6f7fb; --surface: #fff; --surface-2: #f1f3f9; --border: #e3e6ef; --border-strong: #cfd4e3;
  --text: #1a2033; --text-2: #5b6580; --text-3: #8a93ab;
  --ok: #1f8a4c; --ok-soft: #e4f6ec; --warn: #b7791f; --warn-soft: #fff4de; --bad: #d1344a; --bad-soft: #fde8eb; --info-soft: #e8edff;
  --r-s: 8px; --r: 12px; --r-l: 16px; --gap: 16px; --side-w: 248px; --top-h: 60px;
  --font: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --shadow: 0 1px 2px rgba(20, 28, 58, .05), 0 8px 24px rgba(20, 28, 58, .06);
  color-scheme: light;
}
:root[data-theme='dark'] {
  --accent: #7c93f5; --accent-600: #96a8f8; --accent-soft: #232b4d; --on-accent: #0f1428;
  --bg: #0f1424; --surface: #171d33; --surface-2: #1d2440; --border: #2a3354; --border-strong: #3a4570;
  --text: #e8ebf6; --text-2: #aab2cc; --text-3: #7b84a3;
  --ok: #4cc98a; --ok-soft: #14301f; --warn: #f0b95a; --warn-soft: #3a2c10; --bad: #ff7a8c; --bad-soft: #3d1a22; --info-soft: #232b4d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --accent: #7c93f5; --accent-600: #96a8f8; --accent-soft: #232b4d; --on-accent: #0f1428;
    --bg: #0f1424; --surface: #171d33; --surface-2: #1d2440; --border: #2a3354; --border-strong: #3a4570;
    --text: #e8ebf6; --text-2: #aab2cc; --text-3: #7b84a3;
    --ok: #4cc98a; --ok-soft: #14301f; --warn: #f0b95a; --warn-soft: #3a2c10; --bad: #ff7a8c; --bad-soft: #3d1a22; --info-soft: #232b4d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.6; color: var(--text); background: var(--bg); overflow-x: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; }
h2 { font-size: 18px; } h3 { font-size: 16px; } h4 { font-size: 14px; color: var(--text-2); }
p { margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num, .ltr { white-space: nowrap; direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; }
.neg { color: var(--bad); }
.dim { color: var(--text-2); } .dim2 { color: var(--text-3); }
.small { font-size: 13px; }
.bold { font-weight: 700; }
.hidden { display: none !important; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.between { justify-content: space-between; }
.end { margin-inline-start: auto; }
.center { text-align: center; }

/* ----- الهيكل ----- */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-inline-end: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; font-weight: 700; font-size: 17px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.nav-group { margin-top: 10px; }
.nav-title { font-size: 12px; color: var(--text-3); padding: 4px 10px; font-weight: 600; letter-spacing: .02em; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 12px; border-radius: var(--r-s); color: var(--text-2); font-weight: 600; text-decoration: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current='page'] { background: var(--accent-soft); color: var(--accent); }
svg.i { width: 18px; height: 18px; flex: none; }
.nav svg { width: 20px; height: 20px; flex: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: 12px; padding: 0 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.top h1 { font-size: 19px; }
.burger { display: none; }
.content { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }
.scrim { display: none; }
.userbtn { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; cursor: pointer; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.menu { position: absolute; top: calc(var(--top-h) - 6px); inset-inline-end: 24px; min-width: 230px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); padding: 8px; z-index: 40; }
.menu button, .menu .mi { display: flex; width: 100%; align-items: center; gap: 10px; min-height: 42px; padding: 0 12px; border: 0; background: none; border-radius: var(--r-s); cursor: pointer; text-align: start; }
.menu button:hover { background: var(--surface-2); }
.menu .who { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }

/* ----- مكونات ----- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-l); padding: 20px; }
.card + .card { margin-top: var(--gap); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: var(--gap); }
.grid > *, .stack > *, .card, .modal-b { min-width: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { padding: 16px 18px; } .kpi .l { color: var(--text-2); font-size: 13px; font-weight: 600; } .kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; } .kpi .s { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: var(--r-s); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); } .btn.primary:hover { background: var(--accent-600); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); } .btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 44px; padding: 0; } .btn svg { width: 18px; height: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
input, select, textarea { min-height: 44px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-s); background: var(--surface); width: 100%; }
textarea { min-height: 88px; resize: vertical; }
input[type='checkbox'], input[type='radio'] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--accent); }
input[type='date'] { direction: ltr; text-align: end; }
input.num-in { direction: ltr; text-align: end; font-variant-numeric: tabular-nums; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--text-3); }
.form { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); } .form .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .field { min-width: 150px; } .toolbar .search { min-width: 220px; flex: 1 1 220px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 18px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { min-height: 44px; padding: 0 16px; border: 0; background: none; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); } .tab[aria-selected='true'] { color: var(--accent); border-bottom-color: var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.warn { background: var(--warn-soft); color: var(--warn); } .chip.bad { background: var(--bad-soft); color: var(--bad); } .chip.info { background: var(--info-soft); color: var(--accent); }
.note { padding: 10px 14px; border-radius: var(--r-s); background: var(--info-soft); color: var(--text); font-size: 13px; }
.note.warn { background: var(--warn-soft); } .note.bad { background: var(--bad-soft); } .note.ok { background: var(--ok-soft); }
.empty { padding: 36px 16px; text-align: center; color: var(--text-3); }
.loading { padding: 36px 16px; text-align: center; color: var(--text-3); }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; margin-inline-end: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- الجداول ----- */
.tw { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 13px; font-weight: 700; color: var(--text-2); white-space: nowrap; z-index: 1; }
tbody tr:last-child td { border-bottom: 0; } tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
td.n, th.n { text-align: end; } tfoot td { font-weight: 700; background: var(--surface-2); }
tr.sub td:first-child { padding-inline-start: 30px; }
tr.group td { background: var(--surface-2); font-weight: 700; font-size: 13px; color: var(--text-2); }
tr.voided td { color: var(--text-3); text-decoration: line-through; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 4px 0; color: var(--text-2); font-size: 13px; flex-wrap: wrap; }
.sect td { font-weight: 700; background: var(--surface-2); }
.tree-1 td:first-child { padding-inline-start: 34px; } .tree-2 td:first-child { padding-inline-start: 54px; }

/* ----- نوافذ وتنبيهات ----- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(10, 14, 30, .55); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--r-l); border: 1px solid var(--border); width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { width: min(920px, 100%); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 20px; overflow-y: auto; } .modal-f { display: flex; gap: 10px; justify-content: flex-start; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.toasts { position: fixed; bottom: 20px; inset-inline-start: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); }
.toast { padding: 12px 16px; border-radius: var(--r-s); background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-weight: 600; animation: pop .2s ease; }
.toast.ok { background: var(--ok); color: #fff; } .toast.bad { background: var(--bad); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ----- دخول ----- */
.auth { min-height: 100vh; display: grid; grid-template-columns: min(440px, 100%); justify-content: center; align-content: center; padding: 20px; }
.auth-card { width: 100%; }
.auth-card .brand { justify-content: center; padding-bottom: 18px; font-size: 22px; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: var(--r); border: 1px solid var(--border); width: fit-content; margin: 0 auto; }
.qr svg { width: 200px; height: 200px; display: block; }
.secret { font-family: ui-monospace, Consolas, monospace; letter-spacing: .08em; word-break: break-all; padding: 10px 12px; background: var(--surface-2); border-radius: var(--r-s); direction: ltr; text-align: center; user-select: all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; direction: ltr; }
.codes span { font-family: ui-monospace, Consolas, monospace; padding: 8px; background: var(--surface-2); border-radius: var(--r-s); text-align: center; user-select: all; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--text-3); }

/* ----- أنماط خاصة ----- */
.bars { display: block; width: 100%; height: auto; }
.bars .bar { fill: var(--accent); } .bars .bar:hover { fill: var(--accent-600); } .bars text { fill: var(--text-3); font-size: 11px; font-family: var(--font); } .bars line { stroke: var(--border); }
.lines { display: grid; gap: 8px; }
.line-row { display: grid; grid-template-columns: minmax(180px, 3fr) 1fr 1fr 40px; gap: 8px; align-items: center; }
.pl-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.pl-total { font-weight: 700; font-size: 16px; border-bottom: 2px solid var(--border-strong); }
.check-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.ic { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; }
.ic.ok { background: var(--ok-soft); color: var(--ok); } .ic.warn { background: var(--warn-soft); color: var(--warn); } .ic.bad { background: var(--bad-soft); color: var(--bad); }
.tcard { display: flex; flex-direction: column; gap: 6px; } .tcard .bal { font-size: 24px; font-weight: 700; }
details summary { cursor: pointer; font-weight: 600; min-height: 36px; display: flex; align-items: center; }
.picker { position: relative; } .picker-list { position: absolute; inset-inline: 0; top: 100%; z-index: 30; max-height: 240px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-s); box-shadow: var(--shadow); }
.picker-list button { display: flex; width: 100%; gap: 8px; align-items: center; min-height: 40px; padding: 0 12px; border: 0; background: none; cursor: pointer; text-align: start; } .picker-list button:hover, .picker-list button.on { background: var(--accent-soft); }

.nav a .chip { margin-inline-start: auto; }
.map-cell { min-width: 240px; } .map-cell select { margin-bottom: 6px; }
.chip a, a.chip { text-decoration: none; }

/* ----- الهاتف ----- */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(300px, 86vw); z-index: 60; transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  [dir='rtl'] .side { transform: translateX(100%); } .side.open { transform: none !important; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 30, .5); }
  .burger { display: inline-flex; }
  .top { padding: 0 16px; } .content { padding: 16px; }
  .menu { inset-inline-end: 12px; }
  .g2, .g3, .g4, .form { grid-template-columns: 1fr; }
  .kpi .v { font-size: 20px; }
  .line-row { grid-template-columns: 1fr 1fr; } .line-row > :first-child { grid-column: 1 / -1; }
  .toolbar .field { flex: 1 1 140px; }
  th, td { padding: 10px; }
  .tw table { min-width: 640px; }
  .tw table td:nth-child(2) { min-width: 170px; }
  .tw table td:first-child, .tw table th:first-child { position: sticky; inset-inline-start: 0; background: var(--surface); z-index: 1; }
  .tw table thead th:first-child { background: var(--surface-2); z-index: 2; }
  .modal-f .btn { flex: 1 1 auto; }
  .card { padding: 16px; }
}
@media print {
  .side, .top, .toolbar, .tabs, .no-print, .toasts, .scrim { display: none !important; }
  .shell { display: block; } body { background: #fff; color: #000; } .content { padding: 0; max-width: none; }
  .card, .tw { border: 0; padding: 0; } .tw { overflow: visible; } thead th { position: static; }
  :root { --text: #000; --text-2: #333; --surface: #fff; --surface-2: #f2f2f2; --border: #bbb; }
}
