﻿
body.chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

.headerCenter {
    justify-self: center;
}

#chatHeaderButton {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    color: white;
    cursor: pointer;
    flex: 0 0 auto;
}

    #chatHeaderButton .material-icons {
        font-size: 30px;
    }

#chatUnreadBadge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    border-radius: 11px;
    background: #ff3b30;
    color: white;
    font-size: 10px;
    font-weight: bold;
    line-height: 18px;
    text-align: center;
}

.chatHeader button {
    border: none;
    background: transparent;
    color: #050505;
    font-size: 28px;
    min-width: 44px;
    height: 44px;
    cursor: pointer;
}

#chatOverlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.55);
    align-items: center;
    justify-content: center;
}

    #chatOverlay.is-open {
        display: flex !important;
    }
#chatBox {
    width: min(900px, 96vw);
    height: min(720px, 92vh);
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
}

#chatContactsView {
    width: 330px;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

#chatMessagesView {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chatHeader {
    height: 54px;
    min-height: 54px;
    flex-shrink: 0;
    background: #F4F4F4;
    color: darkslategray;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    box-sizing: border-box;
}

#chatInputArea {
    display: flex;
    gap: 8px;
    padding: 8px;
    border-top: 1px solid #ddd;
}

#chatMessageText {
    flex: 1;
    resize: none;
}

.chatContactRow {
    /*
    padding: 12px;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    */
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid #e0e0e0;
    cursor: pointer;
    background: #fff;


}

    .chatContactRow:hover {
        background: #E6E6E6;
    }

    .chatContactRow.active {
        background: #90CAF9;
        color: #212529;
    }

.chatContactName .hasunread {
    font-weight: bold;
}

.chatContactAvatar {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 50%;
    background: #ddd;
    color: #777;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

    .chatContactAvatar .material-icons {
        font-size: 30px;
    }

.chatContactContent {
    flex: 1;
    min-width: 0;
}

.chatContactTop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}


#chatContactName {    
    font-size: 20px;    
    color: #444;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

}

.chatContactDate {
    flex-shrink: 0;
    font-size: 13px;
    color: #555;
}

.chatContactPreview {
    margin-top: 2px;
    font-size: 14px;
    color: #444;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chatContactRow.unread .chatContactName,
.chatContactRow.unread .chatContactPreview {
    font-weight: 700;
}

/* optional: make date slightly stronger for unread */
.chatContactRow.unread .chatContactDate {
    font-weight: 600;
}

.chatContactGroup {
    color: #888;
    font-size: 12px;
}

.contactUnreadBadge {
    float: right;
    background: #25d366;
    color: white;
    border-radius: 10px;
    min-width: 20px;
    padding: 2px 6px;
    text-align: center;
}

#chatGroupTabs {
    height: 48px;
    min-height: 48px;
    flex-shrink: 0;
    display: flex;
    border-bottom: 1px solid #ddd;
}

.chatGroupTab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #1e88e5;
    background: #fff;
}

    .chatGroupTab.active {
        background: #BBDEFB;
        font-weight: bold;
        color: #1565C0;
    }

    .chatGroupTab .material-icons {
        font-size: 28px;
    }

#chatMessagesList {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f7f7f7;
    display: flex;
    flex-direction: column;
}

.chatDateSeparator {
    display: flex;
    align-items: center;
    margin: 12px 0;
    color: #666;
    font-size: 13px;
}

    .chatDateSeparator:before,
    .chatDateSeparator:after {
        content: "";
        flex: 1;
        border-top: 3px solid #ccc;
    }

    .chatDateSeparator span {
        padding: 0 8px;
    }

.chatMessageRow {
    display: flex;
    margin: 6px 0;
}

    .chatMessageRow.mine {
        justify-content: flex-end;
    }

    .chatMessageRow.theirs {
        justify-content: flex-start;
    }

.chatBubble {
    max-width: 70%;
    padding: 6px 8px;
    border-radius: 7px;
    font-size: 14px;
}

.chatMessageRow.mine .chatBubble {
    background: #dcf8c6;
}

.chatMessageRow.theirs .chatBubble {
    background: #f1f1f1;
}

.chatMeta {
    text-align: right;
    font-size: 11px;
    color: #666;
    margin-top: 2px;
}

.chatTicks {
    margin-left: 2px;
    color: #173CEF;
}

#sendChatMessage {
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 50%;
    background: #238D08;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-top: 6px;
}

    #sendChatMessage .material-icons {
        font-size: 18px;
    }


#chatContactsList {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
   
}

.chatEntityLink,
.chatToken {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: 14px;
    font-weight: 600;
    text-decoration: none;
    margin: 2px 0;
}

.chatEntityLink {
    background: #e3f2fd;
    color: #1565c0;
    cursor: pointer;
}

    .chatEntityLink:hover {
        background: #bbdefb;
        text-decoration: none;
    }

    .chatEntityLink .material-icons {
        font-size: 17px;
    }

.chatTokenDisabled {
    background: #f1f1f1;
    color: #777;
}


/* Force visible scrollbar on desktop */
@media (min-width: 701px) {
    #chatContactsList {
        scrollbar-width: thin; /* Firefox */
    }

        #chatContactsList::-webkit-scrollbar {
            width: 8px;
        }

        #chatContactsList::-webkit-scrollbar-thumb {
            background: #aaa;
            border-radius: 8px;
        }

        #chatContactsList::-webkit-scrollbar-track {
            background: #eee;
        }
}

@media (max-width: 700px) {

    #chatOverlay.is-open {
        position: fixed;
        inset: 0;
        display: flex !important;
        background: #fff; /* important */
        overflow: hidden;
    }

    #chatBox {
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        overflow: hidden;
        background: #fff;
    }

    #chatContactsView,
    #chatMessagesView {
        width: 100%;
        height: 100%;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .chatHeader {
        height: 56px;
        min-height: 56px;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 2;
    }

    #chatContactsList,
    #chatMessagesList {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    #chatInputArea {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        background: #fff;
        z-index: 2;
        padding: 8px;
        border-top: 1px solid #ddd;
    }

    #chatOverlay.mobile-show-messages #chatContactsView {
        display: none !important;
    }

    #chatOverlay.mobile-show-messages #chatMessagesView {
        display: flex !important;
    }

    #chatOverlay:not(.mobile-show-messages) #chatContactsView {
        display: flex !important;
    }

    #chatOverlay:not(.mobile-show-messages) #chatMessagesView {
        display: none !important;
    }
}