/* =====================================================================
   الشكل العام — بسيط وواضح، أزرار كبيرة، موبايل أولاً، وشريط جانبي على الكمبيوتر
   ===================================================================== */
:root {
  --main: #0f766e;
  --bg: #f4f6f8; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e5e9ef;
  --ok: #15803d; --okbg: #dcfce7; --warn: #b45309; --warnbg: #fef3c7; --bad: #b91c1c; --badbg: #fee2e2;
  --info: #0369a1; --infobg: #e0f2fe;
  --r: 14px; --fs: 15px; --nav-h: 64px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { font-family: "Cairo", system-ui, "Segoe UI", Tahoma, sans-serif; background: var(--bg); color: var(--ink); font-size: var(--fs); line-height: 1.5; }
body.big { --fs: 18px; }
h2 { font-size: 1.35em; margin: 0; } h3 { font-size: 1.08em; margin: 0 0 8px; } h4 { margin: 16px 0 6px; }
small { display: block; color: var(--muted); font-size: .8em; }
.muted { color: var(--muted); } .center { text-align: center; }
.badt { color: var(--bad); }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-height: 44px; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--main) 40%, transparent); border-color: var(--main); }
input[type=color] { padding: 3px; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--main); flex: none; }

/* ---------- الهيكل ---------- */
#app { min-height: 100vh; }
header.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--main); color: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.05em; flex: 1; min-width: 0; }
.brand b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand.big { justify-content: center; font-size: 1.5em; color: var(--main); margin-bottom: 6px; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: rgba(255, 255, 255, .18); font-size: 18px; }
.brand.big .logo { background: color-mix(in srgb, var(--main) 14%, #fff); width: 44px; height: 44px; font-size: 24px; }
.secchip { background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .25); color: #fff; border-radius: 99px; padding: 5px 12px; cursor: pointer; white-space: nowrap; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
header .pill { cursor: pointer; }
main#view { padding: 14px 14px calc(var(--nav-h) + 90px + env(safe-area-inset-bottom)); max-width: 980px; margin: 0 auto; }

nav.side {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(15, 23, 42, .06);
}
nav.side button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); }
nav.side button span { font-size: 21px; line-height: 1.1; filter: grayscale(1); opacity: .75; }
nav.side button small { font-size: 11px; color: inherit; }
nav.side button.on { color: var(--main); font-weight: 700; }
nav.side button.on span { filter: none; opacity: 1; }

@media (min-width: 900px) {
  nav.side { top: 0; bottom: 0; inset-inline-end: auto; inset-inline-start: 0; width: 96px; height: auto; flex-direction: column; justify-content: flex-start;
             padding-top: 80px; border-top: 0; border-inline-end: 1px solid var(--line); }
  nav.side button { flex: 0; padding: 14px 0; }
  header.top { padding-inline-start: 110px; }
  main#view { padding: 22px 22px 120px; margin-inline-start: 96px; margin-inline-end: auto; max-width: 1100px; }
}

