/* ============================================
   公共样式 - 自适应 + 字体大小控制
   使用 rem 单位，基础字号由 <html> 的 font-size 决定
   默认自适应：屏幕宽度 375px 时对应 2.4vw，约 9px
   ============================================ */

/* ---------- 全局重置 & 自适应 ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* 基础字号：以 375px 宽度为基准，2.4vw ≈ 9px */
    font-size: 2.4vw;
    /* 大屏限制最大字号，防止过大 */
}
@media (min-width: 600px) {
    html {
        font-size: 14px;
    }
}
@media (max-width: 320px) {
    html {
        font-size: 2.2vw;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #ededed;
    line-height: 1.5;
    width: 100%;
    height: 100%;
    height: 100dvh; /* 动态视口高度，适配移动端 */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
}

/* ---------- 顶部导航 ---------- */
.header {
    background: #1a8c5e;
    color: #fff;
    padding: 0.8rem 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 4rem;
    z-index: 100;
    position: relative;
    font-size: 1rem;
}
.header .notify-btn {
    font-size: 1.3rem;
    cursor: pointer;
    width: 2.5rem;
    text-align: left;
    position: relative;
}
.header .notify-btn .badge {
    font-size: 0.5rem;
    background: #ff4444;
    color: #fff;
    border-radius: 50%;
    padding: 0.1rem 0.5rem;
    position: absolute;
    top: -0.3rem;
    left: 1.5rem;
}
.header .title {
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 0.4rem;
}
.header .title .member-badge {
    font-size: 0.65rem;
    font-weight: 400;
    opacity: 0.85;
    margin-left: 0.3rem;
}
.header .menu-btn {
    font-size: 1.5rem;
    cursor: pointer;
    width: 2.5rem;
    text-align: right;
}
.header .back-btn {
    font-size: 1.3rem;
    cursor: pointer;
    width: 2.5rem;
    text-align: left;
    display: none;
}

/* ---------- 菜单面板 ---------- */
.menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 200;
    justify-content: flex-end;
    align-items: flex-start;
    padding-top: 4.5rem;
    padding-right: 1rem;
}
.menu-overlay.active { display: flex; }
.menu-panel {
    background: #fff;
    border-radius: 1rem;
    padding: 0.4rem 0;
    min-width: 14rem;
    box-shadow: 0 0.4rem 2rem rgba(0,0,0,0.2);
}
.menu-panel .menu-item {
    padding: 0.8rem 1.4rem;
    font-size: 1rem;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}
