/* ============================================================ */
/* GESTITO - Mascota Animada Interactiva                        */
/* ============================================================ */

/* 1. Base Integration */
.gw-mascot {
    position: fixed;
    z-index: var(--gestito-z, 9999);
    cursor: pointer;
    width: 60px;
    height: auto;

    /* Master Transition: Handle all animatable properties smoothy */
    /* specialized timing function for "alive" feel */
    transition:
        transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.5s ease-out,
        top 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        left 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        right 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        bottom 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Default Float Animation (can be overridden by states) */
    animation: mascot-float 6s ease-in-out 4;
}

/* 2. Visual Parts */
.mascot-body {
    position: relative;
    width: 100%;
    /* Ensure body doesn't flip independently unless specified */
}

.mascot-body img {
    width: 100%;
    height: auto; /* la <img> lleva width/height explicitos (sept-2026): sin esto se deformaba */
    display: block;
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.2));
}

.mascot-eyes {
    position: absolute;
    top: 2px;
    left: 55%;
    transform: translateX(-50%);
    width: 30%;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    /* Let clicks pass through */
}

.eye {
    width: 6px;
    height: 8px;
    background: white;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    animation: mascot-blink 4s 5;
}

.pupil {
    width: 4px;
    height: 4px;
    background: #333;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 1px;
    transition: transform 0.1s ease-out;
    /* Fast tracking */
}

/* 3. Message Bubble */
.mascot-message {
    position: absolute;
    bottom: 110%;
    /* Slightly higher */
    right: 0;
    width: max-content;
    max-width: 260px;
    background: white;
    padding: 12px 18px;
    border-radius: 18px 18px 2px 18px;
    /* Chat bubble style */
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    font-size: 0.95rem;
    color: #333;
    opacity: 0;
    /* Entra sin girar y sin pasarse de tamaño: girado y con rebote ocupaba más que su caja final y, mientras
       entraba, se salía por el borde y se mezclaba con el texto (revisor de acabados, 20-11-2026) */
    transform: translateY(6px) scale(0.94);
    transform-origin: bottom right;
    transition: opacity 0.25s ease-out, transform 0.25s ease-out;
    pointer-events: none;
    font-weight: 600;
    line-height: 1.4;
    z-index: 10001;
}

/* Show message on hover or when class added */
.gw-mascot:hover .mascot-message,
.gw-mascot.showing-message .mascot-message {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
}

/* Asomado, Gestito gira y sale antes de hablar: el bocadillo espera a que haya salido. Girando, se salía
   por el borde (revisor de acabados, 20-11-2026). Al cerrarse, sin espera. */
.gw-mascot.pos-side-right-mid.showing-message .mascot-message,
.gw-mascot.pos-corner-peek-right.showing-message .mascot-message,
.gw-mascot.pos-corner-peek-left.showing-message .mascot-message {
    transition-delay: 0.6s;
}

/* Asomado a media altura a la derecha, el bocadillo quedaba pegado al borde (revisor de acabados, 20-11-2026) */
.gw-mascot.pos-side-right-mid .mascot-message {
    margin-right: 8px;
}

/* 4. Positions & Transforms */

/* --- Bottom Left --- */
.gw-mascot.pos-bottom-left {
    bottom: 30px;
    left: 30px;
    right: auto;
    top: auto;
}

/* Fix message text for standard orientation */
.gw-mascot.pos-bottom-left .mascot-message {
    right: auto;
    left: 80%;
    /* Push it slightly right of the mascot body */
    bottom: 100%;
    /* Above */
    border-radius: 18px 18px 18px 2px;
    transform: translateY(6px) scale(0.94);
    transform-origin: bottom left;
    min-width: 150px;
    /* Ensure it has width to grow right */
}

.gw-mascot.pos-bottom-left:hover .mascot-message,
.gw-mascot.pos-bottom-left.showing-message .mascot-message,
.gw-mascot.pos-bottom-left.attention .mascot-message {
    transform: translateY(0) scale(1) rotate(0deg);
}


