/* ===== H5Chat 用户端样式：登录注册 + 聊天界面，支持深色模式 =====
   设计令牌只有这一处定义（参考项目把同一套令牌在 chat.css 与 login.css 里各写了一遍，
   容易出现改动不同步，这里合并为一份）。 */

:root {
    --body-bg: #EDEDED;
    --bg: #F8F9FC;
    --surface: #FFFFFF;
    --surface-2: #F0F2F5;
    --text: #1A1A2E;
    --muted: #888888;
    --muted-2: #B0B0B0;
    --border: rgba(0, 0, 0, 0.05);
    --border-solid: #EEF1F5;
    --accent: #4A90D9;
    --accent-dark: #3A7BC8;
    --accent-ring: rgba(74, 144, 217, 0.1);
    --bubble-self-text: #FFFFFF;
    --danger: #FF4757;
    --online: #88B04B;
    --shadow: rgba(0, 0, 0, 0.06);
    --shadow-strong: rgba(0, 0, 0, 0.15);
}

/* 深色模式开关写在 <html> 上：布局的 head 里就要应用，避免白底闪动 */
html[data-theme="dark"] {
    --body-bg: #0B0D12;
    --bg: #12141A;
    --surface: #1B1E27;
    --surface-2: #232733;
    --text: #E8EAF0;
    --muted: #9AA0AE;
    --muted-2: #6C7383;
    --border: rgba(255, 255, 255, 0.08);
    --border-solid: #2C313D;
    --danger: #FF6B6B;
    --shadow: rgba(0, 0, 0, 0.45);
    --shadow-strong: rgba(0, 0, 0, 0.6);
}

/* ===== 基础 ===== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--body-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 12px;
    color: var(--text);
}

button {
    font: inherit;
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
}

input,
textarea {
    font: inherit;
    color: inherit;
    outline: none;
}

.hidden {
    display: none !important;
}

/* ===== 手机容器 ===== */

.app-container,
.login-page {
    width: 100%;
    max-width: 420px;
    height: 780px;
    background: var(--bg);
    border-radius: 32px;
    box-shadow: 0 20px 60px var(--shadow-strong), 0 0 0 1px var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.login-page {
    background: var(--surface-2);
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* ===== 登录 / 注册 ===== */

.login-card {
    background: var(--surface);
    border-radius: 32px;
    padding: 40px 28px 32px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 12px 40px var(--shadow);
    text-align: center;
    max-height: 100%;
    overflow-y: auto;
}

.login-card .login-icon {
    font-size: 52px;
    line-height: 1.1;
    margin-bottom: 6px;
}

.login-card .login-header {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.login-card .login-sub {
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 28px;
}

.input-group {
    text-align: left;
    margin-bottom: 18px;
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
    opacity: 0.8;
}

.input-group input {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--border-solid);
    border-radius: 16px;
    font-size: 16px;
    background: var(--surface-2);
    color: var(--text);
    transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
}

.input-group input:focus {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 4px var(--accent-ring);
}

.input-group input::placeholder {
    color: var(--muted);
}

.error-hint {
    font-size: 13px;
    color: var(--danger);
    margin-top: 6px;
    display: none;
}

.error-hint.visible {
    display: block;
}

.login-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    color: #fff;
    border-radius: 16px;
    font-size: 18px;
    font-weight: 600;
    margin-top: 8px;
    box-shadow: 0 4px 14px var(--accent-ring);
    transition: transform 0.2s, background 0.2s;
}

.login-btn:active {
    transform: scale(0.97);
    background: var(--accent-dark);
}

.login-btn:disabled {
    opacity: 0.6;
    transform: scale(0.99);
    box-shadow: none;
}

.login-extra {
    margin-top: 20px;
    font-size: 13px;
    color: var(--muted);
}

.login-extra a,
.login-extra span {
    color: var(--accent);
    font-weight: 500;
    text-decoration: none;
}

/* ===== 视图栈 ===== */

.views {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.view {
    position: absolute;
    inset: 0;
    background: var(--bg);
    display: none;
    flex-direction: column;
}

.view.active {
    display: flex;
}

/* ===== 底部导航 ===== */

.tab-bar {
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 0 env(safe-area-inset-bottom, 8px) 0;
    flex-shrink: 0;
    box-shadow: 0 -2px 12px var(--shadow);
}

.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 0 4px 0;
    user-select: none;
    color: var(--muted-2);
    font-size: 12px;
    gap: 2px;
    position: relative;
}

.tab-item .tab-icon {
    font-size: 24px;
    line-height: 1;
    transition: transform 0.2s;
}

.tab-item .tab-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.tab-item.active {
    color: var(--accent);
}

.tab-item.active .tab-icon {
    transform: scale(1.05);
}

.tab-item .badge {
    position: absolute;
    top: 2px;
    right: 50%;
    transform: translateX(calc(50% + 18px));
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--surface);
}

