:root {
  --blue-50: #f0f8ff;
  --blue-100: #e1f0ff;
  --blue-200: #c3e0fc;
  --blue-300: #9bcdfb;
  --blue-400: #6bb3f7;
  --blue-500: #3d97ee;
  --blue-600: #2678cc;
  --blue-700: #1c5da3;
  --ink: #1c2b3a;
  --muted: #6b7f92;
  --bg: #f4f9fd;
  --card: #ffffff;
  --border: #dfeaf4;
  --green: #29b779;
  --amber: #e8a33d;
  --red: #e35d5d;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(61, 151, 238, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', Arial, sans-serif;
  direction: rtl;
}

button {
  font-family: inherit;
  cursor: pointer;
}

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

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue-400); box-shadow: 0 0 0 3px var(--blue-100); }

.hidden { display: none !important; }

/* ---------- Auth screens ---------- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--blue-50), var(--blue-100));
}
.auth-card {
  width: 380px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(38, 120, 204, 0.15);
  padding: 32px;
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.auth-logo .mark {
  width: 42px; height: 42px;
  display: block;
}
.auth-logo .title { font-size: 20px; font-weight: 700; color: var(--blue-700); }
.auth-card h2 { margin: 0 0 4px; font-size: 18px; }
.auth-card p.sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card .btn-primary { margin-top: 6px; }
.auth-switch { margin-top: 16px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-switch a { color: var(--blue-600); font-weight: 600; }
.auth-error { background: #fdeaea; color: var(--red); padding: 8px 12px; border-radius: 8px; font-size: 13px; }

/* ---------- App shell ---------- */
#app-shell { display: flex; min-height: 100vh; }

.navrail {
  width: 84px;
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  gap: 6px;
  flex-shrink: 0;
}
.navrail .brand {
  width: 42px; height: 42px;
  display: block;
  margin-bottom: 24px;
}
.nav-item {
  width: 60px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 11px;
  border: none;
  background: transparent;
}
.nav-item .ic { font-size: 20px; }
.nav-item.active { background: var(--blue-100); color: var(--blue-700); }
.nav-item:hover { background: var(--blue-50); color: var(--blue-600); }
.navrail .spacer { flex: 1; }
.nav-item.logout { color: var(--red); }

