/* ============================================
   Click WhatsApp Rotator v1.3
   Popup con animaciones dinámicas estilo Join.chat
   ============================================ */

/* ----- Botón flotante ----- */
#cwr-whatsapp-button {
    position: fixed;
    bottom: 25px;
    z-index: 999998;
    display: flex;
    align-items: center;
    gap: 12px;
}

#cwr-whatsapp-button.cwr-position-right {
    right: 25px;
    flex-direction: row;
}

#cwr-whatsapp-button.cwr-position-left {
    left: 25px;
    flex-direction: row-reverse;
}

.cwr-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    background-color: var(--cwr-bg, #25D366);
    color: #fff;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4), 0 2px 6px rgba(0, 0, 0, 0.15);
    text-decoration: none !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: cwr-pulse 2.5s infinite, cwr-bounceIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    position: relative;
    cursor: pointer;
}

/* Vibración sutil cada cierto tiempo para llamar la atención */
.cwr-button:not(.cwr-active) {
    animation: cwr-pulse 2.5s infinite, cwr-wiggle 6s ease-in-out 4s infinite;
}

.cwr-button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(37, 211, 102, 0.5), 0 4px 12px rgba(0, 0, 0, 0.2);
    animation-play-state: paused;
}

.cwr-button:active {
    transform: scale(0.95);
}

.cwr-button svg {
    width: 32px;
    height: 32px;
    transition: opacity 0.2s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cwr-button:hover svg {
    transform: rotate(-12deg) scale(1.1);
}

/* Estado: botón activo (popup abierto) — se transforma en X con giro */
.cwr-button.cwr-active {
    animation: none;
    transform: rotate(0deg);
}

.cwr-button.cwr-active svg {
    opacity: 0;
    transform: rotate(180deg) scale(0.5);
}

.cwr-button.cwr-active::after {
    content: '×';
    position: absolute;
    color: #fff;
    font-size: 36px;
    font-weight: 300;
    line-height: 1;
    animation: cwr-fadeInRotate 0.3s ease both;
}

@keyframes cwr-fadeInRotate {
    from {
        opacity: 0;
        transform: rotate(-90deg) scale(0.5);
    }
    to {
        opacity: 1;
        transform: rotate(0deg) scale(1);
    }
}

/* ----- Badge de notificación (número rojo "1") ----- */
.cwr-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    animation: cwr-badgePop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 3s both, cwr-badgePulse 1.5s ease-in-out 3.5s 3;
    z-index: 2;
    border: 2px solid #fff;
}

#cwr-whatsapp-button.cwr-popup-open .cwr-badge,
#cwr-whatsapp-button.cwr-badge-dismissed .cwr-badge {
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.25s, transform 0.25s;
}

@keyframes cwr-badgePop {
    0% { opacity: 0; transform: scale(0); }
    60% { opacity: 1; transform: scale(1.3); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes cwr-badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ----- Tooltip ----- */
.cwr-tooltip {
    background-color: #fff;
    color: #333;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    max-width: 240px;
    position: relative;
    animation: cwr-fadeIn 0.4s ease 1.5s both, cwr-tooltipFloat 3s ease-in-out 2s infinite;
    cursor: pointer;
}

.cwr-position-right .cwr-tooltip::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-left: 6px solid #fff;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

.cwr-position-left .cwr-tooltip::after {
    content: '';
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-right: 6px solid #fff;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

#cwr-whatsapp-button.cwr-popup-open .cwr-tooltip {
    display: none;
}

@keyframes cwr-tooltipFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* ----- Animaciones del botón ----- */
@keyframes cwr-bounceIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes cwr-pulse {
    0% {
        box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4), 0 2px 6px rgba(0, 0, 0, 0.15), 0 0 0 0 rgba(37, 211, 102, 0.6);
    }
    70% {
        box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4), 0 2px 6px rgba(0, 0, 0, 0.15), 0 0 0 18px rgba(37, 211, 102, 0);
    }
    100% {
        box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4), 0 2px 6px rgba(0, 0, 0, 0.15), 0 0 0 0 rgba(37, 211, 102, 0);
    }
}

@keyframes cwr-wiggle {
    0%, 90%, 100% { transform: rotate(0); }
    92% { transform: rotate(-8deg); }
    94% { transform: rotate(8deg); }
    96% { transform: rotate(-6deg); }
    98% { transform: rotate(4deg); }
}

@keyframes cwr-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes cwr-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Popup tipo Join.chat (anclado al botón)
   ============================================ */
.cwr-popup {
    position: fixed;
    bottom: 100px;
    width: 340px;
    max-width: calc(100vw - 50px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
    z-index: 999997;
    overflow: hidden;
    transform-origin: bottom right;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.6) translateY(20px);
    transition: opacity 0.28s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.4s;
    pointer-events: none;
}

.cwr-popup.cwr-position-right {
    right: 25px;
}

.cwr-popup.cwr-position-left {
    left: 25px;
    transform-origin: bottom left;
}

.cwr-popup.cwr-popup-open {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* ----- Header verde ----- */
.cwr-popup-header {
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: relative;
    overflow: hidden;
}

.cwr-popup-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle at 15% 30%, rgba(255,255,255,0.18) 0%, transparent 50%);
    pointer-events: none;
}

/* Brillo que cruza el header al abrirse */
.cwr-popup-header::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 60%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
    pointer-events: none;
}

.cwr-popup.cwr-popup-open .cwr-popup-header::after {
    animation: cwr-headerShine 1.2s ease-out 0.3s;
}

