:root {
  --primary: #1f6feb;
  --primary-dark: #1657bd;
  --deposit: #16a34a;
  --withdraw: #dc2626;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1a1f2b;
  --muted: #6b7280;
  --border: #e2e6ee;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Cairo", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 0 0 auto; }
.icon-btn {
  background: rgba(255, 255, 255, .15);
  border: none;
  color: #fff;
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
}
.balance-chips { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: rgba(255, 255, 255, .18);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
}
.chip b { font-size: 14px; }

/* ===== Layout ===== */
.layout { display: flex; min-height: calc(100vh - 60px); position: relative; }
.sidebar {
  width: 220px;
  background: var(--card);
  border-inline-start: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 0 auto;
}
.nav-item {
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  transition: background .15s;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary); color: #fff; }
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 25;
}
.content { flex: 1; padding: 20px; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ===== Views ===== */
.view { display: none; animation: fade .2s; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
h2 { margin: 4px 0 16px; }
h3 { margin: 18px 0 10px; color: var(--muted); font-size: 15px; }

/* ===== Cards & Forms ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.grid-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-form label, .filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}
.grid-form .full { grid-column: 1 / -1; }
input, select, textarea {
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .15);
}
.readonly, input[readonly] { background: #f1f3f7; color: var(--muted); }
textarea { resize: vertical; }

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-light { background: #eef1f6; color: var(--text); }
.btn-light:hover { background: #e2e6ee; }
.btn-big { width: 100%; padding: 15px; font-size: 17px; margin-top: 8px; }
.btn-danger { background: var(--withdraw); color: #fff; padding: 6px 12px; font-size: 13px; }

/* ===== Type toggle ===== */
.type-toggle { display: flex; gap: 10px; margin-bottom: 16px; }
.type-btn {
  flex: 1;
  padding: 16px;
  font-size: 18px;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  color: var(--muted);
}
.type-btn.deposit.active { border-color: var(--deposit); background: #eafbf0; color: var(--deposit); }
.type-btn.withdraw.active { border-color: var(--withdraw); background: #fdecec; color: var(--withdraw); }

/* ===== Camera ===== */
.camera-box { margin: 16px 0; }
.camera-preview {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 4 / 3;
  background: #0c0f16;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}
.camera-preview video, .camera-preview img { width: 100%; height: 100%; object-fit: cover; }
.cam-placeholder { color: #7a8496; font-size: 15px; }
.camera-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cam-status { font-size: 13px; color: var(--muted); margin-inline-end: auto; }
.cam-test-result { margin-top: 10px; }
.cam-test-result img { max-width: 240px; border-radius: 10px; }

/* ===== Stats grid ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border-inline-start: 4px solid var(--primary);
}
.stat-card .label { font-size: 13px; color: var(--muted); }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-card.green { border-color: var(--deposit); }
.stat-card.red { border-color: var(--withdraw); }
.stat-card.gold { border-color: #d97706; }

/* ===== Filters ===== */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; align-items: end; }
.filter-actions { display: flex; gap: 8px; flex-wrap: wrap; grid-column: 1 / -1; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f7f9fc; color: var(--muted); font-weight: 700; position: sticky; top: 0; }
tbody tr:hover { background: #f7f9fc; }
.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.deposit { background: #eafbf0; color: var(--deposit); }
.badge.withdraw { background: #fdecec; color: var(--withdraw); }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; cursor: pointer; }
.muted { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ===== Modal ===== */
.modal { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 50; align-items: center; justify-content: center; padding: 16px; }
.modal.open { display: flex; }
.modal-box { background: var(--card); border-radius: var(--radius); max-width: 480px; width: 100%; max-height: 90vh; overflow: auto; padding: 20px; position: relative; }
.modal-close { position: absolute; inset-inline-start: 12px; top: 12px; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-box img { width: 100%; border-radius: 10px; margin: 10px 0; }
.detail-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.detail-row .k { color: var(--muted); }
.detail-row .v { font-weight: 600; }

/* ===== Report ===== */
.report-area { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-height: 100px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: #1a1f2b;
  color: #fff;
  padding: 12px 22px;
  border-radius: 30px;
  font-size: 15px;
  z-index: 100;
  transition: transform .3s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  max-width: 90%;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--withdraw); }
.toast.success { background: var(--deposit); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    z-index: 26;
    transform: translateX(100%);
    transition: transform .25s;
    box-shadow: -2px 0 12px rgba(0, 0, 0, .15);
  }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0) !important; }
  .overlay.open { display: block; }
  .balance-chips { display: none; }
  .grid-form { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 16px; }
  .content { padding: 14px; }
}
@media (min-width: 769px) {
  #menuBtn { display: none; }
}

/* ===== Print (تقرير PDF) ===== */
@media print {
  .topbar, .sidebar, .filters, #menuBtn, .overlay { display: none !important; }
  .content { max-width: none; padding: 0; }
  .view:not(#view-reports) { display: none !important; }
  .report-area { box-shadow: none; }
}

/* ===== صفحة الدخول ===== */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.auth-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  width: 100%;
  max-width: 420px;
}
.auth-logo { font-size: 22px; text-align: center; margin: 4px 0 20px; }
.auth-lang { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form h2 { margin: 0 0 4px; text-align: center; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.auth-switch { text-align: center; color: var(--primary); font-size: 14px; text-decoration: none; }
.auth-switch:hover { text-decoration: underline; }

/* ===== الشريط الجانبي: معلومات المستخدم والخروج ===== */
.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-footer .muted { margin: 0; font-size: 13px; }

/* ===== زر اللغة ===== */
.lang-toggle { margin-inline-start: 4px; }

/* ===== تحذير الشرائح ===== */
.tier-warning {
  background: #fff7ed;
  color: #b45309;
  border: 1px solid #fcd9a8;
  border-radius: 10px;
  padding: 10px 14px;
  margin-top: 10px;
  font-size: 14px;
}

/* ===== شرائح العمولة ===== */
.tiers-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.tiers-table td { padding: 6px 8px; }
.tier-input { width: 110px; padding: 8px 10px; }
.tier-actions { display: flex; gap: 6px; }
.tier-actions .btn { padding: 7px 12px; font-size: 13px; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-label input[type="checkbox"] { width: auto; }

/* ===== شارة التحويل الداخلي ===== */
.badge.transfer { background: #eef2ff; color: #4f46e5; }

/* ===== سجل التدقيق ===== */
.audit-details {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
#auditTable code { background: #f1f3f7; padding: 2px 6px; border-radius: 6px; font-size: 12px; }

/* محاذاة الجداول حسب اتجاه اللغة */
html[dir="ltr"] th, html[dir="ltr"] td { text-align: left; }

/* ===== شعار وكيلي في صفحة الدخول ===== */
.logo-img { width: 44px; height: 44px; vertical-align: middle; border-radius: 12px; }
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
.auth-tagline { text-align: center; color: var(--muted); font-size: 14px; margin: -10px 0 18px; }
