* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #6b7688;
  --border: #e3e8ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --wa: #25d366;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,.08);
}

html { font-size: 15px; }
body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ===== تسجيل الدخول ===== */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  padding: 16px;
}
.login-box {
  background: var(--card); border-radius: 16px; padding: 36px 32px;
  width: 100%; max-width: 380px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.login-box h1 { font-size: 1.8rem; margin-bottom: 4px; }
.login-box h1 span, .brand span { color: var(--primary); }
.login-box p { margin-bottom: 24px; }
.login-box input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 1rem;
}
.error-msg { color: var(--danger); margin-top: 12px; min-height: 1.2em; font-size: .9rem; }

/* ===== الهيدر ===== */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 58px; position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 800; font-size: 1.15rem; white-space: nowrap; }
#nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: none; border: none; padding: 8px 14px; cursor: pointer;
  font-size: .95rem; color: var(--muted); border-radius: 8px; font-family: inherit;
}
.nav-btn:hover { background: var(--bg); }
.nav-btn.active { color: var(--primary); background: #eff4ff; font-weight: 700; }
.user-area { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 600; font-size: .9rem; }
.mini-shift {
  background: #ecfdf5; color: var(--success); border: 1px solid #bbf7d0;
  padding: 4px 10px; border-radius: 20px; font-size: .85rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ===== عام ===== */
main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.view h2 { margin-bottom: 18px; }
.view h3 { margin: 18px 0 12px; }
.view-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.view-head h2, .view-head h3 { margin: 0; }
.actions { display: flex; gap: 8px; }

.btn {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: var(--radius); cursor: pointer;
  font-size: .92rem; font-family: inherit; font-weight: 600;
  transition: .15s;
}
.btn:hover { filter: brightness(.96); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 32px; font-size: 1.05rem; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-wa {
  background: var(--wa); border-color: var(--wa); color: #fff;
  text-decoration: none; display: inline-block; padding: 5px 12px; font-size: .85rem;
  border-radius: 8px; margin-inline-start: 8px;
}

/* ===== الإحصائيات ===== */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  text-align: center; box-shadow: var(--shadow); border-top: 4px solid var(--primary);
}
.stat-card.st-new { border-top-color: #3b82f6; }
.stat-card.st-contacted { border-top-color: #06b6d4; }
.stat-card.st-subscribed { border-top-color: var(--success); }
.stat-card.st-not-interested { border-top-color: var(--danger); }
.stat-card.st-no-answer { border-top-color: var(--warning); }
.stat-card.st-calls { border-top-color: #8b5cf6; }
.stat-num { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* ===== الفلاتر والجداول ===== */
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 200px; }
input, select, textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .95rem; font-family: inherit; background: var(--card); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }

.table-wrap {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--border); font-size: .92rem; }
th { background: #f8fafc; color: var(--muted); font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }
td.phone { direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* شارات الحالة */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: .8rem; font-weight: 700; white-space: nowrap;
}
.badge.new { background: #dbeafe; color: #1d4ed8; }
.badge.contacted { background: #cffafe; color: #0e7490; }
.badge.subscribed { background: #16a34a; color: #fff; }
.badge.not_interested { background: #fee2e2; color: #b91c1c; }
.badge.no_answer { background: #fef3c7; color: #b45309; }

/* المشترك: السطر كامل أخضر */
tbody tr.row-subscribed { background: #dcfce7; }
tbody tr.row-subscribed:hover { background: #bbf7d0; }
tbody tr.row-subscribed td { border-bottom-color: #bbf7d0; }
.badge.active { background: #dcfce7; color: #15803d; }
.badge.off { background: #f1f5f9; color: var(--muted); }

/* اختيار الفترة من/إلى */
.range-picker { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: .9rem; color: var(--muted); }
.range-picker label { display: flex; align-items: center; gap: 6px; font-weight: 600; }

/* صف الإجمالي */
tfoot td { font-weight: 800; background: #f8fafc; border-top: 2px solid var(--border); padding: 11px 14px; text-align: right; font-size: .92rem; }

/* شريط التحويل الجماعي */
.bulk-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #eff4ff; border: 1px solid #bfdbfe; border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px; font-size: .92rem;
}
.check-col { width: 36px; }
.lead-check, #select-all { width: 17px; height: 17px; cursor: pointer; }

/* ===== الوردية ===== */
.shift-panel {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px; text-align: center; margin-bottom: 10px;
}
.shift-timer {
  font-size: 3.4rem; font-weight: 800; font-variant-numeric: tabular-nums;
  direction: ltr; letter-spacing: 2px;
}
.shift-info { color: var(--muted); margin: 10px 0 20px; }
.shift-info b { color: var(--text); }

/* ===== النوافذ المنبثقة ===== */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
/* نافذة التعديل/الإضافة تظهر فوق نافذة التفاصيل */
#lead-modal { z-index: 150; }
/* تعديل الوردية فوق نافذة الورديات */
#shift-edit-modal { z-index: 150; }
/* بوابة الوردية فوق الكل */
#shift-gate-modal { z-index: 200; }
/* تنبيه الخمول فوق كل شيء */
#idle-modal { z-index: 250; }
#idle-modal .btn-danger { margin-top: 10px; }
.modal-box {
  background: var(--card); border-radius: 14px; padding: 22px;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
}
.modal-lg { max-width: 560px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
.modal form label { display: block; margin-bottom: 12px; font-size: .88rem; font-weight: 600; color: var(--muted); }
.modal form input, .modal form select, .modal form textarea { width: 100%; margin-top: 5px; }

/* تفاصيل الزبون */
.detail-info { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; font-size: .95rem; }
.detail-info select { width: auto; }
.note-form { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 16px; }
.note-form textarea { flex: 1; resize: vertical; }
.notes-list { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }
.note-item { background: var(--bg); border-radius: var(--radius); padding: 10px 14px; }
.note-item .note-meta { font-size: .78rem; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
.note-item .note-text { white-space: pre-wrap; font-size: .92rem; }

/* بوابة الوردية */
.shift-gate { text-align: center; }
.shift-gate h3 { font-size: 1.3rem; margin-bottom: 6px; }
.shift-gate p { margin-bottom: 20px; }
.shift-gate .btn-ghost { margin-top: 10px; }

/* ===== تنبيه ===== */
.toast {
  position: fixed; bottom: 24px; right: 50%; transform: translateX(50%);
  background: var(--text); color: #fff; padding: 12px 22px; border-radius: 30px;
  z-index: 200; font-size: .92rem; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); }

/* ===== موبايل ===== */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  #nav { order: 3; width: 100%; overflow-x: auto; }
  .shift-timer { font-size: 2.4rem; }
  main { padding: 16px 12px 50px; }
}
