/**
 * Estilos para el chat en modo Modal - Braves Chat iA
 * Version: 1.0.0
 * @package BravesChat
 * CORREGIDO: Display del chat window
 */

/* ============================================
   ISOLATION LAYER - THEME PROTECTION
   ============================================ */
/* Comprehensive reset for BravesChat container to prevent theme CSS bleeding */
body #braveslab-chat-container,
body #braveslab-chat-container *,
body #braveslab-chat-container *::before,
body #braveslab-chat-container *::after {
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    line-height: normal;
    letter-spacing: normal;
    text-transform: none;
    font-style: normal;
    font-variant: normal;
}

/* Reset all text elements */
body #braveslab-chat-container h1,
body #braveslab-chat-container h2,
body #braveslab-chat-container h3,
body #braveslab-chat-container h4,
body #braveslab-chat-container h5,
body #braveslab-chat-container h6,
body #braveslab-chat-container p,
body #braveslab-chat-container span,
body #braveslab-chat-container div {
    font-family: inherit;
    margin: 0;
    padding: 0;
    font-weight: normal;
    line-height: inherit;
}

/* Complete button reset to override ALL theme styles */
body #braveslab-chat-container button,
body #braveslab-chat-container input[type="button"],
body #braveslab-chat-container input[type="submit"] {
    all: unset;
    box-sizing: border-box;
    font-family: inherit;
    cursor: pointer;
    display: inline-block;
    text-align: center;
    vertical-align: middle;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Complete input/textarea reset */
body #braveslab-chat-container input,
body #braveslab-chat-container textarea {
    all: unset;
    box-sizing: border-box;
    font-family: inherit;
    display: block;
    width: auto;
}

/* Reset container y contenedor principal */
.braveslab-chat-widget-container {
    position: relative;
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Posiciones del chat */
.braveslab-chat-widget-container.position-bottom-right #braveslab-chat-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
}

.braveslab-chat-widget-container.position-bottom-left #braveslab-chat-container {
    position: fixed;
    bottom: 30px;
    left: 30px;
}

.braveslab-chat-widget-container.position-center #braveslab-chat-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    margin: 0;
}

/* Fix para centrar la ventana del chat cuando la burbuja está en el centro */
.braveslab-chat-widget-container.position-center #braveslab-chat-container #chat-window {
    left: 50%;
    right: auto;
    margin-left: -190px;
    /* Mitad de 380px */
}

/* Fix para centrar la ventana expandida */
.braveslab-chat-widget-container.position-center #braveslab-chat-container.braves-expanded #chat-window {
    margin-left: -300px;
    /* Mitad de 600px */
}

/* Contenedor principal del chat */
body #braveslab-chat-container {
    z-index: 999999;
    font-family: 'Montserrat', 'Segoe UI', Roboto, sans-serif;
}

/* ============================================
   BOTÓN DE TOGGLE (BURBUJA)
   ============================================ */
/* NOTA: Estos estilos NO se aplican al skin Braves, que tiene su propio diseño */
body #braveslab-chat-container:not(.braves-skin-braves) #chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    min-width: 60px;
    min-height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #01B7AF 0%, #5DD5C7 100%);
    background-color: #01B7AF;
    border: none;
    border-width: 0;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(1, 183, 175, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: white;
    font-size: 24px;
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: normal;
    outline: none;
    pointer-events: auto;
    z-index: 999999;
    padding: 0;
    margin: 0;
    overflow: hidden;
    line-height: 1;
    text-decoration: none;
    text-transform: none;
    letter-spacing: normal;
}

body #braveslab-chat-container:not(.braves-skin-braves) #chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(1, 183, 175, 0.6);
}

/* ============================================
   LOTTIE ANIMATION - ESTADO CERRADO
   ============================================ */
body #braveslab-chat-container.chat-closed:not(.braves-skin-braves) #chat-toggle #chat-lottie {
    display: block;
    width: 40px;
    height: 40px;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

body #braveslab-chat-container.chat-closed:not(.braves-skin-braves) #chat-toggle #chat-lottie svg {
    width: 270%;
    height: 100%;
    transform: translate3d(-10px, 0px, 0px);
}

/* ============================================
   ICONO X - ESTADO ABIERTO
   ============================================ */
body #braveslab-chat-container.chat-closed:not(.braves-skin-braves) #chat-toggle #close-icon {
    display: none !important;
}

body #braveslab-chat-container.chat-open:not(.braves-skin-braves) #chat-toggle #chat-lottie {
    display: none !important;
}

