/* ════════════════════════════════════════════════
   WIDGET "Hablá con el agente" — llamada web con el agente de voz.
   Autocontenido: usa los tokens de styles.css si existen y trae
   valores de respaldo para poder pegarlo en otra página MGZ.
   ════════════════════════════════════════════════ */

.ag-launcher {
  --ag-cherry: var(--cherry, #b61742);
  --ag-vino: var(--vino-tinta, #2b1a20);
  --ag-papel: var(--papel, #fafaf9);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px 10px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--ag-vino);
  color: var(--blanco-calido, #fdfbf7);
  font-family: var(--font, "Geist", system-ui, sans-serif);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(43, 26, 32, 0.12), 0 10px 28px rgba(43, 26, 32, 0.22);
  transform: translateY(0);
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.3s ease;
  animation: ag-enter 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) 0.8s both;
}

.ag-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(43, 26, 32, 0.14), 0 16px 36px rgba(43, 26, 32, 0.26);
}

.ag-launcher:focus-visible {
  outline: 2px solid var(--naranja, #f89645);
  outline-offset: 3px;
}

.ag-launcher[hidden] {
  display: none;
}

/* Orbe del botón: punto cherry con ondas que salen */
.ag-launcher .ag-orb {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ag-cherry);
  flex-shrink: 0;
}

.ag-launcher .ag-orb::before,
.ag-launcher .ag-orb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--ag-cherry);
  animation: ag-ring 2.4s ease-out infinite;
}

.ag-launcher .ag-orb::after {
  animation-delay: 1.2s;
}

/* Barras de voz dentro del orbe */
.ag-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 16px;
}

.ag-bars i {
  display: block;
  width: 3px;
  height: 100%;
  border-radius: 2px;
  background: currentColor;
  transform-origin: center;
  animation: ag-bar 1.1s ease-in-out infinite;
}

.ag-bars i:nth-child(2) { animation-delay: 0.15s; }
.ag-bars i:nth-child(3) { animation-delay: 0.3s; }
.ag-bars i:nth-child(4) { animation-delay: 0.45s; }

.ag-launcher .ag-label {
  display: grid;
  line-height: 1.15;
  text-align: left;
}

.ag-launcher .ag-label small {
  font-family: var(--font-mono, "Roboto Mono", monospace);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arena, #b7a79b);
}

