:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #10192b;
  --ink-soft: #5a6980;
  --line: #e2e7f1;
  --brand: #12457f;         /* أزرق بوابة عشتار */
  --brand-dark: #0d3160;
  --gold: #c8912a;
  --ok: #0f8a56;
  --ok-bg: #e7f7ef;
  --warn: #b26a00;
  --warn-bg: #fdf3e2;
  --danger: #c02c3c;
  --danger-bg: #fdecee;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 25, 43, .05), 0 8px 24px rgba(16, 25, 43, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Cairo', 'Segoe UI', Tahoma, 'Noto Naskh Arabic', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.wrap { width: min(1120px, 100% - 32px); margin-inline: auto; }

/* ───────────────────────── الشريط العلوي ───────────────────────── */

.topbar {
  background: linear-gradient(120deg, var(--brand-dark), var(--brand));
  color: #fff;
  box-shadow: 0 2px 14px rgba(13, 49, 96, .25);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 0;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: #fff;
  border-radius: 11px;
  padding: 5px;
  box-shadow: 0 2px 8px rgba(6, 24, 48, .25);
  flex: none;
}
.brand strong { display: block; font-size: 20px; font-weight: 800; letter-spacing: .2px; }
.brand small { display: block; font-size: 12.5px; opacity: .8; }

.tabs { display: flex; gap: 6px; background: rgba(255,255,255,.12); padding: 5px; border-radius: 12px; }

