/* ==========================================================================
   GRUPO LAVEY — asistente comercial con IA.
   Usa los tokens de styles.css. Todo va bajo el prefijo .lav-ag para no
   interferir con ningún estilo del sitio.
   ========================================================================== */

.lav-ag {
  --ag-w: 400px;
  --ag-h: 620px;
  --ag-edge: 20px;
  --ag-launcher: 60px;
  --ag-panel-bg: rgba(7, 11, 22, 0.97);
  position: fixed;
  right: var(--ag-edge);
  bottom: var(--ag-edge);
  z-index: 130;
  font-family: var(--f-sans, system-ui, sans-serif);
  font-size: 15px;
  line-height: 1.55;
}

/* ---------- 1. Botón flotante ---------- */

.lav-ag-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--ag-launcher);
  height: var(--ag-launcher);
  padding: 0;
  border: 1px solid var(--line-2, rgba(160, 180, 220, 0.2));
  border-radius: 50%;
  background: linear-gradient(150deg, rgba(44, 245, 160, 0.16), rgba(61, 123, 255, 0.2)), rgba(8, 12, 24, 0.94);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px -18px rgba(0, 0, 0, 0.9), 0 0 42px -14px rgba(57, 208, 255, 0.55);
  color: var(--ink, #eef2fa);
  cursor: pointer;
  transition: transform 0.4s var(--ease-out, ease), border-color 0.3s, box-shadow 0.3s;
}
.lav-ag-launcher:hover {
  transform: translateY(-3px);
  border-color: rgba(57, 208, 255, 0.5);
  box-shadow: 0 24px 56px -18px rgba(0, 0, 0, 0.95), 0 0 56px -12px rgba(57, 208, 255, 0.7);
}
.lav-ag-launcher svg { width: 26px; height: 26px; }
.lav-ag-launcher .lav-ag-ic-close { display: none; }

