/**
 * WR Botones Mobile — Chat conversacional estilo WhatsApp.
 *
 * Paleta y composición tomadas de WhatsApp real para maximizar la percepción
 * de cercanía y el CTR. El panel está OCULTO por defecto; el motor (wrbtn-chat.js)
 * abre/cierra alternando la clase `.is-open` en el contenedor raíz.
 */

:root {
    --wrbtn-wa-verde:        #25d366;
    --wrbtn-wa-verde-osc:    #128c7e;
    --wrbtn-wa-teal:         #075e54;
    --wrbtn-wa-header:       #008069;
    --wrbtn-wa-burbuja-in:   #ffffff;
    --wrbtn-wa-burbuja-out:  #d9fdd3;
    --wrbtn-wa-texto:        #111b21;
    --wrbtn-wa-texto-tenue:  #667781;
    --wrbtn-wa-fondo:        #efeae2;
    --wrbtn-wa-sombra:       0 12px 40px rgba(11, 20, 26, 0.28);
    --wrbtn-wa-radio:        16px;
    --wrbtn-chat-wall:       url('../../../public/static/img/img_whatsapp/wall.png');
}

/* ── Contenedor raíz ─────────────────────────────────────────────────────── */
.wrbtn-chat-widget {
    position: fixed;
    bottom: 22px;
    z-index: 99990;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    box-sizing: border-box;
}
.wrbtn-chat-widget *,
.wrbtn-chat-widget *::before,
.wrbtn-chat-widget *::after {
    box-sizing: border-box;
}
.wrbtn-chat-widget--positionright { right: 22px; }
.wrbtn-chat-widget--positionleft  { left: 22px; }

/* Dispositivo no habilitado: se oculta solo el botón flotante y el teaser,
   pero el panel sigue disponible para botones .wrc-wapp del tema. */
.wrbtn-chat-widget--sin-trigger .wrbtn-chat-trigger,
.wrbtn-chat-widget--sin-trigger .wrbtn-chat-teaser { display: none !important; }
.wrbtn-chat-widget--sin-trigger:not(.is-open) { pointer-events: none; }
.wrbtn-chat-widget--sin-trigger.is-open { pointer-events: auto; }

/* ── Botón flotante (trigger) ────────────────────────────────────────────── */
.wrbtn-chat-trigger {
    position: relative;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: var(--wrbtn-wa-verde);
    box-shadow: 0 6px 18px rgba(37, 211, 102, 0.45);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.wrbtn-chat-trigger:hover { transform: scale(1.06); }
.wrbtn-chat-trigger__icon {
    width: 34px;
    height: 34px;
    pointer-events: none;
}
.wrbtn-chat-trigger__pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--wrbtn-wa-verde);
    opacity: 0.55;
    z-index: -1;
    animation: wrbtn-chat-pulse 2.2s infinite ease-out;
}
@keyframes wrbtn-chat-pulse {
    0%   { transform: scale(1);   opacity: 0.55; }
    70%  { transform: scale(1.7); opacity: 0; }
    100% { transform: scale(1.7); opacity: 0; }
}

/* Notificación (punto) sobre el trigger */
.wrbtn-chat-trigger[data-badge]::after {
    content: attr(data-badge);
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ff3b30;
    color: #fff;
    font-size: 12px;
    line-height: 20px;
    font-weight: 700;
    text-align: center;
}