.tab {
  border: 0;
  background: transparent;
  color: #dfe8f5;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { color: #fff; background: rgba(255,255,255,.1); }
.tab.is-active { background: #fff; color: var(--brand-dark); }

/* ───────────────────────── العروض والبطاقات ───────────────────────── */

main { padding: 28px 0 40px; }
.view { display: none; }
.view.is-active { display: block; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 18px;
}

.card-head h1 { margin: 0 0 4px; font-size: 21px; font-weight: 800; }
.card-head p { margin: 0 0 20px; color: var(--ink-soft); font-size: 14px; }

/* ───────────────────────── الحقول ───────────────────────── */

.form { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .legend { font-size: 13.5px; font-weight: 600; color: #2b3a52; }
.req { color: var(--danger); }
.hint { font-size: 12px; color: var(--ink-soft); font-weight: 400; }

/* ملاحظات جاهزة: الحقل يبقى فارغاً افتراضياً، والضغط يملؤه والضغط ثانيةً يفرغه. */
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.preset {
  border: 1px dashed #c3cddd; background: #fff; font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--ink-soft); padding: 5px 11px; border-radius: 999px; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.preset:hover { border-color: var(--brand); color: var(--brand); }
.preset.is-on {
  background: var(--brand); border-color: var(--brand); border-style: solid; color: #fff;
}

input[type=text], input[type=tel], input[type=date], input[type=search], input[type=password] {
  font: inherit;
  font-size: 14.5px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  color: var(--ink);
  width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(18, 69, 127, .12);
}
input::placeholder { color: #9aa7ba; }

/* اختيار نوع الضمان */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.choice-box {
  display: block;
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #fbfcfe;
  transition: all .15s;
}
.choice-box b { display: block; font-size: 15px; }
.choice-box small { color: var(--ink-soft); font-size: 12.5px; }
.choice input:checked + .choice-box {
  border-color: var(--brand);
  background: #eff5fd;
  box-shadow: 0 0 0 3px rgba(18, 69, 127, .1);
}
.choice input:focus-visible + .choice-box { outline: 2px solid var(--gold); outline-offset: 2px; }

.form-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.search-row { display: flex; gap: 10px; }
.search-row input { flex: 1; }

/* ───────────────────────── الأزرار ───────────────────────── */

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 14.5px;
  padding: 11px 24px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .1s, filter .15s, background .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: #f5f7fb; color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 8px; }

/* ───────────────────────── الرسائل ───────────────────────── */

.msg { font-size: 13.5px; font-weight: 600; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ───────────────────────── بطاقة النجاح ───────────────────────── */

.success-card { border-inline-start: 5px solid var(--ok); }
.success-card h2 { margin: 0 0 6px; font-size: 18px; color: var(--ok); }

.id-box {
  margin: 14px 0;
  padding: 16px;
  border: 1.5px dashed var(--gold);
  border-radius: 12px;
  background: #fffaf0;
  text-align: center;
}
.id-box small { display: block; color: var(--warn); font-size: 12.5px; font-weight: 600; }
.id-box code {
  display: block;
  font-family: 'Consolas', ui-monospace, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--brand-dark);
  margin-top: 4px;
  direction: ltr;
}

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 12px; }
.kv > div { background: #f7f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; }
.kv dt { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.kv dd { margin: 2px 0 0; font-size: 14.5px; font-weight: 600; }

/* ───────────────────────── نتائج البحث ───────────────────────── */

.results { display: flex; flex-direction: column; gap: 14px; }

.wcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.wcard.state-active { border-inline-start-color: var(--ok); }
.wcard.state-claimed { border-inline-start-color: var(--danger); }
.wcard.state-expired { border-inline-start-color: var(--warn); }

.wcard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.wcard-head h3 { margin: 0; font-size: 17px; }
.wcard-id {
  font-family: 'Consolas', ui-monospace, monospace;
  font-size: 13px;
  color: var(--brand);
  direction: ltr;
  display: inline-block;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.claimed { background: #fdecee; color: var(--danger); }
.badge.expired { background: var(--warn-bg); color: var(--warn); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ───────────────────────── الإحصاءات ───────────────────────── */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat dt { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.stat dd { margin: 4px 0 0; font-size: 28px; font-weight: 800; line-height: 1.2; }
.stat.is-ok dd { color: var(--ok); }
.stat.is-danger dd { color: var(--danger); }
.stat.is-warn dd { color: var(--warn); }

/* ───────────────────────── الجدول ───────────────────────── */

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar > input { flex: 1; min-width: 220px; }

.filters { display: flex; gap: 6px; background: #f2f5fa; padding: 4px; border-radius: 10px; }
.chip {
  border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); padding: 6px 13px; border-radius: 7px; cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip.is-active { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(16,25,43,.1); }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 780px; }
.table th {
  text-align: start; font-size: 12.5px; color: var(--ink-soft); font-weight: 700;
  padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid #f0f3f8; vertical-align: middle; }
.table tbody tr:hover { background: #fafbfe; }
.table code { font-family: 'Consolas', ui-monospace, monospace; font-size: 12px; color: var(--brand); direction: ltr; }
.muted { color: var(--ink-soft); font-size: 12.5px; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 16px; }
.pager span { font-size: 13px; color: var(--ink-soft); }

/* ───────────────────────── النافذة المنبثقة ───────────────────────── */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(16, 25, 43, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  width: min(480px, 100%);
  box-shadow: 0 20px 60px rgba(16, 25, 43, .3);
  display: flex; flex-direction: column; gap: 14px;
}
.modal-box h2 { margin: 0; font-size: 19px; }
.modal-sub { margin: 0; color: var(--ink-soft); font-size: 14px; }
.warn {
  background: var(--warn-bg);
  border: 1px solid #f0dcb8;
  color: #7a4a00;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
}
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; margin-top: 4px; }

/* ───────────────────────── التذييل ───────────────────────── */

.foot { padding: 18px 0 30px; color: var(--ink-soft); font-size: 12.5px; text-align: center; }

@media (max-width: 720px) {
  .grid-2, .choices { grid-template-columns: 1fr; }
  .topbar-inner { justify-content: center; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 8px 6px; font-size: 13px; }
  .card { padding: 18px; }
}

/* ───────────────────────── المنتجات المتعددة ───────────────────────── */

.section-head { margin-top: 6px; }
.section-head h2 { margin: 0 0 2px; font-size: 16px; font-weight: 800; }
.section-head p { margin: 0; color: var(--ink-soft); font-size: 13px; }

.item-card {
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--brand);
  border-radius: 12px;
  background: #fbfcfe;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.item-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.item-num { font-size: 13px; font-weight: 800; color: var(--brand); }

.item-remove {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--danger);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 7px;
}
.item-remove:hover { background: var(--danger-bg); }

.choices-3 { grid-template-columns: repeat(3, 1fr); }

/* ───────────────────────── نتيجة التسجيل ───────────────────────── */

.result-item {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}
.result-item h3 { margin: 0 0 2px; font-size: 15.5px; }
.result-item p { margin: 0 0 10px; font-size: 13px; }

.id-list { display: flex; flex-wrap: wrap; gap: 8px; }
.id-list code {
  font-family: 'Consolas', ui-monospace, monospace;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .6px;
  color: var(--brand-dark);
  background: #fffaf0;
  border: 1.5px dashed var(--gold);
  border-radius: 9px;
  padding: 7px 12px;
  direction: ltr;
}

/* ───────────────────────── حالة "بدون ضمان" ───────────────────────── */

.badge.no_warranty { background: #eef1f6; color: var(--ink-soft); }
.wcard.state-no_warranty { border-inline-start-color: #b4bdcc; }

@media (max-width: 720px) {
  .choices-3 { grid-template-columns: 1fr; }
}

/* ───────────────────────── قائمة منسدلة مع بحث ───────────────────────── */

.combo { position: relative; }

.combo-input {
  font: inherit;
  font-size: 14.5px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  color: var(--ink);
  width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.combo-input:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(18, 69, 127, .12);
}
.combo-input::placeholder { color: #9aa7ba; }
.combo-input:disabled {
  background: #eef1f6;
  color: #9aa7ba;
  cursor: not-allowed;
}

.combo-list {
  position: absolute;
  z-index: 20;
  inset-inline: 0;
  top: calc(100% + 4px);
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: 0 12px 32px rgba(16, 25, 43, .16);
  padding: 5px;
}

.combo-option {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.combo-option:hover,
.combo-option.is-highlighted { background: #eff5fd; color: var(--brand-dark); }

.combo-empty { padding: 10px 12px; font-size: 13px; color: var(--ink-soft); }

/* ───────────────────────── تبويب الطلبات ───────────────────────── */

.tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-inline-start: 5px;
  border-radius: 999px;
  background: var(--gold);
  color: #fff;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
}
.tab.is-active .tab-badge { background: var(--brand); }

.check-all {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.check-all input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand); }

#orders-tbody input[type=checkbox] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--brand);
}
#orders-tbody tr:has(input:checked) { background: #eff5fd; }

#orders-table { min-width: 900px; }

/* نافذة واسعة لنموذج الاستبدال، وضيّقة لتأكيد بسيط */
.modal-wide { width: min(680px, 100%); max-height: 90vh; overflow-y: auto; }
.modal-sm { width: min(400px, 100%); }
.toolbar-select { margin-top: -4px; padding-top: 12px; border-top: 1px solid var(--line); }
#admin-tbody input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand); }
#admin-tbody tr:has(input:checked) { background: #fdeff1; }

/* أزرار داخل صفوف الجدول */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-icon {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.btn-icon:hover { background: #f5f7fb; color: var(--ink); }

.btn-wa { border-color: #bfe6c9; color: #1a7f42; background: #f1faf4; }
.btn-wa:hover { background: #e3f5ea; color: #146634; }

/* معاينة وصل الضمان */
.receipt-preview {
  background: #eef1f6;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  justify-content: center;
  min-height: 220px;
  max-height: 55vh;
  overflow: auto;
}
.receipt-preview canvas {
  width: 100%;
  max-width: 420px;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(16, 25, 43, .18);
}
.receipt-loading { align-self: center; color: var(--ink-soft); font-size: 14px; }
.btn-receipt { border-color: #e0cda0; color: #8a6414; background: #fffaf0; }
.btn-receipt:hover { background: #fdf2dd; color: #6d4d0c; }

/* ═══════════════════════ بوابة الدخول ═══════════════════════ */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #12457f 0%, #0d2f57 100%);
  z-index: 100;
}
.gate-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 18px;
  padding: 30px 26px 26px;
  box-shadow: 0 24px 60px rgba(6, 20, 40, .35);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.gate-logo { width: 62px; height: 62px; align-self: center; }
.gate-card h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: .2px; }
.gate-card p { margin: -8px 0 6px; color: var(--ink-soft); font-size: 13px; }
.gate-card .field { text-align: start; }
.btn-block { width: 100%; justify-content: center; }
.gate-card .msg { min-height: 18px; }

/* شريط تحذير كلمة المرور الافتراضية */
.warn-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #fff6e6;
  border: 1px solid #f0d49a;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13.5px;
  color: #7a5410;
}
.warn-banner strong { font-weight: 800; }
.warn-banner span { flex: 1; min-width: 200px; }

/* أدوات مساعدة تحلّ محلّ الأنماط السطرية (تمنعها سياسة الأمان) */
.spacer { flex: 1; }
.col-check { width: 36px; }
.is-spaced { margin-top: 14px; }
.empty-cell { text-align: center; padding: 30px; }

/* ═══════════════════ الجداول على الهاتف ═══════════════════
   الجدول العريض يصير بطاقة لكل صف: عنوان الحقل من data-label
   بجانب قيمته، فلا سحب أفقي ولا تكبير. */
@media (max-width: 720px) {
  .table { min-width: 0; }
  .table thead { display: none; }
  .table tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #fff;
  }
  .table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 0;
    padding: 6px 0;
    text-align: start;
  }
  .table td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 700;
    color: var(--ink-soft);
    flex: 0 0 auto;
  }
  .table td:empty { display: none; }
  .table td.row-actions { flex-wrap: wrap; justify-content: flex-start; }
  .table td.row-actions::before { flex-basis: 100%; }
  .btn-icon { padding: 8px 12px; }
  .toolbar > input { min-width: 0; }
  .modal-box { padding: 18px; }
}

/* زر التثبيت في الشريط العلوي (أندرويد فقط — آيفون لا يعطي الحدث) */
.btn-install {
  background: rgba(255,255,255,.16);
  border-color: rgba(255,255,255,.4);
  color: #fff;
  font-weight: 700;
}
.btn-install:hover { background: rgba(255,255,255,.26); }
