/* ============================================================
   元速科技 · 智能悬浮接待系统 (Chat Widget)
   ------------------------------------------------------------
   - 右下角悬浮窗，3秒自动弹出，关闭后本次会话不再弹
   - 桌面端宽幅聊天窗 / 移动端底部通栏弹窗
   - 配色匹配主站品牌色（#1E40AF / #06B6D4）
   - 无第三方依赖，原生 JS+CSS
   ============================================================ */

/* ===== 悬浮按钮（收起态）===== */
.ys-chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1E40AF, #06B6D4);
    box-shadow: 0 6px 20px rgba(30, 64, 175, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    transition: transform 0.3s, box-shadow 0.3s;
    animation: ys-chat-fab-pulse 2.5s ease-in-out infinite;
}
.ys-chat-fab:hover { transform: scale(1.08); box-shadow: 0 8px 28px rgba(30, 64, 175, 0.55); }
.ys-chat-fab svg { width: 28px; height: 28px; color: #fff; }
/* 未读消息红点 */
.ys-chat-fab .ys-chat-badge {
    position: absolute; top: -2px; right: -2px;
    min-width: 20px; height: 20px; padding: 0 5px;
    background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
}
@keyframes ys-chat-fab-pulse {
    0%, 100% { box-shadow: 0 6px 20px rgba(30, 64, 175, 0.4), 0 0 0 0 rgba(6, 182, 212, 0.5); }
    50% { box-shadow: 0 6px 20px rgba(30, 64, 175, 0.4), 0 0 0 14px rgba(6, 182, 212, 0); }
}

/* ===== 聊天窗口（展开态）===== */
.ys-chat-window {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.25), 0 4px 12px rgba(15, 23, 42, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.ys-chat-window.ys-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.ys-chat-window.ys-hidden { display: none; }

/* 顶部栏 */
.ys-chat-header {
    background: linear-gradient(135deg, #1E40AF, #2563EB);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.ys-chat-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700; flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.3);
}
.ys-chat-agent-info { flex: 1; min-width: 0; }
.ys-chat-agent-name { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ys-chat-agent-name .ys-online-dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 2px rgba(52,211,153,0.3); }
.ys-chat-agent-title { font-size: 12px; opacity: 0.85; margin-top: 1px; }
.ys-chat-close {
    width: 28px; height: 28px; border-radius: 50%; border: none;
    background: rgba(255,255,255,0.15); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s; flex-shrink: 0;
}
.ys-chat-close:hover { background: rgba(255,255,255,0.3); }
.ys-chat-close svg { width: 16px; height: 16px; }

/* 消息区 */
.ys-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ys-chat-body::-webkit-scrollbar { width: 5px; }
.ys-chat-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* 单条消息 */
.ys-chat-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: ys-chat-msg-in 0.35s ease;
}
@keyframes ys-chat-msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.ys-chat-msg.ys-agent {
    align-self: flex-start;
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}
.ys-chat-msg.ys-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #1E40AF, #2563EB);
    color: #fff;
    border-bottom-right-radius: 4px;
}
/* 打字指示器 */
.ys-chat-typing { align-self: flex-start; padding: 12px 16px; }
.ys-chat-typing span {
    display: inline-block; width: 7px; height: 7px; margin: 0 1px;
    background: #94a3b8; border-radius: 50%;
    animation: ys-chat-typing 1.2s infinite ease-in-out;
}
.ys-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ys-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ys-chat-typing { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* 快捷按钮 */
.ys-chat-quick {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-top: 4px; align-self: flex-start; max-width: 82%;
}
.ys-chat-quick button {
    padding: 6px 12px; font-size: 12.5px;
    border: 1px solid #bfdbfe; background: #eff6ff; color: #1E40AF;
    border-radius: 16px; cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.ys-chat-quick button:hover { background: #1E40AF; color: #fff; border-color: #1E40AF; }

/* 底部输入区 */
.ys-chat-footer {
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.ys-chat-input-wrap { display: flex; gap: 8px; align-items: flex-end; }
.ys-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13.5px;
    outline: none;
    resize: none;
    max-height: 80px;
    min-height: 40px;
    font-family: inherit;
    transition: border-color 0.2s;
}
.ys-chat-input:focus { border-color: #1E40AF; }
.ys-chat-send {
    width: 40px; height: 40px; border-radius: 10px; border: none; cursor: pointer;
    background: linear-gradient(135deg, #1E40AF, #2563EB); color: #fff;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: transform 0.15s;
}
.ys-chat-send:hover { transform: scale(1.05); }
.ys-chat-send svg { width: 18px; height: 18px; }
.ys-chat-footer-hint { font-size: 10.5px; color: #94a3b8; text-align: center; margin-top: 6px; }

/* 成功提示遮罩 */
.ys-chat-success {
    position: absolute; inset: 0; z-index: 10;
    background: rgba(255,255,255,0.97);
    display: none; flex-direction: column; align-items: center; justify-content: center;
    padding: 24px; text-align: center; border-radius: 16px;
}
.ys-chat-success.ys-show { display: flex; animation: ys-chat-msg-in 0.4s; }
.ys-chat-success-icon {
    width: 64px; height: 64px; border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #34d399);
    display: flex; align-items: center; justify-content: center; margin-bottom: 16px;
}
.ys-chat-success-icon svg { width: 34px; height: 34px; color: #fff; }
.ys-chat-success h4 { font-size: 16px; font-weight: 700; color: #1e293b; margin-bottom: 8px; }
.ys-chat-success p { font-size: 13px; color: #64748b; line-height: 1.6; max-width: 280px; }

/* ===== 移动端适配：底部通栏弹窗 ===== */
@media (max-width: 640px) {
    .ys-chat-fab { right: 16px; bottom: 16px; width: 52px; height: 52px; }
    .ys-chat-window {
        right: 0; bottom: 0; left: 0;
        width: 100%; max-width: 100%;
        height: 85vh; max-height: 85vh;
        border-radius: 16px 16px 0 0;
    }
}
