:root {
  --bg: #f4f6f8; --card: #fff; --text: #1a2230; --muted: #5d6779; --line: #e2e6eb;
  --pri: #0f6cbd; --pri-ink: #fff; --ok: #1a7f4b; --warn: #8a5300; --bad: #c4314b; --info: #5b5fc7; --on: #fff;
  --war: #0f6cbd; --cash: #1a7f4b; --link: #7a3fc4;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #12161c; --card: #1b2129; --text: #e8ecf1; --muted: #a3adbb; --line: #2a323d;
    --pri: #4ea1f3; --pri-ink: #0b1320; --ok: #3fb97a; --warn: #e3a33b; --bad: #ef6b81; --info: #9a9df0; --on: #0b1320;
    --war: #4ea1f3; --cash: #3fb97a; --link: #b78af0; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #12161c; --card: #1b2129; --text: #e8ecf1; --muted: #a3adbb; --line: #2a323d;
  --pri: #4ea1f3; --pri-ink: #0b1320; --ok: #3fb97a; --warn: #e3a33b; --bad: #ef6b81; --info: #9a9df0; --on: #0b1320;
  --war: #4ea1f3; --cash: #3fb97a; --link: #b78af0; color-scheme: dark; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; background: var(--bg); color: var(--text);
  line-height: 1.5; font-size: 16px; -webkit-tap-highlight-color: transparent; }
a { color: var(--pri); }
:focus-visible { outline: 3px solid var(--pri); outline-offset: 2px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
small { font-size: 14px; color: var(--muted); }

/* ===== الهيدر ===== */
header.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-block: calc(10px + env(safe-area-inset-top, 0px)) 10px; padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px)); background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: inherit; text-decoration: none; }
.brand i { font-style: normal; background: var(--pri); color: var(--pri-ink); border-radius: 8px; padding: 1px 8px; font-size: 14px; letter-spacing: .5px; }
.who { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.icon-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; min-height: 40px; min-width: 40px; padding: 0 8px;
  border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--bg); color: var(--text); }
.demo-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 16px; font-size: 13px;
  background: color-mix(in srgb, var(--warn) 14%, var(--card)); color: var(--warn); }
.demo-bar button { background: none; border: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; padding: 4px; }

main { max-width: 640px; margin: 0 auto; padding-block: 16px calc(40px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
main.wide { max-width: 1000px; }
h2 { font-size: 21px; margin: 4px 0 14px; }
h3 { font-size: 16px; margin: 24px 0 10px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.center { text-align: center; }

/* ===== الأزرار والحقول ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px; border: 1px solid transparent;
  border-radius: 12px; background: var(--pri); color: var(--pri-ink); font: inherit; font-weight: 600; font-size: 16px; cursor: pointer; text-decoration: none; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 64px; font-size: 19px; border-radius: 16px; }
.btn.ghost { background: transparent; color: var(--pri); border-color: var(--line); }
.btn.ok { background: var(--ok); color: var(--on); }
.btn.bad { background: var(--bad); color: var(--on); }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
label { display: block; margin-bottom: 14px; font-size: 15px; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; min-height: 48px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; font-size: 16px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.chip { min-height: 38px; padding: 6px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--pri); border-color: var(--pri); color: var(--pri-ink); font-weight: 600; }

/* ===== الدخول ===== */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { text-align: center; margin-bottom: 20px; }
.login .logo i { display: inline-block; font-style: normal; font-weight: 700; font-size: 28px; background: var(--pri); color: var(--pri-ink);
  border-radius: 14px; padding: 6px 18px; letter-spacing: 1px; }
.demo-users { display: grid; gap: 8px; }

/* ===== الفني: المسح ===== */
#reader { width: 100%; max-width: 420px; margin: 0 auto 12px; border-radius: 16px; overflow: hidden; background: #000; }
#reader video { display: block; width: 100% !important; }
.scan-hero { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 180px;
  border: 0; border-radius: 20px; background: var(--pri); color: var(--pri-ink); font: inherit; font-size: 22px; font-weight: 700; cursor: pointer; }
.scan-hero span { font-size: 56px; line-height: 1; }
.code-input { display: flex; align-items: stretch; direction: ltr; margin-top: 5px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); overflow: hidden; }
.code-input b { display: flex; align-items: center; padding: 0 4px 0 14px; font-size: 18px; color: var(--muted); }
.code-input input { margin: 0; border: 0; border-radius: 0; background: transparent; font-size: 18px; letter-spacing: 1px; text-transform: uppercase; }
.code-input input:focus { outline: none; }
.code-input:focus-within { outline: 3px solid var(--pri); outline-offset: 1px; }
.manual-row { display: flex; gap: 8px; align-items: flex-end; }
.manual-row label { flex: 1; margin: 0; }
.manual-row .btn { flex-shrink: 0; }
.demo-codes { margin-top: 12px; font-size: 13px; color: var(--warn); }
.demo-codes .chip { font-size: 13px; min-height: 32px; padding: 4px 10px; direction: ltr; }
.torch { position: relative; }

/* ===== بطاقة المعدة ===== */
.mcode { font-size: 26px; font-weight: 700; letter-spacing: 1px; direction: ltr; text-align: end; }
.wbanner { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; margin: 12px 0; font-weight: 700; font-size: 18px; }
.wbanner span { font-size: 28px; }
.wbanner small { display: block; font-weight: 400; font-size: 14px; color: inherit; opacity: .85; }
.wbanner.active { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.wbanner.expired, .wbanner.cancelled { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad); }
.wbanner.none { background: var(--bg); color: var(--muted); }

/* ===== الخيارات الثلاثة ===== */
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 4px; }
.choice { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 110px; padding: 10px 4px;
  border: 2px solid var(--c); border-radius: 16px; background: var(--card); color: var(--c); font: inherit; font-size: 18px; font-weight: 700; cursor: pointer; }
.choice span { font-size: 34px; line-height: 1; }
.choice small { font-size: 12px; font-weight: 400; color: var(--muted); }
.choice.on { background: var(--c); color: var(--card); }
.choice.on small { color: var(--card); }
.choice:disabled { border-style: dashed; opacity: .4; cursor: not-allowed; }
.choice.war, .t-warranty { --c: var(--war); }
.choice.cash, .t-cash { --c: var(--cash); }
.choice.link, .t-link { --c: var(--link); }

/* ===== الصور ===== */
.photo-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 64px; border: 2px dashed var(--line);
  border-radius: 14px; background: var(--bg); color: var(--text); font: inherit; font-size: 17px; font-weight: 600; cursor: pointer; }
