/* ============================================
   聊天界面样式 - WhatsApp风格
   深蓝色主色调：#000066
   边框色：#e1e8ed
   ============================================ */

/* 聊天容器 */
.chat-container {
    display: none; /* 默认隐藏 */
    grid-column: 2 / 4; /* 占据主内容和右侧栏的位置 */
    background: #fff;
    border-radius: 0; /* 左侧直角 */
    border: 1px solid #e1e8ed;
    overflow: hidden;
    height: calc(100vh - 80px); /* 延伸到底部 */
    grid-template-columns: 300px 1fr; /* 再减少30px */
}

/* 对话列表面板 */
.chat-list-panel {
    background: #fff;
    border-right: 1px solid #e1e8ed; /* 灰线 */
    border-radius: 0; /* 直角 */
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid #e1e8ed;
}

.chat-list-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: #222;
}

.new-chat-btn {
    background: #000066;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: #0052a3;
    transform: scale(1.05);
}

/* 搜索框 */
.chat-search-box {
    padding: 12px 16px;
    border-bottom: 1px solid #e1e8ed;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f5f7fa;
}

.chat-search-icon {
    width: 20px;
    height: 20px;
    fill: #888;
}

#chatSearchInput {
    flex: 1;
    border: none;
    background: #fff;
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    border: 1px solid #e1e8ed;
}

#chatSearchInput:focus {
    border-color: #000066;
}

/* 对话列表 */
.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-list-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.chat-list-item:hover {
    background: #f5f7fa;
}

.chat-list-item.active {
    background: #e3f2fd;
    border-left: 3px solid #000066;
}

.chat-list-item-avatar {
    position: relative;
    margin-right: 12px;
}

.chat-list-item-avatar img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-list-item-online {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #25d366;
    border: 2px solid #fff;
    border-radius: 50%;
}

.chat-list-item-content {
    flex: 1;
    min-width: 0;
}

.chat-list-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-list-item-name {
    font-weight: 600;
    font-size: 16px;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item-time {
    font-size: 12px;
    color: #888;
}

.chat-list-item-bottom {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-list-item-message {
    flex: 1;
    font-size: 14px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item-unread {
    background: #000066;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.chat-list-item-read-status {
    width: 16px;
    height: 16px;
}

.chat-list-item-read-status svg {
    fill: #888;
}

.chat-list-item-read-status.read svg {
    fill: #000066;
}

/* 聊天窗口 */
.chat-window {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #fff;
    overflow: hidden; /* 防止溢出 */
}

.chat-window-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #888;
}

.chat-window-empty p {
    margin-top: 20px;
    font-size: 18px;
}

.chat-window-active {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden; /* 防止整体溺出 */
}

/* 聊天头部 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e1e8ed;
    background: #f5f7fa;
    flex-shrink: 0; /* 防止头部被压缩 */
}

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

.back-to-list-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.back-to-list-btn:hover {
    background: #e1e8ed;
}

.chat-user-avatar {
    position: relative;
}

.chat-user-avatar img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

.online-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #888;
    border: 2px solid #fff;
    border-radius: 50%;
}

.online-indicator.online {
    background: #25d366;
}

.chat-user-info {
    display: flex;
    flex-direction: column;
}

.chat-user-name {
    font-weight: 600;
    font-size: 16px;
    color: #222;
}

.chat-user-status {
    font-size: 13px;
    color: #888;
}

.chat-user-status.online {
    color: #25d366;
}

.chat-header-right {
    display: flex;
    gap: 8px;
}

.chat-header-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: #000066;
}

.chat-header-btn:hover {
    background: #e1e8ed;
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #f5f7fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* 关键：允许flex子项缩小 */
}

.chat-message {
    display: flex;
    align-items: flex-start; /* 顶部对齐 */
    gap: 8px;
    max-width: 70%;
}

.chat-message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}


.chat-message-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e1e8ed;
    word-wrap: break-word;
    word-break: break-word;
    display: inline-block;
    max-width: 70%;
    min-width: 80px;
}

.chat-message.sent .chat-message-bubble {
    background: #d1e7ff; /* 浅蓝色 */
    border-color: #d1e7ff;
}

.chat-message-text {
    font-size: 15px;
    color: #222;
    line-height: 1.4;
    display: block;
    margin-bottom: 2px;
}

.chat-message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}

.chat-message-time {
    font-size: 11px;
    color: #888;
    line-height: 1;
}

.message-status {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.message-status svg {
    width: 16px;
    height: 15px;
}

/* 日期分隔符 */
.chat-date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.chat-date-divider-text {
    background: #e1e8ed;
    color: #666;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 12px;
}

/* 输入区域 */
.chat-input-container {
    display: flex;
    align-items: center; /* 水平对齐 */
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #e1e8ed;
    background: #f5f7fa;
    min-height: 70px;
    flex-shrink: 0; /* 防止输入框被压缩 */
}

.chat-attach-btn,
.chat-emoji-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: #888;
}

.chat-attach-btn:hover,
.chat-emoji-btn:hover {
    background: #e1e8ed;
    color: #000066;
}

.chat-input-wrapper {
    flex: 1;
    background: #fff;
    border: 1px solid #e1e8ed;
    border-radius: 20px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
}

#chatInputText {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    resize: none;
    font-family: inherit;
    min-height: 24px;
    max-height: 120px;
    line-height: 1.5;
}

.chat-send-btn {
    background: #000066;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #fff;
}

.chat-send-btn:hover:not(:disabled) {
    background: #0052a3;
    transform: scale(1.05);
}

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

/* 响应式设计 */
@media (max-width: 1200px) {
    .chat-container {
        grid-template-columns: 250px 1fr;
    }
}

@media (max-width: 900px) {
    .chat-container {
        grid-template-columns: 1fr;
    }
    
    .chat-list-panel {
        display: flex;
    }
    
    .chat-window {
        display: none;
    }
    
    .chat-container.chat-open .chat-list-panel {
        display: none;
    }
    
    .chat-container.chat-open .chat-window {
        display: flex;
    }
}

/* 滚动条样式 */
.chat-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: #f5f7fa;
}

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

.chat-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}
