/* ============================================
   PropCRM — WhatsApp Module (Responsive)
   ============================================ */

.wa-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: 100%;
}

/* ── Chat List Sidebar ── */
.wa-sidebar {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  transition: transform var(--transition);
}

.wa-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.wa-header-title { font-size: var(--fs-lg); font-weight: 700; color: var(--text-primary); }

.wa-icon-btn {
  width: 36px; height: 36px;
  background: none; border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.wa-icon-btn:hover { background: var(--surface2); color: var(--text-primary); }

.wa-search-wrap {
  position: relative;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.wa-search-icon {
  position: absolute; left: 25px; top: 50%; transform: translateY(-50%);
  font-size: 16px; color: var(--text-hint);
}
.wa-search-input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface2);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--text-primary);
  outline: none;
}
.wa-search-input::placeholder { color: var(--text-hint); }
.wa-search-input:focus { border-color: var(--brand); }

.wa-chat-list { flex: 1; overflow-y: auto; }
.wa-chat-list::-webkit-scrollbar { width: 4px; }
.wa-chat-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.wa-chat-item {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.wa-chat-item:hover { background: var(--surface2); }
.wa-chat-item.active { background: #eff6ff; }

.wa-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); font-weight: 700;
  flex-shrink: 0;
}

.wa-chat-info { flex: 1; min-width: 0; }
.wa-chat-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.wa-chat-name { font-size: var(--fs-base); font-weight: 700; color: var(--text-primary); }
.wa-chat-time { font-size: var(--fs-xs); color: var(--text-hint); white-space: nowrap; }
.wa-chat-preview { font-size: var(--fs-sm); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.wa-chat-preview.unread { color: var(--text-primary); font-weight: 600; }

.wa-unread-badge {
  min-width: 20px; height: 20px;
  background: #25d366;
  color: #fff;
  border-radius: 10px;
  font-size: var(--fs-xs); font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
}

/* ── Chat Main Area ── */
.wa-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f0f2f5;
  min-width: 0;
}

.wa-chat-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.wa-header-info { flex: 1; min-width: 0; }
.wa-header-name { font-size: var(--fs-md); font-weight: 700; color: var(--text-primary); }
.wa-header-status { font-size: var(--fs-sm); margin-top: 2px; }
.wa-header-status.ai-on  { color: #16a34a; }
.wa-header-status.ai-off { color: var(--text-secondary); }

.wa-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Messages area */
.wa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 30m-1 0a1 1 0 1 0 2 0a1 1 0 1 0-2 0' fill='%23e0e0e0' opacity='0.4'/%3E%3C/svg%3E");
}
.wa-messages::-webkit-scrollbar { width: 5px; }
.wa-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }

/* Message bubbles */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 72%;
  animation: msgIn 0.2s var(--ease);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.out { margin-left: auto; flex-direction: row-reverse; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: var(--fs-base);
  line-height: 1.55;
  max-width: 100%;
  position: relative;
  word-break: break-word;
}

.msg-bubble.in {
  background: var(--surface);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.msg-bubble.out {
  background: #d9fdd3;
  color: #111;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.msg-bubble.ai {
  background: #e8f4fd;
  color: #0c4a6e;
  border-bottom-right-radius: 4px;
  border: 1px solid #bae6fd;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.ai-label {
  display: flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); font-weight: 700;
  color: #0369a1;
  margin-bottom: 5px;
}
.ai-label i { font-size: 13px; }

.msg-time { font-size: var(--fs-xs); color: var(--text-hint); margin-top: 5px; text-align: right; }
.msg-bubble.in .msg-time { text-align: left; }

/* Date separator */
.date-sep {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  background: rgba(255,255,255,0.85);
  border-radius: 20px;
  padding: 4px 14px;
  margin: 10px auto;
  width: fit-content;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* Input bar */
.wa-input-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.ai-toggle-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 13px;
  font-size: var(--fs-sm); font-weight: 600;
  font-family: var(--font-sans);
  border: 1.5px solid #bbf7d0;
  border-radius: var(--radius-md);
  background: #f0fdf4;
  color: #166534;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  flex-shrink: 0;
}
.ai-toggle-btn:hover { background: #dcfce7; }
.ai-toggle-btn.inactive {
  background: var(--surface2);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}
.ai-toggle-btn i { font-size: 17px; }

.wa-textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  background: var(--surface2);
  color: var(--text-primary);
  resize: none;
  line-height: 1.5;
  max-height: 110px;
  outline: none;
  transition: border-color var(--transition);
}
.wa-textarea::placeholder { color: var(--text-hint); }
.wa-textarea:focus { border-color: var(--brand); background: var(--surface); }

.wa-send-btn {
  width: 44px; height: 44px;
  border: none;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  font-size: 19px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), transform 0.1s;
  flex-shrink: 0;
}
.wa-send-btn:hover { background: var(--brand-dark); }
.wa-send-btn:active { transform: scale(0.92); }

/* Typing indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 5px;
  padding: 11px 14px;
  background: var(--surface);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.typing-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #94a3b8;
  animation: typingPulse 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Back button for mobile ── */
.wa-back-btn {
  display: none;
  background: none; border: none;
  font-size: 22px; color: var(--text-secondary);
  cursor: pointer; padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.wa-back-btn:hover { background: var(--surface2); }

/* ── Responsive: tablet ── */
@media (max-width: 900px) {
  .wa-sidebar { width: 280px; }
}

/* ── Responsive: mobile ── */
@media (max-width: 640px) {
  .wa-sidebar {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 10;
    transition: transform var(--transition);
  }
  .wa-sidebar.hidden {
    transform: translateX(-100%);
  }
  .wa-main { width: 100%; }
  .wa-back-btn { display: flex; align-items: center; }

  .msg-row { max-width: 88%; }
  .wa-messages { padding: 12px 14px; }
  .wa-input-bar { padding: 10px 12px; gap: 8px; }

  .ai-toggle-btn span { display: none; }
  .ai-toggle-btn { padding: 9px 10px; }
}
