/* ============================================================
   ASISTENTE VIRTUAL SAN MARCOS — widget de chat
   Usa las variables de marca definidas en styles.css (:root).
   ============================================================ */

.smchat {
  --smchat-top: clamp(5.8rem, 7vw, 6.8rem);
  position: fixed;
  top: var(--smchat-top);
  left: clamp(1rem, 2vw, 1.6rem);
  z-index: 190;
  font-family: var(--sans);
}

/* --- lanzador --- */
.smchat__launcher {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(245, 240, 220, 0.32);
  background: linear-gradient(135deg, rgba(15, 31, 24, 0.96), rgba(56, 69, 29, 0.96));
  color: var(--paper);
  cursor: pointer;
  box-shadow: 0 1.2rem 3rem rgba(0, 0, 0, 0.28);
  transition: transform 0.3s var(--ease-out), border-color 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
}
.smchat__launcher::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -0.42rem;
  border: 1px solid rgba(207, 197, 153, 0.62);
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
  animation: smchat-launcher-pulse 7s ease-out 2s infinite;
}
.smchat__launcher:hover {
  transform: translateY(-4px);
  border-color: rgba(207, 197, 153, 0.6);
  box-shadow: 0 1.6rem 3.6rem rgba(0, 0, 0, 0.34);
}
.smchat__launcher:focus-visible {
  outline: 3px solid var(--copper-soft);
  outline-offset: 4px;
}
.smchat__launcher:hover::after,
.smchat__launcher:hover svg,
.smchat__launcher.is-attended::after,
.smchat__launcher.is-attended svg,
.smchat__launcher:focus::after,
.smchat__launcher:focus svg,
.smchat__launcher:focus-visible::after,
.smchat__launcher:focus-visible svg {
  animation-play-state: paused;
}
.smchat__launcher svg {
  width: 1.65rem;
  height: 1.65rem;
  flex: none;
  color: var(--sage);
  transform-origin: 50% 78%;
  animation: smchat-launcher-greeting 7s ease-in-out 2s infinite;
}
@keyframes smchat-launcher-greeting {
  0%, 3%, 9%, 15%, 21%, 100% { transform: rotate(0deg) scale(1); }
  6%, 18% { transform: rotate(-10deg) scale(1.06); }
  12% { transform: rotate(10deg) scale(1.06); }
}
@keyframes smchat-launcher-pulse {
  0% { opacity: 0; transform: scale(0.82); }
  5% { opacity: 0.72; }
  22% { opacity: 0; transform: scale(1.28); }
  23%, 100% { opacity: 0; transform: scale(1.28); }
}
.smchat__launcher-copy {
  display: none;
  flex-direction: column;
  gap: 0.1rem;
  text-align: left;
}
.smchat__launcher-copy span {
  font-family: var(--sans-exp);
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.62;
}
.smchat__launcher-copy strong {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1;
}
.smchat.is-open .smchat__launcher { display: none; animation: none; }
.smchat.is-open .smchat__launcher::after,
.smchat.is-open .smchat__launcher svg { animation: none; }

/* --- panel --- */
.smchat__panel {
  position: fixed;
  top: var(--smchat-top);
  left: clamp(1rem, 2vw, 1.6rem);
  width: min(380px, calc(100vw - 2rem));
  height: min(600px, calc(100dvh - var(--smchat-top) - 1rem));
  display: flex;
  flex-direction: column;
  border-radius: 1.1rem;
  overflow: hidden;
  border: 1px solid var(--line-ink);
  background: var(--paper);
  box-shadow: 0 2rem 4.5rem rgba(15, 31, 24, 0.35);
  animation: smchat-in 0.35s var(--ease-out);
}
.smchat__panel[hidden] { display: none; }
@keyframes smchat-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .smchat__panel { animation: none; }
  .smchat__launcher,
  .smchat__launcher::after,
  .smchat__launcher svg,
  .smchat__typing span { animation: none !important; }
}

/* --- cabecera --- */
.smchat__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: linear-gradient(135deg, var(--ink), var(--ink-soft));
  color: var(--paper);
  flex: none;
}
.smchat__brand-mark {
  width: 2.1rem;
  height: 2.1rem;
  object-fit: contain;
}
.smchat__head-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 0.12rem;
}
.smchat__head-copy strong {
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1;
}
.smchat__head-copy span {
  font-family: var(--sans-exp);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.6;
}
.smchat__head-copy span::before {
  content: "";
  display: inline-block;
  width: 0.42rem;
  height: 0.42rem;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: var(--leaf);
  vertical-align: 1px;
}
.smchat__mascot {
  position: relative;
  align-self: stretch;
  width: 4.4rem;
  min-height: 3.15rem;
  flex: none;
  margin-block: -0.9rem;
  overflow: hidden;
  pointer-events: none;
}
.smchat__mascot img {
  position: absolute;
  left: 50%;
  bottom: -1.55rem;
  width: 7.25rem;
  max-width: none;
  height: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 0.35rem 0.35rem rgba(0, 0, 0, 0.28));
}
.smchat__reset,
.smchat__close {
  width: 2rem;
  height: 2rem;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: rgba(245, 240, 220, 0.12);
  color: var(--paper);
  line-height: 1;
  cursor: pointer;
  transition: background 0.25s var(--ease-out);
}
.smchat__reset {
  margin-left: auto;
  font-size: 1.05rem;
}
.smchat__close { font-size: 1.25rem; }
.smchat__reset:hover,
.smchat__close:hover { background: rgba(245, 240, 220, 0.24); }
.smchat__reset:focus-visible,
.smchat__close:focus-visible {
  outline: 2px solid var(--copper-soft);
  outline-offset: 2px;
}
.smchat__reset:disabled { cursor: wait; opacity: 0.45; }