/* ── Teaser (burbuja de invitación) ──────────────────────────────────────── */
.wrbtn-chat-teaser {
    position: absolute;
    bottom: 74px;
    max-width: 250px;
    padding: 12px 14px;
    border: 0;
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--wrbtn-wa-sombra);
    text-align: left;
    cursor: pointer;
    display: none;
    flex-direction: column;
    gap: 4px;
    animation: wrbtn-chat-teaser-in 0.4s ease both;
}
.wrbtn-chat-widget--positionright .wrbtn-chat-teaser { right: 0; }
.wrbtn-chat-widget--positionleft  .wrbtn-chat-teaser { left: 0; }
.wrbtn-chat-widget.is-teaser .wrbtn-chat-teaser { display: flex; }
.wrbtn-chat-widget.is-open .wrbtn-chat-teaser { display: none; }
.wrbtn-chat-teaser__label { font-size: 14px; color: var(--wrbtn-wa-texto); }
.wrbtn-chat-teaser__cta {
    font-size: 13px;
    font-weight: 700;
    color: var(--wrbtn-wa-verde-osc);
}
@keyframes wrbtn-chat-teaser-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Panel del chat ──────────────────────────────────────────────────────── */
.wrbtn-chat-panel {
    position: absolute;
    bottom: 78px;
    width: 372px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    border-radius: var(--wrbtn-wa-radio);
    overflow: hidden;
    box-shadow: var(--wrbtn-wa-sombra);
    background: var(--wrbtn-wa-fondo);
    /* Oculto por defecto: aria-hidden NO oculta visualmente, esto sí. */
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    transform-origin: bottom right;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}
.wrbtn-chat-widget--positionright .wrbtn-chat-panel { right: 0; transform-origin: bottom right; }
.wrbtn-chat-widget--positionleft  .wrbtn-chat-panel { left: 0;  transform-origin: bottom left; }
.wrbtn-chat-widget.is-open .wrbtn-chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s;
}

/* ── Modo POPUP (disparado por .wrc-wapp): modal centrado con overlay ─────── */
.wrbtn-chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 20, 26, 0.55);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    z-index: 1;
    pointer-events: none;
    transition: opacity 0.22s ease, visibility 0s linear 0.22s;
}
.wrbtn-chat-widget.is-popup.is-open .wrbtn-chat-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.22s ease;
}
/* En modo popup el panel se centra en la pantalla (no en la esquina). */
.wrbtn-chat-widget.is-popup .wrbtn-chat-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    z-index: 2;
    transform: translate(-50%, -50%) scale(0.96);
    transform-origin: center;
    height: 600px;
    max-height: calc(100vh - 48px);
}
.wrbtn-chat-widget.is-popup.is-open .wrbtn-chat-panel {
    transform: translate(-50%, -50%) scale(1);
}

.wrbtn-chat-card {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.wrbtn-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    background: var(--wrbtn-wa-header);
    color: #fff;
}
.wrbtn-chat-header__identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.wrbtn-chat-header__avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.2);
    flex: 0 0 auto;
}
.wrbtn-chat-header__copy { display: flex; flex-direction: column; min-width: 0; }
.wrbtn-chat-header__title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wrbtn-chat-header__status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.92;
}
.wrbtn-chat-header__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8ef0a0;
    box-shadow: 0 0 0 0 rgba(142, 240, 160, 0.7);
    animation: wrbtn-chat-dot 2s infinite;
}
@keyframes wrbtn-chat-dot {
    0%   { box-shadow: 0 0 0 0 rgba(142, 240, 160, 0.6); }
    70%  { box-shadow: 0 0 0 6px rgba(142, 240, 160, 0); }
    100% { box-shadow: 0 0 0 0 rgba(142, 240, 160, 0); }
}
.wrbtn-chat-close {
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.9;
}
.wrbtn-chat-close:hover { opacity: 1; }

/* ── Área de mensajes ────────────────────────────────────────────────────── */
.wrbtn-chat-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 12px;
    background-color: var(--wrbtn-wa-fondo);
    background-image: var(--wrbtn-chat-wall);
    background-size: 360px;
    scrollbar-width: thin;
}
.wrbtn-chat-scroll::-webkit-scrollbar { width: 6px; }
.wrbtn-chat-scroll::-webkit-scrollbar-thumb { background: rgba(11, 20, 26, 0.2); border-radius: 3px; }
.wrbtn-chat-messages { display: flex; flex-direction: column; gap: 8px; }

