:root {
  /* الهوية: تيل عميق + حجر دافئ + لمسة ذهبية نادرة الاستخدام */
  --ink: #10211F;
  --ink-soft: #5B6B68;
  --teal-900: #0A3330;
  --teal-700: #0F5C56;
  --teal-600: #146B64;
  --teal-500: #16837A;
  --teal-100: #E4EEEC;
  --gold-600: #9C7A3C;
  --gold-100: #F3ECDC;
  --stone-50: #F6F4EF;
  --stone-100: #EFEBE2;
  --line: #DEDAD0;
  --white: #FFFFFF;
  --success: #2E7D53;
  --success-bg: #E7F2EB;
  --danger: #B33A3A;
  --danger-bg: #FBEAEA;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(16, 33, 31, 0.06);
  --shadow-lg: 0 16px 40px rgba(16, 33, 31, 0.18);
  --nav-h: 62px;
  --font-display: "Almarai", "Segoe UI", Tahoma, sans-serif;
  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--stone-50);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--nav-h) + 20px);
  font-size: 15px;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 16px;
}

.icon { width: 16px; height: 16px; flex-shrink: 0; }
.icon-lg { width: 22px; height: 22px; }
.icon-success { color: var(--success); }
.icon-danger { color: var(--danger); }
.icon-gold { color: var(--gold-600); }

/* شريط علوي */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--ink);
  color: var(--white);
  padding: 13px 16px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .brand .mark {
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--gold-600);
  color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800; font-size: 14px;
  flex-shrink: 0;
}
.topbar .brand .name { font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }
.topbar .logout {
  font-size: 12.5px;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
  padding: 7px 12px;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 8px;
  transition: border-color .15s ease, color .15s ease;
}
.topbar .logout:active { border-color: rgba(255,255,255,0.5); color: var(--white); }

/* شريط تنقل سفلي */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--white);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  position: relative;
  transition: color .15s ease;
}
.bottomnav a.active { color: var(--teal-700); }
.bottomnav a.active::before {
  content: ""; position: absolute; top: 0; right: 30%; left: 30%; height: 2.5px;
  background: var(--teal-700); border-radius: 0 0 3px 3px;
}
.bottomnav a:active { opacity: .65; }
.bottomnav svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }

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

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* بطاقة إحصائية بحد جانبي - أسلوب دفتري بدل الصناديق الملوّنة */
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-right: 3px solid var(--teal-600);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.stat .num { font-family: var(--font-display); font-size: 21px; font-weight: 800; color: var(--ink); line-height: 1.2; }
.stat .lbl { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.stat.stat-gold { border-right-color: var(--gold-600); }

h1, h2, h3 { margin: 0 0 4px; color: var(--ink); font-family: var(--font-display); font-weight: 800; }
h1 { font-size: 19px; margin-bottom: 14px; }
h2 { font-size: 15px; margin-bottom: 12px; }
p { line-height: 1.7; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.page-head h1 { margin-bottom: 0; }
.page-head .count { font-size: 13px; color: var(--ink-soft); font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .12s ease, background .12s ease;
  width: 100%;
  font-family: var(--font-body);
}
.btn:active { opacity: .85; }
.btn-primary { background: var(--teal-700); color: var(--white); }
.btn-primary:active { background: var(--teal-900); }
.btn-secondary { background: var(--teal-100); color: var(--teal-700); }
.btn-sand { background: var(--gold-600); color: var(--white); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-outline { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn-sm { width: auto; padding: 9px 14px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-soft); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }
input[type=text], input[type=tel], input[type=password], input[type=number],
input[type=date], input[type=search], input[type=file], select, textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  font-size: 15px;
  background: var(--white);
  color: var(--ink);
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px var(--teal-100);
}
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; }
.switch { position: relative; width: 44px; height: 25px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px;
  transition: background .2s ease; cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; width: 19px; height: 19px; right: 3px; top: 3px;
  background: var(--white); border-radius: 50%; transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--teal-600); }
.switch input:checked + .slider::before { transform: translateX(-19px); }

