/* ===== Poly Chat - 在线客服悬浮窗 & 聊天UI ===== */

/* 悬浮按钮 */
.poly-chat-fab {
    position: fixed;
    right: 20px;
    bottom: 80px;
    z-index: 9998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255,255,255,0.95);
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
    transition: all .3s ease;
    border: none;
    outline: none;
}
.poly-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}
.poly-chat-fab:active {
    transform: scale(0.95);
}
.poly-chat-fab svg {
    width: 28px;
    height: 28px;
    fill: #666;
}
.poly-chat-fab .fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    padding: 0 4px;
    line-height: 14px;
}
.poly-chat-fab .fab-badge.show {
    display: flex;
}

/* 聊天窗口 */
.poly-chat-window {
    position: fixed;
    right: 20px;
    bottom: 80px;
    z-index: 9999;
    width: 360px;
    height: 520px;
    max-height: 80vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: polyChatSlideUp .3s ease;
}
.poly-chat-window.active {
    display: flex;
}

@keyframes polyChatSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 聊天窗口头部 */
.poly-chat-header {
    background: linear-gradient(135deg, #C0392B, #a83225);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.poly-chat-header .chat-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.poly-chat-header .chat-title .online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;
    display: inline-block;
}
.poly-chat-header .chat-subtitle {
    font-size: 12px;
    opacity: .8;
    margin-top: 2px;
}
.poly-chat-header .btn-close-chat {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}
.poly-chat-header .btn-close-chat:hover {
    background: rgba(255,255,255,.3);
}

/* 消息区域 */
.poly-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f6f3;
}
.poly-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.poly-chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
}

/* 单条消息 */
.pchat-msg {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    margin-bottom: 14px;
    gap: 8px;
}
.pchat-msg.pchat-msg-user {
    flex-direction: row-reverse;
}
.pchat-msg .pchat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #fff;
}
.pchat-msg.pchat-msg-admin .pchat-avatar,
.pchat-msg.pchat-msg-system .pchat-avatar {
    background: #C0392B;
}
.pchat-msg.pchat-msg-user .pchat-avatar {
    background: #3498db;
}
.pchat-msg > div {
    min-width: 0;
}
.pchat-msg > div:not(.pchat-avatar) {
    max-width: 70%;
    width: fit-content;
}
.pchat-msg .pchat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    max-width: 100%;
}
.pchat-msg.pchat-msg-admin .pchat-bubble {
    background: #fff;
    color: #333;
    border: 1px solid #eee;
    border-radius: 14px 14px 14px 4px;
}
.pchat-msg.pchat-msg-user .pchat-bubble {
    background: linear-gradient(135deg, #C0392B, #d44637);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
}
.pchat-msg.pchat-msg-system .pchat-bubble {
    background: #eee;
    color: #999;
    font-size: 12px;
    max-width: 100%;
    text-align: center;
    border-radius: 8px;
    margin: 0 auto;
}
.pchat-msg .pchat-bubble img {
    max-width: 180px;
    border-radius: 8px;
    cursor: pointer;
}
.pchat-msg .pchat-time {
    font-size: 11px;
    color: #bbb;
    margin-top: 4px;
}
.pchat-msg.pchat-msg-user .pchat-time {
    text-align: right;
}

/* 输入区域 */
.poly-chat-input {
    border-top: 1px solid #eee;
    padding: 10px 12px;
    background: #fff;
    flex-shrink: 0;
}
.poly-chat-input .input-tools {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}
.poly-chat-input .input-tools .tool-btn {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color .2s;
}
.poly-chat-input .input-tools .tool-btn:hover {
    color: #C0392B;
}
.poly-chat-input .input-tools .tool-btn svg {
    width: 20px;
    height: 20px;
}
.poly-chat-input .input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.poly-chat-input textarea {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 14px;
    resize: none;
    height: 40px;
    max-height: 80px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
}
.poly-chat-input textarea:focus {
    border-color: #C0392B;
}
.poly-chat-input .btn-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #C0392B;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .2s;
}
.poly-chat-input .btn-chat-send:hover {
    background: #a83225;
}
.poly-chat-input .btn-chat-send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* 表情面板 */
.poly-emoji-panel {
    display: none;
    position: absolute;
    bottom: 60px;
    left: 12px;
    right: 12px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
    max-height: 160px;
    overflow-y: auto;
    z-index: 10;
}
.poly-emoji-panel.show {
    display: block;
}
.poly-emoji-panel span {
    cursor: pointer;
    font-size: 20px;
    padding: 3px;
    display: inline-block;
    border-radius: 4px;
    transition: background .15s;
}
.poly-emoji-panel span:hover {
    background: #f5e6d3;
}

/* 图片上传进度 */
.poly-chat-uploading {
    text-align: center;
    padding: 8px;
    font-size: 12px;
    color: #999;
}

/* 移动端适配 */
@media (max-width: 420px) {
    .poly-chat-window {
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    .poly-chat-fab {
        bottom: 72px;
        right: 16px;
    }
}