/* --- Side Right Mid --- */
/* Peeking from the right side, rotated 90deg */
.gw-mascot.pos-side-right-mid {
    top: 50%;
    right: -15px;
    /* Slight peek */
    bottom: auto;
    left: auto;
    transform: translateY(-50%) rotate(-90deg);
}

.gw-mascot.pos-side-right-mid:hover,
.gw-mascot.pos-side-right-mid.attention {
    right: 10px;
    /* Slide out */
    transform: translateY(-50%) rotate(0deg);
    /* Rotate up */
}

/* --- Corner Peek Right --- */
/* Peeking from bottom right corner, rotated 45deg */
.gw-mascot.pos-corner-peek-right {
    bottom: -25px;
    right: -25px;
    transform: rotate(-45deg);
}

.gw-mascot.pos-corner-peek-right:hover,
.gw-mascot.pos-corner-peek-right.attention {
    bottom: 20px;
    right: 20px;
    transform: rotate(0deg);
}

/* --- Corner Peek Left --- */
/* Peeking from bottom left corner, NO FLIP */
.gw-mascot.pos-corner-peek-left {
    bottom: -25px;
    left: -25px;
    /* If not flipped, rotating 45deg makes head point right-down */
    /* We want head pointing right-up (standard peek) */
    transform: rotate(45deg);
}

.gw-mascot.pos-corner-peek-left .mascot-message {
    right: auto;
    left: 100%;
    /* Anchor to right of mascot */
    bottom: 100%;
    transform-origin: bottom left;
}

.gw-mascot.pos-corner-peek-left:hover,
.gw-mascot.pos-corner-peek-left.attention {
    bottom: 20px;
    left: 20px;
    transform: rotate(0deg);
}


/* --- Junto al botón del chat (gestiwia.com y b2bweb.es): a su izquierda --- */
.gw-mascot.pos-junto-chat {
    bottom: 18px;
    right: var(--gestito-derecha, 16px);
    top: auto;
    left: auto;
}

/* 5. States & Animations */

/* --- Hiding (The Exit Animation) --- */
.gw-mascot.hiding {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition:
        transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.5s ease-out,
        top 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        left 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        right 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        bottom 0.8s cubic-bezier(0.34, 1.56, 0.64, 1),
        visibility 0s linear 0.8s;
    /* We assume specific positions define their own hiding transform below */
}

/* Specific Hiding Transforms (Crucial for the "Rotation" request) */
.gw-mascot.pos-bottom-left.hiding {
    /* Dive down and rotate out (standard, no flip) */
    transform: translateY(150px) rotate(-45deg);
}

.gw-mascot.pos-side-right-mid.hiding {
    /* Retreat back right and rotate more */
    transform: translate(100px, -50%) rotate(-135deg);
}

.gw-mascot.pos-corner-peek-right.hiding {
    /* Retreat deeply into corner */
    transform: translate(80px, 80px) rotate(-90deg);
}

.gw-mascot.pos-corner-peek-left.hiding {
    /* Retreat deeply into corner (standard, no flip) */
    transform: translate(-80px, 80px) rotate(90deg);
}

.gw-mascot.pos-junto-chat.hiding {
    transform: translateY(150px);
}

/* --- Interactive States --- */

/* Dancing */
.gw-mascot.dancing .mascot-body {
    /* Los estados animan solo el cuerpo: animando toda la mascota, el bocadillo giraba y crecía con ella y se
       salía de la pantalla (lo dispara bajar deprisa; revisor de acabados, 20-11-2026). Igual los de abajo. */
    animation: mascot-dance-crazy 0.4s 10 alternate;
}

@keyframes mascot-dance-crazy {
    0% {
        transform: rotate(-15deg) scale(1.1) translateY(0);
    }

    100% {
        transform: rotate(15deg) scale(1.1) translateY(-10px);
    }
}

/* Dizzy */
.gw-mascot.dizzy .mascot-body {
    animation: mascot-dizzy-spin 0.5s linear 6;
}