/* ---------- عناصر عامة ---------- */
.card { background: var(--card); border-radius: var(--r); padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); overflow-x: auto; }
.card.warn { background: var(--warnbg); } .card.bad { background: var(--badbg); color: var(--bad); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row > input, .row > select { flex: 1; min-width: 120px; }
.row.between { justify-content: space-between; } .row.end { justify-content: flex-end; } .row.center { justify-content: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 10px; align-items: end; }
.form label, .card > label { display: flex; flex-direction: column; gap: 4px; font-size: .86em; color: var(--muted); margin: 6px 0; }
label.chk { flex-direction: row !important; align-items: center; gap: 10px; color: var(--ink) !important; font-size: .95em !important; }
.btn { border: 0; border-radius: 10px; padding: 10px 14px; min-height: 44px; background: #eef1f5; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--c, var(--main)); color: #fff; }
.btn.bad { background: var(--badbg); color: var(--bad); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: .88em; }
.btn.sq { width: 46px; font-size: 1.3em; padding: 0; }
.btn.big { padding: 14px 18px; font-size: 1.08em; }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; }
.pill { display: inline-block; font-size: 12px; padding: 3px 10px; border-radius: 99px; background: #eef1f5; white-space: nowrap; font-weight: 600; }
.pill.ok { background: var(--okbg); color: var(--ok); } .pill.warn { background: var(--warnbg); color: var(--warn); }
.pill.bad { background: var(--badbg); color: var(--bad); } .pill.info { background: var(--infobg); color: var(--info); }
.msg { min-height: 1.4em; margin: 8px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; }
.sec-title { margin: 18px 4px 10px; color: var(--muted); font-size: .95em; }
.pagehead { margin: 2px 4px 12px; }

/* ---------- الرئيسية ---------- */
.hello { padding: 4px 4px 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile {
  border: 0; border-radius: var(--r); background: #fff; box-shadow: var(--shadow); cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 14px; min-height: 96px; text-align: start;
  border-top: 4px solid var(--c);
}
.tile .ic { font-size: 28px; line-height: 1; }
.tile:active { transform: scale(.97); }
/* البائع: بيع ومرتجع كبار */
.tiles.main { grid-template-columns: 1fr 1fr; }
.tile.big { min-height: 150px; align-items: center; justify-content: center; text-align: center; font-size: 20px; }
.tile.big .ic { font-size: 54px; }
.tiles.small .tile { min-height: 70px; padding: 10px; }
.tiles.small .tile .ic { font-size: 22px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: #fff; border-radius: var(--r); padding: 12px; box-shadow: var(--shadow); border-inline-start: 4px solid var(--c); }
.stat b { font-size: 1.6em; display: block; line-height: 1.2; }
.alert { display: block; width: 100%; text-align: start; border: 0; border-radius: 12px; padding: 12px 14px; margin: 10px 0 0; font-weight: 600; cursor: pointer; }
.alert.warn { background: var(--warnbg); color: var(--warn); } .alert.info { background: var(--infobg); color: var(--info); }
.alert.bad { background: var(--badbg); color: var(--bad); }

/* ---------- شاشة العملية ---------- */
.ophead { display: flex; align-items: center; gap: 8px; background: var(--c); color: #fff; border-radius: var(--r); padding: 10px 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.ophead small { color: rgba(255, 255, 255, .85); }
.ophead .back { color: #fff; font-size: 1.3em; min-width: 44px; }
.ophead .ic { font-size: 1.3em; }
.scanbox #codeInp { font-size: 1.15em; font-weight: 600; letter-spacing: .5px; }
.qtyrow #qtyInp { width: 100px; flex: 0 0 100px; min-width: 0; text-align: center; font-weight: 700; font-size: 1.1em; }
#reader { width: 100%; border-radius: 12px; overflow: hidden; }
.lastscan { min-height: 1.6em; padding: 8px 10px; border-radius: 10px; background: #f6f8fa; font-weight: 600; margin-top: 6px; }
.lastscan.ok { background: var(--okbg); color: var(--ok); } .lastscan.warn { background: var(--warnbg); color: var(--warn); }
.lastscan.bad { background: var(--badbg); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.chip.on { background: var(--main); color: #fff; border-color: var(--main); }
.note { padding: 8px; }
.submitbar {
  position: fixed; inset-inline: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px); border-top: 1px solid var(--line);
}
.submitbar .btn { min-width: 150px; }
@media (min-width: 900px) { .submitbar { inset-inline-start: 96px; bottom: 0; } }

/* ---------- الجداول ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: .93em; }
.tbl th { text-align: start; color: var(--muted); font-weight: 600; font-size: .85em; padding: 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.click tbody tr { cursor: pointer; } .tbl.click tbody tr:hover { background: #f8fafc; }
.tbl tr.unknown td:first-child b { color: var(--bad); }
.tbl tr.low { background: #fff7f7; } .tbl tr.off { opacity: .5; }
.tbl .qcell { white-space: nowrap; }
.tbl .qin { width: 86px; min-height: 38px; padding: 6px; text-align: center; font-weight: 700; }
.tbl .uin { width: auto; min-height: 38px; padding: 4px 6px; margin-top: 4px; display: block; }
.tbl input, .tbl select { min-height: 38px; }

/* ---------- القوايم والتبويبات ---------- */
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.item { text-align: start; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
button.item:hover { border-color: var(--main); }
.item.on { border-color: var(--main); background: color-mix(in srgb, var(--main) 7%, #fff); }
.item.danger b { color: var(--bad); }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 12px; padding-bottom: 2px; }
.tabs button { border: 0; background: #e9edf2; border-radius: 99px; padding: 8px 14px; cursor: pointer; white-space: nowrap; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--main); color: #fff; }
.opcard { border-inline-start: 4px solid var(--c); }
.opcard .btn.primary { background: var(--ok); }
.sf { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 10px 0; background: #fafbfc; }
.card.me b { display: block; font-size: 1.1em; }

/* ---------- النوافذ ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { position: relative; background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
.sheet.wide { max-width: 860px; }
.sheet .x { position: absolute; top: 10px; inset-inline-end: 10px; border: 0; background: #eef1f5; border-radius: 99px; width: 34px; height: 34px; cursor: pointer; }
.sheet h3 { padding-inline-end: 40px; }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.huge { font-size: 2em !important; text-align: center; font-weight: 700; margin: 8px 0; }
.done { text-align: center; padding: 8px 0; }
.done .ic { font-size: 54px; }
.done h2 { font-size: 1.6em; margin: 6px 0; letter-spacing: .5px; }

.toast { position: fixed; z-index: 60; inset-inline: 16px; bottom: calc(var(--nav-h) + 80px); margin: auto; max-width: 460px; padding: 12px 16px; border-radius: 12px;
         background: #0f172a; color: #fff; font-weight: 600; opacity: 0; transform: translateY(10px); transition: .25s; text-align: center; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); } .toast.info { background: var(--info); }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px;
         background: radial-gradient(1000px 500px at 50% -10%, color-mix(in srgb, var(--main) 25%, #fff), var(--bg)); }
.login .card { width: min(400px, 100%); padding: 26px 20px; text-align: center; }
.login input { margin: 6px 0; }

/* ---------- شريط النسخة التجريبية ---------- */
.demo-bar { background: #fef3c7; color: #92400e; padding: 8px 12px; font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.demo-bar select { width: auto; min-height: 32px; padding: 2px 8px; }
