/* ============================================================

   Chatbot widget - Sofia (amarresparasiempre.com)

   ============================================================ */



:root {

  --sofia-bg: #1a0736;

  --sofia-bg-soft: #2a0a4a;

  --sofia-card: #3a1362;

  --sofia-accent: #d4af37;

  --sofia-accent-soft: #e6c46a;

  --sofia-text: #f5efe0;

  --sofia-muted: #c4b3dc;

  --sofia-success: #25d366;

}



/* Botón flotante trigger */

#sofia-trigger {

  position: fixed;

  bottom: 25px;

  left: 25px;

  z-index: 9998;

  display: flex;

  align-items: center;

  gap: 10px;

  padding: 14px 20px 14px 18px;

  background: linear-gradient(135deg, #d4af37, #b68e1e);

  color: #1a0736;

  border: none;

  border-radius: 50px;

  font-family: 'Playfair Display', Georgia, serif;

  font-size: 15px;

  font-weight: 700;

  cursor: pointer;

  box-shadow: 0 6px 25px rgba(212, 175, 55, 0.4), 0 0 0 0 rgba(212, 175, 55, 0.7);

  animation: sofia-pulse 2.2s infinite;

  transition: transform 0.25s ease, box-shadow 0.25s ease;

}

#sofia-trigger:hover {

  transform: scale(1.05);

  box-shadow: 0 10px 35px rgba(212, 175, 55, 0.55);

}

#sofia-trigger .sofia-trigger-icon {

  width: 28px;

  height: 28px;

  border-radius: 50%;

  background: rgba(255,255,255,0.25);

  display: flex;

  align-items: center;

  justify-content: center;

  font-size: 16px;

}

@keyframes sofia-pulse {

  0%   { box-shadow: 0 6px 25px rgba(212, 175, 55, 0.4), 0 0 0 0 rgba(212, 175, 55, 0.7); }

  70%  { box-shadow: 0 6px 25px rgba(212, 175, 55, 0.4), 0 0 0 14px rgba(212, 175, 55, 0); }

  100% { box-shadow: 0 6px 25px rgba(212, 175, 55, 0.4), 0 0 0 0 rgba(212, 175, 55, 0); }

}



/* Globo inicial (popup de bienvenida) */

#sofia-welcome {

  position: fixed;

  bottom: 95px;

  left: 25px;

  z-index: 9997;

  max-width: 270px;

  background: var(--sofia-card);

  color: var(--sofia-text);

  padding: 14px 16px 14px 16px;

  border-radius: 14px 14px 4px 14px;

  font-family: 'Crimson Text', Georgia, serif;

  font-size: 14px;

  line-height: 1.5;

  box-shadow: 0 8px 30px rgba(0,0,0,0.35);

  border: 1px solid rgba(212, 175, 55, 0.35);

  animation: sofia-fadein 0.5s ease;

  cursor: pointer;

}

#sofia-welcome::before {

  content: '✨';

  margin-right: 6px;

}

#sofia-welcome .sofia-welcome-close {

  position: absolute;

  top: 4px;

  right: 8px;

  background: none;

  border: none;

  color: var(--sofia-muted);

  cursor: pointer;

  font-size: 18px;

  line-height: 1;

  padding: 4px;

}

@keyframes sofia-fadein {

  from { opacity: 0; transform: translateY(10px); }

  to   { opacity: 1; transform: translateY(0); }

}



/* Panel principal del chat */

#sofia-panel {

  position: fixed;

  bottom: 95px;

  left: 25px;

  z-index: 9999;

  width: 380px;

  max-width: calc(100vw - 40px);

  height: 560px;

  max-height: calc(100vh - 120px);

  background: var(--sofia-bg);

  border-radius: 18px;

  box-shadow: 0 20px 60px rgba(0,0,0,0.5);

  border: 1px solid rgba(212, 175, 55, 0.3);

  display: none;

  flex-direction: column;

  overflow: hidden;

  font-family: 'Crimson Text', Georgia, serif;

  box-sizing: border-box;

}

#sofia-panel.open {

  display: flex;

  animation: sofia-slideup 0.35s ease;

}

