/* ==========================================================================
   Módulo CRM de Leads — Quadro Kanban & Sistema de Lembretes
   ========================================================================== */

/* Badge contador de lembretes na aba superior do menu */
.header-agent-selector .tab-button {
  position: relative;
}

.crm-nav-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #EF4444;
  color: #FFFFFF;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(239, 68, 68, 0.35);
  animation: crmPulseBadge 2.2s infinite ease-in-out;
}

.crm-nav-badge.hidden {
  display: none !important;
}

@keyframes crmPulseBadge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* Painel Superior de Alertas de Lembretes (Hoje / Atrasados) */
.crm-reminders-alert {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-left: 4px solid #F59E0B;
  border-radius: var(--radius-base);
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.06);
}

.crm-reminders-alert.has-overdue {
  background: #FEF2F2;
  border-color: #FECACA;
  border-left-color: #EF4444;
}

.crm-reminders-alert.hidden {
  display: none !important;
}

.crm-reminders-alert-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.crm-reminders-alert-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #92400E;
}

.crm-reminders-alert.has-overdue .crm-reminders-alert-title {
  color: #991B1B;
}

.crm-reminders-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.crm-reminder-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--brand-secondary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  cursor: pointer;
  transition: all 0.15s ease;
}

.crm-reminder-pill:hover {
  border-color: var(--brand-accent);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06);
}

.crm-reminder-pill.is-overdue {
  border-left: 3px solid #EF4444;
}

.crm-reminder-pill.is-today {
  border-left: 3px solid #09C1DC;
}

.crm-reminder-pill-time {
  font-weight: 700;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #F1F5F9;
  color: #475569;
}

.crm-reminder-pill.is-overdue .crm-reminder-pill-time {
  background: #FEE2E2;
  color: #B91C1C;
}

.crm-reminder-pill.is-today .crm-reminder-pill-time {
  background: #E0F7FA;
  color: #007B8A;
}

.crm-reminder-pill-name {
  font-weight: 700;
  color: var(--brand-secondary);
}

.crm-reminder-pill-note {
  color: #64748B;
  font-size: 11.5px;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-crm-complete-reminder {
  background: #F8FAFC;
  border: 1px solid #CBD5E1;
  color: #475569;
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-crm-complete-reminder:hover {
  background: #DCFCE7;
  border-color: #86EFAC;
  color: #15803D;
}

/* Barra de Ferramentas e Filtros do CRM (1 Linha Única) */
.crm-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  flex-wrap: nowrap;
}

.crm-toolbar .kanban-search-box input {
  width: 340px;
}

/* Botão Único de Etapas Ocultas (Fechado, Perdido, Desqualificado) */
.crm-archived-single-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 4px 10px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--brand-secondary);
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.crm-archived-single-btn > i:first-child {
  color: #64748B;
  font-size: 12px;
}

.crm-archived-single-btn:hover,
.crm-archived-single-btn.active {
  border-color: var(--brand-accent);
  background: #F8FDFD;
  color: #077A8C;
}

.crm-archived-single-btn.active > i:first-child {
  color: var(--brand-accent);
}

.crm-archived-single-btn.is-dragging-card {
  background: #F0FDFA;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(9, 193, 220, 0.15);
}

.crm-archived-btn-label {
  font-weight: 700;
}

.crm-archived-counts-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.crm-archived-drop-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 5px;
  background: #F1F5F9;
  border: 1px solid #E2E8F0;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  transition: all 0.15s ease;
}

.crm-archived-drop-pill strong {
  font-weight: 800;
  color: var(--brand-secondary);
}

.crm-archived-drop-pill.pill-fechado.drag-over {
  background: #ECFDF5;
  border-color: #10B981;
  color: #047857;
  transform: scale(1.08);
}

.crm-archived-drop-pill.pill-perdido.drag-over {
  background: #FEF2F2;
  border-color: #EF4444;
  color: #B91C1C;
  transform: scale(1.08);
}

.crm-archived-drop-pill.pill-desqualificado.drag-over {
  background: #E2E8F0;
  border-color: #475569;
  color: #1E293B;
  transform: scale(1.08);
}

.crm-archived-chevron {
  font-size: 10px;
  color: #64748B;
  transition: transform 0.2s ease;
}

.crm-archived-single-btn.active .crm-archived-chevron {
  transform: rotate(180deg);
  color: var(--brand-accent);
}

/* Botão de Mensagens Sem Etapa ao lado do Salvo na planilha */
.btn-crm-general-msg {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 4px 10px;
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--brand-secondary);
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-crm-general-msg i {
  color: var(--brand-accent);
  font-size: 12px;
}

.btn-crm-general-msg:hover {
  border-color: var(--brand-accent);
  background: #F8FDFD;
  color: #077A8C;
}

.crm-general-msg-badge {
  background: #ECFEFF;
  border: 1px solid rgba(9, 193, 220, 0.35);
  color: #0891B2;
  font-size: 10.5px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  line-height: 1.2;
}

/* Indicador "Salvo na planilha" mais compacto no CRM */
.crm-sync-status-compact {
  margin-left: 0;
  font-size: 11px !important;
  padding: 4px 10px !important;
  width: auto !important;
  min-width: 132px !important;
  max-width: 155px !important;
  gap: 5px !important;
}

