#teapin-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

#teapin-button img {
    width: 80px;
    cursor: pointer;
    filter: drop-shadow(0px 0px 8px rgba(0,0,0,0.4));
    transition: transform 0.2s ease-in-out;
}

#teapin-button img:hover {
    transform: scale(1.05);
}

/* Responsive para móviles */
@media (max-width: 768px) {
    #teapin-button {
        bottom: 15px;
        right: 15px;
    }
    
    #teapin-button img {
        width: 70px;
    }
}

@media (max-width: 480px) {
    #teapin-button {
        bottom: 10px;
        right: 10px;
    }
    
    #teapin-button img {
        width: 65px;
    }
}

/* ===== ANIMACIONES PARA TEAPIN ===== */
.teapin-floating {
    animation: teapin-float 4s ease-in-out infinite !important;
}

.teapin-typing {
    animation: teapin-type 1.5s ease-in-out infinite !important;
}

.teapin-greet {
    animation: teapin-greet 2s ease-out !important;
}

.teapin-notify {
    animation: teapin-notify 0.8s ease-in-out 3 !important;
}

.teapin-error {
    animation: teapin-error 0.5s ease-in-out !important;
}

/* Animación principal de flotación suave */
@keyframes teapin-float {
    0%, 100% { 
        transform: translateY(0) scale(1) rotate(0deg);
    }
    33% { 
        transform: translateY(-8px) scale(1.05) rotate(2deg);
    }
    66% { 
        transform: translateY(-4px) scale(1.02) rotate(-1deg);
    }
}

/* Animación cuando está escribiendo */
@keyframes teapin-type {
    0%, 100% { 
        transform: scale(1) rotate(0deg);
    }
    25% { 
        transform: scale(1.1) rotate(5deg);
    }
    75% { 
        transform: scale(1.1) rotate(-5deg);
    }
}

/* Animación de saludo al abrir el chat */
@keyframes teapin-greet {
    0% { 
        transform: scale(0.8) rotate(-20deg);
        opacity: 0.7;
    }
    50% { 
        transform: scale(1.2) rotate(10deg);
    }
    100% { 
        transform: scale(1) rotate(0deg);
    }
}

/* Animación de notificación para nuevos mensajes */
@keyframes teapin-notify {
    0%, 100% { 
        transform: scale(1);
        filter: brightness(1) drop-shadow(0px 0px 8px rgba(0,0,0,0.4));
    }
    50% { 
        transform: scale(1.15);
        filter: brightness(1.3) drop-shadow(0px 0px 12px rgba(255, 204, 51, 0.6));
    }
}

/* Animación cuando hay error */
@keyframes teapin-error {
    0%, 100% { 
        transform: translateX(0);
    }
    25% { 
        transform: translateX(-5px);
    }
    75% { 
        transform: translateX(5px);
    }
}

/* Efecto hover mejorado para Teapin */
#teapin-button:hover img {
    animation: teapin-hover 0.5s ease-in-out !important;
}

@keyframes teapin-hover {
    0%, 100% { 
        transform: scale(1.05) rotate(0deg);
    }
    50% { 
        transform: scale(1.1) rotate(3deg);
    }
}

/* ---------------------------------------------------- */
/* VENTANA DEL CHAT - COMPLETAMENTE RESPONSIVA */
/* ---------------------------------------------------- */

#teapin-window {
    /* Tamaño base para desktop */
    width: 380px;
    height: 500px;
    max-width: 90vw;
    max-height: 70vh;
    
    position: fixed;
    bottom: 110px;
    right: 20px;
    background: white;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.35);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    
    /* Animaciones */
    opacity: 1;
    visibility: visible;
    transform: scale(1);
    transition: opacity 0.3s ease-out, transform 0.3s ease-out, visibility 0.3s;
    transform-origin: bottom right;
}

/* Tablets */
@media (max-width: 1024px) {
    #teapin-window {
        width: 360px;
        height: 480px;
        right: 15px;
        bottom: 100px;
    }
}

/* Móviles grandes */
@media (max-width: 768px) {
    #teapin-window {
        width: calc(100vw - 40px);
        height: 65vh;
        right: 20px;
        left: 20px;
        bottom: 90px;
        transform-origin: bottom center;
    }
}

/* Móviles pequeños */
@media (max-width: 480px) {
    #teapin-window {
        width: calc(100vw - 30px);
        height: 70vh;
        right: 15px;
        left: 15px;
        bottom: 80px;
        border-radius: 16px;
    }
}

/* Pantallas muy pequeñas */
@media (max-width: 360px) {
    #teapin-window {
        width: calc(100vw - 20px);
        height: 75vh;
        right: 10px;
        left: 10px;
        bottom: 75px;
        border-radius: 14px;
    }
}

/* CLASE OCULTA */
.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    transform: scale(0.9) !important;
}

/* ---------------------------------------------------- */
/* HEADER RESPONSIVO */
/* ---------------------------------------------------- */

