:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --primary-soft: #eef2ff;
  --accent: #f97316;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 8px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Rubik", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  background: var(--surface);
  color: var(--text);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 19px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
}
.brand img, .brand svg { display: block; }

.integration-status {
  font-size: 13px;
  display: flex;
  gap: 14px;
}
.integration-status span {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  font-weight: 600;
}
.integration-status .ok { color: var(--success); }
.integration-status .off { color: var(--muted); }
.integration-status .ok::before { content: "●"; font-size: 8px; }
.integration-status .off::before { content: "●"; font-size: 8px; }

.container { max-width: 1280px; margin: 28px auto; padding: 0 28px; }

/* --- כרטיסי KPI --- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-card .kpi-label {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.kpi-card .kpi-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}
.kpi-card.accent .kpi-value { color: var(--primary); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.view-tab {
  border: none;
  background: transparent;
  padding: 7px 16px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.view-tab.active { background: var(--primary-soft); color: var(--primary-dark); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
}

.actions { display: flex; gap: 8px; }

.btn {
  padding: 9px 18px;
  border-radius: 9px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.btn.secondary:hover { background: var(--bg); }

.leads-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.leads-table th {
  background: var(--bg);
  color: var(--muted);
  text-align: right;
  padding: 13px 16px;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

.leads-table td {
  padding: 13px 16px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.leads-table tbody tr { transition: background 0.1s ease; }
.leads-table tbody tr:hover { background: var(--primary-soft); }

.lead-name-cell { display: flex; align-items: center; gap: 10px; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.badge {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  display: inline-block;
}
.badge.status-ליד-חדש { background: #e0e7ff; color: #4338ca; }
.badge.status-בתהליך { background: #fef3c7; color: #b45309; }
.badge.status-אימון-ניסיון { background: #cffafe; color: #155e75; }
.badge.status-סגר-מנוי { background: #dcfce7; color: #15803d; }
.badge.status-לא-רלוונטי { background: #f1f5f9; color: #64748b; }

.badge.priority-גבוהה { background: #fee2e2; color: #b91c1c; }
.badge.priority-בינונית { background: #fef3c7; color: #b45309; }
.badge.priority-נמוכה { background: #e0f2fe; color: #0369a1; }

.row-delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.row-delete:hover { color: var(--danger); }

.count { color: var(--muted); font-size: 13px; margin-top: 12px; }

/* --- תצוגת Kanban --- */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.kanban-column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 200px;
}
.kanban-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding: 0 2px;
}
.kanban-column-title { font-size: 13.5px; font-weight: 700; }
.kanban-column-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 9px;
}
.kanban-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.kanban-card .kc-name { font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.kanban-card .kc-meta { color: var(--muted); font-size: 12px; }

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }

.modal {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  padding: 26px;
  width: 400px;
  max-width: 90vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  transition: width 0.15s ease;
}
.modal.wide { width: 640px; }
.modal.modal-lg { width: 760px; }
.modal-close {
  position: absolute;
  top: 18px;
  left: 18px;
  background: none;
  border: none;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--danger); }
.modal-body { display: flex; flex-direction: column; gap: 20px; }
@media (min-width: 760px) {
  .modal.wide .modal-body { flex-direction: row; align-items: flex-start; }
  .modal.wide .modal-body form { flex: 0 0 260px; }
  .modal.wide .conversation-section { flex: 1; min-width: 0; }
}

