:root {
  --bg: #f4f6fb;
  --card: #fff;
  --ink: #142033;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #e60000;
  --brand-dark: #b30000;
  --navy: #1a3a6e;
  --ok: #059669;
  --ok-bg: #d1fae5;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --info-bg: #e0f2fe;
  --info: #0369a1;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--navy); }
.ltr { direction: ltr; unicode-bidi: embed; }
.mono { font-family: Consolas, "Courier New", monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 230px; background: var(--navy); color: #fff; padding: 18px 12px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 17px; }
.side .brand .dot { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; font-weight: 800; }
.side a {
  color: #dbe6ff; text-decoration: none; padding: 9px 12px; border-radius: 10px; display: flex; justify-content: space-between;
}
.side a:hover, .side a.on { background: rgba(255, 255, 255, .12); color: #fff; }
.side .me { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.15); font-size: 13px; }
.side .me form { margin-top: 6px; }
.side .me button { background: none; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.main { flex: 1; padding: 22px 26px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.top h1 { margin: 0; font-size: 22px; }
.pill { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 12.5px; font-weight: 600; background: #eef2f7; color: #334155; white-space: nowrap; }
.pill.pending { background: var(--info-bg); color: var(--info); }
.pill.review { background: var(--warn-bg); color: var(--warn); }
.pill.paid, .pill.matched, .pill.matched_late, .pill.matched_manual { background: var(--ok-bg); color: var(--ok); }
.pill.rejected, .pill.unparsed, .pill.wallet_mismatch { background: var(--bad-bg); color: var(--bad); }
.pill.ambiguous, .pill.no_match { background: var(--warn-bg); color: var(--warn); }
.badge { background: var(--brand); color: #fff; border-radius: 999px; font-size: 11.5px; padding: 0 7px; font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi { cursor: pointer; }
.kpi b { font-size: 26px; display: block; }
.kpi.on { outline: 2px solid var(--navy); }
.stack > * + * { margin-top: 12px; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.tbl th, .tbl td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { background: #f8fafc; font-size: 13px; color: var(--muted); font-weight: 600; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f8fbff; }
.tbl tr.fresh td { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: #fff7cc; } to { background: transparent; } }
.amount { font-weight: 800; font-size: 16px; }

/* forms */
label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=search], select, textarea {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 10px; padding: 9px 11px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: #60a5fa; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 140px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; gap: 6px; align-items: center; font-size: 14px; }
.btn {
  border: 0; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 700; cursor: pointer;
  background: var(--navy); color: #fff; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:disabled { opacity: .6; cursor: wait; }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid #cbd5e1; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.notice { border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: #78350f; }
.notice.ok { background: var(--ok-bg); color: #065f46; }
.notice.bad { background: var(--bad-bg); color: #7f1d1d; }
.notice.info { background: var(--info-bg); color: #0c4a6e; }
.secret-box { background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 10px; word-break: break-all; direction: ltr; text-align: left; }

.proof-img { max-width: 100%; max-height: 640px; border-radius: 12px; border: 1px solid var(--line); display: block; }
.sms-text { white-space: pre-wrap; background: #f8fafc; border-radius: 10px; padding: 8px 10px; font-size: 13.5px; }
.sms-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; background: #f8fafc; border-radius: 10px; padding: 8px 10px; margin-top: 6px; }
.sms-sum > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sms-sum span { font-size: 11.5px; color: var(--muted, #64748b); }
.sms-sum b { font-size: 14px; overflow-wrap: anywhere; }
.sms-sum b.ltr { text-align: right; }
.sms-sum small { font-size: 11.5px; color: var(--muted, #64748b); overflow-wrap: anywhere; }
.wallet-bal { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 14px; }
.wallet-bal .card { padding: 12px 14px; }
.wallet-bal b { display: block; font-size: 20px; margin: 2px 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13.5px; }
dl.kv dd { margin: 0; font-weight: 600; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog .dh { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; }
dialog .db { padding: 16px 18px; max-height: 70vh; overflow: auto; }
dialog .df { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-start; }

#toast {
  position: fixed; bottom: 18px; left: 18px; background: #0f172a; color: #fff; padding: 10px 16px;
  border-radius: 12px; opacity: 0; transition: opacity .2s; z-index: 50; max-width: 420px;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); }

/* login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1a3a6e, #0f2a52); padding: 16px; }
.auth { width: min(400px, 100%); background: #fff; border-radius: 18px; padding: 28px; }
.auth h1 { margin: 0 0 4px; font-size: 22px; }

/* payer page */
.pay-wrap { max-width: 520px; margin: 0 auto; padding: 22px 14px 40px; }
.pay-head { text-align: center; margin-bottom: 14px; }
.pay-amount { font-size: 40px; font-weight: 800; color: var(--brand); }
.wallet-num { font-size: 28px; font-weight: 800; letter-spacing: 1px; direction: ltr; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; padding: 8px 0 8px 0; display: flex; gap: 10px; }
.steps li::before { content: counter(s); background: var(--navy); color: #fff; border-radius: 50%; width: 24px; height: 24px; display: grid; place-items: center; font-size: 13px; flex-shrink: 0; }
.status-big { text-align: center; padding: 18px; border-radius: 14px; font-weight: 800; font-size: 18px; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .side { width: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .side .brand { padding: 4px 8px; width: 100%; }
  .side .me { margin: 0; border: 0; width: 100%; }
  .main { padding: 14px; }
  .tbl .hide-sm { display: none; }
}
