/* ═══════════════════════════════════════════════════════
   公共聊天室
   设计 token 全部复用 basic.css / ui.css，这里只做布局与气泡样式
   ═══════════════════════════════════════════════════════ */

/* hidden 属性优先级高于 .btn 的 display:inline-flex，必须显式覆盖 */
.chat-page [hidden] { display: none !important; }

.chat-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px 0 24px;
}

.chat-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    /* 100vh - 导航栏(56) - 本页上下留白(44) */
    height: calc(100vh - 100px);
    min-height: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
@supports (height: 100dvh) {
    .chat-shell { height: calc(100dvh - 100px); }
}

/* ── 顶栏 ── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.chat-title i { color: var(--primary); font-size: 17px; }

.chat-header-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
}
.chat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    transition: background var(--transition-fast);
}
.chat-dot.off { background: var(--danger); }

.chat-identity {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-identity i { color: var(--primary); }

/* 仅 CHAT_NOTIFY_MODE="always"（调试模式）时显示，用来直接看出通知弹/不弹的原因 */
.chat-notify-debug {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: var(--warning-light);
    color: #92400e;
    border: 1px solid #fde68a;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── 消息列表 ── */
.chat-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overscroll-behavior: contain;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.chat-empty i { font-size: 30px; opacity: 0.5; }

.chat-msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: chatMsgIn 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.mine { flex-direction: row-reverse; }

.chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--border);
    background: var(--border-light);
}

.chat-avatar-text {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #94a3b8;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    border-color: transparent;
    user-select: none;
}

.chat-main {
    display: flex;
    flex-direction: column;
    /* 关键：让气泡按自身内容收缩。默认的 stretch 会把 .chat-text 拉宽到
       与「用户名 + 访客徐章 + 时间」那一行同宽，短消息后面就会空一大截 */
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
    max-width: 78%;
}
.chat-msg.mine .chat-main { align-items: flex-end; }

.chat-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}
.chat-msg.mine .chat-meta { flex-direction: row-reverse; }

.chat-name { font-weight: 600; color: var(--text-secondary); }
.chat-time { white-space: nowrap; }

.chat-ip {
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    background: var(--border-light);
    color: var(--text-muted);
}

.chat-del {
    border: none;
    background: none;
    padding: 0 3px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    opacity: 0;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}
.chat-msg:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); }

.chat-text {
    padding: 9px 13px;
    border-radius: var(--radius);
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-msg.mine .chat-text {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.chat-msg.mine .chat-link { color: #fff; }

.chat-link {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* 从系统通知点进来时的定位高亮 */
.chat-msg-flash .chat-text {
    animation: chatFlash 1.8s ease;
}
@keyframes chatFlash {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
    25% { box-shadow: 0 0 0 4px var(--primary-glow); }
    70% { box-shadow: 0 0 0 4px var(--primary-glow); }
}

/* ── 新消息胶囊 ── */
.chat-newpill {
    position: absolute;
    left: 50%;
    bottom: 104px;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--primary);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--primary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 5;
    animation: fadeIn 0.2s ease;
}
.chat-newpill:hover { background: var(--primary-light); }

/* ── 输入区 ── */
.chat-composer {
    border-top: 1px solid var(--border);
    padding: 12px 16px 10px;
    background: var(--surface);
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.chat-composer-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
}

.chat-counter { color: var(--text-muted); white-space: nowrap; }
.chat-counter.over { color: var(--danger); font-weight: 700; }

/* ── 响应式 ── */
@media (max-width: 768px) {
    .chat-page { padding: 0; }
    /* 移动端 .content 自带 20px 上下内边距，这里再多扣掉 */
    .chat-shell { height: calc(100vh - 136px); border-radius: var(--radius); }
    @supports (height: 100dvh) {
        .chat-shell { height: calc(100dvh - 136px); }
    }
    .chat-header { padding: 10px 12px; }
    .chat-header-right .btn { padding: 4px 9px; font-size: 11px; }
    .chat-identity { max-width: 130px; }
    .chat-list { padding: 12px; gap: 12px; }
    .chat-main { max-width: 82%; }
    .chat-avatar { width: 30px; height: 30px; }
    .chat-composer { padding: 10px 12px 8px; }
    .chat-input-row .btn { padding: 9px 12px; }
    .chat-input-row .btn i { font-size: 14px; }
    .chat-newpill { bottom: 96px; }
}
