/* ============================================
   Neuratta — WhatsApp Module con pestañas
   ============================================ */

#page-whatsapp {
  display: none;
  height: calc(100vh - var(--topbar-height));
  flex-direction: column;
  overflow: hidden;
}
#page-whatsapp.active { display: flex; }

/* ── Barra de pestañas ── */
.wa-tabs-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 20px;
  flex-shrink: 0;
  overflow-x: auto;
}
.wa-tabs-bar::-webkit-scrollbar { display: none; }

.wa-tab {
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.wa-tab:hover { color: var(--brand); }
.wa-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* ── Contenido pestañas ── */
.wa-tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
}
.wa-tab-content.active-tab {
  display: flex;
  flex-direction: column;
}
.wa-tab-content.active-tab.scrollable {
  display: block;
  overflow-y: auto;
  padding: 24px;
}

/* ── Layout conversaciones ── */
.wa-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: 100%;
}

/* ── Sidebar ── */
.wa-sidebar {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

@media (max-width: 900px) { .wa-sidebar { width: 260px; } }

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

.wa-icon-btn {
  width: 34px; height: 34px;
  background: none; border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 17px; 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: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.wa-search-icon {
  position: absolute; left: 22px; top: 50%; transform: translateY(-50%);
  font-size: 15px; color: var(--text-hint);
}
.wa-search-input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  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: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.wa-chat-item:hover { background: var(--surface2); }
.wa-chat-item.active { background: #eff6ff; }

.wa-avatar {
  width: 42px; height: 42px; 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: 2px; }

/* ── Área principal ── */
.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: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.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: 6px; flex-shrink: 0; }

/* ── Mensajes ── */
.wa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-color: #efeae2;
}
.wa-messages::-webkit-scrollbar { width: 5px; }
.wa-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }

.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: 72%; }
.msg-row.out { margin-left: auto; flex-direction: row-reverse; }

.msg-bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: var(--fs-base);
  line-height: 1.5;
  word-break: break-word;
}
.msg-bubble.in {
  background: #fff;
  color: var(--text-primary);
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.msg-bubble.out {
  background: #d9fdd3;
  color: #111;
  border-bottom-right-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.msg-bubble.ai {
  background: #e8f4fd;
  color: #0c4a6e;
  border-bottom-right-radius: 3px;
  border: 1px solid #bae6fd;
}
.ai-label { display: flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 700; color: #0369a1; margin-bottom: 4px; }
.msg-time { font-size: 10px; color: var(--text-hint); margin-top: 4px; text-align: right; }
.msg-bubble.in .msg-time { text-align: left; }

.date-sep {
  text-align: center; font-size: var(--fs-xs); color: #667781;
  background: #d1f4cc; border-radius: 20px;
  padding: 4px 14px; margin: 8px auto; width: fit-content;
}

/* ── Input bar ── */
.wa-input-bar {
  background: #f0f2f5;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.ai-toggle-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  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 0.15s; 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); }

.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: #fff;
  color: var(--text-primary);
  resize: none;
  line-height: 1.5;
  max-height: 110px;
  outline: none;
}
.wa-textarea:focus { border-color: var(--brand); }

.wa-send-btn {
  width: 42px; height: 42px;
  border: none; background: var(--brand); color: #fff;
  border-radius: 50%; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s; flex-shrink: 0;
}
.wa-send-btn:hover { background: var(--brand-dark); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .wa-sidebar { width: 100%; position: absolute; height: 100%; z-index: 10; }
  .wa-tab { padding: 12px 10px; font-size: 13px; }
  .wa-tab span { display: none; }
  .msg-row { max-width: 88%; }
}
