/* Botón flotante */
.chatbot-toggler {
    position: fixed;
    bottom: 30px;
    left: 35px;
    outline: none;
    border: none;
    height: 60px;
    width: 60px;
    display: flex;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--primary);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 8px 32px rgba(61, 141, 122, 0.3);
    z-index: 9999;
    animation: pulse 2s infinite;
}

.chatbot-toggler:hover {
    transform: scale(1.1) rotate(5deg);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(61, 141, 122, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(61, 141, 122, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(61, 141, 122, 0);
    }
}

.chatbot-toggler span {
    color: var(--white);
    position: absolute;
    font-size: 1.5rem;
}

.chatbot-toggler span:last-child,
body.show-chatbot .chatbot-toggler span:first-child {
    opacity: 0;
    transform: rotate(90deg);
}

body.show-chatbot .chatbot-toggler span:last-child {
    opacity: 1;
    transform: rotate(0);
}

/* Tooltip de engagement */
.chatbot-tooltip {
    position: fixed;
    bottom: 100px;
    left: 35px;
    background: white;
    padding: 10px 15px;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--primary);
    z-index: 9998;
    opacity: 0;
    transform: translateY(10px);
    animation: tooltipFadeIn 0.5s forwards 2s;
    /* Delay de 2s */
    pointer-events: none;
}

.chatbot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 20px;
    width: 12px;
    height: 12px;
    background: white;
    transform: rotate(45deg);
}

body.show-chatbot .chatbot-tooltip {
    opacity: 0;
    display: none;
}

@keyframes tooltipFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Ventana del chat (Glassmorphism) */
.chatbot {
    position: fixed;
    left: 35px;
    bottom: 100px;
    width: 380px;
    max-width: 90vw;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8) translateY(20px);
    transform-origin: bottom left;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9999;
}

body.show-chatbot .chatbot {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
}

