/* ======================================================= */
/* == Braulio Aquino AI Chat Widget Premium Styling ===== */
/* ======================================================= */

/* Contenedor principal: Centrado verticalmente a la derecha en pantallas grandes */
#ba-ai-chat-container {
    position: fixed;
    top: 50%;
    right: 30px;
    bottom: auto;
    transform: translateY(-50%);
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
}

/* Ocultar elementos */
.ba-chat-hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
    transform: translateY(15px);
    transition: all 0.3s ease;
}

/* --- Botón Flotante Principal --- */
#ba-chat-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #107c41, #0f6236);
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(16, 124, 65, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    outline: none;
    position: relative;
}

#ba-chat-trigger:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 28px rgba(16, 124, 65, 0.45);
}

#ba-chat-trigger:active {
    transform: scale(0.95);
}

/* Punto de notificación */
.ba-chat-notification-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #ff3b30;
    border: 2px solid #ffffff;
    box-shadow: 0 0 8px rgba(255, 59, 48, 0.8);
    animation: ba-pulse 1.8s infinite;
}

/* --- Globo de Texto Automático (Tooltip / Popup) --- */
#ba-chat-tooltip {
    position: absolute;
    right: 75px;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    width: 260px;
    padding: 15px 35px 15px 15px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    color: #2b3a4a;
    font-size: 14px;
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.3s ease;
    animation: ba-bounce-in-left 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#ba-chat-tooltip:hover {
    transform: translateY(-50%) translateX(-4px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.15);
}

#ba-chat-tooltip-close {
    position: absolute;
    top: 6px;
    right: 10px;
    background: none;
    border: none;
    font-size: 18px;
    color: #8899a6;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

#ba-chat-tooltip-close:hover {
    color: #4a5568;
}

/* --- Ventana de Chat (Cuadro Principal) --- */
#ba-chat-box {
    position: fixed;
    top: 50%;
    right: 30px;
    bottom: auto;
    transform: translateY(-50%);
    width: 390px;
    height: 560px;
    max-height: calc(100vh - 60px);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000000;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
    animation: ba-slide-center 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

/* Cabecera del Chat */
#ba-chat-header {
    background: linear-gradient(135deg, rgba(16, 124, 65, 0.9), rgba(15, 98, 54, 0.9));
    padding: 16px 20px;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ba-chat-bot-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ba-chat-avatar {
    font-size: 24px;
}

.ba-chat-status {
    display: flex;
    flex-direction: column;
}

.ba-chat-status-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.ba-chat-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #34c759;
    border-radius: 50%;
    margin-right: 5px;
    box-shadow: 0 0 6px #34c759;
}

.ba-chat-status-text {
    font-size: 11px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    margin-top: 2px;
}

#ba-chat-close {
    background: none;
    border: none;
    font-size: 24px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: color 0.2s ease;
    padding: 0;
    line-height: 1;
}

#ba-chat-close:hover {
    color: #ffffff;
}

/* Historial de Mensajes */
#ba-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(245, 247, 248, 0.4);
}

.ba-chat-msg {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.ba-chat-msg-bot {
    background: #ffffff;
    color: #2c3e50;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.ba-chat-msg-bot a {
    color: #107c41;
    text-decoration: underline;
    font-weight: 500;
}

.ba-chat-msg-bot a:hover {
    color: #0f6236;
}

.ba-chat-msg-user {
    background: #107c41;
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Contenedor de Entrada de Texto */
#ba-chat-input-container {
    padding: 15px;
    background: #ffffff;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 10px;
}

#ba-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    background: #f8fafc;
}

#ba-chat-input:focus {
    border-color: #107c41;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(16, 124, 65, 0.1);
}

#ba-chat-send {
    background: #107c41;
    color: #ffffff;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

#ba-chat-send:hover {
    background: #0f6236;
    transform: scale(1.04);
}

#ba-chat-send:active {
    transform: scale(0.96);
}

/* Indicador de escritura animado */
.ba-chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 20px;
}

.ba-chat-dot {
    width: 6px;
    height: 6px;
    background-color: #8899a6;
    border-radius: 50%;
    animation: ba-typing-blink 1.4s infinite both;
}

.ba-chat-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ba-chat-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* --- Animaciones Keyframes --- */
@keyframes ba-pulse {
    0% { transform: scale(0.9); opacity: 0.9; }
    50% { transform: scale(1.1); opacity: 1; box-shadow: 0 0 12px rgba(255, 59, 48, 0.9); }
    100% { transform: scale(0.9); opacity: 0.9; }
}

@keyframes ba-bounce-in-left {
    0% { transform: translateY(-50%) translateX(20px) scale(0.85); opacity: 0; }
    70% { transform: translateY(-50%) translateX(-4px) scale(1.02); opacity: 0.95; }
    100% { transform: translateY(-50%) translateX(0) scale(1); opacity: 1; }
}

@keyframes ba-bounce-in {
    0% { transform: translateY(30px) scale(0.8); opacity: 0; }
    70% { transform: translateY(-5px) scale(1.02); opacity: 0.9; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes ba-slide-center {
    0% {
        transform: translateY(calc(-50% + 25px)) scale(0.96);
        opacity: 0;
    }
    100% {
        transform: translateY(-50%) scale(1);
        opacity: 1;
    }
}

@keyframes ba-slide-up {
    0% { transform: translateY(40px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

@keyframes ba-typing-blink {
    0% { opacity: 0.2; transform: scale(0.8); }
    20% { opacity: 1; transform: scale(1); }
    100% { opacity: 0.2; transform: scale(0.8); }
}

/* --- Ajustes Responsive --- */
@media (max-width: 768px) {
    #ba-ai-chat-container {
        top: auto;
        bottom: 75px;
        right: 25px;
        transform: none;
    }
    #ba-chat-tooltip {
        top: auto;
        bottom: 75px;
        right: 5px;
        transform: none;
        animation: ba-bounce-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }
    #ba-chat-tooltip:hover {
        transform: translateY(-4px);
    }
    #ba-chat-box {
        position: absolute;
        top: auto;
        bottom: 80px;
        right: 0;
        transform: none;
        width: 360px;
        max-width: calc(100vw - 30px);
        height: 520px;
        max-height: calc(100vh - 120px);
        animation: ba-slide-up 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    }
}

@media (max-width: 480px) {
    #ba-ai-chat-container {
        bottom: 15px;
        right: 15px;
    }
    #ba-chat-box {
        position: fixed;
        bottom: 85px;
        right: 15px;
        left: 15px;
        width: auto;
        height: calc(100vh - 110px);
        max-height: none;
    }
    #ba-chat-tooltip {
        width: calc(100vw - 80px);
        bottom: 75px;
    }
}
