/* ==========================================================================
   Cruzimex — Widget de chat (vanilla, sin dependencias)
   Color primario: #0254A7
   ========================================================================== */

:root {
  --cz-primary: #0254A7;
  --cz-primary-dark: #013d7d;
  --cz-bg: #ffffff;
  --cz-bg-user: #0254A7;
  --cz-bg-agent: #f0f2f5;
  --cz-text-user: #ffffff;
  --cz-text-agent: #1a1a1a;
  --cz-border: #e2e5e9;
  --cz-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  --cz-radius: 14px;
  --cz-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

#cz-chat-root {
  font-family: var(--cz-font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Burbuja flotante ---------- */
#cz-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cz-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--cz-shadow);
  z-index: 999999;
  transition: transform 0.15s ease, background 0.15s ease;
  padding: 0;
}

#cz-chat-bubble:hover {
  transform: scale(1.06);
  background: var(--cz-primary-dark);
}

#cz-chat-bubble svg {
  width: 28px;
  height: 28px;
  fill: #fff;
}

#cz-chat-bubble .cz-unread-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff4757;
  border: 2px solid #fff;
  display: none;
}

#cz-chat-bubble.cz-has-unread .cz-unread-dot {
  display: block;
}

/* ---------- Panel del chat ---------- */
#cz-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 360px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--cz-bg);
  border-radius: var(--cz-radius);
  box-shadow: var(--cz-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 999998;
  border: 1px solid var(--cz-border);
}

#cz-chat-panel.cz-open {
  display: flex;
  animation: cz-panel-in 0.18s ease-out;
}

@keyframes cz-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
#cz-chat-header {
  background: var(--cz-primary);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#cz-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

#cz-chat-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cz-primary);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

#cz-chat-header-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

#cz-chat-header-subtitle {
  font-size: 12px;
  opacity: 0.85;
  line-height: 1.2;
  margin-top: 2px;
}

#cz-chat-close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
  border-radius: 6px;
}

#cz-chat-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

#cz-chat-close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Cuerpo de mensajes */
#cz-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafbfc;
}

#cz-chat-body::-webkit-scrollbar {
  width: 6px;
}

#cz-chat-body::-webkit-scrollbar-thumb {
  background: #cfd5db;
  border-radius: 3px;
}

.cz-msg-row {
  display: flex;
  width: 100%;
}

.cz-msg-row.cz-from-user {
  justify-content: flex-end;
}

.cz-msg-row.cz-from-agent {
  justify-content: flex-start;
}

.cz-msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.cz-from-user .cz-msg-bubble {
  background: var(--cz-bg-user);
  color: var(--cz-text-user);
  border-bottom-right-radius: 4px;
}

.cz-from-agent .cz-msg-bubble {
  background: var(--cz-bg-agent);
  color: var(--cz-text-agent);
  border-bottom-left-radius: 4px;
}

.cz-msg-bubble.cz-error {
  background: #fdecea;
  color: #9c2b1f;
  border: 1px solid #f3c4bd;
}

.cz-retry-btn {
  margin-top: 6px;
  display: inline-block;
  background: none;
  border: 1px solid #9c2b1f;
  color: #9c2b1f;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.cz-retry-btn:hover {
  background: #9c2b1f;
  color: #fff;
}

/* Indicador "escribiendo" */
.cz-typing-bubble {
  background: var(--cz-bg-agent);
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cz-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9098a3;
  animation: cz-typing-bounce 1.2s infinite ease-in-out;
}

.cz-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.cz-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes cz-typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Pie / input */
#cz-chat-footer {
  border-top: 1px solid var(--cz-border);
  padding: 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: #fff;
}

#cz-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--cz-border);
  border-radius: 20px;
  padding: 10px 14px;
  font-family: var(--cz-font);
  font-size: 14px;
  line-height: 1.35;
  max-height: 90px;
  outline: none;
}

#cz-chat-input:focus {
  border-color: var(--cz-primary);
}

#cz-chat-send {
  background: var(--cz-primary);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

#cz-chat-send:hover {
  background: var(--cz-primary-dark);
}

#cz-chat-send:disabled {
  background: #b7c3d1;
  cursor: not-allowed;
}

#cz-chat-send svg {
  width: 18px;
  height: 18px;
  fill: #fff;
  margin-left: -1px;
}

/* ---------- Responsive: móvil ---------- */
@media (max-width: 480px) {
  #cz-chat-panel {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    border: none;
  }

  #cz-chat-bubble {
    bottom: 16px;
    right: 16px;
  }
}