/* ===== 通用头部 ===== */

.chat-list-header,
.friend-list-header,
.settings-header {
    padding: 20px 20px 12px 20px;
    background: var(--bg);
    flex-shrink: 0;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

/* 头部右侧的按钮组（通讯录右上角的「＋」与主题开关） */
.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-list-header h1,
.friend-list-header h1,
.settings-header h1 {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
}

.icon-btn {
    border: none;
    background: transparent;
    font-size: 20px;
    color: var(--muted);
    padding: 4px 6px;
    border-radius: 8px;
    line-height: 1;
}

.icon-btn:active {
    background: var(--surface-2);
}

.search-box {
    margin-top: 10px;
}

.search-box input {
    width: 100%;
    border: none;
    padding: 10px 14px;
    border-radius: 14px;
    background: var(--surface-2);
    font-size: 14px;
    color: var(--text);
}

.search-box input::placeholder {
    color: var(--muted-2);
}

/* ===== 聊天列表 ===== */

.chat-list,
.friend-list,
.settings-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 16px 8px 16px;
}

.chat-item,
.friend-item {
    margin-bottom: 8px;
    cursor: pointer;
    border-radius: 14px;
    box-shadow: 0 1px 3px var(--shadow);
    border: 1px solid transparent;
}

.friend-item {
    display: flex;
    align-items: center;
    padding: 14px 12px;
    background: var(--surface);
}

/* 左滑删除：外层裁切，整行内容跟着手指左移，红色删除从底下露出 */
.chat-item {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
    background: var(--surface);
}

.chat-item-main {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    padding: 14px 12px;
    background: var(--surface);
    border-radius: 14px;
    transition: transform .18s ease;
}

.chat-item.dragging .chat-item-main {
    transition: none;
}

.chat-item.show-delete .chat-item-main {
    transform: translateX(-84px);
}

.chat-item:active .chat-item-main,
.friend-item:active {
    background: var(--surface-2);
}

.chat-item-delete {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 84px;
    border: 0;
    border-radius: 0 14px 14px 0;
    background: #e54d42;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    z-index: 0;
    cursor: pointer;
}

.chat-item:active,
.friend-item:active {
    background: var(--surface-2);
}

.chat-item.pinned {
    border-color: var(--accent);
}

.chat-item .avatar,
.friend-item .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    margin-right: 14px;
    user-select: none;
}

.chat-item .info,
.friend-item .info {
    flex: 1;
    min-width: 0;
}

.chat-item .info .name,
.friend-item .info .name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .info .last-msg,
.friend-item .info .desc {
    font-size: 14px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .meta {
    flex-shrink: 0;
    text-align: right;
    margin-left: 8px;
}

.chat-item .meta .time {
    font-size: 12px;
    color: var(--muted-2);
    display: block;
}

.chat-item .meta .unread {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    margin-top: 4px;
}

/* ===== 聊天详情 ===== */

.chat-detail-header {
    display: flex;
    align-items: center;
    padding: 12px 12px 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-detail-header .back-btn {
    font-size: 26px;
    line-height: 1;
    padding: 0 8px 4px 0;
    color: var(--text);
}

.chat-detail-header .target-info {
    display: flex;
    align-items: center;
    flex: 1;
    margin-left: 4px;
    min-width: 0;
}

.chat-detail-header .target-info .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    margin-right: 10px;
    user-select: none;
}

.chat-detail-header .target-info .name {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-detail-header .target-info .status {
    font-size: 12px;
    color: var(--muted-2);
    margin-left: 8px;
    flex-shrink: 0;
}

.chat-detail-header .target-info .status.online {
    color: var(--online);
}

.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg);
}

