/* Bexa App. واجهة موبايل أولاً، عربية من اليمين لليسار. */
@font-face { font-family: 'Cairo'; font-weight: 200 1000; font-display: swap; src: url('./cairo-arabic-CJWMIGCx.woff2') format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: 'Cairo'; font-weight: 200 1000; font-display: swap; src: url('./cairo-latin-PfPtmrPZ.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+2215; }

:root {
  --brand: #2f6fde;
  --brand-2: #6366f1;
  --navy: #0c2f57;
  --amber: #fdb022;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --info: #38bdf8;

  --bg: #f3f6fb;
  --bg-2: #e9eef7;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --line: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a6;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --glass: rgba(255, 255, 255, .8);
  --chip: rgba(15, 23, 42, .05);

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme='dark'] {
  --bg: #0b1220;
  --bg-2: #0f192c;
  --card: #121c30;
  --card-2: #172338;
  --line: rgba(148, 163, 184, 0.12);
  --text: #eef2f8;
  --text-2: #b4bfd0;
  --muted: #7b879b;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 10px 30px rgba(0, 0, 0, .35);
  --glass: rgba(11, 18, 32, .78);
  --chip: rgba(148, 163, 184, .1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select { font: inherit; color: var(--text); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* ── الهيكل ─────────────────────────────────────────────────────── */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--glass);
  backdrop-filter: saturate(160%) blur(18px); -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 10px; }
.branch-chip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 12px; border-radius: 14px; text-align: start;
}
.branch-chip:active { background: var(--chip); }
.brand-dot {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 900; color: var(--navy);
  background: linear-gradient(135deg, #ffd166, var(--amber)); box-shadow: 0 4px 14px rgba(253, 176, 34, .35);
}
.branch-chip .t1 { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.branch-chip .t2 { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.live-dot.off { background: var(--muted); box-shadow: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--text-2); }
.icon-btn:active { background: var(--chip); }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.ranges { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.ranges::-webkit-scrollbar { display: none; }
.range {
  flex: 0 0 auto; padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
  color: var(--text-2); background: var(--chip); transition: background .2s, color .2s;
}
.range.on { background: var(--text); color: var(--bg); }

.content { flex: 1; padding: 14px 16px calc(96px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }

.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--glass);
  backdrop-filter: saturate(160%) blur(18px); -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 14px; font-size: 11px; font-weight: 700; color: var(--muted); transition: color .2s; }
.tab svg { transition: transform .25s cubic-bezier(.2, .9, .3, 1.4); }
.tab.on { color: var(--brand); }
.tab.on svg { transform: translateY(-2px) scale(1.08); }
[data-theme='dark'] .tab.on { color: #7aa7ff; }

/* ── البطاقات ───────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 16px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-h h3 { margin: 0; font-size: 15px; font-weight: 800; }
.card-h .sub { font-size: 12px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 800; color: var(--muted); margin: 6px 4px -4px; }

.hero {
  position: relative; overflow: hidden; color: #fff; border: 0;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(255, 255, 255, .18), transparent 55%),
    radial-gradient(90% 90% at 0% 100%, rgba(253, 176, 34, .28), transparent 60%),
    linear-gradient(140deg, #2f6fde 0%, #4f46e5 55%, #0c2f57 100%);
  box-shadow: 0 18px 40px rgba(47, 111, 222, .35);
}
.hero .label { font-size: 13px; opacity: .85; font-weight: 600; }
.hero .big { font-size: 38px; font-weight: 900; letter-spacing: -0.5px; line-height: 1.15; margin: 4px 0 2px; }
.hero .big small { font-size: 15px; font-weight: 700; opacity: .8; margin-inline-start: 6px; }
.hero .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.hero .pill { background: rgba(255, 255, 255, .16); border-radius: 999px; padding: 3px 10px; font-weight: 700; }
.hero-grid { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.hero-grid > div { background: rgba(255, 255, 255, .12); border-radius: 14px; padding: 10px; }
.hero-grid .k { font-size: 11px; opacity: .8; }
.hero-grid .v { font-size: 16px; font-weight: 800; }
.hero-spark { position: absolute; inset-inline: 0; bottom: 0; height: 64px; width: 100%; opacity: .22; pointer-events: none; z-index: 0; }
.hero > *:not(.hero-spark) { position: relative; z-index: 1; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.kpi .k i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }
.kpi .v { font-size: 21px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12px; color: var(--text-2); }

.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 800; border-radius: 999px; padding: 1px 8px; }
.delta.up { color: #16a34a; background: rgba(34, 197, 94, .12); }
.delta.down { color: #dc2626; background: rgba(239, 68, 68, .12); }
.delta.flat { color: var(--muted); background: var(--chip); }
.hero .delta.up { color: #bbf7d0; background: rgba(34, 197, 94, .22); }
.hero .delta.down { color: #fecaca; background: rgba(239, 68, 68, .25); }

/* ── القوائم ────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); text-align: start; width: 100%; }
.li:last-child { border-bottom: 0; }
button.li:active { background: var(--chip); border-radius: 12px; }
.li .grow { flex: 1; min-width: 0; }
.li .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .d { font-size: 12px; color: var(--muted); }
.li .end { text-align: end; flex: 0 0 auto; }
.li .end .t { font-weight: 800; }
.avatar { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; font-weight: 900; font-size: 14px; flex: 0 0 auto; background: var(--chip); color: var(--text-2); }

.rank-bar { height: 6px; border-radius: 999px; background: var(--chip); overflow: hidden; margin-top: 6px; }
.rank-bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand-2), var(--brand)); }

.badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 800; border-radius: 8px; padding: 1px 8px; background: var(--chip); color: var(--text-2); }
.badge.good { background: rgba(34, 197, 94, .14); color: #16a34a; }
.badge.bad { background: rgba(239, 68, 68, .14); color: #dc2626; }
.badge.warn { background: rgba(245, 158, 11, .16); color: #b45309; }
.badge.info { background: rgba(56, 189, 248, .16); color: #0284c7; }
[data-theme='dark'] .badge.good { color: #4ade80; }
[data-theme='dark'] .badge.bad { color: #f87171; }
[data-theme='dark'] .badge.warn { color: #fbbf24; }
[data-theme='dark'] .badge.info { color: #7dd3fc; }

.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 7px 4px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.search { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 0 12px; }
.search input { flex: 1; border: 0; background: none; outline: 0; padding: 11px 0; }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 14px; font-size: 13px; font-weight: 600; }
.banner.warn { background: rgba(245, 158, 11, .14); color: #b45309; }
.banner.bad { background: rgba(239, 68, 68, .12); color: #dc2626; }
.banner.info { background: rgba(47, 111, 222, .12); color: var(--brand); }
[data-theme='dark'] .banner.warn { color: #fbbf24; }
[data-theme='dark'] .banner.bad { color: #f87171; }
[data-theme='dark'] .banner.info { color: #93b4ff; }
.banner button { margin-inline-start: auto; font-weight: 800; text-decoration: underline; }

.empty { text-align: center; padding: 28px 10px; color: var(--muted); font-size: 14px; }
.empty .ico { font-size: 34px; margin-bottom: 6px; opacity: .8; }

.sk { background: linear-gradient(90deg, var(--chip) 0%, rgba(148, 163, 184, .18) 50%, var(--chip) 100%); background-size: 200% 100%; animation: sk 1.2s ease-in-out infinite; border-radius: 10px; }
@keyframes sk { 0% { background-position: 100% 0 } 100% { background-position: -100% 0 } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 18px; border-radius: 14px; font-weight: 800; font-size: 15px; transition: transform .1s, opacity .2s; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 8px 20px rgba(79, 70, 229, .3); }
.btn.ghost { background: var(--chip); color: var(--text); }
.btn.block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-2); }
.field input, .field textarea, .field select { width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card-2); outline: 0; }
.field input:disabled, .field select:disabled { opacity: .65; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(47, 111, 222, .15); }

/* ── الورقة السفلية ──────────────────────────────────────────────── */
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(2, 6, 23, .5); backdrop-filter: blur(2px); animation: fade .2s ease; }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 51; max-height: 88dvh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 16px calc(20px + var(--safe-bottom));
  animation: up .28s cubic-bezier(.2, .9, .3, 1); box-shadow: 0 -10px 40px rgba(0, 0, 0, .3);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; font-weight: 900; }
@keyframes up { from { transform: translateY(100%) } to { transform: none } }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

/* ── شاشات البداية (التفعيل والدخول) ────────────────────────────────── */
.gate {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 18px;
  padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px);
  background:
    radial-gradient(90% 60% at 100% 0%, rgba(99, 102, 241, .25), transparent 60%),
    radial-gradient(80% 50% at 0% 100%, rgba(253, 176, 34, .16), transparent 60%),
    var(--bg);
}
.gate-logo { display: flex; align-items: center; gap: 12px; }
.gate-logo .brand-dot { width: 52px; height: 52px; border-radius: 16px; font-size: 24px; }
/* Nexa Solutions logo (components/NexaMark.tsx) on the activation / install screens */
.gate-logo .gate-mark { width: 52px; height: 52px; flex: 0 0 auto; display: block; filter: drop-shadow(0 4px 12px rgba(5, 12, 30, .3)); }
.gate h1 { margin: 0; font-size: 24px; font-weight: 900; }
.gate p { margin: 0; color: var(--text-2); }
.code-box {
  font-family: ui-monospace, 'Cascadia Mono', monospace; font-size: clamp(16px, 5.2vw, 22px); font-weight: 800; letter-spacing: 1px; text-align: center; white-space: nowrap;
  direction: ltr; padding: 16px; border-radius: 16px; background: var(--card); border: 1px dashed var(--brand); user-select: all;
}
.error { color: var(--bad); font-size: 13px; font-weight: 700; }

.fade-in { animation: fade .3s ease; }

@media (min-width: 700px) {
  .content { max-width: 720px; margin: 0 auto; width: 100%; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
}

/* ── المسح وأدوات المخزون ─────────────────────────────────────────── */
.scan-view { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 30% 10%; border: 2px solid rgba(255, 255, 255, .85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); }
.flash-banner { position: sticky; top: 8px; z-index: 20; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); }

.tool-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tool-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px 12px; border-radius: var(--r-md); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center; transition: transform .1s; }
.tool-tile:active { transform: scale(.97); }
.tool-tile .ic { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: #fff; }
.tool-tile .t { font-size: 13px; font-weight: 800; line-height: 1.3; }
.tool-tile .dot { position: absolute; top: 8px; inset-inline-end: 8px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 11px; font-weight: 900; display: grid; place-items: center; }

.tool-head { display: flex; align-items: center; gap: 10px; }
.tool-head .t { font-size: 18px; font-weight: 900; }
.tool-head .d { font-size: 12px; color: var(--muted); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; min-width: 0; }
.stat .k { font-size: 11px; color: var(--muted); font-weight: 700; }
.stat .v { font-size: 16px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.big-input { display: flex; align-items: center; gap: 8px; border: 2px solid var(--brand); border-radius: 16px; padding: 4px 14px; background: var(--card-2); box-shadow: 0 0 0 4px rgba(47, 111, 222, .12); }
.big-input input { flex: 1; min-width: 0; border: 0; background: none; outline: 0; font-size: 30px; font-weight: 900; padding: 6px 0; text-align: center; font-variant-numeric: tabular-nums; direction: ltr; }
.big-input .cur { font-size: 13px; font-weight: 800; color: var(--muted); }
.big-input.bad { border-color: var(--bad); box-shadow: 0 0 0 4px rgba(239, 68, 68, .12); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--chip); font-size: 13px; font-weight: 800; color: var(--text-2); }
.chip:active { transform: scale(.96); }
.chip.on { background: rgba(47, 111, 222, .14); color: var(--brand); }

.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--chip); border-radius: 12px; padding: 3px; }
.stepper button { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--card); box-shadow: var(--shadow); }
.stepper button:disabled { opacity: .4; }
.stepper .n { min-width: 34px; text-align: center; font-weight: 900; font-variant-numeric: tabular-nums; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.switch-row input[type='checkbox'] { width: 20px; height: 20px; accent-color: var(--brand); }

.done-card { text-align: center; padding: 22px 16px; }
.done-card .ok { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 22px; display: grid; place-items: center; background: rgba(34, 197, 94, .14); color: var(--good); }
.done-card h3 { margin: 0 0 4px; font-size: 18px; font-weight: 900; }
.done-card .change { display: inline-flex; align-items: center; gap: 10px; margin: 10px 0 4px; font-size: 22px; font-weight: 900; }
.done-card .change s { color: var(--muted); font-weight: 700; font-size: 17px; }

.li.hot { background: rgba(47, 111, 222, .08); border-radius: 12px; padding-inline: 8px; animation: hot 1.2s ease; }
@keyframes hot { 0% { background: rgba(47, 111, 222, .28) } 100% { background: rgba(47, 111, 222, .08) } }

.sticky-foot { position: sticky; bottom: calc(76px + var(--safe-bottom)); z-index: 10; }
.total-line { display: flex; justify-content: space-between; align-items: center; font-weight: 900; font-size: 17px; }

.price-hero { text-align: center; padding: 14px 10px; border-radius: var(--r-md); background: linear-gradient(135deg, rgba(139, 92, 246, .12), rgba(236, 72, 153, .1)); border: 1px solid var(--line); }
.price-hero .k { font-size: 12px; font-weight: 800; color: var(--muted); }
.price-hero .v { font-size: 38px; font-weight: 900; line-height: 1.2; }
.price-hero .v .cur { font-size: 15px; color: var(--muted); font-weight: 800; }
.price-hero .s { font-size: 13px; color: var(--text-2); }

/* ── كتالوج البيع: كروت أو قائمة ── */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.pcard { position: relative; display: flex; flex-direction: column; text-align: start; border: 1px solid var(--line); border-radius: 14px; background: var(--card-2); overflow: hidden; transition: transform .1s; }
.pcard:active { transform: scale(.97); }
.pcard.out { opacity: .55; }
.pcard .ph { aspect-ratio: 1 / 1; display: grid; place-items: center; font-size: 30px; font-weight: 900; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.pcard .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard .pb { padding: 7px 8px 8px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pcard .pn { font-size: 12.5px; font-weight: 800; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em; }
.pcard .pp { font-size: 13px; font-weight: 900; color: var(--brand); }
.pcard .pq { font-size: 11px; color: var(--muted); }
.pcard .incart { position: absolute; top: 6px; inset-inline-start: 6px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px; display: grid; place-items: center; background: #16a34a; color: #fff; font-size: 12px; font-weight: 900; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.li .thumb { width: 42px; height: 42px; border-radius: 10px; flex: 0 0 auto; display: grid; place-items: center; overflow: hidden; font-weight: 900; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.li .thumb img { width: 100%; height: 100%; object-fit: cover; }
.view-btn.on { color: var(--brand); background: var(--chip); }
.cartbar { position: sticky; bottom: calc(84px + var(--safe-bottom)); z-index: 20; box-shadow: 0 8px 22px rgba(0, 0, 0, .25); }
