/* ============================================================
   WhatsApp CRM - Custom Styles
   ============================================================ */

/* ── Chat Layout ─────────────────────────────────────────── */
.chat-wrapper {
  display: flex;
  /* viewport - navbar(4.5rem) - body-padding(top+bottom = 1.875rem at <1400px) */
  height: calc(100vh - 4.5rem - 1.875rem);
  min-height: 400px;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--base-color, #fff);
}

@media (min-width: 1400px) {
  .chat-wrapper {
    /* body-padding = 1.5rem top + 1.5rem bottom = 3rem */
    height: calc(100vh - 4.5rem - 3rem);
  }
}

.chat-sidebar {
  width: 320px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color, #e5e7eb);
  overflow: hidden;
}

.chat-sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  flex-shrink: 0;
}

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color, #f3f4f6);
  transition: background .15s;
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--primary-50, #eff6ff);
}

.conversation-item .conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #25D366;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.conversation-item .conv-info {
  flex: 1;
  min-width: 0;
}

.conversation-item .conv-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item .conv-preview {
  font-size: 12px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item .conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.conversation-item .conv-time {
  font-size: 11px;
  color: #9ca3af;
}

.conv-badge {
  background: #25D366;
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Chat Main ───────────────────────────────────────────── */
.chat-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Active chat panel fills remaining height of .chat-main */
#chatActive {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  flex-shrink: 0;          /* never compress the header */
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  background: #f0f2f5;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-bubble {
  flex-shrink: 0;          /* KEY: messages must NOT shrink — overflow triggers scroll */
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  position: relative;
  word-break: break-word;
}

.msg-bubble.in {
  background: #fff;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.msg-bubble.out {
  background: #dcf8c6;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.msg-time {
  font-size: 10px;
  color: #9ca3af;
  text-align: right;
  margin-top: 2px;
}

.chat-input-area {
  flex-shrink: 0;          /* always visible at the bottom */
  padding: 12px 16px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-input-area textarea {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 8px 16px;
  resize: none;
  outline: none;
  font-size: 14px;
  max-height: 120px;
}

.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  color: #9ca3af;
  gap: 12px;
}

.chat-empty-state i {
  font-size: 64px;
  color: #d1d5db;
}

/* ── Status Badges ───────────────────────────────────────── */
.badge-open     { background: #dcfce7; color: #16a34a; }
.badge-pending  { background: #fef3c7; color: #d97706; }
.badge-bot      { background: #ede9fe; color: #7c3aed; }
.badge-closed   { background: #f3f4f6; color: #6b7280; }

/* ── Drawflow Custom ─────────────────────────────────────── */
#drawflow {
  width: 100%;
  height: calc(100vh - 4.5rem - 3rem - 130px);
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  position: relative;
}

.drawflow-node {
  border-radius: 8px !important;
}

.drawflow-node.message  { border-color: #3b82f6 !important; }
.drawflow-node.condition { border-color: #f59e0b !important; }
.drawflow-node.input    { border-color: #8b5cf6 !important; }
.drawflow-node.alegra   { border-color: #10b981 !important; }
.drawflow-node.claude   { border-color: #6366f1 !important; }
.drawflow-node.assign   { border-color: #ec4899 !important; }
.drawflow-node.end      { border-color: #ef4444 !important; }

/* ── Auth Page ───────────────────────────────────────────── */
.auth .auth-left {
  background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
}

.otp-inputs {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.otp-inputs input {
  width: 52px;
  height: 56px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  outline: none;
  transition: border-color .2s;
}

.otp-inputs input:focus {
  border-color: #25D366;
}

/* ── Chatbot Toolbar ─────────────────────────────────────── */
.chatbot-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 12px;
}

.node-drag-btn {
  cursor: grab;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: 2px solid transparent;
  background: #f3f4f6;
  transition: all .15s;
}

.node-drag-btn:hover  { filter: brightness(.95); }
.node-drag-btn:active { cursor: grabbing; }
