* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; padding: 0; height: 100%; width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
    background: #ededed; color: #333; font-size: 15px;
}
button { cursor: pointer; border: none; outline: none; font-size: 15px; }
input { outline: none; }

#app { max-width: 480px; margin: 0 auto; height: 100%; position: relative; background: #fff; }
.page { height: 100%; display: flex; flex-direction: column; }

/* 登录/注册 */
#auth { background: #fff; align-items: center; justify-content: center; }
.auth-box { width: 85%; max-width: 360px; padding: 20px; }
.logo-text { text-align: center; font-size: 28px; color: #07c160; margin: 40px 0 30px; font-weight: 600; }
.tabs { display: flex; border-bottom: 1px solid #eee; margin-bottom: 20px; }
.tab { flex: 1; text-align: center; padding: 12px 0; cursor: pointer; color: #666; }
.tab.active { color: #07c160; border-bottom: 2px solid #07c160; }
.tab-panel input { display: block; width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 12px; }
.tab-panel button { width: 100%; padding: 12px; background: #07c160; color: #fff; border-radius: 6px; margin-top: 8px; }

/* 主界面 */
#main { height: 100vh; display: flex; flex-direction: column; }
#top-bar {
    height: 48px; background: #ededed; display: flex; align-items: center;
    padding: 0 14px; border-bottom: 1px solid #ddd; flex: 0 0 auto;
}
#top-title { flex: 1; font-weight: 600; font-size: 17px; }
#top-action { color: #07c160; font-size: 14px; }
#main-content { flex: 1; overflow-y: auto; background: #fff; position: relative; }
#bottom-bar {
    height: 56px; background: #f7f7f7; display: flex; border-top: 1px solid #ddd;
    flex: 0 0 auto;
}
.bottom-item {
    flex: 1; text-align: center; padding: 6px 0; color: #666; cursor: pointer;
    font-size: 12px;
}
.bottom-item > div { font-size: 22px; line-height: 1; margin-bottom: 2px; }
.bottom-item.active { color: #07c160; }

/* 聊天列表 */
.search-row { padding: 10px 14px; background: #f7f7f7; position: relative; }
#search-input {
    width: 100%; padding: 8px 12px; border-radius: 6px; border: none;
    background: #fff; font-size: 14px;
}
#search-results { position: absolute; left: 14px; right: 14px; top: 48px; background: #fff; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.15); z-index: 10; max-height: 320px; overflow-y: auto; display: none; }
#search-results .item { padding: 10px; display: flex; align-items: center; border-bottom: 1px solid #f3f3f3; cursor: pointer; }
#search-results .item:hover { background: #f7f7f7; }

.chat-list-item {
    display: flex; padding: 12px 14px; border-bottom: 1px solid #f0f0f0; cursor: pointer;
}
.chat-list-item .avatar { width: 40px; height: 40px; border-radius: 6px; background: #07c160; color: #fff; text-align: center; line-height: 40px; margin-right: 10px; flex: 0 0 auto; font-size: 13px; }
.chat-list-item .avatar img { width: 100%; height: 100%; border-radius: 6px; object-fit: cover; }
.chat-list-item .meta { flex: 1; min-width: 0; }
.chat-list-item .row1 { display: flex; justify-content: space-between; }
.chat-list-item .name { font-weight: 500; }
.chat-list-item .time { color: #999; font-size: 12px; }
.chat-list-avatar-wrap{position:relative;}
.chat-list-item .content { color: #888; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-top: 4px; }
.chat-list-item .badge { background: #fa5151; color: #fff; border-radius: 10px; padding: 1px 6px; font-size: 11px; margin-left: 6px;position: absolute;
    left: -10px;
    bottom: -5px; }

/* 通讯录 */
.contact-section { border-top: 1px solid #eee; border-bottom: 1px solid #eee; background: #fff; }
.contact-item { padding: 14px; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; cursor: pointer; position: relative; }
.contact-item:last-child { border-bottom: none; }
.contact-item span { margin-right: 12px; font-size: 18px; }
.badge {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0 6px;
    background: #fa5151;
    color: #fff;
    font-size: 12px;
    border-radius: 9px;
    text-align: center;
    margin-left: auto;
    margin-right: 0;
}
.contact-title { padding: 14px; color: #999; font-size: 13px; background: #f7f7f7; }

/* 我的 */
.me-card { padding: 18px 14px; display: flex; align-items: center; background: #fff; border-bottom: 1px solid #eee; }
.me-card img { width: 56px; height: 56px; border-radius: 8px; background: #07c160; margin-right: 14px; object-fit: cover; }
.me-info #me-nick { font-size: 18px; font-weight: 500; }
.muted { color: #888; font-size: 13px; margin-top: 4px; }
.form-section { padding: 12px 14px; background: #fff; border-bottom: 1px solid #eee; }
.form-section label { font-size: 13px; color: #666; display: block; margin-bottom: 6px; }
.form-section input { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; }
#btn-save-me, #btn-logout { display: block; margin: 18px auto; padding: 10px 30px; background: #07c160; color: #fff; border-radius: 6px; width: 80%; }
#btn-logout.secondary { background: #fff; color: #fa5151; border: 1px solid #fa5151; }
.setting-row {
    display: flex; justify-content: space-between; align-items: center;
    margin: 0 auto; padding: 14px 20px;
    background: #fff; border-radius: 6px; width: 80%; cursor: pointer;
    border: 1px solid #ddd; color: #333; font-size: 14px;
    transition: background 0.15s;
}
.setting-row:hover { background: #f5f5f5; }
.setting-row .setting-value { color: #07c160; font-weight: 500; }

/* 聊天窗口 */
.chat-window {
    position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: 100%;
    max-width: 480px; height: 100vh; background: #ededed;
    display: flex; flex-direction: column; z-index: 99;
}
#chat-header {
    height: 48px; background: #ededed; border-bottom: 1px solid #ccc;
    display: flex; align-items: center; padding: 0 12px; flex: 0 0 auto;
}
.back-btn { font-size: 22px; margin-right: 8px; color: #333; cursor: pointer; }
#chat-title { flex: 1; font-weight: 500; cursor: pointer; }
.menu-btn {
    font-size: 22px; cursor: pointer; padding: 4px 8px;
    color: #333; margin-left: auto; user-select: none;
}
.menu-btn:hover { color: #07c160; }
.dropdown-menu {
    position: absolute; top: 50px; right: 12px; z-index: 200;
    background: #fff; border-radius: 6px; box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    min-width: 140px; overflow: hidden; font-size: 14px;
}
.dropdown-item {
    padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #f0f0f0;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: #f5f5f5; color: #07c160; }
.dropdown-item.danger:hover { background: #fef0f0; color: #fa5151; }
.m-avatar { cursor: pointer; }


#chat-messages { flex: 1; overflow-y: auto; padding: 12px; background: #ededed; }

.msg { display: flex; margin: 8px 0; width: 100%; }
.msg .bubble {
    padding: 8px 12px; border-radius: 6px;
    background: #fff; position: relative;
    overflow-wrap: anywhere; word-wrap: break-word;
    line-height: 1.5;
    display: inline-block;
    box-sizing: border-box;
}
.msg.self .bubble { background: #95ec69; }
.msg .nick { font-size: 12px; color: #999; margin-bottom: 4px; }
.msg .m-row {
    display: flex; align-items: flex-start;
    width: 100%;
}
.msg.self .m-row { flex-direction: row-reverse; }  /* self 时头像移到右边 */
.msg .m-content {
    display: flex; flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}
.msg.self .m-content { align-items: flex-end;position:relative; }    /* self 时气泡右对齐 */
.msg .m-avatar {
    width: 32px; height: 32px; border-radius: 4px; background: #07c160; color: #fff;
    text-align: center; line-height: 32px; margin: 0 8px; flex: 0 0 auto; font-size: 12px;
    overflow: hidden;
}
.msg .m-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; }
.msg-time { text-align: center; color: #999; font-size: 11px; margin: 6px 0; }

/* 气泡内的富内容 */
.bubble img.chat-img { max-width: 200px; max-height: 260px; border-radius: 4px; display: block; }
.bubble video.chat-video { max-width: 240px; max-height: 260px; border-radius: 4px; display: block; }
.bubble audio.chat-audio { width: 220px; display: block; }
.bubble .chat-file {
    display: flex; align-items: center; padding: 8px 12px;
    background: rgba(0,0,0,0.04); border-radius: 4px; min-width: 180px;
}
.bubble .chat-file .file-icon { font-size: 28px; margin-right: 10px; }
.bubble .chat-file .file-info { min-width: 0; }
.bubble .chat-file .file-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble .chat-file .file-size { font-size: 12px; color: #888; margin-top: 2px; }
.bubble a { color: inherit; text-decoration: underline; }

/* 输入框扩展区 */
.chat-input {
    display: flex; padding: 8px; border-top: 1px solid #ddd; background: #f7f7f7;
    flex: 0 0 auto; align-items: center;
}
.chat-input textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 18px;
    background: #fff;
    margin-right: 8px;
    resize: none;
    font-size: 14px;
    line-height: 1.4;
    max-height: 96px;
    min-height: 20px;
    overflow: hidden;          /* 不再显示滚动条，配合自动高度 */
    font-family: inherit;
    outline: none;
}

/* 输入有内容时隐藏 + 号按钮（JS 会给 .chat-input 加 has-content） */
.chat-input.has-content [data-tool="plus"] { display: none; }
.chat-input button {
    padding: 0 18px; height: 38px; background: #07c160; color: #fff;
    border-radius: 4px; border: none; font-size: 14px; cursor: pointer;
    display: none; /* 默认隐藏，有内容时 JS 加 .show */
    flex: 0 0 auto;
}
.chat-input button.show { display: block; }
.chat-tool {
    width: 38px; height: 38px; flex: 0 0 38px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; cursor: pointer; color: #555;
    border-radius: 50%; margin-right: 4px;
    transition: background .15s;
}
.chat-tool:hover { background: rgba(0,0,0,0.08); }
.chat-tool.active { background: rgba(7,193,96,0.15); color: #07c160; }

/* 表情/上传扩展面板 */
.chat-ext {
    background: #f7f7f7; border-top: 1px solid #e5e5e5;
    flex: 0 0 auto; overflow: auto; max-height: 220px;
    transition: max-height .25s;
}
.chat-panel { padding: 14px; }

.emoji-grid {
    display: flex; flex-wrap: wrap;
}
.emoji-grid .emoji-item {
    width: 11.11%; aspect-ratio: 1;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; cursor: pointer; border-radius: 4px;
}
.emoji-grid .emoji-item:hover { background: rgba(0,0,0,0.06); }

.plus-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 10px; }
.plus-item {
    display: flex; flex-direction: column; align-items: center;
    cursor: pointer;
}
.plus-icon {
    width: 56px; height: 56px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; color: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform .15s;
}
.plus-item:hover .plus-icon { transform: scale(1.05); }
.plus-label { font-size: 13px; color: #555; margin-top: 8px; }

/* 头像选择弹窗 */
.avatar-popup {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-popup-inner {
    background: #fff;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.avatar-popup-header {
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
    font-size: 15px;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.avatar-popup-body {
    padding: 16px;
    height: 440px;
    max-height: 70vh;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 70px;
    gap: 12px;
}
.avatar-choice {
    width: 70px;
    height: 70px;
    margin: 0 auto;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    display: block;
    background: #f5f5f5;
    border: 2px solid transparent;
    box-sizing: border-box;
    transition: border-color 0.15s;
}
.avatar-choice img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: 50%;
}
.avatar-choice.active,
.avatar-choice:hover { border-color: #07c160; }

/* 头像图片可点击 */
#me-avatar { cursor: pointer; }

/* iframe 发现页 - 列表样式 */
#view-discover { height: 100%; background: #ededed; overflow-y: auto; }
.discover-list { padding: 8px 0; }
.discover-item {
    background: #fff;
    margin: 8px 14px;
    padding: 14px 14px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
    transition: background .15s;
}
.discover-item:active { background: #f0f0f0; }
.discover-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #07c160, #2ba558);
    color: #fff;
    border-radius: 6px;
    text-align: center;
    line-height: 36px;
    font-weight: 600;
    margin-right: 12px;
    flex-shrink: 0;
}
.discover-text { flex: 1; min-width: 0; }
.discover-title { font-size: 15px; color: #222; font-weight: 500; }
.discover-url {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.discover-arrow { color: #ccc; font-size: 20px; margin-left: 8px; flex-shrink: 0; }

/* 发现页 iframe 弹窗 */
.discover-popup {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #fff;
    z-index: 999;
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
}
.discover-popup-header {
    height: 44px;
    background: #f7f7f7;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    padding: 0 14px;
    flex-shrink: 0;
}
#discover-popup-title {
    flex: 1;
    font-size: 15px;
    color: #222;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.discover-close-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    font-size: 26px;
    color: #666;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-left: 8px;
}
.discover-close-btn:active { color: #07c160; }
#discover-popup-frame {
    width: 100%;
    flex: 1;
    border: 0;
    background: #fff;
}
.empty-tip { padding: 40px; text-align: center; color: #999; }

/* 在线状态指示点 */
.online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid #fff;
    position: absolute;
    right: -3px;
    bottom: -3px;
}
.online-dot.online { background: #07c160; }
.online-dot.offline { background: #bbb; }

/* 好友列表 */
.friend-row {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}
.friend-row:hover { background: #f8f8f8; }
.friend-row:last-child { border-bottom: none; }
.friend-avatar-wrap { position: relative; margin-right: 12px; flex-shrink: 0; }
.friend-avatar {
    width: 38px; height: 38px; border-radius: 6px;
    background: #07c160;
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.friend-dot {
    position: absolute; right: -2px; bottom: -2px;
    width: 10px; height: 10px; border-radius: 50%;
    border: 2px solid #fff;
}
.friend-dot.online { background: #4cd964; }
.friend-dot.offline { background: #c8c8c8; }
.friend-info { flex: 1; min-width: 0; }
.friend-name { font-size: 15px; color: #333; display: flex; align-items: center; }

/* 好友页顶部操作栏 */
.contacts-topbar {
    display: flex;
    align-items: center;
    background: #f7f7f7;
    border-bottom: 1px solid #e0e0e0;
    position: relative;
}
.contacts-topbar .contact-item {
    flex: 1;    display: block;
    padding: 12px 0;
    text-align: center;
    font-size: 13px;
    color: #333;
    border-right: 1px solid #e8e8e8;
}
.contacts-topbar .contact-item:last-of-type { border-right: none; }
.contacts-topbar .contact-item:active { background: #e8e8e8; }

.contact-menu-btn {
    width: 44px;
    text-align: center;
    font-size: 18px;
    color: #666;
    padding: 10px 0;
    cursor: pointer;
}
.contact-menu-btn:active { background: #e8e8e8; }

.contact-more-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 4px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 140px;
    overflow: hidden;
}
.contact-more-menu.show { display: block; }
.more-item {
    padding: 12px 16px;
    font-size: 14px;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.more-item:last-child { border-bottom: none; }
.more-item:active { background: #f5f5f5; }

/* 消息长按菜单 - 小优化 */
.context-menu.msg-menu {
    top: 40px;
    min-width: 130px;
}

/* 聊天列表中的红点（置顶标签） */
.pin-tag {
    display: inline-block;
    background: #07c160;
    color: #fff;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 3px;
    margin-right: 6px;
    line-height: 1.4;
}

/* 消息发送状态 */
.msg-status {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
	position: absolute;
    bottom: 0px;
    right: 0px;
}
.msg.self .msg-status { align-self: flex-end; }

/* toast */
#toast {
    position: fixed; top: 30%; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.7); color: #fff; padding: 10px 18px; border-radius: 6px;
    z-index: 999; font-size: 14px; display: none;
}

/* 通用 */
.view { min-height: 100%; }
button:disabled { opacity: .5; }
