/* Chat Modal */
#chat-modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

#chat-modal.is-open {
    display: flex;
    /* Use flexbox for centering */
}

.chat-container {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 800px;
    height: 80vh;
    max-height: 600px;
    display: flex;
    overflow: hidden;
}

/* Left Panel: Conversations */
.conversations-panel {
    width: 35%;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

.user-search {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    display: flex;
}

#user-search-input {
    flex-grow: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px 0 0 4px;
}

#user-search-button {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-left: none;
    background-color: #f0f0f0;
    cursor: pointer;
    border-radius: 0 4px 4px 0;
}

#search-results {
    position: absolute;
    background: #fff;
    border: 1px solid #ccc;
    width: calc(35% - 22px);
    /* Adjust width */
    max-height: 150px;
    overflow-y: auto;
    z-index: 1002;
    display: none;
}

#search-results div {
    padding: 10px;
    cursor: pointer;
}

#search-results div:hover {
    background-color: #f0f0f0;
}

#conversations-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex-grow: 1;
}

#conversations-list li {
    padding: 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    display: flex;
    /* justify-content: space-between; <--- REMOVED */
    align-items: center;
}

#conversations-list li:hover,
#conversations-list li.active {
    background-color: #e9f5ff;
}

.conversation-nickname {
    font-weight: 500;
}

.conversation-unread-badge {
    background-color: #ff3b30;
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 12px;
    min-width: 20px;
    text-align: center;
    line-height: 16px;
    margin-left: 8px;
    /* Add some space between nickname and badge */
}


/* Right Panel: Messages */
.messages-panel {
    width: 65%;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 10px 15px;
    /* 调整内边距 */
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f9f9f9;
}

#chat-with-username {
    margin: 0;
    font-size: 1.1em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* 防止用户名过长时换行 */
}

.chat-header-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    /* 按钮之间的间距 */
}

.chat-header-icon-btn {
    background: none;
    border: none;
    font-size: 18px;
    /* 统一图标大小 */
    cursor: pointer;
    color: #888;
    padding: 5px;
    line-height: 1;
}

.chat-header-icon-btn:hover {
    color: #333;
}

.chat-close-button {
    font-size: 24px;
    /* 关闭按钮可以大一些 */
}

#messages-area {
    flex-grow: 1;
    padding: 15px 20px;
    overflow-y: auto;
    background-color: #fafafa;
}

/* 日期分割线 */
.date-divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
}

.date-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(to right, transparent, #ddd 20%, #ddd 80%, transparent);
}

.date-label {
    background-color: #f5f5f5;
    color: #666;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: 500;
    display: inline-block;
    border: 1px solid #e0e0e0;
    position: relative;
    z-index: 1;
}

.message-container {
    display: flex;
    margin-bottom: 8px;
    align-items: flex-end;
}

.message-container.sent {
    justify-content: flex-end;
}

.message-container.received {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
}

.message-container.sent .message-bubble {
    background-color: #007bff;
    color: white;
    border-bottom-right-radius: 6px;
    margin-left: 8px;
}

.message-container.received .message-bubble {
    background-color: #ffffff;
    color: #333;
    border-bottom-left-radius: 6px;
    border: 1px solid #e4e6ea;
    margin-right: 8px;
}

.message-bubble .nickname {
    font-size: 0.8em;
    font-weight: bold;
    margin-bottom: 5px;
    color: #555;
}

.message-container.sent .message-bubble .nickname {
    color: #f0f0f0;
}

.message-bubble .content {
    font-size: 1em;
    word-wrap: break-word;
    white-space: pre-wrap; /* 保留空格和换行符 */
    line-height: 1.4; /* 改善行间距 */
}

/* 移除气泡内的时间戳 */
.message-bubble .timestamp {
    display: none;
}

/* 外部时间戳样式 */
.message-timestamp {
    font-size: 0.75em;
    color: #999;
    align-self: flex-end;
    margin-bottom: 4px;
    white-space: nowrap;
    user-select: none;
}

.message-container.sent .message-timestamp {
    margin-right: 8px;
    order: -1; /* 时间戳显示在消息左边 */
}

.message-container.received .message-timestamp {
    margin-left: 8px;
}

.message-input-area {
    padding: 10px;
    border-top: 1px solid #ddd;
    display: flex;
}

#message-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 18px;
    resize: none;
    height: 40px;
    margin-right: 10px;
}

#send-button,
#clear-chat-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 0 20px;
    border-radius: 18px;
    cursor: pointer;
    font-size: 1em;
    white-space: nowrap;
    /* 防止文字换行 */
    flex-shrink: 0;
    /* 防止按钮被压缩 */
}

#clear-chat-button {
    background-color: #dc3545;
    margin-left: 5px;
}

/* Dropdown Notification Badge Styling */
.dropdown-item {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notification-badge {
    background-color: #ff3b30;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: bold;
    line-height: 16px;
    min-width: 20px;
    text-align: center;
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
}

/* Toast Notification Styling */
#toast-notification-container {
    position: fixed;
    top: 80px;
    /* Below the header */
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast-notification {
    background-color: #fff;
    color: #333;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    width: 320px;
    animation: toast-in 0.5s, toast-out 0.5s 29.5s;
    /* Extended duration */
    display: flex;
    position: relative;
}

.toast-notification:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.toast-content {
    flex-grow: 1;
    cursor: pointer;
}

.toast-header {
    font-weight: bold;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.toast-body strong {
    color: #007bff;
}

.toast-close-button {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0 8px;
    margin-left: 10px;
    order: 1;
    /* Place it after the content */
}

.toast-close-button:hover {
    color: #333;
}

/* Welcome Badge Styling */
.welcome-badge {
    background-color: #ff3b30;
    color: white;
    border-radius: 50%;
    padding: 1px 5px;
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
    text-align: center;
    display: inline-block;
    vertical-align: middle;
    margin-left: 4px;
    /* 减小间距 */
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* 移动端响应式优化 */
@media (max-width: 768px) {

    /* 响应断点调整为768px以覆盖更多平板设备 */
    .chat-container {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .conversations-panel {
        width: 30%;
        /* 减小会话列表宽度 */
        min-width: 100px;
        /* 设置最小宽度 */
    }

    .messages-panel {
        width: 70%;
        /* 增加消息区域宽度 */
    }

    .user-search {
        flex-direction: row;
        /* 确保搜索框和按钮在同一行 */
        padding: 8px;
    }

    #user-search-input {
        min-width: 0;
        /* 允许输入框收缩 */
    }

    #user-search-button {
        display: inline-block;
        /* 确保按钮可见 */
        padding: 8px;
    }

    .message-input-area {
        padding: 8px;
    }

    #message-input {
        font-size: 16px;
        /* 防止移动端浏览器自动缩放 */
        height: auto;
        /* 允许输入框根据内容自适应高度 */
        min-height: 40px;
    }

    #send-button {
        padding: 0 15px;
        font-size: 1em;
        /* 保持发送按钮字体大小 */
    }

    /* 移动端消息气泡优化 */
    .message-bubble {
        max-width: 80%;
        padding: 10px 14px;
    }

    .message-timestamp {
        font-size: 0.7em;
    }

    #messages-area {
        padding: 10px 15px;
    }

    .date-label {
        padding: 4px 12px;
        font-size: 0.75em;
    }
}