/* Gaveta / Painel Retrátil das 3 Colunas Ocultas */
.crm-archived-drawer {
  background: #F8FAFC;
  border: 1px solid #CBD5E1;
  border-radius: var(--radius-base);
  padding: 12px 14px;
  margin-bottom: 16px;
  box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.03);
}

.crm-archived-drawer.hidden {
  display: none !important;
}

.crm-archived-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.crm-archived-drawer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: #475569;
}

.crm-archived-drawer-title i {
  color: #64748B;
}

.btn-close-archived-drawer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  color: #475569;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-close-archived-drawer:hover {
  border-color: #94A3B8;
  color: var(--brand-secondary);
}

.crm-archived-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}

.crm-archived-column {
  min-height: 220px !important;
  max-height: 42vh !important;
  background: #FFFFFF !important;
}

/* Quadro Kanban Principal de 6 Colunas Ativas do Dia a Dia */
.crm-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(195px, 1fr));
  gap: 12px;
  align-items: start;
  width: 100%;
  overflow-x: auto;
  padding-bottom: 16px;
}

.crm-column {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: var(--radius-base);
  display: flex;
  flex-direction: column;
  min-height: 520px;
  max-height: 76vh;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.crm-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #E2E8F0;
  background: #FFFFFF;
  border-radius: var(--radius-base) var(--radius-base) 0 0;
  border-top: 3px solid #94A3B8;
}