.photo-btn.req { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 4px; inset-inline-start: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0;
  background: rgb(0 0 0 / .6); color: #fff; font-size: 15px; cursor: pointer; }
.amount { display: flex; align-items: stretch; margin-top: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); overflow: hidden; }
.amount input { margin: 0; border: 0; border-radius: 0; background: transparent; font-size: 22px; font-weight: 700; direction: ltr; text-align: end; }
.amount input:focus { outline: none; }
.amount:focus-within { outline: 3px solid var(--pri); outline-offset: 1px; }
.amount b { display: flex; align-items: center; padding: 0 14px; color: var(--muted); font-weight: 600; }

/* ===== تم الإرسال ===== */
.done { text-align: center; padding: 26px 14px; }
.done .big-ok { font-size: 64px; line-height: 1; }
.done h2 { margin: 10px 0 4px; }

/* ===== قوائم ===== */
.list { display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  color: inherit; text-decoration: none; }
a.item:hover { border-color: var(--pri); }
.item .ico { font-size: 22px; flex-shrink: 0; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--c, var(--muted)) 15%, transparent); color: var(--c, var(--muted)); }
.pill.ok { --c: var(--ok); } .pill.bad { --c: var(--bad); } .pill.warn { --c: var(--warn); } .pill.info { --c: var(--info); }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; }

/* ===== المدير ===== */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 6px; min-height: 140px; padding: 18px 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; color: inherit; text-decoration: none; }
.tile:hover { border-color: var(--pri); }
.tile span { font-size: 36px; line-height: 1; }
.tile b { font-size: 18px; margin-top: auto; }
.tile small { font-size: 13px; }
.strip { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 12px; border-radius: 14px; text-decoration: none;
  color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--card)); border: 1px solid color-mix(in srgb, var(--c) 30%, transparent); font-weight: 600; }
