/* =====================================================================
 * AI 客服挂件样式
 * 类名统一 xtx-ai- 前缀，避免与 style.css / mobile.css 冲突
 * z-index：mask=9598  fab=9599  panel=9600（压过 Element UI 2000+）
 * ===================================================================== */

:root {
    --xtx-ai-red: #d12524;
    --xtx-ai-red-dark: #b01f1f;
    --xtx-ai-tabbar-h: 56px;
    --xtx-ai-safe-b: env(safe-area-inset-bottom, 0px);
    --xtx-ai-buycar-h: 92px;
}

/* —— 悬浮球 —— */
.xtx-ai-fab {
    position: fixed;
    right: 20px;
    bottom: 220px;            /* 兜底：.fix-bar 默认 120px + 高 90px + 间距，JS 会运行时测量覆盖 */
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--xtx-ai-red);
    color: #fff;
    border: 0;
    cursor: pointer;
    z-index: 9599;
    box-shadow: 0 6px 20px rgba(209, 37, 36, .35);
    transition: transform .18s, box-shadow .18s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    line-height: 1.2;
    text-align: center;
    user-select: none;
}
.xtx-ai-fab:hover { transform: scale(1.06); box-shadow: 0 8px 28px rgba(209, 37, 36, .45); }
.xtx-ai-fab svg { width: 26px; height: 26px; fill: currentColor; }

/* 红点提示 */
.xtx-ai-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: #ff3b30;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: xtx-ai-pulse 1.6s ease-in-out infinite;
}
@keyframes xtx-ai-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: .6; }
}

/* —— 面板 —— */
.xtx-ai-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 380px;
    height: min(600px, 76vh);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    overflow: hidden;
    z-index: 9600;
}
.xtx-ai-panel[hidden] { display: none; }

.xtx-ai-mask { display: none; }

/* 头部 */
.xtx-ai-hd {
    background: var(--xtx-ai-red);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.xtx-ai-title { font-size: 15px; font-weight: 600; flex: 1; }
.xtx-ai-human {
    background: rgba(255, 255, 255, .2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    margin-right: 8px;
    transition: background .15s;
}
.xtx-ai-human:hover { background: rgba(255, 255, 255, .35); }
.xtx-ai-close {
    background: none;
    border: 0;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    opacity: .8;
}
.xtx-ai-close:hover { opacity: 1; }

/* 消息区 */
.xtx-ai-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f7f8fa;
}
.xtx-ai-body::-webkit-scrollbar { width: 5px; }
.xtx-ai-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.xtx-ai-msg { display: flex; margin-bottom: 14px; }
.xtx-ai-msg.is-bot { justify-content: flex-start; }
.xtx-ai-msg.is-me { justify-content: flex-end; }

.xtx-ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--xtx-ai-red);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
    margin-right: 8px;
}
.xtx-ai-msg.is-me .xtx-ai-avatar { display: none; }

.xtx-ai-bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}
.xtx-ai-msg.is-bot .xtx-ai-bubble {
    background: #fff;
    color: #333;
    border: 1px solid #eee;
    border-top-left-radius: 4px;
}
.xtx-ai-msg.is-me .xtx-ai-bubble {
    background: var(--xtx-ai-red);
    color: #fff;
    border-top-right-radius: 4px;
}

/* 打字机光标 */
.xtx-ai-bubble.typing::after {
    content: '▋';
    animation: xtx-ai-blink .8s steps(2) infinite;
    color: #999;
}
@keyframes xtx-ai-blink { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }

/* 三点等待动画 */
.xtx-ai-typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    margin: 0 2px;
    animation: xtx-ai-bounce 1.2s infinite ease-in-out;
}
.xtx-ai-typing-dots span:nth-child(2) { animation-delay: .15s; }
.xtx-ai-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes xtx-ai-bounce {
    0%, 80%, 100% { transform: scale(.6); opacity: .4; }
    40% { transform: scale(1); opacity: 1; }
}

/* 产品卡片 */
.xtx-ai-cards { margin-top: 8px; }
.xtx-ai-card {
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.5;
}
.xtx-ai-card-model {
    font-weight: 600;
    color: var(--xtx-ai-red);
    font-size: 14px;
    margin-bottom: 4px;
    word-break: break-all;
}
.xtx-ai-card-model a { color: var(--xtx-ai-red); text-decoration: none; }
.xtx-ai-card-model a:hover { text-decoration: underline; }
.xtx-ai-card-row { color: #666; }
.xtx-ai-card-price { color: var(--xtx-ai-red); font-weight: 600; margin-top: 4px; }

/* 转人工按钮 */
.xtx-ai-human-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 6px 18px;
    background: var(--xtx-ai-red);
    color: #fff !important;
    border-radius: 20px;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    border: 0;
}
.xtx-ai-human-btn:hover { background: var(--xtx-ai-red-dark); }

/* 转人工倒计时转接条（客户明确要求转人工时自动跳转） */
.xtx-ai-redirect {
    margin-top: 10px;
    padding: 8px 12px;
    background: #fef0f0;
    border: 1px solid #f6caca;
    border-radius: 8px;
    font-size: 13px;
    color: var(--xtx-ai-red);
    line-height: 1.6;
}
.xtx-ai-redirect b { font-weight: 700; }
.xtx-ai-redirect a {
    color: var(--xtx-ai-red);
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
    margin-left: 8px;
    white-space: nowrap;
}
.xtx-ai-redirect a:hover { color: var(--xtx-ai-red-dark); }
.xtx-ai-redirect .xtx-ai-redirect-cancel { color: #999; font-weight: 400; }
.xtx-ai-redirect .xtx-ai-redirect-cancel:hover { color: #666; }

/* 快捷问 */
.xtx-ai-quick {
    padding: 8px 16px;
    border-top: 1px solid #eee;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}
.xtx-ai-quick button {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 14px;
    padding: 4px 12px;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    transition: all .15s;
}
.xtx-ai-quick button:hover { border-color: var(--xtx-ai-red); color: var(--xtx-ai-red); }

/* 输入区 */
.xtx-ai-ft {
    padding: 10px 16px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}
.xtx-ai-ft textarea {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
    font-family: inherit;
}
.xtx-ai-ft textarea:focus { border-color: var(--xtx-ai-red); }
.xtx-ai-send {
    background: var(--xtx-ai-red);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s;
}
.xtx-ai-send:hover { background: var(--xtx-ai-red-dark); }
.xtx-ai-send:disabled { background: #ccc; cursor: not-allowed; }

/* —— 移动端 —— */
@media (max-width: 768px) {
    .xtx-ai-fab {
        width: 48px;
        height: 48px;
        right: 14px;
        bottom: calc(var(--xtx-ai-tabbar-h) + var(--xtx-ai-safe-b) + 16px);
    }
    body.m-has-bottom-bar .xtx-ai-fab {
        bottom: calc(var(--xtx-ai-tabbar-h) + 60px + var(--xtx-ai-safe-b) + 16px);
    }
    body.m-cart-fix .xtx-ai-fab {
        bottom: calc(var(--xtx-ai-tabbar-h) + var(--xtx-ai-buycar-h) + var(--xtx-ai-safe-b) + 16px);
    }

    .xtx-ai-panel {
        right: 0;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        padding-bottom: var(--xtx-ai-safe-b);
    }
    .xtx-ai-mask {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .45);
        z-index: 9598;
    }
    .xtx-ai-mask[hidden] { display: none; }
    .xtx-ai-bubble { max-width: 85%; }
}
