/* تخطيط: تطبيق جوال أولاً — شريط علوي، محتوى، وشريط تنقل سفلي يصير جانبي على الشاشات العريضة */
:root {
  /* ألوان سوق الخضرة: أخضر ورق للكاش، أحمر بندورة للدين، برتقالي قرع للي بيستنى، أزرق للتحويل */
  --bg: #edf1ea;
  --surface: #ffffff;
  --surface-2: #e3eae0;
  --ink: #17261b;
  --muted: #55665a;
  --line: #d2dccf;
  --accent: #23703a;
  --accent-ink: #ffffff;
  --accent-soft: #dbeedc;
  --debt: #bd3922;
  --debt-soft: #fbe5df;
  --paid: #1e7a44;
  --paid-soft: #dcf1e3;
  --warn: #9c5800;
  --warn-soft: #fcefd8;
  --transfer: #235d92;
  --transfer-soft: #dfebf6;
  --c-veg: #2e8b45;
  --c-fruit: #df7f27;
  --c-leafy: #6a9e1f;
  --c-other: #8a7a64;
  --shadow: 0 1px 2px rgba(23, 38, 27, .07), 0 4px 14px rgba(23, 38, 27, .06);
  --font-display: 'Readex Pro', 'IBM Plex Sans Arabic', Tahoma, 'Segoe UI', sans-serif;
  --font-body: 'IBM Plex Sans Arabic', Tahoma, 'Segoe UI', sans-serif;
  --r: 12px;
  --nav-h: 64px;
  --tray-h: 132px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1611; --surface: #172019; --surface-2: #1e2a21; --ink: #e4ede5; --muted: #95a698; --line: #2a382d;
    --accent: #5cc27a; --accent-ink: #06200e; --accent-soft: #183a23; --debt: #ff8b78; --debt-soft: #3a1d18;
    --paid: #6fd39c; --paid-soft: #16321f; --warn: #ffb65c; --warn-soft: #3a2a12; --transfer: #7db4ea; --transfer-soft: #172c40;
    --c-veg: #4cb466; --c-fruit: #f0a050; --c-leafy: #95c548; --c-other: #b3a48c;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1611; --surface: #172019; --surface-2: #1e2a21; --ink: #e4ede5; --muted: #95a698; --line: #2a382d;
  --accent: #5cc27a; --accent-ink: #06200e; --accent-soft: #183a23; --debt: #ff8b78; --debt-soft: #3a1d18;
  --paid: #6fd39c; --paid-soft: #16321f; --warn: #ffb65c; --warn-soft: #3a2a12; --transfer: #7db4ea; --transfer-soft: #172c40;
  --c-veg: #4cb466; --c-fruit: #f0a050; --c-leafy: #95c548; --c-other: #b3a48c;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.55;
  direction: rtl; -webkit-tap-highlight-color: transparent;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; text-wrap: balance; line-height: 1.3; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.12rem; } h3 { font-size: 1rem; }
