*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #111b21;
  display: flex;
  height: 100dvh;
  align-items: center;
  justify-content: center;
}

.app {
  display: flex;
  width: 100%;
  max-width: 1400px;
  height: 100dvh;
  background: #111b21;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 380px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  background: #111b21;
  border-right: 1px solid #222d34;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #202c33;
  height: 60px;
}

.avatar { border-radius: 50%; overflow: hidden; flex-shrink: 0; }
.sidebar-avatar { width: 40px; height: 40px; }
.chat-avatar  { width: 49px; height: 49px; }
.header-avatar { width: 40px; height: 40px; }
.avatar svg { width: 100%; height: 100%; display: block; }

.sidebar-icons { display: flex; gap: 8px; align-items: center; }
.sidebar-icons svg { cursor: pointer; }

.search-bar {
  padding: 8px 12px;
  background: #111b21;
}
.search-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #202c33;
  border-radius: 8px;
  padding: 8px 12px;
}
.search-inner input {
  border: none;
  outline: none;
  background: transparent;
  color: #d1d7db;
  font-size: 14px;
  width: 100%;
}
.search-inner input::placeholder { color: #8696a0; }

.chat-list { list-style: none; overflow-y: auto; flex: 1; }

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid #222d34;
  transition: background 0.15s;
}
.chat-list-item:hover { background: #202c33; }
.chat-list-item.active { background: #2a3942; }

.chat-info { flex: 1; min-width: 0; }
.chat-name { display: block; color: #e9edef; font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { display: block; color: #8696a0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.chat-time { color: #8696a0; font-size: 12px; }

/* ── Chat window ── */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0b141a;
  position: relative;
}

/* WhatsApp-style subtle background pattern */
.chat-window::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M0 0h60v60H0z' fill='none'/%3E%3Cpath d='M30 10c-1 0-2 .5-2.5 1.5L10 42c-.5 1-.5 2 0 3s1.5 1.5 2.5 1.5h35c1 0 2-.5 2.5-1.5s.5-2 0-3L32.5 11.5C32 10.5 31 10 30 10z' fill='%23182229' opacity='.3'/%3E%3C/svg%3E");
  opacity: 0.05;
  pointer-events: none;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #202c33;
  height: 60px;
  z-index: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}

.header-info { display: flex; flex-direction: column; }
.header-name { color: #e9edef; font-size: 17px; font-weight: 500; }
.header-status { color: #8696a0; font-size: 13px; }
.header-status.typing { color: #00a884; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 1;
}

/* ── Bubbles ── */
.message { display: flex; flex-direction: column; max-width: 65%; }
.message.sent { align-self: flex-end; align-items: flex-end; }
.message.received { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 7px 12px 20px;
  border-radius: 7.5px;
  font-size: 14.5px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

.message.sent .bubble {
  background: #005c4b;
  color: #e9edef;
  border-top-right-radius: 0;
}
.message.received .bubble {
  background: #202c33;
  color: #e9edef;
  border-top-left-radius: 0;
}

.timestamp {
  font-size: 11px;
  color: #8696a0;
  margin-top: 2px;
  padding: 0 4px;
}

/* Typing indicator */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #202c33;
  border-radius: 7.5px;
  border-top-left-radius: 0;
  width: fit-content;
}
.typing-bubble span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #8696a0;
  display: inline-block;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── Input bar ── */
.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #202c33;
  z-index: 1;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 50%;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,.08); }

.emoji-btn { color: #8696a0; }

#msg-input {
  flex: 1;
  background: #2a3942;
  border: none;
  outline: none;
  border-radius: 8px;
  padding: 10px 14px;
  color: #e9edef;
  font-size: 15px;
  line-height: 1.4;
}
#msg-input::placeholder { color: #8696a0; }

.send-btn {
  width: 48px; height: 48px;
  background: #00a884;
  border-radius: 50%;
  flex-shrink: 0;
}
.send-btn:hover { background: #02c39a; }
.send-btn:disabled { background: #2a3942; cursor: default; }

/* ── Error toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #ff4757;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
}
.toast.show { opacity: 1; }

/* ── Responsive ── */
@media (max-width: 700px) {
  .sidebar { display: none; }
  .messages { padding: 12px 4%; }
}

/* ── Endpoint badge (cabecera) ── */
.header-phone {
  margin-left: auto;
  margin-right: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  user-select: none;
  background: #1e3a5f;
  color: #93c5fd;
  border: 1px solid #3b82f644;
  font-family: monospace;
  transition: opacity 0.2s;
}
.header-phone:hover { opacity: 0.8; }
.header-phone[data-phone="34600000001"] {
  background: #3b1f5e;
  color: #d8b4fe;
  border-color: #a855f744;
}

.header-endpoint {
  margin-right: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  background: #1a7f4b;
  color: #d1fae5;
  border: 1px solid #22c55e44;
  transition: opacity 0.2s;
}
.header-endpoint:hover { opacity: 0.8; }
.header-endpoint[data-endpoint="test"] {
  background: #7c3aed22;
  color: #c4b5fd;
  border-color: #7c3aed44;
}

/* ── Modal selector de endpoint ── */
.ep-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: ep-fade-in 0.15s ease;
}
@keyframes ep-fade-in { from { opacity: 0; } to { opacity: 1; } }

.ep-modal {
  background: #1f2c34;
  border: 1px solid #2a3942;
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: ep-slide-up 0.15s ease;
}
@keyframes ep-slide-up { from { transform: translateY(12px); opacity:0; } to { transform: translateY(0); opacity:1; } }

.ep-title {
  font-size: 16px;
  font-weight: 700;
  color: #e9edef;
  margin-bottom: 4px;
}
.ep-subtitle {
  font-size: 13px;
  color: #8696a0;
  margin-bottom: 20px;
}
.ep-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ep-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #2a3942;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.ep-btn:hover { background: #374248; }
.ep-btn.active {
  border-color: #00a884;
  background: #00a88411;
}
.ep-tag {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: #1a7f4b;
  color: #d1fae5;
}
.ep-tag--test {
  background: #7c3aed22;
  color: #c4b5fd;
}
.ep-tag--phone {
  background: #1e3a5f;
  color: #93c5fd;
}
.ep-subtitle--phone {
  margin-top: 20px;
  margin-bottom: 12px;
}
.ep-url {
  font-size: 12px;
  color: #8696a0;
  word-break: break-all;
  font-family: monospace;
}
.ep-btn.active .ep-url { color: #aecbba; }
.ep-hint {
  margin-top: 16px;
  font-size: 11px;
  color: #4a5568;
  text-align: center;
}
