/* Contenedor principal */
#chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    pointer-events: auto;
    will-change: transform;
    z-index: 99999;
}

/* Botón de chat - Estilo base */
#chat-button {
    width: 85px;
    height: 85px;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: none;
    padding: 0;
    outline: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Gradiente principal compartido */
:root {
    /* Variables de color */
    --color-primary-cian: #00ffdd;
    --color-primary-azul: #0099ff;
    --color-primary-morado: #9933ff;
    --color-primary-azul-oscuro: #305590;

    /* Gradientes con fallback */
    --gradient-primary-fallback: linear-gradient(135deg, var(--color-primary-cian), var(--color-primary-azul) 50%, var(--color-primary-morado));
    --gradient-active-fallback: linear-gradient(135deg, var(--color-primary-azul-oscuro), var(--color-primary-azul-oscuro) 50%, var(--color-primary-azul-oscuro));
    
    /* Variables modernas con fallback */
    --gradient-primary: var(--gradient-primary-fallback);
    --gradient-active: var(--gradient-active-fallback);
    --gradient-angle: 0deg;
}

/* Registro de propiedades personalizadas para navegadores modernos */
@supports (background: linear-gradient(var(--gradient-angle), red, blue)) {
    @property --gradient-angle {
        syntax: '<angle>';
        initial-value: 0deg;
        inherits: false;
    }
}

/* Animación del gradiente */
@keyframes rotateGradient {
    0% { transform: rotate(-90deg); }
    100% { transform: rotate(270deg); }
}

/* Transición unificada para todos los elementos que cambian de color */
.button-circle::before,
.button-circle::after,
.ai-text,
.button-text,
.ai-text::after,
.button-text::after {
    transition: all 0.5s ease-in-out;
}


/* Círculo del botón */
.button-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: rgb(247 247 255);
    box-shadow: 0px 1px 4px 0px rgb(0 0 0 / 40%);
}

/* Borde gradiente con rotación */
.button-circle::before {
    content: '';
    position: absolute;
    top: -7px;
    left: -7px;
    right: -7px;
    bottom: -7px;
    background: var(--gradient-primary);
    border-radius: 50%;
    z-index: -1;
    animation: rotateGradient 15s infinite linear;
    box-shadow: 0px 0px 10px 0px rgb(0 0 0 / 30%);
    transition: border-radius 0.3s ease-in-out;
    will-change: transform, border-radius;
}

/* Efecto hover para el borde */
#chat-button:hover .button-circle::before {
    border-radius: 40% !important;
}

/* Borde gradiente estado activo (capa superior con opacidad 0 inicialmente) */
.button-circle::after {
    content: '';
    position: absolute;
    top: -7px;
    left: -7px;
    right: -7px;
    bottom: -7px;
    background: var(--gradient-active);
    border-radius: 50%;
    z-index: -1;
    opacity: 0;
}

/* Contenido interno del botón */
.button-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
    margin-top: 5px;
}

/* Texto "AI" */
.ai-text {
    font-family: Arial, sans-serif;
    font-size: 24px;
    font-weight: bold;
    position: relative;
    z-index: 2;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0px;
    line-height: 1;
    background-image: linear-gradient(
        var(--gradient-angle),
        var(--color-primary-cian),
        var(--color-primary-azul) 30%,
        var(--color-primary-morado)
    );
    animation: rotate-gradient 15s linear infinite;
}

/* Texto del botón */
.button-text {
    font-family: Arial, sans-serif;
    font-size: 11px;
    font-weight: 500;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
    background-image: linear-gradient(
        var(--gradient-angle),
        var(--color-primary-cian),
        var(--color-primary-azul) 20%,
        var(--color-primary-morado)
    );
    animation: rotate-gradient 15s linear infinite;
}

/* Estrellas decorativas con rotación */
.gradient-container {
    position: absolute;
    width: 100%;
    height: 100%;
    animation: rotateGradient 15s infinite linear;
    transform: rotate(-90deg); /* Posición inicial en -90 grados */
    will-change: transform;
}