.main {
  flex: 1;
  padding: 28px 36px;
  overflow-y: auto;
  max-width: 100%;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.topbar h1 { font-size: 22px; margin: 0; }
.topbar .org { color: var(--muted); font-size: 13px; }

.btn-primary {
  background: linear-gradient(135deg, var(--blue-400), var(--blue-600));
  color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(61, 151, 238, 0.35);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary {
  background: var(--blue-50); color: var(--blue-700); border: 1px solid var(--blue-200);
  border-radius: 10px; padding: 9px 16px; font-size: 14px; font-weight: 600;
}
.btn-ghost { background: transparent; border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; font-size: 13px; color: var(--muted); }
.btn-danger { background: #fdeaea; color: var(--red); border: 1px solid #f6c9c9; border-radius: 8px; padding: 6px 12px; font-size: 12px; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; display: flex; align-items: center; gap: 14px;
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  flex-shrink: 0;
}
.stat-icon.blue { background: var(--blue-100); color: var(--blue-600); }
.stat-icon.green { background: #e2f7ec; color: var(--green); }
.stat-icon.amber { background: #fdf1de; color: var(--amber); }
.stat-icon.red { background: #fdeaea; color: var(--red); }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Dialer start card ---------- */
.dialer-card {
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  border-radius: var(--radius); padding: 28px 32px; color: #fff;
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px;
  box-shadow: 0 10px 30px rgba(38, 120, 204, 0.28);
}
.dialer-card .left h2 { margin: 0 0 6px; font-size: 20px; }
.dialer-card .left p { margin: 0; opacity: 0.85; font-size: 13px; }
.dialer-card select {
  margin-top: 14px; min-width: 220px; border: none;
}
.dialer-card .start-btn {
  background: #fff; color: var(--blue-700); border: none; border-radius: 30px;
  padding: 16px 34px; font-size: 16px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.section-title { font-size: 15px; font-weight: 700; margin: 0 0 14px; }

/* ---------- Tables / grid ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: right; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 12px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--blue-50); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.new { background: var(--blue-100); color: var(--blue-700); }
.badge.interested { background: #e2f7ec; color: var(--green); }
.badge.not_interested { background: #fdeaea; color: var(--red); }
.badge.closed { background: #e2f7ec; color: var(--green); }
.badge.callback { background: #fdf1de; color: var(--amber); }
.badge.no_answer { background: #f1f1f1; color: var(--muted); }
.badge.in_progress { background: var(--blue-200); color: var(--blue-700); }
.badge.invalid { background: #f1f1f1; color: var(--muted); }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar input[type=search] { flex: 1; min-width: 180px; }

/* ---------- Campaign cards ---------- */
.campaign-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.campaign-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.campaign-card h3 { margin: 0 0 4px; font-size: 16px; }
.campaign-card .desc { color: var(--muted); font-size: 12px; margin-bottom: 14px; min-height: 16px; }
.campaign-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.campaign-stats .metric { background: var(--blue-50); border-radius: 10px; padding: 10px; text-align: center; }
.campaign-stats .metric .num { font-weight: 700; font-size: 16px; color: var(--blue-700); }
.campaign-stats .metric .lbl { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* ---------- Campaign toggle switch (on/off) ---------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; cursor: pointer; inset: 0; background-color: #ccc; transition: 0.2s; border-radius: 34px; }
.switch-slider::before { position: absolute; content: ""; height: 16px; width: 16px; right: 3px; bottom: 3px; background-color: #fff; transition: 0.2s; border-radius: 50%; }
.switch input:checked + .switch-slider { background-color: var(--blue-500, #2f6fed); }
.switch input:checked + .switch-slider::before { transform: translateX(-18px); }

/* ---------- Campaign card bottom icon row ---------- */
.campaign-icon-row { display: flex; gap: 8px; justify-content: flex-start; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: #fff; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover:not(:disabled) { border-color: var(--blue-400); background: var(--blue-50); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Dialer screen ---------- */
.dialer-active { display: flex; gap: 20px; }
.lead-card { flex: 1; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; }
.lead-card h2 { margin: 0 0 4px; }
.lead-card .phone { font-size: 24px; font-weight: 700; color: var(--blue-700); direction: ltr; text-align: right; margin: 6px 0 18px; }
.lead-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; font-size: 13px; }
.lead-meta .k { color: var(--muted); font-size: 11px; }
.call-controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.outcome-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.outcome-btn { border: 1px solid var(--border); background: #fff; border-radius: 10px; padding: 12px; font-size: 13px; text-align: center; }
.outcome-btn:hover { border-color: var(--blue-400); background: var(--blue-50); }
.queue-side { width: 300px; }
.queue-side .q-item { display: flex; justify-content: space-between; padding: 10px; border-bottom: 1px solid var(--border); font-size: 12px; }

/* ---------- Manager dashboard (rep performance) ---------- */
/* כרטיסי שברון (chevron) מחוברים בשרשרת, בהשראת מסך "ביצועי נציגים" של ToChat */
/* התור בשורה נבנה LTR-פנימי כדי לקבל שרשרת שברונים תקינה; סדר הכרטיסים ב-DOM
   כבר הפוך (זמן שיחה -> ... -> יוצאות) כך שהתוצאה הסופית על המסך (RTL) זהה
   לסדר במסך "ביצועי נציגים" של ToChat: יוצאות, נענו, נוהלו, סגורות, זמן שיחה */
.rep-stat-row {
  display: flex;
  direction: ltr;
  margin-bottom: 24px;
}
.rep-stat-card {
  flex: 1;
  direction: rtl;
  background: var(--card);
  border: 1px solid var(--blue-200);
  padding: 18px 30px;
  text-align: center;
  position: relative;
  margin-left: -18px;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 50%, calc(100% - 18px) 100%, 0 100%, 18px 50%);
}
.rep-stat-row .rep-stat-card:first-child {
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 50%, calc(100% - 18px) 100%, 0 100%);
  border-radius: 14px 0 0 14px;
  margin-left: 0;
}
.rep-stat-row .rep-stat-card:last-child {
  clip-path: polygon(18px 0, 100% 0, 100% 100%, 18px 100%, 0 50%);
  border-radius: 0 14px 14px 0;
}
.rep-stat-card:nth-child(1) { background: var(--blue-700); }
.rep-stat-card:nth-child(1) .rs-label { color: rgba(255,255,255,0.75); }
.rep-stat-card:nth-child(1) .rs-value { color: #fff; }
.rep-stat-card:nth-child(2) { background: #eafbf2; }
.rep-stat-card:nth-child(3) { background: var(--blue-50); }
.rep-stat-card:nth-child(4) { background: #fff8ec; }
.rep-stat-card:nth-child(5) { background: #f4f7f9; }
.rep-stat-card .rs-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; white-space: nowrap; }
.rep-stat-card .rs-value { font-size: 24px; font-weight: 800; color: var(--blue-700); }
.rep-stat-card .rs-pct { font-size: 12px; font-weight: 700; margin-top: 4px; }
.rep-stat-card .rs-pct.good { color: var(--green); }
.rep-stat-card .rs-pct.warn { color: #c9832a; }

.rep-status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; }
.rep-status-dot.online { background: var(--green); }
.rep-status-dot.offline { background: var(--muted); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(28,43,58,0.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; width: 420px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal h3 { margin-top: 0; }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.toast { position: fixed; bottom: 24px; left: 24px; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.25); }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .dialer-active { flex-direction: column; }
  .queue-side { width: 100%; }
}
