.messages{
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
}


.message{
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-end;
    position: relative;
    padding: 0 18px 0 5px;
    transition: filter 200ms ease-in-out, height 200ms ease-in-out;

    --message-color: var(--msg-get);

    &:not(.self):has(.messageReply){
        .msg{
            border-top-left-radius: 5px !important;
        }
    }

    &.self:has(.messageReply){
        .msg{
            border-top-right-radius: 5px !important;
        }
    }

    .messageContainer{
        display: flex;
        flex-direction: row;
        list-style: none;
        align-items: flex-end;
        gap: 3px;
        font-size: 0.8rem;
        width: 100%;
        position: relative;
    }
    .replyIcon {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        background: var(--glass-color);
        border-radius: 50%;
        position: absolute;
        padding: 5px;
        aspect-ratio: 1;
        left: 0;
        visibility: hidden;
        opacity: 0;
        transition: background-color 150ms;
        
        &[data-swipe-start="true"]{
            visibility: visible;
            opacity: 1;
        }
    
        &[data-reply-trigger="true"]{
            background: var(--message-color);
        }

        i{
            color: #ffffff70;
        }
    }

    &.self .replyIcon{
        right: 0;
        left: unset;
    }

    .sent{
        i{
            font-size: 0.5rem !important;
            padding: 0;
            color: var(--transparent-white-color);
        }
    }
    .avatar{
        height: 30px;
        width: 30px;
        border-radius: 50%;
        background: #dadada00;
        display: flex;
        visibility: hidden;
        align-items: center;
        justify-content: center;
    }

    .messageBody{
        position: relative;
        background: #00000000;
        max-width: 78%;
        display: flex;
        flex-direction: column;
        overflow-wrap: anywhere;
    }

    .messageTime{
        color: var(--transparent-white-color);
        font-size: 0.6rem;
        padding: 0 0 0 5px;
        margin-bottom: 10px;
        visibility: hidden;
        opacity: 0;
        transition: 200ms ease-in-out;
        white-space: nowrap;
        display: flex;
        flex-direction: row;
        align-items: flex-end;
        justify-content: flex-start;
        width: 58px;
        min-width: 58px;
        &.active{
            visibility: visible;
            opacity: 1;
        }
    }
    
    &:last-child .messageTime{
        visibility: visible;
        opacity: 1;
    }
}

.start .avatar{
    visibility: hidden;
}

//if previous message has react

.message:has(.reactsContainer){
    .msg{
        border-bottom-right-radius: 18px !important;
        border-bottom-left-radius: 18px !important;
    }
}

#messages > li {
    scroll-snap-align: end;
}

#messages:has(.message.highlight) .message{
    filter: brightness(0.8);
}

.message.highlight{
    filter: brightness(1) !important;
}

.message:has(.reactsContainer) + .message{
    .msg{
        border-top-left-radius: 18px !important;
        border-top-right-radius: 18px !important;
    }
}


//! Classlist based modifications
.message.start{
    .msg{
        border-bottom-left-radius: 5px;
        border-top-left-radius: 18px;
    }
}

.message.newGroup{
    padding-top: 20px;
}

.message.end{
    .msg{
        border-bottom-left-radius: 18px;
    }
    .avatar{
        visibility: visible;
    }
}

.message.reply .messageTitle::before {
    content: '\f3e5';
    font-family: 'FontAwesome', sans-serif;
    font-size: 1rem;
}

.message.self{
    --message-color: var(--msg-send);
    .messageContainer{
        flex-direction: row-reverse;
    }
    .sent{
        display: block;
    }
    .messageTime{
        justify-content: flex-end;
        padding: 0 5px 0 0;
    }
    .messageBody{
        align-items: flex-end;
        .messageReply{
            background: var(--msg-send-reply);
            border-radius: 18px 18px 8px 18px;
            .image{
                border-radius: 18px 18px 8px 18px;
            }
            &.imageReply{
                border-radius: 18px 18px 8px 18px !important;
            }
        }
        .msg{
            border-radius: 18px 5px 5px 18px;
        }
    }
    &.start{
        .msg{
            border-bottom-right-radius: 5px;
            border-top-right-radius: 18px;
        }
    }
    &.end{
        .msg{
            border-bottom-right-radius: 18px;
        }
        .avatar{
            visibility: visible;
        }
    }
}