.load-more {
    text-align: center;
    padding: 6px 0 10px;
}

.load-more button {
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    padding: 6px 14px;
    border-radius: 12px;
}

/* ===== 消息气泡 ===== */

.message-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 92%;
    animation: msgIn 0.25s ease;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

.message-item .msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    margin-top: 2px;
    user-select: none;
}

.message-item .msg-body {
    display: flex;
    flex-direction: column;
    max-width: 78%;
    min-width: 0;
}

.message-item .msg-body .msg-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
    padding: 0 4px;
}

.message-item .msg-body .msg-meta .msg-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
}

.message-item .msg-body .msg-meta .msg-time {
    font-size: 11px;
    color: var(--muted-2);
}

/* 群主标识：跟在群主昵称后面 */
.owner-badge {
    font-size: 10px;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 6px;
    color: #fff;
    background: var(--accent);
    align-self: center;
    user-select: none;
    white-space: nowrap;
}

/* 群主头像可点，点了直接开私聊 */
.message-item .msg-avatar.clickable {
    cursor: pointer;
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

.message-item .msg-avatar.clickable:active {
    transform: scale(0.94);
}

/* 群成员弹层里群主头像也可点 */
.sheet-row .avatar.clickable {
    cursor: pointer;
}

.sheet-row .avatar.clickable:active {
    transform: scale(0.94);
}

.message-item.self .msg-body .msg-meta {
    flex-direction: row-reverse;
}

.message-item.self .msg-body .msg-meta .msg-name {
    color: var(--accent);
}

.message-item .msg-body .msg-content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px var(--shadow);
    white-space: pre-wrap;
}

.message-item.self .msg-body .msg-content {
    background: var(--accent);
    color: var(--bubble-self-text);
    border-bottom-right-radius: 4px;
}

.message-item:not(.self) .msg-body .msg-content {
    border-bottom-left-radius: 4px;
}

.msg-content.media {
    padding: 0;
    background: transparent !important;
    box-shadow: none;
}

.msg-content.media img {
    max-width: 200px;
    max-height: 240px;
    border-radius: 14px;
    display: block;
    cursor: pointer;
}

/* 发送中与发送失败：参考界面没有这两个状态，沿用我们原有的处理 */
.message-item.sending .msg-content {
    opacity: 0.6;
}

.message-item.failed .msg-content {
    background: var(--danger);
    color: #fff;
}

.file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    color: var(--text);
    border-radius: 14px;
    text-decoration: none;
    box-shadow: 0 1px 4px var(--shadow);
    max-width: 240px;
}

.file-card .file-icon {
    font-size: 22px;
    flex-shrink: 0;
}

.file-card .file-info {
    min-width: 0;
}

.file-card .file-name {
    font-size: 13px;
    word-break: break-all;
}

.file-card .file-size {
    font-size: 11px;
    color: var(--muted-2);
}

/* ===== 表情面板 ===== */

.emoji-panel {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    max-height: 168px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex-shrink: 0;
}

.emoji-panel button {
    font-size: 20px;
    line-height: 1;
    padding: 4px;
    border-radius: 8px;
}

.emoji-panel button:active {
    background: var(--surface-2);
}

/* ===== 输入区 ===== */

.input-area {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    gap: 6px;
    /* 「回到底部」按钮的定位基准：贴在输入栏正上方，
       手机上输入栏是固定条、桌面壳里它在文档流，两种都能跟住 */
    position: relative;
}

