/* ============================================================
   仿 Telegram 客服系统 - 公共样式
   ============================================================ */

:root {
    --tg-blue: #2AABEE;
    --tg-blue-dark: #229ED9;
    --tg-green: #EFFDDE;
    --tg-green-bubble: #EEFFDE;
    --tg-white-bubble: #FFFFFF;
    --tg-bg: #E6EBEE;
    --tg-bg-pattern: #DAE2E7;
    --tg-header: #517DA2;
    --tg-header-text: #FFFFFF;
    --tg-sidebar-bg: #FFFFFF;
    --tg-sidebar-hover: #F1F1F1;
    --tg-sidebar-active: #2AABEE;
    --tg-text: #000000;
    --tg-text-secondary: #707579;
    --tg-text-time: #5DB050;
    --tg-text-time-in: #A0ACB6;
    --tg-link: #3390EC;
    --tg-divider: #E7E7E7;
    --tg-input-bg: #FFFFFF;
    --tg-danger: #E53935;
    --tg-online: #4DCD5E;
    --tg-typing: #4EA4F6;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
    font-size: 14px;
    color: var(--tg-text);
    background: var(--tg-bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- 滚动条美化 --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.25); }

/* --- 头像 --- */
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 500;
    color: #fff;
    flex-shrink: 0;
    user-select: none;
    text-transform: uppercase;
}

.avatar-sm {
    width: 34px;
    height: 34px;
    font-size: 14px;
}

.avatar-lg {
    width: 54px;
    height: 54px;
    font-size: 22px;
}

/* --- 在线状态点 --- */
.online-dot {
    width: 10px;
    height: 10px;
    background: var(--tg-online);
    border-radius: 50%;
    border: 2px solid #fff;
    position: absolute;
    bottom: 0;
    right: 0;
}

/* --- 未读红点 --- */
.unread-badge {
    background: var(--tg-blue);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* --- 消息气泡 --- */
.message-bubble {
    max-width: 480px;
    padding: 6px 11px 5px;
    border-radius: 12px;
    position: relative;
    word-break: break-word;
    line-height: 1.35;
    font-size: 14.5px;
}

.message-out {
    background: var(--tg-green-bubble);
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.message-in {
    background: var(--tg-white-bubble);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,.04);
}

/* 气泡尾巴 */
.message-out::after {
    content: '';
    position: absolute;
    right: -8px;
    bottom: 0;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-left-color: var(--tg-green-bubble);
    border-bottom: 0;
    border-right: 0;
}

.message-in::before {
    content: '';
    position: absolute;
    left: -8px;
    bottom: 0;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: var(--tg-white-bubble);
    border-bottom: 0;
    border-left: 0;
}

.message-time {
    font-size: 11px;
    float: right;
    margin-left: 10px;
    margin-top: 4px;
    position: relative;
    bottom: -3px;
}

.message-out .message-time {
    color: var(--tg-text-time);
}

.message-in .message-time {
    color: var(--tg-text-time-in);
}

/* --- 撤回消息 --- */
.message-revoked {
    font-style: italic;
    color: var(--tg-text-secondary);
    font-size: 13px;
}

.message-revoked .message-bubble {
    opacity: .7;
}

/* --- 撤回动画 --- */
@keyframes revokeAnim {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: .5; transform: scale(.95); }
    100% { opacity: 0; max-height: 0; padding: 0; margin: 0; overflow: hidden; }
}

.revoke-animate {
    animation: revokeAnim .4s ease forwards;
}

/* --- 图片消息 --- */
.message-image {
    max-width: 320px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}

.message-image:hover {
    filter: brightness(.95);
}

/* --- 文件消息 --- */
.file-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
}

.file-icon {
    width: 40px;
    height: 40px;
    background: var(--tg-blue);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-info {
    overflow: hidden;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--tg-link);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.file-size {
    font-size: 12px;
    color: var(--tg-text-secondary);
}

/* --- 右键菜单 --- */
.context-menu {
    position: fixed;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,.15);
    padding: 5px 0;
    z-index: 9999;
    min-width: 160px;
    display: none;
}

.context-menu.show {
    display: block;
    animation: ctxFadeIn .12s ease;
}

@keyframes ctxFadeIn {
    from { opacity: 0; transform: scale(.95); }
    to { opacity: 1; transform: scale(1); }
}

.context-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    transition: background .1s;
}

.context-menu-item:hover {
    background: var(--tg-sidebar-hover);
}

.context-menu-item.danger {
    color: var(--tg-danger);
}

/* --- Emoji 选择器 --- */
.emoji-panel {
    position: absolute;
    bottom: 56px;
    left: 8px;
    width: 320px;
    height: 280px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    z-index: 100;
    display: none;
    overflow: hidden;
}

.emoji-panel.show {
    display: block;
    animation: ctxFadeIn .15s ease;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
    height: 100%;
    overflow-y: auto;
}

.emoji-item {
    font-size: 22px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    transition: background .1s;
}

.emoji-item:hover {
    background: var(--tg-sidebar-hover);
}

/* --- 输入区域 --- */
.chat-input-area {
    background: #fff;
    border-top: 1px solid var(--tg-divider);
    padding: 8px 8px;
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.chat-input-wrapper {
    flex: 1;
    background: var(--tg-bg);
    border-radius: 20px;
    padding: 8px 14px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    min-height: 40px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    resize: none;
    font-size: 14.5px;
    font-family: inherit;
    line-height: 1.35;
    max-height: 120px;
    min-height: 20px;
    overflow-y: auto;
}

.chat-input::placeholder {
    color: var(--tg-text-secondary);
}

.input-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-text-secondary);
    transition: all .15s;
    flex-shrink: 0;
}

.input-btn:hover {
    background: rgba(0,0,0,.05);
    color: var(--tg-blue);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--tg-blue);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: all .15s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--tg-blue-dark);
}

.send-btn:active {
    transform: scale(.92);
}

/* --- 系统消息（时间分隔线、撤回提示） --- */
.system-message {
    text-align: center;
    padding: 4px 0;
}

.system-message span {
    background: rgba(0,0,0,.12);
    color: #fff;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 10px;
    display: inline-block;
}

/* --- 正在输入指示 --- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 0;
    color: var(--tg-typing);
    font-size: 13px;
}

.typing-dot {
    width: 5px;
    height: 5px;
    background: var(--tg-typing);
    border-radius: 50%;
    animation: typingBounce .6s infinite alternate;
}

.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typingBounce {
    from { opacity: .3; transform: translateY(0); }
    to { opacity: 1; transform: translateY(-3px); }
}

/* --- 图片预览遮罩 --- */
.image-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.85);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.image-preview-overlay.show {
    display: flex;
}

.image-preview-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 4px;
}

/* --- Toast 提示 --- */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.75);
    color: #fff;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 13px;
    z-index: 10001;
    opacity: 0;
    transition: opacity .3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

/* --- 移动端适配 --- */
@media (max-width: 768px) {
    .message-bubble {
        max-width: 85vw;
    }

    .message-image {
        max-width: 70vw;
    }

    .emoji-panel {
        width: calc(100vw - 16px);
        left: 8px;
        right: 8px;
    }

    .emoji-grid {
        grid-template-columns: repeat(8, 1fr);
    }
}
