/* ==========================================================================
   用户端样式 - 移动端优先
   ========================================================================== */

/* 基础重置 */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    color: #333;
    background: #ededed;
    overflow: hidden;
}

/* 使用 flex 布局撑满整个可视区：顶栏 / 消息区 / 输入区 */
body {
    display: flex;
    flex-direction: column;
}

/* ==================== 顶部标题栏 ==================== */
.topbar {
    flex: 0 0 auto;
    height: 48px;
    background: linear-gradient(135deg, #4a90e2, #357abd);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    z-index: 10;
}
.topbar .title { font-size: 17px; font-weight: 500; }

/* 连接状态小圆点 */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
    transition: background 0.3s;
}
.status-dot.online { background: #52c41a; box-shadow: 0 0 6px #52c41a; }
.status-dot.offline { background: #ff4d4f; }

/* ==================== 消息列表区 ==================== */
.message-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 10px;
    -webkit-overflow-scrolling: touch;
}

/* 时间分隔线 */
.time-divider {
    text-align: center;
    color: #999;
    font-size: 12px;
    margin: 12px 0 8px;
}

/* 消息行：左右气泡 */
.msg-row {
    display: flex;
    margin-bottom: 12px;
    align-items: flex-end;
}
.msg-row.self { flex-direction: row-reverse; }

/* 头像 */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex: 0 0 36px;
    background: #bdbdbd;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}
.msg-row.self .avatar { background: #4a90e2; }
.msg-row:not(.self) .avatar { background: #52c41a; }

/* 气泡 */
.bubble {
    max-width: 72%;
    margin: 0 8px;
    padding: 8px 12px;
    border-radius: 8px;
    word-break: break-word;
    position: relative;
    line-height: 1.4;
    white-space: pre-wrap;
}
.msg-row:not(.self) .bubble {
    background: #fff;
    color: #333;
    border-top-left-radius: 2px;
}
.msg-row.self .bubble {
    background: #95ec69;
    color: #111;
    border-top-right-radius: 2px;
}

/* 图片 / 视频消息气泡去掉背景内边距 */
.bubble.media { padding: 2px; background: transparent !important; }
.bubble.media img,
.bubble.media video {
    max-width: 100%;
    max-height: 240px;
    display: block;
    border-radius: 6px;
    cursor: pointer;
}

/* ==================== 输入区 ==================== */
.input-bar {
    flex: 0 0 auto;
    background: #f7f7f7;
    border-top: 1px solid #ddd;
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

/* 图标按钮（+图片、视频） */
.icon-btn {
    flex: 0 0 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #666;
    cursor: pointer;
}
.icon-btn:active { background: #e0e0e0; }

/* 文本框 */
#text-input {
    flex: 1 1 auto;
    border: none;
    outline: none;
    resize: none;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff;
    font-size: 15px;
    line-height: 1.4;
    max-height: 100px;
    font-family: inherit;
}

/* 发送按钮 */
.send-btn {
    flex: 0 0 auto;
    height: 40px;
    padding: 0 16px;
    border: none;
    border-radius: 8px;
    background: #4a90e2;
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}
.send-btn:active { background: #357abd; }
.send-btn:disabled { background: #bbb; cursor: not-allowed; }

/* ==================== 昵称弹层 ==================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal.hidden { display: none; }
.modal-inner {
    width: 80%;
    max-width: 320px;
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
}
.modal-inner h2 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #4a90e2;
}
.modal-inner p {
    font-size: 13px;
    color: #666;
    margin-bottom: 14px;
}
.modal-inner input {
    width: 100%;
    height: 40px;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0 12px;
    font-size: 15px;
    margin-bottom: 14px;
    outline: none;
}
.modal-inner input:focus { border-color: #4a90e2; }
.modal-inner button {
    width: 100%;
    height: 42px;
    background: #4a90e2;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

/* ==================== 图片预览层 ==================== */
.img-preview {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.img-preview.hidden { display: none; }
.img-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ==================== 加载提示 ==================== */
.loading-tip {
    text-align: center;
    padding: 10px;
    color: #999;
    font-size: 12px;
}
