/* WhatsApp Chat Button - Estilos con Personajes Animados */

:root {
    --whatsapp-green: #25D366;
    --whatsapp-dark-green: #128C7E;
    --whatsapp-light-green: #34E877;
    --shadow-color: rgba(37, 211, 102, 0.4);
    --tooltip-bg: #ffffff;
    --tooltip-text: #333333;
}

.whatsapp-chat-button-container {
    position: fixed;
    z-index: 999999;
    display: flex;
    align-items: flex-end;
    gap: 15px;
    transition: all 0.3s ease;
}

/* Posiciones */
.whatsapp-position-bottom-right {
    bottom: 20px;
    right: 20px;
    flex-direction: row-reverse;
}

.whatsapp-position-bottom-left {
    bottom: 20px;
    left: 20px;
    flex-direction: row;
}

.whatsapp-position-top-right {
    top: 20px;
    right: 20px;
    flex-direction: row-reverse;
}

.whatsapp-position-top-left {
    top: 20px;
    left: 20px;
    flex-direction: row;
}

/* Contenedor del personaje */
.whatsapp-character-container {
    position: relative;
    width: calc(var(--button-size, 60px) * 1.8);
    height: calc(var(--button-size, 60px) * 2.2);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

/* Botón principal */
.whatsapp-chat-button {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    padding: 0;
    filter: drop-shadow(0 4px 12px var(--shadow-color));
}

.whatsapp-chat-button:hover {
    transform: scale(1.1);
    filter: drop-shadow(0 6px 20px var(--shadow-color));
}

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

/* SVG del personaje */
.character-svg {
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
}

/* Burbuja de diálogo estilo cómic */
.whatsapp-speech-bubble {
    position: relative;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    padding: 15px 20px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    max-width: 280px;
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    animation: bubbleEntrance 0.5s ease-out 2s forwards;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    border: 3px solid var(--whatsapp-green);
}

.whatsapp-speech-bubble::before {
    content: '';
    position: absolute;
    bottom: 15px;
    width: 0;
    height: 0;
    border: 15px solid transparent;
}

/* Punta de la burbuja - derecha */
.whatsapp-position-bottom-right .whatsapp-speech-bubble::before,
.whatsapp-position-top-right .whatsapp-speech-bubble::before {
    right: -25px;
    border-left-color: var(--whatsapp-green);
    border-right: 0;
}

.whatsapp-position-bottom-right .whatsapp-speech-bubble::after,
.whatsapp-position-top-right .whatsapp-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: 18px;
    right: -19px;
    width: 0;
    height: 0;
    border: 12px solid transparent;
    border-left-color: var(--tooltip-bg);
    border-right: 0;
}

/* Punta de la burbuja - izquierda */
.whatsapp-position-bottom-left .whatsapp-speech-bubble::before,
.whatsapp-position-top-left .whatsapp-speech-bubble::before {
    left: -25px;
    border-right-color: var(--whatsapp-green);
    border-left: 0;
}

.whatsapp-position-bottom-left .whatsapp-speech-bubble::after,
.whatsapp-position-top-left .whatsapp-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: 18px;
    left: -19px;
    width: 0;
    height: 0;
    border: 12px solid transparent;
    border-right-color: var(--tooltip-bg);
    border-left: 0;
}

.speech-bubble-content {
    position: relative;
}

.speech-text {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--tooltip-text);
}

.speech-close {
    position: absolute;
    top: 5px;
    right: 5px;
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    line-height: 1;
}

.speech-close:hover {
    background: #f0f0f0;
    color: #333;
}

.whatsapp-speech-bubble.hidden {
    animation: bubbleExit 0.3s ease-out forwards;
}

/* Animaciones de personajes */

/* Animación de los ojos (parpadeo) */
@keyframes blink {
    0%, 90%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(0.1); }
}

.character-eye {
    animation: blink 4s infinite;
}

/* Movimiento de pupilas */
@keyframes lookAround {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(1px, 0); }
    50% { transform: translate(0, 1px); }
    75% { transform: translate(-1px, 0); }
}

.character-pupil {
    animation: lookAround 6s infinite ease-in-out;
}

/* Animación del brazo (Clippy) */
@keyframes waveArm {
    0%, 100% { transform: rotate(0deg); transform-origin: left center; }
    25% { transform: rotate(-15deg); transform-origin: left center; }
    75% { transform: rotate(15deg); transform-origin: left center; }
}

.whatsapp-character-assistant .character-arm {
    animation: waveArm 2s infinite ease-in-out;
}

