/* ── CHAT WIDGET ── */

/* Burbuja flotante */
.chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--mag-start), var(--mag-end));
  box-shadow: 0 4px 20px rgba(196,78,196,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(196,78,196,0.6);
}
.chat-bubble svg {
  width: 24px;
  height: 24px;
  fill: #fff;
  transition: opacity 0.2s;
}
.chat-bubble .icon-close { display: none; }
.chat-bubble.open .icon-chat  { display: none; }
.chat-bubble.open .icon-close { display: block; }

/* Badge de notificación */
.chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff4444;
  border: 2px solid var(--bg);
  display: none;
}
.chat-badge.visible { display: block; }

/* Panel */
.chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 999;
  width: 360px;
  height: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.chat-panel.open {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* Header */
.chat-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mag-start), var(--mag-end));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.2;
}
.chat-header-status {
  font-size: 11px;
  color: #4caf50;
  font-weight: 600;
}
.chat-header-status::before {
  content: '● ';
  font-size: 8px;
}
.chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
.chat-close:hover { color: var(--white); background: var(--border); }
.chat-close svg { width: 16px; height: 16px; fill: currentColor; }

/* Área de mensajes */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Burbujas de mensaje */
.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}
.msg-agent {
  align-self: flex-start;
  background: var(--card);
  color: var(--body);
  border-bottom-left-radius: 4px;
}
.msg-user {
  align-self: flex-end;
  background: var(--blue-dim);
  border: 1px solid var(--blue-border);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

/* Indicador typing */
.msg-typing {
  align-self: flex-start;
  background: var(--card);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}
.msg-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.msg-typing span:nth-child(2) { animation-delay: 0.2s; }
.msg-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-5px); opacity: 1; }
}

/* Input row */
.chat-input-row {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: var(--surface);
}
.chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 10px 16px;
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  color: var(--white);
  outline: none;
  transition: border-color 0.2s;
  resize: none;
}
.chat-input::placeholder { color: var(--muted); }
.chat-input:focus { border-color: var(--blue-border); }
.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--mag-start), var(--mag-end));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s;
  align-self: flex-end;
}
.chat-send:disabled { opacity: 0.4; cursor: default; transform: none; }
.chat-send:not(:disabled):hover { transform: scale(1.08); }
.chat-send svg { width: 16px; height: 16px; fill: #fff; }

/* ── RESPONSIVE ── */
@media (max-width: 480px) {
  .chat-panel {
    width: 100vw;
    height: 60vh;
    bottom: 0;
    right: 0;
    border-radius: 20px 20px 0 0;
  }
  .chat-bubble {
    bottom: 16px;
    right: 16px;
  }
}