@keyframes mascot-dizzy-spin {
    0% {
        transform: rotate(0deg) scale(1.2);
    }

    25% {
        transform: rotate(-10deg) scale(1.2) translateX(-5px);
    }

    75% {
        transform: rotate(10deg) scale(1.2) translateX(5px);
    }

    100% {
        transform: rotate(0deg) scale(1.2);
    }
}

/* Lightning Move (Link Click) */
/* Loading/Processing State (Replaces Lightning) */
.gw-mascot.loading {
    transition: top 0.5s ease-in-out, left 0.5s ease-in-out !important;
    z-index: 10000;
}

.gw-mascot.loading .mascot-body {
    animation: mascot-pulse 1s 8 alternate;
}

@keyframes mascot-pulse {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }

    100% {
        transform: scale(1.1);
        filter: brightness(1.2);
    }
}

.gw-mascot.loading .mascot-message {
    opacity: 1;
    transform: translateY(0) scale(1);
    background: #b90e2b;
    /* Blue for info/loading */
    color: white;
}

/* Angry/Saturated phase */
.gw-mascot.loading.angry .mascot-message {
    background: #F44336;
    /* Red for angry */
    transform: translateY(0) scale(1.1) rotate(-2deg);
    animation: mascot-shake-angry 0.3s 10;
}

@keyframes mascot-shake-angry {
    0% {
        transform: translateX(0) rotate(-2deg);
    }

    25% {
        transform: translateX(-2px) rotate(2deg);
    }

    50% {
        transform: translateX(0) rotate(-2deg);
    }

    75% {
        transform: translateX(2px) rotate(2deg);
    }

    100% {
        transform: translateX(0) rotate(-2deg);
    }
}

/* Tickled State */
.gw-mascot.tickled .mascot-body {
    animation: mascot-laugh 0.3s 10;
}

@keyframes mascot-laugh {
    0% {
        transform: scale(1.1) rotate(0deg);
    }

    25% {
        transform: scale(1.1) rotate(5deg);
    }

    50% {
        transform: scale(1.1) rotate(0deg);
    }

    75% {
        transform: scale(1.1) rotate(-5deg);
    }

    100% {
        transform: scale(1.1) rotate(0deg);
    }
}

/* Jumping */
.gw-mascot.jumping .mascot-body {
    animation: mascot-jump-high 0.6s ease-out;
}

@keyframes mascot-jump-high {
    0% {
        transform: scale(1, 0.9);
    }

    30% {
        transform: scale(0.9, 1.1) translateY(-50px);
    }

    50% {
        transform: scale(1, 1) translateY(-50px) rotate(180deg);
    }

    /* Flip! */
    100% {
        transform: scale(1, 1) translateY(0) rotate(360deg);
    }
}

/* 6. Standard Keyframes */
@keyframes mascot-float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes mascot-blink {

    0%,
    96%,
    100% {
        transform: scaleY(1);
    }

    98% {
        transform: scaleY(0.1);
    }
}

/* Adjust for scaleX(-1) positions */
/* If position applies a transform, animation needs to account for it, 
   OR we wrap animation on inner element. 
   Currently base "float" might conflict with position transform.
   FIX: Apply float to body instead of wrapper to separate concerns. */
.gw-mascot {
    animation: none;
    /* Move float to body */
}

.mascot-body {
    /* Flota cuatro veces al llegar y se queda quieta: sin fin, distraía de la lectura
       (MOV01, auditoría de acabados del 20-11-2026). Lo mismo el parpadeo y los estados. */
    animation: mascot-float 6s ease-in-out 4;
}

/* Con el pie a la vista se aparta (gestito.js, «junto-pie»): tapaba los enlaces legales y el
   copyright en las tres webs (ACA04, auditoría de acabados del 20-11-2026) */
.gw-mascot.apartado-bajando {
    opacity: 0 !important;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease-out, visibility 0s linear 0.2s;
}

.gw-mascot.junto-pie {
    opacity: 0 !important;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease-out, visibility 0s linear 0.3s;
}

