:root {
  --bg: #f5f3ff;
  --surface: #ffffff;
  --surface-2: #f1edff;
  --text: #1e1537;
  --muted: #6b6489;
  --line: #e6e0fa;
  --primary: #7c3aed;
  --primary-2: #db2777;
  --accent: #06b6d4;
  --ok: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --grad: linear-gradient(135deg, #7c3aed 0%, #c026d3 50%, #db2777 100%);
  --grad-2: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  --shadow: 0 10px 30px -12px rgba(76, 29, 149, .35);
  --radius: 20px;
  --nav-h: 72px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0a1f;
    --surface: #1a1330;
    --surface-2: #241b40;
    --text: #f3efff;
    --muted: #a59cc7;
    --line: #2f2551;
    --shadow: 0 10px 30px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Cairo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.top {
  background: var(--grad);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 22px;
  border-radius: 0 0 28px 28px;
  box-shadow: var(--shadow);
}
.top .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.top h1 { font-size: 20px; margin: 0; font-weight: 800; }
.top .sub { opacity: .85; font-size: 13px; margin-top: 2px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; vertical-align: middle; }
.dot.on { background: #4ade80; box-shadow: 0 0 0 4px rgba(74, 222, 128, .25); }
.dot.off { background: #fca5a5; }
.chip-top { background: rgba(255, 255, 255, .18); padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }

main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

nav.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
nav.tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; font-weight: 700; position: relative;
}
nav.tabs button svg { width: 24px; height: 24px; }
nav.tabs button.on { color: var(--primary); }
nav.tabs button.scan-btn .ic {
  width: 56px; height: 56px; margin-top: -26px; border-radius: 18px;
  background: var(--grad); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow);
}
nav.tabs .badge { position: absolute; top: 8px; inset-inline-start: calc(50% + 6px); }

/* ---------- cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { border-radius: 18px; padding: 12px; color: #fff; }
.stat b { display: block; font-size: 20px; font-weight: 800; direction: ltr; text-align: right; }
.stat span { font-size: 12px; opacity: .9; }
.stat.v { background: var(--grad); }
.stat.g { background: linear-gradient(135deg, #10b981, #059669); }
.stat.r { background: linear-gradient(135deg, #f43f5e, #e11d48); }
.stat.c { background: var(--grad-2); }

.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; font-weight: 800; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: rgba(16, 185, 129, .15); color: var(--ok); }
.pill.warn { background: rgba(245, 158, 11, .18); color: #d97706; }
.pill.bad { background: rgba(239, 68, 68, .15); color: var(--bad); }
.pill.info { background: rgba(124, 58, 237, .14); color: var(--primary); }

/* ---------- forms ---------- */
label.f { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 12px 0 6px; }
.in {
  width: 100%; height: 52px; padding: 0 16px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--surface); outline: none; transition: border-color .15s;
}
.in:focus { border-color: var(--primary); }
.btn {
  height: 52px; padding: 0 20px; border-radius: 16px; font-weight: 800; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.p { background: var(--grad); color: #fff; box-shadow: var(--shadow); }
.btn.s { background: var(--surface-2); color: var(--primary); }
.btn.ok { background: linear-gradient(135deg, #10b981, #059669); color: #fff; }
.btn.bad { background: rgba(239, 68, 68, .12); color: var(--bad); }
.btn.w { width: 100%; }
.btn.sm { height: 38px; font-size: 14px; padding: 0 14px; border-radius: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; height: 38px; border-radius: 11px; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }

.search { position: relative; margin-bottom: 12px; }
.search .in { padding-inline-start: 46px; }
.search svg { position: absolute; inset-inline-start: 14px; top: 14px; width: 24px; height: 24px; color: var(--muted); }

/* ---------- list ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.it {
  display: flex; align-items: center; gap: 12px; background: var(--surface); padding: 12px 14px;
  border-radius: 18px; box-shadow: 0 4px 14px -8px rgba(76, 29, 149, .3); text-align: start; width: 100%;
}
.it .av {
  width: 44px; height: 44px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: var(--surface-2); color: var(--primary); font-weight: 800;
}
.it .tx { flex: 1; min-width: 0; }
.it .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.it .mt { font-size: 12px; color: var(--muted); }
.it .qt { text-align: center; min-width: 64px; }
.it .qt b { display: block; font-size: 18px; font-weight: 800; color: var(--primary); }
.it .qt small { font-size: 11px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.diff-neg { color: var(--bad); font-weight: 800; }
.diff-pos { color: var(--ok); font-weight: 800; }

/* ---------- scanner ---------- */
.scan-wrap {
  position: relative; border-radius: 26px; overflow: hidden; background: #000;
  aspect-ratio: 3 / 4; max-height: 62vh; width: 100%; box-shadow: var(--shadow);
}
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 22% 10%; border-radius: 22px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35); }
.scan-frame::before, .scan-frame::after {
  content: ""; position: absolute; inset: 0; border-radius: 22px; border: 3px solid transparent;
  background: var(--grad) border-box;
  -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.scan-line { position: absolute; inset-inline: 8%; height: 3px; top: 50%; background: #22d3ee; box-shadow: 0 0 14px #22d3ee; border-radius: 3px; animation: sweep 1.8s ease-in-out infinite; }
@keyframes sweep { 0%, 100% { top: 12%; } 50% { top: 86%; } }
.scan-tools { position: absolute; bottom: 14px; inset-inline: 14px; display: flex; justify-content: space-between; }
.round { width: 48px; height: 48px; border-radius: 50%; background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center; backdrop-filter: blur(6px); }
.round.on { background: #facc15; color: #000; }
.scan-msg { position: absolute; top: 14px; inset-inline: 14px; text-align: center; color: #fff; font-size: 13px; font-weight: 700; text-shadow: 0 1px 4px #000; }
.scan-off { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #fff; padding: 20px; }
.flash { animation: flash .35s; }
@keyframes flash { 0% { box-shadow: inset 0 0 0 0 #22c55e; } 30% { box-shadow: inset 0 0 0 10px #22c55e; } 100% { box-shadow: inset 0 0 0 0 transparent; } }

/* ---------- sheet ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(15, 10, 31, .55); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 41; max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 28px 28px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .25s cubic-bezier(.2, .9, .3, 1.2); max-width: 640px; margin: 0 auto;
}
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.hero { background: var(--grad); color: #fff; border-radius: 22px; padding: 16px; margin-bottom: 12px; }
.hero h2 { margin: 0; font-size: 18px; line-height: 1.5; }
.hero .mt { opacity: .85; font-size: 12px; direction: ltr; text-align: right; }
.hero .kv { display: flex; gap: 10px; margin-top: 12px; }
.hero .kv div { flex: 1; background: rgba(255, 255, 255, .16); border-radius: 14px; padding: 8px 10px; }
.hero .kv b { display: block; font-size: 18px; }
.hero .kv span { font-size: 11px; opacity: .9; }

.batches { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 4px; }
.bt {
  flex: none; min-width: 108px; border-radius: 16px; padding: 10px 12px; background: var(--surface);
  border: 2px solid var(--line); text-align: start;
}
.bt.on { border-color: var(--primary); background: var(--surface-2); }
.bt b { display: block; font-size: 15px; }
.bt span { font-size: 12px; color: var(--muted); }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .in { text-align: center; font-size: 22px; font-weight: 800; direction: ltr; }
.stepper button { width: 52px; height: 52px; flex: none; border-radius: 16px; background: var(--surface-2); color: var(--primary); font-size: 26px; font-weight: 800; }

/* ---------- login ---------- */
.login { min-height: 100%; display: flex; flex-direction: column; }
.login .top { padding-bottom: 70px; text-align: center; }
.login .logo { width: 84px; height: 84px; border-radius: 26px; margin: 16px auto 10px; display: block; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.login .card { margin: -48px 16px 0; max-width: 460px; align-self: center; width: calc(100% - 32px); }

#toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 60;
  text-align: center; pointer-events: none;
}
#toast div {
  display: inline-block; background: #1e1537; color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 700;
  box-shadow: var(--shadow); animation: up .25s;
}
#toast div.ok { background: linear-gradient(135deg, #10b981, #059669); }
#toast div.bad { background: linear-gradient(135deg, #f43f5e, #e11d48); }

.chk { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.muted { color: var(--muted); font-size: 13px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mb { margin-bottom: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.spin { width: 22px; height: 22px; border: 3px solid rgba(255, 255, 255, .4); border-top-color: #fff; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