.crm-col-header.stage-novo-lead { border-top-color: #09C1DC; }
.crm-col-header.stage-qualificado { border-top-color: #3B82F6; }
.crm-col-header.stage-reuniao { border-top-color: #8B5CF6; }
.crm-col-header.stage-enviar-orcamento { border-top-color: #F59E0B; }
.crm-col-header.stage-follow-up { border-top-color: #EC4899; }
.crm-col-header.stage-stand-by { border-top-color: #64748B; }
.crm-col-header.stage-fechado { border-top-color: #10B981; }
.crm-col-header.stage-perdido { border-top-color: #EF4444; }
.crm-col-header.stage-desqualificado { border-top-color: #475569; }

.crm-col-header .col-title-group {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.crm-col-header h3 {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--brand-secondary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-col-header .col-badge {
  background: #F1F5F9;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

.crm-col-header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.btn-crm-stage-msg {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid #E2E8F0;
  background: #F8FAFC;
  color: #64748B;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11.5px;
  padding: 0;
  transition: all 0.15s ease;
}

.btn-crm-stage-msg.has-templates {
  background: #ECFEFF;
  border-color: rgba(9, 193, 220, 0.45);
  color: #0891B2;
}

.btn-crm-stage-msg:hover {
  background: var(--brand-accent);
  border-color: var(--brand-accent);
  color: #FFFFFF;
  transform: translateY(-1px);
}

.crm-col-content {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 160px;
}

.crm-col-content.drag-over {
  background: rgba(9, 193, 220, 0.06);
  border-radius: 0 0 var(--radius-base) var(--radius-base);
}

/* Card Minimalista do Lead */
.crm-card {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: relative;
  user-select: none;
}

.crm-card:hover {
  border-color: var(--brand-accent);
  box-shadow: 0 4px 10px rgba(9, 193, 220, 0.12);
  transform: translateY(-1px);
}

.crm-card.dragging {
  opacity: 0.45;
  transform: scale(0.98);
}

/* Indicadores de linha ao arrastar card para cima/baixo entre os cards */
.crm-card.drop-before::before,
.crm-card.drop-after::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--brand-accent, #09C1DC);
  border-radius: 999px;
  box-shadow: 0 0 8px rgba(9, 193, 220, 0.55);
  pointer-events: none;
  z-index: 5;
}

.crm-card.drop-before::before {
  top: -6px;
}

.crm-card.drop-after::after {
  bottom: -6px;
}

/* Destaques visuais de lembrete no Card */
.crm-card.has-overdue-reminder {
  border-color: #FCA5A5;
  border-left: 4px solid #EF4444;
  background: #FFFDFD;
}

.crm-card.has-today-reminder {
  border-color: #67E8F9;
  border-left: 4px solid #09C1DC;
  background: #FAFFFF;
}

.crm-card-primary {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-secondary);
  line-height: 1.35;
  word-break: break-word;
}

.crm-card-primary.is-unnamed {
  color: #475569;
  font-weight: 600;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.crm-card-primary.is-unnamed i {
  color: var(--brand-accent);
}

.crm-card-company {
  font-size: 11.5px;
  font-weight: 500;
  color: #64748B;
  display: flex;
  align-items: center;
  gap: 5px;
}

.crm-card-phone {
  font-size: 11.5px;
  font-weight: 600;
  color: #0F766E;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.crm-card-phone i {
  color: #10B981;
  font-size: 12.5px;
}

/* Tag de Lembrete no Card */
.crm-card-reminder {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed #E2E8F0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.crm-reminder-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 4px;
  width: fit-content;
}

.crm-reminder-tag.is-overdue {
  background: #FEE2E2;
  color: #B91C1C;
  border: 1px solid #FECACA;
}

.crm-reminder-tag.is-today {
  background: #E0F7FA;
  color: #007B8A;
  border: 1px solid #A5F3FC;
}

.crm-reminder-tag.is-future {
  background: #F1F5F9;
  color: #475569;
  border: 1px solid #CBD5E1;
}

.crm-reminder-note-preview {
  font-size: 11px;
  color: #64748B;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Modal de Detalhes e Edição do Lead */
.crm-modal-container {
  max-width: 980px;
  width: 95%;
}

.crm-modal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
}

.crm-modal-main-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.crm-modal-main-col .form-group,
.crm-modal-side-col .form-group {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.crm-modal-main-col label,
.crm-modal-side-col label {
  margin-bottom: 0;
}

.crm-input-with-paste {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.crm-input-with-paste input {
  width: 100%;
  padding-right: 38px !important;
}

.btn-crm-paste-input {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #E2E8F0;
  background: #F8FAFC;
  color: #64748B;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
  padding: 0;
}

.btn-crm-paste-input:hover {
  background: #ECFEFF;
  border-color: var(--brand-accent);
  color: #0891B2;
}

.btn-crm-paste-input.pasted {
  background: #DCFCE7;
  border-color: #86EFAC;
  color: #16A34A;
}

.crm-modal-side-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.crm-modal-side-col > .form-group {
  display: flex;
  flex-direction: column;
  flex: 1;
}

@media (max-width: 820px) {
  .crm-modal-grid {
    grid-template-columns: 1fr;
  }
  .crm-archived-board {
    grid-template-columns: 1fr;
  }
}

.crm-reminder-box {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 14px;
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.crm-reminder-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.crm-reminder-box-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--brand-secondary);
}

.crm-reminder-box-title i {
  color: #F59E0B;
}

.btn-clear-reminder {
  background: transparent;
  border: 1px solid #CBD5E1;
  color: #64748B;
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-clear-reminder:hover {
  background: #FEE2E2;
  border-color: #FCA5A5;
  color: #B91C1C;
}

.crm-notes-textarea {
  width: 100%;
  flex: 1;
  min-height: 155px;
  resize: vertical;
  line-height: 1.5;
  padding: 10px 12px;
  font-size: 13px;
}

/* Painel Somente Leitura com Dados de Aquisição no Modal */
.crm-origin-meta-box {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 0;
  min-width: 0;
  overflow: hidden;
}

.crm-origin-meta-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #64748B;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.crm-meta-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 5px 14px;
  font-size: 11.5px;
}

.crm-meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px dashed #E2E8F0;
  padding-bottom: 4px;
  min-width: 0;
  overflow: hidden;
}

.crm-meta-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.crm-meta-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748B;
  flex-shrink: 0;
}

.crm-meta-value {
  font-weight: 600;
  color: var(--brand-secondary);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

/* Modal de Mensagem Padrão da Etapa CRM (template_msg) — Layout Compacto 1 Linha com Tooltip no Hover */
.crm-stage-msg-modal-container {
  max-width: 640px;
  width: 95%;
}

.crm-stage-msg-modal-body {
  max-height: 72vh;
  overflow-y: auto;
  padding: 14px 18px;
}

.crm-stage-msg-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.crm-stage-msg-card {
  background: #F8FAFC;
  border: 1.5px solid #E2E8F0;
  border-radius: 8px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.crm-stage-msg-card:hover {
  background: #FFFFFF;
  border-color: var(--brand-accent);
}

.crm-stage-msg-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
}

.crm-stage-msg-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  cursor: default;
}

.crm-stage-msg-name {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-secondary);
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  white-space: nowrap;
}

.crm-stage-msg-name i {
  color: var(--brand-accent);
  font-size: 11px;
}

.crm-stage-msg-preview {
  font-size: 12.5px;
  color: #64748B;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  line-height: 1.4;
}

.crm-stage-msg-card:hover .crm-stage-msg-name {
  border-color: rgba(9, 193, 220, 0.45);
  background: #ECFEFF;
  color: #077A8C;
}

.btn-copy-stage-msg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--brand-accent);
  color: #FFFFFF;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.btn-copy-stage-msg:hover {
  background: #07A7C0;
  transform: translateY(-1px);
}

.btn-copy-stage-msg.copied {
  background: #16A34A;
}

/* Tooltip flutuante para exibir a mensagem completa no hover sem mover o layout */
.crm-msg-floating-tooltip {
  position: fixed;
  z-index: 10100;
  max-width: 480px;
  width: max-content;
  background: #1E293B;
  color: #F8FAFC;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.35);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.crm-msg-floating-tooltip.visible {
  opacity: 1;
}

.crm-stage-msg-empty {
  text-align: center;
  padding: 22px 16px;
  background: #F8FAFC;
  border: 1.5px dashed #CBD5E1;
  border-radius: 10px;
  color: #64748B;
  font-size: 12.5px;
}

.crm-stage-msg-empty i {
  font-size: 22px;
  color: #94A3B8;
  margin-bottom: 6px;
  display: block;
}