body #braveslab-chat-container.chat-open:not(.braves-skin-braves) #chat-toggle #close-icon {
    display: block !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 28px;
    font-weight: 300;
    line-height: 1;
    color: white;
}

/* ============================================
   VENTANA DE CHAT - CORREGIDO ⭐
   ============================================ */
body #braveslab-chat-container #chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(10, 10, 10, 0.15);
    display: flex;
    /* CAMBIADO: Era display: none */
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    /* NUEVO: Usamos opacity en vez de display */
    visibility: hidden;
    /* NUEVO: Ocultamos con visibility */
    transform: translateY(20px);
    /* NUEVO: Animación inicial */
    transition: width 0.3s ease, height 0.3s ease, opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    /* ACTUALIZADO: Añadida transición de width y height para contracción suave */
    pointer-events: none;
    /* NUEVO: Evita clicks cuando está oculto */
}

/* Fix posición bottom-left */
.braveslab-chat-widget-container.position-bottom-left #braveslab-chat-container #chat-window {
    right: auto;
    left: 0;
}

/* Estado ABIERTO - NUEVO ⭐ */
body #braveslab-chat-container.chat-open #chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* Estado EXPANDIDO - NUEVO ⭐ */
body #braveslab-chat-container.braves-expanded #chat-window {
    width: 600px;
    height: 776px;
    transition: width 0.3s ease, height 0.3s ease, opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

/* Estado CERRADO - NUEVO ⭐ */
body #braveslab-chat-container.chat-closed #chat-window {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    pointer-events: none;
}

/* Animación de entrada (mantener por compatibilidad) */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header del chat */
body #braveslab-chat-container #chat-header {
    background: #141414;
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

body #braveslab-chat-container #chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
}

body #braveslab-chat-container #chat-header p {
    margin: 5px 0 0 0;
    font-size: 13px;
    opacity: 0.9;
    color: white;
}

body #braveslab-chat-container #close-chat {
    background: none;
    background-color: transparent;
    border: none;
    border-width: 0;
    color: white;
    font-size: 28px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    line-height: 1;
    padding: 0;
    margin: 0;
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 300;
    text-decoration: none;
    text-transform: none;
}

body #braveslab-chat-container #close-chat:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Área de mensajes */
body #braveslab-chat-container #chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #F8FCFC;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

body #braveslab-chat-container #chat-messages::-webkit-scrollbar {
    width: 6px;
}

body #braveslab-chat-container #chat-messages::-webkit-scrollbar-thumb {
    background: #CEF2EF;
    border-radius: 3px;
}

body #braveslab-chat-container #chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

/* Mensajes */
body #braveslab-chat-container .message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body #braveslab-chat-container .message.user {
    align-self: flex-end;
    align-items: flex-end;
}

body #braveslab-chat-container .message.bot {
    align-self: flex-start;
    align-items: flex-start;
}

body #braveslab-chat-container .message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

body #braveslab-chat-container .message.user .message-bubble {
    background: linear-gradient(135deg, #01B7AF 0%, #5DD5C7 100%);
    color: white;
}

body #braveslab-chat-container .message.bot .message-bubble {
    background: white;
    color: #242424;
    border: 1px solid rgba(1, 183, 175, 0.1);
    box-shadow: 0 2px 8px rgba(1, 183, 175, 0.05);
}

body #braveslab-chat-container .message-time {
    font-size: 11px;
    color: #242424;
    opacity: 0.7;
    margin-top: 5px;
}

/* ============================================
   INPUT CONTAINER
   ============================================ */
body #braveslab-chat-container #chat-input-container {
    padding: 15px;
    background: white;
    border-top: 1px solid #CEF2EF;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

body #braveslab-chat-container #chat-input {
    flex: 1;
    border: 1px solid #CEF2EF;
    border-radius: 25px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: height 0.15s ease-out;
    color: #242424;
    background: white;
    box-shadow: none;
    font-family: 'Montserrat', 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    max-height: 150px;
    vertical-align: middle;
    box-sizing: border-box;
}

body #braveslab-chat-container #chat-input:focus {
    border-color: #01B7AF;
    box-shadow: 0 0 0 3px rgba(1, 183, 175, 0.1);
    outline: none;
}

/* ============================================
   BOTÓN DE ENVIAR
   ============================================ */
