@font-face {
  font-family: 'Tajawal';
  src: url('/fonts/tajawal-ar-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: 'Tajawal';
  src: url('/fonts/tajawal-ar-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: 'Tajawal';
  src: url('/fonts/tajawal-latin-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Tajawal';
  src: url('/fonts/tajawal-latin-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f3f1ec;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e1d8;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Tajawal', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

#app { max-width: 720px; margin: 0 auto; padding-bottom: 84px; }

/* ===== header ===== */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 14px 16px;
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 19px; font-weight: 700; }
.topbar .who { font-size: 13px; opacity: .92; }

/* ===== bottom nav ===== */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav button {
  flex: 1; border: 0; background: none; cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 700; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border-radius: 10px;
}
.bottomnav button .ic { font-size: 21px; }
.bottomnav button.active { color: var(--primary); background: #f0fdfa; }

/* ===== cards & layout ===== */
.page { padding: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 16px; margin-bottom: 10px; }

/* ===== buttons ===== */
.btn {
  font-family: inherit; font-weight: 700; cursor: pointer;
  border: 0; border-radius: 12px; padding: 13px 18px; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #ccfbf1; color: var(--primary-dark); }
.btn-warn { background: #fef3c7; color: var(--accent); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-ghost { background: none; color: var(--muted); padding: 8px 10px; font-size: 14px; }
.btn-sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ===== forms ===== */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 5px; color: var(--ink); }
.field input, .field select, .field textarea {
  width: 100%; font-family: inherit; font-size: 16px;
  padding: 12px 12px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fbfaf7; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
}
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ===== segmented toggle ===== */
.seg { display: flex; background: #e7e4dc; border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button {
  flex: 1; border: 0; background: none; font-family: inherit; font-size: 16px; font-weight: 700;
  padding: 11px; border-radius: 9px; cursor: pointer; color: var(--muted);
}
.seg button.on-in { background: var(--ok); color: #fff; }
.seg button.on-out { background: var(--danger); color: #fff; }
.seg button.on-plain { background: var(--primary); color: #fff; }

/* ===== chips ===== */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  font-family: inherit; font-size: 14px; font-weight: 700;
  padding: 8px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== item rows ===== */
.item-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.item-row:last-child { border-bottom: 0; }
.item-row .nm { font-weight: 700; font-size: 15px; }
.item-row .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item-row .qty { text-align: left; min-width: 76px; }
.item-row .qty b { font-size: 17px; }
.item-row .qty span { display: block; font-size: 12px; color: var(--muted); }
.badge-low {
  display: inline-block; background: #fee2e2; color: var(--danger);
  font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 2px 9px; margin-top: 3px;
}
.badge-ok { color: var(--ok); }

/* ===== login ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo .mark { font-size: 46px; }
.login-logo h1 { font-size: 24px; color: var(--primary-dark); }
.login-logo p { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ===== toast ===== */
#toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; font-weight: 700; font-size: 15px;
  padding: 12px 22px; border-radius: 999px; z-index: 90; box-shadow: var(--shadow);
  max-width: 90vw; text-align: center;
}
#toast.err { background: var(--danger); }
#toast.ok { background: var(--ok); }

/* ===== scanner ===== */
#scanner-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.scanner-box { background: #111; border-radius: 16px; width: 100%; max-width: 440px; overflow: hidden; }
.scanner-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: #fff; font-weight: 700; }
.scanner-head .btn-ghost { color: #fca5a5; }
#scanner-view { width: 100%; min-height: 280px; background: #000; }
#scanner-view video { width: 100% !important; }
.scanner-hint { color: #d1d5db; text-align: center; padding: 10px; font-size: 14px; }

/* ===== modal ===== */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 70; display: flex; align-items: flex-end; justify-content: center; }
.modal-card {
  background: var(--card); width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.modal-card h3 { margin-bottom: 12px; font-size: 18px; }

/* ===== tables ===== */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: right; color: var(--muted); font-size: 12.5px; padding: 8px 6px; border-bottom: 2px solid var(--line); }
.tbl td { padding: 9px 6px; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }

.kind-pill { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 2px 10px; }
.kind-in { background: #dcfce7; color: var(--ok); }
.kind-out { background: #fee2e2; color: var(--danger); }
.kind-adjust { background: #fef3c7; color: var(--accent); }
.kind-transfer { background: #e0e7ff; color: #4338ca; }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; }
.big-num { font-size: 30px; font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 20px; margin-top: 2px; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.warn b { color: var(--danger); }

.menu-list button {
  width: 100%; text-align: right; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 15px 14px; margin-bottom: 10px;
  font-family: inherit; font-size: 16px; font-weight: 700; color: var(--ink); cursor: pointer;
  display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow);
}
.menu-list button .ic { font-size: 20px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 15px; }
.spin { text-align: center; padding: 40px; color: var(--muted); }

.hidden { display: none !important; }

@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal-card { border-radius: 18px; }
}
