:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #17201d;
  --muted: #64716c;
  --line: #dfe5e2;
  --brand: #0f5c4d;
  --brand-soft: #e3f1ed;
  --ok: #1a7f37;
  --warn: #b25e00;
  --bad: #b42318;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --card: #18201d; --ink: #e8eeeb; --muted: #9aa8a2; --line: #2a3531;
    --brand: #4fc3a1; --brand-soft: #1b3a32; --ok: #4cc26b; --warn: #f0a33a; --bad: #ff6b5e;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.5 -apple-system, "SF Arabic", "Geeza Pro", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 20px; margin: 0; flex: 1; }
.chip-btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px; font-size: 14px;
}
main { padding: 16px; max-width: 720px; margin: 0 auto; }

.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  height: var(--nav-h); border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; position: relative;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--brand); font-weight: 600; }
.badge {
  position: absolute; top: 6px; inset-inline-start: calc(50% + 6px);
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--bad); color: #fff; font-size: 12px; line-height: 20px; font-weight: 700;
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.muted { color: var(--muted); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); padding: 10px 14px; font-weight: 600; text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06261f; } }
.btn.big { min-height: 120px; font-size: 20px; flex-direction: column; }
.btn.big svg { width: 40px; height: 40px; }
.btn.danger { color: var(--bad); }
.btn.small { width: auto; min-height: 40px; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }

label.field { display: block; font-size: 14px; color: var(--muted); }
label.field input, label.field select, label.field textarea, .input {
  display: block; width: 100%; margin-top: 4px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 8px 10px;
  color: var(--ink); font-size: 16px;
}
textarea { min-height: 120px; resize: vertical; }

.receipt { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: start; }
.thumb {
  width: 72px; height: 96px; object-fit: cover; border-radius: 10px; background: var(--line);
  border: 1px solid var(--line);
}
.receipt h3 { margin: 0; font-size: 17px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; color: var(--muted); }
.status { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.status.reading { background: #fff4e0; color: var(--warn); }
.status.failed { background: #fde8e6; color: var(--bad); }
@media (prefers-color-scheme: dark) {
  .status.reading { background: #3a2a10; } .status.failed { background: #3a1714; }
}
.list-row { cursor: pointer; }

table.items { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
table.items th, table.items td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: start; }
table.items th { color: var(--muted); font-weight: 500; }
table.items td.num, table.items th.num { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }

.tick {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 12px; width: 100%; min-height: 48px; border-radius: 12px;
  border: 2px solid var(--ok); color: var(--ok); background: transparent; font-weight: 700;
}
.tick svg { width: 22px; height: 22px; }

.item-edit { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-top: 8px; }
.item-edit .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; }
.item-edit .nums input { margin-top: 2px; }
.item-edit .nums label { font-size: 12px; color: var(--muted); }

.photo { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 12px; background: #000; }
pre.text { white-space: pre-wrap; font: inherit; font-size: 15px; margin: 0; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 10; background: var(--ink); color: var(--bg); border-radius: 12px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px; max-width: 520px; margin: 0 auto;
}
.toast span { flex: 1; }
.toast button { background: none; border: 0; color: var(--brand-soft); font-weight: 700; }

.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { text-align: center; }
.error { color: var(--bad); font-size: 14px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
h3.tight { margin: 0 0 4px; }
textarea.short { min-height: 60px; }
.row > .fixed { flex: 0 0 auto; }
.btn svg { width: 22px; height: 22px; flex: 0 0 auto; }
.btn.big svg { width: 40px; height: 40px; }
.thumb { object-position: top; }
.kinds {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.kinds button {
  min-height: 42px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-weight: 600;
}
.kinds button.on { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .kinds button.on { color: #06261f; } }
.kinds .count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--bad); color: #fff; font-size: 12px; line-height: 20px;
}
.status.kind-sale { background: #e8eefc; color: #2f54b8; }
@media (prefers-color-scheme: dark) { .status.kind-sale { background: #1c2747; color: #9db4ff; } }
