/* ===== AI 客服浮窗 ===== */
#aiChatRoot{position:fixed;right:20px;bottom:20px;z-index:99990;font-size:14px}
#aiChatBtn{width:58px;height:58px;border-radius:50%;border:none;cursor:pointer;background:linear-gradient(135deg,#1E40AF,#0EA5E9);color:#fff;box-shadow:0 8px 24px rgba(30,64,175,.34);display:flex;align-items:center;justify-content:center;position:relative;transition:transform .18s ease,box-shadow .18s ease}
#aiChatBtn:hover{transform:translateY(-2px);box-shadow:0 12px 30px rgba(30,64,175,.42)}
#aiChatBtn svg{width:26px;height:26px}
#aiChatBtn .ai-dot{position:absolute;top:-2px;right:-2px;background:#EF4444;color:#fff;font-size:10px;font-weight:700;line-height:1;padding:3px 5px;border-radius:9px;border:2px solid #fff}

#aiChatPanel{position:absolute;right:0;bottom:72px;width:380px;max-width:calc(100vw - 40px);height:620px;max-height:calc(100vh - 100px);background:#fff;border-radius:18px;box-shadow:0 20px 60px rgba(15,23,42,.18),0 2px 8px rgba(15,23,42,.06);display:flex;flex-direction:column;overflow:hidden;transform-origin:bottom right;transition:opacity .18s ease,transform .18s ease}
#aiChatPanel.hidden{opacity:0;transform:scale(.94) translateY(8px);pointer-events:none}