.num, .money { font-family: var(--font-display); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- الهيكل ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; min-height: 56px;
  padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar .title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.topbar .title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-btn { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 18px; flex: none; }
.mode-chip { font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.mode-chip.live { background: var(--paid-soft); color: var(--paid); }
main {
  flex: 1; width: 100%; max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px;
  padding-block: 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.nav a {
  height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .74rem; position: relative;
}
.nav a svg { width: 23px; height: 23px; }
.nav a.on { color: var(--accent); font-weight: 600; }
.nav a.on::before { content: ""; position: absolute; top: 0; width: 34px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.badge { position: absolute; top: 8px; inset-inline-start: calc(50% + 6px); background: var(--debt); color: #fff; font-size: .66rem; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; font-family: var(--font-display); }

@media (min-width: 900px) {
  .app { padding-right: 96px; }
  .nav { inset: 0 0 0 auto; width: 96px; grid-auto-flow: row; grid-auto-columns: auto; grid-auto-rows: 84px; align-content: start; padding-top: 70px; border-top: 0; border-left: 1px solid var(--line); }
  .nav a { height: 84px; }
  .nav a.on::before { top: 20px; right: 0; width: 3px; height: 44px; border-radius: 3px 0 0 3px; }
  main { padding-bottom: 32px; }
}

/* ---------- عناصر ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row > * { min-width: 0; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.grid { display: grid; gap: 10px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 520px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stack { display: flex; flex-direction: column; gap: 10px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 10px; cursor: pointer;
  font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--debt); border-color: var(--debt); color: #fff; }
.btn.ghost { background: transparent; }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 5px 11px; font-size: .86rem; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; flex: none; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: .84rem; color: var(--muted); font-weight: 500; }
.field-hint { font-size: .78rem; color: var(--muted); }
.input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 8px 12px; }
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.input.big { font-size: 1.35rem; font-family: var(--font-display); text-align: center; min-height: 54px; }
.search { position: relative; }
.search .input { padding-inline-start: 38px; }
.search svg { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--muted); min-height: 38px; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.debt { background: var(--debt-soft); color: var(--debt); }
.pill.paid { background: var(--paid-soft); color: var(--paid); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }

/* أرقام كبيرة */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; min-width: 0; }
.stat .k { font-size: .8rem; color: var(--muted); }
.stat .v { font-family: var(--font-display); font-size: 1.32rem; font-weight: 600; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.stat .s { font-size: .76rem; color: var(--muted); }
.stat.total { grid-column: 1 / -1; align-items: center; text-align: center; }
.stat.total .v { text-align: center; font-size: 1.7rem; }
.stat.debt .v { color: var(--debt); } .stat.paid .v { color: var(--paid); } .stat.warn .v { color: var(--warn); }

/* قوائم بشكل دفتر */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; background: transparent; width: 100%; border-inline: 0; border-top: 0; text-align: right; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); }
.item .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .end { text-align: left; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.avatar { width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; flex: none; }
.amt-debt { color: var(--debt); font-weight: 600; }
.amt-paid { color: var(--paid); font-weight: 600; }
.voided { opacity: .5; text-decoration: line-through; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; display: flex; flex-direction: column; gap: 8px; align-items: center; }

/* رصيد الزبون */
.balance-box { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 18px 12px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.balance-box .lbl { color: var(--muted); font-size: .85rem; }
.balance-box .big { font-family: var(--font-display); font-size: 2.1rem; font-weight: 700; direction: ltr; font-variant-numeric: tabular-nums; }
.balance-box.has-debt .big { color: var(--debt); }
.balance-box.credit .big { color: var(--paid); }

/* جداول */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: .78rem; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 140px; }

/* ربح */
.pl { display: flex; flex-direction: column; }
.pl-row { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-bottom: 1px dashed var(--line); gap: 10px; }
.pl-row:last-child { border-bottom: 0; }
.pl-row.total { border-top: 2px solid var(--ink); border-bottom: 0; margin-top: 4px; padding-top: 10px; font-weight: 700; font-size: 1.08rem; }
.pl-row button { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 4px; }

/* أعمدة بسيطة */
.bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: end; gap: 4px; height: 120px; padding-top: 10px; direction: ltr; }
.bars .b { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .b.today { background: var(--warn); }
.bars-x { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; font-size: .64rem; color: var(--muted); direction: ltr; text-align: center; }

/* نوافذ */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 12, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom, 0px); animation: up .18s ease-out; }
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 16px; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; gap: 10px; }
.sheet-body { padding: 8px 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sheet-actions { display: flex; gap: 8px; padding: 10px 16px 16px; border-top: 1px solid var(--line); }
.sheet-actions .btn { flex: 1; }

.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 12px 10px 14px; border-radius: 12px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.toast-err { background: var(--debt); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }

.notice { border-radius: var(--r); padding: 12px 14px; background: var(--warn-soft); color: var(--warn); font-size: .9rem; }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice.bad { background: var(--debt-soft); color: var(--debt); }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 14px; display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: inherit; position: relative; min-height: 112px; }
.tile svg { width: 26px; height: 26px; color: var(--accent); }
.tile .t { font-weight: 600; font-family: var(--font-display); }
.tile .d { font-size: .8rem; color: var(--muted); }
.tile .badge { top: 12px; inset-inline-start: auto; left: 12px; }

/* شاشة الدخول */
.login { min-height: 100%; display: grid; place-items: center; padding-block: 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.login .card { width: min(100%, 420px); padding: 22px; gap: 14px; }
.brand-mark { width: 52px; height: 52px; border-radius: 15px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; }

.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 26px 14px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; background: var(--surface); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop svg { width: 34px; height: 34px; color: var(--accent); }

.sms-preview { background: var(--surface-2); border-radius: 14px 14px 4px 14px; padding: 10px 12px; font-size: .9rem; white-space: pre-wrap; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.sep { height: 1px; background: var(--line); margin: 2px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
/* البيعات اللي بتستنى الدفعة: أزرار "وصلت" كبيرة للكاشير */
.waiting { border-color: var(--warn); }
.wait-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.wait-row:first-child { border-top: 0; }
.wait-row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wait-row .name { font-weight: 600; }
.wait-row .sub { font-size: .82rem; color: var(--muted); }
.big-ok { min-width: 104px; min-height: 52px; font-size: 1.05rem; font-weight: 700; }
details.manual > summary { cursor: pointer; font-weight: 600; color: var(--muted); }
details.manual[open] > summary { margin-bottom: 10px; color: inherit; }
.row.wrap { flex-wrap: wrap; }
.net-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.net-box { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 12px; background: var(--surface-2, rgba(127,127,127,.08)); }
.net-box .k { font-size: 13px; opacity: .8; }
.net-box .v { font-size: 22px; font-weight: 700; }
.net-box .s { font-size: 12px; opacity: .65; }
@media (max-width: 360px) { .net-pair { grid-template-columns: 1fr; } }
.stock-list .item { cursor: default; align-items: flex-start; }
.stock-list .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.stat.clickable { cursor: pointer; text-align: inherit; font: inherit; color: inherit; border: inherit; }
.link-btn { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-align: start; }
.pay-pick { align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.net-box .v { font-family: var(--font-display); font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.received-check { padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }

/* ======================================================================
   محل الخضرة
   ====================================================================== */
.cat-veg { --cat: var(--c-veg); } .cat-fruit { --cat: var(--c-fruit); } .cat-leafy { --cat: var(--c-leafy); } .cat-other { --cat: var(--c-other); }
.big-btn { min-height: 56px; font-size: 1.05rem; }
.toast-act { border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 8px; padding: 5px 12px; font-weight: 700; cursor: pointer; flex: none; min-height: 36px; }
.sheet.narrow { max-width: 420px; }
.sheet-actions.flush { padding: 4px 0 0; border-top: 0; }
.toasts { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px)); }
body[data-view="sale"] .toasts { bottom: calc(var(--nav-h) + var(--tray-h) + 12px + env(safe-area-inset-bottom, 0px)); }

/* بطاقة السعر: فيها خرم زي بطاقات السوق، وشريط فوق بلون النوع */
.tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tag-wrap { position: relative; display: flex; min-width: 0; }
.tag {
  flex: 1; min-width: 0; position: relative; text-align: right; cursor: pointer; touch-action: manipulation;
  background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--cat); border-radius: 14px;
  padding: 11px 10px 9px; min-height: 108px; display: flex; flex-direction: column; gap: 1px; color: var(--ink);
}
.tag::before { content: ""; position: absolute; top: 8px; left: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--bg); box-shadow: inset 0 0 0 1.5px var(--line); }
.tag:active { transform: scale(.97); }
.tag-name { font-weight: 600; font-size: .98rem; line-height: 1.3; padding-left: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tag-price { margin-top: auto; display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.tag-price b { font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; line-height: 1.1; direction: ltr; }
.tag-price small { font-size: .9rem; color: var(--muted); font-family: var(--font-display); }
.tag-foot { font-size: .76rem; color: var(--muted); padding-left: 36px; }
.tag-foot.low { color: var(--warn); font-weight: 600; }
.tag.in { border-color: var(--accent); border-top-color: var(--cat); box-shadow: 0 0 0 1.5px var(--accent); }
.tag-in { align-self: flex-start; margin-left: 0; background: var(--accent); color: var(--accent-ink); font-family: var(--font-display); font-size: .78rem; font-weight: 600; padding: 1px 8px; border-radius: 99px; direction: rtl; }
.tag-edit { position: absolute; bottom: 7px; left: 7px; width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; font-size: .95rem; }
.tag-edit:hover, .tag-edit:focus-visible { color: var(--accent); border-color: var(--accent); }
.tag-wrap.bump .tag { animation: pop .22s ease-out; }
@keyframes pop { 40% { transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) { .tag-wrap.bump .tag { animation: none; } .tag:active { transform: none; } }

/* الفاتورة: شريط تحت على الجوال، ولوحة جنب على الكمبيوتر */
body[data-view="sale"] main { padding-bottom: calc(var(--nav-h) + var(--tray-h) + 24px + env(safe-area-inset-bottom, 0px)); }
.tray {
  position: fixed; z-index: 24; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(23, 38, 27, .08);
  padding: 6px max(12px, env(safe-area-inset-right, 0px)) 10px max(12px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 6px;
}
.tray-sum { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 4px 2px; cursor: pointer; text-align: right; color: var(--ink); width: 100%; }
.tray-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tray-count { font-weight: 600; font-size: .9rem; }
.tray-last { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-sum .money { font-size: 1.6rem; font-weight: 700; }
.tray-chev { width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; transition: transform .15s; color: var(--muted); }
.tray.open .tray-chev { transform: rotate(180deg); }
.tray.is-empty .tray-chev { visibility: hidden; }
.tray-lines { display: none; max-height: 40vh; overflow-y: auto; border-top: 1px solid var(--line); }
.tray.open .tray-lines { display: block; }
.tray-acts { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.tray-acts .btn { min-height: 56px; font-size: 1.05rem; border-radius: 12px; padding-inline: 8px; }
.btn.cash { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-family: var(--font-display); }
.btn.debt-btn { background: var(--debt-soft); border-color: transparent; color: var(--debt); }
.btn.transfer-btn { background: var(--transfer-soft); border-color: transparent; color: var(--transfer); }
.btn.transfer-btn.block { background: var(--transfer); color: #fff; }
.line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line-name { font-weight: 600; }
.line-total { min-width: 56px; text-align: left; }
.stepper { display: flex; align-items: center; gap: 2px; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.stepper button { width: 34px; height: 34px; border: 0; border-radius: 8px; background: var(--surface); font-size: 1.1rem; cursor: pointer; color: var(--ink); }
.stepper .num { min-width: 22px; text-align: center; font-weight: 600; }

@media (min-width: 900px) {
  body[data-view="sale"] main { max-width: 1240px; padding-bottom: 32px; }
  .sale { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
  .tray { position: sticky; top: 72px; bottom: auto; left: auto; right: auto; border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px 14px; box-shadow: var(--shadow); max-height: calc(100vh - 96px); }
  .tray-lines { display: block; max-height: none; flex: 1; min-height: 60px; overflow-y: auto; }
  .tray-chev { display: none; }
  .tray-acts { grid-template-columns: 1fr 1fr; }
  .tray-acts .cash { grid-column: 1 / -1; min-height: 64px; font-size: 1.15rem; }
  body[data-view="sale"] .toasts { bottom: 24px; }
  .tag-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
  .tag { min-height: 120px; }
}

/* الميزان */
.scale-display { display: flex; align-items: baseline; justify-content: center; gap: 8px; direction: ltr; background: var(--surface-2); border-radius: 14px; padding: 12px; }
.scale-display .num { font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; line-height: 1.1; }
.scale-display small { font-size: 1.1rem; color: var(--muted); }
.scale-result { text-align: center; color: var(--muted); min-height: 1.5em; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; direction: ltr; }
.keypad button { min-height: 58px; font-size: 1.35rem; font-family: var(--font-display); border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; cursor: pointer; touch-action: manipulation; }
.keypad button:active { background: var(--surface-2); }

/* اختيار الزبون والتحويل */
.chosen { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest:empty { display: none; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 99px; padding: 6px 12px; min-height: 38px; cursor: pointer; font-weight: 500; }
.chip small { color: var(--muted); }
.switch-row { align-items: flex-start; padding: 6px 0; }
.switch-row input { margin-top: 3px; }

/* أسعار اليوم */
.price-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.price-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 10px; border-bottom: 1px solid var(--line); border-inline-start: 4px solid var(--cat); cursor: text; }
.price-row:last-child { border-bottom: 0; }
.price-name { font-weight: 600; }
.price-in { width: 92px; flex: none; text-align: center; font-family: var(--font-display); font-size: 1.2rem; min-height: 46px; direction: ltr; }
.price-row.changed { background: var(--warn-soft); }
.price-row.changed .price-in { border-color: var(--warn); }
.prices-foot { position: sticky; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 6px; background: var(--bg); padding-top: 8px; }
@media (min-width: 900px) { .prices-foot { bottom: 12px; } .prices { max-width: 640px; } }

/* كاردس الأصناف */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.icard { background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--cat); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.icard-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.icard-head h3 { font-size: 1.08rem; }
.icard-price { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.icard-price b { font-family: var(--font-display); font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.icard-price small { color: var(--muted); font-size: .8rem; }
.icard-kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: .9rem; }
.icard-kv dt { color: var(--muted); }
.icard-kv dd { margin: 0; }
.icard-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.icard-acts .btn { flex: 1; min-width: 64px; }

/* مشتريات الزبون */
details.buy > summary { list-style: none; }
details.buy > summary::-webkit-details-marker { display: none; }
details.buy { border-bottom: 1px solid var(--line); }
details.buy:last-child { border-bottom: 0; }
details.buy > summary.item { border-bottom: 0; }
details.buy[open] > summary { background: var(--surface-2); }
.buy-items { padding: 8px 14px 12px; display: flex; flex-direction: column; gap: 4px; background: var(--surface-2); }
details.card > summary { cursor: pointer; font-weight: 600; }

/* والنافذة مفتوحة: التنبيهات فوق عشان ما تغطي الخانات */
body:has(.backdrop) .toasts { bottom: auto; top: calc(12px + env(safe-area-inset-top, 0px)); }

/* ======================================================================
   شاشة التحميل: الأيقونة بتنبني قدامه
   ====================================================================== */
#splash {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: #1a5530; color: #eef4ea; transition: opacity .35s ease, visibility .35s;
  padding: 24px;
}
#splash.out { opacity: 0; visibility: hidden; }
.sp-center { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.sp-mark { width: 112px; height: 112px; overflow: visible; margin-bottom: 14px; }
.sp-tile { fill: #23703a; transform-origin: 256px 256px; animation: sp-tile .45s cubic-bezier(.2,.9,.3,1.2) both; }
.sp-page { fill: #edf1ea; transform-origin: 256px 380px; animation: sp-page .4s .2s ease-out both; }
.sp-line { stroke: #23703a; stroke-width: 22; stroke-linecap: round; fill: none; stroke-dasharray: 130; stroke-dashoffset: 130; }
.sp-line.l1 { animation: sp-draw .28s .55s ease-out forwards; }
.sp-line.l2 { animation: sp-draw .28s .78s ease-out forwards; }
.sp-line.l3 { stroke-dasharray: 90; stroke-dashoffset: 90; animation: sp-draw .22s 1s ease-out forwards; }
.sp-stamp { transform-origin: 356px 356px; opacity: 0; animation: sp-stamp .45s 1.18s cubic-bezier(.3,1.6,.5,1) forwards; }
.sp-stamp circle { fill: #e0a43a; }
.sp-check { stroke: #16201e; stroke-width: 16; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 70; stroke-dashoffset: 70; animation: sp-draw .25s 1.45s ease-out forwards; }
.sp-word { font-family: var(--font-display); font-weight: 700; font-size: 2.6rem; line-height: 1.1; letter-spacing: 0; animation: sp-up .45s .35s ease-out both; }
.sp-tag { font-size: 1.02rem; color: #c9dcc6; animation: sp-up .45s .55s ease-out both; }
.sp-track { width: 132px; height: 4px; border-radius: 99px; background: rgba(238,244,234,.16); overflow: hidden; margin-top: 22px; animation: sp-up .4s .8s ease-out both; }
.sp-track span { display: block; width: 40%; height: 100%; border-radius: 99px; background: #e0a43a; animation: sp-sweep 1.15s 1.2s ease-in-out infinite; transform: translateX(160%); }
@keyframes sp-tile { from { transform: scale(.6); opacity: 0; } }
@keyframes sp-page { from { transform: translateY(40px) scale(.9); opacity: 0; } }
@keyframes sp-draw { to { stroke-dashoffset: 0; } }
@keyframes sp-stamp { 0% { opacity: 0; transform: scale(1.9) rotate(-18deg); } 60% { opacity: 1; } 100% { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes sp-up { from { opacity: 0; transform: translateY(10px); } }
/* الشريط بيمر من اليمين لليسار، زي اتجاه الكتابة */
@keyframes sp-sweep { 0% { transform: translateX(160%); } 100% { transform: translateX(-260%); } }
@media (prefers-reduced-motion: reduce) {
  .sp-tile, .sp-page, .sp-word, .sp-tag, .sp-track { animation: none; }
  .sp-line, .sp-check { animation: none; stroke-dashoffset: 0; }
  .sp-stamp { animation: none; opacity: 1; }
  .sp-track span { animation: sp-pulse 1.4s ease-in-out infinite; transform: none; width: 100%; }
  @keyframes sp-pulse { 50% { opacity: .35; } }
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #splash { background: #10331d; } }
:root[data-theme="dark"] #splash { background: #10331d; }

/* ======================================================================
   شاشة الدخول: بتكمل من شاشة التحميل
   ====================================================================== */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.auth-hero { background: #1a5530; color: #eef4ea; text-align: center; padding: calc(40px + env(safe-area-inset-top, 0px)) 24px 76px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.auth-hero svg { width: 68px; height: 68px; margin-bottom: 8px; }
.auth-hero .sp-word { font-size: 2.1rem; animation: none; }
.auth-hero .sp-tag { animation: none; }
.auth-card {
  width: min(100% - 32px, 420px); margin: -48px auto 24px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 18px 18px 20px; box-shadow: 0 10px 30px rgba(23, 38, 27, .14); display: flex; flex-direction: column; gap: 14px;
  animation: auth-in .45s ease-out both;
}
@keyframes auth-in { from { opacity: 0; transform: translateY(16px); } }
@media (prefers-reduced-motion: reduce) { .auth-card { animation: none; } }
.auth-card h1 { font-size: 1.25rem; }
.auth-card .lead { color: var(--muted); font-size: .92rem; margin-top: -8px; }
.auth-card .input { min-height: 52px; font-size: 1.05rem; }
.pass-wrap { position: relative; }
.pass-wrap .input { padding-left: 76px; }
.pass-toggle { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); border: 0; background: var(--surface-2); color: var(--muted); border-radius: 9px; padding: 7px 10px; font-size: .82rem; cursor: pointer; min-height: 36px; }
.auth-foot { text-align: center; color: var(--muted); font-size: .86rem; padding: 0 16px 24px; }
.auth-foot button { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 6px; }
.auth-help { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: .88rem; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auth-hero { background: #10331d; } }
:root[data-theme="dark"] .auth-hero { background: #10331d; }
@media (min-width: 900px) { .auth-hero { padding-top: 64px; padding-bottom: 96px; } .auth-card { margin-top: -64px; } }
/* تحميل الشاشات بين الصفحات: نفس الشريط الذهبي، صغير */
.loading { display: grid; place-items: center; min-height: 40vh; }
.mini-load { display: block; width: 96px; height: 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.mini-load span { display: block; width: 40%; height: 100%; border-radius: 99px; background: #e0a43a; animation: sp-sweep 1.1s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .mini-load span { animation: none; width: 100%; opacity: .6; } }

#splash.quick .sp-tile, #splash.quick .sp-page, #splash.quick .sp-word, #splash.quick .sp-tag, #splash.quick .sp-track { animation: none; }
#splash.quick .sp-line, #splash.quick .sp-check { animation: none; stroke-dashoffset: 0; }
#splash.quick .sp-stamp { animation: none; opacity: 1; }
#splash.quick .sp-track span { animation-delay: 0s; }

/* الشريط فوق: اسم الحساب، وبيصير برتقالي إذا ما في نت أو في بيعات بتستنى */
button.mode-chip { border: 0; font: inherit; cursor: pointer; }
.mode-chip.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
/* لوحة يزن */
.admin { min-height: 100vh; background: var(--bg); }
.admin-head { background: #1a5530; color: #eef4ea; padding-block: calc(16px + env(safe-area-inset-top, 0px)) 16px; }
.admin-head h1 { font-family: var(--font-display); font-size: 1.35rem; }
.admin .wrap { max-width: 760px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.shop-card { display: flex; flex-direction: column; gap: 10px; }
.shop-card.off { opacity: .75; }
.code-card { background: var(--surface-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.code-card .code { font-family: var(--font-display); font-size: 1.6rem; letter-spacing: .12em; direction: ltr; text-align: right; font-weight: 700; }

/* ---------- شريط التحديث ---------- */
.update-bar { position: fixed; z-index: 40; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top, 0px)); width: min(92vw, 420px);
  display: flex; align-items: center; gap: 10px; background: var(--accent); color: var(--accent-ink); padding: 8px 8px 8px 14px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; animation: upd-in .3s ease-out; }
.update-bar .btn { background: var(--accent-ink); color: var(--accent); border-color: var(--accent-ink); flex: none; }
@keyframes upd-in { from { opacity: 0; transform: translate(-50%, -8px); } }