/* ===== 回到底部 ===== */

.scroll-bottom-btn {
    position: absolute;
    right: 16px;
    bottom: calc(100% + 10px);
    width: 38px;
    height: 38px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--surface);
    color: var(--accent);
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--shadow-strong);
    user-select: none;
}

.scroll-bottom-btn:active {
    background: var(--surface-2);
}

/* 按钮右上角的未读数：你在上面看历史时新来的消息数（点回底部就清） */
.scroll-bottom-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    box-sizing: border-box;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

.input-area input[type="text"] {
    flex: 1;
    border: none;
    padding: 10px 16px;
    border-radius: 24px;
    background: var(--surface-2);
    font-size: 15px;
    color: var(--text);
    min-width: 0;
}

.input-area input[type="text"]::placeholder {
    color: var(--muted-2);
}

.input-area .send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
}

.input-area .send-btn:active {
    transform: scale(0.94);
    background: var(--accent-dark);
}

.input-area .send-btn:disabled {
    opacity: 0.5;
}

/* ===== 群冻结提示 ===== */

.frozen-banner {
    flex-shrink: 0;
    padding: 8px 16px;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    color: #8a5a00;
    background: #fff4d6;
    border-bottom: 1px solid #f0dca8;
}

@media (prefers-color-scheme: dark) {
    .frozen-banner {
        color: #f2c96a;
        background: #3a2f12;
        border-bottom-color: #5a4a1e;
    }
}

.input-area.frozen input[type="text"] {
    opacity: 0.6;
}

/* ===== 通讯录 ===== */

.friend-item .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--online);
    flex-shrink: 0;
}

.friend-item .status-dot.offline {
    background: var(--muted-2);
}

.friend-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.friend-more {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.friend-more:active {
    background: var(--surface-2);
}

/* ===== 底部操作面板 ===== */

.sheet-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 2500;
}

.sheet {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: 4px 12px calc(12px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: sheetIn 0.2s ease;
}

@keyframes sheetIn {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.sheet-title {
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    padding: 14px 8px 6px;
    word-break: break-all;
}

.sheet-hint {
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    padding: 0 8px 4px;
    line-height: 1.5;
}

.sheet-item {
    padding: 14px;
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 15px;
    text-align: center;
}

.sheet-item:active {
    opacity: 0.7;
}

.sheet-item.danger {
    color: var(--danger);
}

.sheet-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--surface-2);
    border: 2px solid var(--border-solid);
    font-size: 15px;
    color: var(--text);
}

.sheet-input:focus {
    border-color: var(--accent);
}

.sheet-primary {
    padding: 14px;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
}

.sheet-primary.danger {
    background: var(--danger);
}

.sheet-primary:disabled {
    opacity: 0.6;
}

/* 面板内的可滚动列表（群成员、入群申请等） */
.sheet-list {
    max-height: 46vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sheet-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 12px;
    background: var(--surface-2);
}

.sheet-row .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    user-select: none;
}

.sheet-row .sheet-row-main {
    flex: 1;
    min-width: 0;
}