/* Animación para hacer desaparecer y aparecer las estrellas */
@keyframes fadeStarTransform {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    5% {
        opacity: 0;
        transform: scale(0.3);
    }
    15% {
        opacity: 1;
        transform: scale(1);
    }
    65% {
        opacity: 1;
        transform: scale(1);
    }
    75% {
        opacity: 0;
        transform: scale(0.3);
    }
    100% {
        opacity: 0;
        transform: scale(0.3);
    }
}

.sparkle {
    position: absolute;
    color: transparent;
    z-index: 1;
    animation: fadeStarTransform 15s infinite linear;
    will-change: transform, opacity;
}

.sparkle-1 {
    width: 8px;
    height: 8px;
    top: -7px; 
    left: -1px;
    color: var(--color-primary-azul);
    animation-delay: -1s;
}

.sparkle-2 {
    width: 16px;
    height: 16px;
    top: -18px; 
    left: 1px; 
    color: var(--color-primary-azul);
    animation-delay: -2s;
}

.sparkle-3 {
    width: 10px;
    height: 10px;
    top: -11px; 
    left: 12px;  
    color: var(--color-primary-azul);
    animation-delay: -3s;
}

/* Estado activo - Mantiene fondo blanco */
#chat-button.active .button-circle::before {
    animation: none !important;
    border-radius: 50% !important;
}

#chat-button.active .button-circle::after {
    opacity: 1;
}

#chat-button.active .ai-text,
#chat-button.active .button-text {
    animation: none;
}

/* Aplicamos técnica de múltiples capas con opacidad para los textos */
.ai-text, .button-text {
    position: relative;
}

.ai-text::after, .button-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: var(--gradient-active);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0;
    z-index: 1;
    transition: opacity 0.5s ease-in-out;
}

.button-text::after {
    content: attr(data-text);
}

#chat-button.active .ai-text::after,
#chat-button.active .button-text::after {
    opacity: 1;
}

/* Mantenemos los estilos para las estrellas */
#chat-button.active .sparkle,
#chat-button.active .sparkle-1,
#chat-button.active .sparkle-2,
#chat-button.active .sparkle-3 {
    color: var(--color-primary-azul-oscuro);
}

@keyframes rotate-gradient {
    0% {
        --gradient-angle: 0deg;
    }
    100% {
        --gradient-angle: 360deg;
    }
}

/* Aseguramos compatibilidad con navegadores que no soportan @property */
@supports not (background: linear-gradient(var(--gradient-angle), red, blue)) {
    .ai-text{
        background-image: linear-gradient(
            45deg,
            var(--color-primary-cian),
            var(--color-primary-azul) 30%,
            var(--color-primary-morado)
        );
    }
    .button-text {
        background-image: linear-gradient(
            45deg,
            var(--color-primary-cian),
            var(--color-primary-azul) 20%,
            var(--color-primary-morado)
        );
    }
}

/* Contenedor del iframe */
#chat-iframe-container {
    display: none;
    width: 420px;
    height: calc(100vh - 220px);
    max-height: 600px;
    min-height: 400px;
    margin-bottom: 16px;
    pointer-events: auto;
    position: absolute;
    bottom: 100%;
    right: 0;
    transform-origin: bottom right;
}

#chat-iframe-container iframe {
    width: 100%;
    height: 100%;
    border: 1px solid #ccc;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    background: white;
}

/* Estilos responsive */
/* Pantallas extra pequeñas (móviles en vertical) */
@media (max-width: 480px) {
    #chat-iframe-container {
        width: 90vw;
        height: calc(100vh - 180px);
        max-height: 80vh;
        min-height: 400px;
        right: 0;
        margin-bottom: 14px;
    }

    #chat-container {
        right: 5vw;
        bottom: 16px;
    }

    /* Ocultar botón cuando el chat está activo en móvil */
    #chat-button.active {
        display: none;
    }
}

/* Tablets en vertical y móviles grandes en horizontal */
@media (min-width: 481px) and (max-width: 768px) {
    #chat-iframe-container {
        width: 380px;
        height: calc(100vh - 200px);
        max-height: 700px;
        min-height: 450px;
        right: 0;
    }

    #chat-container {
        right: 20px;
        bottom: 20px;
    }

    /* Ocultar botón cuando el chat está activo en móvil */
    #chat-button.active {
        display: none;
    }
}

