:root {
  --bg: #f4f5f9;
  --panel: #ffffff;
  --ink: #1b1c30;
  --muted: #6b6f88;
  --line: #e3e5ef;
  --brand: #4f008c;
  --brand-soft: #f2e9fa;
  --ok: #0f7b4f;
  --ok-soft: #e4f5ec;
  --warn: #a05e00;
  --warn-soft: #fdf1dd;
  --err: #b3261e;
  --err-soft: #fdeaea;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- التخطيط ---------- */

.topbar {
  background: var(--brand);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.topbar .brand {
  font-weight: 700;
  font-size: 18px;
  padding: 14px 0;
  margin-inline-end: 8px;
}

.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }

.topbar nav a {
  color: #e8dcf5;
  padding: 14px 14px;
  border-bottom: 3px solid transparent;
}
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a.active {
  color: #fff;
  border-bottom-color: #fff;
  font-weight: 600;
}

.topbar .logout { color: #e8dcf5; font-size: 14px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

/* ---------- البطاقات والشبكات ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 900px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .value.small { font-size: 20px; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.alert { border-color: #f0c9c6; background: var(--err-soft); }
.stat.good { border-color: #bfe4d1; background: var(--ok-soft); }

/* ---------- الجداول ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; font-weight: 600; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
.table-wrap { overflow-x: auto; }

code, .mono {
  font-family: "Consolas", "Courier New", monospace;
  direction: ltr;
  unicode-bidi: embed;
  display: inline-block;
}
/* الخليّة نفسها يجب أن تبقى table-cell: وضع inline-block على <td class="mono">
   يكسر تخطيط الجدول ويترك فراغاً أبيض تحت الخليّة. */
td.mono, th.mono { display: table-cell; }

/* ---------- الشارات ---------- */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.pending { background: #eef0f7; color: var(--muted); }
.badge.processing { background: var(--brand-soft); color: var(--brand); }
.badge.success { background: var(--ok-soft); color: var(--ok); }
.badge.already_used { background: var(--warn-soft); color: var(--warn); }
.badge.invalid { background: var(--err-soft); color: var(--err); }
.badge.error { background: var(--err-soft); color: var(--err); }
.badge.requested { background: var(--warn-soft); color: var(--warn); }
.badge.paid { background: var(--ok-soft); color: var(--ok); }
.badge.rejected { background: #eef0f7; color: var(--muted); }
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: #eef0f7; color: var(--muted); }

/* مفتاح تفعيل/إيقاف (checkbox slider) */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #cfd2e0; border-radius: 999px; transition: .2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; right: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(-20px); }
.switch input:disabled + .slider { opacity: .5; cursor: default; }

/* تمييز بطاقات نون عن ريزر في جدول البطاقات — نلوّن الخلايا (أوضح وأقوى من
   خلفية الصفّ التي قد تُغطّى)، ونضيف شريطاً جانبياً على أول خليّة. */
tr.card-noon > td { background: #f7f1fc; }
tr.card-razer > td { background: #f0f8f3; }
tbody tr.card-noon:hover > td { background: #f1e7fa; }
tbody tr.card-razer:hover > td { background: #e7f3ec; }
tr.card-noon > td:first-child { box-shadow: inset -3px 0 0 #b98fe0; }
tr.card-razer > td:first-child { box-shadow: inset -3px 0 0 #7cc9a3; }
.prod-pill { display:inline-block; padding:1px 8px; border-radius:999px; font-size:11px; font-weight:700; }
.prod-pill.noon { background: var(--brand-soft); color: var(--brand); }
.prod-pill.razer { background: var(--ok-soft); color: #1b8f5a; }
/* تبويبات فلترة */
.tabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; }
.tabs a, .tabs button { padding:5px 14px; border-radius:999px; border:1px solid var(--line); background:var(--panel); color:var(--muted); font-weight:600; font-size:13px; }
.tabs a.active, .tabs button.active { background: var(--brand); color:#fff; border-color:var(--brand); }

/* ---------- النماذج ---------- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}
textarea { min-height: 70px; resize: vertical; }

.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }

.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.check label { margin: 0; color: var(--ink); font-size: 14px; }

button, .btn {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
button:hover, .btn:hover { opacity: .9; text-decoration: none; }
.btn.ghost { background: #fff; color: var(--brand); border-color: var(--line); }
.btn.ok, button.ok { background: var(--ok); }
.btn.warn, button.warn { background: var(--warn); }
.btn.err, button.err { background: var(--err); }
.btn.sm, button.sm { padding: 5px 12px; font-size: 13px; }
.btn.block { display: block; width: 100%; }

.inline-form { display: inline; }

/* ---------- التنبيهات ---------- */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-weight: 600;
}
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--err-soft); color: var(--err); }

.notice {
  background: var(--warn-soft);
  color: var(--warn);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 14px;
}

.empty { color: var(--muted); text-align: center; padding: 32px 12px; }

/* ---------- الدخول ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box { width: 100%; max-width: 380px; }
.login-box .card { padding: 28px; }
.login-box h1 { text-align: center; margin-bottom: 22px; }

/* ---------- صفحة المعالجة ---------- */

.copyfield {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fbfbfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.copyfield .val {
  flex: 1;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  direction: ltr;
  text-align: left;
}
.copyfield .cap { color: var(--muted); font-size: 13px; min-width: 78px; }

.steps { counter-reset: step; padding: 0; margin: 0 0 16px; list-style: none; }
.steps li {
  counter-increment: step;
  position: relative;
  padding-inline-start: 34px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  inset-inline-start: 0;
  top: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
  font-size: 12px;
  display: grid;
  place-items: center;
}

.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 560px) { .result-grid { grid-template-columns: 1fr; } }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.tal { text-align: left; }
.mb0 { margin-bottom: 0; }
.mt16 { margin-top: 16px; }
.small { font-size: 13px; }

details.inline > summary {
  cursor: pointer;
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
}
details.inline[open] > summary { margin-bottom: 10px; }

kbd {
  display: inline-block;
  padding: 1px 6px;
  margin-inline-start: 4px;
  border: 1px solid rgba(0, 0, 0, .18);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .22);
  font-family: "Consolas", monospace;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
}
.muted kbd { background: #fff; border-color: var(--line); color: var(--ink); }