/* ── Burbujas ────────────────────────────────────────────────────────────── */
.wrbtn-chat-msg {
    position: relative;
    max-width: 82%;
    padding: 7px 10px 6px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--wrbtn-wa-texto);
    box-shadow: 0 1px 1px rgba(11, 20, 26, 0.12);
    word-wrap: break-word;
    animation: wrbtn-chat-msg-in 0.22s ease both;
}
.wrbtn-chat-msg--in  { align-self: flex-start; background: var(--wrbtn-wa-burbuja-in);  border-top-left-radius: 2px; }
.wrbtn-chat-msg--out { align-self: flex-end;   background: var(--wrbtn-wa-burbuja-out); border-top-right-radius: 2px; }
.wrbtn-chat-msg__time {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    text-align: right;
    color: var(--wrbtn-wa-texto-tenue);
}
@keyframes wrbtn-chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Indicador de "escribiendo…" */
.wrbtn-chat-typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 8px;
    border-top-left-radius: 2px;
    background: var(--wrbtn-wa-burbuja-in);
    box-shadow: 0 1px 1px rgba(11, 20, 26, 0.12);
}
.wrbtn-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9aa6ad;
    animation: wrbtn-chat-typing 1.2s infinite ease-in-out;
}
.wrbtn-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.wrbtn-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes wrbtn-chat-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ── Quick actions (botones de acción) ───────────────────────────────────── */
.wrbtn-chat-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-self: stretch;
    margin-top: 2px;
}
.wrbtn-chat-action {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid rgba(0, 128, 105, 0.35);
    border-radius: 10px;
    background: #fff;
    color: var(--wrbtn-wa-verde-osc);
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}
.wrbtn-chat-action:hover { background: #f2fbf6; }
.wrbtn-chat-action:active { transform: scale(0.99); }

/* ── Footer dinámico (input / CTA) ───────────────────────────────────────── */
.wrbtn-chat-footer {
    flex: 0 0 auto;
    padding: 10px 12px;
    background: #f0f2f5;
    border-top: 1px solid rgba(11, 20, 26, 0.08);
}
.wrbtn-chat-footer:empty { display: none; }

.wrbtn-chat-inputbar { display: flex; align-items: flex-end; gap: 8px; }
.wrbtn-chat-input {
    flex: 1 1 auto;
    min-height: 42px;
    max-height: 110px;
    padding: 10px 14px;
    border: 0;
    border-radius: 21px;
    background: #fff;
    font-size: 14px;
    line-height: 1.35;
    resize: none;
    outline: none;
    font-family: inherit;
    box-shadow: 0 1px 1px rgba(11, 20, 26, 0.1);
}
.wrbtn-chat-send {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: var(--wrbtn-wa-verde-osc);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.wrbtn-chat-send:hover { background: var(--wrbtn-wa-teal); }
.wrbtn-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Consentimiento GDPR inline */
.wrbtn-chat-consent { display: flex; flex-direction: column; gap: 10px; }
.wrbtn-chat-consent__check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 12.5px;
    color: var(--wrbtn-wa-texto);
    line-height: 1.35;
}
.wrbtn-chat-consent__check input { margin-top: 2px; flex: 0 0 auto; }
.wrbtn-chat-consent__check a { color: var(--wrbtn-wa-verde-osc); }

/* CTA de WhatsApp y botones primarios */
.wrbtn-chat-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 13px 16px;
    border: 0;
    border-radius: 24px;
    background: var(--wrbtn-wa-verde);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}
.wrbtn-chat-cta:hover { background: var(--wrbtn-wa-verde-osc); }
.wrbtn-chat-cta:active { transform: scale(0.99); }
.wrbtn-chat-cta:disabled { opacity: 0.55; cursor: not-allowed; }

.wrbtn-chat-maps-wrap { display: flex; align-self: stretch; margin-top: 4px; }

.wrbtn-chat-datetime {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.wrbtn-chat-datetime input {
    flex: 1 1 130px;
    padding: 10px 12px;
    border: 1px solid rgba(11, 20, 26, 0.15);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}

/* ── Mobile: panel a pantalla completa ───────────────────────────────────── */
@media (max-width: 480px) {
    /* En mobile, AMBOS modos (flotante y popup) ocupan toda la pantalla. */
    .wrbtn-chat-widget.is-open .wrbtn-chat-panel,
    .wrbtn-chat-widget.is-popup.is-open .wrbtn-chat-panel {
        position: fixed;
        inset: 0;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        transform: none;
    }
    .wrbtn-chat-teaser { max-width: 200px; }
}

/* Respeta usuarios con preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
    .wrbtn-chat-trigger__pulse,
    .wrbtn-chat-header__dot,
    .wrbtn-chat-typing span { animation: none; }
    .wrbtn-chat-panel,
    .wrbtn-chat-msg { transition: none; animation: none; }
}
