:root {
  --bg: #f7f3ee;
  --card: #ffffff;
  --ink: #2a211b;
  --muted: #7a6d62;
  --line: #e8e0d6;
  --brand: #3b2a1f;
  --accent: #b8742a;
  --ok: #2f7d4f;
  --ok-bg: #e6f3ea;
  --warn: #a86400;
  --warn-bg: #fdf1de;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --info-bg: #ecebf7;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif; font-size: 16px; line-height: 1.5; }
input, select, textarea, button { font: inherit; color: inherit; }
a { color: var(--accent); }
.splash { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* شريط علوي */
.top { position: sticky; top: 0; z-index: 5; background: var(--brand); color: #fff; padding: calc(10px + var(--safe-t)) 16px 10px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 600; }
.top .back { background: none; border: 0; color: #fff; font-size: 22px; padding: 0 4px; cursor: pointer; }
.top .who { font-size: 12px; opacity: .8; }

main { max-width: 820px; margin: 0 auto; padding: 14px 14px calc(90px + var(--safe-b)); }

/* شريط سفلي */
.tabs { position: fixed; bottom: 0; inset-inline: 0; z-index: 5; background: #fff; border-top: 1px solid var(--line); display: flex; padding-bottom: var(--safe-b); }
.tabs a { flex: 1; text-align: center; padding: 8px 2px 9px; color: var(--muted); text-decoration: none; font-size: 12px; position: relative; }
.tabs a .ic { display: block; font-size: 20px; line-height: 1.2; }
.tabs a.on { color: var(--brand); font-weight: 600; }
.tabs .dot { position: absolute; top: 4px; inset-inline-start: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 10px; font-size: 10px; padding: 0 5px; min-width: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.spacer { height: 8px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-decoration: none; color: inherit; display: block; }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.hot { border-color: var(--accent); background: #fff8ef; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=number] { direction: ltr; text-align: center; }
textarea { min-height: 64px; resize: vertical; }

.btn { border: 0; border-radius: 10px; padding: 11px 16px; background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.block { width: 100%; }
.btn.big { padding: 16px; font-size: 18px; }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }

.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--info-bg); white-space: nowrap; }
.pill.pending { background: var(--warn-bg); color: var(--warn); }
.pill.approved { background: #e5f0fb; color: #1d5d99; }
.pill.received { background: var(--ok-bg); color: var(--ok); }
.pill.rejected, .pill.cancelled { background: var(--bad-bg); color: var(--bad); }
.pill.diff { background: var(--bad-bg); color: var(--bad); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); padding: 11px 2px; }
.list > li:last-child { border-bottom: 0; }
a.item-link { display: block; text-decoration: none; color: inherit; }

.seg { display: flex; background: #efe8df; border-radius: 10px; padding: 3px; gap: 3px; overflow-x: auto; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 8px; white-space: nowrap; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 500; }
table.t td.num, table.t th.num { text-align: center; direction: ltr; white-space: nowrap; }
.scroll-x { overflow-x: auto; }
.neg { color: var(--bad); font-weight: 600; }
.pos { color: var(--ok); font-weight: 600; }
.low { background: var(--warn-bg); }

/* محرر الأسطر */
.line { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; background: #fffdfa; }
.line .name { font-weight: 600; }
.line .conv { font-size: 12px; color: var(--muted); }
.line .qtyrow { display: grid; grid-template-columns: 1fr 1.3fr auto; gap: 6px; margin-top: 6px; align-items: center; }
.x { background: none; border: 0; color: var(--bad); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.picker { position: relative; }
.picker .results { position: absolute; inset-inline: 0; top: 100%; z-index: 10; background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; max-height: 300px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.picker .results button { display: block; width: 100%; text-align: start; border: 0; background: none; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.picker .results button:hover { background: var(--bg); }

.toast { position: fixed; bottom: calc(80px + var(--safe-b)); inset-inline: 16px; z-index: 50; max-width: 520px; margin: 0 auto; background: var(--ink); color: #fff; padding: 12px 14px; border-radius: 12px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.err { background: var(--bad); }

.auth { max-width: 380px; margin: 0 auto; padding: calc(40px + var(--safe-t)) 18px 30px; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 10px; }
.auth h1 { text-align: center; font-size: 22px; margin: 0 0 18px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.banner { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
details summary { cursor: pointer; padding: 4px 0; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }

@media print {
  .top, .tabs, .noprint, .toast { display: none !important; }
  body, main { background: #fff; padding: 0; }
  .card { border: 0; }
}

.langbtn { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; padding: 3px 10px; font-size: 13px; cursor: pointer; }
.auth .langbtn { background: #fff; color: var(--brand); border-color: var(--line); float: inline-end; }