body #braveslab-chat-container #send-button {
    width: 45px;
    height: 45px;
    min-width: 45px;
    min-height: 45px;
    max-width: 45px;
    max-height: 45px;
    flex-shrink: 0;
    border: none;
    border-width: 0;
    background: linear-gradient(135deg, #01B7AF 0%, #5DD5C7 100%);
    background-color: #01B7AF;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    outline: none;
    padding: 0;
    margin: 0;
    font-size: 18px;
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: normal;
    line-height: 1;
    text-decoration: none;
    text-transform: none;
    letter-spacing: normal;
}

body #braveslab-chat-container #send-button span {
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateX(1px);
    line-height: 1;
}

body #braveslab-chat-container #send-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(1, 183, 175, 0.3);
}

body #braveslab-chat-container #send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

body #braveslab-chat-container #send-button:active:not(:disabled) {
    transform: scale(0.95);
}

/* ============================================
   INDICADOR DE ESCRITURA
   ============================================ */
body #braveslab-chat-container .typing-indicator {
    display: none;
    align-items: center;
    gap: 5px;
    color: #242424;
    opacity: 0.8;
    font-style: italic;
    font-size: 13px;
    padding: 0 20px;
}

/* Ocultar indicador en skin Braves (ya tiene cursor de latido) */
body #braveslab-chat-container.braves-skin-braves .typing-indicator {
    display: none !important;
}

body #braveslab-chat-container .typing-dots {
    display: flex;
    gap: 3px;
}

body #braveslab-chat-container .typing-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #01B7AF;
    animation: typing 1.4s infinite ease-in-out;
}

body #braveslab-chat-container .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

body #braveslab-chat-container .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-10px);
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 480px) {

    body #braveslab-chat-container #chat-window,
    body #braveslab-chat-container.braves-expanded #chat-window {
        width: calc(100vw - 40px);
        right: -10px;
        height: calc(100vh - 140px);
    }

    .braveslab-chat-widget-container.position-bottom-right #braveslab-chat-container,
    .braveslab-chat-widget-container.position-bottom-left #braveslab-chat-container {
        bottom: 20px;
        right: 20px;
        left: auto;
    }
}

/* ============================================
   RESET DE ESTILOS
   ============================================ */
body #braveslab-chat-container * {
    box-sizing: border-box;
}

body #braveslab-chat-container button {
    appearance: none;
    -webkit-appearance: none;
}

body #braveslab-chat-container input {
    appearance: none;
    -webkit-appearance: none;
}

/* Ocultar elementos de burbuja Braves cuando el chat está abierto */
body #braveslab-chat-container.chat-open #chat-toggle .braves-bubble-wrapper {
    display: none !important;
}

body #braveslab-chat-container.chat-open #chat-toggle #chat-bubble-image {
    display: none !important;
}

/* ============================================
   HEADER STATUS TEXT & ANIMATION
   ============================================ */
body #braveslab-chat-container .chat-header-badge {
    display: flex;
    align-items: center;
    gap: 12px;
}

body #braveslab-chat-container .chat-header-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

body #braveslab-chat-container .chat-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    color: white;
    margin: 0;
}

body #braveslab-chat-container .chat-status-text {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    margin-top: 2px;
    animation: slideOutText 0.8s ease-out forwards;
    transform-origin: left;
    max-width: 0;
    opacity: 0;
}

@keyframes slideOutText {
    0% {
        max-width: 0;
        opacity: 0;
        transform: translateX(-10px);
    }

    100% {
        max-width: 250px;
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================
   STREAMING VISUAL - CURSOR PARPADEANTE
   ============================================ */
body #braveslab-chat-container .typing-cursor {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #01B7AF;
    animation: heartbeat 2s ease-in-out infinite;
    /* Efecto latido de corazón */
    margin-left: 4px;
    margin-bottom: 2px;
    vertical-align: middle;
}

/* Animación tipo latido de corazón: "tun-tun" (pausa) "tun-tun" */
@keyframes heartbeat {
    0% {
        opacity: 0.4;
        transform: scale(1);
    }

    /* Primer latido */
    10% {
        opacity: 1;
        transform: scale(1.1);
    }

    20% {
        opacity: 0.4;
        transform: scale(1);
    }

    /* Segundo latido */
    30% {
        opacity: 1;
        transform: scale(1.1);
    }

    40% {
        opacity: 0.4;
        transform: scale(1);
    }

    /* Pausa larga */
    100% {
        opacity: 0.4;
        transform: scale(1);
    }
}


/* Smooth scrolling durante streaming */
body #braveslab-chat-container #chat-messages {
    scroll-behavior: smooth;
}

/* Input deshabilitado durante streaming */
body #braveslab-chat-container #chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #f5f5f5;
}