.strip.link { --c: var(--link); } .strip.bad { --c: var(--bad); }
.strip .n { margin-inline-start: auto; min-width: 32px; height: 32px; padding: 0 8px; border-radius: 99px; background: var(--c); color: var(--card);
  display: flex; align-items: center; justify-content: center; font-weight: 700; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 10px; color: var(--muted); text-decoration: none; font-size: 15px; min-height: 40px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.filters label { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat em { display: block; font-style: normal; font-size: 14px; color: var(--c, var(--text)); font-weight: 600; }
.stat > span { font-size: 14px; color: var(--muted); }
.stat.t-warranty b, .stat.t-cash b, .stat.t-link b, .stat.t-unpaid b { color: var(--c); }
.t-unpaid { --c: var(--bad); }
.stats.money { margin-top: -4px; }
.stats.money .stat b { font-size: 21px; }
.pdf-sheet.wide { width: 277mm; }
.pdf-sheet h3 { color: #333; margin: 5mm 0 2mm; font-size: 12pt; }
.pdf-sheet .tbl-wrap { border: 0; overflow: visible; }
.export { display: flex; gap: 8px; flex-wrap: wrap; }
.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; background: var(--bg); }
td.n, th.n { text-align: end; font-variant-numeric: tabular-nums; }
td.notes { white-space: pre-line; min-width: 160px; max-width: 280px; font-size: 13px; color: var(--muted); }
tr.cancelled td { opacity: .55; }
.photos-mini { display: flex; gap: 6px; }
.photos-mini img { width: 44px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.search { position: relative; }
.search input { padding-inline-start: 40px; }
.search::before { content: '🔍'; position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); font-size: 16px; margin-top: 2px; }
.viewer { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / .9); display: flex; align-items: center; justify-content: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ===== الملصقات ===== */
.stickers { display: flex; flex-wrap: wrap; gap: 4mm; }
.sticker { width: 60mm; height: 34mm; display: flex; align-items: center; gap: 3mm; padding: 2.5mm 3mm; background: #fff; color: #000;
  border: 1px dashed #999; border-radius: 2mm; break-inside: avoid; font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; }
.sticker svg { width: 27mm; height: 27mm; flex-shrink: 0; display: block; }
.sticker .s-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1mm; }
.sticker .s-brand { font-size: 8pt; font-weight: 700; letter-spacing: 1px; }
.sticker .s-code { font-size: 11pt; font-weight: 700; direction: ltr; text-align: right; white-space: nowrap; overflow: hidden; }
.sticker .s-name { font-size: 7.5pt; line-height: 1.3; overflow: hidden; }

/* ===== نوافذ وتنبيهات ===== */
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); inset-inline: 16px; max-width: 480px; margin: auto; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 16px; }
.toast.err { background: var(--bad); color: #fff; }
.toast .x { background: none; border: 0; color: inherit; font-size: 20px; min-width: 40px; min-height: 40px; cursor: pointer; }
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgb(0 0 0 / .45); }
.modal-box { width: 100%; max-width: 400px; background: var(--card); color: var(--text); border-radius: 16px; padding: 18px; box-shadow: 0 10px 40px rgb(0 0 0 / .3); }
.modal-box p { margin: 0 0 8px; font-size: 17px; }
.modal-box .actions .btn { flex: 1; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2s; } }

/* ===== PDF (دايماً أبيض) ===== */
.pdf-wrap { position: fixed; top: 0; left: -10000px; }
.pdf-sheet { width: 190mm; padding: 6mm; background: #fff; color: #111; font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; font-size: 11pt; }
.pdf-sheet h1 { font-size: 16pt; margin: 0 0 2mm; }
.pdf-sheet .sub { color: #555; margin-bottom: 5mm; }
.pdf-sheet .stats { grid-template-columns: repeat(4, 1fr); gap: 3mm; margin: 0 0 5mm; }
.pdf-sheet .stat { border-color: #ddd; background: #fff; padding: 3mm; }
.pdf-sheet .stat b { font-size: 15pt; color: #111 !important; }
.pdf-sheet .stat > span, .pdf-sheet .stat em { color: #555; font-size: 9pt; }
.pdf-sheet table { font-size: 9pt; }
.pdf-sheet th { background: #f1f3f5; color: #333; position: static; }
.pdf-sheet th, .pdf-sheet td { border-bottom: 1px solid #ddd; padding: 2mm 2.5mm; }
.pdf-sheet tfoot td { background: #f1f3f5; }
.pdf-sheet a { color: inherit; text-decoration: none; }

@media print {
  header.top, .demo-bar, .noprint { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .sticker { border-color: #ccc; }
  @page { margin: 8mm; }
}
@media (max-width: 380px) {
  .choice { font-size: 16px; min-height: 100px; }
  .tile { min-height: 124px; padding: 14px; }
  .split, .filters { grid-template-columns: 1fr; }
}
