/* =====================================================================
   منصة محافظ العطاء — نظام التصميم المشترك (Design System)
   ملتزم بالمرجع البصري الرسمي: docs/ui-reference/main-dashboard-reference.png
   RTL أولًا · Mobile-first · بطاقات بيضاء · تدرّج بنفسجي/أزرق · ظلال خفيفة.
   ⚠️ واجهات هيكلية — Empty States، لا بيانات وهمية.
   يدعم LTR هيكليًا عبر [dir="ltr"] (Phase 3).
   ===================================================================== */

:root {
  /* الهوية اللونية (مستخلصة من المرجع البصري) */
  --brand-700: #3730a3;
  --brand-600: #4f46e5;
  --brand-500: #6366f1;
  --brand-100: #eef0ff;
  --sidebar-grad-a: #4f46e5;
  --sidebar-grad-b: #362f9e;

  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1f2340;
  --ink-soft: #4a4f6b;
  --muted: #8b8fa7;
  --line: #ececf4;

  /* ألوان حالات مستمدة من روح المرجع (لا ألوان عشوائية) */
  --ok-100: #e7f7ef;   --ok-600: #12a366;
  --warn-100: #fdf3e3; --warn-600: #d98b0b;
  --danger-100: #fdecec; --danger-600: #d64545;
  --info-100: #eaf1fd;   --info-600: #3b6fd4;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(31, 35, 64, 0.06);
  --shadow-sm: 0 2px 8px rgba(31, 35, 64, 0.05);

  --sidebar-w: 260px;
  --font: "Segoe UI", "Tahoma", "Noto Naskh Arabic", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}
[dir="ltr"] body, body[dir="ltr"] { direction: ltr; }

a { color: inherit; text-decoration: none; }

/* ---------- التخطيط العام (Shell) ---------- */
/* في RTL يكون المسار الأول (sidebar) في أقصى اليمين، والمحتوى في اليسار. */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- الشريط الجانبي الأيمن ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--sidebar-grad-a), var(--sidebar-grad-b));
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
  padding: 6px 8px 14px;
}
.brand .logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px;
}
.brand .brand-text b { display: block; font-size: 18px; }
.brand .brand-text span { font-size: 12px; opacity: 0.8; }

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav .nav-group-title {
  font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  opacity: .6; padding: 12px 14px 4px;
}
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.85);
  font-size: 15px;
  transition: background 0.15s, color 0.15s;
}
.nav a .ic { width: 20px; text-align: center; opacity: 0.9; }
.nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.nav a.active {
  background: #fff; color: var(--brand-700); font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.sidebar-footer {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 13px;
}
.sidebar-footer .status { display: flex; align-items: center; gap: 8px; opacity: 0.9; }
.sidebar-footer .dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; }

/* غطاء التعتيم للـ Drawer في الجوال */
.scrim { display: none; }

/* ---------- المحتوى الرئيسي ---------- */
.main { padding: 22px 26px; min-width: 0; overflow-x: hidden; }
.page-head h1 { overflow-wrap: anywhere; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 22px;
}
.topbar .user { display: flex; align-items: center; gap: 10px; }
.topbar .avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-600);
  display: grid; place-items: center; font-weight: 700;
}
.topbar .user b { display: block; font-size: 14px; }
.topbar .user span { font-size: 12px; color: var(--muted); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; cursor: pointer;
  color: var(--ink-soft); position: relative;
}
.icon-btn .badge-dot {
  position: absolute; top: 6px; inset-inline-end: 8px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--danger-600); color: #fff; font-size: 10px;
  display: grid; place-items: center; font-weight: 700;
}

