/* ============================================
   RICKK IA — CRM (funil de vendas)
   ============================================ */

/* Busca (usada no CRM e em Clientes) */
.crm-search {
  display: flex; align-items: center; gap: 0.55rem;
  height: 40px; padding: 0 0.9rem;
  min-width: 240px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.crm-search:focus-within { border-color: var(--border-active); box-shadow: 0 0 0 4px var(--accent-glow); }
.crm-search input {
  flex: 1; min-width: 0;
  background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 0.84rem;
}
.crm-search input::placeholder { color: var(--text-muted); }

.metrics-grid.crm-stats { margin-bottom: 1.25rem; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.85rem; }
.crm-stats .metric-card { gap: 0.7rem; padding: 1rem 1.1rem 1.1rem; }
.crm-stats .metric-card::after { top: 0.9rem; right: 0.9rem; width: 26px; height: 26px; }
.crm-stats .metric-icon { width: 32px; height: 32px; font-size: 0.8rem; }
.crm-stats .metric-value { font-size: 1.6rem; }
@media (max-width: 900px) { .metrics-grid.crm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Linha de apoio e barra nos cards de número */
.metric-sub { font-size: 0.74rem; color: var(--text-muted); }
.metric-bar {
  width: 100%; height: 5px; margin-top: 0.35rem;
  background: var(--bg-glass-2);
  border-radius: 999px; overflow: hidden;
}
.metric-bar > div {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit;
  transition: width 0.8s var(--ease);
}
.metrics-grid .metric-body { width: 100%; }

/* ---- Quadro do funil ---- */
.crm-board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(250px, 1fr);
  gap: 0.85rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  align-items: start;
}

.crm-col {
  display: flex; flex-direction: column;
  background: var(--card-fill);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 0.75rem 0.75rem;
  min-height: 420px;
  max-height: calc(100vh - 330px);
  animation: npPop 0.6s var(--ease) both;
  position: relative;
  overflow: hidden;
}
/* Linha de cor da etapa no topo da coluna */
.crm-col::before {
  content: '';
  position: absolute; top: 0; left: 18%; right: 18%; height: 2px;
  border-radius: 0 0 4px 4px;
  background: var(--stage);
  box-shadow: 0 0 14px var(--stage);
  opacity: 0.85;
}
.crm-col:nth-child(2) { animation-delay: 50ms; }
.crm-col:nth-child(3) { animation-delay: 100ms; }
.crm-col:nth-child(4) { animation-delay: 150ms; }
.crm-col:nth-child(5) { animation-delay: 200ms; }
.crm-col:nth-child(6) { animation-delay: 250ms; }

.crm-col-head { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.25rem; }
.crm-col-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stage); box-shadow: 0 0 8px var(--stage); flex-shrink: 0; }
.crm-col-name { font-size: 0.82rem; font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-col-count {
  font-size: 0.7rem; font-weight: 600; color: var(--text-secondary);
  background: var(--bg-glass-2); border: 1px solid var(--border);
  padding: 0.05rem 0.5rem; border-radius: 999px;
}
.crm-col-total {
  padding: 0.35rem 0.25rem 0.8rem;
  font-size: 1.25rem; font-weight: 500; letter-spacing: -0.03em;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.7rem;
}

.crm-col-cards {
  flex: 1;
  display: flex; flex-direction: column; gap: 0.6rem;
  overflow-y: auto;
  min-height: 80px;
  padding: 2px;
}
.crm-empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 1.25rem 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---- Card do lead ---- */
.crm-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 0.8rem;
  cursor: grab;
  display: flex; flex-direction: column; gap: 0.6rem;
  transition: transform 0.35s var(--ease), border-color 0.35s var(--ease), box-shadow 0.35s var(--ease);
  animation: npPop 0.45s var(--ease) both;
}
.crm-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hover);
  box-shadow: 0 16px 30px -20px var(--accent);
}
.crm-card:active { cursor: grabbing; }
.crm-card.sortable-ghost { opacity: 0.25; }
.crm-card.sortable-drag { transform: rotate(2deg); }

.crm-card-top { display: flex; align-items: center; gap: 0.6rem; }
.crm-avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--stage, var(--accent)), var(--accent-deep));
}
.crm-card-titles { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.crm-card-title { font-size: 0.84rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-card-sub { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-wa {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #25d366; background: rgba(37, 211, 102, 0.12);
  text-decoration: none; font-size: 0.9rem;
  transition: transform 0.35s var(--spring), background 0.2s ease;
}
.crm-wa:hover { transform: scale(1.12); background: rgba(37, 211, 102, 0.22); }

.crm-card-value { font-size: 1.05rem; font-weight: 500; letter-spacing: -0.02em; }

.crm-card-meta { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.crm-chip, .crm-follow {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.66rem; font-weight: 500;
  padding: 0.18rem 0.55rem; border-radius: 999px;
  background: var(--bg-glass-2); border: 1px solid var(--border);
  color: var(--text-secondary);
}
.crm-chip-client { color: #22c55e; background: rgba(34, 197, 94, 0.1); border-color: rgba(34, 197, 94, 0.25); }
.crm-follow.late   { color: #ef4444; background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); }
.crm-follow.late i { animation: badgePulse 2s ease-in-out infinite; border-radius: 50%; }
.crm-follow.today  { color: #f59e0b; background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.3); }

.crm-add-inline {
  margin-top: 0.6rem;
  display: flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.6rem;
  background: none;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.crm-add-inline:hover { border-color: var(--border-hover); color: var(--text-primary); background: var(--accent-glow); }

@media (max-width: 768px) {
  .crm-search { min-width: 0; flex: 1; }
  .crm-board { grid-auto-columns: minmax(240px, 82vw); }
  .crm-col { max-height: none; }
}

/* Formulário do lead */
#lead-form { display: flex; flex-direction: column; gap: 1rem; }

/* Aviso de "só visualizando" na demanda */
.tv-readonly-note {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.78rem; color: var(--text-muted);
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.tv-readonly-note.hidden { display: none; }
