/* ==========================================================================
   Centro de contacto flotante (prefijo cx-). Usa los tokens de app.css.
   ========================================================================== */

/* ---------- Botón y menú ---------- */
.cx { position: fixed; right: calc(1rem + env(safe-area-inset-right)); bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 60; font-family: var(--f-body); transition: opacity .2s, visibility .2s; }
.menu-open .cx { opacity: 0; visibility: hidden; }
.cx::before { content: ""; position: fixed; inset: 0; z-index: -1; background: radial-gradient(130% 100% at 100% 100%, rgba(10, 11, 20, .62), rgba(10, 11, 20, .2) 70%); opacity: 0; visibility: hidden; transition: opacity .3s, visibility 0s .3s; }
.cx.is-open::before { opacity: 1; visibility: visible; transition-delay: 0s; }

.cx-fab { position: relative; display: grid; place-items: center; width: 3.75rem; height: 3.75rem; padding: 0; border: 3px solid transparent; border-radius: 50%; background: var(--gradient) border-box; color: #fff; box-shadow: var(--shadow-purple-lg); text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .3s cubic-bezier(.2, .8, .2, 1), box-shadow .3s, color .3s; }
/* Pulso: anillo que crece y se desvanece dos veces (menos de 5 s); solo transform y opacity */
.cx-fab::before { content: ""; position: absolute; inset: -3px; border: 2px solid rgba(124, 58, 237, .6); border-radius: 50%; opacity: 0; pointer-events: none; animation: cx-pulso 2.4s ease-out 2; }
.cx.is-usado .cx-fab::before, .cx.is-open .cx-fab::before { animation: none; }
@keyframes cx-pulso { 0% { opacity: .9; transform: scale(1); } 70%, 100% { opacity: 0; transform: scale(1.55); } }
.cx-fab .ic { grid-area: 1 / 1; width: 1.7rem; height: 1.7rem; transition: transform .35s cubic-bezier(.2, .8, .2, 1), opacity .2s; }
.cx-toggle, .js .cx-nojs { display: none; }
.js .cx-toggle { display: grid; }
.cx-x { opacity: 0; transform: rotate(-90deg) scale(.5); }
.cx.is-open .cx-toggle { background: linear-gradient(#fff, #fff) padding-box, var(--gradient) border-box; color: var(--dark); box-shadow: 0 14px 34px -10px rgba(10, 11, 20, .55); }
.cx.is-open .cx-ico { opacity: 0; transform: rotate(90deg) scale(.5); }
.cx.is-open .cx-x { opacity: 1; transform: none; }
@media (hover: hover) { .cx-fab:hover { transform: translateY(-2px); } }
.cx .cx-fab:focus-visible { outline: none; box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--primary), var(--shadow-purple-lg); }

.cx-menu { position: absolute; right: .375rem; bottom: calc(100% + .9rem); display: grid; justify-items: end; gap: .75rem; width: max-content; margin: 0; padding: 0; list-style: none; visibility: hidden; transition: visibility 0s .3s; }
.cx.is-open .cx-menu { visibility: visible; transition-delay: 0s; }
.cx-menu li { opacity: 0; transform: translateY(14px) scale(.85); transform-origin: 100% 50%; transition: opacity .2s, transform .3s cubic-bezier(.2, .8, .2, 1); }
.cx.is-open .cx-menu li { opacity: 1; transform: none; transition-delay: calc(var(--d, 0) * 55ms); }
.cx-item { display: flex; align-items: center; gap: .7rem; min-height: 3rem; padding: 0; border: 0; background: none; color: var(--dark); font: 700 .95rem/1.2 var(--f-display); letter-spacing: -.01em; text-decoration: none; white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cx-label, .cx-bubble { background: #fff; box-shadow: 0 10px 28px -10px rgba(10, 11, 20, .45), 0 0 0 1px rgba(10, 11, 20, .06); transition: transform .2s, color .2s, box-shadow .2s; }
.cx-label { padding: .6rem 1rem; border-radius: 999px; }
.cx-bubble { display: grid; place-items: center; width: 3rem; height: 3rem; border-radius: 50%; }
.cx-bubble .ic { width: 1.35rem; height: 1.35rem; }
@media (hover: hover) {
    .cx-item:hover .cx-bubble { color: var(--primary); transform: scale(1.08); }
    .cx-item:hover .cx-label { color: var(--primary-dark); }
}
.cx-item:focus-visible { outline: none; }
.cx-item:focus-visible .cx-label, .cx-item:focus-visible .cx-bubble { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--primary); }

/* ---------- Panel ---------- */
body.cx-bloqueo { overflow: hidden; }
html.cx-gutter { scrollbar-gutter: stable; }
.cx-velo { position: fixed; inset: 0; z-index: 70; background: rgba(10, 11, 20, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: cx-aparece .25s ease; }
.cx-panel { position: fixed; z-index: 71; right: calc(1rem + env(safe-area-inset-right)); bottom: calc(var(--cx-teclado, 0px) + 1rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; width: min(26rem, 100vw - 2rem); height: min(41rem, 100vh - 2rem); height: min(41rem, var(--cx-vh, 100dvh) - 2rem); overflow: hidden; background: #fff; color: var(--text); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg), 0 0 0 1px rgba(10, 11, 20, .06); font-family: var(--f-body); animation: cx-sube .35s cubic-bezier(.2, .8, .2, 1); }
.cx-velo[hidden], .cx-panel[hidden], .cx-vista[hidden], .cx-err[hidden] { display: none; }
.cx-panel :focus-visible { outline-color: var(--primary); }
@keyframes cx-aparece { from { opacity: 0; } }
@keyframes cx-sube { from { opacity: 0; transform: translateY(20px) scale(.98); } }

.cx-head { position: relative; isolation: isolate; display: flex; align-items: center; gap: .75rem; padding: 1rem 1rem 1rem 1.1rem; background: var(--dark); color: #fff; }
.cx-head::after { content: ""; position: absolute; inset: 0; z-index: -1; background: radial-gradient(18rem 9rem at 100% 0%, rgba(124, 58, 237, .45), transparent 70%); }
.cx-avatar { display: grid; place-items: center; flex-shrink: 0; width: 2.75rem; height: 2.75rem; border-radius: 50%; background: rgba(255, 255, 255, .08); box-shadow: 0 0 0 1px rgba(255, 255, 255, .12); }
.cx-avatar img { width: 2rem; height: 2rem; }
.cx-head-txt { flex: 1; min-width: 0; }
.cx-titulo { margin: 0; font: 600 1.05rem/1.25 var(--f-display); letter-spacing: -.01em; color: #fff; }
.cx-sub { display: flex; align-items: center; gap: .45rem; margin: .1rem 0 0; font-size: .8rem; color: var(--slate-400); }
.cx-sub::before { content: ""; flex-shrink: 0; width: .45rem; height: .45rem; border-radius: 50%; background: var(--primary-light); box-shadow: 0 0 0 3px rgba(167, 139, 250, .25); }
.cx-cerrar { display: grid; place-items: center; flex-shrink: 0; width: 2.75rem; height: 2.75rem; padding: 0; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .08); color: #fff; cursor: pointer; transition: background .2s; }
.cx-cerrar:hover { background: rgba(255, 255, 255, .16); }
.cx-head .cx-cerrar:focus-visible { outline-color: var(--primary-light); }
.cx-cerrar .ic { width: 1.25rem; height: 1.25rem; }

.cx-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; margin: .8rem 1rem .1rem; padding: .25rem; border: 1px solid var(--slate-border); border-radius: 999px; background: var(--slate-light); }
.cx-tab { min-height: 2.75rem; padding: .3rem .5rem; border: 0; border-radius: 999px; background: none; color: var(--slate-600); font: 600 .88rem/1.2 var(--f-body); cursor: pointer; transition: background .2s, color .2s, box-shadow .2s; }
/* Pestaña activa: relleno de marca y texto blanco, no solo cambio de tono */
.cx-tab[aria-selected="true"] { background: var(--gradient); color: #fff; box-shadow: var(--shadow-purple); }

.cx-vista { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.cx-faq, .cx-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .9rem 1rem; }
.cx-faq { display: block; }
.cx-scroll { position: relative; }

/* ---------- Preguntas frecuentes ---------- */
.cx-faq details { margin-bottom: .55rem; border: 1px solid var(--slate-border); border-radius: 14px; background: #fff; transition: box-shadow .25s, border-color .25s; }
.cx-faq details[open] { border-color: var(--primary-soft-2); box-shadow: var(--shadow); }
.cx-faq summary { display: flex; justify-content: space-between; align-items: center; gap: .75rem; min-height: 2.75rem; padding: .7rem .9rem; border-radius: 14px; font-weight: 600; font-size: .93rem; line-height: 1.35; list-style: none; cursor: pointer; }
.cx-faq summary::-webkit-details-marker { display: none; }
.cx-faq summary::after { content: "+"; display: grid; place-items: center; flex-shrink: 0; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--primary-soft-2); color: var(--primary); font: 600 1rem/1 var(--f-body); transition: transform .25s; }
.cx-faq details[open] summary::after { transform: rotate(45deg); background: var(--gradient); color: #fff; }
.cx-faq details p { margin: 0; padding: 0 .9rem .85rem; font-size: .9rem; color: var(--slate-600); }
.cx-faq-pie { display: grid; justify-items: start; gap: .35rem; margin-top: 1rem; padding: 1rem; border-radius: 16px; background: var(--primary-soft); }
.cx-faq-pie p { margin: 0 0 .3rem; font-weight: 600; font-size: .92rem; }

/* ---------- Chat ---------- */
.cx-log { display: flex; flex-direction: column; gap: .6rem; border-radius: 12px; }
.cx-lead-slot:not(:empty) { margin-top: .6rem; }
.cx-msg { max-width: 90%; padding: .7rem .9rem; border-radius: 18px; font-size: .92rem; line-height: 1.5; overflow-wrap: anywhere; animation: cx-sube .3s cubic-bezier(.2, .8, .2, 1); }
.cx-msg :where(p) { margin: 0; }
.cx-msg > * + * { margin-top: .5rem; }
.cx-msg ul { margin-bottom: 0; padding-left: 1.1rem; }
.cx-bot { align-self: flex-start; background: var(--slate-light); border: 1px solid var(--slate-border); border-bottom-left-radius: 6px; }
.cx-yo { align-self: flex-end; background: var(--gradient); color: #fff; border-bottom-right-radius: 6px; }
.cx-acc { display: flex; flex-wrap: wrap; gap: .45rem; }
.cx-escribe { display: flex; gap: .3rem; padding: .95rem 1rem; }
.cx-escribe span { width: .45rem; height: .45rem; margin: 0; border-radius: 50%; background: var(--slate-400); animation: cx-punto 1s infinite; }
.cx-escribe span:nth-child(2) { animation-delay: .15s; }
.cx-escribe span:nth-child(3) { animation-delay: .3s; }
@keyframes cx-punto { 50% { opacity: .35; transform: translateY(-3px); } }

.cx-btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 2.75rem; padding: .55rem 1.05rem; border: 0; border-radius: 999px; background: var(--gradient); color: #fff; font: 600 .9rem/1.2 var(--f-body); text-decoration: none; cursor: pointer; box-shadow: var(--shadow-purple); transition: transform .2s, box-shadow .2s; }
.cx-btn-sec { background: #fff; color: var(--primary-dark); box-shadow: inset 0 0 0 1.5px var(--primary-light); }
.cx-btn-wa { background: var(--wa); color: #06271A; box-shadow: none; }
.cx-btn[disabled] { opacity: .65; cursor: progress; }
@media (hover: hover) { .cx-btn:hover { transform: translateY(-1px); } }

/* scroll-padding: al llegar con Tab, el chip se detiene antes del borde desvanecido */
.cx-chips { display: flex; gap: .4rem; padding: .45rem 1rem .55rem; overflow-x: auto; overscroll-behavior-x: contain; scroll-padding-inline: 1rem 3.5rem; scrollbar-width: thin; -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent); }
.cx-chips::after { content: ""; flex: 0 0 1.5rem; }
.cx-chip { flex-shrink: 0; min-height: 2.75rem; padding: .45rem .9rem; border: 1px solid var(--primary-soft-2); border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark); font: 600 .84rem/1.25 var(--f-body); white-space: nowrap; cursor: pointer; transition: background .2s, border-color .2s; }
@media (hover: hover) { .cx-chip:hover { background: var(--primary-soft-2); border-color: var(--primary-light); } }

.cx-form { display: flex; gap: .5rem; padding: .65rem 1rem; border-top: 1px solid var(--slate-border); }
.cx-form input, .cx-lead :is(input[type="text"], input[type="tel"], textarea) { width: 100%; min-width: 0; min-height: 2.75rem; padding: .55rem .9rem; border: 1.5px solid var(--slate-300); background: var(--slate-light); color: var(--text); font: 400 16px/1.4 var(--f-body); transition: border-color .2s, box-shadow .2s; }
.cx-form input { flex: 1; border-radius: 999px; }
.cx-form input:focus, .cx-lead :is(input[type="text"], input[type="tel"], textarea):focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(124, 58, 237, .16); }
.cx-enviar { display: grid; place-items: center; flex-shrink: 0; width: 2.75rem; height: 2.75rem; padding: 0; border: 0; border-radius: 50%; background: var(--gradient); color: #fff; cursor: pointer; box-shadow: var(--shadow-purple); }
.cx-enviar .ic { width: 1.2rem; height: 1.2rem; }
.cx-nota { margin: 0; padding: 0 1rem .7rem; font-size: .74rem; line-height: 1.4; color: var(--muted); text-align: center; }

.cx-lead { display: grid; gap: .65rem; padding: .95rem; border: 1px solid var(--slate-border); border-radius: 18px; background: #fff; box-shadow: var(--shadow); animation: cx-sube .3s cubic-bezier(.2, .8, .2, 1); }
.cx-lead > p:first-child { margin: 0; font-weight: 600; font-size: .92rem; }
.cx-campo { display: grid; gap: .25rem; }
.cx-campo label { font-size: .82rem; font-weight: 600; }
.cx-lead :is(input[type="text"], input[type="tel"], textarea) { border-radius: 12px; }
.cx-lead textarea { min-height: 4.5rem; resize: vertical; }
.cx-lead :is(input, textarea)[aria-invalid="true"] { border-color: #F87171; background: #FFF7F7; }
.cx-check { display: flex; gap: .6rem; align-items: flex-start; min-height: 2.75rem; font-size: .8rem; line-height: 1.45; color: var(--slate-600); cursor: pointer; }
.cx-check input { flex-shrink: 0; width: 1.25rem; height: 1.25rem; margin: .1rem 0 0; accent-color: var(--primary); }
.cx-check input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.cx-check a { color: var(--primary-dark); }
.cx-err { margin: 0; font-size: .8rem; font-weight: 500; color: var(--danger-text); }

/* Formulario abierto o teclado visible: se ocultan piezas fijas para dar espacio a la conversación */
.cx-chat.is-lead .cx-chips, .cx-chat.is-lead .cx-form, .cx-chat.is-lead .cx-nota,
.cx-panel.is-teclado .cx-tabs, .cx-panel.is-teclado .cx-chips, .cx-panel.is-teclado .cx-nota { display: none; }
.cx-panel.is-teclado { padding-bottom: 0; }

/* ---------- Celular: hoja inferior ---------- */
@media (max-width: 480px) {
    .cx-panel { left: 0; right: 0; bottom: var(--cx-teclado, 0px); width: auto; height: 80vh; height: min(80dvh, var(--cx-vh, 100dvh) - .75rem); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding-bottom: env(safe-area-inset-bottom); animation-name: cx-hoja; }
    .cx-panel.is-teclado { padding-bottom: 0; }
    .cx-head { padding: 1.3rem .9rem .8rem; }
    .cx-tabs { margin: .6rem .9rem 0; }
    .cx-faq, .cx-scroll { padding: .75rem .9rem; }
    .cx-form { padding: .5rem .9rem; }
    .cx-head::before { content: ""; position: absolute; top: .5rem; left: 50%; width: 2.5rem; height: 4px; margin-left: -1.25rem; border-radius: 4px; background: rgba(255, 255, 255, .25); }
    .cx-chips { scrollbar-width: none; }
}
@keyframes cx-hoja { from { transform: translateY(100%); } }

/* ---------- Pantallas bajas (celular horizontal, zoom 200–400 %): el panel se desplaza completo ---------- */
@media (max-height: 520px) {
    .cx-panel { overflow-y: auto; overscroll-behavior: contain; }
    .cx-vista, .cx-scroll { flex: 1 0 auto; min-height: auto; overflow: visible; }
    .cx-scroll { min-height: 9rem; }
    .cx-head { position: sticky; top: 0; z-index: 1; padding-block: .5rem; }
    .cx-head::before, .cx-avatar, .cx-nota { display: none; }
    .cx-tabs { margin-top: .4rem; }
}

@media (prefers-reduced-motion: reduce) {
    .cx *, .cx::before, .cx-fab::before, .cx-velo, .cx-panel, .cx-panel * { animation: none !important; transition: none !important; }
}
@media print { .cx, .cx-velo, .cx-panel { display: none !important; } }
