/* Shortages (النواقص) - the Sadad look: ivory paper, navy ink, brass accent.
 * Dark: slate with a gold finish. */
:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --field: #f7f5f0;
  --ink: #141b2b;
  --muted: #677084;
  --line: #e3ddd1;
  --primary-fill: #14213d;
  --on-primary: #ffffff;
  --accent: #b08d57;
  --accent-ink: #80622f;
  --tint: #f3ecdf;
  --hero-a: #14213d;
  --hero-b: #223560;
  --hero-ink: #ffffff;
  --hero-muted: #b8c2d8;
  --hero-line: rgba(255, 255, 255, .22);
  --danger: #a3271b;
  --ok: #1c6a4e;
  --ok-tint: #e2f2ea;
  --warn: #8a5a00;
  --warn-tint: #fdf1d6;
  --shadow: 0 1px 2px rgba(20, 27, 43, .04), 0 8px 24px rgba(20, 27, 43, .06);
  --sheen: none;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b202a;
    --surface: #262d3a;
    --field: #1e242f;
    --ink: #f3f5f8;
    --muted: #aab3c3;
    --line: #3b4455;
    --primary-fill: linear-gradient(135deg, #f0dfb8 0%, #d3b47a 45%, #b9975c 100%);
    --on-primary: #1d170b;
    --accent: #d9bd88;
    --accent-ink: #e0c692;
    --tint: #303848;
    --hero-a: #2b3445;
    --hero-b: #4a566b;
    --hero-ink: #ffffff;
    --hero-muted: #c3cbd9;
    --hero-line: rgba(224, 198, 146, .4);
    --danger: #ff9585;
    --ok: #74d3ab;
    --ok-tint: #22382f;
    --warn: #f0c060;
    --warn-tint: #3a3326;
    --shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 10px 24px rgba(0, 0, 0, .22);
    --sheen: inset 0 1px 0 rgba(255, 255, 255, .07);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1b202a;
  --surface: #262d3a;
  --field: #1e242f;
  --ink: #f3f5f8;
  --muted: #aab3c3;
  --line: #3b4455;
  --primary-fill: linear-gradient(135deg, #f0dfb8 0%, #d3b47a 45%, #b9975c 100%);
  --on-primary: #1d170b;
  --accent: #d9bd88;
  --accent-ink: #e0c692;
  --tint: #303848;
  --hero-a: #2b3445;
  --hero-b: #4a566b;
  --hero-ink: #ffffff;
  --hero-muted: #c3cbd9;
  --hero-line: rgba(224, 198, 146, .4);
  --danger: #ff9585;
  --ok: #74d3ab;
  --ok-tint: #22382f;
  --warn: #f0c060;
  --warn-tint: #3a3326;
  --shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 10px 24px rgba(0, 0, 0, .22);
  --sheen: inset 0 1px 0 rgba(255, 255, 255, .07);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Behave like an installed app: no zoom, no text selection or callouts, no rubber-band page. */
html { -webkit-text-size-adjust: 100%; overscroll-behavior: none; overflow-x: hidden; scrollbar-width: none; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}
input, textarea { -webkit-user-select: text; user-select: text; }
::-webkit-scrollbar { display: none; }
body.locked { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 24px 8px; display: grid; gap: 12px; justify-items: center; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { max-width: 1200px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
/* The back arrow points to where the reader came from: right in Arabic. */
[dir="rtl"] .icon.flip { transform: scaleX(-1); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  font-weight: 700; background: var(--surface); color: var(--ink);
}
.btn.wide { width: 100%; }
.btn.primary { border: 0; background: var(--primary-fill); color: var(--on-primary); min-height: 54px; }
.btn.primary:disabled, .btn:disabled { opacity: .45; cursor: default; }
.btn.soft { background: var(--tint); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { border: 0; background: var(--danger); color: #fff; }
.btn.danger-text { background: transparent; border-color: transparent; color: var(--danger); margin-top: 4px; }
.btn.ordered { border: 0; background: var(--ok); color: #fff; min-height: 54px; }
:root[data-theme="dark"] .btn.ordered, :root[data-theme="dark"] .btn.danger { color: #10241b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.ordered, :root:not([data-theme="light"]) .btn.danger { color: #10241b; } }
.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  display: inline-grid; place-items: center; color: var(--ink);
}
.chip-btn { display: inline-flex; align-items: center; gap: 4px; border: 0; border-radius: 999px; padding: 4px 10px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 13px; }
.chip-btn .icon { width: 16px; height: 16px; }

/* ---------- sign in ---------- */
.signin { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); }
.signin-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 24px; box-shadow: var(--shadow), var(--sheen); display: grid; gap: 10px; }
.signin-top { display: flex; align-items: center; gap: 8px; }
.signin-logo { width: 56px; height: 56px; border-radius: 14px; margin-inline-end: auto; }
.signin h1 { font-size: 1.7rem; }
form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; color: var(--muted); }
input, textarea {
  width: 100%; min-height: 50px; border: 1px solid var(--line); background: var(--field); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; font-weight: 400; color: var(--ink); outline: none;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(176, 141, 87, .22); }
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
.form-error { color: var(--danger); font-weight: 600; font-size: 14px; }

/* ---------- top bar and hero ---------- */
.bar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 14px) 16px 10px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; margin-inline-end: auto; min-width: 0; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand h1 { font-size: 1.7rem; line-height: 1.15; letter-spacing: -.01em; }
.who { color: var(--muted); font-size: .85rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-tools { display: flex; gap: 8px; }

.hero {
  position: relative; overflow: hidden; margin: 4px 16px 0; padding: 18px 20px; border-radius: 22px;
  background: linear-gradient(140deg, var(--hero-b), var(--hero-a) 70%); color: var(--hero-ink);
  border: 1px solid var(--hero-line); box-shadow: var(--shadow);
  display: grid; gap: 2px;
}
.hero::after {
  content: ""; position: absolute; inset-block-start: -70px; inset-inline-end: -70px; width: 190px; height: 190px;
  border-radius: 50%; border: 1px solid var(--hero-line); pointer-events: none;
}
.eyebrow { font-size: .8rem; font-weight: 600; letter-spacing: .03em; color: #d9bd88; }
.hero-count { font-size: 2.4rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.hero-sub { font-size: .85rem; color: var(--hero-muted); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 12px 16px 0; padding: 4px; border-radius: 14px; background: var(--field); border: 1px solid var(--line); }
.tabs:empty { display: none; }
.tabs button { min-height: 44px; border: 0; border-radius: 10px; background: none; color: var(--muted); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.tabs button[aria-pressed="true"] { background: var(--primary-fill); color: var(--on-primary); }
.tabs .count { min-width: 24px; padding: 0 7px; border-radius: 999px; background: var(--tint); color: var(--accent-ink); font-size: 13px; line-height: 22px; }
.tabs button[aria-pressed="true"] .count { background: rgba(255, 255, 255, .2); color: inherit; }
.ordered-by { display: flex; align-items: center; gap: 4px; color: var(--ok); font-weight: 600; }
.ordered-by .icon { width: 15px; height: 15px; }
.advance.back { background: var(--tint); color: var(--accent-ink); }
.search { position: relative; display: block; margin: 14px 16px 0; }
.search .icon { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-inline-start: 46px; background: var(--surface); }
.search.in-sheet { margin: 0 0 12px; }
.search.in-sheet input { background: var(--field); }

.btn.install { margin: 12px 16px 0; width: calc(100% - 32px); }
.demo { margin: 12px 16px 0; padding: 10px 14px; border-radius: 12px; background: var(--warn-tint); color: var(--warn); font-size: 14px; }

/* ---------- list ---------- */
.list { padding: 14px 16px calc(110px + var(--safe-bottom)); }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow), var(--sheen); overflow: hidden;
  display: grid; grid-template-columns: 104px 1fr; grid-template-rows: 1fr auto; cursor: pointer; min-height: 120px;
}
@media (min-width: 560px) { .card { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; } }
.card-photo { position: relative; grid-row: span 2; background: var(--field); }
@media (min-width: 560px) { .card-photo { grid-row: auto; aspect-ratio: 4 / 3; } }
.card-photo .photo, .card-photo .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ph { display: grid; place-items: center; color: var(--muted); background: var(--field); }
.ph .icon { width: 36px; height: 36px; stroke-width: 1.3; }
.qty {
  position: absolute; bottom: 6px; inset-inline-start: 6px; padding: 2px 10px; border-radius: 999px;
  background: rgba(20, 33, 61, .88); color: #fff; font-weight: 700; font-size: 14px; direction: ltr;
}
.card-body { padding: 10px 12px 4px; display: grid; gap: 4px; align-content: start; min-width: 0; }
.card-body h3 { font-size: 15px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.code { font-size: 12px; color: var(--muted); direction: ltr; unicode-bidi: isolate; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--field); color: var(--muted); font-weight: 600; justify-self: start; }
.chip.new { background: var(--tint); color: var(--accent-ink); }
.chip.warn { background: var(--warn-tint); color: var(--warn); }
.chip.bad { background: var(--warn-tint); color: var(--danger); }
.meta .chip .icon { width: 13px; height: 13px; vertical-align: -2px; margin-inline-end: 3px; }
/* Saved on this phone, not on the server yet. */
.card.pending { border-style: dashed; border-color: var(--warn); }
.card.pending.failed { border-color: var(--danger); }
.section-label { margin: 6px 0 -4px; font-size: 13px; font-weight: 700; color: var(--muted); }
/* The add button stays in reach while the optional details are filled in. */
.sticky-save { position: sticky; bottom: calc(-20px - var(--safe-bottom)); margin: 4px -16px calc(-20px - var(--safe-bottom)); padding: 10px 16px calc(12px + var(--safe-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.note { font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.by { font-size: 12px; color: var(--muted); }
.advance {
  margin: 4px 12px 10px; justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: var(--ok-tint); color: var(--ok); border-radius: 10px; padding: 7px 14px; font-size: 14px; font-weight: 700;
}
.advance .icon { width: 18px; height: 18px; }
.skeleton { min-height: 120px; background: linear-gradient(90deg, var(--surface), var(--field), var(--surface)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 56px 16px; color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.empty .icon { width: 44px; height: 44px; stroke-width: 1.3; }

.fab {
  position: fixed; z-index: 15; bottom: calc(18px + var(--safe-bottom)); inset-inline-end: 18px;
  display: inline-flex; align-items: center; gap: 8px; height: 56px; padding: 0 22px; border: 0; border-radius: 999px;
  background: var(--primary-fill); color: var(--on-primary); font-weight: 700; font-size: 16px; box-shadow: 0 8px 24px rgba(20, 27, 43, .28);
}

/* ---------- sheets ---------- */
#sheet { position: fixed; inset: 0; z-index: 40; display: none; }
#sheet.show { display: block; }
.sheet-back { position: absolute; inset: 0; background: rgba(8, 12, 22, .45); animation: fade .2s ease; }
.sheet {
  position: absolute; inset-inline: 0; bottom: 0; max-height: calc(100% - 24px - var(--safe-top)); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 0 16px calc(20px + var(--safe-bottom));
  animation: rise .22s ease;
}
@media (min-width: 700px) {
  .sheet { inset-inline-start: auto; top: 0; bottom: 0; width: 460px; max-height: none; border-radius: 0; animation: fade .22s ease; }
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 14px 0 12px; background: var(--bg); }
.sheet-head h2 { flex: 1; text-align: center; font-size: 1.1rem; }
@media (min-width: 700px) { .sheet-head { padding-top: calc(14px + var(--safe-top)); } }

.choices { display: grid; gap: 12px; padding: 4px 0 8px; }
.choice {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; row-gap: 2px; align-items: center;
  text-align: start; padding: 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow), var(--sheen);
}
.choice .icon { grid-row: span 2; width: 34px; height: 34px; padding: 8px; box-sizing: content-box; border-radius: 12px; background: var(--tint); color: var(--accent-ink); }
.choice strong { font-size: 17px; }
.choice span { color: var(--muted); font-size: 14px; }
/* «مادة جديدة» is a label (it opens the camera); undo the form-label look. */
label.choice { font-weight: 400; font-size: 16px; color: var(--ink); cursor: pointer; }
.choice strong { color: var(--ink); }

.results { display: grid; gap: 8px; }
.result {
  display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; text-align: start;
  padding: 8px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
}
.thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--field); }
.thumb.ph .icon { width: 26px; height: 26px; }
.result-text { display: grid; gap: 2px; min-width: 0; }
.result-text strong { font-size: 15px; line-height: 1.35; }

.picked { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.picked > div { display: grid; gap: 4px; }
.picked-photo { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; background: var(--field); }

.stepper { display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; align-items: center; max-width: 240px; }
.stepper .icon-btn { width: 52px; height: 50px; }
.stepper input { text-align: center; font-size: 20px; font-weight: 700; padding: 10px 4px; direction: ltr; }

.photo-pick { display: grid; gap: 10px; }
.photo-preview { position: relative; border-radius: 14px; overflow: hidden; background: var(--field); }
.photo-preview img { display: block; width: 100%; max-height: 280px; object-fit: contain; }
.photo-preview .chip-btn { position: absolute; top: 8px; inset-inline-end: 8px; }
.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }

.detail { display: grid; gap: 12px; }
.photos { border-radius: 16px; overflow: hidden; background: var(--field); border: 1px solid var(--line); }
.photos .big { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--surface); }
.photos.two { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.photos figure { margin: 0; }
.photos figcaption { font-size: 12px; text-align: center; color: var(--muted); padding: 4px; background: var(--surface); }
.detail-name { font-size: 1.25rem; line-height: 1.35; }
.history summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.history ul { margin: 0; padding-inline-start: 18px; display: grid; gap: 6px; font-size: 14px; }

/* ---------- dialog and toast ---------- */
#dialog:empty { display: none; }
.dialog-back { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(8, 12, 22, .45); animation: fade .15s ease; }
.dialog { width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px; padding: 20px; display: grid; gap: 16px; box-shadow: var(--shadow); }
.dialog p { font-size: 17px; font-weight: 600; text-align: center; }
.dialog-actions { display: grid; gap: 8px; }
#toast { position: fixed; z-index: 70; inset-inline: 0; top: calc(10px + var(--safe-top)); display: flex; justify-content: center; pointer-events: none; opacity: 0; transform: translateY(-8px); transition: opacity .2s, transform .2s; padding: 0 16px; }
#toast.show { opacity: 1; transform: none; }
#toast.show .toast { pointer-events: auto; }
.toast { display: flex; align-items: center; gap: 12px; max-width: 440px; padding: 12px 16px; border-radius: 14px; background: #14213d; color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.toast.ok { background: #1c6a4e; }
.toast.warn { background: #8a5a00; }
.toast.bad { background: #a3271b; }
.toast-action { border: 0; border-radius: 10px; padding: 6px 12px; background: rgba(255, 255, 255, .2); color: #fff; font-weight: 700; flex: none; }

@media (hover: hover) {
  .card:hover, .result:hover, .choice:hover { border-color: var(--accent); }
  .btn.primary:hover, .fab:hover { filter: brightness(1.08); }
}