.teapin-header {
    background: linear-gradient(90deg, #ffcc33, #f9d71c);
    color: #333;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.teapin-header span {
    font-weight: bold;
    margin-left: 8px;
    font-size: 1.1rem;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.teapin-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    text-align: center;
    line-height: 36px;
    font-size: 20px;
    background: #fff;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#teapin-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #333;
    line-height: 1;
    transition: color 0.2s;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#teapin-close:hover {
    color: #555;
}

/* Responsive header */
@media (max-width: 480px) {
    .teapin-header {
        padding: 14px 16px;
    }
    
    .teapin-header span {
        font-size: 1rem;
    }
    
    .teapin-avatar {
        width: 32px;
        height: 32px;
        line-height: 32px;
        font-size: 18px;
    }
    
    #teapin-close {
        font-size: 20px;
    }
}

/* ---------------------------------------------------- */
/* MENSAJES - MEJOR TIPOGRAFÍA Y RESPONSIVIDAD */
/* ---------------------------------------------------- */

.teapin-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: #f5f5f5;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Scrollbar personalizado */
.teapin-messages::-webkit-scrollbar {
    width: 6px;
}

.teapin-messages::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}

/* ----------------------------- */
/* ANIMACIÓN DE ENTRADA DE MENSAJES */
/* ----------------------------- */

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

.msg {
    max-width: 85%;
    padding: 14px 18px;
    margin: 8px 0;
    border-radius: 18px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease-out;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msg.user {
    background-color: #33aaff;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.msg.bot {
    background-color: #ffffff;
    color: #333;
    margin-right: auto;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Mejorar legibilidad del texto del bot */
.msg.bot strong {
    font-weight: 600;
    color: #222;
}

.msg.bot em {
    font-style: italic;
    color: #555;
}

.msg.bot ul, .msg.bot ol {
    margin: 8px 0;
    padding-left: 20px;
}

.msg.bot li {
    margin: 4px 0;
    line-height: 1.4;
}

.msg.bot p {
    margin: 8px 0;
    line-height: 1.5;
}

.msg.bot p:first-child {
    margin-top: 0;
}

.msg.bot p:last-child {
    margin-bottom: 0;
}

/* Responsive para mensajes */
@media (max-width: 768px) {
    .teapin-messages {
        padding: 14px;
    }
    
    .msg {
        max-width: 90%;
        padding: 12px 16px;
        font-size: 14px;
        line-height: 1.5;
    }
}

@media (max-width: 480px) {
    .teapin-messages {
        padding: 12px;
    }
    
    .msg {
        max-width: 92%;
        padding: 11px 14px;
        font-size: 14px;
        line-height: 1.5;
    }
}

/* ----------------------------- */
/* ANIMACIÓN "ESCRIBIENDO..." */
/* ----------------------------- */

@keyframes writingDots {
    0% { content: "."; }
    33% { content: ".."; }
    66% { content: "..."; }
    100% { content: "."; }
}

.msg.bot[data-content="Escribiendo..."] {
    font-style: italic;
    color: #777;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.msg.bot[data-content="Escribiendo..."]::after {
    content: " .";
    animation: writingDots 1.5s infinite linear;
}

/* ---------------------------------------------------- */
/* ÁREA DE INPUT RESPONSIVA */
/* ---------------------------------------------------- */

.teapin-input-area {
    display: flex;
    padding: 16px;
    border-top: 1px solid #ddd;
    background: #ffffff;
    gap: 10px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#teapin-text {
    flex-grow: 1;
    padding: 14px 18px;
    border: 1px solid #ccc;
    border-radius: 20px;
    margin-right: 0;
    outline: none;
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.4;
}

#teapin-text:focus {
    border-color: #f9d71c;
    box-shadow: 0 0 5px rgba(249, 215, 28, 0.5);
}

#teapin-send {
    background-color: #ffcc33;
    color: #333;
    border: none;
    border-radius: 50%;
    width: 46px;
    height: 46px;
    cursor: pointer;
    font-size: 20px;
    line-height: 46px;
    text-align: center;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#teapin-send:hover {
    background-color: #ffde66;
}

#teapin-send:active {
    transform: scale(0.9);
}

/* Responsive input area */
@media (max-width: 768px) {
    .teapin-input-area {
        padding: 14px;
        gap: 8px;
    }
    
    #teapin-text {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    #teapin-send {
        width: 44px;
        height: 44px;
        line-height: 44px;
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .teapin-input-area {
        padding: 12px;
        gap: 6px;
    }
    
    #teapin-text {
        padding: 11px 14px;
        font-size: 14px;
    }
    
    #teapin-send {
        width: 42px;
        height: 42px;
        line-height: 42px;
        font-size: 18px;
    }
}

/* ---------------------------------------------------- */
/* ANIMACIONES ADICIONALES PARA MEJOR EXPERIENCIA */
/* ---------------------------------------------------- */

/* Efecto sutil cuando el input está enfocado */
#teapin-text:focus ~ #teapin-send {
    background-color: #ffde66;
    transform: scale(1.05);
}