/* Quien pide menos movimiento en su sistema la ve quieta (MOV01) */
@media (prefers-reduced-motion: reduce) {
    .gw-mascot,
    .gw-mascot * {
        animation: none !important;
        transition: none !important;
    }
}

/* Equipo lento (src/62-vigia.js de la biblioteca): Gestito sigue ahí y sigue hablando, pero quieto */
html.gw-lento .gw-mascot,
html.gw-lento .gw-mascot * {
    animation: none !important;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .gw-mascot {
        width: 50px;
        /* Por debajo del cajon del menu (2000), que si debe taparla. */
        z-index: var(--gestito-z, 1500);
    }

    .mascot-message {
        font-size: 0.8rem;
        padding: 8px 12px;
    }

    /* En movil la mascota va SIEMPRE a la esquina inferior derecha, sea cual sea
       la posicion que le toque al azar (gestito.js elige una de cuatro en cada
       carga). Las posiciones de escritorio la ponian a media altura y asomando
       fuera del viewport: tapaba el texto del cuerpo —incluidos subtitulos de
       cabecera y algun titular entero— y su margen negativo era el unico
       desbordamiento horizontal real de la web, que ensanchaba el viewport de
       390 a 397px y encogia toda la pagina. */
    .gw-mascot.pos-bottom-left,
    .gw-mascot.pos-side-right-mid,
    .gw-mascot.pos-corner-peek-right,
    .gw-mascot.pos-corner-peek-left,
    .gw-mascot.pos-bottom-left:hover,
    .gw-mascot.pos-bottom-left.attention,
    .gw-mascot.pos-side-right-mid:hover,
    .gw-mascot.pos-side-right-mid.attention,
    .gw-mascot.pos-corner-peek-right:hover,
    .gw-mascot.pos-corner-peek-right.attention,
    .gw-mascot.pos-corner-peek-left:hover,
    .gw-mascot.pos-corner-peek-left.attention,
    .gw-mascot.pos-junto-chat,
    .gw-mascot.pos-junto-chat:hover,
    .gw-mascot.pos-junto-chat.attention {
        top: auto;
        left: auto;
        bottom: 16px;
        right: var(--gestito-derecha, 16px);
        transform: none;
    }

    /* En el móvil, en la esquina de abajo a la derecha, se esconde hundiéndose: de lado salía por el borde y
       ensanchaba la página (en el ordenador, un fijo fuera de la pantalla no la desplaza: allí se asoma como
       siempre; revisor de acabados, 20-11-2026) */
    .gw-mascot.pos-bottom-left.hiding,
    .gw-mascot.pos-side-right-mid.hiding,
    .gw-mascot.pos-corner-peek-right.hiding,
    .gw-mascot.pos-corner-peek-left.hiding,
    .gw-mascot.pos-junto-chat.hiding {
        transform: translateY(120px);
    }

    /* El bocadillo, hacia dentro de la pantalla. Con las posiciones de escritorio delante
       (.pos-bottom-left lo manda a la derecha, left: 80%) ganaban por especificidad y el
       bocadillo se salía por la derecha (29-10-2026). */
    .gw-mascot .mascot-message,
    .gw-mascot.pos-bottom-left .mascot-message,
    .gw-mascot.pos-corner-peek-left .mascot-message {
        right: 100%;
        left: auto;
        bottom: 0;
        margin-right: 8px;
        /* lo que queda a la izquierda de Gestito (que se aparta del botón del chat), con 16 px de margen: con el
           60 % fijo se salía por la izquierda en gestiwia.com (revisor de acabados, 20-11-2026) */
        max-width: min(60vw, calc(100vw - var(--gestito-derecha, 16px) - 74px));
        border-radius: 18px 18px 2px 18px;
    }
}

/* Crying State - for abandoned visitors */
.gw-mascot.crying .mascot-body {
    animation: mascot-cry 0.5s ease-in-out 8;
}

@keyframes mascot-cry {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    25% {
        transform: translateY(3px) rotate(-2deg);
    }

    75% {
        transform: translateY(3px) rotate(2deg);
    }
}

@media print { .gw-mascot { display: none !important; } }
