:root {
  /* هوية توميديا: ذهبي + أكحل */
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --border: #e7e1d4;
  --text: #17140f;
  --muted: #6f6656;
  --primary: #c9962b;        /* ذهبي — للخلفيات والأزرار */
  --primary-2: #b0821f;      /* ذهبي أغمق عند المرور */
  --primary-text: #8a6414;   /* ذهبي غامق — للنصوص والروابط على الأبيض (مقروء) */
  --on-primary: #121110;     /* الكتابة فوق الذهبي: أكحل */
  --primary-soft: #fbf3e0;
  --danger: #c2410c;
  --danger-soft: #fdeee6;
  --warn: #a16207;
  --warn-soft: #fdf6e3;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --side: #121110;           /* أكحل */
  --side-text: #d9cfc0;
  --gold-line: linear-gradient(90deg, #e9c46a, #c9962b);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-text); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
#print-frame { position: fixed; width: 0; height: 0; border: 0; left: -10px; top: -10px; }

/* ===== Layout ===== */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { display: block; color: #e9c46a; font-size: 16px; }
.brand span { font-size: 12px; opacity: .7; }
.nav { padding: 10px 8px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--side-text); margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: var(--on-primary); font-weight: 700; }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.nav .sep { font-size: 11px; opacity: .5; padding: 12px 12px 4px; }
.side-user { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side-user button { background: none; border: 0; color: #f4b8a0; cursor: pointer; padding: 0; margin-top: 4px; }
.main { min-width: 0; }
.topbar { display: none; }
.page { padding: 22px 24px 40px; max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== Components ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 16px; }
.card-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid { display: grid; gap: 14px; }
.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)); }
.stat { padding: 14px 16px; }
.stat .lbl { color: var(--muted); font-size: 12px; }
.stat .val { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat.ok .val { color: var(--ok); }
.stat.warn .val { color: var(--warn); }
.stat.danger .val { color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; white-space: nowrap; min-height: 36px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); border-color: #f1c7b3; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; min-height: 28px; font-size: 13px; }
.btn.lg { padding: 12px 20px; font-size: 16px; font-weight: 700; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.in, select.in, textarea.in { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); min-height: 36px; }
.in:focus { outline: 2px solid rgba(201,150,43,.3); border-color: var(--primary); }
.in.num-in { direction: ltr; text-align: right; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters .f { min-width: 140px; }

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th, .t td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.t th { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 12px; position: sticky; top: 0; }
.t tr:hover td { background: #fdfaf2; }
.t tfoot td { font-weight: 700; background: var(--surface-2); }
.t td.wrap { white-space: normal; }
.t tr.click { cursor: pointer; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--primary-soft); color: var(--primary-text); border-color: transparent; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary-text); border-bottom-color: var(--primary); font-weight: 600; }

/* ===== Modal & Toast ===== */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.netbar { position: fixed; top: 0; left: 0; right: 0; z-index: 70; background: #b3261e; color: #fff; text-align: center;
  padding: 8px 12px; font-size: 14px; font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.update-bar { position: fixed; bottom: 16px; right: 16px; left: 16px; max-width: 420px; margin: 0 auto; z-index: 65; display: flex; gap: 10px; align-items: center;
  background: var(--side, #121110); color: #fff; padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--primary); }
.update-bar span { flex: 1; font-size: 14px; }
#toast-root { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ===== Login ===== */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(circle at 80% 0%, rgba(201,150,43,.35), transparent 55%), linear-gradient(160deg, #121110, #241c10); }
.login { flex-direction: column; gap: 14px; }
.login .card { width: 100%; max-width: 380px; }
.login-logo { display: block; width: 96px; height: 96px; margin: 0 auto 10px; border-radius: 50%; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.credit { color: rgba(255,255,255,.75); font-size: 12px; }
.side-credit { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 11px; opacity: .6; }
.side-credit img { width: 18px; height: 18px; border-radius: 50%; }
.login h1 { margin-bottom: 4px; }

/* ===== POS ===== */
/* ترتيب نقطة البيع من اليمين: الحاسبة | الأصناف | الفاتورة والدفع — دائماً جنب بعض */
.pos { display: grid; grid-template-columns: 230px minmax(0, 1fr) 390px; gap: 12px; height: calc(100vh - 44px); }
.pos-right { min-width: 0; }
.numpad { display: flex; flex-direction: column; gap: 8px; padding: 10px; align-self: start; }
.np-screen { background: var(--side); color: #fff; border-radius: 8px; padding: 10px 12px; text-align: left; min-height: 92px; }
.np-screen .np-name { text-align: right; font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-screen .np-val { font-size: 30px; font-weight: 800; display: block; min-height: 40px; }
.np-screen .muted { color: #b9ab93; text-align: right; }
.np-modes { display: flex; gap: 6px; }
.np-modes button { flex: 1; min-height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.np-modes button.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.np-modes .np-del { color: var(--danger); border-color: #f1c7b3; }
.np-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; direction: ltr; }
.np-keys button { height: 58px; font-size: 22px; font-weight: 700; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.np-keys button:active, .np-modes button:active { transform: scale(.96); }
.np-keys button:hover { background: var(--primary-soft); }
.cart-row { cursor: pointer; }
.cart-row.sel { background: var(--primary-soft); box-shadow: inset -4px 0 0 var(--primary); }
.pos-left, .pos-right { display: flex; flex-direction: column; min-height: 0; }
.pos-search { display: flex; gap: 8px; margin-bottom: 10px; }
.pos-search .in { font-size: 16px; min-height: 44px; }
.cats { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; }
.cats button { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
.cats button.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; overflow-y: auto; align-content: start; padding-bottom: 10px; }
.prod { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; text-align: right; display: flex; flex-direction: column; gap: 6px; min-height: 96px; }
.prod:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.prod .n { font-weight: 600; line-height: 1.3; }
.prod .p { color: var(--primary-text); font-weight: 700; margin-top: auto; }
.prod .q { font-size: 12px; color: var(--muted); }
.prod.out { opacity: .5; }
.cart { flex: 1; overflow-y: auto; }
.cart-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.cart-row .n { font-weight: 600; }
.qty-ctl { display: flex; align-items: center; gap: 4px; }
.qty-ctl button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 16px; }
.qty-ctl input { width: 58px; text-align: center; padding: 4px; min-height: 30px; }
.pos-total { padding: 14px; border-top: 1px solid var(--border); background: var(--surface-2); }
.pos-total .row { display: flex; justify-content: space-between; padding: 3px 0; }
.pos-total .grand { font-size: 26px; font-weight: 800; color: var(--primary-text); }
.dropdown { position: relative; }
.dd-list { position: absolute; top: 100%; right: 0; left: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12); z-index: 20; max-height: 320px; overflow-y: auto; }
.dd-list div { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.dd-list div:hover, .dd-list div.hi { background: var(--primary-soft); }

/* ===== Chart ===== */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding: 10px 4px 0; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .bar { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars .b:hover .bar { opacity: 1; }
.bars .d { font-size: 10px; color: var(--muted); }

/* ===== قارئ الباركود بالكاميرا ===== */
.scan-btn { padding: 6px 10px; min-width: 44px; color: var(--primary-text); }
.scan-wrap { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 30%; bottom: 30%; border: 3px solid var(--primary); border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scan-line { position: absolute; left: 6%; right: 6%; height: 2px; background: #ff3b30; box-shadow: 0 0 8px #ff3b30; top: 50%;
  animation: scanmove 1.6s ease-in-out infinite alternate; }
@keyframes scanmove { from { top: 12%; } to { top: 88%; } }
.scan-msg { text-align: center; margin-top: 10px; font-size: 15px; min-height: 1.6em; }

.alert { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin-bottom: 14px; }

@media (max-width: 1100px) {
  .pos { grid-template-columns: 190px minmax(0, 1fr) 320px; gap: 8px; height: calc(100vh - 32px); }
  .layout:has(.pos) .page { padding: 12px; }
  .prod-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
  .prod { padding: 8px; min-height: 80px; }
  .np-keys button { height: 50px; font-size: 20px; }
  .pos-total .grand { font-size: 22px; }
  .cart-row { padding: 8px 10px; }
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 800px) {
  .pos { grid-template-columns: 150px minmax(0, 1fr) 270px; height: calc(100vh - 80px); gap: 6px; }
  .layout:has(.pos) .page { padding: 8px; }
  .numpad { padding: 6px; gap: 6px; }
  .np-screen { min-height: 70px; padding: 6px 8px; }
  .np-screen .np-val { font-size: 24px; min-height: 30px; }
  .np-keys { gap: 4px; }
  .np-keys button { height: 44px; font-size: 18px; }
  .np-modes button { min-height: 34px; font-size: 12px; }
  .prod-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .prod { padding: 6px; min-height: 70px; font-size: 12px; }
  .pos-search .in { font-size: 13px; min-height: 38px; }
  .pos-search select.in { width: 110px !important; }
  /* الكمية تتكتب من الحاسبة، فنخفي أزرار + و − لتوفير المساحة */
  .qty-ctl button { display: none; }
  .qty-ctl input { width: 46px; }
  .cart-row { padding: 6px 8px; gap: 4px; font-size: 13px; }
  .pos-total { padding: 8px; font-size: 13px; }
  .pos-total .grand { font-size: 20px; }
  .pos-total .btn.lg { padding: 10px; font-size: 14px; }
}
@media (max-width: 480px) {
  .pos { grid-template-columns: 1fr; height: auto; }
  .numpad { order: 2; }
  .pos-right { order: 3; }
  .prod-grid { max-height: 45vh; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  /* القائمة المخفية على اليمين كانت تخلي الصفحة تتمرر بالعرض في التليفون */
  html, body { overflow-x: hidden; }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 250px; z-index: 40; transform: translateX(100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--side); color: #e9c46a; position: sticky; top: 0; z-index: 30; border-bottom: 3px solid var(--primary); font-weight: 700; }
  .topbar button { background: none; border: 0; color: #e9c46a; font-size: 22px; cursor: pointer; }
  .page { padding: 16px; }
  .g2, .g3, .g4, .form-grid { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .topbar, .actions, .filters, .tabs, .no-print { display: none !important; }
  .layout { display: block; }
  .card { box-shadow: none; border: 0; }
  body { background: #fff; }
}

/* خلايا الجدول اللي فيها أرقام تبقى خلايا جدول عادية */
td.num, th.num { display: table-cell; }
