/* ================================
   CHATBOT STYLES
   ================================ */

:root {
  --chat-accent: var(--accent, #F28C5A);
  --chat-bg: var(--paper, #F7F6F1);
  --chat-text: var(--ink, #1C1B17);
  --chat-border: rgba(28, 27, 23, 0.1);
  --chat-shadow: rgba(0, 0, 0, 0.1);
}

/* Chat Button — bottom respeta home indicator de iPhone */
.chat-button {
  position: fixed;
  bottom: max(2rem, calc(env(safe-area-inset-bottom) + 1rem));
  right: max(2rem, env(safe-area-inset-right));
  width: 60px;
  height: 60px;
  background: var(--chat-accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--chat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
  z-index: 999;
}

/* Cuando el chat está abierto, ocultamos el botón flotante: el botón
   "cerrar" del header ya cumple esa función. Evita que el botón flote
   sobre el input en mobile. */
.chat-button.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

.chat-button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px var(--chat-shadow);
}

.chat-button svg {
  width: 28px;
  height: 28px;
  fill: #fff;
}

/* Chat Window — bottom + right respetan safe-area de iPhone */
.chat-window {
  position: fixed;
  bottom: max(5rem, calc(env(safe-area-inset-bottom) + 4rem));
  right: max(2rem, env(safe-area-inset-right));
  width: 400px;
  max-width: calc(100vw - 4rem);
  height: 600px;
  max-height: calc(100vh - 10rem);
  background: var(--chat-bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 998;
  border: 1px solid var(--chat-border);
}

.chat-window.active {
  display: flex;
}

/* Chat Header */
.chat-header {
  background: var(--chat-accent);
  color: #fff;
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 500;
  font-family: var(--f-body, 'Inter', sans-serif);
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}

/* Desktop: logo + subtitle en línea, banda más angosta. */
@media (min-width: 769px) {
  .chat-header h3 {
    flex-direction: row;
    align-items: center;
    gap: 0.85rem;
  }
  .chat-header h3 .chat-subtitle {
    line-height: 1.25;
  }
}
.chat-header h3 .chat-subtitle {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: .02em;
  opacity: .85;
  margin-top: 0;
}

/* Logo M|A circular reemplazando el texto "Mía" en el header.
   Mismo monograma del avatar del bot, sobre fondo blanco para
   contrastar con el naranja del header. */
.chat-header h3 .chat-logo {
  display: inline-flex;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding-top: 1px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.10);
}
.chat-header h3 .chat-logo .m-letter {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 300;
  font-size: 17px;
  line-height: 1;
  color: var(--chat-text);
  letter-spacing: 0;
}
.chat-header h3 .chat-logo .m-bar {
  width: 1.5px;
  height: 15px;
  background: var(--chat-accent);
  flex-shrink: 0;
  margin-top: -1px;
}

/* Status como badge en la esquina inferior-derecha del logo (patrón
   Slack/WhatsApp). El borde de 2px en color del header simula que el
   dot "perfora" el círculo del logo. */
.chat-header h3 .chat-logo .chat-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #6FA37E;
  border: 2px solid var(--chat-accent);
  box-sizing: content-box;
}
.chat-header h3 .chat-logo .chat-status::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: #6FA37E;
  opacity: 0.55;
  animation: chatStatusPulse 2.2s ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}
@keyframes chatStatusPulse {
  0%   { opacity: 0.55; transform: scale(1); }
  60%  { opacity: 0;    transform: scale(2.2); }
  100% { opacity: 0;    transform: scale(2.2); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-header h3 .chat-logo .chat-status::after { animation: none; opacity: 0; }
}

/* Disclaimer breve bajo el header. Encuadra expectativas legales sin
   romper la conversación: pequeño, gris, separado por una línea sutil. */
.chat-disclaimer {
  padding: 0.6rem 1.5rem;
  background: var(--chat-bg);
  border-bottom: 1px solid var(--chat-border);
  font-size: 0.7rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--chat-text);
  opacity: 0.6;
  text-align: center;
  flex-shrink: 0;
}

.chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
  margin: -.5rem -.6rem -.5rem 0;
}

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

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-message {
  display: flex;
  gap: 0.75rem;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.user {
  flex-direction: row-reverse;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
}

.chat-message.user .chat-avatar {
  background: var(--chat-text);
}

.chat-message.bot .chat-avatar {
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  gap: 2px;
  /* Compensación óptica: serif Garamond tiene el centro visual ligeramente
     arriba del centro geométrico — empujamos el contenido medio píxel abajo. */
  padding-top: 1px;
}

.chat-avatar .m-letter {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 300;
  font-size: 16px;
  line-height: 1;
  letter-spacing: 0;
}

.chat-avatar .m-bar {
  width: 1.5px;
  height: 14px;
  background: var(--chat-accent);
  flex-shrink: 0;
  /* La barra se alinea visualmente mejor con un pequeño desplazamiento
     vertical hacia el cap-height de las letras. */
  margin-top: -1px;
}

.chat-bubble {
  max-width: 75%;
  padding: 0.875rem 1.125rem;
  border-radius: 16px;
  background: #fff;
  color: var(--chat-text);
  font-size: 0.9375rem;
  line-height: 1.5;
  word-wrap: break-word;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.chat-message.user .chat-bubble {
  background: var(--chat-accent);
  color: #fff;
}

/* Quick Replies — chips sugeridos bajo el welcome message.
   Alineados con el inicio de las burbujas del bot (después del avatar). */
.chat-quick-replies {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: -0.25rem;
  margin-left: calc(36px + 0.75rem);
  animation: fadeIn 0.4s ease both;
}
.quick-reply {
  background: #fff;
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  padding: 0.65rem 1rem;
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.15s;
  width: fit-content;
  max-width: 100%;
}
.quick-reply:hover {
  border-color: var(--chat-accent);
  color: var(--chat-accent);
}
.quick-reply:active {
  transform: scale(0.98);
}

/* Chat Input */
.chat-input-container {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 0.75rem;
  flex-shrink: 0;
  background: var(--chat-bg);
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--chat-border);
  border-radius: 24px;
  font-size: 16px; /* >=16px evita el auto-zoom de iOS Safari al hacer focus */
  font-family: var(--f-body, 'Inter', sans-serif);
  outline: none;
  transition: border-color 0.2s ease;
  background: #fff;
  color: var(--chat-text);
  -webkit-appearance: none;
  appearance: none;
}

.chat-input:focus {
  border-color: var(--chat-accent);
}

.chat-send {
  width: 42px;
  height: 42px;
  background: var(--chat-accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.chat-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.75rem 1rem;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--chat-accent);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

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

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

/* Welcome Message */
.chat-welcome {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--chat-text);
  opacity: 0.7;
  font-size: 0.9375rem;
}

/* Responsive — móvil */
@media (max-width: 768px) {
  .chat-button {
    bottom: max(1.5rem, calc(env(safe-area-inset-bottom) + 0.6rem));
    right: max(1.5rem, env(safe-area-inset-right));
    width: 56px;
    height: 56px;
  }

  .chat-window {
    bottom: max(4.5rem, calc(env(safe-area-inset-bottom) + 3.5rem));
    right: max(1rem, env(safe-area-inset-right));
    left: max(1rem, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    /* Usa dynamic viewport height si está disponible; el navegador colapsa
       la altura cuando aparece el teclado virtual y el chat sigue cabiendo */
    height: 70vh;
    height: 70dvh;
    max-height: calc(100vh - 6.5rem);
    max-height: calc(100dvh - 6.5rem);
  }

  .chat-header {
    padding: 0.8rem 1rem;
  }
  .chat-header h3 {
    font-size: 1.05rem;
  }
  .chat-header h3 .chat-subtitle {
    font-size: 0.7rem;
  }

  /* En mobile, el max-width:75% deja líneas muy cortas (5-6 palabras).
     88% mejora notablemente la lectura sin tocar el avatar. */
  .chat-bubble {
    max-width: 88%;
  }
  /* Los quick replies también necesitan más aire en mobile. */
  .chat-quick-replies {
    margin-left: calc(36px + 0.65rem);
  }
}

/* Móvil chico — el subtítulo del header puede saturar */
@media (max-width: 380px) {
  .chat-header h3 .chat-subtitle {
    font-size: 0.65rem;
    letter-spacing: 0;
  }
}