/* Anillo de latido, discreto y solo mientras el chat está cerrado */
.lav-ag-launcher::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid rgba(57, 208, 255, 0.5);
  opacity: 0;
  animation: lav-ag-ping 3.6s var(--ease-out, ease) infinite;
}
@keyframes lav-ag-ping {
  0%   { transform: scale(1);    opacity: 0.6; }
  60%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

.lav-ag.is-open .lav-ag-launcher::after { animation: none; }
.lav-ag.is-open .lav-ag-ic-chat { display: none; }
.lav-ag.is-open .lav-ag-ic-close { display: block; }

/* El botón de WhatsApp del sitio sube para dejar sitio al asistente */
body.lav-ag-on .wa-float { bottom: calc(var(--ag-edge, 20px) + 60px + 14px); }
body.lav-ag-on.lav-ag-consent .lav-ag { bottom: 120px; }

/* ---------- 2. Panel ---------- */

.lav-ag-panel {
  position: absolute;
  right: 0;
  bottom: calc(var(--ag-launcher) + 16px);
  display: flex;
  flex-direction: column;
  width: var(--ag-w);
  height: min(var(--ag-h), calc(100vh - 140px));
  overflow: hidden;
  border: 1px solid var(--line-2, rgba(160, 180, 220, 0.2));
  border-radius: 22px;
  background: var(--ag-panel-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 40px 100px -24px rgba(0, 0, 0, 0.92), 0 0 90px -40px rgba(61, 123, 255, 0.5);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.28s var(--ease, ease), transform 0.38s var(--ease-out, ease), visibility 0.38s;
}
.lav-ag.is-open .lav-ag-panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  visibility: visible;
}

/* ---------- 3. Cabecera ---------- */

.lav-ag-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 16px 18px;
  border-bottom: 1px solid var(--line, rgba(160, 180, 220, 0.11));
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.012));
}
.lav-ag-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 13px;
  background: linear-gradient(140deg, rgba(44, 245, 160, 0.2), rgba(61, 123, 255, 0.24));
  border: 1px solid var(--line-2, rgba(160, 180, 220, 0.2));
}
.lav-ag-avatar img { width: 24px; height: auto; }
.lav-ag-id { min-width: 0; flex: 1; }
.lav-ag-id b {
  display: block;
  color: var(--ink, #eef2fa);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.lav-ag-state {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted, #8a94a9);
  font-size: 12px;
}
.lav-ag-state i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green, #2cf5a0);
  box-shadow: 0 0 8px rgba(44, 245, 160, 0.9);
}
.lav-ag-x {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--muted, #8a94a9);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.lav-ag-x:hover {
  color: var(--ink, #eef2fa);
  border-color: var(--line-2, rgba(160, 180, 220, 0.2));
  background: rgba(255, 255, 255, 0.04);
}
.lav-ag-x svg { width: 17px; height: 17px; }

/* ---------- 4. Conversación ---------- */

.lav-ag-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(160, 180, 220, 0.28) transparent;
}
.lav-ag-log::-webkit-scrollbar { width: 8px; }
.lav-ag-log::-webkit-scrollbar-thumb {
  background: rgba(160, 180, 220, 0.24);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.lav-ag-msg {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: lav-ag-in 0.36s var(--ease-out, ease) both;
}
@keyframes lav-ag-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.lav-ag-msg--bot {
  align-self: flex-start;
  border: 1px solid var(--line, rgba(160, 180, 220, 0.11));
  border-bottom-left-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink-2, #c2cadb);
}
.lav-ag-msg--me {
  align-self: flex-end;
  border: 1px solid rgba(61, 123, 255, 0.34);
  border-bottom-right-radius: 6px;
  background: linear-gradient(140deg, rgba(61, 123, 255, 0.24), rgba(57, 208, 255, 0.16));
  color: var(--ink, #eef2fa);
}
.lav-ag-msg b { color: var(--ink, #eef2fa); font-weight: 600; }
.lav-ag-msg a { color: var(--blue-ink, #9fb9ff); text-decoration: underline; text-underline-offset: 3px; }

.lav-ag-msg--nota {
  align-self: stretch;
  max-width: 100%;
  border: 1px dashed rgba(255, 207, 107, 0.36);
  background: rgba(255, 207, 107, 0.07);
  color: var(--amber, #ffcf6b);
  font-size: 13.5px;
  border-radius: 14px;
}

/* Indicador de escritura */
.lav-ag-typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 15px;
  border: 1px solid var(--line, rgba(160, 180, 220, 0.11));
  border-radius: 16px 16px 16px 6px;
  background: rgba(255, 255, 255, 0.045);
}
.lav-ag-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted, #8a94a9);
  animation: lav-ag-dot 1.3s ease-in-out infinite;
}
.lav-ag-typing i:nth-child(2) { animation-delay: 0.18s; }
.lav-ag-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes lav-ag-dot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

/* ---------- 5. Botones de acción ---------- */

.lav-ag-acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  max-width: 100%;
  animation: lav-ag-in 0.4s var(--ease-out, ease) both;
}
.lav-ag-chip {
  padding: 8px 14px;
  border: 1px solid var(--line-2, rgba(160, 180, 220, 0.2));
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-2, #c2cadb);
  font-size: 13.5px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.24s, color 0.24s, background 0.24s, transform 0.24s;
}
.lav-ag-chip:hover {
  border-color: rgba(57, 208, 255, 0.55);
  background: rgba(57, 208, 255, 0.09);
  color: var(--ink, #eef2fa);
  transform: translateY(-1px);
}
.lav-ag-chip--wa {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-color: rgba(44, 245, 160, 0.45);
  background: rgba(44, 245, 160, 0.12);
  color: #d6ffef;
  font-weight: 500;
}
.lav-ag-chip--wa:hover { background: rgba(44, 245, 160, 0.2); border-color: rgba(44, 245, 160, 0.7); }
.lav-ag-chip--wa svg { width: 16px; height: 16px; flex: none; }
.lav-ag-chip--link { border-style: dashed; }

/* ---------- 6. Formulario de contacto ---------- */

.lav-ag-form {
  align-self: stretch;
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line-2, rgba(160, 180, 220, 0.2));
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  animation: lav-ag-in 0.4s var(--ease-out, ease) both;
}
.lav-ag-form h4 {
  margin: 0;
  color: var(--ink, #eef2fa);
  font-size: 14.5px;
  font-weight: 600;
}
.lav-ag-form p.lav-ag-hint {
  margin: 0;
  color: var(--muted, #8a94a9);
  font-size: 12.5px;
  line-height: 1.5;
}
.lav-ag-form input,
.lav-ag-form select {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--line-2, rgba(160, 180, 220, 0.2));
  border-radius: 11px;
  background: rgba(4, 6, 12, 0.6);
  color: var(--ink, #eef2fa);
  font-size: 14px;
}
.lav-ag-form input::placeholder { color: var(--dim, #5d6680); }
.lav-ag-form input:focus,
.lav-ag-form select:focus {
  outline: none;
  border-color: rgba(57, 208, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(57, 208, 255, 0.12);
}
.lav-ag-form .lav-ag-check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  color: var(--muted, #8a94a9);
  font-size: 12.5px;
  line-height: 1.5;
  cursor: pointer;
}
.lav-ag-form .lav-ag-check input {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 2px;
  accent-color: var(--green, #2cf5a0);
}
.lav-ag-form .lav-ag-check a { color: var(--blue-ink, #9fb9ff); text-decoration: underline; }
.lav-ag-send {
  padding: 11px 16px;
  border: 0;
  border-radius: 11px;
  background: var(--grad, linear-gradient(100deg, #2cf5a0, #39d0ff 48%, #6f95ff));
  color: #03150d;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.24s, transform 0.24s;
}
.lav-ag-send:hover { filter: brightness(1.08); transform: translateY(-1px); }
.lav-ag-send[disabled] { opacity: 0.55; cursor: progress; transform: none; }
.lav-ag-err { margin: 0; color: var(--error, #ff9aa6); font-size: 12.5px; }
.lav-ag-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- 7. Barra de escritura ---------- */

.lav-ag-foot {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line, rgba(160, 180, 220, 0.11));
  background: rgba(4, 6, 12, 0.45);
}
.lav-ag-bar {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 7px 7px 7px 15px;
  border: 1px solid var(--line-2, rgba(160, 180, 220, 0.2));
  border-radius: 18px;
  background: rgba(4, 6, 12, 0.7);
  transition: border-color 0.24s, box-shadow 0.24s;
}
.lav-ag-bar:focus-within {
  border-color: rgba(57, 208, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(57, 208, 255, 0.1);
}
.lav-ag-bar textarea {
  flex: 1;
  min-height: 24px;
  max-height: 120px;
  padding: 7px 0;
  border: 0;
  background: none;
  color: var(--ink, #eef2fa);
  font-size: 14.5px;
  line-height: 1.5;
  resize: none;
  outline: none;
}
.lav-ag-bar textarea::placeholder { color: var(--dim, #5d6680); }
.lav-ag-go {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: var(--grad, linear-gradient(100deg, #2cf5a0, #39d0ff 48%, #6f95ff));
  color: #03150d;
  cursor: pointer;
  transition: filter 0.24s, opacity 0.24s;
}
.lav-ag-go svg { width: 18px; height: 18px; }
.lav-ag-go:hover { filter: brightness(1.1); }
.lav-ag-go[disabled] { opacity: 0.4; cursor: not-allowed; }
.lav-ag-legal {
  margin: 9px 2px 0;
  color: var(--dim, #5d6680);
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
}
.lav-ag-legal a { color: var(--muted, #8a94a9); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- 8. Móvil ---------- */

@media (max-width: 640px) {
  .lav-ag { --ag-edge: 14px; --ag-launcher: 54px; }
  .lav-ag-launcher svg { width: 23px; height: 23px; }
  .lav-ag-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    transform-origin: bottom center;
  }
  .lav-ag-head { padding-top: max(16px, env(safe-area-inset-top)); }
  .lav-ag-foot { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .lav-ag-msg { max-width: 92%; }
  /* Con el panel abierto se ocultan los flotantes para no tapar el chat */
  .lav-ag.is-open .lav-ag-launcher { display: none; }
  body.lav-ag-abierto .wa-float { display: none; }
  body.lav-ag-abierto { overflow: hidden; }
}

/* ---------- 9. Accesibilidad ---------- */

.lav-ag :focus-visible {
  outline: 2px solid var(--green, #2cf5a0);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .lav-ag *,
  .lav-ag *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