.message.self:has(.seenBy > img:nth-child(2)){

    margin-bottom: 12px;

    .msg{
        border-bottom-left-radius: 18px !important;
        border-bottom-right-radius: 18px !important;
    }

    .seenBy{
        bottom: -14px;
    }
}

.message.self:has(.seenBy > img:nth-child(2)) + .message.self .msg {
    border-top-left-radius: 18px !important;
    border-top-right-radius: 18px !important;
}

.msg-item.serverMessage{
    .seenBy{
        right: 10px;
        flex-wrap: nowrap;
        max-width: unset;
    }
}


.data{
    width: max-content;
    max-width: 100%;
}

//!Main Message Element
.msg{
    color: white;
    position: relative;
    max-width: 100%;
    width: min-content;
    border-radius: 5px 18px 18px 5px;

    &:hover{
        cursor: pointer;
    }

    transition: 100ms ease-in-out;
    border-top-right-radius: 18px;
    border-bottom-right-radius: 18px;
    overflow: hidden;
    &[data-mtype="text"] .data{
        white-space: pre-wrap;
        display: block;
        padding: 8px 15px;
        min-width: 100%;
        a{
            color: inherit;
            text-decoration: underline;
            width: 100%;
        }
    }

    &[data-mtype="emoji"]{
        .data{
            font-size: 2rem;
        }
    }

    &[data-mtype="image"]{
        .data{
            background: var(--glass-color);

            &:hover{
                filter: brightness(1.1) contrast(0.9);
            }
        }
    }

    &[data-mtype="text"], &[data-mtype="file"], &[data-mtype="audio"]{
        .data{
            background: var(--message-color);
        }
    }
}

.messageReply + .msg{
    margin-top: -10px;
}

//if code has no pre parent
:not(pre) > code{
    background: #ffffff4a;
    border-radius: 5px;
    padding: 0 3px;
    font-family: monospace;
}

pre{
    display: grid;
    grid-auto-flow: column;
    background: #282c34;
    border-radius: 5px;
    padding: 5px;
    gap: 3px;
    margin-top: 5px;
    margin-bottom: 5px;
    padding-top: 25px;
    tab-size: 2;
    margin-left: -9px;
    margin-right: -9px;
    position: relative;
    cursor: default;

    .copy-btn{
        position: absolute;
        top: 2px;
        right: 2px;
        font-size: 0.6rem;
        color: rgb(255 255 255);
        background: #ffffff38;
        padding: 3px;
        border-radius: 5px;
        cursor: pointer;

        &::after{
            content: attr(data-action);
        }
    }

    
    &::before{
        position: absolute;
        content: attr(data-lang);
        inset: 0;
        width: max-content;
        height: max-content;
        padding: 3px 4px;
        border-radius: 4px;
        font-size: 0.6rem;
        margin: 2px;
        transition: 100ms;
        color: #ffffff82;
    }
    
    code{
        background: transparent;
        font-family: monospace;
        font-size: 0.7rem;
        overflow-x: scroll;
        width: 100%;
        cursor: text;
        user-select: text;
        span {
            font-family: monospace;
            user-select: text;
        }
    }
}

.progress i {
    font-size: inherit !important;
    color: inherit !important;
}

::selection{
    background: var(--glass-color);
}

.line-row{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: min-content;
    font-size: 0.7rem;
    line-height: 0.85rem;
    padding: 0 5px;
    margin-right: 2px;
    border-right: 1px solid var(--glass-color);
    color: var(--transparent-white-color);
    counter-reset: codeLine;

    span {
        counter-increment: codeLine;
        color: inherit;
    }

    span::before {
        content: counter(codeLine);
        color: var(--grayscale-gs-secondary-1);
        margin-right: 5px;
    }
}

#textbox *{
    position: relative;
    white-space: break-spaces;
    color: inherit !important;
    background: transparent !important;
    font-size: inherit !important;
    font-family: inherit !important;
}

@media screen and (orientation: landscape) and (min-device-aspect-ratio: 1.5 / 1) {
    .message {
        .messageBody{
            max-width: 65%;
        }
    }
}