.ai-head{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:14px 16px;background:linear-gradient(135deg,#1E40AF,#0EA5E9);color:#fff;flex:0 0 auto;min-width:0}
.ai-head-left{display:flex;align-items:center;gap:10px;min-width:0}
.ai-avatar{width:34px;height:34px;border-radius:10px;background:rgba(255,255,255,.22);display:flex;align-items:center;justify-content:center;font-weight:700;font-size:13px;letter-spacing:.5px}
.ai-title{font-size:15px;font-weight:600;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ai-sub{font-size:11px;opacity:.86;line-height:1.3;margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#aiClose{background:transparent;border:none;color:#fff;font-size:24px;line-height:1;cursor:pointer;opacity:.85;padding:0 4px}
#aiClose:hover{opacity:1}

.ai-msgs{flex:1 1 auto;overflow-y:auto;overflow-x:hidden;padding:16px;background:#F8FAFC;display:flex;flex-direction:column;gap:12px;scroll-behavior:smooth;min-width:0}
.ai-msgs::-webkit-scrollbar{width:6px}
.ai-msgs::-webkit-scrollbar-thumb{background:#CBD5E1;border-radius:3px}

.msg{display:flex;gap:8px;width:100%;min-width:0}
.msg.user{flex-direction:row-reverse}
.bubble{padding:10px 13px;border-radius:14px;font-size:14px;line-height:1.65;flex:0 1 auto;min-width:0;max-width:calc(100% - 36px);overflow-wrap:anywhere;word-break:break-word;white-space:pre-wrap}
.msg.bot .bubble{background:#fff;border:1px solid #E2E8F0;border-bottom-left-radius:5px;color:#1E293B}
.msg.user .bubble{background:#1E40AF;color:#fff;border-bottom-right-radius:5px}
.msg .ava{width:28px;height:28px;border-radius:8px;flex:0 0 28px;display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:700}
.msg.bot .ava{background:linear-gradient(135deg,#1E40AF,#0EA5E9);color:#fff}
.msg.owner .ava{background:linear-gradient(135deg,#047857,#10B981);color:#fff}
.msg.owner .bubble{background:#F0FDF4;border-color:#BBF7D0}
.msg.user .ava{background:#E2E8F0;color:#475569}

.srcs{margin-top:9px;padding-top:9px;border-top:1px dashed #E2E8F0;display:flex;flex-direction:column;gap:5px}
.srcs-t{font-size:11px;color:#94A3B8;font-weight:600;letter-spacing:.3px}
.srcs a{font-size:12.5px;color:#1E40AF;text-decoration:none;line-height:1.5;display:block;padding-left:12px;position:relative}
.srcs a:before{content:"›";position:absolute;left:0;color:#94A3B8}
.srcs a:hover{text-decoration:underline}

.typing{display:flex;gap:4px;padding:13px}
.typing i{width:6px;height:6px;border-radius:50%;background:#94A3B8;animation:bnc 1.2s infinite}
.typing i:nth-child(2){animation-delay:.18s}
.typing i:nth-child(3){animation-delay:.36s}
@keyframes bnc{0%,60%,100%{transform:translateY(0);opacity:.5}30%{transform:translateY(-5px);opacity:1}}

.wechat-card{background:#fff;border:1px solid #DBEAFE;border-radius:12px;padding:12px;display:flex;gap:12px;align-items:center}
.wechat-card img{width:88px;height:88px;border-radius:8px;flex:0 0 88px;object-fit:contain;background:#fff;border:1px solid #F1F5F9;padding:2px}
.wechat-card .wc-t{font-size:13px;font-weight:600;color:#0F172A;margin-bottom:3px}
.wechat-card .wc-d{font-size:12px;color:#64748B;line-height:1.5}

.ai-quick{flex:0 0 auto;padding:9px 12px 9px;display:flex;gap:6px;flex-wrap:wrap;background:#fff;border-top:1px solid #F1F5F9}
.ai-quick button{border:1px solid #DBEAFE;background:#EFF6FF;color:#1E40AF;font-size:12px;padding:5px 10px;border-radius:999px;cursor:pointer;transition:.15s}
.ai-quick button:hover{background:#DBEAFE}

.ai-input-row{flex:0 0 auto;padding:10px 12px 12px;display:flex;gap:8px;align-items:flex-end;background:#fff}
#aiInput{flex:1;resize:none;border:1px solid #E2E8F0;border-radius:11px;padding:9px 12px;font-size:14px;font-family:inherit;line-height:1.5;max-height:96px;outline:none;transition:.15s;color:#0F172A}
#aiInput:focus{border-color:#93C5FD;box-shadow:0 0 0 3px rgba(59,130,246,.12)}
#aiSend{border:none;background:#1E40AF;color:#fff;font-size:13.5px;font-weight:600;padding:10px 16px;border-radius:11px;cursor:pointer;transition:.15s;flex:0 0 auto}
#aiSend:hover{background:#1E3A8A}
#aiSend:disabled{background:#CBD5E1;cursor:not-allowed}

.ai-head-actions{display:flex;align-items:center;gap:6px;flex:0 0 auto}
#aiHumanBtn{background:rgba(255,255,255,.18);border:1px solid rgba(255,255,255,.32);color:#fff;font-size:11.5px;font-weight:600;padding:5px 10px;border-radius:8px;cursor:pointer;white-space:nowrap;transition:.15s}
#aiHumanBtn:hover{background:rgba(255,255,255,.32)}

.handoff{background:#fff;border:1px solid #DBEAFE;border-radius:14px;padding:14px;box-shadow:0 2px 10px rgba(30,64,175,.06)}
.handoff .hf-t{font-size:13.5px;font-weight:700;color:#1E40AF;margin-bottom:4px}
.handoff .hf-d{font-size:12px;color:#64748B;margin-bottom:11px;line-height:1.55}
.handoff input,.handoff textarea{width:100%;border:1px solid #E2E8F0;border-radius:9px;padding:8px 10px;font-size:13px;font-family:inherit;outline:none;margin-bottom:8px;resize:none;color:#0F172A;transition:.15s}
.handoff input:focus,.handoff textarea:focus{border-color:#93C5FD;box-shadow:0 0 0 3px rgba(59,130,246,.1)}
.hf-row{display:flex;gap:8px}
.hf-row button{flex:1;border:none;border-radius:9px;padding:9px;font-size:13px;cursor:pointer;font-weight:600;transition:.15s}
#hfSubmit{background:#1E40AF;color:#fff}
#hfSubmit:hover{background:#1E3A8A}
#hfSubmit:disabled{background:#CBD5E1;cursor:not-allowed}
#hfCancel{background:#F1F5F9;color:#64748B}
#hfCancel:hover{background:#E2E8F0}
.hf-ok{font-size:13.5px;color:#059669;font-weight:600;text-align:center;padding:10px}

@media(max-width:520px){
  #aiChatRoot{right:14px;bottom:14px}
  #aiChatPanel{position:fixed;left:0;right:0;bottom:0;top:0;width:100vw;max-width:100vw;height:100%;max-height:100%;border-radius:0;transform-origin:center}
  #aiChatPanel.hidden{transform:translateY(20px)}
}

/* 未读提醒 */
#aiChatBtn .ai-dot.unread{font-size:11px;padding:3px 6px;animation:aiPulse 1.8s ease-in-out infinite}
@keyframes aiPulse{0%,100%{transform:scale(1)}50%{transform:scale(1.14)}}
/* 主动邀请气泡 */
.ai-invite{position:fixed;right:86px;bottom:30px;max-width:236px;background:#fff;border:1px solid #E2E8F0;border-radius:14px;box-shadow:0 10px 28px rgba(15,23,42,.14);padding:12px 30px 12px 14px;font-size:13px;line-height:1.6;color:#1E293B;z-index:99991;display:none;cursor:pointer}
.ai-invite.on{display:block;animation:aiInvIn .26s ease}
@keyframes aiInvIn{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
.ai-invite b{color:#1E40AF}
.ai-invite .ai-inv-x{position:absolute;top:2px;right:6px;border:0;background:none;font-size:16px;color:#94A3B8;cursor:pointer;line-height:1;padding:4px}
@media (max-width:640px){.ai-invite{right:74px;bottom:24px;max-width:196px;font-size:12.5px;padding:10px 28px 10px 12px}}
/* 移动端底部安全区 */
@media(max-width:520px){
  .ai-input-row{padding-bottom:calc(12px + env(safe-area-inset-bottom))}
  .ai-quick{padding-bottom:calc(9px + env(safe-area-inset-bottom))}
}

/* 结束态按钮 */
#aiHumanBtn.end{background:#FEF2F2;border-color:#FECACA;color:#B91C1C}
#aiHumanBtn.end:hover{background:#FEE2E2}
/* 满意度 */
.ai-csat{display:flex;align-items:center;gap:7px;flex-wrap:wrap;margin:2px 0 0 36px;font-size:12.5px;color:#64748B}
.ai-csat button{border:1px solid #DBEAFE;background:#fff;color:#1E40AF;font-size:12.5px;padding:4px 11px;border-radius:999px;cursor:pointer;transition:.15s}
.ai-csat button:hover{background:#EFF6FF}
.ai-csat.done{color:#059669;font-weight:600;margin-left:36px}

/* 图片上传 */
.ai-attach{flex:0 0 auto;width:34px;height:34px;border:1px solid #E2E8F0;background:#fff;border-radius:9px;cursor:pointer;color:#64748B;font-size:15px;display:flex;align-items:center;justify-content:center;padding:0;transition:.15s}
.ai-attach:hover{background:#F1F5F9;color:#1E40AF}
.ai-img{max-width:min(200px,58vw);border-radius:8px;display:block;cursor:zoom-in}

/* 头部图标按钮（复制对话） */
#aiCopy{background:rgba(255,255,255,.18);border:1px solid rgba(255,255,255,.32);color:#fff;width:26px;height:26px;border-radius:8px;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0;transition:.15s}
#aiCopy:hover{background:rgba(255,255,255,.32)}
#aiCopy svg{display:block}

/* 轻提示 */
.ai-toast{position:absolute;left:50%;bottom:88px;transform:translate(-50%,6px);background:rgba(15,23,42,.92);color:#fff;font-size:12.5px;line-height:1.5;padding:8px 14px;border-radius:10px;max-width:82%;text-align:center;opacity:0;pointer-events:none;transition:opacity .2s ease,transform .2s ease;z-index:5}
.ai-toast.on{opacity:1;transform:translate(-50%,0)}

/* ===== 深色模式 ===== */
@media (prefers-color-scheme: dark){
  #aiChatPanel{background:#0F172A;box-shadow:0 20px 60px rgba(0,0,0,.5)}
  #aiChatBtn{box-shadow:0 8px 24px rgba(2,6,23,.6)}
  .ai-head{background:linear-gradient(135deg,#1E3A8A,#0C4A6E)}
  .ai-msgs{background:#0B1220}
  .ai-msgs::-webkit-scrollbar-thumb{background:#334155}
  .msg.bot .bubble{background:#1E293B;border-color:#334155;color:#E2E8F0}
  .msg.owner .bubble{background:#052E16;border-color:#166534;color:#DCFCE7}
  .msg.user .bubble{background:#1D4ED8;color:#fff}
  .msg.user .ava{background:#334155;color:#CBD5E1}
  .srcs{border-top-color:#334155}
  .srcs-t{color:#64748B}
  .srcs a{color:#93C5FD}
  .typing i{background:#64748B}
  .ai-quick{background:#0F172A;border-top-color:#1E293B}
  .ai-quick button{background:#1E293B;border-color:#334155;color:#93C5FD}
  .ai-quick button:hover{background:#334155}
  .ai-input-row{background:#0F172A}
  #aiInput{background:#0B1220;border-color:#334155;color:#E2E8F0}
  #aiInput:focus{border-color:#2563EB;box-shadow:0 0 0 3px rgba(37,99,235,.2)}
  #aiInput::placeholder{color:#64748B}
  .ai-attach{background:#1E293B;border-color:#334155;color:#94A3B8}
  .ai-attach:hover{background:#334155;color:#93C5FD}
  #aiSend{background:#1D4ED8}
  #aiSend:hover{background:#1E40AF}
  #aiHumanBtn.end{background:rgba(185,28,28,.18);border-color:rgba(248,113,113,.4);color:#FCA5A5}
  .ai-csat{color:#94A3B8}
  .ai-csat button{background:#1E293B;border-color:#334155;color:#93C5FD}
  .ai-csat button:hover{background:#334155}
  .ai-invite{background:#1E293B;border-color:#334155;color:#E2E8F0;box-shadow:0 10px 28px rgba(0,0,0,.5)}
  .ai-invite b{color:#93C5FD}
  .ai-toast{background:rgba(226,232,240,.95);color:#0F172A}
}

/* 微信引导卡片 */
.wechat-card .wc-body{min-width:0;flex:1}
.wechat-card .wc-copy{display:inline-block;margin-top:6px;font-size:12px;color:#1E40AF;font-weight:600;text-decoration:none;border-bottom:1px dashed rgba(30,64,175,.4)}
.wechat-card .wc-copy:hover{color:#1E3A8A}
.wechat-card.offline{background:#FFFBEB;border-color:#FDE68A}
.wechat-card.offline .wc-t{color:#B45309}
@media (prefers-color-scheme: dark){
  .wechat-card{background:#1E293B;border-color:#334155}
  .wechat-card .wc-t{color:#E2E8F0}
  .wechat-card .wc-d{color:#94A3B8}
  .wechat-card .wc-copy{color:#93C5FD;border-bottom-color:rgba(147,197,253,.4)}
  .wechat-card.offline{background:#1C1917;border-color:#78350F}
  .wechat-card.offline .wc-t{color:#FBBF24}
}
