/* 
 * Estilos do Chat de Suporte Inspefire - App Mobile
 * Bolinha flutuante + janela de chat
 */

/* Botão flutuante (bolinha) */
#chat-suporte-btn {
    position: fixed;
    bottom: 5px;
    right: 0px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: transparent;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: none !important;
    z-index: 9999998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    animation: pulse-chat 2s infinite;
}

#chat-suporte-btn svg {
    width: 28px;
    height: 28px;
    fill: white;
}

#chat-suporte-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(177, 54, 54, 0.6);
}

#chat-suporte-btn.tem-mensagem::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    background: #4CAF50;
    border-radius: 50%;
    border: 2px solid white;
}

@keyframes pulse-chat {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(177, 54, 54, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(177, 54, 54, 0.7);
    }
}

/* Janela do chat */
#chat-suporte-janela {
    position: fixed;
    bottom: 10px;
    right: 10px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 9999999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

#chat-suporte-janela.aberto {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Cabeçalho do chat */
.chat-header {
    background: linear-gradient(135deg, #b13636 0%, #d94545 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 16px 16px 0 0;
}

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

.chat-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.chat-avatar svg {
    width: 24px;
    height: 24px;
    fill: #b13636;
}

.chat-header-texto h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header-texto p {
    margin: 2px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
}

.chat-status-online {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #4CAF50;
    border-radius: 50%;
    margin-right: 5px;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.chat-fechar {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    opacity: 0.8;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.chat-fechar:hover {
    opacity: 1;
}

/* Área de mensagens */
.chat-mensagens {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    gap: 15px;
    -webkit-overflow-scrolling: touch;
}

.chat-mensagens::-webkit-scrollbar {
    width: 6px;
}

.chat-mensagens::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Placeholder de boas-vindas centralizado */
.chat-boas-vindas-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 30px 20px;
    color: #999;
    gap: 12px;
}

.chat-boas-vindas-placeholder svg {
    width: 48px;
    height: 48px;
    fill: #d0bfbf;
}

.chat-boas-vindas-placeholder strong {
    display: block;
    font-size: 15px;
    color: #b13636;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-boas-vindas-placeholder p {
    font-size: 13px;
    color: #aaa;
    margin: 0;
    line-height: 1.5;
}

/* Mensagem individual */
.chat-msg {
    display: flex;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg.usuario {
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #b13636;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-msg-avatar svg {
    width: 18px;
    height: 18px;
    fill: white;
}

.chat-msg.usuario .chat-msg-avatar {
    background: #666;
}

.chat-msg-conteudo {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-msg.usuario .chat-msg-conteudo {
    align-items: flex-end;
}

.chat-msg-balao {
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
}

.chat-msg.assistente .chat-msg-balao {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-msg.usuario .chat-msg-balao {
    background: #b13636;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg-hora {
    font-size: 11px;
    color: #999;
    padding: 0 8px;
}

/* Formatação markdown nas mensagens */
.chat-msg-balao strong {
    font-weight: 600;
}

.chat-msg-balao ul, .chat-msg-balao ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chat-msg-balao li {
    margin: 4px 0;
}

.chat-msg-balao code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

/* Mensagem de digitando */
.chat-digitando {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
}

.chat-digitando.ativo {
    display: flex;
}

.chat-digitando-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #b13636;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-digitando-avatar svg {
    width: 18px;
    height: 18px;
    fill: white;
}

.chat-digitando-pontos {
    display: flex;
    gap: 4px;
}

.chat-digitando-pontos span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.chat-digitando-pontos span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-digitando-pontos span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Área de input */
.chat-input-area {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    /* Importante para Android: manter sempre visível */
    position: relative;
    z-index: 10;
}

/* Android WebView: prevenir que o input suma ou chat suba */
@media (max-width: 480px) {
    .chat-input-area {
        position: sticky;
        bottom: 0;
        background: white;
    }
}

.chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.chat-input:focus {
    border-color: #b13636;
}

.chat-enviar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #b13636;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.chat-enviar svg {
    width: 20px;
    height: 20px;
    fill: white;
    transform: rotate(0deg);
    transition: transform 0.2s;
}

.chat-enviar:hover:not(:disabled) svg {
    transform: translateX(2px);
}

.chat-enviar:hover:not(:disabled) {
    background: #d94545;
    transform: scale(1.05);
}

.chat-enviar:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Mensagem de boas-vindas - NÃO USADO MAIS (agora é mensagem da IA) */
/*
.chat-boas-vindas {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.chat-boas-vindas-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #b13636 0%, #d94545 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 4px 12px rgba(177, 54, 54, 0.3);
}

.chat-boas-vindas-avatar svg {
    width: 40px;
    height: 40px;
    fill: white;
}

.chat-boas-vindas h3 {
    color: #333;
    margin-bottom: 10px;
}

.chat-boas-vindas p {
    font-size: 14px;
    line-height: 9px;
    margin-bottom: 20px;
}
*/

.chat-sugestoes {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.chat-sugestao-btn {
    background: white;
    border: 1px solid #e0e0e0;
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 10px;
    -webkit-tap-highlight-color: transparent;
}

.chat-sugestao-btn svg {
    width: 18px;
    height: 18px;
    fill: #b13636;
    flex-shrink: 0;
}

.chat-sugestao-btn:hover,
.chat-sugestao-btn:active {
    border-color: #b13636;
    color: #b13636;
    transform: translateX(5px);
}

/* Loading spinner */
.chat-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Container e Botão WhatsApp no chat */
.chat-whatsapp-container {
    margin: 15px 0;
    display: flex;
    justify-content: center;
}

.chat-whatsapp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: white !important;
    padding: 14px 24px;
    border-radius: 30px;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.4);
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
}

.chat-whatsapp-btn:hover,
.chat-whatsapp-btn:active {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(37, 211, 102, 0.6);
    background: linear-gradient(135deg, #128C7E 0%, #25D366 100%);
    color: white !important;
}

.chat-whatsapp-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.5);
}

.chat-whatsapp-btn svg {
    flex-shrink: 0;
}

/* Responsivo - Mobile */
@media (max-width: 480px) {
    #chat-suporte-janela {
        width: calc(100vw - 10px);
        height: calc(100vh - 70px);
        right: 5px;
        left: 5px;
        top: 5px!important; /* Garante que não use top, apenas bottom */
        max-height: calc(100vh - 70px);
        border-radius: 8px;
        /* Força recalculo no iOS quando viewport muda */
        will-change: height, bottom;
        margin-top: 64px!important;
        padding: 0px!important;
        margin-left: 0px!important;
        margin-right: 0px!important;
        left: 0px!important;
        max-height: calc(90vh - 65px)!important;
    }
    
    #chat-suporte-btn {
        bottom: 15px;
        right: 15px;
        width: 90px;
        height: 90px;
    }
    
    #chat-suporte-btn svg {
        width: 26px;
        height: 26px;
    }
    
    .chat-header {
        display:none;
        padding: 16px;
        border-radius: 8px 8px 0 0;
    }
    
    .chat-avatar {
        width: 40px;
        height: 40px;
    }
    
    .chat-header-texto h3 {
        font-size: 15px;
    }
    
    .chat-header-texto p {
        font-size: 11px;
    }
    
    .chat-msg-conteudo {
        max-width: 80%;
    }
    
    .chat-msg-balao {
        padding: 10px 14px;
        font-size: 13px;
    }
}

