:root {
  --bg: #f3f7fb;
  --surface: #fff;
  --text: #141a3a;
  --muted: #5f6886;
  --line: #dfe5ef;
  --primary: #01058c;
  --primary-dark: #000466;
  --sky: #4fc6fa;
  --cyan: #09c9fd;
  --accent: #e6f7fe;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #2f855a;
  --info: #2b6cb0;
  --radius: 10px;
  --nav-w: 220px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif; font-size: 15px; line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.08rem; margin: 0 0 .75rem; }
code, pre { background: #eef1f4; border-radius: 6px; padding: 2px 6px; font-size: .9em; }
pre { padding: 10px; overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: .87em; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: Consolas, "Courier New", monospace; letter-spacing: .3px; }
.pre { white-space: pre-wrap; }
.hidden { display: none !important; }
.grow { flex: 1 1 auto; }

/* Layout */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 56px; z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: #fff; color: var(--primary); border-bottom: 3px solid var(--cyan);
}
.topbar a { color: var(--primary); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; }
.brand img { height: 38px; }
.brand small { font-weight: 500; color: var(--muted); font-size: .8rem; }
.topbar .user { margin-inline-start: auto; display: flex; gap: 14px; align-items: center; font-size: .9rem; }
.menu-btn { display: none; background: none; border: 0; color: var(--primary); font-size: 1.5rem; cursor: pointer; }
.sidenav {
  position: fixed; top: 56px; bottom: 0; right: 0; width: var(--nav-w); z-index: 15;
  background: var(--surface); border-inline-start: 1px solid var(--line); padding: 12px 0; overflow-y: auto;
}
.sidenav a { display: block; padding: 10px 20px; color: var(--text); border-inline-start: 4px solid transparent; }
.sidenav a:hover { background: var(--accent); text-decoration: none; }
.sidenav a.active { background: var(--accent); border-inline-start-color: var(--cyan); font-weight: 700; color: var(--primary); }
.main { margin-top: 56px; margin-right: var(--nav-w); padding: 24px; max-width: 1400px; }
.main.bare { margin: 0 auto; padding-top: 40px; }

