/* ================================================================
   chat-widget.css — SPEC-045: Chat widget de prospectos OpsTrack
   Mobile-first: estilos base para móvil, min-width para desktop.
   ================================================================ */

:root {
  --chat-primary:  #1B3A5C;
  --chat-accent:   #E07B39;
  --chat-bg:       #F4F6F9;
  --chat-radius:   1rem;
  --chat-shadow:   0 8px 32px rgba(0,0,0,.14);
  --chat-width:    360px;
}

/* ── Burbuja ─────────────────────────────────────────────────────── */
.chat-bubble {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 1rem);
  right: 1rem;
  z-index: 9000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--chat-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(224,123,57,.45);
  transition: transform .2s, box-shadow .2s;
}
.chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(224,123,57,.55);
}
.chat-bubble svg { width: 26px; height: 26px; }

/* ── Ripple / Sonar ───────────────────────────────────────────────── */
.chat-bubble::before,
.chat-bubble::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--chat-accent);
  animation: chat-ripple 2.4s ease-out infinite;
  z-index: -1;
}
.chat-bubble::after {
  animation-delay: 1.2s;
}
.chat-bubble:hover::before,
.chat-bubble:hover::after {
  animation-play-state: paused;
}

@keyframes chat-ripple {
  0%   { transform: scale(1);   opacity: .5; }
  100% { transform: scale(2.2); opacity: 0;  }
}

/* ── Panel principal ─────────────────────────────────────────────── */
.chat-panel {
  position: fixed;
  bottom: 4.5rem;
  right: 0;
  left: 0;
  z-index: 9000;
  width: 100%;
  max-height: 72dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 1rem 1rem 0 0;
  box-shadow: var(--chat-shadow);
  overflow: hidden;
  transform-origin: bottom center;
  transition: opacity .2s, transform .2s;
}
.chat-panel[hidden] {
  display: none;
}

/* ── Header ──────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1rem;
  background: var(--chat-primary);
  color: #fff;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-header-avatar svg { width: 20px; height: 20px; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name {
  font-weight: 600;
  font-size: .9rem;
  line-height: 1.2;
}
.chat-header-status {
  font-size: .75rem;
  color: rgba(255,255,255,.72);
}
.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  padding: .25rem;
  border-radius: .375rem;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.chat-close-btn:hover {
  color: #fff;
  background: rgba(255,255,255,.12);
}
.chat-close-btn svg { width: 18px; height: 18px; }

/* ── Área de mensajes ────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .625rem;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

/* ── Burbujas de mensaje ─────────────────────────────────────────── */
.chat-msg {
  max-width: 82%;
  padding: .625rem .875rem;
  border-radius: 1rem;
  font-size: .875rem;
  line-height: 1.5;
  word-break: break-word;
  animation: chat-msg-in .18s ease-out;
}
@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg-bot {
  background: var(--chat-bg);
  color: #1a202c;
  border-bottom-left-radius: .25rem;
  align-self: flex-start;
}
.chat-msg-user {
  background: var(--chat-primary);
  color: #fff;
  border-bottom-right-radius: .25rem;
  align-self: flex-end;
}

/* Markdown renderizado dentro de mensajes del bot */
.chat-msg-bot p {
  margin: 0 0 .4rem 0;
}
.chat-msg-bot p:last-child { margin-bottom: 0; }
.chat-msg-bot ul {
  margin: .25rem 0 .25rem 1rem;
  padding: 0;
  list-style: disc;
}
.chat-msg-bot li { margin-bottom: .2rem; }
.chat-msg-bot strong { font-weight: 600; }

/* ── Indicador de escritura ──────────────────────────────────────── */
.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: .625rem .875rem;
  background: var(--chat-bg);
  border-radius: 1rem;
  border-bottom-left-radius: .25rem;
  align-self: flex-start;
  animation: chat-msg-in .18s ease-out;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: chat-typing-dot 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-typing-dot {
  0%, 80%, 100% { transform: scale(.8); opacity: .5; }
  40%           { transform: scale(1.1); opacity: 1; }
}

/* ── Chips de selección rápida ───────────────────────────────────── */
.chat-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .25rem .5rem .5rem;
  align-self: flex-start;
  max-width: 100%;
}
.chat-chip {
  padding: .35rem .75rem;
  border-radius: 999px;
  border: 1.5px solid var(--chat-accent);
  color: var(--chat-accent);
  font-size: .8rem;
  font-weight: 500;
  background: #fff;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.chat-chip:hover {
  background: var(--chat-accent);
  color: #fff;
}

/* ── Fila de input ───────────────────────────────────────────────── */
.chat-input-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .625rem .75rem;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
  background: #fff;
}
.chat-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: .5rem;
  padding: .5rem .75rem;
  font-size: .875rem;
  outline: none;
  transition: border-color .15s;
  min-width: 0;
}
.chat-input:focus { border-color: var(--chat-primary); }
.chat-input:disabled { background: #f7fafc; cursor: not-allowed; }
.chat-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: .5rem;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s;
}
.chat-send-btn:hover { opacity: .85; }
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }
.chat-send-btn svg { width: 18px; height: 18px; }

/* ── Desktop ─────────────────────────────────────────────────────── */
@media (min-width: 481px) {
  .chat-bubble {
    bottom: 1.5rem;
    right: 1.5rem;
  }
  .chat-panel {
    width: var(--chat-width);
    right: 1.5rem;
    left: auto;
    bottom: 5.5rem;
    border-radius: var(--chat-radius);
    max-height: 70dvh;
    transform-origin: bottom right;
  }
}
