/* =============================================
   Alarmas.dev · Chat Widget (Sprint 1 · 2026-05-19)
   Asistente conversacional con IA
   ============================================= */

:root {
  --chat-primary: #4F7CFF;
  --chat-accent: #FF7A59;
  --chat-bg: #ffffff;
  --chat-bg-soft: #F4F6FB;
  --chat-bg-bot: #F8F9FC;
  --chat-bg-user: linear-gradient(135deg, #4F7CFF 0%, #6F8DFF 100%);
  --chat-text: #1F2937;
  --chat-text-soft: #6B7280;
  --chat-border: #E5E7EB;
  --chat-shadow: 0 12px 40px rgba(31, 41, 55, 0.18);
  --chat-shadow-button: 0 8px 24px rgba(79, 124, 255, 0.35);
  --chat-radius: 16px;
}

/* ------- Premium pill launcher (centered bottom) ------- */
.chat-launcher {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px) scale(0.94);
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px 11px 14px;
  height: auto;
  width: auto;
  min-height: 48px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1F2937 0%, #2F3F5C 50%, #4F7CFF 100%);
  color: #ffffff;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  box-shadow:
    0 14px 40px rgba(31, 41, 55, 0.32),
    0 4px 12px rgba(79, 124, 255, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.25s cubic-bezier(.2,.8,.25,1), box-shadow 0.25s ease, opacity 0.25s ease;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.chat-launcher.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}
.chat-launcher:hover {
  transform: translateX(-50%) translateY(-2px) scale(1.02);
  box-shadow:
    0 18px 50px rgba(31, 41, 55, 0.42),
    0 6px 16px rgba(79, 124, 255, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.chat-launcher-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4F7CFF 0%, #FF7A59 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79, 124, 255, 0.5), inset 0 1px 0 rgba(255,255,255,0.3);
  position: relative;
}
.chat-launcher-avatar::after {
  content: '';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  background: #4ADE80;
  border-radius: 50%;
  border: 2px solid #1F2937;
  box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.4);
}
.chat-launcher-avatar svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-launcher-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.05;
}
.chat-launcher-label-top {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 2px;
}
.chat-launcher-label-main {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
}
.chat-launcher .chat-launcher-badge {
  background: #FF3B30;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 12px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(255, 59, 48, 0.4);
  border: 2px solid #ffffff;
  margin-left: 4px;
}

/* ------- Inviter bubble (encima del launcher, centrado) ------- */
.chat-inviter {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 9998;
  background: #ffffff;
  color: var(--chat-text);
  padding: 10px 32px 10px 14px;
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(31, 41, 55, 0.18), 0 2px 8px rgba(31, 41, 55, 0.08);
  border: 1px solid rgba(31, 41, 55, 0.06);
  font-size: 13px;
  font-weight: 500;
  max-width: 260px;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  cursor: pointer;
  white-space: normal;
}
.chat-inviter.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
/* Pequeña flecha apuntando al launcher de abajo */
.chat-inviter::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-right: 1px solid rgba(31, 41, 55, 0.06);
  border-bottom: 1px solid rgba(31, 41, 55, 0.06);
  transform: translateX(-50%) rotate(45deg);
  border-bottom-right-radius: 2px;
}
.chat-inviter strong {
  display: block;
  font-weight: 700;
  margin-bottom: 1px;
  color: var(--chat-primary);
  font-size: 13px;
}
.chat-inviter .chat-inviter-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(31, 41, 55, 0.08);
  border: none;
  color: var(--chat-text-soft);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease;
}
.chat-inviter .chat-inviter-close:hover {
  background: rgba(31, 41, 55, 0.16);
}
/* Cuando el sticky CTA mobile está visible, el inviter sube con el launcher */
.mobile-cta-stack.is-visible ~ .chat-inviter,
body:has(.mobile-cta-stack.is-visible) .chat-inviter {
  bottom: 152px;
}