@media (max-width: 900px) {
  .menu-btn { display: block; }
  .sidenav { transform: translateX(100%); transition: transform .2s; box-shadow: 0 0 20px rgba(0,0,0,.15); }
  body.nav-open .sidenav { transform: none; }
  .main { margin-right: 0; padding: 16px; }
  .topbar .user span { display: none; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.narrow { max-width: 460px; margin-inline: auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.span2 { grid-column: span 2; }
@media (max-width: 900px) {
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .row { flex-wrap: wrap; }
}

.btn {
  display: inline-block; border: 1px solid var(--primary); background: var(--primary); color: #fff;
  padding: 8px 16px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-align: center;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.alt { background: #fff; color: var(--primary); }
.btn.alt:hover { background: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .87rem; }
.btn.big { font-size: 1.15rem; padding: 14px 22px; margin-bottom: 16px; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0 4px; }
.link.danger { color: var(--danger); }
form.inline, .inline { display: inline-flex; align-items: center; gap: 6px; }

input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid #cdd5de; border-radius: 8px; background: #fff; color: var(--text);
  max-width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9fdcfb; border-color: var(--primary); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
input.short { width: 110px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; margin-bottom: 10px; }
.form label.inline { flex-direction: row; font-weight: 400; }
.form input:not([type=checkbox]), .form select, .form textarea { width: 100%; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 16px; padding: 12px 16px; }
legend { font-weight: 700; color: var(--primary-dark); padding: 0 6px; }
.field-err { color: var(--danger); font-weight: 400; }
.warn-text { color: var(--warn); }
.req { color: var(--danger); }
.checks-inline { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.confirm { background: #fff8e6; padding: 10px; border-radius: 8px; margin-bottom: 10px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.alert.ok { background: #eaf7ef; border-color: #b6e2c6; color: #1e5b3a; }
.alert.err { background: #fdeeee; border-color: #f2c1bc; color: #8a2a20; }
.alert.warn { background: #fff8e6; border-color: #f3dca5; color: #7a5410; }
.alert.info { background: #ebf4ff; border-color: #bcd6f5; color: #234e80; }
.alert ul { margin: 6px 0 0; padding-inline-start: 20px; }
.big-msg { font-size: 1.2rem; font-weight: 700; text-align: center; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.card .table-wrap { border: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
.table th { background: #f1f8fd; font-weight: 700; font-size: .9rem; white-space: nowrap; }
.table tbody tr:hover { background: #fafcfc; }
.table td select { padding: 4px 6px; }
.row-err { background: #fff5f4; }
.row-warn { background: #fffbf0; }
.details { max-width: 420px; word-break: break-word; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: .82rem; background: #eef1f4; white-space: nowrap; }
.need-A { background: #fdeeee; color: #8a2a20; }
.need-B { background: #fff8e6; color: #7a5410; }
.need-C { background: #ebf4ff; color: #234e80; }
.st-received { background: #eaf7ef; color: #1e5b3a; }
.st-pending { background: #fff8e6; color: #7a5410; }
.st-excluded { background: #fdeeee; color: #8a2a20; }
.st-unreachable { background: #eef1f4; color: #4a5560; }
.ps-active { background: #eaf7ef; color: #1e5b3a; }
.ps-closed { background: #eef1f4; color: #4a5560; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat .n { font-size: 1.5rem; font-weight: 700; color: var(--primary-dark); }
.stat.st-received .n { color: var(--ok); }
.stat.st-excluded .n { color: var(--danger); }
.stat.st-unreachable .n, .stat.st-pending .n { color: var(--warn); }
.bar-row { display: grid; grid-template-columns: minmax(0, 1.4fr) 2fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.bar { height: 10px; background: #edf1f4; border-radius: 6px; overflow: hidden; }
.bar.sm { height: 6px; width: 120px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--sky)); }

.filters details { margin-top: 10px; }
.filters summary { cursor: pointer; color: var(--primary); }
.filters .row.wrap { margin-top: 10px; }
.bulkbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; }
.pager { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.pager a, .pager .cur { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pager .cur { background: var(--primary); color: #fff; border-color: var(--primary); }

.profile { display: flex; gap: 16px; align-items: flex-start; }
.idbox { text-align: center; min-width: 230px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.idbox .photo { width: 120px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.idbox .qr svg { width: 180px; height: 180px; }
.mono.big { font-size: 1.15rem; font-weight: 700; }
@media (max-width: 900px) { .profile { flex-direction: column; } .idbox { width: 100%; } }
.kvs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 20px; }
@media (max-width: 700px) { .kvs { grid-template-columns: 1fr; } }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.kv span { color: var(--muted); }
.files { list-style: none; padding: 0; margin: 0 0 10px; }
.files li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { background: var(--accent); border-radius: 20px; padding: 2px 10px; display: inline-flex; align-items: center; }
.steps li { margin-bottom: 6px; }
.checks { list-style: none; padding: 0; }
.checks .ok { color: var(--ok); }
.checks .bad { color: var(--danger); font-weight: 700; }
.login { text-align: center; }
.login .form { text-align: start; }
.login-logo { max-height: 120px; }
.logo-preview { max-height: 70px; }

/* Field scanning */
.scan-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .scan-grid { grid-template-columns: 1fr; } }
.camera { position: relative; background: #111; border-radius: 8px; aspect-ratio: 4 / 3; overflow: hidden; margin-bottom: 10px; }
.camera video { width: 100%; height: 100%; object-fit: cover; }
.cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #ddd; text-align: center; padding: 20px; }
.ben-card { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 12px; }
.ben-card img { width: 90px; height: 110px; object-fit: cover; border-radius: 8px; }
.ben-card .name { font-size: 1.3rem; font-weight: 700; }
.scan-setup select { min-width: 280px; }

/* Cards (ID / voucher) — 85.6mm x 54mm, 10 per A4 */
.cards-page { background: #fff; }
.toolbar { display: flex; gap: 12px; align-items: center; padding: 12px; flex-wrap: wrap; }
.sheet { display: grid; grid-template-columns: repeat(2, 85.6mm); gap: 4mm; justify-content: center; padding: 6mm 0; }
.idcard {
  width: 85.6mm; height: 54mm; border: 1px solid #9aa5b1; border-radius: 3mm; padding: 2.5mm 3mm; overflow: hidden;
  display: flex; flex-direction: column; break-inside: avoid; page-break-inside: avoid; font-size: 9pt; line-height: 1.35;
}
.idcard-head { display: flex; gap: 2mm; align-items: center; border-bottom: .6mm solid var(--primary); padding-bottom: 1.5mm; margin-bottom: 1.5mm; }
.idcard-head img { height: 9mm; }
.idcard-head .org { font-weight: 700; font-size: 9.5pt; color: var(--primary-dark); }
.idcard-head .sub { font-size: 7.5pt; color: #444; }
.idcard-body { display: flex; gap: 2mm; flex: 1; align-items: center; }
.idcard-body .info { flex: 1; }
.idcard-body .info span { color: #555; }
.idcard .name { font-weight: 700; font-size: 10pt; margin-bottom: 1mm; }
.idcard .qr svg { width: 27mm; height: 27mm; display: block; }

/* Print */
.print-head { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.print-head img { height: 60px; }
.print-head h2, .print-head h3 { margin: 0; }
.table.print th, .table.print td { border: 1px solid #999; padding: 5px 6px; font-size: 10pt; }
.signatures { display: flex; justify-content: space-between; margin-top: 30px; }
/* Reports */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--line); margin-bottom: 14px; }
.tabs a { padding: 8px 16px; border-radius: 8px 8px 0 0; color: var(--text); }
.tabs a.active { background: var(--primary); color: #fff; }
.tabs a:hover { text-decoration: none; background: var(--accent); }
.tabs a.active:hover { background: var(--primary); }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 0 16px; }
.report-grid .card.wide { grid-column: 1 / -1; }
.report-grid .bar.sm { width: 100%; max-width: 160px; margin-top: 3px; }
.print-only { display: none; }
.live-note::before { content: "● "; color: var(--ok, #2f855a); }
.live-bar { position: fixed; bottom: 16px; left: 16px; right: 16px; max-width: 520px; margin-inline: auto; z-index: 50; background: var(--primary); color: #fff;
  border-radius: 10px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.live-bar .btn { background: #fff; color: var(--primary); }

@media print {
  .print-only { display: flex; }
  .report-grid { display: block; }
  .report-grid .card { break-inside: avoid; }
  @page { size: A4; margin: 10mm; }
  .no-print, .topbar, .sidenav { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .main { margin: 0; padding: 0; max-width: none; }
  .table-wrap { border: 0; overflow: visible; }
  .table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet { padding: 0; gap: 3mm 4mm; }
  .idcard { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; }
}

/* Beneficiary card (85.6 x 54 mm, two-sided) based on the ناس الخيرية template */
.ncard {
  --c-navy: #01058c; --c-sky: #4fc6fa; --c-line: #09c9fd; --c-ice: #d8f6fe; --c-frost: #eefbff;
  position: relative; width: 85.6mm; height: 54mm; max-width: 100%; border-radius: 3mm; border: .3mm solid #b9c3cf;
  background: #fff; color: var(--c-navy); overflow: hidden; padding: 2.6mm 3.6mm 0; font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  display: flex; flex-direction: column; line-height: 1.25; break-inside: avoid; page-break-inside: avoid;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.ncard-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 2mm; border-bottom: .5mm solid var(--c-line); padding-bottom: 1.1mm; }
.ncard-head img { height: 9.5mm; width: auto; display: block; }
.ncard-title { font-size: 12.5pt; font-weight: 800; letter-spacing: 0; white-space: nowrap; }
.ncard-title small { display: block; font-size: 6.5pt; font-weight: 700; color: #1b5fb8; text-align: left; }
.ncard-body { position: relative; z-index: 1; flex: 1; display: flex; align-items: center; gap: 3mm; padding: 1.4mm 0 4.2mm; }
.ncard-info { flex: 1; min-width: 0; }
.ncard-name { font-size: 10.5pt; font-weight: 800; margin-bottom: 1mm; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ncard-row { font-size: 7.4pt; display: flex; gap: 1.2mm; margin-bottom: .55mm; white-space: nowrap; }
.ncard-row b { font-weight: 800; }
.ncard-row span { font-weight: 500; color: #111; }
.ncard-qr { position: relative; flex: 0 0 23mm; width: 23mm; height: 23mm; border: .45mm solid var(--c-line); border-radius: 1.6mm; padding: 1.6mm; background: #fff; }
.ncard-qr svg { width: 100%; height: 100%; display: block; }
.ncard-qr i { position: absolute; width: 2.6mm; height: 2.6mm; border: 0 solid var(--c-navy); }
.ncard-qr i:nth-child(1) { top: .6mm; right: .6mm; border-top-width: .6mm; border-right-width: .6mm; }
.ncard-qr i:nth-child(2) { top: .6mm; left: .6mm; border-top-width: .6mm; border-left-width: .6mm; }
.ncard-qr i:nth-child(3) { bottom: .6mm; right: .6mm; border-bottom-width: .6mm; border-right-width: .6mm; }
.ncard-qr i:nth-child(4) { bottom: .6mm; left: .6mm; border-bottom-width: .6mm; border-left-width: .6mm; }
.ncard-band { position: absolute; left: 0; right: 0; bottom: 0; height: 3mm; z-index: 0;
  background: repeating-linear-gradient(45deg, transparent 0 .9mm, #bfeefd .9mm 1.1mm), repeating-linear-gradient(-45deg, var(--c-frost) 0 .9mm, #bfeefd .9mm 1.1mm); }
.ncard-step { position: absolute; bottom: 0; width: 7mm; height: 9mm; z-index: 0; }
.ncard-step::before { content: ""; position: absolute; bottom: 0; width: 7mm; height: 4.2mm; background: var(--c-sky); }
.ncard-step::after { content: ""; position: absolute; bottom: 4.2mm; width: 3.2mm; height: 4.8mm; background: var(--c-sky); }
.ncard-step i { position: absolute; bottom: 4.2mm; width: 2.2mm; height: 2.2mm; background: #1338c2; z-index: 1; }
.ncard-step.r { right: 0; } .ncard-step.r::before { right: 0; border-top-left-radius: 1mm; } .ncard-step.r::after { right: 0; } .ncard-step.r i { right: 3.2mm; }
.ncard-step.l { left: 0; } .ncard-step.l::before { left: 0; border-top-right-radius: 1mm; } .ncard-step.l::after { left: 0; } .ncard-step.l i { left: 3.2mm; }
/* back */
.ncard-rules { list-style: none; margin: 1.3mm 0 0; padding: 0; position: relative; z-index: 1; }
.ncard-rules li { display: flex; align-items: center; gap: 1.4mm; font-size: 6.6pt; font-weight: 500; color: #0c1450; margin-bottom: .55mm; }
.ncard-rules li::before { counter-increment: rule; content: counter(rule); flex: 0 0 3.4mm; height: 3.4mm; border-radius: 50%; background: #bfeefd; color: var(--c-navy); font-weight: 800; font-size: 6.2pt; display: flex; align-items: center; justify-content: center; }
.ncard-rules { counter-reset: rule; }
.ncard-box { position: relative; z-index: 1; margin: .6mm 4mm 3.6mm; background: var(--c-ice); border-radius: 1.6mm; padding: 1mm 2mm; text-align: center; font-size: 6.3pt; color: #0c1450; }
.ncard-box b { color: var(--c-navy); font-weight: 800; }
.ncard-box .tel { font-weight: 800; color: var(--c-navy); font-size: 7pt; }
.ncard-mark { position: absolute; left: 6mm; top: 14mm; width: 15mm; opacity: .1; z-index: 0; }
/* print sheets: fronts page, then backs page with columns swapped for double-sided printing */
.card-sheet { display: grid; grid-template-columns: repeat(2, 85.6mm); gap: 3mm 5mm; justify-content: center; padding: 4mm 0; }
.card-sheet.backs { direction: ltr; }
.card-sheet.backs .ncard { direction: rtl; }
.card-pair { display: flex; flex-wrap: wrap; gap: 4mm; margin-bottom: 5mm; }
@media print { .card-sheet { page-break-after: always; break-after: page; padding: 0; } .card-sheet:last-child { page-break-after: auto; break-after: auto; } }
