:root {
    --green: #25D366;
    --green-dark: #075e54;
    --text: #000000;
    --text-light: #ffffff;
    --white: #ffffff;
    --black: #000000;
    --text-bg: #DCF8C6;
}

.a21chat {
    position: relative;

    ::-webkit-scrollbar {
        width: 5px;
    }

    ::-webkit-scrollbar-track {
        background: #f1f1f1;
    }

    ::-webkit-scrollbar-thumb {
        background: var(--green-dark);
        border-radius: 5px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: var(--green-dark);
    }

    .a21chat-icon {
        position: fixed;
        bottom: 50px;
        right: 50px;
        cursor: pointer;
        z-index: 99;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 8px 16px;
        border-radius: 50px;
        background-color: var(--green);
        border: 1px solid var(--green);
        color: var(--text-light);
        font-size: 16px;
        line-height: 100%;
        font-weight: 500;
        transition: all 0.3s ease;
        outline: none;
        box-shadow: none;

        img {
            height: 16px;
            margin-right: 6px;
        }

        &:hover {
            background-color: var(--green-dark);
            border-color: var(--green-dark);
            transform: scale(0.95);
        }
    }

    .a21chat-header {
        display: flex;
        align-items: center;
        background-color: var(--green-dark);
        padding: 12px;
        min-height: 65px;
        
        .a21chat-header-icon {
            background-color: var(--white);
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 4px;
            height: 35px;
            width: 35px;
            margin-right: 16px;

            img {
                height: 16px;
                width: auto;
            }
        }

        .a21chat-header-content {
            color: var(--text-light);

            h2 {
                color: var(--text-light);
                margin: 0;
                font-size: 16px;
                line-height: 140%;
            }

            p {
                color: var(--text-light);
                margin: 0;
                font-size: 12px;
                line-height: 140%;
                padding: 0;
            }
        }
    }

    .a21chat-close {
        border: 1px solid var(--text-light);
        border-radius: 50%;
        color: var(--text-light);
        font-size: 16px;
        line-height: 100%;
        transition: all 0.3s ease;
        cursor: pointer;
        height: 24px;
        width: 24px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-left: auto;

        &:hover {
            transform: scale(0.95);
        }
    }

    .a21chat-back {
        color: var(--text-light);
        font-size: 16px;
        transform: scaleY(2.5);
        line-height: 100%;
        transition: all 0.3s ease;
        cursor: pointer;
        height: 24px;
        width: 24px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 12px;

        &:hover {
            transform: scaleY(2);
        }
    }

    .area-visivel {
        position: fixed;
        bottom: 70px;
        right: 30px;
        opacity: 0;
        z-index: -1;
        overflow: hidden;
        transition: all 0.1s ease;
        min-width: 350px;

        &.active {
            opacity: 1;
            z-index: 9999;
        }
    }

    .a21chat-content {
        background-color: #E5DDD5;
        padding: 0;
        height: 470px;
        /* Nunca passa do topo do ecrã: 70px em baixo + 65px do cabeçalho + 16px de margem em cima */
        max-height: calc(100vh - 151px);
        max-height: calc(100dvh - 151px);

        .messages {
            display: flex;
            flex-direction: column;
            height: 100%;
            padding: 12px;
            background-image: url('bg.svg');
            background-size: 185px;
            overflow-y: auto;

            .message-item {
                background-color: var(--white);
                border: none;
                border-radius: 12px;
                padding: 12px;
                color: var(--black);
                display: flex;
                align-items: center;
                margin-bottom: 12px;
                transition: all 0.3s ease;
                cursor: pointer;
                font-size: 14px;
                line-height: 130%;

                a {
                    color: var(--green-dark);

                    &:hover {
                        color: var(--black);
                    }
                }

                &:hover {
                    transform: scale(0.99);
                    background-color: #eeeeee;
                }

                &:first-of-type {
                    border-top-left-radius: 0;
                    width: fit-content;

                    &:hover {
                        transform: scale(1);
                        cursor: default;
                    }
                }

                &:last-of-type {
                    margin-bottom: 0;
                }

                &.bot {
                    margin-right: 20px;
                    border-top-left-radius: 0;
                }

                &.human {
                    background-color: var(--text-bg);
                    margin-left: 20px;
                    margin-right: 0;
                    border-top-right-radius: 0;
                }

                &.form {
                    margin-top: auto;
                    background-color: transparent;
                    padding: 0;

                    &:hover {
                        transform: scale(1);
                        cursor: default;
                    }

                    input {
                        width: 100%;
                        border: 1px solid var(--text-light);
                        border-radius: 12px;
                        padding: 8px;
                        margin-bottom: 12px;
                        outline: none;
                        box-shadow: none;
                        font-size: 12px;
                        line-height: 100%;

                        &::placeholder {
                            color: #aaaaaa;
                        }
                    }

                    textarea {
                        width: 100%;
                        height: 140px;
                        border: 1px solid var(--text-light);
                        border-radius: 12px;
                        padding: 8px;
                        margin-bottom: 12px;
                        outline: none;
                        box-shadow: none;
                        font-size: 12px;
                        line-height: 100%;

                        &::placeholder {
                            color: #aaaaaa;
                        }
                    }

                    button {
                        border: 1px solid var(--green);
                        background-color: var(--green);
                        border-radius: 12px;
                        color: var(--text-light);
                        font-size: 16px;
                        line-height: 16px;
                        padding: 8px 16px;
                        width: 100%;
                        transition: all 0.3s ease;
                        cursor: pointer;
                        outline: none;
                        box-shadow: none;

                        &:hover {
                            transform: scale(0.99);
                            background-color: var(--green-dark);
                            border-color: var(--green-dark);
                        }
                    }
                }

                .contact-wrapper {
                    height: 35px;
                    width: 35px;
                    margin: 0;
                    margin-right: 12px;
                    border-radius: 50%;
                    overflow: hidden;

                    img {
                        object-fit: cover;
                        height: 100%;
                        width: 100%;
                    }
                }

                .contact-content {
                    margin-right: 12px;

                    .contact-name {
                        color: var(--black);
                        font-size: 16px;
                        line-height: 140%;
                        margin: 0;
                        padding: 0;
                    }

                    .contact-position {
                        color: #aaaaaa;
                        font-size: 12px;
                        line-height: 140%;
                        margin: 0;
                        padding: 0;
                    }
                }

                .contact-link {
                    margin-left: auto;
                    font-size: 16px;
                    transform: scaleY(2.5);
                }
            }
        }
    }

    .a21chat-body {
        position: relative;
        overflow: hidden;
        border-radius: 12px;
        background-color: var(--white);
        border: none;
    }

    .contact-card {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        overflow: hidden;
        border-radius: 12px;
        background-color: var(--white);
        border: none;
        transition: all 0.3s ease;
        transform: translateX(100%);
        z-index: -1;

        &.active {
            transform: translateX(0);
            z-index: inherit;
        }

        .a21chat-header {
            .a21chat-header-icon {
                padding: 0;
                overflow: hidden;

                img {
                    width: 100%;
                    height: 100%;
                    object-fit: cover;
                }
            }
        }

        .messages {
            .message-item {
                display: flex;
                flex-direction: column;
                align-items: start;
                justify-content: center;

                .phone {
                    height: 16px;
                    width: auto;
                    margin-right: 5px;
                }

                .phone-link {
                    display: flex;
                    align-items: center;
                }

                .disclaimer {
                    font-size: 12px;
                    color: #757575;
                }
            }

            &#chat-messages {
                .spacer {
                    margin-top: auto;
                }
                
                .message-item {
                    margin-bottom: 6px;
                }
            }
        }
    }
    
    .online {
        
        display: flex;
        align-items: center;

        .icon {
            position: relative;
            height: 20px;
            width: 20px;
            
            span {
                background-color: var(--green);
                border-radius: 50%;
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                height: 10px;
                width: 10px;

                &:first-of-type {
                    height: 7px;
                    width: 7px; 
                }

                &:last-of-type {
                    animation: myAnimation 2s linear infinite;
                }
            }
        }

        p {
            color: #757575;
            font-size: 12px;
            line-height: 140%;
            margin: 0;
            padding: 0;
        }
    }

    .input-chat {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 6px 12px 12px 12px;
        background-color: #E5DDD5;
        background-image: url('bg.svg');
        background-size: 185px;
        margin-right: 5px;

        label {
            position: absolute;
            height: 0;
            width: 0;
        }

        textarea {
            margin: 0;
            height: 100%;
            width: 100%;
            border-radius: 100px;
            padding: 10px 20px;
            border: none;
            outline: none;
            box-shadow: none;
            display: block;
            line-height: 120%;
        }
    }

    #chat-messages {
        padding-bottom: 75px;
    }
}

