:root {
  --bg: #faf7f1;
  --card: #ffffff;
  --text: #1c2526;
  --muted: #6b7778;
  --line: #e4e9ea;
  --primary: #8a6a1f;
  --primary-soft: #f6eedb;
  --expense: #c2410c;
  --income: #15803d;
  --danger: #dc2626;
  --warn: #b45309;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1415; --card: #1a2224; --text: #e8eeee; --muted: #93a2a3; --line: #2a3537;
    --primary: #e0bd6a; --primary-soft: #3a2f17; --expense: #fb923c; --income: #4ade80; --danger: #f87171;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  font-size: 16px; line-height: 1.5;
  padding-top: var(--safe-t);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
}
main { max-width: 640px; margin: 0 auto; padding: 12px 14px; }
h1 { font-size: 1.35rem; margin: 6px 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
a { color: var(--primary); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden, [hidden] { display: none !important; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); border: 1px solid var(--line); }
.card + .card, .card + .grid2, .grid2 + .card, .banner + .card, .card + details, details + .card { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.stat .label { font-size: .85rem; color: var(--muted); }
.stat .value { font-size: 1.35rem; font-weight: 700; }
.big { font-size: 2rem; font-weight: 800; }
.pos { color: var(--income); } .neg { color: var(--danger); } .exp { color: var(--expense); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; }
.topbar h1 { margin: 0; font-size: 1.2rem; }
.monthnav { display: flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.monthnav button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; font-size: 1.2rem; color: var(--text); }
.monthnav button:active { background: var(--primary-soft); }
.monthnav .ml { min-width: 108px; text-align: center; font-weight: 600; font-size: .95rem; }

.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.over > i { background: var(--danger); }
.bar.thin { height: 6px; margin-top: 6px; }

.cat-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; padding-bottom: 0; }
.ico { width: 38px; height: 38px; border-radius: 12px; background: var(--primary-soft); display: grid; place-items: center; font-size: 1.2rem; flex: none; }

details.explain { background: var(--primary-soft); border-radius: var(--radius); padding: 12px 14px; font-size: .92rem; }
details.explain summary { cursor: pointer; font-weight: 600; color: var(--primary); }
.banner { background: #fff7ed; color: #7c2d12; border: 1px solid #fed7aa; border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 10px; align-items: center; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2412; color: #fed7aa; border-color: #7c2d12; } }

/* أزرار وحقول */
button, .btn { font: inherit; cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--primary); color: #fff; text-decoration: none; min-height: 46px; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .55; }
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; font-size: 16px; width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
input[type=date] { -webkit-appearance: none; appearance: none; text-align: right; }
.field + .field { margin-top: 12px; }
.err { color: var(--danger); font-size: .9rem; margin-top: 8px; min-height: 1em; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; border-radius: 9px; padding: 10px; background: transparent; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button.on[data-type=expense] { color: var(--expense); }
.seg button.on[data-type=income] { color: var(--income); }

.amount-wrap { position: relative; }
.amount-wrap input { font-size: 2.2rem; font-weight: 800; text-align: center; padding: 14px 60px; direction: ltr; }
.amount-wrap .cur { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .8rem; color: var(--text); min-height: 64px; }
.chip .e { font-size: 1.4rem; }
.chip.on { border-color: var(--primary); background: var(--primary-soft); outline: 2px solid var(--primary); }

.sticky-save { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); margin-top: 16px; }

/* السجل */
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.filters select { padding: 8px; min-height: 40px; font-size: 14px; }
.day-h { font-size: .85rem; color: var(--muted); margin: 14px 4px 6px; font-weight: 600; }
.tx { display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; width: 100%; text-align: right; color: var(--text); }
.tx + .tx { margin-top: 6px; }
.tx .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .t2 { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 700; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.pill { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.pill.ok { background: #dcfce7; color: #166534; }
.pill.warn { background: #ffedd5; color: #9a3412; }

/* شريط التبويبات */
.tabbar {
  position: fixed; inset: auto 0 0 0; height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; z-index: 20;
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: .7rem; color: var(--muted); text-decoration: none; height: 100%; }
.tabbar a .ti { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--primary); font-weight: 700; }
.tabbar a.on .ti { filter: none; opacity: 1; }
.tabbar a.fab { color: var(--primary); font-weight: 700; }
.fab-plus { width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 2.1rem; line-height: 1; margin-top: -26px; box-shadow: 0 6px 16px rgba(138,106,31,.4); border: 4px solid var(--bg); }

/* نافذة الحوار */
dialog { border: 0; border-radius: 20px; padding: 0; width: min(92vw, 440px); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 18px; max-height: 85vh; overflow: auto; }
.dlg-actions { display: flex; gap: 8px; margin-top: 16px; }
.dlg-actions .btn { flex: 1; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 1.2rem; }
.emoji-pick button.on { outline: 2px solid var(--primary); background: var(--primary-soft); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-b) + 20px); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 50; font-size: .95rem; max-width: 90vw; text-align: center; }
.toast.error { background: var(--danger); }

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

.auth-hero { text-align: center; margin: 28px 0 18px; }
.auth-hero .logo { width: 76px; height: 76px; border-radius: 20px; }
.auth-hero h1 { margin: 10px 0 4px; font-size: 1.6rem; }
.linkbtn { background: none; border: 0; color: var(--primary); padding: 6px; font-weight: 600; }

/* ---------- جملة: الكتالوج والطلبات ---------- */
input[type=search] { width: 100%; }
.hscroll { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 4px; scrollbar-width: none; margin: 0 -14px; padding-inline: 14px; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll .chip { flex: 0 0 auto; white-space: nowrap; flex-direction: row; gap: 6px; padding: 8px 14px; min-height: 40px; border-radius: 999px; font-size: .9rem; }
.hscroll .chip .e { font-size: 1.05rem; }
#sizes .chip, #colors .chip { min-height: 44px; justify-content: center; font-size: .95rem; font-weight: 600; }
.pgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
@media (min-width: 560px) { .pgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.pcard:active { transform: scale(.98); }
.pimg { position: relative; aspect-ratio: 3 / 4; background: var(--line); }
.pimg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pbody { padding: 8px 10px 10px; }
.pname { font-weight: 600; font-size: .92rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pprice { margin-top: 4px; font-weight: 700; color: var(--primary); }
.tag { position: absolute; top: 8px; inset-inline-start: 8px; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #f59e0b; color: #fff; }
.tag.off { background: #6b7280; inset-inline-start: auto; inset-inline-end: 8px; }
.tag.static { position: static; }
.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius); background: var(--line); scrollbar-width: none; }
.gallery::-webkit-scrollbar { display: none; }
.gallery img { flex: 0 0 100%; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; scroll-snap-align: center; }
.dots { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--primary); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.stepper button { width: 48px; height: 48px; border: 0; background: var(--primary-soft); color: var(--primary); font-size: 1.4rem; font-weight: 700; }
.stepper input { width: 72px; text-align: center; border: 0; border-radius: 0; font-size: 1.15rem; font-weight: 700; min-height: 48px; }
.stepper.sm button { width: 34px; height: 34px; font-size: 1.1rem; }
.stepper.sm span { min-width: 36px; text-align: center; font-weight: 700; }
.cline { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cline:last-of-type { border-bottom: 0; }
.cline img { width: 64px; height: 84px; object-fit: cover; border-radius: 10px; background: var(--line); flex: 0 0 auto; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; width: 84px; height: 110px; border-radius: 10px; overflow: hidden; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .x, .thumb .cover { position: absolute; top: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: .8rem; padding: 0; min-height: 0; }
.thumb .x { inset-inline-end: 4px; } .thumb .cover { inset-inline-start: 4px; }
.thumb .tag { top: auto; bottom: 4px; }
.badge { position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; font-style: normal; }
.tabbar a { position: relative; }
.tabbar { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
.pill.info { background: #dbeafe; color: #1e40af; }
@media (prefers-color-scheme: dark) { .pill.info { background: #1e3a5f; color: #bfdbfe; } }
.statusbtns { display: flex; flex-wrap: wrap; gap: 6px; }
a.tx { color: inherit; text-decoration: none; }
#unitseg { grid-template-columns: repeat(3, 1fr); display: grid; }
