:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1d2530; --muted: #6b7684; --line: #e3e7ec;
  --pri: #1f4e79; --pri2: #2f6fab; --ok: #1e8e3e; --warn: #c77700; --bad: #c62828; --ret: #6a3fb5;
  --r: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; }
a { color: var(--pri2); }
button, input, select { font: inherit; }
.hidden { display: none !important; }

header.top { background: var(--pri); color: #fff; display: flex; align-items: center; gap: 12px; padding: 10px 14px; position: sticky; top: 0; z-index: 20; }
header.top .brand { font-weight: 700; font-size: 17px; }
header.top .who { margin-inline-start: auto; font-size: 13px; opacity: .9; }
header.top button { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); padding: 6px 8px; position: sticky; top: 48px; z-index: 19; }
nav.tabs a { white-space: nowrap; text-decoration: none; color: var(--ink); padding: 8px 12px; border-radius: 8px; font-size: 14px; }
nav.tabs a.on { background: var(--pri); color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select { border: 1px solid #cfd6de; border-radius: 9px; padding: 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus { outline: 2px solid var(--pri2); border-color: transparent; }
.btn { border: 0; border-radius: 9px; padding: 10px 14px; cursor: pointer; background: var(--pri); color: #fff; font-weight: 600; }
.btn.sec { background: #e8edf3; color: var(--ink); }
.btn.ok { background: var(--ok); } .btn.bad { background: var(--bad); } .btn.warn { background: var(--warn); }
.btn.sm { padding: 6px 10px; font-size: 13px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kpi.ok .v { color: var(--ok); } .kpi.bad .v { color: var(--bad); } .kpi.ret .v { color: var(--ret); } .kpi.pri .v { color: var(--pri); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
.tw { overflow-x: auto; }
td.n, th.n { text-align: center; white-space: nowrap; }
tr.low td { background: #fff4f4; }
.bar { height: 8px; background: #e9edf1; border-radius: 4px; overflow: hidden; min-width: 70px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.mid > i { background: var(--warn); } .bar.lo > i { background: var(--bad); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.t-in { background: #e3f1ff; color: #0d5aa7; } .t-out { background: #e5f6ea; color: var(--ok); }
.t-return { background: #efe7fb; color: var(--ret); } .t-damaged { background: #fdeaea; color: var(--bad); }
.t-new { background: #eee; color: #555; } .t-in_stock { background: #e3f1ff; color: #0d5aa7; }

/* scan page */
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.modes button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 4px; cursor: pointer; font-weight: 700; font-size: 14px; }
.modes button .ic { display: block; font-size: 22px; }
.modes button.on.in { border-color: #0d5aa7; background: #e3f1ff; }
.modes button.on.out { border-color: var(--ok); background: #e5f6ea; }
.modes button.on.return { border-color: var(--ret); background: #efe7fb; }
.modes button.on.damaged { border-color: var(--bad); background: #fdeaea; }
#reader { width: 100%; max-width: 520px; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #000; }
#reader video { border-radius: 12px; }
.flash { padding: 14px; border-radius: 12px; font-weight: 700; font-size: 16px; margin: 10px 0; text-align: center; }
.flash.ok { background: #e5f6ea; color: var(--ok); } .flash.err { background: #fdeaea; color: var(--bad); }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 8px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed li .c { font-family: monospace; direction: ltr; }
.feed li .p { flex: 1; }
.feed li.err { color: var(--bad); }
.feed li.undone { text-decoration: line-through; opacity: .5; }
.counters { display: flex; gap: 8px; flex-wrap: wrap; }
.counters span { background: #f0f3f7; border-radius: 8px; padding: 4px 10px; font-size: 13px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 14px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 460px; max-height: 88vh; overflow: auto; padding: 16px; }
.modal h3 { margin: 0 0 10px; }
.plist { list-style: none; padding: 0; margin: 8px 0; }
.plist li { padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; cursor: pointer; display: flex; justify-content: space-between; }
.plist li:hover { background: #f0f5fb; }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.chart .d { flex: 1 0 18px; max-width: 46px; display: flex; flex-direction: column-reverse; align-items: stretch; height: 100%; position: relative; }
.chart .d i { display: block; }
.chart .d small { position: absolute; bottom: -18px; font-size: 10px; color: var(--muted); width: 100%; text-align: center; }
.legend { display: flex; gap: 14px; font-size: 12px; margin-top: 22px; }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 4px; }

.center-box { max-width: 380px; margin: 8vh auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 200; font-size: 14px; }

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
}
.sheet { width: 210mm; height: 297mm; position: relative; overflow: hidden; page-break-after: always; break-after: page; background: #fff; }
.sheet:last-child { page-break-after: auto; break-after: auto; }
.lbl { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; padding: 1.5mm 2mm; }
.lbl .nm { font-size: 7pt; font-weight: 700; line-height: 1; margin-bottom: .6mm; white-space: nowrap; color: #000; }
.lbl svg { display: block; width: 100%; }
.preview-wrap { overflow: auto; background: #888; padding: 10px; border-radius: 10px; max-height: 70vh; }
.preview-wrap .sheet { transform-origin: top right; margin-bottom: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.preview-wrap .lbl { outline: 1px dashed #ccc; }
