:root {
  --navy: #17324D; --navy-dark: #10263B; --teal: #0E8C7F; --teal-dark: #0A6F65; --mint: #DDF3EC;
  --page: #F2F5F9; --card: #fff; --ink: #14263A; --muted: #5B6B7D; --line: #E1E7EE; --field: #B9C5D2;
  --amber: #9A5B00; --amber-bg: #FFF1D9; --red: #A3262E; --red-bg: #FBE3E0; --green: #0B6B3A; --grey: #EDF1F5;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", Tahoma, Arial, sans-serif; font-size: 15px; color: var(--ink); background: var(--page); }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- الهيكل ---------- */
.shell { display: flex; min-height: 100%; }
.side { width: 230px; background: var(--navy); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 16px; font-weight: 700; font-size: 18px; }
.brand .logo { width: 38px; height: 38px; border-radius: 10px; background: var(--teal); display: grid; place-items: center; }
.nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.nav button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 12px; margin-bottom: 4px; border: 0; border-radius: 10px; background: transparent; color: #DCE6F0; cursor: pointer; text-align: right; font-weight: 600; }
.nav button:hover { background: rgba(255,255,255,.08); }
.nav button.on { background: var(--teal); color: #fff; }
svg { width: 20px; height: 20px; flex-shrink: 0; }
.sim { margin: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.08); color: #FFD88A; font-size: 13px; font-weight: 600; text-align: center; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 22px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.top h1 { font-size: 18px; margin: 0; }
.top .sub { color: var(--muted); font-size: 13px; }
.top .grow { flex: 1; }
.userbox { display: flex; align-items: center; gap: 8px; background: var(--page); border-radius: 20px; padding: 6px 14px; font-weight: 600; }
.btn.menu-btn { display: none; }
.content { padding: 22px; max-width: 1280px; width: 100%; }

/* ---------- عناصر ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 150px; flex: 1; }
.field.small { flex: 0 0 120px; min-width: 100px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea { border: 1px solid var(--field); border-radius: 10px; padding: 9px 12px; background: #fff; min-height: 42px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
.btn { border: 1px solid var(--field); background: #fff; border-radius: 10px; padding: 9px 18px; min-height: 42px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn:hover { background: var(--page); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.teal { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.teal:hover { background: var(--teal-dark); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.sm { padding: 5px 12px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.msg { padding: 10px 14px; border-radius: 10px; margin: 12px 0 0; font-weight: 600; }
.msg.err { background: var(--red-bg); color: var(--red); }
.msg.ok { background: var(--mint); color: var(--green); }
.msg.info { background: var(--grey); color: var(--muted); }
.muted { color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 18px; }
.tile { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 22px 16px; cursor: pointer; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.tile small { font-weight: 400; color: var(--muted); font-size: 12px; }
.tile svg { width: 34px; height: 34px; }
.tile:hover { border-color: var(--teal); box-shadow: 0 4px 14px rgba(23,50,77,.08); }
.tile.navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.tile.navy small { color: #C9D6E3; }
.tile.teal { border: 2px solid var(--teal); color: var(--teal-dark); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: right; font-size: 13px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #F8FAFC; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.pill { display: inline-block; padding: 4px 12px; border-radius: 14px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.pill.Valid { background: var(--mint); color: var(--green); }
.pill.Invalid { background: var(--red-bg); color: var(--red); }
.pill.Pending, .pill.Unknown { background: var(--amber-bg); color: var(--amber); }
.pill.None, .pill.NotSent { background: var(--grey); color: var(--muted); }
.ico { width: 34px; height: 34px; border-radius: 9px; display: inline-grid; place-items: center; vertical-align: middle; margin-inline-end: 8px; }
.ico.Sale { background: var(--mint); color: var(--teal); }
.ico.Purchase { background: var(--grey); color: var(--navy); }
.ico.Return, .ico.CreditNote, .ico.DebitNote { background: var(--amber-bg); color: var(--amber); }

/* ---------- بحث العميل ---------- */
.suggest { position: relative; }
.suggest-list { position: absolute; inset-inline: 0; top: 100%; z-index: 20; background: #fff; border: 1px solid var(--field); border-radius: 10px; margin-top: 4px; box-shadow: 0 10px 24px rgba(23,50,77,.14); max-height: 300px; overflow-y: auto; }
.suggest-list div { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.suggest-list div:last-child { border-bottom: 0; }
.suggest-list div:hover { background: var(--mint); }
.suggest-list small { color: var(--muted); display: block; }
.chosen { background: var(--mint); border-radius: 10px; padding: 10px 14px; margin-top: 12px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.totals { display: flex; gap: 26px; flex-wrap: wrap; justify-content: flex-end; margin-top: 14px; font-size: 16px; }
.totals b { font-size: 20px; }

/* ---------- تسجيل الدخول ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-dark) 100%); }
.login .card { width: 100%; max-width: 400px; padding: 28px; }
.login .brand { color: var(--ink); padding: 0 0 18px; justify-content: center; }
.login .field { margin-bottom: 12px; }
.login .btn { width: 100%; margin-top: 6px; }

/* ---------- نافذة ---------- */
.modal { position: fixed; inset: 0; background: rgba(16,38,59,.55); z-index: 50; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal .box { background: #fff; border-radius: 16px; padding: 22px; width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal .box.paper-box { max-width: 440px; background: #EEF3F7; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 22px; border-radius: 12px; z-index: 60; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }

/* ---------- ورقة الإيصال ---------- */
.paper { background: #fff; border: 1px solid #999; padding: 18px; width: 100%; max-width: 380px; margin: 0 auto; color: #000; font-size: 13px; }
.paper .banner { border: 2px solid var(--red); color: var(--red); font-weight: 700; text-align: center; padding: 6px; font-size: 15px; margin-bottom: 8px; }
.paper .c { text-align: center; }
.paper .b { font-weight: 700; }
.paper hr { border: 0; border-top: 1px solid #000; margin: 7px 0; }
.paper .pr { display: flex; justify-content: space-between; gap: 10px; margin: 2px 0; }
.paper .mono { font-family: Consolas, monospace; font-size: 11px; direction: ltr; text-align: left; word-break: break-all; }
.paper img { display: block; margin: 10px auto 6px; width: 150px; height: 150px; }

@media (max-width: 820px) {
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40; transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .content { padding: 14px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 16px 8px; font-size: 15px; }
  .top { padding: 10px 14px; }
}
@media print {
  body { background: #fff; }
  #app, .toast, .no-print { display: none !important; }
  .modal { position: static; background: none; padding: 0; display: block; }
  .modal .box { padding: 0; max-height: none; overflow: visible; background: #fff; }
  .paper { border: 0; margin: 0; }
}

/* شريط «نزلت نسخة جديدة» */
.update-bar{position:fixed;inset-inline:12px;bottom:12px;z-index:60;display:flex;gap:12px;align-items:center;justify-content:space-between;flex-wrap:wrap;
  background:#123049;color:#fff;padding:10px 14px;border-radius:12px;box-shadow:0 6px 24px rgba(0,0,0,.25);font-size:14px}
@media print{.update-bar{display:none}}
/* ملاحظة البند تحت اسم الصنف */
.line-note{font-size:12px;color:#5b6b7b;font-weight:400;margin-top:2px;white-space:normal}
.paper .line-note{font-size:11px;color:#333}
.perm-groups{display:grid;grid-template-columns:repeat(auto-fill,minmax(230px,1fr));gap:14px;margin:14px 0}
.perm-group{border:1px solid #e3e8ee;border-radius:10px;padding:10px 12px;display:flex;flex-direction:column;gap:6px}
.perm-group>b{margin-bottom:2px}
.perm{display:flex;align-items:center;gap:8px;cursor:pointer;font-size:14px}
.perm input{width:auto;margin:0}
.perm .pill{font-size:11px;padding:1px 6px}