/* ── Panel ── */
.ag-panel {
  --ag-cherry: var(--cherry, #b61742);
  --ag-vino: var(--vino-tinta, #2b1a20);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 61;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 18px;
  background: var(--ag-vino);
  color: var(--blanco-calido, #fdfbf7);
  font-family: var(--font, "Geist", system-ui, sans-serif);
  box-shadow: 0 4px 10px rgba(43, 26, 32, 0.18), 0 24px 60px rgba(43, 26, 32, 0.32);
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ag-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.ag-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 0;
  font-family: var(--font-mono, "Roboto Mono", monospace);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arena, #b7a79b);
}

.ag-head .ag-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ag-head .ag-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--arena, #b7a79b);
}

.ag-panel[data-state="live"] .ag-head .ag-status::before {
  background: var(--naranja, #f89645);
  animation: ag-blink 1.2s ease-in-out infinite;
}

.ag-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(253, 251, 247, 0.08);
  color: inherit;
  cursor: pointer;
}

.ag-close:hover {
  background: rgba(253, 251, 247, 0.16);
}

.ag-close svg {
  width: 16px;
  height: 16px;
}

.ag-body {
  padding: 18px 22px 22px;
  display: grid;
  gap: 16px;
}

/* Orbe grande: late solo, y crece cuando habla el agente */
.ag-stage {
  position: relative;
  display: grid;
  place-items: center;
  height: 150px;
}

.ag-big {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d4325d 0%, var(--ag-cherry) 55%, #8f1234 100%);
  display: grid;
  place-items: center;
  color: var(--blanco-calido, #fdfbf7);
  transform: scale(var(--ag-level, 1));
  transition: transform 0.12s ease-out;
  animation: ag-breathe 3.2s ease-in-out infinite;
}

.ag-big .ag-bars {
  height: 26px;
  gap: 4px;
}

.ag-big .ag-bars i {
  width: 4px;
  animation-play-state: paused;
  transform: scaleY(0.35);
}

.ag-panel[data-speaking="agent"] .ag-big .ag-bars i,
.ag-panel[data-state="connecting"] .ag-big .ag-bars i {
  animation-play-state: running;
}

.ag-stage .ag-wave {
  position: absolute;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 1.5px solid rgba(248, 150, 69, 0.55);
  opacity: 0;
}

.ag-panel[data-speaking="agent"] .ag-stage .ag-wave {
  animation: ag-ring-big 1.8s ease-out infinite;
}

.ag-panel[data-speaking="agent"] .ag-stage .ag-wave:nth-child(2) {
  animation-delay: 0.6s;
}

.ag-panel[data-speaking="agent"] .ag-stage .ag-wave:nth-child(3) {
  animation-delay: 1.2s;
}

.ag-title {
  margin: 0;
  font-family: var(--font-title, "Oswald", sans-serif);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
}

.ag-title em {
  font-style: normal;
  color: var(--naranja, #f89645);
}

.ag-text {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: rgba(253, 251, 247, 0.8);
  text-align: center;
}

.ag-timer {
  font-family: var(--font-mono, "Roboto Mono", monospace);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--arena, #b7a79b);
}

.ag-transcript {
  display: grid;
  gap: 8px;
  max-height: 150px;
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  background: rgba(253, 251, 247, 0.06);
  font-size: 13.5px;
  line-height: 1.45;
}

.ag-transcript:empty {
  display: none;
}

.ag-transcript p {
  margin: 0;
}

.ag-transcript b {
  font-family: var(--font-mono, "Roboto Mono", monospace);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--naranja, #f89645);
  margin-right: 6px;
}

.ag-transcript p.user b {
  color: var(--arena, #b7a79b);
}

.ag-actions {
  display: grid;
  gap: 10px;
}

.ag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.ag-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.ag-btn:active {
  transform: scale(0.98);
}

.ag-btn--primary {
  background: var(--ag-cherry);
  color: var(--blanco-calido, #fdfbf7);
}

.ag-btn--primary:hover {
  background: var(--cherry-hover, #9a1338);
}

.ag-btn--hang {
  background: var(--blanco-calido, #fdfbf7);
  color: var(--ag-vino);
}

.ag-btn--ghost {
  background: rgba(253, 251, 247, 0.08);
  color: var(--blanco-calido, #fdfbf7);
}

.ag-btn--ghost:hover {
  background: rgba(253, 251, 247, 0.16);
}

.ag-btn--wa {
  background: var(--whatsapp, #25d366);
  color: #0b2b17;
}

.ag-fine {
  margin: 0;
  font-family: var(--font-mono, "Roboto Mono", monospace);
  font-size: 10.5px;
  line-height: 1.6;
  letter-spacing: 0.04em;
  color: var(--arena, #b7a79b);
  text-align: center;
}

/* Botones de la página que abren el widget */
[data-agente] .ag-bars {
  height: 14px;
}

@keyframes ag-enter {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

@keyframes ag-ring {
  0%   { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.9); opacity: 0; }
}

@keyframes ag-ring-big {
  0%   { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

@keyframes ag-bar {
  0%, 100% { transform: scaleY(0.35); }
  50%      { transform: scaleY(1); }
}

@keyframes ag-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(182, 23, 66, 0.45); }
  50%      { box-shadow: 0 0 0 14px rgba(182, 23, 66, 0); }
}

@keyframes ag-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

@media (max-width: 540px) {
  .ag-launcher {
    right: 12px;
    bottom: 12px;
    padding-right: 16px;
    font-size: 14px;
  }

  .ag-panel {
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
  }
}

/* Pantallas muy angostas: el botón queda en orbe + texto corto, siempre dentro */
@media (max-width: 380px) {
  .ag-launcher {
    max-width: calc(100vw - 24px);
    gap: 10px;
  }
  .ag-launcher .ag-label small {
    display: none;
  }
}