.menu-panel .menu-item:last-child { border-bottom: none; }
.menu-panel .menu-item:active { background: #f0f0f0; }
.menu-panel .menu-item .icon { font-size: 1.1rem; }
.menu-panel .menu-item .arrow { margin-left: auto; color: #ccc; font-size: 0.8rem; }

/* ---------- 内容区域 ---------- */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.tab-page {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
.tab-page.active { display: flex; }

/* ---------- 消息列表 ---------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.6rem;
    background: #ededed;
    -webkit-overflow-scrolling: touch;
    position: relative;
}
.message-item {
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    position: relative;
    touch-action: manipulation;
}
.message-item .avatar {
    width: 3.6rem;
    height: 3.6rem;
    border-radius: 50%;
    background: #1a8c5e;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 600;
    flex-shrink: 0;
    margin: 0 0.6rem;
    cursor: pointer;
}
.message-item .avatar:active { opacity: 0.7; }
.message-item.mine {
    flex-direction: row-reverse;
}
.message-item.mine .avatar {
    margin: 0 0.6rem;
}
.message-item.mine .body {
    align-items: flex-end;
}
.message-item .body {
    flex: 1;
    max-width: 75%;
    display: flex;
    flex-direction: column;
}
.message-item .body .name-time {
    font-size: 0.6rem;
    color: #b0b0b0;
    margin-bottom: 0.1rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
}
.message-item .body .name-time .muted-tag {
    font-size: 0.55rem;
    color: #dc3545;
    background: #ffe0e0;
    padding: 0.1rem 0.4rem;
    border-radius: 0.4rem;
}
.message-item .body .bubble {
    padding: 0.5rem 0.8rem;
    border-radius: 0.6rem;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    max-width: 100%;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}
.message-item:not(.mine) .body .bubble {
    background: #ffffff;
    border-radius: 0.6rem 0.6rem 0.6rem 0.2rem;
}
.message-item.mine .body .bubble {
    background: #95ec69;
    border-radius: 0.6rem 0.6rem 0.2rem 0.6rem;
}
.message-item .body .bubble img {
    max-width: 100%;
    max-height: 14rem;
    border-radius: 0.3rem;
    display: block;
    cursor: pointer;
    pointer-events: auto;
}
.message-item .body .bubble .file-link {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    background: #f0f0f0;
    padding: 0.5rem 0.8rem;
    border-radius: 0.6rem;
    text-decoration: none;
    color: #1a8c5e;
    font-size: 0.9rem;
    border: 1px solid #ddd;
}
.message-item .body .bubble .file-link:active {
    background: #e0e0e0;
}
/* 收藏星星 */
.favorite-star {
    position: absolute;
    right: 0.4rem;
    top: 0.4rem;
    font-size: 1.8rem;
    cursor: pointer;
    color: #ccc;
    z-index: 10;
    background: rgba(255,255,255,0.7);
    border-radius: 50%;
    padding: 0.1rem;
    line-height: 1;
    transition: 0.2s;
    touch-action: manipulation;
}
.favorite-star.active { color: #f5a623; }
.favorite-star:active { transform: scale(0.8); }
.message-item.mine .favorite-star {
    right: auto;
    left: 0.4rem;
}
/* 系统消息 */
.message-item.system .body .bubble {
    background: #e8e8e8 !important;
    color: #888 !important;
    font-size: 0.9rem !important;
    text-align: center !important;
    padding: 0.3rem 0.8rem !important;
    border-radius: 1rem !important;
    box-shadow: none !important;
}
.message-item.system .avatar { display: none !important; }
.message-item.system .body { max-width: 100% !important; text-align: center !important; }
.message-item.system .favorite-star { display: none !important; }

/* ---------- 输入区域 ---------- */
.chat-input {
    background: #f7f7f7;
    border-top: 2px solid #e8e8e8;
    padding: 0.5rem 0.8rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    z-index: 50;
    position: sticky;
    bottom: 0;
    font-size: 1rem;
}
.chat-input .btn-plus {
    font-size: 1.3rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 0.2rem;
    color: #666;
    flex-shrink: 0;
}
.chat-input input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 2rem;
    font-size: 1rem;
    outline: none;
    min-width: 1.5rem;
    background: #fff;
    height: 3.6rem;
    transition: border-color 0.2s;
}
.chat-input input:focus { border-color: #1a8c5e; }
.chat-input input:disabled {
    background: #f0f0f0;
    color: #999;
}
.chat-input .btn-send {
    background: #1a8c5e;
    color: #fff;
    border: none;
    padding: 0.5rem 1.2rem;
    border-radius: 2rem;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    height: 3.4rem;
    display: flex;
    align-items: center;
}
.chat-input .btn-send:active { background: #0f6b46; }
.chat-input .btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- 更多面板 ---------- */
.more-panel {
    width: 100%;
    display: none;
    padding: 0.5rem 0 0.3rem 0;
    border-top: 2px solid #e8e8e8;
    margin-top: 0.3rem;
}
.more-panel.show { display: block; }
.more-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.6rem;
}
.more-grid .item {
    background: #fff;
    border-radius: 0.6rem;
    padding: 0.5rem 0.2rem;
    text-align: center;
    font-size: 0.8rem;
    color: #333;
    cursor: pointer;
    border: 2px solid #eee;
}
.more-grid .item .icon {
    font-size: 1.3rem;
    display: block;
    margin-bottom: 0.1rem;
}
.more-grid .item:active { background: #f0f0f0; }

/* ---------- 底部导航 ---------- */
.bottom-nav {
    display: flex;
    background: #fafafa;
    border-top: 2px solid #e8e8e8;
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
    min-height: 3.8rem;
    z-index: 100;
}
.bottom-nav .tab {
    flex: 1;
    text-align: center;
    padding: 0.3rem 0 0.2rem 0;
    font-size: 0.65rem;
    color: #999;
    cursor: pointer;
    border-top: 3px solid transparent;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.bottom-nav .tab .icon {
    font-size: 1.3rem;
    display: block;
    margin-bottom: 0.1rem;
}
.bottom-nav .tab .label {
    font-size: 0.6rem;
    display: block;
}
.bottom-nav .tab.active {
    color: #1a8c5e;
    border-top-color: #1a8c5e;
}

/* ---------- 其他通用组件 ---------- */
.placeholder-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #aaa;
    padding: 1.5rem;
    text-align: center;
}
.placeholder-page .big-icon { font-size: 3rem; margin-bottom: 0.8rem; }
.placeholder-page h3 { color: #555; font-weight: 500; font-size: 1.3rem; margin-bottom: 0.6rem; }
.placeholder-page p { font-size: 1rem; color: #bbb; max-width: 14rem; line-height: 1.5; }

.my-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 1.5rem;
    text-align: center;
}
.my-page .avatar-square {
    width: 6rem;
    height: 6rem;
    border-radius: 0.6rem;
    background: #1a8c5e;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.8rem;
    font-weight: 600;
    margin-bottom: 0.8rem;
}
.my-page .my-name {
    font-size: 1.4rem;
    font-weight: 600;
    color: #1a8c5e;
    margin-bottom: 0.3rem;
}
.my-page .my-role {
    font-size: 1rem;
    color: #888;
    margin-bottom: 0.8rem;
}
.my-page .btn-logout {
    background: #dc3545;
    color: #fff;
    border: none;
    padding: 0.6rem 1.8rem;
    border-radius: 2rem;
    font-size: 1rem;
    cursor: pointer;
}
.my-page .btn-logout:active { background: #c82333; }
.my-page .my-tip {
    margin-top: 1.2rem;
    font-size: 0.8rem;
    color: #bbb;
}

/* ---------- 弹窗、Toast、预览 ---------- */
.report-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    justify-content: center;
    align-items: center;
}
.report-overlay.active { display: flex; }
.report-box {
    background: #fff;
    border-radius: 1.2rem;
    padding: 1.4rem;
    max-width: 24rem;
    width: 90%;
}
.report-box h3 {
    font-size: 1.3rem;
    margin-bottom: 0.8rem;
    text-align: center;
}
.report-box .report-option {
    padding: 0.7rem 1rem;
    font-size: 1rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.report-box .report-option:last-child { border-bottom: none; }
.report-box .report-option:active { background: #f0f0f0; }
.report-box .report-option .icon { font-size: 1.1rem; }
.report-box .cancel-btn {
    width: 100%;
    padding: 0.8rem;
    background: #eee;
    border: none;
    border-radius: 0.6rem;
    font-size: 1rem;
    margin-top: 0.8rem;
    cursor: pointer;
}
.report-box .cancel-btn:active { background: #ddd; }
.report-box input[type="text"] {
    width: 100%;
    padding: 0.6rem;
    border: 2px solid #ddd;
    border-radius: 0.6rem;
    font-size: 0.9rem;
    margin-top: 0.3rem;
    display: none;
}
.report-box input[type="text"].show { display: block; }

.system-toast {
    position: fixed;
    bottom: 6rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 0.7rem 1.4rem;
    border-radius: 1rem;
    font-size: 1rem;
    z-index: 400;
    display: none;
    text-align: center;
    max-width: 90%;
}
.system-toast.show { display: block; }
.system-toast.warning { background: rgba(200,80,0,0.9); }
.system-toast.error { background: rgba(200,0,0,0.9); }
.system-toast.success { background: rgba(0,150,0,0.9); }

.image-preview-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.92);
    z-index: 999;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0.8rem;
}
.image-preview-overlay.active { display: flex; }
.image-preview-overlay img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 0.3rem;
}

.msg-action-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 500;
    justify-content: center;
    align-items: center;
}
.msg-action-overlay.active { display: flex; }
.msg-action-menu {
    background: #fff;
    border-radius: 1rem;
    padding: 0.4rem 0;
    min-width: 12rem;
    box-shadow: 0 0.4rem 2rem rgba(0,0,0,0.3);
}
.msg-action-menu .action-item {
    padding: 0.8rem 1.4rem;
    font-size: 1rem;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    text-align: center;
    touch-action: manipulation;
}
.msg-action-menu .action-item:last-child { border-bottom: none; }
.msg-action-menu .action-item:active { background: #f0f0f0; }
.msg-action-menu .action-item.danger { color: #dc3545; }

/* ---------- 响应式微调 ---------- */
@media (max-width: 480px) {
    html { font-size: 2.2vw; }
    .header .title { font-size: 1rem; }
    .header .title .member-badge { font-size: 0.55rem; }
    .message-item .avatar { width: 3rem; height: 3rem; font-size: 1.5rem; margin: 0 0.4rem; }
    .message-item .body .bubble { padding: 0.4rem 0.7rem; }
    .message-item .body .name-time { font-size: 0.55rem; }
    .chat-input input { font-size: 0.9rem; height: 3rem; padding: 0.4rem 0.7rem; }
    .chat-input .btn-send { font-size: 0.9rem; height: 3rem; padding: 0.4rem 0.8rem; }
    .chat-input .btn-plus { font-size: 1.2rem; }
    .bottom-nav .tab .icon { font-size: 1.2rem; }
    .bottom-nav .tab .label { font-size: 0.5rem; }
    .bottom-nav { min-height: 3rem; }
    .report-box h3 { font-size: 1.2rem; }
    .report-box .report-option { font-size: 0.9rem; }
    .menu-panel { min-width: 12rem; }
    .menu-panel .menu-item { font-size: 0.9rem; padding: 0.7rem 1rem; }
    .favorite-star { font-size: 1.5rem; }
    .msg-action-menu .action-item { font-size: 0.9rem; padding: 0.6rem 1rem; }
}