/* ==========================================================================
   Saaving Digital — Agente de clientes (burbuja de chat)
   Componente independiente: todas las clases empiezan por .ag-
   ========================================================================== */
.ag-launcher, .ag-panel { --ag-y: #FFCC00; --ag-y2: #FFB800; --ag-ink: #1B1C1F; --ag-muted: #5C606A; --ag-bg: #FFFDF7; --ag-cream: #FFF6DA; --ag-line: rgba(27, 28, 31, .1); font-family: "Inter", system-ui, sans-serif; }

/* ---------- Botón flotante ---------- */
.ag-launcher { position: fixed; right: 20px; bottom: 20px; z-index: 70; display: inline-flex; align-items: center; gap: .6rem; min-height: 56px; padding: .45rem 1.1rem .45rem .45rem; border: 0; border-radius: 999px; cursor: pointer; background: var(--ag-ink); color: #fff; font: 600 .95rem "Sora", system-ui, sans-serif; box-shadow: 0 16px 36px -14px rgba(27, 28, 31, .6); transition: transform .25s, opacity .25s, top .3s, bottom .3s; }
.ag-launcher:hover { transform: translateY(-2px); }
.ag-launcher:focus-visible { outline: 3px solid var(--ag-y); outline-offset: 3px; }
.ag-launcher img { width: 44px; height: 44px; border-radius: 50%; }
.ag-launcher__dot { position: absolute; top: 6px; left: 38px; width: 11px; height: 11px; border-radius: 50%; background: #2BD576; box-shadow: 0 0 0 2px var(--ag-ink); }
.ag-launcher[aria-expanded="true"] { opacity: 0; pointer-events: none; transform: scale(.9); }
/* Durante la historia las tarjetas de cada escena ocupan la parte de abajo: el botón sube bajo la cabecera */
.ag-launcher.ag-arriba { bottom: auto; top: calc(var(--header-h, 68px) + 30px); }

/* ---------- Panel ---------- */
.ag-panel { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; width: min(390px, calc(100vw - 24px)); height: min(640px, calc(100vh - 40px)); height: min(640px, calc(100dvh - 40px)); overflow: hidden; background: var(--ag-bg); color: var(--ag-ink); border: 1px solid var(--ag-line); border-radius: 24px; box-shadow: 0 30px 80px -24px rgba(27, 28, 31, .45); opacity: 0; transform: translateY(16px) scale(.98); transform-origin: bottom right; pointer-events: none; visibility: hidden; transition: opacity .25s, transform .25s, visibility .25s; }
.ag-panel.is-open { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }

.ag-head { display: flex; align-items: center; gap: .7rem; padding: .85rem .9rem .85rem 1rem; background: var(--ag-ink); color: #fff; }
.ag-head img { width: 38px; height: 38px; border-radius: 50%; }
.ag-head__txt { flex: 1; min-width: 0; line-height: 1.25; }
.ag-head__txt b { display: block; font: 700 .98rem "Sora", system-ui, sans-serif; }
.ag-head__txt small { color: #C9CCD3; font-size: .78rem; }
.ag-head__txt small::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: .35rem; border-radius: 50%; background: #2BD576; vertical-align: 1px; }
.ag-sim { margin-left: .4rem; padding: .05rem .45rem; border-radius: 999px; background: var(--ag-y); color: var(--ag-ink); font: 700 .66rem "Sora", system-ui, sans-serif; letter-spacing: .04em; vertical-align: 2px; }
.ag-close { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .1); color: #fff; font-size: 1.3rem; cursor: pointer; }
.ag-close:hover { background: rgba(255, 255, 255, .2); }
.ag-close:focus-visible { outline: 3px solid var(--ag-y); outline-offset: 2px; }

/* ---------- Mensajes ---------- */
.ag-log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; scroll-behavior: smooth; overscroll-behavior: contain; }
.ag-msg { max-width: 86%; padding: .65rem .85rem; border-radius: 18px; font-size: .95rem; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; animation: ag-in .25s ease-out; }
.ag-msg--bot { align-self: flex-start; background: #fff; border: 1px solid var(--ag-line); border-bottom-left-radius: 6px; }
.ag-msg--yo { align-self: flex-end; background: var(--ag-y); border-bottom-right-radius: 6px; }
.ag-msg--error { align-self: flex-start; background: #FFF0F0; border: 1px solid #F3C7C7; }
.ag-msg--error a { color: inherit; font-weight: 600; }
@keyframes ag-in { from { opacity: 0; transform: translateY(6px); } }

.ag-typing { align-self: flex-start; display: flex; gap: 4px; padding: .8rem .9rem; background: #fff; border: 1px solid var(--ag-line); border-radius: 18px; border-bottom-left-radius: 6px; }
.ag-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ag-muted); animation: ag-blink 1.1s infinite; }
.ag-typing i:nth-child(2) { animation-delay: .15s; } .ag-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ag-blink { 50% { opacity: .25; } }

/* Respuestas rápidas y horarios */
.ag-chips { display: flex; flex-wrap: wrap; gap: .4rem; align-self: stretch; }
.ag-chip { min-height: 40px; padding: .45rem .85rem; border: 1.5px solid var(--ag-ink); border-radius: 999px; background: transparent; color: var(--ag-ink); font: 600 .85rem "Inter", system-ui, sans-serif; cursor: pointer; transition: background .2s; }
.ag-chip:hover { background: var(--ag-cream); }
.ag-chip:focus-visible { outline: 3px solid var(--ag-y2); outline-offset: 2px; }
.ag-slots { display: grid; gap: .4rem; align-self: stretch; }
.ag-slot { display: flex; align-items: center; gap: .6rem; min-height: 46px; padding: .55rem .85rem; border: 1.5px solid var(--ag-line); border-radius: 14px; background: #fff; color: var(--ag-ink); font: 600 .9rem "Inter", system-ui, sans-serif; text-align: left; cursor: pointer; transition: border-color .2s, background .2s; }
.ag-slot::before { content: "📅"; }
.ag-slot:hover { border-color: var(--ag-y2); background: var(--ag-cream); }
.ag-slot:focus-visible { outline: 3px solid var(--ag-y2); outline-offset: 2px; }
.ag-slots[aria-disabled="true"] .ag-slot, .ag-chips[aria-disabled="true"] .ag-chip { opacity: .45; pointer-events: none; }

/* Confirmación de la reunión */
.ag-cita { align-self: stretch; padding: 1rem; border-radius: 18px; background: var(--ag-cream); border: 1.5px solid var(--ag-y); }
.ag-cita b { display: block; margin-bottom: .2rem; font: 700 1rem "Sora", system-ui, sans-serif; }
.ag-cita p { margin: 0 0 .7rem; color: var(--ag-muted); font-size: .88rem; }
.ag-cita a { display: inline-flex; align-items: center; min-height: 42px; padding: .5rem 1rem; border-radius: 999px; background: var(--ag-ink); color: #fff; font: 600 .88rem "Sora", system-ui, sans-serif; text-decoration: none; }

/* Consentimiento de datos */
.ag-consent { align-self: stretch; padding: .9rem 1rem; border-radius: 16px; background: #fff; border: 1px dashed var(--ag-line); color: var(--ag-muted); font-size: .82rem; line-height: 1.5; }
.ag-consent button { display: block; margin-top: .7rem; min-height: 44px; padding: .5rem 1.2rem; border: 0; border-radius: 999px; background: linear-gradient(135deg, #FFDD33, var(--ag-y) 55%, var(--ag-y2)); color: var(--ag-ink); font: 700 .9rem "Sora", system-ui, sans-serif; cursor: pointer; }

/* ---------- Escribir ---------- */
.ag-form { display: flex; align-items: flex-end; gap: .5rem; padding: .7rem; border-top: 1px solid var(--ag-line); background: #fff; }
.ag-form textarea { flex: 1; min-height: 44px; max-height: 120px; padding: .65rem .85rem; border: 1.5px solid var(--ag-line); border-radius: 16px; background: var(--ag-bg); color: var(--ag-ink); font: 400 16px/1.4 "Inter", system-ui, sans-serif; resize: none; }
.ag-form textarea:focus { outline: none; border-color: var(--ag-ink); }
.ag-form textarea:disabled { opacity: .55; }
.ag-send { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--ag-ink); color: var(--ag-y); cursor: pointer; }
.ag-send:disabled { opacity: .4; cursor: default; }
.ag-send:focus-visible { outline: 3px solid var(--ag-y); outline-offset: 2px; }
.ag-foot { margin: 0; padding: 0 .9rem .55rem; background: #fff; color: var(--ag-muted); font-size: .7rem; text-align: center; }

/* ---------- Móvil ---------- */
@media (max-width: 600px) {
  .ag-launcher { right: 14px; bottom: 14px; padding: .4rem; }
  .ag-launcher span:not(.ag-launcher__dot) { display: none; }
  .ag-panel { inset: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; border: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .ag-launcher, .ag-panel, .ag-msg { transition: none; animation: none; }
}

/* Burbuja oculta mientras no se confirme que el agente está disponible */
.ag-launcher[hidden] { display: none !important; }