.conversation-section h3 {
  margin: 0 0 12px;
  font-size: 15px;
}
.notes-timeline {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  padding-left: 4px;
}
.note-item {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  max-width: 90%;
}
.note-item .note-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.note-item.note-note { background: var(--bg); border: 1px solid var(--border); align-self: stretch; }
.note-item.note-in { background: #e0e7ff; align-self: flex-start; }
.note-item.note-out { background: var(--primary); color: white; align-self: flex-end; }
.note-item.note-out .note-meta { color: rgba(255,255,255,0.75); }

.note-input-row { display: flex; gap: 8px; margin-bottom: 10px; }
.note-input-row input {
  flex: 1;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13.5px;
}
.hint { font-size: 12px; color: var(--muted); }
.modal h2 { margin-top: 0; }
.modal form label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.modal form input, .modal form select {
  width: 100%;
  padding: 9px 11px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

@media (max-width: 900px) {
  .kanban-board { grid-template-columns: repeat(5, minmax(200px, 1fr)); }
}

/* --- פעולות עליונות: אוטומציות / הגדרות --- */
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-divider { width: 1px; height: 20px; background: var(--border); }
.icon-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 12px;
  color: var(--primary-dark);
  cursor: pointer;
  font-family: inherit;
}
.icon-btn.icon-only { padding: 6px; width: 32px; height: 32px; justify-content: center; color: var(--muted); }
.icon-btn:hover { background: var(--bg); }

/* --- תיבת שיחות --- */
.inbox-filters { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.inbox-pill {
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface);
}
.inbox-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.inbox-filters input {
  margin-right: auto;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13px;
  width: 200px;
}

.inbox-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 480px;
}
.inbox-list { border-left: 1px solid var(--border); overflow-y: auto; max-height: 620px; }
.inbox-conv-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.inbox-conv-row:hover { background: var(--bg); }
.inbox-conv-row.active { background: var(--primary-soft); }
.inbox-conv-info { flex: 1; min-width: 0; }
.inbox-conv-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.inbox-conv-name { font-size: 13px; font-weight: 600; }
.inbox-conv-time { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.inbox-conv-preview {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.inbox-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); align-self: center; flex-shrink: 0; }

.inbox-pane { display: flex; flex-direction: column; background: var(--bg); }
.inbox-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.inbox-thread-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.inbox-header-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.inbox-header-name { font-size: 13px; font-weight: 600; white-space: nowrap; }
.inbox-header-phone { font-size: 11px; color: var(--muted); white-space: nowrap; }
.inbox-channel-badge { font-size: 10px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.inbox-status-select {
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 11px;
  font-family: inherit;
  padding: 0 6px;
}
.inbox-more-link { font-size: 11px; color: var(--primary); cursor: pointer; white-space: nowrap; }
.inbox-thread { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.inbox-composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  align-items: center;
}
.inbox-composer input {
  flex: 1;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0 12px;
  font-family: inherit;
  font-size: 13px;
}

/* --- הגדרות מערכת ואוטומציות --- */
.settings-body { display: flex; flex-direction: column; gap: 22px; }
.settings-section h3 { margin: 0 0 10px; font-size: 14px; }
.settings-integrations { display: flex; gap: 10px; flex-wrap: wrap; }
.settings-integration-chip {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
}
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  max-height: 220px;
  overflow-y: auto;
}
.settings-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
}
.settings-list-item .sli-main { flex: 1; min-width: 0; }
.settings-list-item .sli-title { font-weight: 600; }
.settings-list-item .sli-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings-list-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  flex-shrink: 0;
}
.settings-list-remove:hover { color: var(--danger); }
.settings-list-empty { color: var(--muted); font-size: 12.5px; padding: 8px 0; }

.automation-body { display: flex; gap: 24px; flex-wrap: wrap; }
.automation-body > div { flex: 1 1 300px; min-width: 0; }
.automation-body .settings-list { max-height: 420px; }
.automation-form h3 { margin: 0 0 10px; font-size: 14px; }
.automation-form { display: flex; flex-direction: column; gap: 10px; }
.automation-form label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  display: block;
}
.automation-form input, .automation-form select {
  width: 100%;
  padding: 8px 10px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13.5px;
  font-family: inherit;
}
.automation-toggle {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  flex-shrink: 0;
}
.automation-toggle.on { background: var(--success); }
.automation-toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.automation-toggle.on::after { transform: translateX(-16px); }
