:root {
  --primary: #ea580c; --primary-d: #c2410c; --primary-l: #ffedd5;
  --ink: #0f172a; --ink2: #475569; --mute: #94a3b8; --line: #e2e8f0; --bg: #f1f5f9; --card: #ffffff;
  --side: #111827; --side2: #1f2937; --ok: #16a34a; --ok-l: #dcfce7; --bad: #dc2626; --bad-l: #fee2e2; --warn: #d97706; --warn-l: #fef3c7; --info: #2563eb; --info-l: #dbeafe;
  --r: 12px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-d); text-decoration: none; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--ink2); } .small { font-size: 12.5px; } .mono { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: embed; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }

/* layout */
#app { display: flex; min-height: 100vh; }
.side { width: 248px; background: var(--side); color: #e5e7eb; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; overflow-y: auto; transition: transform .2s; z-index: 30; }
.brand { padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; color: #fff; letter-spacing: .3px; }
.brand .logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), #f59e0b); display: grid; place-items: center; font-size: 19px; }
.nav { padding: 6px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #6b7280; padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: #cbd5e1; font-weight: 500; }
.nav a:hover { background: var(--side2); color: #fff; }
.nav a.on { background: var(--primary); color: #fff; }
.nav a .ic { width: 20px; text-align: center; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 10px 22px; position: sticky; top: 0; z-index: 20; }
.top .sp { flex: 1; }
.top select { width: auto; min-width: 150px; }
.burger { display: none; }
.content { padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-h { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-h h1 { font-size: 22px; flex: 1; min-width: 160px; }

/* cards & grid */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card h3 { font-size: 16px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; border-inline-start: 4px solid var(--primary); }
.stat .v { font-size: 26px; font-weight: 800; letter-spacing: -.5px; } .stat .l { color: var(--ink2); font-size: 13px; }
.stat.ok { border-color: var(--ok); } .stat.bad { border-color: var(--bad); } .stat.info { border-color: var(--info); } .stat.warn { border-color: var(--warn); }
.stat a { font-size: 12px; margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.sp { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; }

/* forms */
label.f { display: block; font-size: 13px; color: var(--ink2); font-weight: 600; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], input[type=tel], input[type=email], input[type=time], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(234,88,12,.15); }
textarea { resize: vertical; min-height: 64px; }
.fg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.fg .full { grid-column: 1 / -1; }
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; } .chk input { width: 18px; height: 18px; accent-color: var(--primary); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.hint { font-size: 12px; color: var(--mute); margin-top: 3px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg label { padding: 7px 16px; cursor: pointer; background: #fff; font-weight: 600; }
.seg input { display: none; } .seg input:checked + span { color: #fff; } .seg label:has(input:checked) { background: var(--primary); color: #fff; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px; border: 1px solid transparent; background: var(--primary); color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, transform .05s; }
.btn:hover { background: var(--primary-d); } .btn:active { transform: translateY(1px); }
.btn.sec { background: #fff; color: var(--ink); border-color: var(--line); } .btn.sec:hover { background: #f8fafc; }
.btn.bad { background: var(--bad); } .btn.bad:hover { background: #b91c1c; }
.btn.ok { background: var(--ok); } .btn.ok:hover { background: #15803d; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px 8px; border-radius: 8px; font-size: 18px; } .icon-btn:hover { background: var(--bg); }

/* tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th { background: #f8fafc; font-size: 12.5px; color: var(--ink2); text-align: start; padding: 10px 12px; white-space: nowrap; border-bottom: 1px solid var(--line); }
td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: #fff7ed; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--mute); padding: 30px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge.ok { background: var(--ok-l); color: #166534; } .badge.bad { background: var(--bad-l); color: #991b1b; } .badge.warn { background: var(--warn-l); color: #92400e; } .badge.info { background: var(--info-l); color: #1e40af; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-l); color: var(--primary-d); display: grid; place-items: center; font-weight: 800; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; } .avatar.lg { width: 84px; height: 84px; font-size: 30px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 16px; cursor: pointer; font-weight: 600; color: var(--ink2); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs button.on { color: var(--primary-d); border-color: var(--primary); }

/* modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 14px; overflow-y: auto; z-index: 100; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .15s ease-out; }
.modal.wide { max-width: 860px; } .modal.xl { max-width: 980px; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal header { display: flex; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal header h3 { flex: 1; font-size: 17px; margin: 0; }
.modal .body { padding: 18px 20px; } .modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#toasts { position: fixed; bottom: 18px; inset-inline-end: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: pop .15s; }
.toast.ok { background: #166534; } .toast.bad { background: #991b1b; }
.err { background: var(--bad-l); color: #991b1b; padding: 8px 12px; border-radius: 9px; margin-bottom: 10px; font-size: 14px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 20%, #fb923c33, transparent 40%), linear-gradient(135deg, #0f172a, #1e293b); padding: 20px; }
.login { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 32px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.login .brand { color: var(--ink); padding: 0 0 18px; justify-content: center; font-size: 26px; }

/* reception */
.scan-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.scan-input { font-size: 22px; padding: 16px 18px; text-align: center; letter-spacing: 2px; border: 2px solid var(--primary); border-radius: 14px; direction: ltr; }
.result { border-radius: 16px; padding: 26px; text-align: center; margin-top: 16px; color: #fff; min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.result.ok { background: linear-gradient(135deg, #16a34a, #22c55e); } .result.bad { background: linear-gradient(135deg, #dc2626, #ef4444); } .result.idle { background: #e2e8f0; color: var(--ink2); }
.result .big { font-size: 34px; font-weight: 800; } .result .nm { font-size: 24px; font-weight: 700; }
.result .avatar { width: 96px; height: 96px; font-size: 36px; background: rgba(255,255,255,.25); color: #fff; border: 3px solid rgba(255,255,255,.6); }
.feed { display: flex; flex-direction: column; max-height: 520px; overflow-y: auto; }
.feed .it { display: flex; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid #f1f5f9; }
.feed .it .t { margin-inline-start: auto; color: var(--mute); font-size: 12px; direction: ltr; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; } .dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

/* charts */
.chart { width: 100%; height: 180px; } .chart text { font-size: 10px; fill: var(--mute); } .chart .bar { fill: var(--primary); } .chart .bar:hover { fill: var(--primary-d); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink2); }

/* invoice / card print */
.invoice { background: #fff; color: #000; padding: 10px 4px; font-size: 13px; }
.invoice .ih { display: flex; justify-content: space-between; gap: 14px; border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 10px; }
.invoice .it { text-align: center; font-size: 18px; font-weight: 800; margin: 8px 0; }
.invoice table { font-size: 12.5px; } .invoice th { background: #f1f5f9; color: #000; border: 1px solid #cbd5e1; } .invoice td { border: 1px solid #e2e8f0; }
.invoice .tot { margin-inline-start: auto; width: 320px; max-width: 100%; margin-top: 10px; } .invoice .tot div { display: flex; justify-content: space-between; padding: 4px 8px; border-bottom: 1px solid #e2e8f0; } .invoice .tot .gt { font-weight: 800; font-size: 15px; background: #f1f5f9; }
.invoice .qrbox { display: flex; justify-content: center; margin-top: 14px; } .invoice .qrbox svg { width: 150px; height: 150px; }
.invoice .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; margin: 8px 0; }
.mcard { width: 340px; border-radius: 16px; background: linear-gradient(135deg, #111827, #1f2937 60%, #ea580c); color: #fff; padding: 18px; margin: 0 auto; box-shadow: var(--shadow); }
.mcard .qrw { background: #fff; border-radius: 10px; padding: 6px; width: 140px; margin: 12px auto 6px; } .mcard .qrw svg { width: 100%; height: auto; display: block; }
#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block !important; }
  body { background: #fff; } .invoice, .mcard { box-shadow: none; }
}

@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(2, 1fr); } .scan-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; transform: translateX(-105%); } [dir=rtl] .side { transform: translateX(105%); }
  .side.open { transform: none; } .burger { display: inline-block; } .content { padding: 14px; } .top { padding: 8px 12px; }
  .fg, .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: 1fr 1fr; } .top select { min-width: 110px; max-width: 150px; }
  .stat .v { font-size: 21px; }
}

.warnbox { background: var(--warn-l); color: #92400e; padding: 8px 12px; border-radius: 9px; margin-bottom: 10px; font-size: 14px; }

@media (max-width: 860px) {
  .side { visibility: hidden; transition: transform .2s, visibility 0s linear .2s; }
  .side.open { visibility: visible; transition: transform .2s; }
  .uinfo { display: none; }
  .top { gap: 6px; } .top select { min-width: 0; max-width: 130px; }
  .page-h h1 { min-width: 0; }
}
.invoice th, .invoice td { padding: 6px 8px; font-size: 12px; }
.invoice .tbl-wrap { overflow-x: auto; }

.invoice { position: relative; }
.invoice .copymark { position: absolute; top: 6px; inset-inline-end: 6px; border: 2px solid #b91c1c; color: #b91c1c; font-weight: 800; padding: 2px 12px; border-radius: 6px; transform: rotate(-6deg); font-size: 15px; }
.invoice .subbox { border: 1px solid #cbd5e1; border-radius: 8px; padding: 6px 10px; margin: 8px 0; background: #f8fafc; } .invoice .subbox .stt { font-weight: 800; margin-bottom: 2px; }
.invoice .terms { margin-top: 14px; border-top: 1px dashed #94a3b8; padding-top: 8px; font-size: 11.5px; } .invoice .terms .tx { margin-top: 4px; line-height: 1.6; }
.invoice .sign { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 20px; margin-top: 26px; font-size: 12px; text-align: center; } .invoice .sign .sl { border-bottom: 1px solid #000; height: 38px; margin-bottom: 4px; }
@media print { @page { size: A4; margin: 12mm; } .invoice { font-size: 12px; } .invoice, .invoice * { break-inside: avoid; } }
@media print { .invoice .qrbox svg { width: 105px; height: 105px; } .invoice .qrbox { margin-top: 6px; } .invoice .terms { font-size: 10px; margin-top: 8px; } .invoice .terms .tx { margin-top: 2px; line-height: 1.45; } .invoice .sign { margin-top: 14px; } .invoice .sign .sl { height: 30px; } .invoice td, .invoice th { padding: 4px 6px; } .invoice .tbl-wrap { overflow: visible; } .invoice table { font-size: 11px; } }
.rpt .rh { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 8px; } .rpt table { font-size: 12px; width: 100%; } .rpt th { background: #f1f5f9; border: 1px solid #cbd5e1; } .rpt td { border: 1px solid #e2e8f0; padding: 5px 8px; }

.invoice .qrbox { display: flex; justify-content: center; gap: 28px; } .invoice .qrbox figure { margin: 0; text-align: center; } .invoice .qrbox figcaption { font-size: 10.5px; margin-top: 2px; }
.invoice .ih { align-items: center; }
.okbox { background: #dcfce7; color: #166534; padding: 8px 12px; border-radius: 9px; margin-bottom: 10px; font-size: 14px; }