@keyframes cwr-headerShine {
    0% { left: -100%; }
    100% { left: 200%; }
}

.cwr-popup-header-content {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.cwr-popup-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
    color: #fff;
    margin: 0 0 3px 0;
}

.cwr-popup-subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.3;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.3s ease;
}

.cwr-popup-subtitle::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
    animation: cwr-onlinePulse 2s infinite;
    flex-shrink: 0;
    box-shadow: 0 0 8px #4ade80;
}

@keyframes cwr-onlinePulse {
    0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7), 0 0 8px #4ade80; }
    70% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0), 0 0 8px #4ade80; }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0), 0 0 8px #4ade80; }
}

.cwr-popup-close {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    backdrop-filter: blur(8px);
    font-size: 16px;
    line-height: 1;
    padding: 0;
}

.cwr-popup-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* ----- Body con burbuja de chat ----- */
.cwr-popup-body {
    padding: 22px 20px 18px;
    background: #ECE5DD;
    background-image:
        repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(255,255,255,0.04) 35px, rgba(255,255,255,0.04) 70px);
    min-height: 90px;
    position: relative;
}

/* Indicador de "escribiendo..." (typing dots) */
.cwr-typing {
    background: #fff;
    border-radius: 0 12px 12px 12px;
    padding: 14px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.cwr-typing.cwr-typing-show {
    opacity: 1;
    transform: translateY(0);
}

.cwr-typing.cwr-typing-hide {
    opacity: 0;
    transform: translateY(-4px);
}

.cwr-typing::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 10px 10px 0;
    border-color: transparent #fff transparent transparent;
}

.cwr-typing-dot {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: cwr-typingDot 1.3s ease-in-out infinite;
}

.cwr-typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.cwr-typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes cwr-typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Burbuja de chat */
.cwr-chat-bubble {
    background: #fff;
    border-radius: 0 12px 12px 12px;
    padding: 12px 14px 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    position: relative;
    max-width: 95%;
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    transition: opacity 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.cwr-chat-bubble.cwr-bubble-show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.cwr-chat-bubble:hover {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.cwr-chat-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 10px 10px 0;
    border-color: transparent #fff transparent transparent;
}

.cwr-chat-bubble p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: #303030;
}

.cwr-chat-bubble p + p {
    margin-top: 6px;
}

.cwr-chat-time {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    font-size: 10px;
    color: #999;
    margin-top: 4px;
}

/* Doble check azul (visto) */
.cwr-chat-check {
    color: #4FC3F7;
    font-size: 11px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.4s ease 0.6s;
}

.cwr-chat-bubble.cwr-bubble-show .cwr-chat-check {
    opacity: 1;
}

/* ----- Footer con CTA ----- */
.cwr-popup-footer {
    padding: 14px 16px 14px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
}

.cwr-popup-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, #25D366 0%, #1eb858 100%);
    color: #fff;
    border: none;
    border-radius: 30px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 3px 10px rgba(37, 211, 102, 0.3);
    text-decoration: none;
    font-family: inherit;
    position: relative;
    overflow: hidden;
}

/* Brillo (shimmer) que pasa por el botón cada cierto tiempo */
.cwr-popup-cta::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    pointer-events: none;
}

.cwr-popup.cwr-popup-open .cwr-popup-cta::before {
    animation: cwr-ctaShimmer 3s ease-in-out 1.5s infinite;
}

@keyframes cwr-ctaShimmer {
    0% { left: -100%; }
    50%, 100% { left: 200%; }
}

.cwr-popup-cta:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 18px rgba(37, 211, 102, 0.45);
}

.cwr-popup-cta:hover .cwr-cta-icon svg {
    transform: translateX(4px) rotate(-15deg);
}

.cwr-popup-cta:active {
    transform: translateY(0) scale(0.98);
}

.cwr-popup-cta.cwr-loading {
    opacity: 0.7;
    pointer-events: none;
}

.cwr-popup-cta.cwr-loading .cwr-cta-icon svg {
    animation: cwr-spin 0.8s linear infinite;
}

.cwr-popup-cta svg {
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ============================================
   Shortcode button (inline)
   ============================================ */
.cwr-shortcode-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background-color: #25D366;
    color: #fff !important;
    border-radius: 10px;
    text-decoration: none !important;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
    cursor: pointer;
}

.cwr-shortcode-button:hover {
    background-color: #1eb858;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 600px) {
    #cwr-whatsapp-button {
        bottom: 20px;
    }
    #cwr-whatsapp-button.cwr-position-right {
        right: 20px;
    }
    #cwr-whatsapp-button.cwr-position-left {
        left: 20px;
    }
    .cwr-tooltip {
        display: none;
    }
    .cwr-button {
        width: 56px;
        height: 56px;
    }
    .cwr-button svg {
        width: 28px;
        height: 28px;
    }
    .cwr-popup {
        bottom: 90px;
        width: calc(100vw - 40px);
        max-width: 360px;
    }
    .cwr-popup.cwr-position-right {
        right: 20px;
    }
    .cwr-popup.cwr-position-left {
        left: 20px;
    }
}

/* Respetar usuarios que prefieren menos movimiento */
@media (prefers-reduced-motion: reduce) {
    .cwr-button,
    .cwr-button:not(.cwr-active),
    .cwr-tooltip,
    .cwr-popup-cta::before,
    .cwr-popup-header::after,
    .cwr-typing-dot,
    .cwr-popup-subtitle::before {
        animation: none !important;
    }
}
