/* =============================================================
   سيستم متابعة المهام والحملات — ستايلات عامة (RTL)
   ============================================================= */
:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --ink: #1c2333;
  --muted: #68708a;
  --line: #e4e8f0;
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --brand-soft: #eef0fe;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --info: #1d4ed8;
  --info-soft: #e9effd;
  --side: #171d2d;
  --side-ink: #c6cddd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Cairo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}
body.no-scroll { overflow: hidden; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { line-height: 1.3; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); font-weight: 700; }
.mono { font-variant-numeric: tabular-nums; }
.loading { text-align: center; color: var(--muted); padding: 60px 16px; }

/* ================= الهيكل ================= */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  flex: none;
  background: var(--side);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-logo { font-size: 22px; background: var(--brand); width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; flex: none; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; opacity: .55; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--side-ink); font-weight: 500; font-size: 14px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav-ico { width: 22px; text-align: center; }

.side-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.07); display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; gap: 10px; align-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.user-name { color: #fff; font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; opacity: .55; }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 18px; margin: 0; flex: 1; }
.topbar-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.menu-btn { display: none; }

.content { padding: 22px; max-width: 1200px; width: 100%; margin: 0 auto; }

.scrim { position: fixed; inset: 0; background: rgba(15,20,35,.45); opacity: 0; pointer-events: none; transition: .2s; z-index: 40; }
.scrim.show { opacity: 1; pointer-events: auto; }

/* ================= بطاقات ================= */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15.5px; }
.dash-grid .card { margin-bottom: 0; }
.card-overdue { background: linear-gradient(180deg, #fff5f5, #fff 70%); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border-top: 3px solid var(--brand); }
.stat-card.sc-danger { border-top-color: var(--danger); }
.stat-card.sc-warn { border-top-color: var(--warn); }
.stat-card.sc-muted { border-top-color: #c3c9d6; }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-ico { font-size: 20px; }
.stat-num { font-size: 26px; font-weight: 800; }
.stat-num small { font-size: 15px; color: var(--muted); font-weight: 600; }
.stat-label { color: var(--muted); font-size: 13px; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ================= أدوات الشاشات ================= */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; min-width: 180px; }
.w-auto { width: auto; }

.input, input, select, textarea { font-family: inherit; font-size: 14px; }
.input {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; background: #fff; color: var(--ink);
}
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.inline-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: #3c4358; }

.seg { display: inline-flex; background: #e8ebf3; border-radius: 11px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16,24,40,.12); }

/* ================= أزرار ================= */
.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  font-family: inherit; transition: background .15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f4f6fb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 15px; padding: 6px; border-radius: 8px; line-height: 1; }
.icon-btn:hover { background: #eef0f5; }

/* ================= الجداول ================= */
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 680px; }
.table th {
  text-align: right; font-size: 12px; color: var(--muted); font-weight: 700;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  background: #fafbfd; white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #f8faff; }
.cell-strong { font-weight: 600; }
.cell-sub { font-size: 12px; margin-top: 2px; }
.actions-cell { white-space: nowrap; }
.row-late { background: var(--danger-soft) !important; }
.row-done .cell-strong { text-decoration: line-through; color: var(--muted); }

/* ================= شارات وعناصر صغيرة ================= */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #eef0f5; color: var(--muted); }

.chip { display: inline-block; background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: 2px 8px; font-size: 12px; margin: 1px; white-space: nowrap; }
.chip-soft { background: #eef0f5; color: var(--muted); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.dot-high { background: var(--danger); }
.dot-medium { background: #f59e0b; }
.dot-low { background: #94a3b8; }

.pill { background: var(--brand-soft); color: var(--brand); font-weight: 700; border-radius: 999px; min-width: 26px; height: 26px; display: grid; place-items: center; font-size: 12.5px; padding: 0 8px; flex: none; }
.repeat-ico { font-size: 12px; }

/* ================= صفوف التاسكات (الداشبورد) ================= */
.task-list { margin: 0 -8px; }
.task-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-bottom: 1px solid var(--line); border-radius: 10px; }
.task-row:last-child { border-bottom: 0; }
.task-row.task-late { background: var(--danger-soft); }
.task-row.task-done .task-title { text-decoration: line-through; color: var(--muted); }
.check {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #c3c9d6; background: #fff; cursor: pointer;
  color: transparent; font-size: 13px; line-height: 1;
  flex: none; margin-top: 2px; display: grid; place-items: center;
  transition: all .15s;
}
.check:hover { border-color: var(--ok); }
.check.checked { background: var(--ok); border-color: var(--ok); color: #fff; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 600; }
.task-sub { color: var(--muted); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; align-items: center; }
.task-sub .sep { opacity: .5; }
.status-select { font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: #fff; color: var(--ink); flex: none; cursor: pointer; }

/* ================= صفوف عامة (داشبورد/إعدادات) ================= */
.row-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row-item:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { font-size: 12.5px; margin-top: 3px; }
.more-note { color: var(--muted); font-size: 12.5px; text-align: center; padding-top: 10px; }
.empty-state { text-align: center; color: var(--muted); padding: 28px 10px; }
.empty-ico { font-size: 30px; margin-bottom: 8px; }

/* ================= النماذج ================= */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #3c4358; }
label input, label select, label textarea, label .input { font-weight: 400; }
input, select, textarea { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; font-weight: 400; }

.check-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.check-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; font-weight: 500;
  cursor: pointer; background: #fff; color: var(--ink);
}
.check-chip input { display: none; }
.check-chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 700; }
.check-chip input:disabled { cursor: not-allowed; }

/* مفتاح تفعيل/تعطيل */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #cbd2e0; border-radius: 999px; transition: .2s; cursor: pointer; }
.slider:before { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 3px; right: 3px; transition: .2s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider:before { transform: translateX(-18px); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: #3c4358; }

.platform-add { display: flex; gap: 10px; margin-bottom: 10px; }

/* ================= المودال ================= */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,20,35,.5); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-wide { max-width: 680px; }
.modal-sm { max-width: 400px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }
.confirm-body p { font-weight: 600; margin: 0 0 16px; }
.confirm-actions { display: flex; gap: 10px; }

/* ================= التوست ================= */
#toast-box { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(340px, 80vw); }
.toast { background: #1c2333; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); animation: pop .2s ease; }
.toast-err { background: var(--danger); }
.toast.out { opacity: 0; transition: .3s; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ================= شاشة الدخول ================= */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(160deg, #171d2d 0%, #232b40 55%, #2d3a5f 100%);
}
.auth-card { background: #fff; border-radius: 20px; padding: 34px 30px; width: 100%; max-width: 400px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.auth-logo { font-size: 42px; text-align: center; }
.auth-card h2 { text-align: center; margin: 10px 0 4px; font-size: 22px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }

/* ================= موبايل ================= */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 0;
    z-index: 50; width: 264px;
    transform: translateX(100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: -8px 0 30px rgba(0,0,0,.25); }
  .menu-btn { display: inline-grid; }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .page-title { font-size: 16px; }
  .topbar-date { display: none; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .toolbar .grow { min-width: 140px; }
  .status-select { width: 105px; }
}