.sheet-row .sheet-row-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-row .sheet-row-desc {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 会话列表里的群标识 */
.chat-item .group-tag {
    display: inline-block;
    margin-left: 6px;
    padding: 0 5px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    vertical-align: middle;
}

/* 通讯录里的群 / 邀请条目复用 request-item 的排版 */
.group-item .group-no {
    font-size: 12px;
    color: var(--muted);
}

.section-title {
    font-size: 12px;
    color: var(--muted);
    padding: 10px 4px 6px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* 列表的分组标题（按群名分组，点一下收起/展开）—— 通讯录和聊天列表共用。
   字号/字重/颜色照抄旁边那一行的名字（.chat-item .info .name），不然看着像注脚 */
.chat-group-head {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 10px 4px 6px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.chat-group-count {
    font-size: 13px;
    font-weight: 400;
    color: var(--muted);
}

/* 展开/收起的箭头在最左边：▾ = 展开，▸ = 收起。字号跟群名一样（16px/600），小了看不出开合 */
.chat-group-caret {
    flex-shrink: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1;
    color: var(--text);
}

/* 这一组的未读角标，贴最右边；样式照抄会话行上那个 .unread */
.chat-group-unread {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* 群名太长就截断，别把条数挤下去 */
.chat-group-name {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.section-add {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--accent);
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.section-add:active {
    background: var(--border-solid);
}

.sheet-row-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.request-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--surface);
    border-radius: 14px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px var(--shadow);
    gap: 10px;
}

.request-item .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}

.request-item .info {
    flex: 1;
    min-width: 0;
}

.request-item .info .name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.request-item .info .desc {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.request-item .actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.mini-btn {
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    background: var(--accent);
    color: #fff;
}

.mini-btn:disabled {
    opacity: 0.6;
}

.mini-btn.ghost {
    background: var(--surface-2);
    color: var(--muted);
}


/* ===== 设置 ===== */

.settings-group {
    background: var(--surface);
    border-radius: 14px;
    padding: 4px 0;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px var(--shadow);
}

.settings-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-item .icon {
    font-size: 20px;
    margin-right: 14px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.settings-item .label {
    flex: 1;
    font-size: 15px;
    color: var(--text);
}

.settings-item .value {
    font-size: 14px;
    color: var(--muted);
}

.settings-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    margin-right: 14px;
    flex-shrink: 0;
    user-select: none;
}

.settings-item .info {
    flex: 1;
    min-width: 0;
}

.settings-item .info .name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.settings-item .info .desc {
    font-size: 12px;
    color: var(--muted);
}

.settings-item .toggle {
    position: relative;
    width: 44px;
    height: 26px;
    background: var(--surface-2);
    border-radius: 13px;
    flex-shrink: 0;
    transition: background 0.25s;
}

.settings-item .toggle.active {
    background: var(--accent);
}

.settings-item .toggle .knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.25s;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.settings-item .toggle.active .knob {
    transform: translateX(18px);
}

.logout-item {
    justify-content: center;
    color: var(--danger);
    font-weight: 500;
    cursor: pointer;
}

/* ===== 图片预览 ===== */

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 24px;
    /* 放大后的图会摊到黑边以外，别让它把页面撑出滚动条 */
    overflow: hidden;
    /* iOS 上滑动手势会被浏览器当成「滚页面」→ 整个定图层跟着位移（图片看着偏、按钮也跟着跑）。
       交给 JS 自己处理手势，浏览器别插手（仍允许点击）。 */
    touch-action: none;
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    /* 放大后按住能拖：光标给个可拖的暗示；拖动中换成抓手 */
    cursor: grab;
    /* 缩放/平移走 transform，图片本身还是「适应屏幕」的尺寸 */
    z-index: 1;
}

.lightbox.dragging img {
    cursor: grabbing;
}

/* ===== 空状态 ===== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--muted-2);
}

.empty-state .emoji {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state .text {
    font-size: 15px;
}

/* ===== 轻提示 ===== */

.toast {
    position: fixed;
    left: 50%;
    bottom: 80px;
    transform: translateX(-50%) translateY(10px);
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    font-size: 13px;
    padding: 10px 18px;
    border-radius: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 3000;
    max-width: 80vw;
    text-align: center;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== 滚动条 ===== */

::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--muted-2);
    border-radius: 4px;
}

/* ===== 响应式 ===== */

@media (max-width: 440px) {
    body {
        padding: 0;
        background: var(--bg);

        /* 手机上壳就**铺满视口**：把基础样式里那套「flex 居中 + min-height:100vh」去掉。
           原因：iOS 地址栏可见时 100vh（大视口）> 100dvh（当前视口），壳会**被居中往下推**几十像素；
           而固定的顶栏/底栏是贴视口的 —— 于是顶栏下面露出一截壳的灰底、还会盖住消息
           （地址栏一隐藏就正常，所以是「有时」被挡）。 */
        display: block;
        min-height: 100dvh;
    }

    .app-container,
    .login-page {
        border-radius: 0;
        height: 100vh;
        height: 100dvh;
        max-width: 100%;
        box-shadow: none;
    }

    /* 各条固定栏的高度写成变量：高度定死，别的元素才能用 CSS 精确算出让位。
       （之前靠 JS 量高度，量早了/字体变了会飘，于是有时盖住输入框。） */
    :root {
        --tab-bar-h: 58px;
        --compose-h: 64px;
        /* 聊天详情顶栏高度：内容实际 37px + 上下各 12px 内边距 = 61，取 68 留点余量（矮了会裁内容、高了就多几 px 白边） */
        --detail-header-h: 68px;
    }

    /* 聊天详情顶栏（返回 + 彩种信息 + 右侧按钮）也**固定在最上面**：
       手机上整页会滚，不固定的话往上滚就看不见返回键和彩种了。
       高度**定死**（与下面 #view-chatdetail 让出的高度严格相等），否则字体一变顶栏就矮一点，
       底下会露出一截灰空白、还把消息区吃掉一块。 */
    .chat-detail-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 22;
        height: calc(var(--detail-header-h) + env(safe-area-inset-top, 0px));
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }

    /* 顶栏脱离文档流了，这个视图的内容（冻结提示 + 消息列表）整体下移一个顶栏高度 */
    #view-chatdetail {
        padding-top: calc(var(--detail-header-h) + env(safe-area-inset-top, 0px));
    }

    /* 图片预览：图尽量铺满屏幕 —— 左右各留 1px；上边离会话标题栏 1px、下边离底部导航 1px
       （他 2026-10-16：「图片太小了，看不大清楚…可以就比手机小一点就行，边间距不用留这么多，
       然后在固定的顶部下面1px，底部固定的上面1px」）。
       底部只让开最下面那条导航栏，输入栏那一行让图盖住，图才够大。 */
    .lightbox {
        padding: 1px;
        padding-top: calc(var(--detail-header-h) + env(safe-area-inset-top, 0px) + 1px);
        padding-bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px) + 1px);
    }

    /* 图按「铺满宽度」显示：宽度用满，高度按原图比例走，比一屏高就上下拖动看
       （他 2026-10-16：「图片宽度尽量宽一点，高度已经合适了」）。
       宽度再少 1px（他 2026-10-16），max-content = 原图宽度：本来就比屏幕窄的小图不放大，免得发虚。 */
    .lightbox img {
        width: calc(100% - 1px);
        max-width: max-content;
        max-height: none;
    }

    /* 底部导航（聊天/通讯录/设置）钉在视口底部。（桌面那个手机壳仍走 flex 布局，别动。） */
    .tab-bar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        height: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px));
    }

    /* 聊天输入栏也固定，**紧贴在导航栏上方 1px**（z-index 大一点，保证不被导航栏压住） */
    .input-area {
        position: fixed;
        left: 0;
        right: 0;
        z-index: 21;
        bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px) + 1px);
    }

    /* 表情面板跟着输入栏固定（原来在文档流里，会被固定后的输入栏压住） */
    .emoji-panel {
        position: fixed;
        left: 0;
        right: 0;
        z-index: 20;
        bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px) + 1px + var(--compose-h));
    }

    /* 两条栏脱离了文档流，各滚动区要留出它们的高度，否则最后一条会被压在下面 */
    .chat-list,
    .friend-list,
    .settings-list {
        padding-bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px) + 1px);
    }

    .message-list {
        padding-bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px) + 1px + var(--compose-h));
    }
}

