/* =========================================================================
   MODAL DE CONTATO — exibe todos os dados do lead
   Acessado pela conversa (clique no nome) ou pelo pipeline (clique no card).
   ========================================================================= */

.contact-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
  z-index: 1050;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: contact-fade-in .15s ease-out;
}
.contact-modal-backdrop.open { display: flex; }

@keyframes contact-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.contact-modal {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 48px rgba(0, 0, 0, .5);
  animation: contact-slide-up .2s cubic-bezier(.16, 1, .3, 1);
}

/* Wrapper interno que o JS injeta — precisa ser flex column ocupando o modal,
   senão o body com overflow:auto não funciona (faltava height referencial). */
.contact-modal-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;  /* CRÍTICO: permite que o flex item interno role */
  overflow: hidden;
}

@keyframes contact-slide-up {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* HEADER — avatar grande, nome, etapa */
.contact-modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(135deg, rgba(0, 168, 132, .08), transparent);
  position: relative;
}
.contact-modal-header .avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), #00d4a0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.contact-modal-header .head-info { flex: 1; min-width: 0; }
.contact-modal-header .head-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  word-break: break-word;
}
.contact-modal-header .head-stage {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.contact-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .04);
  color: var(--text-mute);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.contact-modal-close:hover {
  background: rgba(255, 255, 255, .08);
  color: var(--text);
}

/* BODY — seções de info — SCROLLÁVEL */
.contact-modal-body {
  padding: 16px 22px 20px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;  /* CRÍTICO em flex layouts — sem isso, overflow não rola */
  /* Scrollbar mais discreto */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.contact-modal-body::-webkit-scrollbar { width: 6px; }
.contact-modal-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.contact-modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-mute);
}

.contact-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
}
.contact-section:last-child { border-bottom: none; }

.contact-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-mute);
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.contact-section-label i { font-size: 12px; }

.contact-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13.5px;
}
.contact-field .field-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mute);
  font-size: 13px;
  flex-shrink: 0;
}
.contact-field .field-value {
  color: var(--text);
  word-break: break-word;
  flex: 1;
}
.contact-field .field-value.empty {
  color: var(--text-mute);
  font-style: italic;
  font-size: 12.5px;
}
.contact-field .field-copy {
  background: transparent;
  border: none;
  color: var(--text-mute);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
  opacity: 0;
  transition: all var(--transition);
}
.contact-field:hover .field-copy { opacity: 1; }
.contact-field .field-copy:hover {
  background: var(--bg-elev);
  color: var(--brand);
}

/* Tags como chips */
.contact-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.contact-tag-chip {
  background: rgba(83, 189, 235, .12);
  color: var(--accent);
  border: 1px solid rgba(83, 189, 235, .25);
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 500;
}

/* Notas — bloco com fundo */
.contact-notes {
  background: var(--bg-elev);
  border-left: 3px solid var(--warning);
  padding: 10px 12px;
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  color: var(--text-soft);
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
}

/* Grid de info pequena (orçamento, vidas, etc) */
.contact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.contact-grid-item {
  background: var(--bg-elev);
  padding: 10px 12px;
  border-radius: 8px;
}
.contact-grid-item .gi-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-mute);
  margin-bottom: 4px;
}
.contact-grid-item .gi-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.contact-grid-item .gi-value.brand { color: var(--brand); }

/* FOOTER — ações */
.contact-modal-footer {
  display: flex;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg);
  flex-shrink: 0;
}
.contact-modal-footer .btn {
  flex: 1;
  font-size: 13px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* Loading state */
.contact-modal-loading {
  padding: 60px 22px;
  text-align: center;
  color: var(--text-mute);
}
.contact-modal-loading .spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: contact-spin .8s linear infinite;
  margin-bottom: 10px;
}
@keyframes contact-spin {
  to { transform: rotate(360deg); }
}

/* Indicador clicável no nome do header da conversa e nos cards do kanban */
.chat-header .name.clickable,
.kanban-card .card-name.clickable {
  cursor: pointer;
  transition: color var(--transition);
}
.chat-header .name.clickable:hover,
.kanban-card .card-name.clickable:hover {
  color: var(--brand);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

/* Toast pequeno de "copiado!" */
.contact-toast-copy {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand);
  color: #fff;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0, 168, 132, .4);
  z-index: 1100;
  animation: copy-toast .2s ease-out;
}
@keyframes copy-toast {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

/* MOBILE — modal ocupa tela inteira */
@media (max-width: 640px) {
  .contact-modal-backdrop { padding: 0; align-items: stretch; }
  .contact-modal {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
}

/* =========================================================================
   ANALYTICS — seção exclusiva master/coordenador
   ========================================================================= */
.contact-analytics .analytics-badge {
  font-size: 9.5px;
  background: rgba(255, 181, 71, .15);
  color: var(--warning);
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  border: 1px solid rgba(255, 181, 71, .3);
}

.contact-grid.contact-grid-2 {
  grid-template-columns: 1fr 1fr;
}

/* Timeline do funil */
.contact-timeline {
  position: relative;
  margin-top: 6px;
  padding-left: 4px;
}
.contact-timeline-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  position: relative;
}
.contact-timeline-row:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 22px;
  bottom: -8px;
  width: 1px;
  background: var(--border-soft);
}

.contact-timeline .ct-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  border: 2px solid var(--text-mute);
  flex-shrink: 0;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}
/* Cores específicas dos estágios (reaproveita as cores do pipeline) */
.contact-timeline .ct-dot.stage-mensagem_enviada { border-color: #6c8aff; background: #6c8aff; }
.contact-timeline .ct-dot.stage-em_conversacao   { border-color: #00a884; background: #00a884; }
.contact-timeline .ct-dot.stage-cotacao_enviada  { border-color: #53bdeb; background: #53bdeb; }
.contact-timeline .ct-dot.stage-proposta_digitada{ border-color: #a07eff; background: #a07eff; }
.contact-timeline .ct-dot.stage-em_analise       { border-color: #ffb547; background: #ffb547; }
.contact-timeline .ct-dot.stage-aguardando_pagamento { border-color: #ff8a3d; background: #ff8a3d; }
.contact-timeline .ct-dot.stage-plano_fechado    { border-color: #00d4a0; background: #00d4a0; }
.contact-timeline .ct-dot.stage-lead_frio        { border-color: #6c757d; background: #6c757d; }
.contact-timeline .ct-dot.stage-created          { border-color: var(--brand); background: var(--brand); }

.contact-timeline .ct-content { flex: 1; min-width: 0; }
.contact-timeline .ct-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.contact-timeline .ct-when {
  font-size: 11.5px;
  color: var(--text-mute);
  margin-top: 1px;
}
.contact-timeline .ct-user {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 2px;
  font-style: italic;
}

/* =========================================================================
   SLA POR ETAPA (stage_durations) — dentro do modal de contato
   Lista o tempo total que o lead passou em cada etapa do funil.
   Visível apenas no payload para master/coordenador.
   ========================================================================= */
.stage-dur-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}
.stage-dur-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12.5px;
}
.stage-dur-row.is-current {
  border-color: var(--brand);
  background: rgba(0, 168, 132, .06);
}
.stage-dur-label {
  flex: 1;
  color: var(--text);
  font-weight: 500;
}
.stage-dur-value {
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.stage-dur-flag {
  background: var(--brand);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  text-transform: uppercase;
}
