/* Chatbot CSS - Completamente Responsive usando Tailwind CSS */

/* Prevenir scroll horizontal */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Contenedor principal del chat - sin desbordamiento */
.chat-main {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Chat log - prevenir contenido que se desborde */
#chat-log {
    overflow-x: hidden;
    /* Prefer breaking at word boundaries and avoid splitting words mid-word */
    word-wrap: normal; /* legacy */
    overflow-wrap: break-word;
    word-break: normal;
}

/* Mensajes del chat - asegurar que no se desborden */
#chat-log > div {
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: break-word; /* allow long words to wrap but prefer word boundaries */
}

/* Contenido de mensajes - controlar ancho */
#chat-log [class*="max-w-"] {
    max-width: 85%;
    word-wrap: normal;
    overflow-wrap: break-word;
    /* disable automatic hyphenation to avoid unexpected mid-word breaks */
    hyphens: none;
}

/* Prevenir URLs largas y texto sin espacios que causen desbordamiento */
#chat-log p, #chat-log div {
    word-wrap: normal;
    overflow-wrap: break-word; /* prefer wrapping at word boundaries */
    word-break: normal;        /* avoid breaking words in the middle */
    hyphens: none;            /* disable automatic hyphenation */
    max-width: 100%;
    box-sizing: border-box;
}

/* Asegurar que los enlaces largos se rompan */
#chat-log a {
    /* Allow long URLs to wrap but avoid aggressive mid-word breaks */
    word-break: normal;
    overflow-wrap: anywhere; /* better handling for very long URLs */
}

/* Auto-resize del textarea */
#user-input.auto-resize {
    height: auto;
}

/* Estados de conexión específicos */
.connection-status.online {
    background: rgb(168 85 247 / 0.3);
    color: rgb(221 214 254);
    border-color: rgb(168 85 247 / 0.5);
}

.connection-status.offline {
    background: rgb(239 68 68 / 0.3);
    color: rgb(254 202 202);
    border-color: rgb(239 68 68 / 0.5);
}

/* Animaciones específicas del chat */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Animación bounce (faltaba si no se compila Tailwind completo) */
@keyframes bounce {
    0%, 100% { transform: translateY(0); animation-timing-function: cubic-bezier(0.8,0,1,1); }
    50% { transform: translateY(-6px); animation-timing-function: cubic-bezier(0,0,0.2,1); }
}

.animate-bounce {
    animation: bounce 1s infinite;
}

/* Variante accesible: si usuario reduce movimiento, eliminar rebote */
@media (prefers-reduced-motion: reduce) {
    .animate-bounce { animation: none; }
}

/* Indicador de escritura personalizado */
    .typing-dots {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    height: 1rem;
}

