/* Botão Flutuante */
#chat-widget-button {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    background: #D4003B;
    color: #fff;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

#chat-widget-button i {
    font-size: 26px;
}

/* Janela Principal do Chat */
#chat-widget-box {
    display: none;
    position: fixed;
    bottom: 90px;
    left: 20px;
    z-index: 9999;
    width: 350px;
    max-width: 90vw;
    height: 480px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.25);
    flex-direction: column;
    overflow: hidden;
    font-family: sans-serif;
    transition: all 0.3s ease;
}

/* Cabeçalho */
.chat-header {
    background: #D4003B;
    color: #fff;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header strong {
    display: block;
    font-size: 15px;
}

.chat-header small {
    opacity: 0.8;
    font-size: 11px;
}

.chat-close-btn {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

/* Corpo das Mensagens */
#chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg-ia {
    background: #e9ecef;
    color: #333;
    padding: 10px 14px;
    border-radius: 10px;
    align-self: flex-start;
    max-width: 80%;
    font-size: 13px;
}

.chat-msg-user {
    background: #D4003B;
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    align-self: flex-end;
    max-width: 80%;
    font-size: 13px;
}

.chat-msg-loading {
    background: #e9ecef;
    color: #666;
    padding: 8px 12px;
    border-radius: 10px;
    align-self: flex-start;
    font-size: 12px;
    font-style: italic;
}

.chat-msg-error {
    background: #f8d7da;
    color: #721c24;
    padding: 10px 14px;
    border-radius: 10px;
    align-self: flex-start;
    max-width: 80%;
    font-size: 13px;
}

/* Formulário de Envio */
#chat-form {
    display: flex;
    padding: 10px;
    background: #fff;
    border-top: 1px solid #eee;
}

#chat-input {
    flex: 1;
    border: 1px solid #ddd;
    padding: 8px 12px;
    border-radius: 20px;
    outline: none;
    font-size: 13px;
}

#chat-btn-submit {
    background: #D4003B;
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-left: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 1069px) {
    #chat-widget-button {
        bottom: 75px;
        left: 15px;
    }
    #chat-widget-box {
        bottom: 145px;
        left: 15px;
    }

    body.page-produtos #chat-widget-button {
        bottom: 135px;
        left: 15px;
    }
    body.page-produtos #chat-widget-box {
        bottom: 205px;
        left: 15px;
    }
	
	body.page-match #chat-widget-button {
        bottom: 20px;
        left: 15px;
    }
    body.page-match #chat-widget-box {
        bottom: 90px;
        left: 15px;
    }

    #chat-widget-button.scrolled-down {
        bottom: 20px !important;
    }
    #chat-widget-box.scrolled-down {
        bottom: 90px !important;
    }
}

/* Modal Fullscreen para Celulares (< 768px) com suporte a iOS Safari */
@media (max-width: 767px) {
    #chat-widget-box {
        width: 100vw !important;
        /* Usamos 100dvh para respeitar dinamicamente as barras do Safari */
        height: 100vh !important;
        height: 100dvh !important;
        max-width: 100vw !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        z-index: 999999 !important;
    }

    /* Recuo inferior de segurança para o formulário no iOS */
    #chat-form {
        padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        padding-bottom: calc(10px + constant(safe-area-inset-bottom)) !important; /* Fallback iOS antigo */
    }
	
	body.page-match #chat-widget-button {
        display:none;
    }
}