/* دفتر المحل — الأنماط. خطوط النظام فقط (لا خطوط من الإنترنت). */
:root {
  --ink: #23396b;
  --ink-2: #3d5a9a;
  --paper: #f7f4ec;
  --card: #ffffff;
  --line: #e2dccd;
  --text: #1d2433;
  --muted: #6a7184;
  --good: #1f7a4c;
  --good-bg: #e5f4ec;
  --bad: #b3362b;
  --bad-bg: #fbe9e6;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --gold: #c98a2b;
  --radius: 14px;
  --font: "Noto Naskh Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, "Geeza Pro", "Arial", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.55;
  background: var(--paper); color: var(--text);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--ink-2); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.02rem; }
small, .muted { color: var(--muted); }
bdi { unicode-bidi: isolate; direction: ltr; }
[hidden] { display: none !important; }

/* ---------- الرأس والتنقل ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 12px; background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand img { border-radius: 8px; }
.brand strong { display: block; font-size: 1.05rem; }
.brand small { display: block; color: #c9d4ef; font-size: .72rem; direction: ltr; text-align: right; }
.status { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: .72rem; padding: 3px 8px; border-radius: 99px; background: rgba(255,255,255,.14); white-space: nowrap; }
.badge.ok { background: #2f7d55; }
.badge.off { background: #a23a2e; }
.badge.wait { background: #8a6a1f; }
.gear { color: #fff; text-decoration: none; font-size: .85rem; padding: 6px 8px; border-radius: 10px; background: rgba(255,255,255,.12); white-space: nowrap; }
.gear span { margin-inline-start: 2px; }
.demo-banner { background: #b3362b; color: #fff; padding: 8px 12px; font-weight: 600; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.demo-banner button { background: #fff; color: #b3362b; border: 0; border-radius: 8px; padding: 4px 10px; }

nav.bottom {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: grid; grid-template-columns: repeat(6, 1fr);
  background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 60px;
  text-decoration: none; color: var(--muted); font-size: .72rem; position: relative; text-align: center; line-height: 1.2;
}
nav.bottom a i { font-style: normal; font-size: 1.25rem; }
nav.bottom a.active { color: var(--ink); font-weight: 700; background: #eef2fb; }
nav.bottom b { position: absolute; top: 4px; inset-inline-start: 50%; transform: translateX(-90%); background: var(--bad); color: #fff; border-radius: 99px; font-size: .65rem; padding: 0 6px; }

main { max-width: 1100px; margin: 0 auto; padding: 14px 12px 24px; outline: none; }
.loading { text-align: center; color: var(--muted); padding: 40px; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-inline-start: 120px; }
  nav.bottom { top: 56px; bottom: 0; inset-inline-start: 0; inset-inline-end: auto; width: 120px; grid-template-columns: 1fr; grid-auto-rows: 72px; border-top: 0; border-inline-end: 1px solid var(--line); align-content: start; }
  nav.bottom a { font-size: .85rem; }
}

/* ---------- عناصر عامة ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.tight { padding: 10px 12px; }
.card.warn { background: var(--warn-bg); border-color: #f0d79a; }
.card.bad { background: var(--bad-bg); border-color: #f0bdb5; }
.card.good { background: var(--good-bg); border-color: #b9e0c9; }
.card.info { background: #eef2fb; border-color: #cfd9f0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid2 > *, .grid3 > * { min-width: 0; }
.fld input, .fld select { min-width: 0; max-width: 100%; }
@media (max-width: 640px) { .grid3 { grid-template-columns: 1fr; } .grid2.keep { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .grid2:not(.keep) { grid-template-columns: minmax(0, 1fr); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 8px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: #fff; cursor: pointer; text-decoration: none; color: var(--text);
  font-weight: 600; touch-action: manipulation;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.good { background: var(--good); color: #fff; border-color: var(--good); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 38px; padding: 4px 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; padding: 4px; min-height: 36px; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.quick button { min-height: 64px; border-radius: 14px; border: 1px solid var(--line); background: #fff; font-weight: 700; font-size: .92rem; cursor: pointer; padding: 6px; }
.quick button i { display: block; font-style: normal; font-size: 1.3rem; color: var(--ink-2); }
.quick button.photo { background: #eef2fb; border-color: #cfd9f0; }
@media (max-width: 380px) { .quick { grid-template-columns: repeat(2, 1fr); } }

/* ---------- المبالغ ---------- */
.money { white-space: nowrap; }
.money bdi { font-variant-numeric: tabular-nums; font-weight: 700; }
.money .u { font-size: .78em; color: var(--muted); font-weight: 400; }
.money.neg bdi { color: var(--bad); }
.dzd { display: block; font-size: .8rem; color: var(--muted); }
.big { font-size: 1.6rem; line-height: 1.2; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

.balances { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 760px) { .balances { grid-template-columns: 1fr; } }
.bal { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; border-top: 5px solid var(--ink); }
.bal.drawer { border-top-color: var(--gold); }
.bal.change { border-top-color: #6a8f5b; }
.bal h3 { display: flex; justify-content: space-between; align-items: baseline; }
.bal .code { font-size: 1.4rem; color: var(--ink); }
.bal dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; font-size: .86rem; }
.bal dt { color: var(--muted); }
.bal dd { margin: 0; text-align: left; }
.disc { margin-top: 8px; padding: 6px 8px; border-radius: 8px; font-size: .85rem; }
.disc.ok { background: var(--good-bg); color: var(--good); }
.disc.diff { background: var(--bad-bg); color: var(--bad); }

/* ---------- القوائم ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .main { flex: 1; min-width: 0; }
.item .amt { text-align: left; }
.item .tag { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 99px; background: #eef2fb; color: var(--ink); margin-inline-end: 4px; }
.tag.receipt { background: var(--good-bg); color: var(--good); }
.tag.expense { background: #fdeee0; color: #9a4b0d; }
.tag.withdrawal { background: #f2e9fb; color: #5c2f8a; }
.tag.supplier { background: #fbe9e6; color: #a03a2c; }
.tag.transfer { background: #e8eef9; color: var(--ink); }
.tag.photo { background: #fff3d6; color: var(--warn); }
.item .acts { display: flex; gap: 4px; }
.daygroup > h3 { position: sticky; top: 52px; background: var(--paper); padding: 6px 0; margin: 0; z-index: 2; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { background: #f1ede2; font-weight: 700; }
td.num, th.num { text-align: left; white-space: nowrap; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
tfoot td { font-weight: 700; background: #faf8f2; }

/* ---------- النماذج ---------- */
.fld { display: block; margin-bottom: 12px; }
.fld > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
.fld input, .fld select, .fld textarea, .inp {
  width: 100%; min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 1px solid #cfc7b4; background: #fff;
}
.fld textarea { min-height: 80px; }
.fld input:focus, .fld select:focus, .fld textarea:focus, .inp:focus { outline: 3px solid #bcd0f5; border-color: var(--ink-2); }
.fld .hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.amtbox { display: flex; gap: 6px; }
.amtbox input { flex: 1; font-size: 1.25rem; font-weight: 700; direction: ltr; text-align: left; }
.amtbox select { width: auto; flex: 0 0 auto; font-size: .9rem; }
.amt-prev { margin-top: 5px; font-size: .88rem; padding: 6px 10px; border-radius: 10px; background: #f3f1ea; min-height: 34px; }
.amt-prev.ok { background: var(--good-bg); color: #164e33; }
.amt-prev.err { background: var(--bad-bg); color: var(--bad); }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid #cfc7b4; border-radius: 12px; overflow: hidden; background: #fff; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 10px 12px; min-height: 44px; cursor: pointer; border-inline-start: 1px solid #e6e0d1; font-size: .9rem; }
.seg label:first-child span { border-inline-start: 0; }
.seg input:checked + span { background: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid #bcd0f5; }
.errors { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.errors:empty { display: none; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button, .tabs a { min-height: 42px; padding: 6px 14px; border-radius: 99px; border: 1px solid var(--line); background: #fff; cursor: pointer; text-decoration: none; color: var(--text); display: inline-flex; align-items: center; }
.tabs .on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- النوافذ ---------- */
dialog { border: 0; padding: 0; border-radius: 18px; width: min(640px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); background: var(--paper); color: var(--text); }
dialog.wide { width: min(1000px, calc(100vw - 16px)); }
dialog::backdrop { background: rgba(20, 28, 48, .55); }
.modal-inner { padding: 16px; }
.modal-inner.small { max-width: 480px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; position: sticky; top: -16px; background: var(--paper); padding: 6px 0; z-index: 3; }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; margin-top: 14px; position: sticky; bottom: -16px; background: var(--paper); padding: 10px 0; flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 4px 10px; min-height: 44px; }
#toast { position: fixed; bottom: 90px; inset-inline: 12px; margin: auto; max-width: 520px; z-index: 50; }
#toast div { background: #1d2433; color: #fff; padding: 12px 16px; border-radius: 12px; margin-top: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.bad { background: var(--bad); }

/* ---------- الحضور ---------- */
.attrow { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.attrow .who { font-weight: 700; }
.attrow .who .code { display: inline-block; min-width: 30px; text-align: center; background: var(--ink); color: #fff; border-radius: 8px; margin-inline-end: 6px; }
.attrow .mins { width: 110px; min-height: 44px; }
.attrow.changed { background: #fffbea; }
.qual { display: inline-block; font-size: .72rem; border-radius: 99px; padding: 0 8px; background: var(--bad-bg); color: var(--bad); }
.qual.no { background: #eee; color: var(--muted); }

/* ---------- الصور والمراجعة ---------- */
.uploadbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.uploadbtns button { min-height: 96px; font-size: 1.05rem; }
.imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.imgcard { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.imgcard img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #ddd; }
.imgcard .body { padding: 8px; font-size: .82rem; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.chip { display: inline-block; font-size: .74rem; border-radius: 99px; padding: 1px 8px; background: #eee; }
.chip.ready { background: var(--warn-bg); color: var(--warn); }
.chip.done { background: var(--good-bg); color: var(--good); }
.chip.fail { background: var(--bad-bg); color: var(--bad); }
.chip.wait { background: #eef2fb; color: var(--ink); }

.review { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 900px) { .review { grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.1fr); align-items: start; } .review .pane-img { position: sticky; top: 64px; } }
.viewer { position: relative; overflow: auto; background: #2a2f3a; border-radius: 12px; height: 46vh; touch-action: pan-x pan-y; }
@media (min-width: 900px) { .viewer { height: calc(100dvh - 190px); } }
.viewer .stage { position: relative; transform-origin: 0 0; display: inline-block; }
.viewer .stage img, .viewer .stage canvas { display: block; max-width: none; }
.viewer .box { position: absolute; border: 3px solid #ffcc33; background: rgba(255, 204, 51, .18); border-radius: 4px; pointer-events: none; }
.viewer .box.sel { border-color: #ff4d4d; background: rgba(255, 77, 77, .18); box-shadow: 0 0 0 9999px rgba(0,0,0,.25); }
.viewer .cropbox { position: absolute; border: 2px dashed #fff; background: rgba(255,255,255,.12); pointer-events: none; }
.viewtools { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.ditem { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; border-inline-start: 6px solid #c5c0b2; }
.ditem.confirmed { border-inline-start-color: var(--good); }
.ditem.excluded { border-inline-start-color: #999; opacity: .62; }
.ditem.problem { border-inline-start-color: var(--bad); }
.ditem.selected { box-shadow: 0 0 0 3px #ff9c8f; }
.ditem .raw { font-size: .82rem; background: #f6f3ea; border-radius: 8px; padding: 4px 8px; margin: 6px 0; }
.ditem .fld { margin-bottom: 8px; }
.unc { outline: 3px solid #f2b705 !important; background: #fffbea !important; }
.unc-label { color: var(--warn); font-size: .76rem; font-weight: 700; }
.probs { color: var(--bad); font-size: .85rem; }
.dupw { color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 4px 8px; font-size: .84rem; margin-top: 6px; }
.postbar { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px; box-shadow: 0 -4px 16px rgba(0,0,0,.08); z-index: 5; }
@media (min-width: 900px) { .postbar { bottom: 8px; } }

/* ---------- الطباعة ---------- */
.print-head { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; padding: 0; font-size: 12pt; }
  .top, nav.bottom, .no-print, .demo-banner, #toast, .quick, .tabs, .btn, .linkbtn { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 1px solid #bbb; break-inside: avoid; }
  .print-head { display: block; border-bottom: 2px solid #000; margin-bottom: 10px; padding-bottom: 6px; }
  .daygroup > h3 { position: static; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
