/* 基础重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1e1f22;
    height: 100vh;
    overflow: hidden;
}

/* ========== 桌面端布局（默认） ========== */
@media (min-width: 769px) {
    .chat-app {
        display: flex;
        height: 100vh;
    }
    .sidebar {
        width: 280px;
        background: #2b2d31;
        color: #dbdee1;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
    }
    .chat-main {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-width: 0;
    }
    /* 侧边栏按钮横排 */
    .sidebar-actions {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
        padding: 12px;
    }
    .sidebar-actions button {
        flex: 0 1 auto;
        padding: 6px 12px;
        font-size: 14px;
        margin: 2px 0;
    }
}

/* ========== 手机端布局（宽度 ≤768px） ========== */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
        height: auto;
    }
    .chat-app {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        width: 100%;
        background: #2b2d31;
        color: #dbdee1;
        display: flex;
        flex-direction: column;
        max-height: 45vh;
        overflow-y: auto;
        border-bottom: 1px solid #3c3f45;
    }
    .chat-main {
        width: 100%;
        display: flex;
        flex-direction: column;
        height: 55vh;
        min-height: 300px;
    }
    .messages-area {
        padding: 12px;
    }
    .message {
        max-width: 90%;
    }
    .input-area textarea {
        font-size: 16px;
    }
    .sidebar-actions {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
        padding: 12px;
    }
    .sidebar-actions button {
        flex: 0 1 auto;
        padding: 6px 12px;
        font-size: 14px;
        margin: 2px 0;
    }
    .channel-item, .private-item, .group-item {
        white-space: normal;
        word-break: break-word;
    }
}

/* ========== 共用样式 ========== */
.channel-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
}
.channel-item, .private-item, .group-item {
    padding: 10px 12px;
    margin: 2px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.channel-item:hover, .private-item:hover, .group-item:hover {
    background: #3c3f45;
}
.channel-item.active {
    background: #404249;
    color: white;
}
.channel-group-title {
    font-size: 12px;
    text-transform: uppercase;
    padding: 12px 8px 4px;
    color: #949ba4;
}
.sidebar-actions {
    border-top: 1px solid #3c3f45;
    display: flex;
    gap: 8px;
}
.sidebar-actions button {
    background: #3c3f45;
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
}
.logout-btn {
    background: #da373c !important;
}
.admin-btn {
    background: #f39c12 !important;
}
.chat-header {
    padding: 14px 16px;
    background: #2b2d31;
    border-bottom: 1px solid #3c3f45;
    font-weight: bold;
    color: white;
}
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #313338;
}

/* ===== 消息样式 ===== */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}
.message-self {
    align-items: flex-end;
    align-self: flex-end;
}
.message-other {
    align-items: flex-start;
}
.msg-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.message-self .msg-avatar {
    order: 2;
}
.message-other .msg-avatar {
    order: 0;
}
.msg-content {
    display: flex;
    flex-direction: column;
    max-width: 100%;
}
.message-self .msg-content {
    align-items: flex-end;
}
.message-other .msg-content {
    align-items: flex-start;
}
.message-sender {
    font-size: 12px;
    color: #b5bac1;
    margin-bottom: 4px;
}
.message-bubble {
    background: #2b2d31;
    padding: 8px 12px;
    border-radius: 18px;
    color: #dbdee1;
    word-wrap: break-word;
    display: inline-block;
    max-width: 100%;
    width: fit-content;
}
.message-self .message-bubble {
    background: #5865f2;
    color: white;
}
.message-time {
    font-size: 10px;
    color: #949ba4;
    margin-top: 4px;
}
.message-self .message-time {
    align-self: flex-end;
    text-align: right;
}
.message-other .message-time {
    align-self: flex-start;
    text-align: left;
}

/* ===== 输入区 ===== */
.input-area {
    padding: 12px;
    background: #2b2d31;
    display: flex;
    gap: 8px;
}
.input-area textarea {
    flex: 1;
    background: #383a40;
    border: none;
    border-radius: 20px;
    padding: 10px 16px;
    color: white;
    resize: none;
    font-family: inherit;
}
.input-area button {
    background: #5865f2;
    border: none;
    padding: 0 20px;
    border-radius: 20px;
    color: white;
    font-weight: bold;
    cursor: pointer;
}

/* ===== 模态框 ===== */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: #2b2d31;
    padding: 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 350px;
    color: white;
}
.modal-content input {
    width: 100%;
    margin: 10px 0;
    padding: 12px;
    background: #1e1f22;
    border: 1px solid #3c3f45;
    color: white;
    border-radius: 8px;
}
.modal-content button {
    width: 100%;
    padding: 12px;
    background: #5865f2;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
}
.close {
    float: right;
    cursor: pointer;
    font-size: 24px;
}

/* ===== 图片查看器 ===== */
#imageViewer {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
#imageViewer img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    user-select: none;
}
#imageViewer .close {
    position: fixed;
    top: 20px;
    right: 30px;
    font-size: 40px;
    color: white;
    cursor: pointer;
    z-index: 10000;
}

/* ===== 侧边栏用户信息 ===== */
.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #1e1f22;
    border-bottom: 1px solid #3c3f45;
    cursor: pointer;
}
.user-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}
.user-name {
    font-weight: bold;
    font-size: 16px;
    color: #dbdee1;
}
.user-username {
    font-size: 12px;
    color: #949ba4;
}
#cropImage {
    max-width: 100%;
    display: block;
}
.cropper-container {
    margin: 0 auto;
}