:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17202a;
  --muted: #5d6b78;
  --line: #dde3e9;
  --brand: #0f6e5c;
  --brand-ink: #ffffff;
  --brand-soft: #e1f2ee;
  --warn: #b25b00;
  --warn-soft: #fff1e0;
  --bad: #b3261e;
  --bad-soft: #fde8e7;
  --good: #1e7b34;
  --good-soft: #e5f4e8;
  --m0: #b3261e; --m1: #d9590d; --m2: #c99500; --m3: #5a8f29; --m4: #2f7a8a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418; --surface: #182026; --surface-2: #212b33; --text: #e7edf2; --muted: #9aa8b4; --line: #2c3842;
    --brand: #3fb59a; --brand-ink: #062019; --brand-soft: #173a33;
    --warn: #f0a24a; --warn-soft: #3a2a14; --bad: #f2867f; --bad-soft: #3d1d1b; --good: #6fcf86; --good-soft: #17331e;
    --m0: #f2867f; --m1: #f5a066; --m2: #e8c44d; --m3: #9ccc6b; --m4: #6cc1d1;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1418; --surface: #182026; --surface-2: #212b33; --text: #e7edf2; --muted: #9aa8b4; --line: #2c3842;
  --brand: #3fb59a; --brand-ink: #062019; --brand-soft: #173a33;
  --warn: #f0a24a; --warn-soft: #3a2a14; --bad: #f2867f; --bad-soft: #3d1d1b; --good: #6fcf86; --good-soft: #17331e;
  --m0: #f2867f; --m1: #f5a066; --m2: #e8c44d; --m3: #9ccc6b; --m4: #6cc1d1;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px;
}
.bar h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .who { font-size: 13px; opacity: .9; text-align: end; line-height: 1.3; }
.bar button { background: transparent; border: 1px solid currentColor; border-radius: 10px; padding: 4px 10px; color: inherit; font-size: 13px; }
.bar .back { border: 0; font-size: 22px; padding: 0 4px; line-height: 1; }

