/* Asistente virtual. Usa la paleta de styles.css y añade el rosa empolvado de los mensajes de la clienta. */
:root {
  --chat-rose: #ecd5cc;
  --chat-rose-ink: #4a2f26;
  --chat-shadow: 0 24px 60px rgba(59, 42, 32, 0.22);
}

/* Botón flotante: monograma de la marca con globo de chat, en café espresso con filo dorado */
.chat-launcher {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 24px 8px 8px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #574034 0%, var(--text) 65%);
  color: var(--bg);
  font-family: var(--sans);
  text-align: left;
  cursor: pointer;
  box-shadow:
    0 16px 36px rgba(59, 42, 32, 0.32),
    inset 0 0 0 1px rgba(176, 140, 62, 0.5);
  transition: transform 0.3s ease, box-shadow 0.3s ease, bottom 0.3s ease;
  animation: launcher-in 0.6s cubic-bezier(0.2, 0.8, 0.3, 1.2) 0.5s backwards;
}
.chat-launcher:hover {
  transform: translateY(-3px);
  box-shadow:
    0 20px 44px rgba(59, 42, 32, 0.38),
    inset 0 0 0 1px rgba(176, 140, 62, 0.9);
}
/* Halo suave que llama la atención unas pocas veces al cargar la página */
.chat-launcher::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  animation: launcher-halo 2.4s ease-out 1.4s 3;
}
.chat-launcher.is-active::before { animation: none; }
@keyframes launcher-in {
  from { opacity: 0; transform: translateY(16px) scale(0.9); }
}
@keyframes launcher-halo {
  0% { box-shadow: 0 0 0 0 rgba(212, 137, 94, 0.5); }
  70%, 100% { box-shadow: 0 0 0 16px rgba(212, 137, 94, 0); }
}

.chat-launcher__avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #fffaf4 0%, #efe2d4 100%);
  box-shadow: 0 0 0 2px var(--gold), 0 4px 10px rgba(0, 0, 0, 0.25);
}
/* La "M" dorada del logo */
.chat-launcher__m {
  font: 700 1.55rem/1 var(--brand-serif);
  color: var(--gold);
  transform: scaleX(0.86);
  text-shadow: 0 1px 2px rgba(60, 40, 10, 0.2);
}
.chat-launcher__badge {
  position: absolute;
  top: -5px;
  right: -7px;
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--accent-dark);
  border: 2px solid var(--text);
  color: #fff;
}
.chat-launcher__badge svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}
.chat-launcher__badge svg .fill { fill: currentColor; stroke: none; }
.chat-launcher__x { display: none; color: var(--text); }
.chat-launcher__x svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}
.chat-launcher.is-active .chat-launcher__m,
.chat-launcher.is-active .chat-launcher__badge,
.chat-launcher.is-active .chat-launcher__sub { display: none; }
.chat-launcher.is-active .chat-launcher__x { display: grid; }

.chat-launcher__text { display: grid; gap: 2px; }
.chat-launcher__title {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.1;
}
.chat-launcher__sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: rgba(247, 241, 234, 0.72);
}
/* Punto verde: asistente disponible */
.chat-launcher__sub::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8fbf86;
  box-shadow: 0 0 0 3px rgba(143, 191, 134, 0.22);
}

