:root {
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #1c5cab;
  --accent-soft: #e5eefa;
  --bar: #2a78d6;
  --bar-dim: #9ec5f4;
  --good: #0a7d0a;
  --bad: #c43b3a;
  --warn-bg: #fff4dc;
  --warn-text: #7a5200;
  --radius: 14px;
  --nav-h: 64px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #6da7ec;
    --accent-soft: #1b2b40;
    --bar: #3987e5;
    --bar-dim: #184f95;
    --good: #4cc24c;
    --bad: #e66767;
    --warn-bg: #3a2c0c;
    --warn-text: #f5c96a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
body.no-nav { padding-bottom: 0; }
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* الشريط العلوي */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }

/* شريط التنقل السفلي */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px;
}
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a { position: relative; }
.badge {
  position: absolute; top: 6px; left: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700;
}

/* التنبيهات */
.alert-item { display: flex; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); color: inherit; }
.alert-item:first-child { border-top: 0; }
.alert-item .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; background: var(--muted); }
.alert-item.high .dot { background: var(--bad); }
.alert-item.normal .dot { background: #e8a200; }
.alert-item .t { font-weight: 600; }
.alert-item.info .t { font-weight: 500; color: var(--text-2); }
.alert-item .b { font-size: 13px; color: var(--text-2); }
.alert-item .w { font-size: 12px; color: var(--muted); }
.alert-item.new .t::after { content: "جديد"; margin-inline-start: 6px; font-size: 11px; color: #fff; background: var(--accent); padding: 0 6px; border-radius: 6px; }
.day-head { font-size: 12px; color: var(--muted); font-weight: 600; margin: 14px 2px 4px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

.alert-item a.t { color: inherit; display: block; }
.alert-item.done { opacity: 0.75; }
.alert-item.done .dot { background: var(--good); }
.ackbtn { height: 34px; padding: 0 12px; margin-top: 8px; font-size: 13px; font-weight: 600; }
.acked { margin-top: 6px; font-size: 12px; color: var(--good); }
.linkbtn { border: 0; background: none; color: var(--accent); font-size: 12px; cursor: pointer; padding: 0 4px; }
.changes { margin-top: 6px; font-size: 13px; }
.changes summary { color: var(--accent); cursor: pointer; }
.changes ul { margin: 6px 0 0; padding-inline-start: 18px; color: var(--text-2); }
.changes li { margin: 2px 0; }

/* سطر آخر قراءة من البيان */
.syncbar { padding: 8px 14px; background: var(--card, #fff); border-bottom: 1px solid var(--line, #e3e6eb); font-size: 13px; color: var(--muted); }
.syncbar[hidden] { display: none; }
.syncbar .sb-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 900px; margin: 0 auto; }
.syncbar .sb-text { min-width: 0; }
.syncbar .sb-btn { flex: none; padding: 6px 14px; min-height: 36px; font-size: 13px; }
.syncbar .sb-err { max-width: 900px; margin: 6px auto 0; color: var(--warn-text); }
.sync { text-align: center; font-size: 13px; color: var(--muted); margin: 14px 4px 4px; }
.sync .stale { display: inline-block; padding: 8px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); font-weight: 600; }
.sync .stale small { font-weight: 400; }

/* الصلاحيات */
.perm { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.perm input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.perm span { display: flex; flex-direction: column; }
.perm small { color: var(--muted); font-size: 12px; }
#areas.dim { opacity: 0.45; pointer-events: none; }
.perm-box { margin: 0 32px 10px 0; }

/* الصندوق: إغلاق الكاشير وجرد القاصة */
.who { font-size: 14px; color: var(--text-2); margin: 0 2px 10px; }
.money-in { font-size: 24px !important; font-weight: 700; height: 54px !important; direction: ltr; text-align: right; }
.cash-total { display: flex; justify-content: space-between; align-items: baseline; margin: 12px 2px; font-size: 15px; color: var(--text-2); }
.cash-total b { font-size: 22px; color: var(--text); }
.result { border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 2px solid; }
.result .r-title { font-size: 22px; font-weight: 800; }
.result .r-amt { font-size: 30px; font-weight: 800; margin-top: 2px; }
.result .r-sub { font-size: 13px; margin-top: 8px; color: var(--text-2); }
.result.ok { border-color: var(--good); color: var(--good); }
.result.over { border-color: #e8a200; color: var(--warn-text); background: var(--warn-bg); }
.result.short { border-color: var(--bad); color: var(--bad); }
/* زر نسخ باركود المادة + رسالة النسخ */
.item-cell { display: inline-flex; align-items: center; gap: 6px; }
.bc-btn {
  flex: none; display: inline-grid; place-items: center; width: 30px; height: 26px; padding: 0;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--text-2); cursor: pointer;
}
.bc-btn svg { width: 18px; height: 16px; stroke-width: 1.6; stroke-linecap: butt; }
.bc-btn:hover { border-color: var(--accent); color: var(--accent); }
.bc-btn.done { background: var(--good); border-color: var(--good); color: #fff; }
.bc-line { display: flex; align-items: center; gap: 6px; margin: 4px 0 2px; font-size: 12px; color: var(--muted); }
.toast {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-size: 14px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.2); text-align: center;
}

/* شاشة الاختيار: إدخال الكاشير / جرد القاصة */
.cash-hub { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.hub-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 22px 10px 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.hub-tile:hover, .hub-tile:focus-visible { border-color: var(--accent); }
.hub-tile svg { width: 52px; height: 52px; stroke: var(--accent); stroke-width: 1.6; margin-bottom: 6px; }
.hub-tile b { font-size: 17px; }
.hub-tile small { color: var(--muted); font-size: 12px; }
.hub-state { margin-top: 6px; font-size: 12px; padding: 2px 10px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.hub-state.done { color: var(--good); }
.hub-state.warn { background: var(--warn-bg); color: var(--warn-text); }

/* سحوبات القاصة */
#wf { margin-bottom: 10px; }
.w-item { align-items: flex-start; }
.w-item .sub { font-size: 12px; color: var(--muted); }
.w-end { flex: none; height: 36px; padding: 0 14px; font-size: 13px; }
.w-close { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.w-close .btn { height: 36px; padding: 0 12px; font-size: 13px; }

/* تعديل/حذف إدخال الكاشير أو الجرد (المدير) */
.btn.e-edit { height: 32px; padding: 0 10px; font-size: 12px; white-space: nowrap; }
.btn.ghost.e-del { color: var(--bad); }
.btn.e-del-ok { background: var(--bad); }
#entry-edit .actions { flex-wrap: wrap; }

/* جرد القاصة: كتابة المبلغ أو حسب الفئات */
.mode-seg { margin-bottom: 12px; }
form[data-mode="amount"] .m-notes, form[data-mode="notes"] .m-amount { display: none; }
.notes-head, .note-row { display: grid; grid-template-columns: 90px 1fr 110px; gap: 10px; align-items: center; }
.notes-head { font-size: 12px; color: var(--muted); padding: 0 2px 4px; }
.notes-head span:last-child, .note-row .ns { text-align: left; }
.note-row { padding: 5px 0; border-top: 1px solid var(--line); cursor: text; }
.note-row .nd { font-weight: 700; font-size: 17px; text-align: right; }
.note-row .ns { color: var(--text-2); }
.count-in {
  width: 100%; height: 46px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  font-size: 20px; font-weight: 700; direction: ltr; text-align: center; appearance: none;
}
.count-in:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* آلة حاسبة جانبية: على الحاسوب فقط */
.calc { display: none; }
@media (min-width: 900px) {
  .cash-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
  .calc { display: block; position: sticky; top: 72px; outline: none; }
  .calc:focus-within, .calc:focus { border-color: var(--accent); }
}
.calc-tape { list-style: none; margin: 0 0 6px; padding: 0 4px; height: 132px; overflow-y: auto; font-size: 14px; color: var(--text-2); border-bottom: 1px dashed var(--line); }
.calc-tape li { display: flex; justify-content: space-between; padding: 1px 0; }
.calc-screen { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 4px 10px; }
.calc-op { font-size: 20px; color: var(--muted); }
.calc-screen .num { font-size: 28px; font-weight: 800; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; direction: ltr; }
.calc-keys button {
  height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  font-size: 19px; font-weight: 600; cursor: pointer;
}
.calc-keys button:active { transform: scale(0.97); }
.calc-keys button.fn { color: var(--accent); }
.calc-keys button.eq { background: var(--accent); border-color: var(--accent); color: #fff; }
.calc-keys button[data-k="C"] { font-size: 14px; color: var(--bad); }
.kv { list-style: none; margin: 0; padding: 0; }
.kv li { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.kv li:first-child { border-top: 0; }

main { max-width: 960px; margin: 0 auto; padding: 12px 16px 24px; }

/* حاسبة التسعير */
.price-page { max-width: 640px; margin: 0 auto; }
.kind-seg .chip { flex: 1; font-size: 15px; padding: 9px 12px; }
.quote { border: 2px solid var(--good); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: var(--surface); }
.q-label { font-size: 12px; color: var(--muted); }
.q-say { font-size: 24px; font-weight: 800; color: var(--good); margin: 2px 0 6px; }
.q-lines { font-size: 13px; color: var(--text-2); }
.q-suggest { border: 2px solid #e8a200; background: var(--warn-bg); }
.q-suggest h2 { color: var(--warn-text); }
.q-sg-say { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.sheet-prev { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.sheet-prev svg { flex: none; stroke-width: 0.8; }
.sheet-prev .paper { fill: var(--surface-2); stroke: var(--line); }
.sheet-prev .use { fill: var(--accent-soft); stroke: var(--accent); }
.sheet-prev .free { fill: none; stroke: var(--muted); stroke-dasharray: 2 2; }

/* بطاقات */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 a, .card h2 small { font-size: 13px; font-weight: 500; color: var(--muted); }
.card h2 a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* الرقم الرئيسي */
.hero .label { color: var(--text-2); font-size: 14px; }
.hero .big { font-size: 34px; font-weight: 800; line-height: 1.15; margin: 4px 0; letter-spacing: -0.5px; }
.hero .big small { font-size: 15px; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.hero .row { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-2); font-size: 14px; }
.delta { font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid2 .card { margin: 0; }
.stat .label { color: var(--text-2); font-size: 13px; }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
a.stat { display: block; color: inherit; }

.split { display: flex; gap: 10px; }
.split > div { flex: 1; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.split .label { font-size: 12px; color: var(--muted); }
.split .value { font-weight: 700; }

/* قوائم */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; padding-top: 2px; }
.list .grow { flex: 1; min-width: 0; }
.list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 12px; color: var(--muted); }
.list .amt { font-weight: 600; white-space: nowrap; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--bar); border-radius: 3px; }

.alert {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; margin-bottom: 12px;
  border-radius: var(--radius); background: var(--warn-bg); color: var(--warn-text); font-size: 14px;
}
.alert svg { flex: none; }
.alert b { font-weight: 700; }

/* الرسم */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; stroke: none; }
.chart .bar { fill: var(--bar); }
.chart .bar.dim { fill: var(--bar-dim); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; stroke: none; }
.chart .hbar-label { fill: var(--text-2); font-size: 12px; }
.tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 8px;
  font-size: 13px; line-height: 1.4; white-space: nowrap; transform: translate(50%, -110%);
}

/* قائمة التقارير */
.group-title { margin: 18px 4px 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.group-title:first-child { margin-top: 4px; }
.rlink {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px;
}
.rlink .t { font-weight: 600; }
.rlink .d { font-size: 13px; color: var(--muted); }
.rlink .grow { flex: 1; }
.rlink .chev { color: var(--muted); transform: scaleX(-1); }

/* فلاتر */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; height: 42px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); appearance: none; -webkit-appearance: none;
}
.field input[type="date"] { direction: ltr; text-align: right; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px;
  padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 18px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1; }
.filter-toggle { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.filter-toggle .summary { font-size: 13px; color: var(--text-2); }
.filter-btn { flex: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); }
.filter-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* الجدول */
.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.totals div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.totals .label { font-size: 12px; color: var(--muted); }
.totals .value { font-weight: 700; }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; white-space: nowrap; border-bottom: 1px solid var(--line); text-align: right; }
th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-weight: 600; color: var(--text-2); }
td.n, th.n { text-align: left; font-variant-numeric: tabular-nums; }
td.neg { color: var(--bad); }
th:first-child, td:first-child { position: sticky; right: 0; z-index: 1; background: var(--surface); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
th:first-child { z-index: 3; background: var(--surface-2); }
tfoot td { position: sticky; bottom: 0; background: var(--surface-2); font-weight: 700; border-bottom: 0; }
tfoot td:first-child { background: var(--surface-2); }
tbody tr:active td { background: var(--accent-soft); }
.note { font-size: 13px; color: var(--muted); margin: 8px 2px 0; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.error { background: var(--warn-bg); color: var(--warn-text); padding: 12px 14px; border-radius: 12px; }
.loading { text-align: center; padding: 40px 0; color: var(--muted); }
.loading::before {
  content: ""; display: block; width: 28px; height: 28px; margin: 0 auto 10px;
  border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite;
}

/* الدخول */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: 100%; max-width: 360px; }
.login .logo { width: 64px; height: 64px; margin: 0 auto 12px; display: block; border-radius: 16px; }
.login h1 { text-align: center; margin: 0 0 4px; font-size: 22px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 20px; }
.login .field { margin-bottom: 12px; }
.login .error { margin-bottom: 12px; }

.print-head { display: none; }

@media (min-width: 720px) {
  .grid2.wide { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: repeat(4, 1fr); }
}

/* الطباعة / PDF */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; color: #000; padding: 0; font-size: 11px; }
  .top, .tabs, .no-print, .tip { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; box-shadow: none; background: #fff; }
  .print-head { display: block; margin-bottom: 8px; }
  .print-head h1 { font-size: 18px; margin: 0; }
  .print-head div { color: #444; }
  .table-wrap { overflow: visible; max-height: none; border: 0; }
  table { font-size: 10px; }
  th, td { padding: 4px 6px; border-bottom: 1px solid #ccc; white-space: normal; }
  th, td:first-child, th:first-child, tfoot td { position: static; background: #fff !important; color: #000; }
  thead { display: table-header-group; }
  tfoot { display: table-row-group; }
  .chart { display: none; }
  .totals div { background: #fff; border: 1px solid #ccc; }
}
