/* ==== 极简基础样式 —— M1 demo 阶段 ==== */
:root {
    --bg: #f7f7f8;
    --card: #ffffff;
    --text: #1f2328;
    --muted: #6e7681;
    --accent: #2563eb;
    --accent-2: #1d4ed8;
    --err: #d92d20;
    --border: #e5e7eb;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
    /* emoji 字体降级链：iOS / Windows / Linux / 通用 */
    --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", emoji;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* topbar */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 18px; color: var(--text); display: inline-flex; flex-direction: column; line-height: 1.1; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-name { font-weight: 700; font-size: 18px; color: var(--text); }
.brand-slogan { font-weight: 400; font-size: 11px; color: var(--muted); margin-top: 2px; }
.topnav { display: flex; gap: 14px; align-items: center; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

/* container */
.container { max-width: 720px; margin: 32px auto; padding: 0 16px; }
/* 聊天窗口页有侧边栏，需要更宽的容器（其余页面保持 720px） */
.container:has(.chat-window) { max-width: 1080px; }

/* auth card */
.auth-card { background: var(--card); padding: 28px; border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-card h1 { margin-top: 0; }
.auth-card label { display: block; margin-bottom: 14px; }
.auth-card label > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.auth-card label > span small { color: var(--muted); }
.auth-card input { width: 100%; padding: 10px 12px; font: inherit; border: 1px solid var(--border); border-radius: 8px; outline: none; }
.auth-card input:focus { border-color: var(--accent); }
.auth-card button { width: 100%; padding: 10px 12px; background: var(--accent); color: white; border: 0; border-radius: 8px; font: inherit; cursor: pointer; }
.auth-card button:hover:not(:disabled) { background: var(--accent-2); }
.auth-card button:disabled { opacity: .6; cursor: not-allowed; }
.auth-card .err { color: var(--err); margin-top: 10px; min-height: 1em; }
.auth-card .hint { text-align: center; margin-top: 14px; color: var(--muted); }

/* me card */
.me-card { background: var(--card); padding: 28px; border-radius: var(--radius); box-shadow: var(--shadow); }
.me-head { display: flex; align-items: center; gap: 16px; }
.me-info { flex: 1; min-width: 0; }
.avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 28px; }
.bio { color: var(--muted); margin: 6px 0 0; }

/* me bio inline 编辑 */
.bio-wrap { position: relative; }
.bio-wrap .bio {
    cursor: pointer;
    padding: 6px 10px;
    margin: 6px 0 0 -10px;
    border-radius: 6px;
    border: 1px dashed transparent;
    transition: background .15s, border-color .15s;
    display: inline-block;
    max-width: 100%;
    word-break: break-word;
}
.bio-wrap .bio:hover { background: var(--bg); border-color: var(--border); }
.bio-wrap .bio-empty { color: #b5b9be; font-style: italic; }
.bio-wrap .bio-edit-hint {
    margin-left: 6px;
    color: var(--muted);
    font-size: 12px;
    opacity: 0;
    transition: opacity .15s;
}
.bio-wrap .bio:hover .bio-edit-hint { opacity: 1; }
.bio-wrap .bio-edit { margin-top: 6px; }
.bio-wrap .bio-edit textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: var(--card);
    resize: vertical;
    min-height: 70px;
}
.bio-wrap .bio-edit textarea:focus { outline: none; border-color: var(--accent); }
.bio-wrap .bio-edit-actions {
    display: flex; align-items: center; gap: 10px;
    margin-top: 8px;
}
.bio-wrap .bio-count { font-size: 12px; margin-right: auto; }
.bio-wrap .bio-edit .err { margin: 6px 0 0; }
.me-meta { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.me-meta p { margin: 6px 0; color: var(--muted); }
.me-actions { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.btn-outline { padding: 8px 16px; font: inherit; font-size: 14px; border: 1px solid var(--border);
               border-radius: 8px; background: white; color: var(--text); cursor: pointer; }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* 修改密码弹窗内表单 */
.modal-box label { display: block; margin-bottom: 12px; }
.modal-box label > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.modal-box label > span small { color: var(--muted); }
.modal-box input { width: 100%; padding: 9px 12px; font: inherit; border: 1px solid var(--border); border-radius: 8px; outline: none; }
.modal-box input:focus { border-color: var(--accent); }
.modal-box .err { color: var(--err); font-size: 13px; margin: 4px 0; }
.modal-box .ok { color: #15803d; font-size: 13px; margin: 4px 0; }

.footer { text-align: center; color: var(--muted); padding: 24px 0; font-size: 12px; }

/* ============== M2: badge / friends page / notifications ============== */
.badge { display: inline-block; min-width: 18px; padding: 0 6px; height: 18px; line-height: 18px;
         text-align: center; background: var(--err); color: white; border-radius: 9px;
         font-size: 11px; vertical-align: top; margin-left: 4px; }
.badge.hidden { display: none; }

/* 中性计数（灰底小胶囊）：用于展示数量，不是提醒/未读 */
.count { display: inline-block; min-width: 18px; padding: 0 6px; height: 18px; line-height: 18px;
         text-align: center; background: #e5e7eb; color: #374151; border-radius: 9px;
         font-size: 11px; font-weight: 600; vertical-align: top; margin-left: 4px; }
.count.hidden { display: none; }

.card { background: var(--card); padding: 18px 22px; border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 16px; }
.card h2 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.empty { margin: 0; }
.err { color: var(--err); font-size: 13px; }

/* friends */
.friends-page h1 { margin-bottom: 16px; }
.friends-page .user-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.friends-page .user-row:last-child { border-bottom: 0; }
.friends-page .user-row .avatar { width: 36px; height: 36px; font-size: 16px; }
.friends-page .user-link {
    display: inline-flex; align-items: center; gap: 10px;
    text-decoration: none; color: inherit;
    padding: 4px 8px; border-radius: 8px;
    margin-left: -8px;
    transition: background .15s;
}
.friends-page .user-link:hover { background: var(--bg); }
.friends-page .username { font-weight: 600; }
.friends-page .timestamp { color: var(--muted); font-size: 12px; flex: 1; }
.friends-page ul { list-style: none; margin: 8px 0 0; padding: 0; }
.friends-page .user-list { list-style: none; margin: 0; padding: 0; }
.friends-page .btn { background: white; border: 1px solid var(--border); color: var(--text);
                       padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.friends-page .btn:hover { background: var(--bg); }
.friends-page .btn-primary { background: var(--accent); color: white; border-color: var(--accent); }

/* ============ me 页：我的朋友圈 ============ */
.me-posts { margin-top: 16px; padding: 0; }
.me-posts-title {
    margin: 0;
    padding: 16px 22px 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}
.me-posts .empty { padding: 24px; }

/* ============ Friends tabs ============ */
.friends-page { max-width: 760px; margin: 0 auto; }
.friends-page > h1 { margin: 8px 4px 16px; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }

.friends-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
    padding: 0 4px;
}
.friends-tabs .tab-btn {
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color .15s, border-color .15s;
}
.friends-tabs .tab-btn:hover { color: var(--text); }
.friends-tabs .tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}
.friends-tabs .tab-btn .badge {
    background: var(--err);
    color: white;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 999px;
}
.friends-tabs .tab-count {
    color: var(--muted);
    font-weight: 400;
    font-size: 12px;
}
.friends-tabs .tab-btn.active .tab-count { color: var(--accent); }

.tab-panel { margin-top: 0; }   /* 第一个 panel 的 margin 由卡片自带 .card 处理 */

/* ============ 用户主页（/u/<username>） ============ */
.profile-page { max-width: 640px; margin: 0 auto; }
.profile-head {
    display: flex; gap: 18px; align-items: flex-start;
    padding: 22px;
}
.profile-head .avatar-lg {
    width: 72px; height: 72px; font-size: 28px; flex-shrink: 0;
}
.profile-meta { flex: 1; min-width: 0; }
.profile-meta h1 {
    margin: 0 0 4px; font-size: 22px; font-weight: 700;
    letter-spacing: -.01em; color: var(--text);
}
.profile-bio { margin: 0 0 12px; line-height: 1.5; }
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.profile-section-title {
    margin: 0; padding: 16px 22px 8px;
    font-size: 14px; font-weight: 600; color: var(--muted);
    border-bottom: 1px solid var(--border);
}
.like-readonly {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 14px; color: var(--muted);
    padding: 4px 8px; border-radius: 16px;
    border: 1px solid var(--border);
}
.friends-page .btn-primary:hover { background: var(--accent-2); }
.friends-page .btn:disabled { opacity: .5; cursor: not-allowed; }
.friends-page form { display: flex; gap: 8px; margin-top: 8px; }
.friends-page form input[type="text"] { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font: inherit; outline: none; }
.friends-page form input[type="text"]:focus { border-color: var(--accent); }
.friends-page form button { padding: 8px 16px; background: var(--accent); color: white; border: 0; border-radius: 6px; cursor: pointer; font: inherit; }
.friends-page form button:disabled { opacity: .5; cursor: not-allowed; }
.friends-page .results { margin-top: 10px; }
.friends-page .results ul { list-style: none; padding: 0; margin: 8px 0 0; }

/* notifications dropdown */
.notif-wrap { position: relative; display: inline-block; }
.notif-btn { background: transparent; border: 0; cursor: pointer; font: inherit; color: var(--text); padding: 0; }
.notif-dropdown { position: absolute; right: 0; top: calc(100% + 6px); width: 320px; max-height: 400px; overflow-y: auto;
                  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
                  z-index: 50; padding: 8px 0; }
.notif-dropdown.hidden { display: none; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:hover { background: var(--bg); }
.notif-item:last-child { border-bottom: 0; }
.notif-item.unread { background: #eff6ff; }

/* ============== 用户菜单（顶栏最右：用户名 + 下拉） ============== */
.user-menu { margin-left: auto; position: relative; display: inline-block; }  /* ml-auto 推到最右 */
.user-menu-btn { background: transparent; border: 1px solid transparent; cursor: pointer;
                 font: inherit; color: var(--text); padding: 4px 10px; border-radius: 6px;
                 display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.user-menu-btn:hover { background: var(--bg); border-color: var(--border); }
.user-menu-btn[aria-expanded="true"] { background: var(--bg); border-color: var(--border); }
.user-menu-caret { font-size: 10px; opacity: .6; transition: transform .15s; }
.user-menu-btn[aria-expanded="true"] .user-menu-caret { transform: rotate(180deg); }
.user-menu-dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 160px;
                      background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
                      box-shadow: var(--shadow); z-index: 50; padding: 4px 0; }
.user-menu-dropdown.hidden { display: none; }
.user-menu-item { display: flex; align-items: center; gap: 8px; width: 100%;
                   padding: 10px 14px; font: inherit; color: var(--text);
                   background: transparent; border: 0; text-align: left; cursor: pointer;
                   text-decoration: none; box-sizing: border-box; }
.user-menu-item:hover { background: var(--bg); text-decoration: none; }
.user-menu-item-danger { color: var(--err); }
.user-menu-item-danger:hover { background: #fef2f2; }

/* ============== 语言切换（顶栏右侧） ============== */
.lang-switch { position: relative; display: inline-block; margin-left: 6px; }
.lang-switch-btn { background: transparent; border: 1px solid var(--border);
                   font: inherit; color: var(--text); padding: 4px 8px; border-radius: 6px;
                   cursor: pointer; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.lang-switch-btn:hover { background: var(--bg); }
.lang-switch-btn[aria-expanded="true"] { background: var(--bg); }
.lang-caret { font-size: 10px; opacity: .6; transition: transform .15s; }
.lang-switch-btn[aria-expanded="true"] .lang-caret { transform: rotate(180deg); }
.lang-switch-dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 120px;
                        background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
                        box-shadow: var(--shadow); z-index: 50; padding: 4px 0; }
.lang-switch-dropdown.hidden { display: none; }
.lang-switch-item { display: flex; align-items: center; gap: 8px; width: 100%;
                    padding: 6px 12px; color: var(--text); text-decoration: none; font-size: 13px; }
.lang-switch-item:hover { background: var(--bg); text-decoration: none; }
.lang-switch-item.active { font-weight: 600; color: var(--primary); }

.notif-item .notif-row { display: flex; align-items: center; gap: 6px; }
.notif-item .actor { font-weight: 600; flex-shrink: 0; }
.notif-item .text { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-item .time { color: var(--muted); font-size: 11px; margin-top: 2px; }
.notif-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.notif-empty { text-align: center; color: var(--muted); padding: 20px; }

/* ============== M3: chat ============== */
.chat-list { max-width: 760px; margin: 0 auto; }
.chat-list > h1 {
    margin: 8px 4px 20px;
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.01em;
}
.chat-list .empty {
    background: var(--card);
    padding: 36px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    color: var(--muted);
}

/* 分组：每个联系人一张卡 */
.conv-groups { display: flex; flex-direction: column; gap: 12px; }
.conv-group {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* 分组头：左半边是头像+名字链接，右半边是会话数/badge/按钮 */
.conv-group-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.conv-group-user {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 4px 10px;
    margin-left: -10px;     /* 让头像贴回左边边缘 */
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background .15s;
}
.conv-group-user:hover { background: #eef0f3; text-decoration: none; }
.conv-group-head .avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
    flex-shrink: 0;
}
.conv-group-head strong {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.conv-group-head .muted {
    font-size: 12px;
    color: var(--muted);
}
.conv-group-head .badge { margin-left: auto; }
.conv-group-head .group-add {
    margin-left: 6px;
    padding: 5px 10px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 999px;       /* 胶囊形，跟整体现代风一致 */
    background: var(--card);
    color: var(--accent);
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.conv-group-head .group-add:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* 会话行：统一布局，时间戳绝对靠右 */
.conv-row {
    display: flex;
    align-items: stretch;
    gap: 4px;
    border-bottom: 1px solid var(--border);
}
.conv-row:last-child { border-bottom: 0; }
.conv-row:hover { background: var(--bg); }

.conv-link {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    padding: 14px 8px 14px 18px;
    text-decoration: none;
    color: var(--text);
    gap: 12px;
}
.conv-link:hover { text-decoration: none; }   /* 压过全局 a:hover 的下划线 */
.conv-link .conv-body { flex: 1; min-width: 0; }

/* 顶部行：标题 + 时间，标题 flex:1 让时间始终贴右 */
.conv-row .conv-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.conv-row .conv-topic {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* 不设 flex: 1：让 topic 自适应内容宽度，时间戳紧跟在 topic 后面而不是被推到最右
       长 topic 自然撑满到右边；短 topic（如"默认对话"）时间戳就贴左对齐，看起来一致 */
    max-width: 100%;
    min-width: 0;
}
/* "默认对话" 弱化为纯文本（去掉背景色块），跟主题会话视觉一致 */
.conv-row .conv-topic.default-topic {
    color: var(--muted);
    font-weight: 500;
}
.conv-row .conv-topic .tag { display: none; }   /* 旧版带背景色的 tag 完全关掉 */

.conv-row .conv-time {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    flex: none;
    margin-left: 12px;
}

.conv-row .conv-preview {
    font-size: 13px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-row .badge.unread {
    background: var(--err);
    color: white;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 999px;
    flex: none;
}

.conv-del {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
    padding: 6px 14px 6px 6px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity .15s;
    align-self: center;
}
.conv-row:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--err); background: rgba(217,45,32,.08); }

.conv-row .chevron { color: var(--muted); font-size: 18px; }

/* "查看全部 (N)" 链接：弱化、居中、上下留白 */
.conv-group-more {
    text-align: center;
    padding: 12px 18px;
    border-top: 1px dashed var(--border);
}
.conv-group-more a {
    display: inline-block;
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 999px;
    transition: background .15s;
}
.conv-group-more a:hover {
    background: var(--bg);
    text-decoration: none;
}

.chat-list .open {
    background: var(--accent);
    color: white;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    text-decoration: none;
}
.chat-list .badge.unread { background: var(--err); }

/* 响应式：小屏上下 padding 收紧一点 */
@media (max-width: 600px) {
    .conv-group-head { padding: 12px 14px; }
    .conv-link { padding: 12px 6px 12px 14px; }
}

/* 聊天窗口 */
.chat-window { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
                display: flex; flex-direction: row; height: calc(100vh - 200px); min-height: 480px; overflow: hidden; }

/* 左栏：与当前好友的其它主题会话 */
.cw-side { width: 220px; flex: none; border-right: 1px solid var(--border); background: #f7f8fa;
            display: flex; flex-direction: column; overflow-y: auto; padding: 10px 8px; }
.cw-side-head { font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 8px 10px; }
.cw-side-item { display: flex; align-items: center; justify-content: space-between; gap: 6px;
                padding: 7px 10px; margin-bottom: 2px; border-radius: 8px; color: var(--text);
                text-decoration: none; font-size: 14px; transition: background .12s; }
.cw-side-item:hover { background: rgba(0,0,0,.05); }
.cw-side-item.active { background: var(--accent); color: #fff; font-weight: 500; }
.cw-side-item .cw-side-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-side-item .badge.unread { flex: none; }

/* 聊天主区 */
.cw-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* 手机端顶部主题条（横向滚动） */
.cw-topic-strip { display: none; }

.cw-topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cw-topbar .avatar { width: 36px; height: 36px; font-size: 16px; }
.cw-topbar-user {
    text-decoration: none; color: inherit;
    border-radius: 4px;
}
.cw-topbar-user:hover { text-decoration: underline; color: var(--accent); }
.cw-side-head a { text-decoration: none; color: var(--muted); }
.cw-side-head a:hover { color: var(--accent); }
.cw-messages { flex: 1; overflow-y: auto; padding: 14px; background: #fafbfc; }
.bubble-row { display: flex; margin-bottom: 10px; }
.bubble-row.mine { justify-content: flex-end; }
.bubble { max-width: 70%; padding: 8px 12px; background: white; border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
           word-break: break-word; }
.bubble-row.mine .bubble { background: var(--accent); color: white; }
.bubble-row.mine .bubble .ts { color: rgba(255,255,255,.7); }
.bubble .ts { font-size: 11px; margin-top: 4px; }
.bubble-img { max-width: 240px; max-height: 240px; border-radius: 8px; display: block; cursor: zoom-in; }
.bubble audio { display: block; max-width: 240px; }

/* 文件卡片 */
.file-card { display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 280px;
             padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.bubble-row.mine .file-card { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); }
.file-ico { font-size: 26px; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 11px; }
.file-dl { font-size: 12px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.bubble-row.mine .file-dl { color: #fff; text-decoration: underline; }
.file-dl:hover { text-decoration: underline; }
.loading-history { text-align: center; padding: 8px; }

.cw-input { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; border-top: 1px solid var(--border); background: white; }
.cw-input textarea { flex: 1; resize: none; min-height: 38px; max-height: 120px;
                       padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit; outline: none; }
.cw-input textarea:focus { border-color: var(--accent); }
.cw-input .ico { width: 40px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
                   cursor: pointer; border: 1px solid var(--border); border-radius: 8px; background: white; position: relative; color: var(--text);
                   font-family: var(--font-emoji); }
.cw-input .ico input { display: none; }
.cw-input .ico.rec { background: var(--err); color: white; border-color: var(--err); }
.cw-input .btn-send { padding: 0 16px; height: 38px; background: var(--accent); color: white; border: 0; border-radius: 8px; cursor: pointer; font: inherit; }
.cw-input .btn-send:disabled { opacity: .5; cursor: not-allowed; }

/* 实时连接状态：正常是 muted，离线变红色 */
.cw-conn-offline { color: var(--err, #e74c3c) !important; font-weight: 600; }
.cw-reconnect { background: var(--err, #e74c3c); color: white; border-color: var(--err, #e74c3c); }

/* ========== 桌面端：.cw-toolbar 不产生盒子，子元素直接参与父 flex ========== */
.cw-input .cw-toolbar { display: contents; }
/* 桌面端：隐藏 mobile 专属的图标标签 */
.ico-lbl { display: none; }

/* Alpine x-cloak：初始隐藏（防闪烁） */
[x-cloak] { display: none !important; }

/* 主题弹窗 */
.modal { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.5);
         display: flex; align-items: center; justify-content: center; }
.modal-box { background: white; padding: 24px 28px; border-radius: 12px; box-shadow: 0 8px 40px rgba(0,0,0,.3);
             width: 360px; max-width: 90vw; }
.modal-box h3 { margin-top: 0; }
.modal-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit; margin: 8px 0 16px; }
.modal-box input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions .btn { padding: 8px 16px; }

/* 聊天窗口顶部标题 + 主题 */
.cw-title { display: flex; flex-direction: column; line-height: 1.2; }
.cw-topic { font-size: 12px; }
.btn-sm { padding: 4px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 6px;
          background: white; color: var(--accent); cursor: pointer; }
.btn-sm:hover { background: var(--bg); }
.btn-sm.danger { color: var(--err); border-color: #f3c1bc; }
.btn-sm.danger:hover { background: rgba(217,45,32,.06); }

/* 其他会话新消息横幅 */
.other-msg-banner { display: flex; align-items: center; gap: 6px; padding: 10px 16px;
                    background: #eff6ff; border-bottom: 1px solid #bfdbfe; cursor: pointer;
                    font-size: 14px; }
.other-msg-banner:hover { background: #dbeafe; }
.other-msg-banner .muted { margin-left: auto; }
.conv-topic { color: var(--accent); font-size: 13px; }

/* 默认会话（无 title 的通用会话）标注：醒目琥珀色背景 + 深色字 */
.default-topic { display: inline-flex; align-items: center; gap: 4px; }
.default-topic .tag { background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
                      font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px;
                      letter-spacing: .5px; }

/* 图片预览 popup（lightbox） */
.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.85);
            display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,.5); }
.lightbox-close { position: absolute; top: 16px; right: 20px; background: rgba(255,255,255,.15);
                  color: white; border: 0; border-radius: 50%; width: 40px; height: 40px;
                  font-size: 24px; line-height: 1; cursor: pointer; }
.lightbox-close:hover { background: rgba(255,255,255,.3); }

/* ============== 移动端适配 (max-width: 600px) ============== */
@media (max-width: 600px) {
  /* 聊天窗口：隐藏左栏，改用顶部横向主题条 */
  .chat-window { flex-direction: column; }
  .cw-side { display: none; }
  .cw-topic-strip { display: flex; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border);
                    background: #fff; overflow-x: auto; -webkit-overflow-scrolling: touch; flex: none; }
  .cw-topic-chip { flex: none; display: inline-flex; align-items: center; gap: 5px;
                   padding: 4px 10px; border-radius: 999px; background: #f0f1f3; color: var(--text);
                   text-decoration: none; font-size: 13px; white-space: nowrap; }
  .cw-topic-chip.active { background: var(--accent); color: #fff; }
  .cw-topic-chip .badge.unread { flex: none; }

  /* 消息气泡：自己发的（mine 端，右侧）放宽到 88%，避免 audio 自然宽度溢出；
     别人的保留 75%，因为别人的语音框看起来正常 */
  .bubble { max-width: 75%; }
  .bubble-row.mine .bubble { max-width: 88%; }

  /* 顶栏精简：隐藏主题名、连接状态文字、新主题按钮的文字 */
  .cw-topbar { padding: 10px 12px; gap: 6px; }
  .cw-topbar .cw-topic { display: none; }
  .cw-topbar .cw-conn { display: none; }
  .cw-topbar .btn { padding: 6px 8px; font-size: 13px; }
  .cw-topbar .cw-new-topic-text { display: none; }
  .cw-topbar .avatar { width: 32px; height: 32px; font-size: 14px; }

  /* 输入区：上下两行布局
     上排：textarea 占满整行；下排：4 个功能按钮平铺 */
  .cw-input { flex-direction: column; padding: 8px 10px; gap: 6px; }
  .cw-input textarea { width: 100%; min-height: 38px; max-height: 120px; }

  /* 第二行：4 个按钮平铺 */
  .cw-input .cw-toolbar { display: flex; gap: 6px; align-items: stretch; }
  .cw-input .cw-toolbar .ico {
      flex: 1; min-width: 0; height: 50px;
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      gap: 2px; padding: 0;
      border: 1px solid var(--border); border-radius: 8px;
      background: white; color: var(--text);
      font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .cw-input .cw-toolbar .ico input { display: none; }
  .cw-input .cw-toolbar .ico .ico-em { font-size: 20px; line-height: 1; }
  .cw-input .cw-toolbar .ico .ico-lbl { font-size: 11px; line-height: 1.2; font-family: inherit; }
  /* 录音态：按钮整体变红 + 变宽（容纳"录音中 60s"），同时缩小字号 */
  .cw-input .cw-toolbar .ico.rec {
      flex: 1.5; background: var(--err); color: white; border-color: var(--err);
  }
  .cw-input .cw-toolbar .ico.rec .ico-em,
  .cw-input .cw-toolbar .ico.rec .ico-lbl { color: white; }
  .cw-input .cw-toolbar .ico.rec .ico-lbl { font-size: 10px; }

  /* 发送键：比图标按钮更宽（容纳"发送"二字不被压扁），横排，14px 字号 */
  .cw-input .cw-toolbar .btn-send {
      flex: 1.4; min-width: 0; height: 50px;
      display: flex; flex-direction: row; align-items: center; justify-content: center;
      gap: 0; padding: 0 12px;
      border: 1px solid var(--accent); border-radius: 8px;
      background: var(--accent); color: white;
      font-size: 15px; line-height: 1; font-family: inherit;
      cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .cw-input .cw-toolbar .btn-send:disabled { opacity: .5; cursor: not-allowed; }
}

/* ============== 头像（带图片时） ============== */
.avatar { position: relative; overflow: hidden; }  /* 防止 img 溢出圆形 */
.avatar.has-image { background: var(--bg); }
.avatar img { width: 100%; height: 100%; border-radius: 50%;
              object-fit: cover; display: block; position: absolute; inset: 0; }
.avatar.clickable { cursor: pointer; transition: opacity .15s; }
.avatar.clickable:hover { opacity: .85; }

/* ============== 头像 picker ============== */
.avatar-picker-box { width: 460px; max-width: 92vw; }
.avatar-picker-section { margin-bottom: 18px; }
.avatar-picker-section h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.avatar-picker-section input[type="file"] {
    display: block; margin-top: 4px; font: inherit; font-size: 13px;
}
.avatar-picker-grid { display: grid; grid-template-columns: repeat(4, 1fr);
                     gap: 12px; margin: 8px 0 0; }
.avatar-picker-item {
    width: 100%; aspect-ratio: 1; border-radius: 50%;
    cursor: pointer; border: 3px solid transparent; overflow: hidden;
    padding: 0; background: var(--bg); transition: transform .15s, border-color .15s;
}
.avatar-picker-item img { width: 100%; height: 100%; display: block; border-radius: 50%; }
.avatar-picker-item:hover { transform: scale(1.05); }
.avatar-picker-item.selected { border-color: var(--accent); }

/* ============ M4: Feed / Posts ============ */
.feed-page { max-width: 640px; margin: 0 auto; }
.feed-composer textarea {
    width: 100%; min-height: 70px; resize: vertical;
    border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font: inherit; color: var(--text);
    background: var(--card); box-sizing: border-box;
}
.feed-composer textarea:focus { outline: none; border-color: var(--accent); }
.composer-preview { position: relative; margin-top: 10px; display: inline-block; }
.composer-preview img { max-width: 200px; max-height: 200px; border-radius: 8px; display: block; }
.composer-preview button {
    position: absolute; top: 4px; right: 4px;
    background: rgba(0,0,0,.6); color: #fff; border: none;
    border-radius: 50%; width: 24px; height: 24px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
}
.composer-preview button:hover { background: rgba(0,0,0,.8); }
.composer-actions {
    display: flex; align-items: center; gap: 12px;
    margin-top: 10px;
}
.composer-actions .ico {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer; color: var(--muted); user-select: none;
}
.composer-actions .ico:hover { border-color: var(--accent); color: var(--accent); }
.composer-actions input[type="file"] { display: none; }
.composer-actions .btn-primary { margin-left: auto; }
.composer-hint { font-size: 12px; margin-left: auto; }
.composer-hint + .btn-primary { margin-left: 0; }

.feed-list { padding: 0; }
.post {
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
}
.post:last-child { border-bottom: none; }
.post-head {
    display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.avatar-sm { width: 36px; height: 36px; font-size: 16px; flex-shrink: 0; }
.post-avatar { display: block; line-height: 0; text-decoration: none; }
.post-meta { flex: 1; min-width: 0; }
.post-author { font-weight: 600; color: var(--text); line-height: 1.2; text-decoration: none; }
.post-author:hover { text-decoration: underline; color: var(--accent); }
.post-time { font-size: 12px; line-height: 1.2; margin-top: 2px; }
.post-del {
    margin-left: auto; background: transparent; border: none;
    color: var(--muted); cursor: pointer; font-size: 16px;
    padding: 4px 8px; border-radius: 6px;
}
.post-del:hover { color: var(--err); background: var(--bg); }
.post-body {
    white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
    color: var(--text); line-height: 1.6; margin: 6px 0;
    font-size: 15px;
}
.post-image { display: block; margin-top: 8px; }
.post-image img {
    max-width: 100%; max-height: 480px;
    border-radius: 8px; border: 1px solid var(--border);
    display: block;
}
.feed-more { padding: 16px; text-align: center; border-top: 1px solid var(--border); }
.empty { padding: 32px; text-align: center; }
.empty p { margin: 0; }

/* ============ M4: 点赞 + 评论 + 图片 popup ============ */
.post-image-wrap { margin-top: 8px; }
.post-image {
    cursor: zoom-in;
    max-width: 100%; max-height: 480px;
    border-radius: 8px; border: 1px solid var(--border);
    display: block;
}

.like-bar {
    display: flex; align-items: center; gap: 10px;
    margin-top: 10px; padding-top: 8px;
    border-top: 1px solid var(--border);
}
.like-btn {
    background: transparent; border: 1px solid var(--border); border-radius: 16px;
    padding: 4px 10px; font-size: 14px; cursor: pointer;
    color: var(--muted); display: inline-flex; align-items: center; gap: 4px;
    transition: background .15s, border-color .15s, color .15s;
}
.like-btn:hover { border-color: var(--accent); color: var(--accent); }
.like-btn.liked { color: var(--err); border-color: var(--err); }
.like-users {
    display: inline-flex; align-items: center; gap: -4px;
}
.like-users > * { margin-left: -4px; border: 2px solid var(--card); border-radius: 50%; }
.like-users > *:first-child { margin-left: 0; }
.avatar-xs { width: 22px; height: 22px; font-size: 11px; flex-shrink: 0; }

.post-comments {
    margin-top: 8px;
    background: var(--bg);
    border-radius: 8px;
    padding: 8px 12px;
}
.comment-item {
    font-size: 14px; line-height: 1.6;
    color: var(--text);
    display: flex; align-items: flex-start; gap: 6px;
    padding: 3px 0;
}
.comment-author { color: var(--accent); font-weight: 600; flex-shrink: 0; text-decoration: none; }
.comment-author:hover { text-decoration: underline; }
.comment-body { flex: 1; word-wrap: break-word; overflow-wrap: anywhere; }
.comment-del {
    background: transparent; border: none; color: var(--muted);
    cursor: pointer; font-size: 12px; padding: 0 4px; line-height: 1;
    visibility: hidden;
}
.comment-item:hover .comment-del { visibility: visible; }
.comment-del:hover { color: var(--err); }
.comment-input {
    display: flex; gap: 6px; margin-top: 6px;
    padding-top: 6px; border-top: 1px dashed var(--border);
}
.comment-input input {
    flex: 1; min-width: 0;
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 16px;
    font: inherit; background: var(--card); color: var(--text);
}
.comment-input input:focus { outline: none; border-color: var(--accent); }

/* ============ @ 提及 ============ */
.comment-input-wrap { position: relative; }
.mention-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 200px;
    overflow-y: auto;
    min-width: 180px;
    z-index: 50;
    padding: 4px;
}
.mention-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 10px;
    border: 0;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    color: var(--text);
    text-align: left;
}
.mention-item:hover { background: var(--bg); }
.mention-item.selected { background: var(--bg); outline: 1px solid var(--accent); }
.mention-empty {
    padding: 8px 10px;
    color: var(--muted);
    font-size: 13px;
}
.mention-link {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}
.mention-link:hover { text-decoration: underline; }

/* ============ 图片 popup（遮罩 + 居中 + ESC 关闭） ============ */
.img-popup {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.img-popup-overlay {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, .82);
}
.img-popup-img {
    position: relative; z-index: 1;
    max-width: 95vw; max-height: 92vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,.5);
    background: var(--bg);
}
.img-popup-close {
    position: fixed; top: 16px; right: 16px; z-index: 2;
    background: rgba(0,0,0,.5); color: #fff; border: none;
    border-radius: 50%; width: 36px; height: 36px;
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
}
.img-popup-close:hover { background: rgba(0,0,0,.75); }