.chatbot header {
    padding: 16px 20px;
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(61, 141, 122, 0.95);
    backdrop-filter: blur(5px);
    color: var(--white);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.header-icon {
    background: rgba(255, 255, 255, 0.2);
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.chatbot header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.chatbot header .close-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
}

.chatbot header .close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chatbot .chatbox {
    overflow-y: auto;
    height: 400px;
    padding: 20px 20px 80px;
}

/* Scrollbar Custom */
.chatbot .chatbox::-webkit-scrollbar {
    width: 6px;
}

.chatbot .chatbox::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot .chatbox::-webkit-scrollbar-thumb {
    background: rgba(136, 192, 180, 0.3);
    border-radius: 25px;
}

.chatbox .chat {
    display: flex;
    list-style: none;
    margin-bottom: 15px;
}

.chatbox .outgoing {
    justify-content: flex-end;
}

.chatbox .incoming span {
    width: 32px;
    height: 32px;
    color: var(--white);
    cursor: default;
    text-align: center;
    line-height: 32px;
    align-self: flex-end;
    background: var(--primary);
    border-radius: 12px 12px 0 12px;
    font-size: 1.1rem;
    margin-right: 10px;
    box-shadow: 0 4px 10px rgba(61, 141, 122, 0.2);
}

.chatbox .chat p {
    white-space: pre-wrap;
    padding: 12px 16px;
    border-radius: 12px 12px 12px 0;
    max-width: 80%;
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chatbox .outgoing p {
    border-radius: 12px 12px 0 12px;
    background: var(--primary);
    color: var(--white);
    box-shadow: 0 4px 15px rgba(61, 141, 122, 0.2);
}

.chatbox .incoming p {
    background: white;
    color: var(--black);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.chatbox .incoming p.error {
    color: #721c24;
    background: #f8d7da;
}

/* Typing Animation Dots */
.typing-animation {
    display: inline-flex;
    gap: 4px;
    padding: 5px 0;
}

.typing-animation .dot {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-animation .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-animation .dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Input Area */
.chatbot .chat-input {
    display: flex;
    gap: 5px;
    position: absolute;
    bottom: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 20px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.chat-input textarea {
    height: 45px;
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 25px;
    outline: none;
    resize: none;
    max-height: 100px;
    padding: 12px 15px;
    font-size: 0.95rem;
    font-family: inherit;
    background: white;
    transition: all 0.2s;
}

.chat-input textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(61, 141, 122, 0.1);
}

.chat-input span {
    align-self: flex-end;
    color: var(--primary);
    cursor: pointer;
    height: 45px;
    width: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    font-size: 1.5rem;
    border-radius: 50%;
    background: rgba(61, 141, 122, 0.1);
    transition: all 0.2s;
    margin-left: 5px;
}

.chat-input textarea:valid~span {
    visibility: visible;
}

.chat-input span:hover {
    background: var(--primary);
    color: white;
}

@media (max-width: 490px) {
    .chatbot-toggler {
        right: 20px;
        bottom: 20px;
        left: auto;
    }

    .chatbot-tooltip {
        left: auto;
        right: 20px;
        bottom: 90px;
    }

    .chatbot-tooltip::after {
        left: auto;
        right: 20px;
    }

    .chatbot {
        left: 0;
        bottom: 0;
        height: 100%;
        border-radius: 0;
        width: 100%;
        max-width: 100%;
    }

    .chatbot .chatbox {
        height: calc(100% - 130px);
    }
}

.chatbot-toggler:hover {
    transform: scale(1.1);
}

.chatbot-toggler span {
    color: var(--white);
    position: absolute;
}

.chatbot-toggler span:last-child,
body.show-chatbot .chatbot-toggler span:first-child {
    opacity: 0;
}

body.show-chatbot .chatbot-toggler span:last-child {
    opacity: 1;
}

/* Ventana del chat */
.chatbot {
    position: fixed;
    left: 35px;
    bottom: 90px;
    width: 350px;
    background: var(--white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
    transform-origin: bottom left;
    box-shadow: 0 0 128px 0 rgba(0, 0, 0, 0.1),
        0 32px 64px -48px rgba(0, 0, 0, 0.5);
    transition: all 0.1s ease;
    z-index: 9999;
}

body.show-chatbot .chatbot {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.chatbot header {
    padding: 16px 0;
    position: relative;
    text-align: center;
    color: var(--white);
    background: var(--primary);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.chatbot header h2 {
    font-size: 1.4rem;
    font-weight: 600;
}

.chatbot header span {
    position: absolute;
    right: 15px;
    top: 50%;
    display: none;
    cursor: pointer;
    transform: translateY(-50%);
}

.chatbot .chatbox {
    overflow-y: auto;
    height: 400px;
    padding: 30px 20px 100px;
}

.chatbot :where(.chatbox, textarea)::-webkit-scrollbar {
    width: 6px;
}

.chatbot :where(.chatbox, textarea)::-webkit-scrollbar-track {
    background: #fff;
    border-radius: 25px;
}

.chatbot :where(.chatbox, textarea)::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 25px;
}

.chatbox .chat {
    display: flex;
    list-style: none;
}

.chatbox .outgoing {
    margin: 20px 0;
    justify-content: flex-end;
}

.chatbox .incoming span {
    width: 32px;
    height: 32px;
    color: var(--white);
    cursor: default;
    text-align: center;
    line-height: 32px;
    align-self: flex-end;
    background: var(--primary);
    border-radius: 4px;
    margin: 0 10px 7px 0;
}

.chatbox .chat p {
    white-space: pre-wrap;
    padding: 12px 16px;
    border-radius: 10px 10px 0 10px;
    max-width: 75%;
    color: var(--white);
    font-size: 0.95rem;
    background: var(--primary);
}

.chatbox .outgoing p {
    border-radius: 10px 10px 0 10px;
}

.chatbox .incoming p {
    border-radius: 10px 10px 10px 0;
    color: var(--black);
    background: #f2f2f2;
}

.chatbot .chat-input {
    display: flex;
    gap: 5px;
    position: absolute;
    bottom: 0;
    width: 100%;
    background: #fff;
    padding: 3px 20px;
    border-top: 1px solid #ddd;
}

.chat-input textarea {
    height: 55px;
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    max-height: 180px;
    padding: 15px 15px 15px 0;
    font-size: 0.95rem;
    font-family: inherit;
}

.chat-input span {
    align-self: flex-end;
    color: var(--primary);
    cursor: pointer;
    height: 55px;
    display: flex;
    align-items: center;
    visibility: hidden;
    font-size: 1.35rem;
}

.chat-input textarea:valid~span {
    visibility: visible;
}

@media (max-width: 490px) {
    .chatbot-toggler {
        left: 20px;
        bottom: 20px;
    }

    .chatbot {
        left: 0;
        bottom: 0;
        height: 100%;
        border-radius: 0;
        width: 100%;
    }

    .chatbot .chatbox {
        height: 90%;
        padding: 25px 15px 100px;
    }

    .chatbot .chat-input {
        padding: 5px 15px;
    }

    .chatbot header span {
        display: block;
    }
}