:root {
  --primary: #6366f1;
  --primary-dark: #4338ca;
  --primary-light: #818cf8;
  --accent: #f59e0b;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --info: #3b82f6;
  --info-light: #dbeafe;
  --bg: #f3f4fb;
  --card-bg: #ffffff;
  --text: #1f2430;
  --text-muted: #6b7280;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(99, 102, 241, 0.08);
  --shadow-hover: 0 10px 24px rgba(99, 102, 241, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3, .brand, .login-card h1 {
  font-family: "Poppins", "Inter", sans-serif;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #6366f1 0%, #818cf8 45%, #f59e0b 100%);
}
.login-card {
  background: #fff;
  padding: 2.75rem;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(67, 56, 202, 0.25);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.login-card h1 {
  margin: 0 0 1rem;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  color: var(--primary-dark);
}
.login-card input {
  padding: 0.7rem 0.9rem;
  border: 1.5px solid #e5e7eb;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.login-card button {
  padding: 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.login-card button:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4); }
.error-text { color: var(--danger); font-size: 0.85rem; min-height: 1em; font-weight: 600; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: linear-gradient(120deg, #4338ca 0%, #6366f1 55%, #818cf8 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(67, 56, 202, 0.25);
}
.brand { font-weight: 800; font-size: 1.2rem; letter-spacing: 0.2px; }
.brand span { font-weight: 500; opacity: 0.85; }
.tabs { display: flex; gap: 0.4rem; background: rgba(255,255,255,0.12); padding: 0.3rem; border-radius: 999px; }
.tab-btn {
  background: transparent;
  border: none;
  color: #e0e7ff;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.tab-btn:hover { background: rgba(255,255,255,0.14); transform: translateY(-1px); }
.tab-btn.active { background: #fff; color: var(--primary-dark); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; }
.topbar-right button {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.15s ease;
}
.topbar-right button:hover { background: rgba(255,255,255,0.3); transform: translateY(-1px); }

.content { flex: 1; overflow-y: auto; padding: 1.75rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Tasks ---------- */
.task-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.task-card {
  background: var(--card-bg);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.task-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.task-card.overdue { border-left-color: var(--danger); }
.task-card .task-lead-name { font-weight: 700; }
.task-card .task-meta { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }
.task-card.overdue .task-badge { background: var(--danger-light); color: #b91c1c; }
.task-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--info-light);
  color: var(--primary-dark);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

/* ---------- Leads ---------- */
.leads-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.toolbar-actions { display: flex; gap: 0.5rem; align-items: center; }
.toolbar-actions select, .toolbar-actions button, #template-search {
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid #e5e7eb;
  font-size: 0.9rem;
  background: #fff;
}
#new-lead-btn, .qd-btn, #interaction-form button, #new-lead-form button[type="submit"],
.modal-actions button[type="submit"], .copy-btn {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.3);
}
#new-lead-btn:hover, .qd-btn:hover, #interaction-form button:hover, #new-lead-form button[type="submit"]:hover,
.modal-actions button[type="submit"]:hover, .copy-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4); }
.leads-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.lead-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.lead-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.lead-card .lead-name { font-weight: 700; }
.lead-card .lead-sub { font-size: 0.85rem; color: var(--text-muted); }
.status-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: #eee;
  color: #333;
  white-space: nowrap;
}
.status-pill.New { background: var(--info-light); color: var(--primary-dark); }
.status-pill.Contacted { background: var(--warning-light); color: #92400e; }
.status-pill.AssessmentBooked { background: #e0f2fe; color: #0369a1; }
.status-pill.Enrolled { background: var(--success-light); color: #047857; }
.status-pill.Lost { background: var(--danger-light); color: #b91c1c; }
.assignment-badge { display: inline-block; margin-top: 0.4rem; font-weight: 700; }
.assignment-badge.unassigned { background: var(--danger-light); color: #b91c1c; }
.assignment-badge.assigned { background: var(--info-light); color: var(--primary-dark); }

#unassigned-queue { margin-bottom: 1.5rem; }
#unassigned-list .lead-card { align-items: center; }
#unassigned-list .lead-card select {
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid #e5e7eb;
  font-size: 0.85rem;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(31, 36, 48, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: #fff;
  border-radius: 18px;
  padding: 1.75rem;
  width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 24px 60px rgba(31, 36, 48, 0.3);
  animation: fadeIn 0.2s ease;
}
.modal-box.large { width: 820px; }
.modal-close {
  position: absolute;
  top: 0.7rem; right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}
#new-lead-form, #interaction-form, #team-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.75rem;
}
#new-lead-form input, #interaction-form input, #interaction-form select,
#interaction-form textarea, #team-form input, #team-form select {
  padding: 0.6rem 0.75rem;
  border: 1.5px solid #e5e7eb;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  width: 100%;
  max-width: 320px;
  transition: border-color 0.15s ease;
}
#new-lead-form input:focus, #interaction-form input:focus, #interaction-form select:focus,
#interaction-form textarea:focus, #team-form input:focus, #team-form select:focus {
  outline: none;
  border-color: var(--primary);
}
#team-form button[type="submit"] {
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  align-self: flex-start;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.modal-actions button, #interaction-form button {
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
}
.btn-secondary { background: #eef0f6; border: none; cursor: pointer; color: var(--text); transition: background 0.15s ease; }
.btn-secondary:hover { background: #e1e4f0; }

/* ---------- Lead Detail ---------- */
.lead-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.lead-meta { font-size: 0.9rem; color: var(--text-muted); }
#ld-status { margin: 0.5rem 0 1rem; padding: 0.45rem 0.7rem; border-radius: var(--radius-sm); font-weight: 700; }
.call-script-panel {
  background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
  border: 1px solid #e0e7ff;
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
  font-size: 0.88rem;
  line-height: 1.6;
}
.call-script-panel h3 { margin-top: 0; color: var(--primary-dark); }
.quick-disposition { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.75rem; }
.qd-btn { padding: 0.5rem 0.85rem; border-radius: var(--radius-sm); font-size: 0.8rem; }
.interaction-history { max-height: 260px; overflow-y: auto; margin-top: 0.5rem; }
.interaction-entry {
  border-bottom: 1px solid #eef0f6;
  padding: 0.65rem 0;
  font-size: 0.85rem;
}
.interaction-entry .ie-head { font-weight: 700; }
.interaction-entry .ie-meta { color: var(--text-muted); font-size: 0.78rem; }

/* ---------- Language toggle ---------- */
.lang-toggle { display: flex; gap: 0.4rem; }
.lang-btn {
  background: #eef0f6;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.lang-btn.active { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); color: #fff; }

/* ---------- Promos & Templates ---------- */
.replies-split { display: grid; grid-template-columns: 1fr 1.2fr; gap: 1.5rem; margin-top: 1rem; }
[dir="rtl"] { text-align: right; }
[dir="rtl"] .modal-actions { justify-content: flex-start; }
.promo-panel, .template-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.promo-card {
  border: 1px solid #eef0f6;
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  margin-bottom: 0.65rem;
  transition: box-shadow 0.15s ease;
}
.promo-card:hover { box-shadow: 0 4px 14px rgba(99, 102, 241, 0.12); }
.promo-card .promo-name { font-weight: 700; }
.promo-card .promo-terms { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.2rem; }
.promo-card .promo-countdown { color: var(--danger); font-size: 0.85rem; font-weight: 700; }
.template-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
#template-search { flex: 1; max-width: 220px; }
.template-card {
  border: 1px solid #eef0f6;
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  margin-bottom: 0.65rem;
  transition: box-shadow 0.15s ease;
}
.template-card:hover { box-shadow: 0 4px 14px rgba(99, 102, 241, 0.12); }
.template-card .tpl-title { font-weight: 700; }
.template-card .tpl-meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.template-card .tpl-body { font-size: 0.85rem; white-space: pre-wrap; margin-bottom: 0.5rem; }
.tpl-promo-select, .tpl-resource-select, #int-insert-resource {
  display: block;
  margin-bottom: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid #e5e7eb;
  font-size: 0.8rem;
  width: 100%;
}
.copy-btn { padding: 0.45rem 0.8rem; border-radius: var(--radius-sm); font-size: 0.8rem; text-decoration: none; display: inline-block; color: #fff; }
.copy-btn.copied { background: var(--success); }

/* ---------- Resources Hub ---------- */
.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.1rem;
  margin-top: 1rem;
}
.resource-card {
  background: var(--card-bg);
  border: 1px solid #eef0f6;
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.resource-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.resource-thumb {
  font-size: 2.3rem;
  text-align: center;
  background: linear-gradient(135deg, #eef2ff 0%, #fef3c7 100%);
  border-radius: var(--radius-sm);
  padding: 1rem 0;
}
.resource-title { font-weight: 700; font-size: 0.9rem; }
.resource-meta { font-size: 0.78rem; color: var(--text-muted); }
.resource-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.resource-actions .btn-secondary { padding: 0.45rem 0.8rem; border-radius: var(--radius-sm); font-size: 0.8rem; }