@media (min-width: 441px) and (max-height: 820px) {
    .app-container,
    .login-page {
        height: 96vh;
        max-height: 780px;
    }
}

/* 通讯录里的游戏房间：房间号小标签与未读红点 */
.friend-actions .room-no {
    font-size: 11px;
    color: #8a8f99;
    background: rgba(127, 127, 127, .12);
    padding: 2px 6px;
    border-radius: 8px;
    margin-right: 6px;
}

.friend-actions .unread {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* 封盘 / 开奖提示以群主身份发普通消息，不再单独做样式 */

/* 添加群页的 6 位群号输入框（OTP 风格） */
.group-no-boxes {
    display: flex;
    gap: 10px;
    margin: 16px 0 8px;
    justify-content: center;
}

.group-no-boxes input {
    width: 48px;
    height: 56px;
    border: 2px solid var(--border-solid, #d2d6de);
    border-radius: 12px;
    background: var(--surface, #fff);
    color: var(--text, #333);
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    outline: none;
    caret-color: var(--accent, #009688);
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    transition: border-color .15s, box-shadow .15s;
}

.group-no-boxes input:focus {
    border-color: var(--accent, #009688);
    box-shadow: 0 0 0 3px var(--accent-ring, rgba(74, 144, 217, 0.15));
}

.group-no-boxes input.filled {
    border-color: var(--accent, #009688);
    background: var(--surface-2, #f0f2f5);
}

/* ---------- 没加群时的引导层（半透明透底盖在聊天界面上） ---------- */

.join-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(17, 18, 24, 0.45);
    backdrop-filter: blur(3px);
    padding: 16px;
    box-sizing: border-box;
}

.join-overlay.hidden {
    display: none;
}

.join-sheet {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: 18px 18px 14px 14px;
    padding: 22px 20px 20px;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.25);
    max-height: 88vh;
    overflow-y: auto;
}

.join-icon {
    font-size: 30px;
    text-align: center;
    line-height: 1;
}

.join-title {
    margin-top: 8px;
    text-align: center;
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
}

.join-desc {
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--muted);
    text-align: center;
}

/* 引导层里的 6 格群号：窄屏自动缩一点 */
.join-sheet .group-no-boxes {
    margin: 18px 0 12px;
    gap: 8px;
}

.join-sheet .group-no-boxes input {
    width: auto;
    flex: 1;
    min-width: 0;
    height: 52px;
    font-size: 22px;
}

.join-actions {
    display: flex;
    gap: 10px;
}

.join-primary,
.join-ghost {
    flex: 1;
    height: 44px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
}

.join-primary {
    background: var(--accent);
    color: #fff;
}

.join-primary:active {
    background: var(--accent-dark);
}

.join-ghost {
    background: var(--surface-2);
    color: var(--muted);
}

.join-hint {
    margin-top: 8px;
    min-height: 16px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.join-waiting {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--surface-2);
}

.join-waiting-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

.join-waiting-desc {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.7;
    color: var(--muted);
}

.join-waiting.hidden {
    display: none;
}

/* 引导层里找到的群 / 收到的邀请 */
.join-sheet .friend-item {
    background: var(--surface-2);
    border-radius: 12px;
    margin-top: 10px;
    border-bottom: none;
}

/* 记住密码的原生勾选框（H5 登录页没有 layui，直接一个原生小方框） */
.remember-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: -6px 0 14px;
}

.remember-row input[type="checkbox"] {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    margin: 0;
    padding: 0;
    accent-color: #009669;
    cursor: pointer;
}

.remember-row label {
    font-size: 13px;
    color: #6b7686;
    cursor: pointer;
}

/* 自定义头像（图片）：撑满原本的首字色块容器（圆形 + 裁切），没设头像时仍是首字色块 */
.avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* ===== 图片预览：左右切换（箭头实心看得清；只有一张图时不显示 .single；手机上也可左右滑动） ===== */

.lightbox-nav {
    position: absolute;
    /* 放大后图片会摊到箭头上面去，箭头抬起来，保证还点得到 */
    z-index: 3;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    color: #333333;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0 4px 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.lightbox-nav:hover {
    background: #ffffff;
}

.lightbox-nav.prev {
    left: 16px;
}

.lightbox-nav.next {
    right: 16px;
}

.lightbox.single .lightbox-nav {
    display: none;
}
