:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7486;
  --line: #e2e6ee;
  --brand: #1f4e8c;
  --brand-2: #2f6fc4;
  --brand-ink: #ffffff;
  --side: #17233a;
  --side-ink: #c9d3e6;
  --ok: #1e8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); text-decoration: none; }
.num, td.num, th.num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }

/* ---------- تسجيل الدخول ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #17233a, #1f4e8c); }
.login-card { width: 360px; max-width: 92vw; background: var(--panel); border-radius: 14px; padding: 32px 28px; box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.login-card h1 { margin: 0 0 4px; font-size: 24px; color: var(--brand); }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card .logo { width: 56px; height: 56px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #dfe5ee 60%, #b9c3d3); box-shadow: inset -4px -6px 10px rgba(0,0,0,.12), 0 4px 10px rgba(0,0,0,.15); margin-bottom: 14px; }

/* ---------- الهيكل ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 14px 0; overflow-y: auto; height: 100vh; position: sticky; top: 0; }
.side .brand { padding: 4px 18px 14px; font-weight: 700; font-size: 18px; color: #fff; display: flex; align-items: center; gap: 10px; }
.side .brand .dot { width: 26px; height: 26px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #cfd8e6 60%, #9aa8bf); }
.side .grp { margin-top: 6px; }
.side .grp > .gt { padding: 8px 18px; font-size: 12px; color: #8a97b1; cursor: pointer; display: flex; justify-content: space-between; user-select: none; }
.side .grp.closed .links { display: none; }
.side a { display: block; padding: 7px 26px; color: var(--side-ink); border-inline-start: 3px solid transparent; }
.side a:hover { background: rgba(255,255,255,.05); color: #fff; }
.side a.on { background: rgba(47,111,196,.25); color: #fff; border-inline-start-color: #5b9bf0; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 20px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 5; }
.top .title { font-weight: 700; font-size: 17px; flex: 1; }
.top .who { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; }
.content { padding: 18px 20px 40px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 0 0 auto; width: 260px; z-index: 30; transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
}

/* ---------- عناصر عامة ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row > .f { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.row > .f.grow { flex: 1; min-width: 200px; }
.row > .f.sm { min-width: 90px; width: 110px; }
label.l { font-size: 12px; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  border: 1px solid #cfd5df; border-radius: 6px; padding: 7px 9px; background: #fff; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(47,111,196,.15); }
input[readonly] { background: #f6f7f9; }
.btn { border: 1px solid #cfd5df; background: #fff; border-radius: 6px; padding: 7px 14px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f4f6fa; }
.btn.p { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.p:hover { background: var(--brand-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { color: var(--bad); border-color: #e7b9b3; }
.btn.bad:hover { background: #fdf1ef; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.toolbar .sp { flex: 1; }
.muted { color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: #eef2f8; color: #3c4a63; }
.tag.void { background: #fdecea; color: var(--bad); }
.tag.ok { background: #e7f6ee; color: var(--ok); }
.pos { color: var(--ok); } .neg { color: var(--bad); }

/* ---------- الجداول ---------- */
.tbl-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th { background: #f6f8fb; position: sticky; top: 0; font-weight: 600; font-size: 13px; color: #44506a; z-index: 1; }
table.t tbody tr:hover { background: #f8fafd; }
table.t tr.click { cursor: pointer; }
table.t tfoot td { background: #f6f8fb; font-weight: 700; position: sticky; bottom: 0; }
table.t tr.void td { color: #a3a9b5; text-decoration: line-through; }
table.lines td { padding: 4px 6px; }
table.lines input { padding: 5px 7px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; direction: ltr; text-align: right; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; direction: ltr; text-align: right; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; direction: ltr; }
.bars .b { flex: 1; background: var(--brand-2); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .b:hover { background: var(--brand); }
.bars .b:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 2px 6px; border-radius: 4px; font-size: 11px; white-space: nowrap; }

/* ---------- البحث المنسدل ---------- */
.combo { position: relative; }
.combo .dd { position: absolute; top: 100%; inset-inline: 0; background: #fff; border: 1px solid #cfd5df; border-radius: 6px; max-height: 280px; overflow: auto; z-index: 20; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.combo .dd div { padding: 6px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo .dd div.hl, .combo .dd div:hover { background: #eaf1fb; }
.combo .dd small { color: var(--muted); }

/* ---------- النوافذ ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,15,25,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 640px; max-width: calc(100vw - 32px); max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.wide { width: 960px; }
.modal .mh { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; justify-content: space-between; }
.modal .mb { padding: 16px 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-start; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.grid2 .f, .grid3 .f { display: flex; flex-direction: column; gap: 4px; }
.perm-grid { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px 16px; align-items: center; }
.perm-grid .h { font-weight: 600; color: var(--muted); font-size: 12px; }

/* ---------- الاشعارات ---------- */
#toasts { position: fixed; bottom: 16px; left: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 16px rgba(0,0,0,.2); max-width: 420px; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- محرر الفاتورة ---------- */
.doc-totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.doc-totals .f { display: flex; flex-direction: column; gap: 4px; }
.doc-totals .big input { font-size: 18px; font-weight: 700; }
.scan { font-size: 16px; padding: 10px 12px !important; }

/* ---------- الطباعة ---------- */
#print-area { display: none; }
@media print {
  @page { margin: 10mm; }
  body { background: #fff; }
  #app, #toasts, .modal-bg { display: none !important; }
  #print-area { display: block; }
}
.pdoc { font-size: 13px; color: #000; }
.pdoc .ph { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 10px; }
.pdoc .ph h2 { margin: 0; font-size: 20px; }
.pdoc .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; margin-bottom: 10px; }
.pdoc table { width: 100%; border-collapse: collapse; }
.pdoc th, .pdoc td { border: 1px solid #444; padding: 4px 6px; text-align: right; }
.pdoc th { background: #eee; }
.pdoc .tot { margin-top: 10px; display: flex; justify-content: flex-end; }
.pdoc .tot table { width: auto; min-width: 260px; }
.pdoc .foot { margin-top: 24px; text-align: center; font-size: 12px; }
.pdoc .sign { margin-top: 40px; display: flex; justify-content: space-around; }
.pdoc.r80 { width: 72mm; font-size: 11px; }
.pdoc.r80 .meta { grid-template-columns: 1fr; }
.pdoc.r80 th, .pdoc.r80 td { border: none; border-bottom: 1px dashed #777; padding: 2px; }

/* ---------- العمل بدون انترنت ---------- */
.net { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 4px 12px 4px 12px; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.net::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.net.off { background: #fff4e5; border-color: #f0c27a; color: #8a5300; }
.net.off::before { background: var(--warn); }
.net.busy::before { background: var(--brand-2); }
.tag.wait { background: #fff4e5; color: #8a5300; }
.offline-note { background: #fff4e5; border: 1px solid #f0c27a; color: #6b4300; border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; }
.offline-panel h3 { color: #8a5300; }