@media (max-width: 767.99px) {
    .a21chat {
        .a21chat-icon {
            left: 0;
            right: 0;
            bottom: calc(16px + env(safe-area-inset-bottom, 0px));
            width: fit-content;
            margin: 0 auto;
        }

        .area-visivel {
            min-width: 100%;
            top: 0;
            bottom: 0;
            right: 0;
            left: 0;
        }

        .a21chat-body {
            height: 100%;
            border-radius: 0;

            .general {
                height: 100%;

                
            }
        }

        .a21chat-content {
            height: calc(100% - 65px);
        }

        .contact-card {
            border-radius: 0;
        }
    }
}

@keyframes myAnimation {
  0% {
    opacity: 0.1;
  }
  50% {
    opacity: 0.75;
  }
  100% {
    opacity: 0.1;
  }
}
/* Slider de viaturas sugeridas pelo assistente */
.a21chat {

    /* Termos à esquerda e versão do chatbot no canto inferior direito */
    .input-chat .chat-rodape {
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        gap: 8px;
        margin: 6px 0 0 0;
        padding: 0 8px;
    }

    .input-chat .chat-versao {
        flex-shrink: 0;
        font-size: 9px;
        line-height: 130%;
        color: #9e9e9e;
        white-space: nowrap;
    }

    .input-chat .chat-termos {
        margin: 0;
        padding: 0;
        font-size: 11px;
        line-height: 130%;
        color: #555555;

        a {
            color: var(--green-dark);
            text-decoration: underline;
        }
    }

    /* As mensagens ficam numa camada própria, para nada lá dentro passar por cima da caixa de texto */
    #chat-messages {
        position: relative;
        z-index: 0;
        isolation: isolate;
    }

    #chat-messages {
        /* Valor de recurso: o JS acerta-o para a altura real da .input-chat */
        padding-bottom: 130px;

        /* Cartões das viaturas sugeridas, em 2 colunas */
        .message-item.cartoes-viaturas {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 8px;
            width: 100%;
            min-width: 0;
            flex-shrink: 0;
            padding: 0;
            background-color: transparent;
            cursor: default;
            margin-bottom: 6px;

            &:hover {
                transform: none;
                background-color: transparent;
            }

            .chat-viatura {
                display: flex;
                flex-direction: column;
                height: 100%;
                background-color: var(--white);
                border-radius: 12px;
                overflow: hidden;
                color: var(--black);
                text-decoration: none;

                figure {
                    margin: 0;
                    aspect-ratio: 4 / 3;
                    background-color: #eeeeee;

                    img {
                        width: 100%;
                        height: 100%;
                        object-fit: cover;
                        display: block;
                    }
                }

                .chat-viatura-info {
                    display: flex;
                    flex-direction: column;
                    flex-grow: 1;
                    padding: 8px 10px 10px 10px;

                    h3 {
                        margin: 0;
                        font-size: 13px;
                        line-height: 130%;
                        color: var(--black);
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }

                    p {
                        margin: 0;
                        padding: 0;
                        font-size: 11px;
                        line-height: 140%;
                    }

                    .versao {
                        color: #757575;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }

                    .detalhes {
                        color: #757575;
                        margin-top: 4px;
                    }

                    /* Preço e botão na mesma linha, no fundo do cartão (o botão desce se não couber) */
                    .rodape {
                        display: flex;
                        flex-wrap: wrap;
                        align-items: center;
                        justify-content: space-between;
                        gap: 6px;
                        margin-top: auto;
                        padding-top: 8px;
                    }

                    .preco {
                        font-size: 14px;
                        font-weight: 700;
                        color: var(--green-dark);
                        white-space: nowrap;
                    }

                    .ver {
                        flex-shrink: 0;
                        margin-left: auto;
                        padding: 2px 8px;
                        border: 1px solid var(--green-dark);
                        border-radius: 100px;
                        font-size: 10px;
                        line-height: 130%;
                        color: var(--green-dark);
                        white-space: nowrap;
                        transition: all 0.3s ease;
                    }
                }

                &:hover .ver {
                    background-color: var(--green-dark);
                    color: var(--text-light);
                }
            }
        }

        /* Indicador de resposta a ser escrita */
        .message-item.a-escrever {
            flex-direction: row;
            align-items: center;
            gap: 4px;
            width: fit-content;

            span {
                width: 7px;
                height: 7px;
                border-radius: 50%;
                background-color: #9e9e9e;
                animation: a21chatEscrever 1.2s infinite ease-in-out;

                &:nth-child(2) {
                    animation-delay: 0.2s;
                }

                &:nth-child(3) {
                    animation-delay: 0.4s;
                }
            }
        }
    }
}

@keyframes a21chatEscrever {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Caixa de texto sempre por cima das mensagens e dos cartões */
.a21chat .contact-card .input-chat {
    z-index: 10;
}