main { max-width: 760px; margin: 0 auto; padding: 12px 16px calc(env(safe-area-inset-bottom) + 96px); }
.wide main, main.wide { max-width: 1280px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stack > * + * { margin-top: 10px; }

/* forms */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 12px; font-size: 16px;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 11px 16px;
  background: var(--brand); color: var(--brand-ink); font-weight: 600; font-size: 15px;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.msg { border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.msg.bad { background: var(--bad-soft); color: var(--bad); }
.msg.good { background: var(--good-soft); color: var(--good); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }
.msg.info { background: var(--surface-2); color: var(--muted); }

/* login */
.login { max-width: 380px; margin: 8vh auto 0; }
.login h2 { margin: 0 0 4px; font-size: 22px; }
.pin { letter-spacing: .5em; text-align: center; font-size: 22px; }

/* chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; vertical-align: middle; }
.tag .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-inline-end: 4px; }
.store .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 4px; }
.store .change { margin-top: 8px; font-size: 13px; line-height: 1.9; }
.chip.in-count { border-color: var(--warn); color: var(--warn); }
.chip.in-count[aria-pressed="true"] { background: var(--warn); color: #fff; }
.item .wh { color: var(--warn); }
.store .lines { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.store .line { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 2px 0; }
.store .line .num { white-space: nowrap; }
.store .todo { margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--warn); }
.video.small-video { aspect-ratio: 16 / 9; }
table.chk th, table.chk td { padding: 6px 8px; }
table.chk tr.has td { background: var(--brand-soft); }
table.chk .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 5px; }
.chip-label { flex: none; align-self: center; font-size: 12px; color: var(--muted); }
.item .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 5px; }
.filters { position: sticky; top: calc(env(safe-area-inset-top) + 52px); z-index: 10; background: var(--bg); padding: 8px 0 2px; margin-top: -4px; }
.filters .label { font-size: 12px; color: var(--muted); margin: 2px 0; }

/* summary tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.tile b { display: block; font-size: 19px; }
.tile span { font-size: 12px; color: var(--muted); }

/* store list */
.store {
  display: block; width: 100%; text-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px;
}
.store .top { display: flex; gap: 10px; align-items: flex-start; }
.store .name { font-weight: 700; flex: 1; min-width: 0; }
.store .meta { font-size: 12px; color: var(--muted); }
.store .val { text-align: end; }
.store .val b { display: block; color: var(--brand); }
.bars { display: flex; height: 6px; border-radius: 4px; overflow: hidden; margin-top: 8px; background: var(--surface-2); }
.bars i { display: block; height: 100%; }
.tag { display: inline-block; font-size: 11px; border-radius: 6px; padding: 1px 6px; background: var(--surface-2); color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

/* items */
.month-h { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; font-weight: 700; }
.month-h .sw { width: 10px; height: 10px; border-radius: 3px; }
.month-h .sum { margin-inline-start: auto; font-weight: 400; font-size: 13px; color: var(--muted); }
.item { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.item + .item { margin-top: 6px; }
.item .what { flex: 1; min-width: 0; }
.item .ar { font-weight: 600; }
.item .en { font-size: 12px; color: var(--muted); direction: ltr; text-align: start; unicode-bidi: plaintext; }
.item .q { text-align: end; white-space: nowrap; }
.item .q .qty { font-size: 14px; }
.item .q .qty b { font-size: 18px; }
.item .q .money { font-size: 13px; color: var(--brand); margin-top: 2px; }
.item.added { border-style: dashed; border-color: var(--brand); }
.item .x { border: 0; background: transparent; color: var(--bad); font-size: 13px; padding: 4px; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

/* floating scan button */
.fab {
  position: fixed; inset-inline-end: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); z-index: 30;
  border: 0; border-radius: 999px; padding: 14px 20px; background: var(--brand); color: var(--brand-ink); font-weight: 700;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25); display: flex; align-items: center; gap: 8px; font-size: 16px;
}

/* bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 40; }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 41; background: var(--surface); border-radius: 18px 18px 0 0;
  max-height: 92vh; overflow-y: auto; padding: 14px 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 760px; margin: 0 auto;
}
.sheet h3 { margin: 0 0 10px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet h3 .close { margin-inline-start: auto; border: 0; background: var(--surface-2); border-radius: 50%; width: 32px; height: 32px; font-size: 18px; }
.video { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 4 / 3; }
.video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video .aim { position: absolute; inset: 30% 12%; border: 2px solid rgba(255, 255, 255, .85); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); }
.found { display: flex; gap: 10px; align-items: center; background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; }
.results { max-height: 40vh; overflow-y: auto; }
.result { display: block; width: 100%; text-align: start; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 9px 4px; }
.qty-row { display: flex; gap: 8px; align-items: center; }
.qty-row .input { text-align: center; font-size: 20px; }
.qty-row button { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 22px; flex: none; }

/* admin */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 12px; border-bottom: 3px solid transparent; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--brand); border-color: var(--brand); }
.drops { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 14px; background: var(--surface); min-height: 150px; display: flex; flex-direction: column; gap: 6px;
}
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop.ok { border-style: solid; border-color: var(--good); }
.drop.err { border-style: solid; border-color: var(--bad); }
.drop h4 { margin: 0; font-size: 15px; }
.drop .pick { margin-top: auto; }
.drop details { font-size: 13px; }
.drop details select { width: 100%; margin: 2px 0 6px; padding: 4px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.dropall { border: 2px dashed var(--brand); border-radius: var(--radius); padding: 18px; text-align: center; background: var(--brand-soft); margin-bottom: 10px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { background: var(--surface-2); position: sticky; top: 0; font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar .input { width: auto; padding: 7px 10px; font-size: 14px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }
@media (max-width: 520px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile b { font-size: 16px; }
}