/* Ventana del chat */
.chat {
  position: fixed;
  right: 28px;
  bottom: 104px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: 390px;
  height: min(640px, calc(100vh - 134px));
  height: min(640px, calc(100dvh - 134px));
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--chat-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.chat[hidden] { display: none; }
.chat.is-open { opacity: 1; transform: none; }

.chat__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 16px 18px;
  background: var(--text);
  color: var(--bg);
}
.chat__avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--gold);
  font: 700 1.35rem var(--brand-serif);
}
.chat__heading { flex: 1; min-width: 0; }
.chat__title { font-family: var(--serif); font-size: 1.3rem; line-height: 1.1; }
.chat__subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: rgba(247, 241, 234, 0.75);
}
.chat__subtitle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8fbf86;
}
.chat__close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 0.2s ease;
}
.chat__close:hover { background: rgba(247, 241, 234, 0.12); }
.chat__close svg,
.chat__send svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Conversación */
.chat__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 100% 0%, rgba(236, 213, 204, 0.45), transparent 40%),
    var(--bg);
  scroll-behavior: smooth;
}
.chat__log:focus { outline: none; }
.chat__msg { display: flex; animation: chat-in 0.3s ease both; }
.chat__msg--user { justify-content: flex-end; }
@keyframes chat-in {
  from { opacity: 0; transform: translateY(6px); }
}
.chat__bubble {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.chat__msg--bot .chat__bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.chat__msg--user .chat__bubble {
  background: var(--chat-rose);
  color: var(--chat-rose-ink);
  border-bottom-right-radius: 6px;
}
.chat__text { white-space: pre-line; }
.chat__note {
  margin-top: 8px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
}

/* Resumen de la solicitud */
.chat__summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 0.88rem;
}
.chat__summary dt { color: var(--muted); }
.chat__summary dd { font-weight: 500; overflow-wrap: anywhere; }

/* Enlaces de acción (WhatsApp, teléfono, mapa) */
.chat__links { display: grid; gap: 8px; margin-top: 12px; }
.chat__link {
  display: block;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent-dark);
  font-size: 0.88rem;
  text-align: center;
  transition: background 0.2s ease, color 0.2s ease;
}
.chat__link:hover { background: var(--tint); }
.chat__link--primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.chat__link--primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }

/* Respuestas rápidas */
.chat__options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 6px;
  animation: chat-in 0.3s ease both;
}
.chat__chip {
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-dark);
  font: 400 0.86rem var(--sans);
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.chat__chip:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }

/* Indicador de escritura */
.chat__typing .chat__bubble { display: inline-flex; gap: 5px; padding: 14px 16px; }
.chat__typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  animation: chat-dot 1.1s infinite ease-in-out;
}
.chat__typing i:nth-child(2) { animation-delay: 0.15s; }
.chat__typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Campo de texto */
.chat__form {
  display: flex;
  gap: 8px;
  padding: 12px 14px 6px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.chat__input {
  flex: 1;
  min-width: 0;
  /* 16px como mínimo para que el iPhone no haga zoom al escribir */
  font: 300 1rem var(--sans);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.chat__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 137, 94, 0.22);
}
.chat__send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  transition: background 0.2s ease;
}
.chat__send:hover { background: var(--accent-dark); }
.chat__legal {
  padding: 4px 16px 12px;
  background: var(--surface);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}
.chat__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .chat,
  .chat__msg,
  .chat__options { transition: none; animation: none; }
  .chat__log { scroll-behavior: auto; }
  .chat__typing i { animation: none; opacity: 0.7; }
  .chat-launcher,
  .chat-launcher::before { animation: none; }
}

/* Móvil: botón redondo en la misma fila que el botón fijo de reserva y chat a pantalla completa */
@media (max-width: 560px) {
  /* En móvil solo el monograma redondo, sin texto, a la altura de la barra de reserva (56px) */
  .chat-launcher {
    right: 16px;
    bottom: 14px;
    padding: 5px;
    transition: transform 0.35s ease, opacity 0.3s ease, box-shadow 0.3s ease;
  }
  .chat-launcher__text { display: none; }
  .chat-launcher__avatar { width: 46px; height: 46px; }
  .chat-launcher__m { font-size: 1.45rem; }
  .chat-open .chat-launcher { display: none; }

  .chat {
    inset: 0;
    width: auto;
    height: 100%;
    border: none;
    border-radius: 0;
    transform: translateY(24px);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
  }
  .chat__head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .chat__bubble { max-width: 90%; }
  html.chat-open,
  html.chat-open body { overflow: hidden; }
}