.typing-dot {
    width: 0.45rem;
    height: 0.45rem;
    background: rgb(168 85 247);
    border-radius: 9999px;
    opacity: 0.6;
    animation: typingBlink 1s infinite ease-in-out;
    box-shadow: 0 0 4px rgba(168,85,247,0.7), 0 0 8px rgba(168,85,247,0.4);
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBlink {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-6px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .typing-dot { animation: none; opacity: 0.8; }
}

.message-fade-in {
    animation: fadeInUp 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Burbuja de usuario más oscura */
.user-bubble-dark {
    /* Lado derecho ahora más oscuro manteniendo transición suave */
    background: linear-gradient(135deg, #150a2b 0%, #241046 50%, #1a0f33 100%);
    filter: brightness(.93) saturate(.95) contrast(.98);
    box-shadow: 0 0 6px -1px rgba(50,25,95,0.55), 0 2px 10px -2px rgba(0,0,0,0.6);
}

@media (prefers-contrast: high) {
    .user-bubble-dark { filter: none; }
}


/* Scrollbar personalizado para todos los navegadores */
.chat-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgb(147 51 234) rgb(55 65 81);
}

/* Webkit scrollbar (Chrome, Safari, Edge) */
.chat-scroll::-webkit-scrollbar {
    width: 6px;
}

.chat-scroll::-webkit-scrollbar-track {
    background: rgb(55 65 81 / 0.5);
    border-radius: 3px;
}

.chat-scroll::-webkit-scrollbar-thumb {
    background: rgb(147 51 234);
    border-radius: 3px;
    transition: background 0.3s ease;
}

.chat-scroll::-webkit-scrollbar-thumb:hover {
    background: rgb(139 92 246);
}

/* Modal-like chat scrollbar (copiado desde index.html modal) */
/* Aplica a #chat-log: grosor aumentado, thumb translúcido y soporte para móviles */
html body #chat-log::-webkit-scrollbar {
    width: 30px; /* 50% más grueso para mejorar la usabilidad */
}
html body #chat-log::-webkit-scrollbar-track {
    background: transparent;
}
html body #chat-log::-webkit-scrollbar-thumb {
    background: rgba(196, 60, 150, 0.35);
    border-radius: 999px;
    border: 5px solid rgba(0,0,0,0.35);
}
/* Firefox */
html body #chat-log {
    scrollbar-width: auto;
    scrollbar-color: rgba(196, 60, 150, 0.35) transparent;
    -webkit-overflow-scrolling: touch; /* touch momentum scrolling */
    /* max-height: calc(100vh - 220px); limit height similar al modal */
}

/* Breakpoints responsive mejorados */

/* Extra Small devices (phones, 320px and up) */
@media (max-width: 480px) {
    .chat-main {
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height para móviles */
        border-radius: 0;
        border: none;
        max-width: none;
        max-height: none;
        margin: 0;
    }
    
    /* Ajustar padding del contenedor padre */
    .chat-main + * {
        padding: 0;
    }
    
    
    #user-input {
        font-size: 1.17rem; /* ~18.7px (antes ~14px-16px) */
        line-height: 1.45;
    }
    /* Mensajes (usuario y bot) */
    #chat-log p {
        font-size: 1.17rem;
        line-height: 1.5;
    }
}

/* También aplicar hasta 640px para cubrir rango sm:hidden base */
@media (min-width: 481px) and (max-width: 640px) {
    #user-input { font-size: 1.17rem; line-height: 1.45; }
    #chat-log p { font-size: 1.17rem; line-height: 1.5; }
}

/* Small devices (landscape phones, 481px and up) */
@media (min-width: 481px) and (max-width: 640px) {
    .chat-main {
        width: calc(100vw - 1rem);
        height: calc(100vh - 1rem);
        max-height: calc(100vh - 1rem);
        border-radius: 0.75rem;
    }
}

/* Medium devices (tablets, 641px and up) */
@media (min-width: 641px) and (max-width: 768px) {
    .chat-main {
        width: calc(100vw - 2rem);
        height: min(650px, calc(100vh - 2rem));
        max-height: calc(100vh - 2rem);
    }
}

/* Large devices (desktops, 769px and up) */
@media (min-width: 769px) {
    .chat-main {
        width: 100%;
        height: 700px;
        max-height: 90vh;
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 600px) {
    .chat-main {
        height: 100vh;
        max-height: 100vh;
    }
    
    .chat-header {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        min-height: 60px;
    }
    
    .chat-input-area {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }
}

/* Reducir animaciones para accesibilidad */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms;
        animation-iteration-count: 1;
        transition-duration: 0.01ms;
    }
    
    .message-fade-in {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chat-main {
        border-width: 2px;
        border-color: rgb(147 51 234);
    }
    
    .connection-status.online {
        background: rgb(34 197 94);
        color: rgb(255 255 255);
        border-color: rgb(34 197 94);
    }
}

/* Print styles */
@media print {
    .chat-main {
        width: 100%;
        height: auto;
        max-height: none;
        border: 1px solid #000;
        border-radius: 0;
        box-shadow: none;
    }
    
    .chat-input-area {
        display: none;
    }
}
