/* Estilos adicionales para Chatbot branding */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

:root {
    --chatbot-orange: #FF6B35;
    --chatbot-dark-blue: #0F2340;
    --chatbot-navy: #1B365D;
    --chatbot-light-blue: #F5F5F5;
    --chatbot-gray: #718096;
    --chatbot-light-gray: #F7FAFC;
    --chatbot-white: #FFFFFF;
    --chatbot-black: #2D3748;
    --app-height: 100vh;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* === LAYOUT BASE - Mobile First === */
html {
    height: var(--app-height);
    height: 100dvh;
}

body {
    font-family: 'Poppins', sans-serif;
    height: var(--app-height);
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto; /* Permitir pull-to-refresh */
    display: flex;
    flex-direction: column;
}

/* Chat input container - desktop: fila, móvil: columna */
.chat-input-container {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Main ocupa espacio disponible */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Chat container */
main > .bg-white.rounded-xl,
.bg-white.rounded-xl.shadow-lg {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Mensajes: área scrollable */
#chatMessages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

/* Input area: siempre visible */
.border-t.bg-white {
    flex-shrink: 0 !important;
    padding-bottom: calc(1rem + var(--safe-bottom));
}

/* Botón enviar: nunca se comprime */
#sendButton {
    flex-shrink: 0;
    min-width: 48px;
    min-height: 48px;
}

/* Animaciones personalizadas */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.fade-in-up {
    animation: fadeInUp 0.5s ease-out;
}

.pulse-animation {
    animation: pulse 2s infinite;
}

/* Estilo para mensajes de chat */
.message-bubble {
    max-width: 80%;
    word-wrap: break-word;
}

.user-message {
    background: linear-gradient(135deg, var(--chatbot-orange), #FF8A65);
    color: white;
    margin-left: auto;
    margin-right: 0;
}

.bot-message {
    background: white;
    border: 1px solid #e5e7eb;
}

/* Efectos hover personalizados */
.hover-lift:hover {
    transform: translateY(-2px);
    transition: transform 0.2s ease-in-out;
}

/* Scrollbar personalizado para el chat */
#chatMessages::-webkit-scrollbar {
    width: 6px;
}

#chatMessages::-webkit-scrollbar-track {
    background: #f1f5f9;
}

#chatMessages::-webkit-scrollbar-thumb {
    background: var(--chatbot-orange);
    border-radius: 3px;
}

#chatMessages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-dark-blue);
}

/* Estilo para estado de escritura */
.typing-indicator {
    display: flex;
    align-items: center;
    space-x: 1;
}

.typing-dot {
    height: 8px;
    width: 8px;
    border-radius: 50%;
    background-color: #9ca3af;
    animation: pulse 1.4s infinite ease-in-out;
    margin: 0 2px;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

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

/* === RESPONSIVE MÓVIL === */
@media (max-width: 768px) {
    /* Header principal más compacto */
    header.chatbot-header .py-4 {
        padding: 0.5rem 0;
    }

    header.chatbot-header .w-12 {
        width: 2.5rem;
        height: 2.5rem;
    }

    header.chatbot-header h1 {
        font-size: 1.25rem;
    }

    /* Ocultar "Servicio 24/7" en móvil */
    header.chatbot-header .text-right {
        display: none;
    }

    /* Main: padding reducido */
    main.px-4 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    main.py-4 {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    /* Chat header interno más compacto */
    .chatbot-header.p-4 {
        padding: 0.75rem;
    }

    .chatbot-header .w-10 {
        width: 2rem;
        height: 2rem;
    }

    .chatbot-header h3 {
        font-size: 1rem;
    }

    .chatbot-header .text-sm {
        font-size: 0.75rem;
    }

    /* Mensajes */
    .message-bubble {
        max-width: 90%;
    }

    #chatMessages {
        padding: 0.75rem;
    }

    #chatMessages .flex.items-start.space-x-3 {
        margin-bottom: 0.5rem;
    }

    #chatMessages .text-xs.mt-2.block {
        margin-top: 0.25rem;
        margin-bottom: 0.25rem;
    }

    /* Input area - en móvil: columna */
    .chat-input-area {
        padding: 0.75rem;
        padding-bottom: calc(0.75rem + var(--safe-bottom));
    }

    .chat-input-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    #userInput {
        width: 100%;
        padding: 0.75rem;
        font-size: 1rem;
    }

    /* Botón: ancho completo debajo del input */
    #sendButton {
        width: 100%;
        padding: 0.75rem;
        min-height: 48px;
        justify-content: center;
    }

    #sendButton span {
        display: inline; /* Mostrar texto en móvil también */
    }

    /* Footer compacto */
    main > .py-3 {
        padding: 0.25rem 0;
    }

    main > .py-3 p {
        font-size: 0.6rem;
        margin: 0;
        line-height: 1.3;
    }

    /* Ocultar líneas extra del footer en móvil */
    main > .py-3 p:nth-child(2),
    main > .py-3 p:nth-child(3) {
        display: none;
    }
}

/* Pantallas muy pequeñas (< 380px) */
@media (max-width: 380px) {
    /* Ocultar header principal, solo mostrar chat */
    body > header.chatbot-header {
        display: none;
    }

    main {
        padding: 0.25rem;
    }

    .bg-white.rounded-xl {
        border-radius: 0.5rem;
    }

    /* Ocultar footer completamente */
    main > .py-3 {
        display: none;
    }
}

/* Efectos de foco mejorados */
input:focus, button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
}

/* Estilo para enlaces en mensajes */
.message-content a {
    color: var(--chatbot-orange);
    text-decoration: underline;
}

.message-content a:hover {
    color: var(--chatbot-dark-blue);
}

/* Gradiente de fondo Chatbot */
.chatbot-gradient {
    background: linear-gradient(135deg, var(--chatbot-light-blue) 0%, var(--chatbot-white) 100%);
}

.chatbot-header {
    background: linear-gradient(90deg, var(--chatbot-dark-blue) 0%, var(--chatbot-navy) 100%);
}

/* Botones Chatbot */
.btn-chatbot-primary {
    background: linear-gradient(135deg, var(--chatbot-orange) 0%, #FF8A65 100%);
    border: none;
    transition: all 0.3s ease;
}

.btn-chatbot-primary:hover {
    background: linear-gradient(135deg, #FF8A65 0%, var(--chatbot-orange) 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 107, 53, 0.3);
}

.btn-chatbot-secondary {
    background: transparent;
    border: 2px solid var(--chatbot-orange);
    color: var(--chatbot-orange);
    transition: all 0.3s ease;
}

.btn-chatbot-secondary:hover {
    background: var(--chatbot-orange);
    color: white;
}

/* Cursor de streaming para respuestas en tiempo real */
@keyframes blink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

.streaming-cursor::after {
    content: '▋';
    color: var(--chatbot-orange);
    animation: blink 1s infinite;
    margin-left: 2px;
}

.streaming-content {
    min-height: 1.5em;
}
