/* ============================================================
   مخزني — التنسيقات
   ============================================================ */
/* ---------- خطوط هيكلا ----------
   حط ملفات الخطوط في مجلد fonts/ بنفس الأسماء هذي (أي صيغة من الثلاث تكفي).
   إذا ما كانت موجودة، التطبيق يستخدم الخط الاحتياطي تلقائياً. */
@font-face {
  font-family: "GE Dinar One";
  src: url("fonts/GEDinarOne.woff2") format("woff2"), url("fonts/GEDinarOne.ttf") format("truetype"), url("fonts/GEDinarOne.otf") format("opentype");
  font-weight: 100 900; font-display: swap;
}
@font-face {
  font-family: "Papercut";
  src: url("fonts/Papercut.woff2") format("woff2"), url("fonts/Papercut.ttf") format("truetype"), url("fonts/Papercut.otf") format("opentype");
  font-weight: 100 900; font-display: swap;
}

/* ---------- ألوان هيكلا ---------- */
:root {
  --brand: #DF482B;
  --brand-light: #EBF4F3;
  --bg: #EBF4F3;
  --surface: #FFFFFF;
  --surface-2: #dde9e7;
  --line: #d3e0de;
  --text: #000000;
  --muted: #5d6b69;
  --primary: #DF482B;
  --primary-ink: #FFFFFF;
  --primary-soft: #fbe2dc;
  --danger: #a4161a;
  --danger-soft: #f8dcdc;
  --warn: #a86400;
  --warn-soft: #fbedd2;
  --in: #000000;
  --out: #DF482B;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .05);
  /* الإنجليزي والأرقام بخط Papercut، والعربي بخط GE Dinar One */
  --font: "Papercut", "GE Dinar One", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f0f; --surface: #171a1a; --surface-2: #222727; --line: #2d3333;
    --text: #EBF4F3; --muted: #9aa8a6; --primary: #DF482B; --primary-ink: #FFFFFF;
    --primary-soft: #3a1a12; --danger: #ff6b6b; --danger-soft: #3a1414;
    --warn: #f5b04a; --warn-soft: #3a2a10; --in: #EBF4F3; --out: #ff7a5c;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- الهيكل ---------- */
.shell { min-height: 100vh; padding-bottom: calc(84px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; display: block; }
.me-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 6px 5px 12px; min-height: 40px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.demo-bar { background: var(--warn-soft); color: var(--warn); font-size: 13px; padding: 8px 16px; text-align: center; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.page-head h1 { font-size: 22px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border: 0; background: none; color: var(--muted); font-size: 12px; text-decoration: none; min-height: 52px; border-radius: 10px; }
.tab[aria-current="page"] { color: var(--primary); font-weight: 600; }
.tab svg { width: 24px; height: 24px; }

.fab {
  position: fixed; z-index: 31; inset-inline-start: 50%; transform: translateX(50%);
  bottom: calc(40px + var(--safe-b)); width: 62px; height: 62px; border-radius: 50%; border: 4px solid var(--bg);
  background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; box-shadow: 0 6px 18px rgba(223, 72, 43, .4);
}
.fab svg { width: 30px; height: 30px; }
.fab:active { transform: translateX(50%) scale(.95); }
.tab-gap { flex: 0 0 72px; }

/* ---------- البطاقات ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); text-align: start; }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.warn b { color: var(--warn); }
.stat.danger b { color: var(--danger); }
button.stat { width: 100%; }
button.stat[aria-pressed="true"] { outline: 2px solid var(--primary); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; min-height: 64px; box-shadow: var(--shadow);
}
button.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); }
.row-end { text-align: end; flex-shrink: 0; }
.qty { font-weight: 700; font-size: 18px; }
.st-low { border-inline-start: 4px solid var(--warn); }
.st-out { border-inline-start: 4px solid var(--danger); }
.st-low .qty { color: var(--warn); }
.st-out .qty { color: var(--danger); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--primary-soft); color: var(--primary); }
.badge.in { background: var(--surface-2); color: var(--in); }
.badge.out { background: var(--primary-soft); color: var(--out); }

.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--text); border-radius: 999px; }
.st-low .bar i { background: var(--warn); }
.st-out .bar i { background: var(--danger); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .5; }
.section-title { font-size: 14px; color: var(--muted); font-weight: 600; margin: 18px 4px 8px; }

/* ---------- النماذج ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 14px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.ltr { direction: ltr; text-align: right; }
.search { position: relative; margin-bottom: 12px; }
.search .input { padding-inline-start: 42px; }
.search svg { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.with-unit { position: relative; }
.with-unit .unit { position: absolute; inset-inline-end: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.with-unit .input { padding-inline-end: 56px; font-size: 22px; font-weight: 700; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { border: 0; background: transparent; border-radius: 9px; min-height: 44px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.move button[data-v="out"][aria-pressed="true"] { background: var(--out); color: #fff; }
.seg.move button[data-v="in"][aria-pressed="true"] { background: var(--text); color: var(--bg); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid transparent; font-weight: 600; background: var(--surface-2); color: var(--text);
}
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 6px 14px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { inset-inline-start: 23px; }
.switch input:disabled + span { opacity: .5; }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }

/* ---------- الشاشات المنبثقة ---------- */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 12, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(18px + var(--safe-b)); animation: up .22s ease-out;
}
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; } }
.grab { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { font-size: 19px; margin: 0; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2); display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.pick-list { max-height: 38vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; padding: 2px; }
.pick { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); min-height: 52px; text-align: start; width: 100%; }
.pick[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border: 1px solid var(--primary); border-radius: 12px; background: var(--primary-soft); margin-bottom: 14px; }
.preview { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px; border-radius: 12px; background: var(--surface); border: 1px dashed var(--line); margin-bottom: 14px; font-size: 15px; }
.preview .after { font-weight: 700; }
.preview.bad { border-color: var(--danger); color: var(--danger); }

/* ---------- التقرير ---------- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.filters .field { margin: 0; }
.filters .input { min-height: 44px; font-size: 15px; padding: 8px 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-size: 14px; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.mv { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; }
.mv-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.mv-ico svg { width: 20px; height: 20px; }
.mv-ico.out { background: var(--primary-soft); color: var(--out); }
.mv-ico.in { background: var(--surface-2); color: var(--in); }
.mv-amt.out { color: var(--out); } .mv-amt.in { color: var(--in); }
.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 4px 6px; }

/* ---------- الدخول ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 18px; }
.auth-box { width: 100%; max-width: 400px; }
.auth-logo { width: 88px; height: 88px; border-radius: 22px; overflow: hidden; margin: 0 auto 14px; box-shadow: 0 8px 24px rgba(223, 72, 43, .3); }
.auth-logo img { width: 100%; height: 100%; display: block; }
.auth h1 { text-align: center; margin: 0 0 4px; font-size: 26px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 24px; }
.auth .card { padding: 20px; }

/* ---------- التنبيهات ---------- */
#toasts { position: fixed; z-index: 80; top: calc(12px + var(--safe-t)); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: 15px; box-shadow: var(--shadow); animation: up .2s; max-width: 420px; }
.toast.ok { background: var(--primary); color: var(--primary-ink); }
.toast.bad { background: var(--danger); color: #fff; }

.user-row { padding: 12px 14px; }
.user-top { display: flex; align-items: center; gap: 12px; }
.user-ctrls { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 4px; }
.user-off { opacity: .6; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
