:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e3e8ee;
  --text: #16202b;
  --muted: #6b7a8d;
  --brand: #0f9d58;
  --brand-dark: #0b7a44;
  --danger: #d93025;
  --warn: #f4a300;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 32, 48, .08);
}

* { box-sizing: border-box; }

/* لازم تسبق أي display صريح، وإلا خاصية hidden ما تشتغل على .login و .stats */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 14px;
}

h1, h2 { margin: 0 0 8px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 10px; }
.brand { color: var(--brand); font-weight: 800; font-size: 22px; }

/* ---------- الدخول ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card input[type="email"],
.login-card input[type="password"] { text-align: right; letter-spacing: normal; }
.login-card input[type="email"] { direction: ltr; text-align: left; }
.setup-note { margin: 14px 0 0; }

/* تبويبا طريقة الدخول */
.login-tabs {
  display: flex;
  gap: 4px;
  margin-top: 18px;
  background: #f2f4f7;
  border-radius: 10px;
  padding: 4px;
}
.login-tab {
  flex: 1;
  border: 0;
  background: none;
  padding: 8px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.login-tab.active { background: #fff; color: var(--text); font-weight: 700; box-shadow: var(--shadow); }
.login-card label { display: block; text-align: right; margin: 16px 0 6px; color: var(--muted); }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  text-align: center;
  letter-spacing: 1px;
}

/* ---------- التخطيط ---------- */
/* الشريط العلوي والتبويبات يلزمون مكانهم عند تمرير الجداول الطويلة */
.chrome { position: sticky; top: 0; z-index: 40; background: var(--surface); }

.topbar {
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.brand-row { display: flex; align-items: baseline; gap: 10px; }
.dash::before { content: "— "; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.who {
  color: var(--muted);
  background: #f2f4f7;
  border-radius: 999px;
  padding: 5px 12px;
  margin-left: 4px;
  white-space: nowrap;
}

/* الأيقونات ترث لون الزر، فتتلوّن معه بحالة التفعيل والتحويم */
.ico {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn { display: inline-flex; align-items: center; gap: 6px; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 20px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  background: none;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  border-radius: 8px 8px 0 0;
}
.tab:hover { background: #f7f9fa; color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; background: none; }

/* على الشاشات الضيقة تبقى الأيقونات وتختفي الكلمات من أزرار الشريط العلوي */
@media (max-width: 620px) {
  .topbar { padding: 10px 14px; }
  .tabs { padding: 8px 14px 0; }
  .icon-btn span { display: none; }
  .who { display: none; }
}

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

/* ---------- بطاقات الأرقام ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat .value { font-size: 22px; font-weight: 700; }
.stat .value.accent { color: var(--brand); }

/* ---------- المخطط ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
/* max-width يمنع تمدد الأعمدة لما تكون البيانات يوم أو يومين فقط */
.bar-wrap { flex: 1; max-width: 56px; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar {
  width: 100%;
  background: var(--brand);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: opacity .15s;
}
.bar:hover { opacity: .75; }
.bar-label { font-size: 10px; color: var(--muted); white-space: nowrap; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr:hover { background: #fafbfc; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #eef1f4;
  color: var(--muted);
}
.badge.ok      { background: #e6f4ea; color: var(--brand-dark); }
.badge.warn    { background: #fef3e0; color: #a76a00; }
.badge.danger  { background: #fce8e6; color: var(--danger); }
.badge.info    { background: #e8f0fe; color: #1967d2; }

/* ---------- الأزرار والحقول ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}
.btn:hover { background: #f7f9fa; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; width: 100%; margin-top: 14px; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: none; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #f3c6c2; }
/* زر الإجراء الرئيسي داخل النوافذ — أخضر بدون العرض الكامل تبع .primary */
.btn.primary-action { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary-action:hover { background: var(--brand-dark); }

.select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: var(--surface);
}

/* ---------- نموذج التسعيرة ---------- */
.pricing-row {
  display: grid;
  grid-template-columns: 110px repeat(6, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.pricing-row .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pricing-row label { font-size: 11px; color: var(--muted); }
.pricing-row input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}
.pricing-name { font-weight: 700; }

@media (max-width: 860px) {
  .pricing-row { grid-template-columns: repeat(2, 1fr); }
  .pricing-name { grid-column: 1 / -1; }
}

/* ---------- بطاقة رابط الدعوة ---------- */
.invite-card { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.invite-text { flex: 1; min-width: 260px; }
.invite-row { display: flex; gap: 8px; margin-top: 12px; }
.invite-row input {
  flex: 1;
  min-width: 0;
  direction: ltr;
  text-align: left;
  font-family: Consolas, monospace;
  font-size: 13px;
}
.invite-qr {
  width: 150px;
  height: 150px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

/* ---------- نافذة ملف السائق ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 32, 48, .55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px 16px;
  margin-bottom: 20px;
}
.detail-item { font-size: 13px; }
.detail-item .k { color: var(--muted); font-size: 11px; display: block; }
.detail-item .v { font-weight: 600; }

.docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.doc-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.doc-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: #f0f2f5;
  display: block;
  cursor: zoom-in;
}
.doc-card .pdf-mark {
  height: 130px;
  display: grid;
  place-items: center;
  background: #f0f2f5;
  color: var(--muted);
  font-size: 13px;
}
.doc-card-body { padding: 10px; }
.doc-card-name { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.doc-card-actions { display: flex; gap: 6px; margin-top: 8px; }
.doc-card-actions .btn { flex: 1; padding: 5px; font-size: 12px; }

.modal-footer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.modal-footer .btn { flex: 1; min-width: 120px; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .85);
  display: grid;
  place-items: center;
  z-index: 70;
  cursor: zoom-out;
  padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; }

/* ---------- التنبيه ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: #16202b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
  z-index: 50;
}
.toast.bad { background: var(--danger); }

/* ---------- صفوف النماذج ---------- */
.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
}
.form-row .field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 200px; }
.form-row label { font-size: 12px; color: var(--muted); }
.select.block { width: 100%; display: block; margin-bottom: 12px; }
.modal-body > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.modal-box.narrow { max-width: 420px; }

.link-box {
  margin-top: 16px;
  padding: 14px;
  border: 1px dashed var(--brand);
  border-radius: var(--radius);
  background: #f2fbf5;
}
.link-box .invite-row { margin-top: 8px; }

/* الصف المميّز بالجداول — مستحقات كبيرة مثلاً */
tbody tr.hot td { background: #fffaf0; }
.num { font-variant-numeric: tabular-nums; font-weight: 600; }