/* Transición suave para todos los estados de Teapin */
#teapin-button img {
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Estado de atención cuando el chat está cerrado pero hay actividad */
.teapin-attention {
    animation: teapin-attention 2s ease-in-out infinite !important;
}

@keyframes teapin-attention {
    0%, 100% { 
        transform: scale(1);
        filter: drop-shadow(0px 0px 8px rgba(0,0,0,0.4));
    }
    50% { 
        transform: scale(1.1);
        filter: drop-shadow(0px 0px 15px rgba(255, 204, 51, 0.8));
    }
}

/* Soporte para reduced motion */
@media (prefers-reduced-motion: reduce) {
    .teapin-floating,
    .teapin-typing,
    .teapin-greet,
    .teapin-notify,
    .teapin-error,
    #teapin-button:hover img {
        animation: none !important;
    }
    
    .msg {
        animation-duration: 0.1s;
    }
    
    #teapin-window {
        transition: opacity 0.3s ease, visibility 0.3s;
    }
}

/* Estilos para mensajes formateados */
.msg.bot .msg-content {
    line-height: 1.5;
}

.message-item {
    padding: 4px 0;
    margin: 2px 0;
    border-left: 3px solid #ffcc33;
    padding-left: 12px;
    margin-left: 8px;
}

.msg.bot strong {
    color: #333;
    font-weight: 600;
}

/* Mejorar legibilidad de listas */
.msg.bot br + br {
    content: "";
    display: block;
    margin: 8px 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, #e0e0e0, transparent);
}


/* ANEXOS */

/* Indicador de escritura */
.typing-indicator .typing-dots {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing-bounce 1.4s ease-in-out infinite both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mejoras para mensajes formateados */
.message-item {
    padding: 4px 0 4px 16px;
    margin: 2px 0;
    position: relative;
    line-height: 1.4;
}

.message-item:before {
    content: "•";
    color: #ffcc33;
    position: absolute;
    left: 0;
    font-weight: bold;
}

.message-link {
    color: #007bff;
    text-decoration: underline;
    word-break: break-all;
}

.message-link:hover {
    color: #0056b3;
}

/* Mejorar legibilidad de los mensajes del bot */
.msg.bot .msg-content {
    line-height: 1.5;
}

.msg.bot strong {
    color: #333;
    font-weight: 600;
}

/* Separadores entre mensajes */
.msg + .msg {
    margin-top: 4px;
}

/* Efectos de hover en mensajes */
.msg:hover {
    transform: translateX(2px);
    transition: transform 0.2s ease;
}

/* Mejorar scrollbar */
.teapin-messages::-webkit-scrollbar {
    width: 6px;
}

.teapin-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.teapin-messages::-webkit-scrollbar-thumb {
    background: #ffcc33;
    border-radius: 3px;
}

.teapin-messages::-webkit-scrollbar-thumb:hover {
    background: #f9d71c;
}



/* =============================== */
/* MENSAJE FLOTANTE DE TEAPIN */
/* =============================== */

#teapin-floating-msg {
    position: fixed;
    bottom: 160px; /* MÁS ARRIBA para no tapar el botón */
    right: 30px;   /* más cerca del botón pero sin bloquearlo */

    background: #ffcc33; /* Fondo amarillo */
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 16px;
    color: #333;
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);

    opacity: 0;
    transform: translateY(10px);
    pointer-events: none; /* 🔥 NO BLOQUEA CLICS */
    z-index: 9999;

    transition: opacity 0.4s ease, transform 0.4s ease;
    font-family: 'Segoe UI', Tahoma, sans-serif;
}

#teapin-floating-msg.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Móviles */
@media (max-width: 768px) {
    #teapin-floating-msg {
        bottom: 150px;
        right: 20px;
        font-size: 14px;
        padding: 10px 14px;
        pointer-events: none;
    }
}



/* ===== ESPACIADO DE MENSAJES ===== */
.msg-content {
    line-height: 1.7;
    font-size: 14px;
    color: #1f2937;
    word-wrap: break-word;
}

/* Separación visual entre párrafos (cada <br> genera espacio) */
.msg-content br {
    display: block;
    content: "";
    margin-bottom: 2px;
}

/* Negritas del bot */
.msg-content strong {
    color: #111827;
    font-weight: 700;
}

/* Cursivas */
.msg-content em {
    color: #6b7280;
    font-style: italic;
}

/* Enlaces */
.msg-content a.message-link {
    color: #2563eb;
    text-decoration: underline;
    word-break: break-all;
}

/* ===== MENSAJE FLOTANTE ===== */
#teapin-floating-msg {
    position: fixed;
    bottom: 100px;
    right: 20px;
    background: #ffffff;
    color: #1f2937;
    padding: 12px 18px;
    border-radius: 16px;
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    border: 2px solid #fbbf24;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 999999;
    pointer-events: none;
    max-width: 220px;
    line-height: 1.5;
}

#teapin-floating-msg.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

#teapin-floating-msg small {
    color: #6b7280;
    font-size: 12px;
}

/* ===== SCROLL SUAVE ===== */
#teapin-messages {
    scroll-behavior: smooth;
}