@keyframes sofia-slideup {

  from { opacity: 0; transform: translateY(20px) scale(0.95); }

  to   { opacity: 1; transform: translateY(0) scale(1); }

}



/* Header */

.sofia-header {

  display: flex;

  align-items: center;

  gap: 12px;

  padding: 16px 18px;

  background: linear-gradient(135deg, #3a1362, #1a0736);

  border-bottom: 1px solid rgba(212, 175, 55, 0.25);

  position: relative;

}

.sofia-avatar {

  width: 42px;

  height: 42px;

  border-radius: 50%;

  background: linear-gradient(135deg, #d4af37, #b68e1e);

  display: flex;

  align-items: center;

  justify-content: center;

  color: #1a0736;

  font-weight: 700;

  font-size: 16px;

  font-family: 'Cinzel', serif;

  flex-shrink: 0;

}

.sofia-header-info .sofia-name {

  font-family: 'Cinzel', serif;

  font-size: 15px;

  color: var(--sofia-text);

  font-weight: 600;

  letter-spacing: 0.5px;

}

.sofia-header-info .sofia-status {

  font-size: 11px;

  color: var(--sofia-accent-soft);

  display: flex;

  align-items: center;

  gap: 5px;

  font-family: sans-serif;

}

.sofia-status::before {

  content: '';

  width: 7px;

  height: 7px;

  background: #25d366;

  border-radius: 50%;

  box-shadow: 0 0 8px #25d366;

  animation: sofia-blink 2s infinite;

}

@keyframes sofia-blink {

  0%,100% { opacity: 1; }

  50%     { opacity: 0.5; }

}

.sofia-close {

  margin-left: auto;

  background: rgba(255,255,255,0.1);

  border: none;

  color: var(--sofia-text);

  width: 32px;

  height: 32px;

  border-radius: 50%;

  cursor: pointer;

  font-size: 18px;

  display: flex;

  align-items: center;

  justify-content: center;

  transition: background 0.2s;

}

.sofia-close:hover { background: rgba(255,255,255,0.2); }



/* Cuerpo de mensajes */

.sofia-messages {

  flex: 1;

  overflow-y: auto;

  padding: 20px 16px;

  display: flex;

  flex-direction: column;

  gap: 12px;

  scrollbar-width: thin;

  scrollbar-color: var(--sofia-accent) transparent;

}

.sofia-messages::-webkit-scrollbar { width: 6px; }

.sofia-messages::-webkit-scrollbar-thumb {

  background: var(--sofia-accent);

  border-radius: 3px;

}



.sofia-msg {

  max-width: 85%;

  padding: 11px 14px;

  border-radius: 16px;

  font-size: 14.5px;

  line-height: 1.5;

  word-wrap: break-word;

  animation: sofia-msgfade 0.3s ease;

}

@keyframes sofia-msgfade {

  from { opacity: 0; transform: translateY(6px); }

  to   { opacity: 1; transform: translateY(0); }

}

.sofia-msg.bot {

  background: var(--sofia-card);

  color: var(--sofia-text);

  border-bottom-left-radius: 4px;

  align-self: flex-start;

  border: 1px solid rgba(212, 175, 55, 0.2);

}

.sofia-msg.user {

  background: linear-gradient(135deg, #d4af37, #b68e1e);

  color: #1a0736;

  border-bottom-right-radius: 4px;

  align-self: flex-end;

  font-weight: 500;

}



/* Typing indicator */

.sofia-typing {

  display: inline-flex;

  gap: 4px;

  padding: 14px 18px;

  background: var(--sofia-card);

  border-radius: 16px;

  border-bottom-left-radius: 4px;

  align-self: flex-start;

  border: 1px solid rgba(212, 175, 55, 0.2);

}

.sofia-typing span {

  width: 7px;

  height: 7px;

  border-radius: 50%;

  background: var(--sofia-accent);

  animation: sofia-bounce 1.4s infinite ease-in-out;

}

.sofia-typing span:nth-child(2) { animation-delay: 0.2s; }

.sofia-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sofia-bounce {

  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }

  30% { transform: translateY(-6px); opacity: 1; }

}



/* Botón WhatsApp permanente abajo */

.sofia-wa-cta {

  padding: 12px 16px;

  background: var(--sofia-bg-soft);

  border-top: 1px solid rgba(212, 175, 55, 0.25);

  border-bottom: 1px solid rgba(212, 175, 55, 0.25);

}

.sofia-wa-cta a {

  display: flex;

  align-items: center;

  justify-content: center;

  gap: 8px;

  background: #25d366;

  color: #fff !important;

  padding: 11px 16px;

  border-radius: 10px;

  text-decoration: none !important;

  font-weight: 700;

  font-family: sans-serif;

  font-size: 14px;

  transition: transform 0.2s, box-shadow 0.2s;

  box-shadow: 0 4px 15px rgba(37, 211, 102, 0.3);

}

.sofia-wa-cta a:hover {

  transform: translateY(-1px);

  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.45);

}

.sofia-wa-cta svg { width: 18px; height: 18px; flex-shrink: 0; }



/* Input area */

.sofia-input-wrap {

  display: flex;

  gap: 8px;

  padding: 12px 14px 14px;

  border-top: 1px solid rgba(212, 175, 55, 0.15);

}

.sofia-input {

  flex: 1 1 auto;

  min-width: 0; /* critical para que flex children no desborden */

  padding: 11px 14px;

  background: var(--sofia-card);

  border: 1px solid rgba(212, 175, 55, 0.3);

  border-radius: 12px;

  color: var(--sofia-text);

  font-family: 'Crimson Text', Georgia, serif;

  font-size: 16px; /* 16px evita que iOS haga zoom automatico */

  resize: none;

  max-height: 100px;

  line-height: 1.4;

  transition: border-color 0.2s;

  box-sizing: border-box;

  width: 100%;

}

.sofia-input:focus {

  outline: none;

  border-color: var(--sofia-accent);

}

.sofia-input::placeholder { color: var(--sofia-muted); }



.sofia-send {

  background: linear-gradient(135deg, #d4af37, #b68e1e);

  border: none;

  color: #1a0736;

  width: 44px;

  height: 44px;

  border-radius: 12px;

  cursor: pointer;

  font-size: 18px;

  flex-shrink: 0;

  display: flex;

  align-items: center;

  justify-content: center;

  transition: transform 0.2s;

}

.sofia-send:hover { transform: scale(1.05); }

.sofia-send:disabled {

  opacity: 0.5;

  cursor: not-allowed;

  transform: none;

}



/* Footer privacy */

.sofia-footer {

  padding: 6px 14px 10px;

  text-align: center;

  font-size: 10.5px;

  color: var(--sofia-muted);

  font-family: sans-serif;

  letter-spacing: 0.3px;

}

.sofia-footer a {

  color: var(--sofia-accent);

  text-decoration: none;

}



/* Responsive - mobile */

@media (max-width: 480px) {

  #sofia-panel {

    /* Anclar a TODOS los bordes para que el teclado no pueda mover el panel */

    right: 10px;

    left: 10px;

    top: auto;

    bottom: 85px;

    width: auto;

    max-width: none;

    height: auto;

    max-height: calc(100vh - 110px);

    max-height: calc(100dvh - 110px); /* dynamic viewport height: se ajusta al teclado */

  }

  /* Evitar que el input-wrap desborde cuando hay pocos pixels */

  .sofia-input-wrap {

    padding: 10px 12px 12px;

  }

  .sofia-input {

    max-width: 100%;

  }

  #sofia-trigger {

    left: 15px;

    bottom: 15px;

    padding: 12px 16px 12px 14px;

    font-size: 14px;

  }

  #sofia-welcome {

    right: 15px;

    left: 15px;

    max-width: none;

    bottom: 75px;

  }

}



/* Cuando el panel esta abierto en mobile, prevenir scroll horizontal del body */

body.sofia-open {

  overflow-x: hidden;

}



/* Ocultar el boton de WhatsApp nativo de la web cuando el chat esta abierto, para que no se superponga */

body.sofia-open .wa-float,

body.sofia-open [class*="whatsapp-float"],

body.sofia-open a[href*="whatsapp://send"]:not(.sofia-wa-cta a) {

  /* no modificamos nada del sitio en vivo, solo el test */

}

