:root {
  --blue: #2563EB; --blue-h: #1D4ED8; --blue-soft: rgba(37, 99, 235, .10);
  --teal: #059669; --teal-soft: rgba(5, 150, 105, .10);
  --warn: #D97706; --warn-soft: rgba(217, 119, 6, .10);
  --danger: #DC2626; --danger-soft: rgba(220, 38, 38, .08);
  --bg: #F4F6FC; --card: #FFFFFF; --surface: #EBEEF8; --surface2: #DDE2F0;
  --bd: rgba(0, 0, 0, .08); --bd2: rgba(0, 0, 0, .14);
  --text: #0B0F1A; --text2: #4B5468; --text3: #9299AE;
  --r: 8px; --rl: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06); --shadow-md: 0 8px 24px rgba(15, 23, 42, .12);
  --side: 236px;
  font-family: "Noto Sans Arabic", system-ui, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.55; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--card); border-left: 1px solid var(--bd); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 14px 10px; }
.side .brand { display: flex; flex-direction: column; align-items: center; padding: 4px 8px 14px; border-bottom: 1px solid var(--bd); margin-bottom: 10px; }
.side .brand img { width: 150px; }
.side .sect { font-size: 11.5px; color: var(--text3); padding: 12px 12px 4px; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--r); color: var(--text2); margin: 1px 0; }
.side a.nav i { font-size: 18px; }
.side a.nav:hover { background: var(--bg); color: var(--text); }
.side a.nav.on { background: var(--blue-soft); color: var(--blue); font-weight: 500; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 58px; background: var(--card); border-bottom: 1px solid var(--bd); display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 20; }
.top h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; }
.top .user { display: flex; align-items: center; gap: 8px; color: var(--text2); font-size: 13px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; font-weight: 600; }
.burger { display: none; }
.page { padding: 20px; max-width: 1400px; width: 100%; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r); border: 1px solid var(--bd2); background: var(--card); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-h); }
.btn.green { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.danger { color: var(--danger); border-color: rgba(220, 38, 38, .35); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 32px; padding: 0; justify-content: center; }
.btn:disabled { opacity: .55; cursor: default; }
.btn i { font-size: 17px; }
input, select, textarea { height: 38px; border: 1px solid var(--bd2); border-radius: var(--r); padding: 0 10px; background: #fff; width: 100%; }
textarea { height: 70px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
input[type=checkbox] { width: 18px; height: 18px; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text2); }
label.f.req > span::after { content: " *"; color: var(--danger); }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.form .wide { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--text3); }
.calc { background: var(--teal-soft); color: var(--teal); border-radius: var(--r); padding: 8px 12px; font-size: 13px; }

/* ---------- cards & tables ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.card { background: var(--card); border: 1px solid var(--bd); border-radius: var(--rl); box-shadow: var(--shadow-sm); }
.card.pad { padding: 16px 18px; }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--bd); border-radius: var(--rl); padding: 14px 16px; }
.kpi .l { color: var(--text2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 22px; font-weight: 600; margin-top: 4px; }
.kpi .s { font-size: 12px; color: var(--text3); }
.kpi.blue .v { color: var(--blue); } .kpi.green .v { color: var(--teal); } .kpi.warn .v { color: var(--warn); } .kpi.red .v { color: var(--danger); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { background: #F8F9FD; color: var(--text2); font-weight: 500; text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--bd); white-space: nowrap; position: sticky; top: 0; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--bd); white-space: nowrap; }
table.t tbody tr:hover { background: #FAFBFF; }
table.t tfoot td { font-weight: 600; background: var(--surface); border-top: 1px solid var(--bd2); }
table.t tr.sub td { background: var(--blue-soft); font-weight: 600; }
table.t td.n, table.t th.n { text-align: left; font-variant-numeric: tabular-nums; }
table.t .pos { color: var(--teal); } table.t .neg { color: var(--danger); }
.empty { padding: 40px; text-align: center; color: var(--text3); }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: var(--surface); color: var(--text2); }
.badge.blue { background: var(--blue-soft); color: var(--blue); } .badge.green { background: var(--teal-soft); color: var(--teal); }
.badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.red { background: var(--danger-soft); color: var(--danger); }
.alert { border-radius: var(--r); padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }
.alert.warn { background: var(--warn-soft); color: #92400E; } .alert.ok { background: var(--teal-soft); color: #065F46; } .alert.info { background: var(--blue-soft); color: #1E3A8A; }
.bars .row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 110px; gap: 10px; align-items: center; margin: 8px 0; font-size: 13px; }
.bars .bar { height: 10px; border-radius: 6px; background: var(--surface); overflow: hidden; }
.bars .bar span { display: block; height: 100%; background: var(--blue); border-radius: 6px; }

/* ---------- modal & toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(11, 15, 26, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--card); border-radius: var(--rl); width: 100%; max-width: 760px; box-shadow: var(--shadow-md); }
.modal .mh { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--bd); }
.modal .mh h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal .mb { padding: 18px; }
.modal .mf { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 18px; border-top: 1px solid var(--bd); background: #FAFBFF; border-radius: 0 0 var(--rl) var(--rl); }
.toasts { position: fixed; bottom: 18px; left: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--r); box-shadow: var(--shadow-md); font-size: 13px; }
.toast.err { background: var(--danger); } .toast.ok { background: var(--teal); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .box { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--bd); border-radius: 20px; padding: 28px; box-shadow: var(--shadow-md); }
.login img { width: 230px; display: block; margin: 0 auto 18px; }
.login .tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: var(--r); padding: 4px; margin-bottom: 16px; }
.login .tabs button { border: 0; background: transparent; height: 34px; border-radius: 6px; cursor: pointer; color: var(--text2); }
.login .tabs button.on { background: #fff; color: var(--text); box-shadow: var(--shadow-sm); font-weight: 500; }
.login form { display: grid; gap: 12px; }
.login .btn { width: 100%; justify-content: center; height: 40px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--surface2); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- invoice ---------- */
.doc { background: #fff; max-width: 900px; margin: 0 auto; padding: 32px 36px; border: 1px solid var(--bd); border-radius: var(--rl); }
.doc .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 2px solid var(--blue); padding-bottom: 14px; margin-bottom: 16px; }
.doc .head img { width: 210px; }
.doc .head .co { font-size: 12.5px; color: var(--text2); line-height: 1.8; }
.doc h2.title { text-align: center; margin: 4px 0 16px; font-size: 20px; color: var(--blue); }
.doc .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; margin-bottom: 16px; font-size: 13px; }
.doc .meta div b { color: var(--text2); font-weight: 500; margin-left: 6px; }
.doc .totals { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-top: 16px; }
.doc .totals table { width: 320px; font-size: 13.5px; border-collapse: collapse; }
.doc .totals td { padding: 7px 10px; border-bottom: 1px solid var(--bd); }
.doc .totals tr:last-child td { font-weight: 700; background: var(--blue-soft); color: var(--blue); }
.doc .qr { width: 130px; height: 130px; }
.doc .foot { margin-top: 24px; font-size: 12px; color: var(--text3); text-align: center; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; right: 0; top: 0; z-index: 40; width: 260px; transform: translateX(105%); transition: transform .2s; box-shadow: var(--shadow-md); }
  .side.open { transform: none; }
  .burger { display: inline-flex; }
  .page { padding: 14px; }
  .top { padding: 0 12px; }
  .top .user span { display: none; }
  .doc { padding: 18px; }
  .doc .meta { grid-template-columns: 1fr; }
  .bars .row { grid-template-columns: 90px minmax(0, 1fr) 90px; }
}

/* ---------- print ---------- */
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 12px; }
  .side, .top, .toolbar, .no-print, .toasts { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; max-width: none; }
  .card, .doc { border: 0; box-shadow: none; padding: 0; }
  table.t th { position: static; }
  table.t td, table.t th { padding: 5px 6px; }
  .print-only { display: block !important; }
  .print-head { display: flex !important; }
}
.print-only { display: none; }
.print-head { align-items: center; justify-content: space-between; border-bottom: 2px solid var(--blue); padding-bottom: 8px; margin-bottom: 12px; }
.print-head img { width: 150px; }