/* ------- Chat panel ------- */
.chat-panel {
  position: fixed;
  bottom: 92px;
  right: 20px;
  z-index: 9999;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.chat-panel.is-open {
  display: flex;
  animation: chat-slide-up 0.25s ease-out;
}
@keyframes chat-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------- Header ------- */
.chat-header {
  background: linear-gradient(135deg, #1F2937 0%, #2F3F5C 50%, #4F7CFF 100%);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 4px 16px rgba(31, 41, 55, 0.18);
}
.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4F7CFF 0%, #FF7A59 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 17px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(79,124,255,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
}
.chat-header-info {
  flex: 1;
  min-width: 0;
}
.chat-header-name {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 2px;
  letter-spacing: 0.01em;
}
.chat-header-status {
  font-size: 12px;
  margin: 0;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-header-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #4ADE80;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
  animation: pulse-status 2s ease-in-out infinite;
}
@keyframes pulse-status {
  0%, 100% { box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3); }
  50% { box-shadow: 0 0 0 5px rgba(74, 222, 128, 0.05); }
}
.chat-close {
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
  margin-left: 4px;
}
.chat-close:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.06);
}
.chat-close:active { transform: scale(0.96); }

/* ------- Messages area ------- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--chat-bg-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }

.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: chat-msg-in 0.2s ease-out;
}
@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg-bot {
  align-self: flex-start;
  background: var(--chat-bg-bot);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}
.chat-msg-user {
  align-self: flex-end;
  background: var(--chat-bg-user);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}
.chat-msg p { margin: 0 0 4px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg strong { font-weight: 700; }
.chat-msg a { color: inherit; text-decoration: underline; }
.chat-msg-user a { color: #ffffff; }

/* ------- Quick reply chips ------- */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 6px;
  animation: chat-msg-in 0.25s ease-out;
}
.chat-chip {
  background: #ffffff;
  border: 1px solid var(--chat-primary);
  color: var(--chat-primary);
  padding: 8px 14px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: inherit;
}
.chat-chip:hover { background: var(--chat-primary); color: #ffffff; }
.chat-chip:disabled { opacity: 0.5; cursor: default; }

/* ------- Typing indicator ------- */
.chat-typing {
  align-self: flex-start;
  background: var(--chat-bg-bot);
  border: 1px solid var(--chat-border);
  padding: 12px 16px;
  border-radius: 16px 16px 16px 4px;
  display: flex;
  gap: 4px;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--chat-text-soft);
  border-radius: 50%;
  animation: chat-typing 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ------- Input area ------- */
.chat-input-wrap {
  border-top: 1px solid var(--chat-border);
  background: #ffffff;
  padding: 12px 14px 10px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  border: 1px solid var(--chat-border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  outline: none;
  color: var(--chat-text);
  background: #ffffff;
  transition: border-color 0.15s ease;
}
.chat-input:focus { border-color: var(--chat-primary); }
.chat-input::placeholder { color: var(--chat-text-soft); }
.chat-send {
  background: linear-gradient(135deg, var(--chat-primary) 0%, #6F8DFF 100%);
  border: none;
  color: #ffffff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.chat-send:hover { transform: scale(1.05); }
.chat-send:disabled { opacity: 0.4; cursor: default; transform: none; }
.chat-send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-footer {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--chat-text-soft);
}
.chat-footer a {
  color: var(--chat-text-soft);
  text-decoration: none;
}
.chat-footer a:hover { color: var(--chat-primary); }
.chat-handoff-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #1EBE5D !important;
  font-weight: 600;
}
.chat-handoff-link svg { width: 14px; height: 14px; }

/* ------- Mobile adjustments ------- */
@media (max-width: 520px) {
  .chat-launcher {
    bottom: 16px;
    padding: 10px 16px 10px 12px;
    min-height: 44px;
    font-size: 13px;
  }
  .chat-launcher-avatar { width: 26px; height: 26px; }
  .chat-launcher-avatar svg { width: 15px; height: 15px; }
  .chat-launcher-label-top { font-size: 9px; }
  .chat-launcher-label-main { font-size: 13px; }
  .chat-inviter {
    bottom: 78px;
    left: 50%;
    right: auto;
    max-width: 280px;
    padding: 9px 28px 9px 12px;
    font-size: 12.5px;
  }
  .chat-inviter strong { font-size: 12.5px; }
  .mobile-cta-stack.is-visible ~ .chat-inviter,
  body:has(.mobile-cta-stack.is-visible) .chat-inviter {
    bottom: 138px;
  }
  .chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
}

/* ------- Launcher se eleva sobre los botones sticky móvil al aparecer ------- */
.mobile-cta-stack.is-visible ~ .chat-launcher,
body:has(.mobile-cta-stack.is-visible) .chat-launcher {
  bottom: 88px;
}
@media (max-width: 520px) {
  .mobile-cta-stack.is-visible ~ .chat-launcher,
  body:has(.mobile-cta-stack.is-visible) .chat-launcher {
    bottom: 78px;
  }
}