/* --- cuerpo --- */
.smchat__body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scrollbar-width: thin;
  background:
    radial-gradient(circle at 85% 8%, rgba(99, 141, 69, 0.07), transparent 42%),
    var(--paper);
}
.smchat__msg {
  max-width: 86%;
  padding: 0.65rem 0.85rem;
  border-radius: 0.85rem;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--ink);
  overflow-wrap: break-word;
}
.smchat__msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line-ink);
  border-bottom-left-radius: 0.25rem;
}
.smchat__msg--user {
  align-self: flex-end;
  background: var(--moss);
  color: var(--paper);
  border-bottom-right-radius: 0.25rem;
}

/* resumen del lead */
.smchat__summary {
  list-style: none;
  margin: 0.6rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.smchat__summary li {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  border-bottom: 1px dashed var(--line-ink);
  padding-bottom: 0.3rem;
}
.smchat__summary li span {
  font-family: var(--sans-exp);
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--copper);
  min-width: 4.2rem;
}

/* tarjetas de acción (brochure / WhatsApp) */
.smchat__card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.6rem;
  padding: 0.7rem 0.9rem;
  border-radius: 0.7rem;
  border: 1px solid var(--line-ink);
  background: var(--paper-deep);
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.25s var(--ease-out), border-color 0.25s var(--ease-out);
}
.smchat__card:hover { transform: translateY(-2px); border-color: var(--copper); }
.smchat__card strong { font-family: var(--serif); font-weight: 500; font-size: 0.95rem; }
.smchat__card span { font-size: 0.72rem; opacity: 0.7; }
.smchat__card--wa {
  background: linear-gradient(135deg, var(--ink), var(--ink-soft));
  color: var(--paper);
  border-color: rgba(245, 240, 220, 0.25);
}
.smchat__card--wa:hover { border-color: var(--copper-soft); }
.smchat__card--wa strong::before { content: "🟢 "; font-size: 0.75em; }

/* opciones rápidas: separadas del historial cronológico */
.smchat__actions {
  max-height: 8.5rem;
  overflow-y: auto;
  padding: 0.6rem 0.8rem;
  border-top: 1px solid var(--line-ink);
  background: var(--paper-deep);
  scrollbar-width: thin;
  flex: none;
}
.smchat__actions:empty { display: none; }
.smchat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.smchat__chips button {
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--moss);
  background: transparent;
  color: var(--moss);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out);
}
.smchat__chips button:hover {
  background: var(--moss);
  color: var(--paper);
}

/* indicador escribiendo */
.smchat__typing {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  min-height: 1.6rem;
}
.smchat__typing span {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--sage);
  animation: smchat-dot 1.1s infinite;
}
.smchat__typing span:nth-child(2) { animation-delay: 0.18s; }
.smchat__typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes smchat-dot {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* --- entrada --- */
.smchat__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  border-top: 1px solid var(--line-ink);
  background: #fff;
  flex: none;
}
.smchat__form input {
  flex: 1;
  border: 1px solid var(--line-ink);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font-family: var(--sans);
  font-size: 0.86rem;
  color: var(--ink);
  background: var(--paper);
  outline: none;
  transition: border-color 0.2s var(--ease-out);
}
.smchat__form input:focus { border-color: var(--leaf); }
.smchat__form input:disabled { cursor: wait; opacity: 0.65; }
.smchat__form button {
  width: 2.6rem;
  height: 2.6rem;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--moss);
  color: var(--paper);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}
.smchat__form button:hover { background: var(--leaf); transform: translateY(-2px); }
.smchat__form button svg { width: 1.15rem; height: 1.15rem; }

.smchat__note {
  margin: 0;
  padding: 0.45rem 1rem 0.6rem;
  background: #fff;
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  color: rgba(15, 31, 24, 0.55);
  text-align: center;
  flex: none;
}

/* --- móvil: panel a pantalla completa --- */
@media (max-width: 560px) {
  .smchat {
    --smchat-top: 5.4rem;
    top: var(--smchat-top);
    left: 1rem;
  }
  .smchat__panel {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }
  .smchat.is-open ~ .floating-whatsapp,
  body:has(.smchat.is-open) .floating-whatsapp { display: none; }
}

/* --- chips dentro del flujo de conversación (2026-07-23) ---
   Antes vivían en .smchat__actions (bloque fijo entre historial y campo de
   texto) y tapaban el input, sobre todo en móvil. Ahora scrollean con el chat. */
.smchat__body .smchat__chips {
  margin: 0.15rem 0 0.35rem;
  flex: none;
}
