/* =========================================================================
   CHATFLOW WHATSAPP CRM - REAL-TIME DIALOGUES, SIDEBARS & BUBBLES
   ========================================================================= */

.chat-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 110px);
  gap: 1.5rem;
}

@media (max-width: 900px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }
}

/* Sidebar for conversation threads */
.chat-sidebar {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--inset-shadow);
}

.chat-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.1);
}

.chat-threads-list {
  flex: 1;
  overflow-y: auto;
}

/* Single thread element */
.chat-thread-item {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: var(--transition-fast);
}

.chat-thread-item:hover {
  background: rgba(255, 255, 255, 0.02);
}

.chat-thread-item.active {
  background: rgba(255, 255, 255, 0.05);
  border-left: 3px solid var(--theme-glow);
}

.thread-name {
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-main);
}

.thread-phone {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.thread-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.25rem;
}

/* Active central chat dialogues panels */
.crm-chat-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--inset-shadow);
}

.crm-chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.crm-chat-logs {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Dialogue message bubble styles */
.crm-msg-bubble {
  max-width: 65%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  font-size: 0.85rem;
  line-height: 1.5;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
  animation: bubbleSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes bubbleSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.crm-msg-bubble.incoming {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  align-self: flex-start;
  border-top-left-radius: 0;
  color: var(--text-main);
}

.crm-msg-bubble.outgoing {
  background: linear-gradient(135deg, var(--theme-glow), var(--theme-glow-end));
  color: #080c16;
  font-weight: 500;
  align-self: flex-end;
  border-top-right-radius: 0;
}

.crm-msg-bubble .time {
  font-size: 0.65rem;
  opacity: 0.6;
  text-align: right;
  margin-top: 0.4rem;
}

/* Bouncing customer typing simulator bubble */
.typing-bubble {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-style: italic;
  color: var(--text-muted);
}

.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Reply messaging footer controls */
.crm-chat-input-bar {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 0.75rem;
  background: rgba(0, 0, 0, 0.2);
}

.crm-chat-input-bar input {
  flex: 1;
  background: #03050a;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  color: white;
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition-smooth);
}

.crm-chat-input-bar input:focus {
  border-color: rgba(0, 242, 254, 0.5);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.1);
}

.crm-chat-input-bar button {
  background: linear-gradient(135deg, var(--theme-glow), var(--theme-glow-end));
  border: none;
  color: #080c16;
  font-weight: 600;
  padding: 0 1.25rem;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition-smooth);
  box-shadow: 0 4px 10px rgba(0, 242, 254, 0.15);
}

.crm-chat-input-bar button:hover {
  opacity: 0.95;
  box-shadow: 0 4px 15px rgba(0, 242, 254, 0.3);
}

.crm-chat-input-bar button:active {
  transform: scale(0.97);
}