.search {
  flex: 1; max-width: 420px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px;
  color: var(--muted); font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.btn {
  border: 0; cursor: pointer;
  background: var(--brand-600); color: #fff;
  padding: 11px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: var(--card); color: var(--brand-600); border: 1px solid var(--line); box-shadow: none; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.danger { background: var(--danger-600); }
.btn.block { width: 100%; justify-content: center; }
.spacer { flex: 1; }

.page-head { margin-bottom: 18px; display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.page-head .page-head-text { min-width: 0; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* مسار التنقل (Breadcrumb) */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a:hover { color: var(--brand-600); }
.crumbs .sep { margin: 0 6px; opacity: .6; }

/* ---------- البطاقات ---------- */
.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(4, 1fr); }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.grid.two { grid-template-columns: repeat(2, 1fr); }
.grid.wide-narrow { grid-template-columns: 2fr 1fr; }

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .sub { color: var(--muted); font-size: 13px; }
.card .card-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--brand-100); color: var(--brand-600);
  display: grid; place-items: center; font-size: 18px; flex: none;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.card-head + .card-body { margin-top: 12px; }

/* ---------- بطاقة إحصائية (Stat) — Empty State بدل الأرقام الوهمية ---------- */
.stat .card-head { margin-bottom: 10px; }
.stat .stat-value {
  font-size: 26px; font-weight: 700; color: var(--ink);
  min-height: 34px; display: flex; align-items: center; gap: 8px;
}
.stat .stat-value.is-empty {
  font-size: 14px; font-weight: 500; color: var(--muted);
}
.stat .stat-value.is-empty::before { content: "—"; font-size: 20px; opacity: .6; }
.stat .stat-caption { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- الشارات (Badges) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.6;
}
.badge.ok { background: var(--ok-100); color: var(--ok-600); }
.badge.warn { background: var(--warn-100); color: var(--warn-600); }
.badge.danger { background: var(--danger-100); color: var(--danger-600); }
.badge.info { background: var(--info-100); color: var(--info-600); }
.badge.neutral { background: var(--brand-100); color: var(--brand-600); }

/* ---------- لافتات الحالة (State banners: loading/error/no-permission) ---------- */
.state {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.7;
}
.state .state-ic { font-size: 18px; flex: none; }
.state.loading { background: var(--info-100); color: var(--info-600); }
.state.error { background: var(--danger-100); color: var(--danger-600); }
.state.locked { background: var(--warn-100); color: var(--warn-600); }
.state.privacy { background: var(--brand-100); color: var(--brand-600); }

/* مؤشر تحميل بسيط */
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Empty State ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  padding: 40px 20px; gap: 12px; color: var(--muted);
}
.empty .empty-ic {
  width: 64px; height: 64px; border-radius: 18px;
  background: var(--brand-100); color: var(--brand-500);
  display: grid; place-items: center; font-size: 28px;
}
.empty h4 { margin: 0; color: var(--ink); font-size: 16px; }
.empty p { margin: 0; font-size: 14px; max-width: 460px; line-height: 1.7; }
.empty .btn { margin-top: 6px; }
.empty.small { padding: 24px 16px; }
.empty.small .empty-ic { width: 48px; height: 48px; font-size: 22px; border-radius: 14px; }

.section { margin-top: 20px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.section-title h2 { font-size: 17px; margin: 0; }
.section-title .sub { color: var(--muted); font-size: 13px; }

/* ---------- التبويبات (Tabs) ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs .tab {
  padding: 10px 16px; border-radius: 12px 12px 0 0; cursor: pointer;
  color: var(--ink-soft); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; border-bottom: 0; background: transparent;
}
.tabs .tab[aria-selected="true"] {
  color: var(--brand-600); background: var(--card);
  border-color: var(--line); box-shadow: var(--shadow-sm);
}
.tab-panel[hidden] { display: none; }

/* ---------- شريط أدوات/فلاتر ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.field { display: inline-flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field > span { color: var(--muted); }
.input, select.input, textarea.input {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; font: inherit; color: var(--ink);
  min-width: 160px;
}
textarea.input { min-height: 90px; resize: vertical; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-soft); font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--brand-100); color: var(--brand-600); border-color: var(--brand-100); }

/* ---------- الجداول (تتحول إلى Cards في الجوال) ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: start; color: var(--muted); font-weight: 600; font-size: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 12px; border-bottom: 1px solid var(--line); }
table.data tr:last-child td { border-bottom: 0; }
.list-cards { display: none; }

/* ---------- بطاقة عنصر قائمة (تُستخدم كبديل جوال أو مباشرة) ---------- */
.item-card {
  border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.item-card .item-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.item-card .item-row .k { color: var(--muted); }

/* ---------- الخط الزمني (Timeline) ---------- */
.timeline { position: relative; padding-inline-start: 26px; }
.timeline::before {
  content: ""; position: absolute; inset-inline-start: 9px; top: 4px; bottom: 4px;
  width: 2px; background: var(--line);
}
.tl-item { position: relative; padding: 0 0 20px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item .tl-dot {
  position: absolute; inset-inline-start: -26px; top: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-600);
  display: grid; place-items: center; font-size: 11px;
  border: 3px solid var(--card);
}
.tl-item .tl-title { font-weight: 600; font-size: 14px; }
.tl-item .tl-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- مسار المراحل (Stepper) ---------- */
.stepper { display: flex; gap: 8px; flex-wrap: wrap; }
.step {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  flex: 1; min-width: 90px; text-align: center;
}
.step .step-ic {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--brand-100); color: var(--brand-600);
  display: grid; place-items: center; font-size: 16px;
}
.step .step-label { font-size: 12px; color: var(--ink-soft); }

/* ---------- قائمة المرفقات ---------- */
.attach-list { display: flex; flex-direction: column; gap: 10px; }
.attach {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px;
}
.attach .att-ic {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  background: var(--brand-100); color: var(--brand-600);
  display: grid; place-items: center; font-size: 16px;
}
.attach .att-name { font-weight: 600; font-size: 14px; }
.attach .att-meta { color: var(--muted); font-size: 12px; }

/* ---------- بطاقة فرصة دعم (مجهّلة) ---------- */
.opp {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.opp .opp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.opp .opp-title { font-weight: 700; font-size: 15px; }
.opp .opp-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; font-size: 13px; }
.opp .opp-fields .k { color: var(--muted); }
.opp .opp-amount { font-size: 20px; font-weight: 700; color: var(--brand-600); }
.opp .privacy-note {
  font-size: 12px; color: var(--brand-600); background: var(--brand-100);
  padding: 8px 10px; border-radius: 10px; display: flex; gap: 8px; align-items: center;
}

/* ---------- التحليل الجغرافي الآمن (مجمّع فقط) ---------- */
.geo-bars { display: flex; flex-direction: column; gap: 12px; }
.geo-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; align-items: center; font-size: 13px; }
.geo-row .geo-name { color: var(--ink-soft); }
.geo-track { height: 10px; border-radius: 999px; background: var(--brand-100); overflow: hidden; }
.geo-fill { height: 100%; background: linear-gradient(90deg, var(--brand-500), var(--brand-600)); border-radius: 999px; }
.geo-val { color: var(--muted); font-variant-numeric: tabular-nums; }

/* رسم بياني كـ placeholder هيكلي (بلا أرقام وهمية) */
.chart-placeholder {
  height: 200px; border-radius: var(--radius-md);
  background:
    repeating-linear-gradient(0deg, var(--line) 0, var(--line) 1px, transparent 1px, transparent 40px);
  display: grid; place-items: center;
}

/* ---------- إشعارات (Toast) ---------- */
.toast-wrap {
  position: fixed; inset-block-end: 20px; inset-inline-start: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: 10px; max-width: min(92vw, 380px);
}
.toast {
  background: var(--card); border: 1px solid var(--line);
  border-inline-start: 4px solid var(--brand-600);
  border-radius: var(--radius-md); box-shadow: var(--shadow);
  padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in .2s ease;
}
.toast.ok { border-inline-start-color: var(--ok-600); }
.toast.warn { border-inline-start-color: var(--warn-600); }
.toast.danger { border-inline-start-color: var(--danger-600); }
.toast .toast-ic { font-size: 16px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- launcher ---------- */
.launch-wrap { max-width: 980px; margin: 0 auto; padding: 40px 20px; }
.launch-head { text-align: center; margin-bottom: 30px; position: relative; }
.launch-head .logo {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 14px;
  background: linear-gradient(180deg, var(--sidebar-grad-a), var(--sidebar-grad-b));
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 22px;
}
.launch-head h1 { margin: 0; font-size: 26px; }
.launch-head p { color: var(--muted); }
.portal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.portal-card {
  background: var(--card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 22px; display: block;
  border: 1px solid transparent; transition: border-color .15s, transform .15s;
}
.portal-card:hover { border-color: var(--brand-500); transform: translateY(-2px); }
.portal-card.soon { opacity: .75; }
.portal-card .card-icon { margin-bottom: 12px; }
.portal-card b { display: block; font-size: 16px; margin-bottom: 4px; }
.portal-card span { color: var(--muted); font-size: 13px; line-height: 1.6; }
.lang-toggle {
  position: absolute; inset-inline-end: 0; top: 0;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-soft);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer;
}

/* ---------- الجوال (Mobile-first responsive) ---------- */
.menu-toggle { display: none; }

@media (max-width: 1000px) {
  .grid.cards { grid-template-columns: repeat(2, 1fr); }
  .grid.wide-narrow, .grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 0 0 auto; z-index: 50;
    width: min(80vw, var(--sidebar-w));
    transform: translateX(100%); transition: transform .2s;
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .scrim {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(31, 35, 64, .35);
  }
  .menu-toggle {
    display: grid; place-items: center;
    width: 42px; height: 42px; border-radius: 12px;
    background: var(--card); border: 1px solid var(--line);
    color: var(--brand-600); cursor: pointer; flex: none;
  }
  .grid.two { grid-template-columns: 1fr; }
  .search { max-width: none; }

  /* الجداول → بطاقات */
  table.data { display: none; }
  .list-cards { display: grid; gap: 12px; }

  .opp .opp-fields { grid-template-columns: 1fr; }
  .geo-row { grid-template-columns: 90px 1fr auto; }
}

@media (max-width: 560px) {
  html, body { overflow-x: hidden; }
  .main { padding: 16px; }
  .grid.cards { grid-template-columns: 1fr; }
  .portal-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .topbar .user span { display: none; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .page-head h1 { font-size: 19px; }
  .toast-wrap { inset-inline: 12px auto; inset-block-end: 12px; }
}

/* ---------- بطاقة المصادقة (تسجيل الدخول / تغيير كلمة المرور) — Phase 7.2.1 ---------- */
.auth-card {
  max-width: 420px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(20, 20, 60, .06);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-card .field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.auth-card .field input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: var(--bg);
}
.auth-card .btn-primary {
  padding: 11px 16px;
  border: none;
  border-radius: 10px;
  background: var(--brand-600);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.auth-card .btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.auth-card .btn-secondary {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--brand-600);
  font: inherit;
  cursor: pointer;
}
.auth-error {
  color: var(--danger-600, #c0392b);
  background: rgba(192, 57, 43, .08);
  border: 1px solid rgba(192, 57, 43, .2);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
}
.auth-ok {
  color: #1e7e34;
  background: rgba(30, 126, 52, .08);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
}
.auth-hint { color: var(--muted); font-size: 12px; text-align: center; margin: 0; }
