:root {
  --bg: #0e1f12;
  --bg-soft: #16321d;
  --surface: #ffffff;
  --surface-2: #f6f8f5;
  --border: #e1e8df;
  --text: #14241a;
  --text-soft: #5e6b62;
  --primary: #1f7a3d;
  --primary-dark: #155f2c;
  --primary-soft: #e6f4ea;
  --gold: #c79a1e;
  --gold-dark: #a87f12;
  --gold-soft: #fbf3da;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #c0392b;
  --danger-soft: #fbe6e3;
  --warning: #c8861a;
  --warning-soft: #fbf0d8;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(14, 31, 18, 0.08);
  --shadow-lg: 0 20px 50px rgba(14, 31, 18, 0.2);
  font-family: "Tajawal", "Segoe UI", "Tahoma", system-ui, sans-serif;
}

body, input, select, textarea, button {
  font-family: "Tajawal", "Segoe UI", "Tahoma", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  direction: rtl;
  text-align: right;
  color: var(--text);
  background: var(--surface-2);
  min-height: 100vh;
  line-height: 1.7;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== أزرار ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--primary);
  color: #fff;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* ===== حقول الإدخال ===== */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.field .req { color: var(--danger); }
input, select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ===== شارات الحالة ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-matched { background: var(--success-soft); color: var(--success); }
.badge-not_matched { background: var(--danger-soft); color: var(--danger); }
.badge-pending { background: var(--warning-soft); color: var(--warning); }

/* ===== تنبيهات ===== */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  display: none;
}
.alert.show { display: block; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }

/* ===== Toast ===== */
.toast-wrap {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.toast {
  background: var(--bg);
  color: #fff;
  padding: 12px 22px;
  border-radius: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }

/* =============== الواجهة العامة (الفورمة) =============== */
.public-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 30px 16px;
  background: linear-gradient(135deg, #0e1f12 0%, #1f5c33 55%, #14532d 100%);
}
.form-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  overflow: hidden;
  border-top: 5px solid var(--gold);
}
.form-header {
  position: relative;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.10) 1.4px, transparent 1.6px) 0 0 / 20px 20px,
    radial-gradient(circle, rgba(199, 154, 30, 0.18) 1.4px, transparent 1.6px) 10px 10px / 20px 20px,
    linear-gradient(135deg, #0f3219, #1f7a3d);
  color: #fff;
  padding: 28px 30px 26px;
  text-align: center;
  border-bottom: 3px solid var(--gold);
  overflow: hidden;
}
.form-header > * { position: relative; z-index: 1; }
.form-header::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(15, 50, 25, 0.55) 100%);
  pointer-events: none;
}
.form-header .brand-logo {
  width: 116px;
  height: auto;
  margin: 0 auto 12px;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}
.form-header h1 { font-size: 23px; margin-bottom: 4px; color: #fff; }
.form-header h1 .accent { color: var(--gold); }
.form-header .form-subtitle {
  font-size: 17px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 10px;
}
.form-header p { opacity: 0.92; font-size: 14px; }
.form-body { padding: 28px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.credit {
  text-align: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-soft);
}
.credit a {
  color: var(--primary);
  font-weight: 700;
}

/* حقل الفخّ ضد البوتات - مخفي تماماً عن المستخدم */
.hp {
  position: absolute !important;
  left: -9999px !important;
  top: -9999px !important;
  width: 1px; height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* صف التحقق البشري */
.captcha-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.captcha-row .captcha-q {
  position: relative;
  flex: 1 1 100%;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 11px 46px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 1px;
  user-select: none;
  text-align: center;
  white-space: nowrap;
}
.captcha-row .captcha-q #captchaQuestion { display: block; }
#captchaRefresh {
  position: absolute;
  left: 7px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  font-family: inherit;
}
#captchaRefresh:hover { color: var(--primary); border-color: var(--primary); transform: translateY(-50%) rotate(90deg); }
.captcha-row input { flex: 1 1 auto; min-width: 0; }

/* =============== الاستمارة مغلقة =============== */
.closed-box { text-align: center; padding: 10px 6px 6px; }
.closed-icon {
  width: 76px; height: 76px; margin: 0 auto 16px;
  border-radius: 50%; background: var(--danger-soft);
  display: flex; align-items: center; justify-content: center; font-size: 34px;
}
.closed-box h2 { font-size: 22px; color: var(--danger); margin-bottom: 8px; }
.closed-box > p { color: var(--text-soft); font-size: 15px; margin-bottom: 18px; }
.open-at {
  display: inline-flex; flex-direction: column; gap: 4px;
  background: var(--gold-soft); border: 1px solid var(--gold);
  border-radius: 12px; padding: 14px 26px; margin-top: 4px;
}
.open-at-label { font-size: 13px; color: var(--gold-dark); font-weight: 700; }
.open-at-value { font-size: 18px; font-weight: 800; color: var(--primary-dark); }

/* =============== صفحة النجاح =============== */
.success-card .form-body { padding: 32px 28px; }
.success-check { margin: 6px auto 18px; width: 76px; height: 76px; }
.success-check svg { display: block; }
.sc-circle {
  stroke: var(--success);
  stroke-width: 3;
  stroke-dasharray: 151;
  stroke-dashoffset: 151;
  animation: scCircle 0.5s ease forwards;
}
.sc-tick {
  stroke: var(--success);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  animation: scTick 0.35s ease forwards 0.45s;
}
@keyframes scCircle { to { stroke-dashoffset: 0; } }
@keyframes scTick { to { stroke-dashoffset: 0; } }
.success-title { font-size: 23px; color: var(--primary-dark); margin-bottom: 10px; }
.success-text { color: var(--text-soft); font-size: 15px; margin-bottom: 24px; line-height: 1.8; }

/* =============== صفحة الدخول =============== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #0e1f12 0%, #16321d 55%, #14532d 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 410px;
  padding: 32px 30px;
  border-top: 5px solid var(--gold);
}
.login-card .logo {
  width: 90px; height: 90px;
  margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
}
.login-card .logo img { width: 100%; height: 100%; object-fit: contain; }
.login-card h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--text-soft); font-size: 14px; margin-bottom: 24px; }

/* =============== لوحة الأدمن =============== */
.admin-layout { max-width: 100%; margin: 0 auto; padding: 20px 26px; }
body:has(.admin-layout) { background: var(--surface-2); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); padding: 14px 22px; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
  border-top: 4px solid var(--gold);
}
.topbar .brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 17px; color: var(--primary-dark); }
.topbar .brand .mark {
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
}
.topbar .brand .mark img { width: 100%; height: 100%; object-fit: contain; }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--text-soft); font-size: 14px; }

