﻿/* ============================================================
   DESKTOP
   ============================================================ */

.chat-sidebar {
    position: fixed;
    right: 0;
    bottom: 20px;
    width: 50vw;
    height: 50vh;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.15);
    overflow: hidden;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s ease;
    box-sizing: border-box;
}

    .chat-sidebar.open {
        transform: translateX(0);
    }

/* ============================================================
   BOTÃO TOGGLE (ABRIR/FECHAR)
   ============================================================ */

.chat-toggle-btn {
    position: fixed;
    right: 16px;
    bottom: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #007bff;
    cursor: pointer;
    z-index: 10001;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

    .chat-toggle-btn .chat-icon {
        font-size: 20px;
        color: white;
    }

    .chat-toggle-btn:hover .chat-icon {
        opacity: 0.8;
    }

/* ============================================================
   HEADER
   ============================================================ */

.chat-header {
    background: #007bff;
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 600;
    
    position: sticky;
    top: 0;
    z-index: 10002;
}

.chat-close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

    .chat-close-btn:hover {
        opacity: 0.7;
    }

/* ============================================================
   CONTAINER INTERNO
   ============================================================ */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    background: white;
    overflow: hidden;
}

/* ============================================================
   MENSAGENS
   ============================================================ */

.messages-window {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
    background: #ffffff;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

#messagesWindow {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================================
   MENSAGEM INDIVIDUAL
   ============================================================ */

.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 80%;
}

.user-message {
    margin-left: auto;
    flex-direction: row-reverse;
}

.bot-message {
    margin-right: auto;
}

/* ============================================================
   AVATAR 
   ============================================================ */

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.user-message .avatar {
    background: white;
    color: #d00000;
}

    .user-message .avatar i {
        color: #d00000; 
    }

.bot-message .avatar {
    background: white;
    color: #007bff;
}

    .bot-message .avatar i {
        color: #007bff;
    }

.avatar i {
    font-size: 26px;
}

/* ============================================================
   BUBBLES
   ============================================================ */

.bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.4;
    max-width: 100%;
}

.user-message .bubble {
    background: #007bff;
    color: white;
    border-bottom-right-radius: 4px;
}

.bot-message .bubble {
    background: #e9ecef;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* ============================================================
   INDICADOR DE ESCRITA
   ============================================================ */

.typing-indicator {
    display: flex;
    gap: 4px;
}

    .typing-indicator span {
        width: 8px;
        height: 8px;
        background: #999;
        border-radius: 50%;
        animation: blink 1.4s infinite both;
    }

        .typing-indicator span:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-indicator span:nth-child(3) {
            animation-delay: 0.4s;
        }

@keyframes blink {
    0% {
        opacity: .2;
    }

    20% {
        opacity: 1;
    }

    100% {
        opacity: .2;
    }
}

/* ============================================================
   INPUT
   ============================================================ */

.input-area {
    margin-top: auto;
    background: transparent;
    padding: 0;
}

.input-wrapper {
    position: relative;
    width: 100%;
}

.message-input {
    width: 100%;
    height: 60px;
    padding: 14px 60px 14px 14px;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid #ddd;
    outline: none;
    resize: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

    .message-input:focus {
        background: #f1f3f5;
    }

/* ============================================================
   BOTÃO ENVIAR
   ============================================================ */

.send-icon-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #007bff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
}

    .send-icon-btn:hover {
        background: #0056b3;
        transform: scale(1.1);
    }

#sendIcon {
    font-size: 22px;
    color: white;
}

/* ============================================================
   SPINNER
   ============================================================ */

#chatSpinner {
    font-size: 20px;
    color: white !important;
}

/* ============================================================
   MOBILE FIRST (iOS + Android) 
   ============================================================ */

@media (max-width: 768px) {

    .chat-sidebar {
        position: fixed;
        left: env(safe-area-inset-left, 0);
        right: env(safe-area-inset-right, 0);
        bottom: env(safe-area-inset-bottom, 0);
        width: calc(100vw - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
        height: calc(60vh - env(safe-area-inset-bottom, 0));
        background: #ffffff;
        border-radius: 0;
        overflow: hidden;
        transform: translateX(100%) !important;
        transition: transform 0.35s ease;
        z-index: 9999;
        display: flex;
        flex-direction: column;
    }

        .chat-sidebar.open {
            transform: translateX(0) !important;
        }

    .message {
        max-width: 100% !important;
    }
}

/* Fix específico para Safari iOS */
@supports (-webkit-touch-callout: none) {
    .chat-sidebar {
        position: fixed;
        left: env(safe-area-inset-left, 0);
        right: env(safe-area-inset-right, 0);
        bottom: env(safe-area-inset-bottom, 0);
        width: calc(100vw - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
        height: calc(60dvh - env(safe-area-inset-bottom, 0));
        max-height: calc(60dvh - env(safe-area-inset-bottom, 0));
        background: #ffffff;
        border-radius: 0;
        overflow: hidden;
        transform: translateX(100%) !important;
        transition: transform 0.35s ease;
        z-index: 9999;
        display: flex;
        flex-direction: column;
    }

    .message-input {
        width: 100%;
        height: 60px;
        font-size: 16px !important;
        padding: 14px 60px 14px 14px;
        border-radius: 12px;
        background: #ffffff;
        border: 1px solid #ddd;
        outline: none;
        resize: none;
        box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    }
    /*.messages-window {
        overflow-y: auto !important;
    }*/
}

/* ============================================================
   FIM DO DOCUMENTO
   ============================================================ */