/* Tablets en horizontal y laptops pequeñas */
@media (min-width: 769px) and (max-width: 1024px) {
    #chat-iframe-container {
        width: 400px;
        height: calc(100vh - 220px);
        max-height: 700px;
        min-height: 500px;
    }
}

/* Laptops y pantallas de escritorio */
@media (min-width: 1025px) {
    #chat-iframe-container {
        width: 420px;
        height: calc(100vh - 220px);
        max-height: 600px;
        min-height: 400px;
    }
}

/* Pantallas extra grandes */
@media (min-width: 1201px) {
    #chat-iframe-container {
        width: 450px;
        height: calc(100vh - 200px);
        max-height: 700px;
        min-height: 450px;
    }
}

/* Orientación del dispositivo */
@media (orientation: landscape) and (max-height: 600px) {
    #chat-iframe-container {
        height: calc(100vh - 100px);
        min-height: 300px;
        margin-bottom: 10px;
    }

    #chat-button {
        width: 70px;
        height: 70px;
    }

    .button-circle {
        width: 60px;
        height: 60px;
    }
}

/* Soporte para pantallas de alta densidad */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .button-circle {
        box-shadow: 0px 1px 6px 0px rgba(0, 0, 0, 0.2);
    }
    
    #chat-iframe-container {
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
}

/* Preferencias de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
    .button-circle::before,
    .gradient-container,
    .sparkle,
    .slide-in,
    .slide-out {
        animation: none !important;
        transition: opacity 0.3s ease-in-out !important;
    }

    .chat-tooltip {
        transition: opacity 0.3s ease-in-out !important;
    }
}

/* Soporte para pantallas ultra-wide */
@media (min-width: 1921px) {
    #chat-iframe-container {
        width: 500px;
        max-height: 800px;
        margin-bottom: 20px;
    }

    #chat-button {
        width: 95px;
        height: 95px;
    }

    .button-circle {
        width: 80px;
        height: 80px;
    }

    .ai-text {
        font-size: 28px;
    }

    .button-text {
        font-size: 13px;
    }
}

/* Animaciones */
@keyframes slideIn {
    from { 
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideOut {
    from { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to { 
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

.slide-in {
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    display: block !important;
}

.slide-out {
    animation: slideOut 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Estilos para el mensaje emergente */
.chat-tooltip {
    background-color: #fffdf9;
    color: #305590;
    box-shadow: rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px;
    border-radius: 10px;
    padding: 15px;
    font-size: 14px;
    font-family: Arial, sans-serif;
    position: absolute;
    bottom: 100%;
    right: 0;
    width: max-content;
    max-width: 240px;
    opacity: 0;
    transform: scale(0.8) translateY(10px);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    margin-bottom: 26px;
    text-align: center;
    cursor: default;
    transform-origin: bottom right;
}

/* Flecha del tooltip */
.chat-tooltip::after {
    content: "";
    position: absolute;
    bottom: -10px;
    right: 32px;
    width: 20px;
    height: 20px;
    background-color: #fffdf9;
    transform: rotate(45deg);
    box-shadow: rgba(150, 150, 150, 0.1) 1px 1px 0px 0px;
    z-index: -1;
}

/* Clase para mostrar el tooltip */
.chat-tooltip.show {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
    cursor: pointer;
}

/* Ocultamos el tooltip cuando el chat está abierto */
#chat-button.active + .chat-tooltip {
    display: none;
}

/* Cuando el tooltip está visible */
.chat-tooltip.show ~ #chat-button .button-circle::before {
    border-radius: 40%;
}

/* Aseguramos que el border-radius vuelva a 50% cuando el tooltip no está visible */
.chat-tooltip:not(.show) ~ #chat-button .button-circle::before {
    border-radius: 50%;
}

/* Ajuste para los SVGs reutilizables */
.sparkle svg {
    width: 100%;
    height: 100%;
} 