/* Ajustes para telas muito pequenas */
@media (max-width: 360px) {
    #chat-suporte-janela {
        width: calc(100vw - 10px);
        height: calc(100vh - 70px);
        right: 5px;
        left: 5px;
        top: 5px !important; /* Garante que não use top, apenas bottom */
        max-height: calc(100vh - 70px);
        margin-top: 64px!important;
        padding: 0px!important;
        margin-left: 0px!important;
        margin-right: 0px!important;
        left: 0px!important;
        max-height: calc(90vh - 65px)!important;
    }
    
    #chat-suporte-btn {
        bottom: 10px;
        right: 10px;
        width: 80px;
        height: 80px;
    }
    
    .chat-boas-vindas {
        padding: 30px 15px;
    }
    
    .chat-boas-vindas-avatar {
        width: 70px;
        height: 70px;
    }
    
    .chat-boas-vindas-avatar svg {
        width: 35px;
        height: 35px;
    }
}

/* Garantir que o input fique sempre visível quando o teclado abre */
@media (max-width: 480px) {
    #chat-suporte-janela {
        transition: none; /* Remove transição para evitar jumps */
        margin-top: 64px!important;
        padding: 0px!important;
        margin-left: 0px!important;
        margin-right: 0px!important;
        left: 0px!important;
        max-height: calc(90vh - 65px)!important;
    }
    
    .chat-input-area {
        position: sticky;
        bottom: 0;
        z-index: 10;
        background: white;
    }
    
    .chat-mensagens {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0; /* Importante para flex funcionar corretamente */
    }
    
    /* Prevenir scroll do body quando chat estiver aberto */
    body.chat-aberto {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100vh !important;
        top: 0 !important;
    }
    
    /* Garantir que o HTML também não faça scroll */
    body.chat-aberto,
    html:has(body.chat-aberto) {
        overflow: hidden !important;
        height: 100vh !important;
        width: 100% !important;
    }
}

/* Container page_ para mobile em tela cheia */
.pagina#page_chat_suporte,
#page_chat_suporte {
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: white;
    z-index: 9999999;
    overflow: hidden;
}

.pagina#page_chat_suporte #chat-suporte-janela,
#page_chat_suporte #chat-suporte-janela {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    bottom: auto;
    right: auto;
    border-radius: 0;
    box-shadow: none;
    display: flex;
}

/* Botão voltar no mobile */
.chat-voltar {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transition: background 0.2s;
}

.chat-voltar:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-voltar svg {
    width: 24px;
    height: 24px;
    fill: white;
}

/* Prevenir scroll do body quando chat mobile está aberto */
body.chat-aberto-mobile {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100vh !important;
    top: 0 !important;
}

html:has(body.chat-aberto-mobile) {
    overflow: hidden !important;
    height: 100vh !important;
    width: 100% !important;
}

.chat-whatsapp-btn span {
    white-space: normal;
}