/* شارات الحالة: نقطة + نص بدل الحبّة الملوّنة الكبيرة */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { color: var(--success); }
.badge-danger { color: var(--danger); }
.badge-muted { color: var(--ink-soft); }
.badge-sand { color: var(--gold-600); }

.tabs { display: flex; gap: 2px; border-bottom: 1.5px solid var(--line); margin-bottom: 16px; }
.tabs a { flex: 1; text-align: center; padding: 10px 8px; font-size: 13.5px; font-weight: 700; color: var(--ink-soft); border-bottom: 2.5px solid transparent; margin-bottom: -1.5px; transition: all .15s ease; }
.tabs a.active { color: var(--teal-700); border-bottom-color: var(--teal-700); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-size: 11.5px; font-weight: 700; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.table-wrap table { margin: 0; }
.table-wrap th:first-child, .table-wrap td:first-child { padding-right: 14px; }

.flash { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13.5px; font-weight: 600; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

.empty { text-align: center; padding: 48px 16px; color: var(--ink-soft); font-size: 14px; }

.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,33,31,0.5);
  display: none; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--white); border-radius: 18px 18px 0 0; width: 100%; max-width: 480px;
  padding: 20px; max-height: 85vh; overflow-y: auto;
}
@media (min-width: 560px) {
  .modal { border-radius: var(--radius); margin-bottom: 40px; }
}

.fab {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 16px;
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--ink);
  color: var(--white); display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg); z-index: 25; border: none; cursor: pointer;
}
.fab:active { opacity: .85; }
.fab svg { width: 22px; height: 22px; }

/* صف دفتري مسطّح للقوائم الطويلة (شاليهات، مستخدمون، سجلات) */
.ledger { border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); overflow: hidden; }
.ledger-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  transition: background .1s ease;
}
.ledger-row:last-child { border-bottom: none; }
a.ledger-row:active { background: var(--stone-50); }
.ledger-row .title { font-weight: 700; font-size: 14.5px; color: var(--ink); }
.ledger-row .sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ledger-row .chev { color: var(--ink-soft); opacity: .6; flex-shrink: 0; }
.ledger-actions { display: flex; gap: 8px; margin-top: 12px; }

.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0; }
.list-item .title { font-weight: 700; font-size: 14.5px; }
.list-item .sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; display: flex; align-items: center; gap: 8px; }

.text-muted { color: var(--ink-soft); font-size: 13px; }
.center { text-align: center; }
.mt-0 { margin-top: 0; }

.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span { min-width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 13px; font-weight: 700; }
.pagination a { background: var(--white); border: 1px solid var(--line); color: var(--ink); }
.pagination span.current { background: var(--ink); color: var(--white); }

.scan-box {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #000; aspect-ratio: 1/1; max-width: 360px; margin: 0 auto 16px;
  box-shadow: var(--shadow-lg);
}
.scan-box video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 14%; border: 2px solid var(--gold-600); border-radius: 16px; }

.token-display {
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  font-size: 21px; font-weight: 700; letter-spacing: 3px;
  color: var(--ink);
}

.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 6px; background: var(--ink-soft); flex-shrink: 0; }
.status-dot--success { background: var(--success); }
.status-dot--danger { background: var(--danger); }

/* شاشة الدخول */
.auth-shell { min-height: 100vh; background: var(--ink); display: flex; align-items: center; }
.auth-card { max-width: 400px; margin: 0 auto; padding: 32px 20px; width: 100%; }
.auth-seal {
  width: 64px; height: 64px; border-radius: 16px; background: var(--gold-600);
  color: var(--ink); font-family: var(--font-display); font-weight: 800; font-size: 24px;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 20px;
}
.auth-title { color: var(--white); text-align: center; font-size: 19px; margin-bottom: 4px; }
.auth-sub { color: rgba(255,255,255,0.6); text-align: center; font-size: 13px; margin: 0 0 28px; }
.auth-form { background: var(--white); border-radius: var(--radius); padding: 22px; }