/* Animación de la bombilla (Einstein) */
@keyframes glowBulb {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; filter: drop-shadow(0 0 8px #FFD700); }
}

.whatsapp-character-scientist .idea-bulb {
    animation: glowBulb 2s infinite;
}

/* Animación de antena del robot */
@keyframes antennaGlow {
    0%, 100% { filter: drop-shadow(0 0 2px #FFD700); }
    50% { filter: drop-shadow(0 0 8px #FFD700); }
}

.whatsapp-character-robot line {
    animation: antennaGlow 1.5s infinite;
}

/* Sonrisa que se mueve */
@keyframes smile {
    0%, 100% { d: path("M40 60 Q50 68 60 60"); }
    50% { d: path("M40 60 Q50 70 60 60"); }
}

/* Animaciones del contenedor */

/* Pulso */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.whatsapp-animation-pulse .whatsapp-character-container {
    animation: pulse 2s infinite ease-in-out;
}

/* Vibración */
@keyframes shake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-3px) rotate(-2deg); }
    20%, 40%, 60%, 80% { transform: translateX(3px) rotate(2deg); }
}

.whatsapp-animation-shake .whatsapp-character-container {
    animation: shake 3s infinite;
}

/* Rebote */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

.whatsapp-animation-bounce .whatsapp-character-container {
    animation: bounce 2s infinite;
}

/* Balanceo */
@keyframes swing {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(10deg); }
    40% { transform: rotate(-8deg); }
    60% { transform: rotate(6deg); }
    80% { transform: rotate(-4deg); }
}

.whatsapp-animation-swing .whatsapp-character-container {
    animation: swing 2.5s infinite;
    transform-origin: bottom center;
}

/* Desactivar animación al hover */
.whatsapp-animation-pulse .whatsapp-character-container:hover,
.whatsapp-animation-shake .whatsapp-character-container:hover,
.whatsapp-animation-bounce .whatsapp-character-container:hover,
.whatsapp-animation-swing .whatsapp-character-container:hover {
    animation: none;
}

/* Animación de entrada de burbuja */
@keyframes bubbleEntrance {
    0% {
        opacity: 0;
        visibility: hidden;
        transform: scale(0.3) translateY(20px);
    }
    50% {
        transform: scale(1.05) translateY(-5px);
    }
    100% {
        opacity: 1;
        visibility: visible;
        transform: scale(1) translateY(0);
    }
}

/* Animación de salida de burbuja */
@keyframes bubbleExit {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.8);
        visibility: hidden;
    }
}

/* Estilo simple - mantener compatibilidad con icono original */
.whatsapp-character-simple .whatsapp-character-container {
    width: var(--button-size, 60px);
    height: var(--button-size, 60px);
}

.whatsapp-character-simple .whatsapp-chat-button {
    background: linear-gradient(135deg, var(--whatsapp-green) 0%, var(--whatsapp-dark-green) 100%);
    border-radius: 50%;
    box-shadow: 0 4px 12px var(--shadow-color),
                0 2px 4px rgba(0, 0, 0, 0.1);
}

.whatsapp-character-simple .whatsapp-chat-button svg {
    width: 60%;
    height: 60%;
    color: #ffffff;
}

.whatsapp-character-simple .whatsapp-chat-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle, var(--whatsapp-light-green) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 50%;
}

.whatsapp-character-simple .whatsapp-chat-button:hover::before {
    opacity: 0.3;
}

/* Responsive */
@media screen and (max-width: 768px) {
    .whatsapp-chat-button-container {
        bottom: 15px;
        right: 15px;
    }

    .whatsapp-position-bottom-right,
    .whatsapp-position-top-right {
        right: 15px;
    }

    .whatsapp-position-bottom-left,
    .whatsapp-position-top-left {
        left: 15px;
    }

    .whatsapp-position-top-right,
    .whatsapp-position-top-left {
        top: 15px;
    }

    .whatsapp-speech-bubble {
        max-width: 220px;
        font-size: 13px;
        padding: 12px 16px;
    }
}

@media screen and (max-width: 480px) {
    .whatsapp-character-container {
        width: calc(var(--button-size, 60px) * 1.5);
        height: calc(var(--button-size, 60px) * 1.8);
    }

    .whatsapp-speech-bubble {
        max-width: 180px;
        min-width: 150px;
    }
}

/* Efecto de ondas al hacer clic */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

.whatsapp-chat-button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: 50%;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    pointer-events: none;
}

.whatsapp-chat-button:active::after {
    animation: ripple 0.6s ease-out;
}

/* Accesibilidad */
.whatsapp-chat-button:focus {
    outline: 3px solid var(--whatsapp-light-green);
    outline-offset: 3px;
    border-radius: 10px;
}

.whatsapp-chat-button:focus:not(:focus-visible) {
    outline: none;
}

/* Animación de aparición inicial del personaje */
@keyframes characterAppear {
    0% {
        opacity: 0;
        transform: translateY(100px) scale(0.3);
    }
    60% {
        transform: translateY(-10px) scale(1.1);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.whatsapp-character-container {
    animation: characterAppear 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Efecto hover especial para personajes */
.whatsapp-character-assistant .whatsapp-chat-button:hover .character-mouth,
.whatsapp-character-robot .whatsapp-chat-button:hover .character-mouth,
.whatsapp-character-scientist .whatsapp-chat-button:hover .character-mouth {
    stroke-width: 4;
    transition: stroke-width 0.3s ease;
}

/* Brillo en los ojos al hacer hover */
.whatsapp-chat-button:hover .character-eye {
    filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.8));
}

/* Tema oscuro */
@media (prefers-color-scheme: dark) {
    :root {
        --tooltip-bg: #2c2c2c;
        --tooltip-text: #ffffff;
    }

    .whatsapp-speech-bubble {
        border-color: var(--whatsapp-light-green);
    }
}

/* Ajustes finos para cada personaje */
.whatsapp-character-assistant .character-body {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.whatsapp-character-robot .character-body {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.whatsapp-character-scientist .character-body {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

/* Indicador de "está escribiendo" (puntos animados) */
@keyframes typingDots {
    0%, 20% { opacity: 0.2; }
    50% { opacity: 1; }
    100% { opacity: 0.2; }
}

.whatsapp-speech-bubble.typing::after {
    content: '...';
    position: absolute;
    bottom: 10px;
    right: 20px;
    font-size: 20px;
    animation: typingDots 1.4s infinite;
}