/* بطاقات الإحصائيات */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px;
}
.stat-card .icon {
  width: 46px; height: 46px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 22px;
}
.stat-card .icon.total { background: var(--gold-soft); }
.stat-card .num { color: var(--primary-dark); }
.stat-card .icon.matched { background: var(--success-soft); }
.stat-card .icon.pending { background: var(--warning-soft); }
.stat-card .icon.not_matched { background: var(--danger-soft); }
.stat-card .num { font-size: 24px; font-weight: 800; }
.stat-card .lbl { font-size: 13px; color: var(--text-soft); }

/* لوحة الفلاتر */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.panel h2 { font-size: 15px; color: var(--text-soft); font-weight: 700; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.panel-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-excel { background: #1d6f42; }
.btn-excel:hover { background: #15572f; }
.btn-excel span { font-size: 15px; }

/* لوحة التحكم بالاستمارة */
.form-control-row { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.form-state-badge {
  padding: 4px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
}
.form-state-badge.open { background: var(--success-soft); color: var(--success); }
.form-state-badge.closed { background: var(--danger-soft); color: var(--danger); }
.open-at-field { flex: 1 1 280px; }
.open-at-field label { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 6px; }
.open-at-field input { padding: 9px 12px; font-size: 14px; }

/* مفتاح التبديل */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .slider {
  position: relative; width: 50px; height: 28px; background: #cbd5cb;
  border-radius: 999px; transition: background 0.2s; flex: 0 0 auto;
}
.switch .slider::before {
  content: ""; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px;
  background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(-22px); }
.switch-label { font-size: 14px; font-weight: 600; }
.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.filters .field { margin-bottom: 0; }
.filters .field label { font-size: 12px; color: var(--text-soft); }
.filters input, .filters select { padding: 9px 12px; font-size: 14px; }
.filters-actions { display: flex; gap: 10px; margin-top: 14px; }

/* الجدول */
.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  background: var(--surface-2); padding: 12px 10px; text-align: right;
  font-weight: 700; color: var(--text-soft); white-space: nowrap;
  border-bottom: 1px solid var(--border); user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--primary); }
thead th .arrow { font-size: 11px; opacity: 0.5; }
thead th.active .arrow { opacity: 1; color: var(--primary); }
tbody td { padding: 11px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 6px; }
.status-select { padding: 5px 8px; font-size: 13px; border-radius: 8px; width: auto; }

.empty { text-align: center; padding: 50px 20px; color: var(--text-soft); }
.empty .ico { font-size: 40px; margin-bottom: 10px; }

/* الترقيم */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; flex-wrap: wrap; gap: 12px;
}
.pagination .info { font-size: 13px; color: var(--text-soft); }
.pagination .pages { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.page-btn {
  min-width: 36px; height: 36px; padding: 0 10px; border-radius: 9px;
  border: 1px solid var(--border); background: #fff; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--text); font-family: inherit;
}
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.per-page { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); }
.per-page select { width: auto; padding: 6px 10px; font-size: 13px; }

.loading { text-align: center; padding: 40px; color: var(--text-soft); }

/* ===== نافذة التأكيد ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.18s ease; }
.modal {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  padding: 28px 26px;
  text-align: center;
  animation: modalPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-icon {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--danger-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
}
.modal-title { font-size: 19px; margin-bottom: 8px; color: var(--text); }
.modal-text { font-size: 14px; color: var(--text-soft); margin-bottom: 22px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalPop { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* استجابة الشاشات الصغيرة */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .public-page { padding: 16px 10px; }
  .form-card { border-radius: 16px; }
  .form-header { padding: 22px 18px; }
  .form-header h1 { font-size: 20px; }
  .form-body { padding: 20px 16px; }
  .login-card { padding: 28px 20px; }

  /* صف التحقق الأمني: المعادلة فوق وحقل الإجابة تحته */
  .captcha-row { flex-direction: column; align-items: stretch; }
  .captcha-row .captcha-q { flex: 1 1 auto; width: 100%; }
  .captcha-row input { flex: 1 1 auto; width: 100%; }
}
