/* ========== 全局 ========== */
* { margin:0; padding:0; box-sizing:border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(160deg, #d6eaf8 0%, #e8f5e9 100%);
    color: #333;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px 0;
}

/* ========== 主容器 ========== */
.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 780px;
    height: calc(100vh - 40px);
    background: #ffffff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.12);
    position: relative;
}

/* ========== 头部 ========== */
.header {
    background: linear-gradient(160deg, #07C160 0%, #05a14d 100%);
    padding: 14px 20px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(7,193,96,0.25);
}
.header-left {
    flex: 1;
    text-align: center;
}
.group-name {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 1px;
}
.group-desc {
    font-size: 11px;
    color: rgba(255,255,255,0.85);
    margin-top: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.online-dot {
    display: inline-block;
    width: 7px; height: 7px;
    background: #ffffff;
    border-radius: 50%;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ========== 密码验证页 ========== */
.password-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 30px;
    background: #f5f5f5;
}
.password-page .lock-icon {
    font-size: 56px;
    margin-bottom: 20px;
}
.password-page h2 {
    font-size: 20px;
    color: #333;
    margin-bottom: 24px;
}
.password-page .pw-form {
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.password-page input[type="password"] {
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}
.password-page input[type="password"]:focus {
    border-color: #07C160;
}
.password-page button {
    padding: 12px;
    background: #07C160;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.password-page button:hover { background: #06a955; }
.password-page .pw-error {
    color: #e74c3c;
    font-size: 13px;
    text-align: center;
    min-height: 18px;
}

/* ========== 聊天内容区 ========== */
.chat-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 14px 16px;
    background: #f0f0f0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.chat-content::-webkit-scrollbar { display: none; }

/* 欢迎横幅 */
.welcome-banner {
    text-align: center;
    margin: 0 -14px 8px;
    background: linear-gradient(135deg, #e8f8ee 0%, #f0faf4 50%, #e8f5e9 100%);
    border-bottom: 1px solid #d4f0d9;
    animation: fadeBanner 0.6s ease;
}
@keyframes fadeBanner {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.welcome-banner .welcome-icon { font-size: 28px; margin-bottom: 6px; }
.welcome-banner .welcome-text {
    font-size: 13px;
    color: #2d8a4e;
    font-weight: 500;
    line-height: 1.6;
}
.welcome-banner .welcome-name {
    color: #07C160;
    font-weight: 700;
}

/* ========== 消息行 ========== */
.message {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 0 2px;
    animation: msgIn 0.3s ease;
}
.message.self {
    flex-direction: row-reverse;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 头像 */
.msg-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    font-weight: 600;
    overflow: hidden;
    background: #ccc;
}
.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* 名字 + 时间（气泡外部，头像右侧上方） */
.msg-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 5px;
    padding: 0 2px;
    line-height: 1;
    flex-wrap: wrap;
}
.msg-header .msg-name {
    font-size: 12px;
    color: #888;
    font-weight: 500;
}
.msg-header .msg-sep {
    font-size: 10px;
    color: #bbb;
    margin: 0 2px;
}
.msg-header .msg-time {
    font-size: 11px;
    color: #aaa;
}
.message.self .msg-header {
    flex-direction: row-reverse;
}

/* 气泡 */
.msg-body {
    max-width: 80%;
    display: flex;
    flex-direction: column;
}
.message.self .msg-body {
    align-items: flex-end;
}
.msg-bubble {
    width: fit-content;
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 4px 18px 18px 18px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}
.message:not(.self) .msg-bubble {
    background: #5bc778;
    color: #333;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.message.self .msg-bubble {
    background: #95ec69;
    color: #333;
}
.msg-bubble.msg-image {
    padding: 4px;
    background: transparent !important;
    box-shadow: none;
}
.msg-bubble.msg-image img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    cursor: zoom-in;
    display: block;
}
.msg-bubble.msg-image img:hover {
    opacity: 0.9;
}

/* ========== 图片灯箱 ========== */
.lightbox-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lbFadeIn 0.25s ease;
}
@keyframes lbFadeIn { from { opacity: 0; } to { opacity: 1; } }
.lightbox-overlay.lb-closing {
    animation: lbFadeOut 0.2s ease forwards;
}
@keyframes lbFadeOut { from { opacity: 1; } to { opacity: 0; } }
.lightbox-close {
    position: absolute;
    top: 16px; right: 20px;
    width: 40px; height: 40px;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.2s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.3); }
.lightbox-img-wrap {
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    cursor: zoom-in;
}
.lightbox-img-wrap.lb-zoomed {
    overflow: auto;
    cursor: zoom-out;
    max-width: 98vw;
    max-height: 98vh;
}
.lightbox-img-wrap img {
    display: block;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 4px;
    object-fit: contain;
    transition: transform 0.3s ease, max-width 0.3s ease, max-height 0.3s ease;
}
.lightbox-img-wrap.lb-zoomed img {
    max-width: none;
    max-height: none;
    object-fit: none;
}

/* 系统消息 */
.message.system {
    justify-content: center;
}
.message.system .msg-bubble {
    background: transparent;
    color: #aaaaaa;
    font-size: 12px;
    padding: 2px 0;
    box-shadow: none;
}

/* ========== 输入区 ========== */
.input-area {
    display: flex;
    align-items: flex-end;
    padding: 10px 14px;
    background: #f8f8f8;
    border-top: 1px solid #eeeeee;
    gap: 10px;
}
.msg-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    overflow-y: auto;
    background: #fff;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.msg-input::-webkit-scrollbar { display: none; }
.msg-input:focus { border-color: #07C160; }

.send-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #07C160;
    color: #fff;
    border: none;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.send-btn:hover { background: #06a955; }
.send-btn:disabled { background: #ccc; cursor: default; }

.plus-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    color: #555;
    border: none;
    font-size: 22px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.plus-btn:hover { background: #e0e0e0; }

/* ========== 隐藏原生文件选择 ========== */
#file-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

/* ========== 管理员徽章（消息内） ========== */
.msg-badge {
    background: linear-gradient(135deg, #2924ab, #e12020);
    color: #fff;
    font-weight: 700;
    padding: 0px 5px;
    border-radius: 6px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    animation: badgePulse 2s ease-in-out infinite;
    white-space: nowrap;
}
@keyframes badgePulse {
    0%,100% { transform: scale(1); }
    50%      { transform: scale(1.1); }
}
.message.self .msg-badge {
    background: linear-gradient(135deg, #ff4d4f, #ff7a45);
}

/* ========== 欢迎横幅徽章 ========== */
.welcome-badges {
    display: inline-flex;
    gap: 4px;
    margin-left: 6px;
    vertical-align: middle;
}
.welcome-badges .badge {
    display: inline-block;
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 10px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    animation: badgePulse 2s ease-in-out infinite;
}

/* ========== 滚动公告条 ========== */
.notice-bar {
    background: linear-gradient(90deg, #fff8e1 0%, #fffde7 100%);
    border-bottom: 1px solid #ffe082;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    flex-shrink: 0;
}
.notice-bar .notice-icon {
    font-size: 14px;
    flex-shrink: 0;
    animation: noticeRing 2.5s ease-in-out infinite;
}
@keyframes noticeRing {
    0%, 80%, 100% { transform: rotate(0deg); }
    10%  { transform: rotate(-15deg); }
    20%  { transform: rotate(15deg); }
    30%  { transform: rotate(-10deg); }
    40%  { transform: rotate(10deg); }
    50%  { transform: rotate(-5deg); }
    60%  { transform: rotate(5deg); }
}
.notice-bar .notice-scroll {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
}
.notice-bar .notice-text {
    display: inline-block;
    font-size: 12px;
    color: #e65100;
    font-weight: 500;
    animation: noticeMarquee 18s linear infinite;
}
@keyframes noticeMarquee {
    0%   { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}
.notice-bar:hover .notice-text {
    animation-play-state: paused;
}

/* ========== 响应式 ========== */
@media (max-width: 800px) {
    body { padding: 0; background: #f0f0f0; }
    .chat-container {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }
    .msg-bubble { max-width: 100%; }
    /* 手机端消息体尽量宽，留一点空间给头像 */
    .msg-body {
        max-width: 100%;
    }
    /* 手机端名字和badge换行优化 */
    .msg-header {
        gap: 4px;
        align-items: center;
    }
    .msg-badge {
        font-size: 9px;
        padding: 0px 4px;
        border-radius: 4px;
        margin-left: 1px;
    }
    .msg-header .msg-name {
        font-size: 11px;
    }
    .msg-header .msg-time {
        font-size: 10px;
    }
    /* 头像缩小，省空间 */
    .msg-avatar {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }
    .message {
        gap: 8px;
    }
}

/* ========== 加载提示 ========== */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 14px;
    color: #999;
    font-size: 14px;
    animation: loadingFadeIn 0.4s ease-out;
}
@keyframes loadingFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.loading-indicator.hidden {
    display: none;
}
.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e0e0e0;
    border-top-color: #07C160;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loading-text {
    font-size: 13px;
    letter-spacing: 0.5px;
}
