#ai-chat-trigger{
  position:fixed;z-index:99999;cursor:pointer;
  bottom:24px;right:24px;
  width:60px;height:60px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  box-shadow:0 4px 20px rgba(0,0,0,.25);
  transition:transform .3s,box-shadow .3s;
  background:linear-gradient(135deg,#1890ff,#096dd9)
}
#ai-chat-trigger:hover{transform:scale(1.1);box-shadow:0 6px 28px rgba(0,0,0,.32)}
#ai-chat-trigger svg{width:28px;height:28px;fill:#fff}
#ai-chat-trigger .ai-badge{
  position:absolute;top:-4px;right:-4px;
  background:#ff4d4f;color:#fff;font-size:11px;
  min-width:20px;height:20px;border-radius:10px;
  display:none;align-items:center;justify-content:center;
  border:2px solid #fff;padding:0 4px;
  animation:badgePulse 2s infinite
}
@keyframes badgePulse{0%,100%{transform:scale(1)}50%{transform:scale(1.15)}}

/* =========================================
   手机端遮罩层
   ========================================= */
#ai-chat-overlay{
  display:none;
  position:fixed;inset:0;z-index:99998;
  background:rgba(0,0,0,.45);
  backdrop-filter:blur(3px);
  -webkit-backdrop-filter:blur(3px);
  animation:overlayIn .28s ease
}
#ai-chat-overlay.show{display:block}
@keyframes overlayIn{from{opacity:0}to{opacity:1}}

/* =========================================
   聊天窗口 — 桌面端
   浮于屏幕右下角，底部保留 96px 间距，四角全圆
   ========================================= */
#ai-chat-widget{
  position:fixed;z-index:100000;
  width:380px;height:600px;
  max-height:calc(100vh - 120px);
  right:24px;bottom:96px;          /* ← 距底部间距 */
  border-radius:16px;              /* ← 四角全圆 */
  overflow:hidden;
  box-shadow:0 16px 48px rgba(0,0,0,.16),
             0 4px 12px rgba(0,0,0,.08),
             0 0 0 1px rgba(0,0,0,.05);
  display:none;flex-direction:column;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;
  background:#fff;
  animation:desktopSlideUp .35s cubic-bezier(0.16,1,0.3,1)
}
@keyframes desktopSlideUp{
  from{opacity:0;transform:translateY(18px) scale(.97)}
  to  {opacity:1;transform:translateY(0)   scale(1)}
}

/* =========================================
   平板适配 481-768px
   ========================================= */
@media(max-width:768px) and (min-width:481px){
  #ai-chat-widget{
    width:calc(100vw - 32px);max-width:420px;
    height:calc(100vh - 110px);max-height:620px;
    right:16px;bottom:88px;
    border-radius:16px
  }
  #ai-chat-trigger{bottom:20px;right:16px}
}

/* =========================================
   手机端适配 ≤480px
   底部抽屉样式，留出顶部约 1/3 屏幕高度
   ========================================= */
@media(max-width:480px){

  #ai-chat-trigger{
    width:54px;height:54px;
    bottom:16px!important;right:16px!important
  }
  #ai-chat-trigger svg{width:24px;height:24px}

  #ai-chat-widget{
    /* 宽度铺满 */
    width:100%!important;
    left:0!important;right:0!important;
    /* 底部贴边 */
    bottom:0!important;top:auto!important;
    /* 高度约占屏幕 2/3，留出顶部 1/3 */
    height:67vh!important;
    height:67dvh!important;
    max-height:67vh!important;
    max-height:67dvh!important;
    /* 仅顶部圆角 */
    border-radius:20px 20px 0 0!important;
    box-shadow:0 -8px 40px rgba(0,0,0,.18)!important;
    animation:mobileSheetUp .4s cubic-bezier(0.16,1,0.3,1)!important
  }
  @keyframes mobileSheetUp{
    from{transform:translateY(100%)}
    to  {transform:translateY(0)}
  }

  /* 消息气泡自适应宽度 */
  .ai-m .ai-bb,.ai-m.img-msg .ai-bb{max-width:calc(100vw - 100px)}

  /* Safe-area 适配 */
  .ai-ftr{padding-bottom:calc(12px + env(safe-area-inset-bottom))}
  .ai-form .af-foot{padding-bottom:calc(24px + env(safe-area-inset-bottom))}
}

/* =========================================
   手机端顶部拖动把手
   ========================================= */
@media(max-width:480px){
  .ai-hdr{padding-top:22px}
  .ai-hdr::before{
    content:'';
    position:absolute;top:9px;left:50%;transform:translateX(-50%);
    width:36px;height:4px;border-radius:2px;
    background:rgba(255,255,255,.38)
  }
}

/* =========================================
   头部
   ========================================= */
.ai-hdr{
  padding:14px 20px;
  display:flex;align-items:center;justify-content:space-between;
  color:#fff;flex-shrink:0;position:relative;
  background:linear-gradient(135deg,#1890ff,#096dd9);
  user-select:none
}
.ai-hdr .ai-hdr-l{display:flex;align-items:center;gap:10px;min-width:0;flex:1}
.ai-hdr .ai-hdr-l .ai-av{
  width:40px;height:40px;border-radius:50%;
  background:rgba(255,255,255,.2);
  display:flex;align-items:center;justify-content:center;
  overflow:hidden;flex-shrink:0;position:relative
}
.ai-hdr .ai-hdr-l .ai-av::after{
  content:'';position:absolute;bottom:1px;right:1px;
  width:10px;height:10px;border-radius:50%;
  background:#52c41a;border:2px solid #fff
}
.ai-hdr .ai-hdr-l .ai-av svg{width:22px;height:22px;fill:#fff}
.ai-hdr .ai-hdr-l .ai-av img{width:100%;height:100%;object-fit:cover}
.ai-hdr .ai-hdr-l .ai-info{min-width:0;flex:1}
.ai-hdr .ai-hdr-l .ai-info h4{
  margin:0;font-size:15px;font-weight:600;color:#fff;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis
}
.ai-hdr .ai-hdr-l .ai-info span{
  font-size:11px;opacity:.9;color:#fff;
  display:flex;align-items:center;gap:4px
}
.ai-hdr .ai-hdr-l .ai-info span::before{
  content:'';width:6px;height:6px;border-radius:50%;
  background:#52c41a;display:inline-block;animation:pulse 2s infinite
}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.4}}
.ai-hdr .ai-hdr-r{display:flex;gap:4px;flex-shrink:0}
.ai-hdr .ai-hdr-r button{
  background:none;border:none;color:#fff;cursor:pointer;
  width:32px;height:32px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  opacity:.8;font-size:20px;line-height:1;
  transition:background .2s,opacity .2s
}
.ai-hdr .ai-hdr-r button:hover{opacity:1;background:rgba(255,255,255,.15)}

/* =========================================
   消息区
   ========================================= */
.ai-body{flex:1;display:flex;flex-direction:column;overflow:hidden;position:relative;min-height:0}
.ai-msgs{
  flex:1;overflow-y:auto;padding:16px;background:#f7f8fa;
  -webkit-overflow-scrolling:touch
}
.ai-msgs::-webkit-scrollbar{width:4px}
.ai-msgs::-webkit-scrollbar-thumb{background:#ccc;border-radius:2px}
.ai-msgs::-webkit-scrollbar-thumb:hover{background:#999}

.ai-m{margin-bottom:16px;display:flex;gap:8px;animation:aiIn .3s ease}
@keyframes aiIn{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}
.ai-m.user{flex-direction:row-reverse}
.ai-m .ai-mav{
  width:36px;height:36px;border-radius:50%;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;
  font-size:13px;font-weight:600;overflow:hidden
}
.ai-m .ai-mav img{width:100%;height:100%;object-fit:cover}
.ai-m.user .ai-mav{background:#e6f7ff;color:#1890ff}
.ai-m.ai .ai-mav,.ai-m.staff .ai-mav{background:#f0f5ff;color:#2f54eb}
.ai-m.system .ai-mav{display:none}
.ai-m .ai-bb{
  max-width:270px;padding:10px 14px;border-radius:14px;
  font-size:14px;line-height:1.7;word-break:break-word
}
.ai-m.user .ai-bb{color:#fff;border-bottom-right-radius:4px;background:#1890ff}
.ai-m.ai .ai-bb,.ai-m.staff .ai-bb{
  background:#fff;color:#333;border-bottom-left-radius:4px;
  box-shadow:0 1px 4px rgba(0,0,0,.06)
}
.ai-m.system .ai-bb{
  background:#fff7e6;color:#d48806;border-radius:8px;
  font-size:12px;max-width:100%;text-align:center;
  margin:0 auto;padding:8px 14px
}
.ai-m.system{justify-content:center}
.ai-m .ai-bb .ai-tm{font-size:11px;margin-top:6px;display:block}
.ai-m.user .ai-bb .ai-tm{color:rgba(255,255,255,.65)}
.ai-m.ai .ai-bb .ai-tm,.ai-m.staff .ai-bb .ai-tm{color:rgba(0,0,0,.3)}

/* 富文本 */
.ai-m .ai-bb .ai-text{white-space:pre-wrap;word-break:break-word}
.ai-m .ai-bb .ai-text b,.ai-m .ai-bb .ai-text strong{font-weight:600}
.ai-m .ai-bb .ai-text a{color:#1890ff;text-decoration:underline;word-break:break-all}
.ai-m.user .ai-bb .ai-text a{color:#fff}
.ai-m .ai-bb .ai-text .ai-num{display:inline-block;margin-right:4px;font-weight:600;color:#1890ff}
.ai-m.user .ai-bb .ai-text .ai-num{color:#fff}
.ai-m .ai-bb .ai-text .ai-code{
  background:rgba(0,0,0,.06);padding:1px 6px;border-radius:3px;
  font-family:Monaco,Menlo,Consolas,monospace;font-size:.9em
}
.ai-m.user .ai-bb .ai-text .ai-code{background:rgba(255,255,255,.2)}

/* 图片消息 */
.ai-m.img-msg .ai-bb{padding:6px;max-width:230px;background:#fff}
.ai-m.img-msg.user .ai-bb{background:#1890ff}
.ai-m.img-msg.staff .ai-bb{background:#f6ffed}
.ai-m.img-msg .ai-img{display:block;max-width:100%;max-height:220px;border-radius:10px;cursor:pointer;transition:transform .2s}
.ai-m.img-msg .ai-img:hover{transform:scale(1.02)}
.ai-m.img-msg .ai-img-caption{margin-top:6px;padding:0 6px 2px;font-size:13px;line-height:1.5;word-break:break-word}
.ai-m.img-msg.user .ai-img-caption{color:#fff}
.ai-m.img-msg .ai-tm{margin-top:4px;padding:0 6px 2px}

/* 图片查看器 */
.ai-img-viewer{
  position:fixed;top:0;left:0;width:100%;height:100%;
  background:rgba(0,0,0,.92);z-index:999999;
  display:none;align-items:center;justify-content:center;cursor:zoom-out
}
.ai-img-viewer.show{display:flex}
.ai-img-viewer img{max-width:92%;max-height:92%;object-fit:contain;border-radius:4px}
.ai-img-viewer .ai-iv-close{
  position:absolute;top:20px;right:20px;
  width:42px;height:42px;border-radius:50%;
  background:rgba(255,255,255,.2);color:#fff;font-size:26px;
  display:flex;align-items:center;justify-content:center;cursor:pointer;
  transition:background .2s
}
.ai-img-viewer .ai-iv-close:hover{background:rgba(255,255,255,.3)}

/* 打字动画 */
.ai-typing{display:flex;gap:4px;padding:8px 14px;align-items:center}
.ai-typing span{width:6px;height:6px;border-radius:50%;background:#bbb;animation:tdot 1.4s infinite}
.ai-typing span:nth-child(2){animation-delay:.2s}
.ai-typing span:nth-child(3){animation-delay:.4s}
@keyframes tdot{0%,80%,100%{transform:scale(1);opacity:.4}40%{transform:scale(1.3);opacity:1}}

/* =========================================
   底部输入区
   ========================================= */
.ai-ftr{
  padding:12px 16px;background:#fff;
  border-top:1px solid #f0f0f0;flex-shrink:0
}
.ai-ftr .ai-irow{display:flex;gap:8px;align-items:flex-end}
.ai-ftr textarea{
  flex:1;border:1px solid #e0e0e0;border-radius:12px;
  padding:10px 14px;font-size:14px;resize:none;outline:none;
  font-family:inherit;max-height:80px;min-height:40px;
  line-height:1.4;transition:border-color .2s;
  color:#333;background:#fff;-webkit-appearance:none
}
.ai-ftr textarea:focus{border-color:#1890ff}
.ai-ftr .ai-img-btn,.ai-ftr .ai-sbtn{
  width:40px;height:40px;border-radius:50%;border:none;cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  flex-shrink:0;transition:all .2s;padding:0
}
.ai-ftr .ai-img-btn{background:#f0f0f0;color:#666}
.ai-ftr .ai-img-btn:hover{background:#e6f7ff;color:#1890ff}
.ai-ftr .ai-img-btn:active{transform:scale(.93)}
.ai-ftr .ai-img-btn svg{width:20px;height:20px;fill:currentColor}
.ai-ftr .ai-sbtn{background:#1890ff}
.ai-ftr .ai-sbtn:active{transform:scale(.93)}
.ai-ftr .ai-sbtn:disabled{opacity:.4;cursor:not-allowed}
.ai-ftr .ai-sbtn svg{width:18px;height:18px;fill:#fff}
.ai-ftr .ai-tools{display:flex;gap:12px;margin-top:8px;justify-content:center}
.ai-ftr .ai-tools button{
  background:none;border:none;color:#999;font-size:12px;
  cursor:pointer;transition:color .2s;padding:4px 8px;border-radius:4px
}
.ai-ftr .ai-tools button:hover{color:#1890ff;background:#f0f7ff}

/* 图片预览（发送前） */
.ai-img-preview{
  margin-bottom:10px;padding:10px;background:#f7f8fa;
  border:1px dashed #d9d9d9;border-radius:10px;
  display:none;position:relative
}
.ai-img-preview.show{display:block}
.ai-img-preview img{max-width:100%;max-height:120px;border-radius:8px;display:block}
.ai-img-preview .ai-img-remove{
  position:absolute;top:4px;right:4px;
  width:24px;height:24px;border-radius:50%;
  background:rgba(0,0,0,.5);color:#fff;border:none;
  cursor:pointer;font-size:14px;line-height:24px;text-align:center;padding:0
}
.ai-img-preview .ai-img-remove:hover{background:rgba(0,0,0,.7)}
.ai-img-preview .ai-upload-progress{
  position:absolute;bottom:0;left:0;right:0;
  height:3px;background:#e6f7ff;border-radius:0 0 10px 10px;overflow:hidden
}
.ai-img-preview .ai-upload-progress-bar{height:100%;background:#1890ff;width:0;transition:width .3s}

/* =========================================
   联系资料表单
   ========================================= */
.ai-form{
  position:absolute;top:0;left:0;right:0;bottom:0;
  background:#fff;z-index:10;display:none;
  flex-direction:column;overflow-y:auto;-webkit-overflow-scrolling:touch
}
.ai-form .af-head{padding:24px 24px 0;text-align:center}
.ai-form .af-head .af-icon{
  width:64px;height:64px;border-radius:50%;
  margin:0 auto 12px;display:flex;align-items:center;
  justify-content:center;font-size:28px;
  background:#e6f7ff;color:#1890ff
}
.ai-form .af-head h3{font-size:17px;font-weight:600;color:#1a1a2e;margin-bottom:6px}
.ai-form .af-head p{font-size:13px;color:#999;margin:0}
.ai-form .af-body{padding:20px 24px;flex:1}
.ai-form .af-g{margin-bottom:16px}
.ai-form .af-g label{display:block;font-size:13px;font-weight:600;color:#555;margin-bottom:6px}
.ai-form .af-g label .req{color:#ff4d4f;margin-left:2px}
.ai-form .af-g input,.ai-form .af-g textarea{
  width:100%;padding:10px 14px;border:1px solid #e0e0e0;
  border-radius:8px;font-size:14px;outline:none;
  font-family:inherit;transition:border-color .2s;
  color:#333;background:#fff;-webkit-appearance:none;box-sizing:border-box
}
.ai-form .af-g input:focus,.ai-form .af-g textarea:focus{
  border-color:#1890ff;box-shadow:0 0 0 2px rgba(24,144,255,.1)
}
.ai-form .af-g textarea{height:70px;resize:none}
.ai-form .af-g .af-err-input{border-color:#ff4d4f!important}
.ai-form .af-g .af-err{color:#ff4d4f;font-size:12px;margin-top:4px;display:none}
.ai-form .af-foot{padding:0 24px 24px}
.ai-form .af-submit{
  width:100%;padding:12px;border:none;border-radius:10px;
  font-size:15px;font-weight:600;color:#fff;cursor:pointer;
  transition:all .2s;background:linear-gradient(135deg,#1890ff,#096dd9)
}
.ai-form .af-submit:hover{opacity:.9}
.ai-form .af-submit:disabled{opacity:.5;cursor:not-allowed}

/* 拖拽提示 */
.ai-drop-hint{
  position:absolute;top:0;left:0;right:0;bottom:0;
  background:rgba(24,144,255,.1);border:2px dashed #1890ff;z-index:20;
  display:none;align-items:center;justify-content:center;
  color:#1890ff;font-size:16px;font-weight:600;pointer-events:none
}
.ai-drop-hint.show{display:flex}

/* =========================================
   多主题
   ========================================= */
.theme-green #ai-chat-trigger,.theme-green .ai-hdr{background:linear-gradient(135deg,#52c41a,#389e0d)}
.theme-green .ai-ftr .ai-sbtn,.theme-green .ai-m.user .ai-bb{background:#52c41a}
.theme-green .ai-form .af-head .af-icon{background:#f6ffed;color:#52c41a}
.theme-green .ai-form .af-submit{background:linear-gradient(135deg,#52c41a,#389e0d)}
.theme-green .ai-m.user .ai-mav{background:#f6ffed;color:#52c41a}

.theme-purple #ai-chat-trigger,.theme-purple .ai-hdr{background:linear-gradient(135deg,#722ed1,#531dab)}
.theme-purple .ai-ftr .ai-sbtn,.theme-purple .ai-m.user .ai-bb{background:#722ed1}
.theme-purple .ai-form .af-head .af-icon{background:#f9f0ff;color:#722ed1}
.theme-purple .ai-form .af-submit{background:linear-gradient(135deg,#722ed1,#531dab)}
.theme-purple .ai-m.user .ai-mav{background:#f9f0ff;color:#722ed1}

.theme-orange #ai-chat-trigger,.theme-orange .ai-hdr{background:linear-gradient(135deg,#fa8c16,#d46b08)}
.theme-orange .ai-ftr .ai-sbtn,.theme-orange .ai-m.user .ai-bb{background:#fa8c16}
.theme-orange .ai-form .af-head .af-icon{background:#fff7e6;color:#fa8c16}
.theme-orange .ai-form .af-submit{background:linear-gradient(135deg,#fa8c16,#d46b08)}
.theme-orange .ai-m.user .ai-mav{background:#fff7e6;color:#fa8c16}

.theme-red #ai-chat-trigger,.theme-red .ai-hdr{background:linear-gradient(135deg,#f5222d,#cf1322)}
.theme-red .ai-ftr .ai-sbtn,.theme-red .ai-m.user .ai-bb{background:#f5222d}
.theme-red .ai-form .af-head .af-icon{background:#fff1f0;color:#f5222d}
.theme-red .ai-form .af-submit{background:linear-gradient(135deg,#f5222d,#cf1322)}
.theme-red .ai-m.user .ai-mav{background:#fff1f0;color:#f5222d}

.theme-dark #ai-chat-trigger,.theme-dark .ai-hdr{background:linear-gradient(135deg,#2c3e50,#1a1a2e)}
.theme-dark .ai-ftr .ai-sbtn,.theme-dark .ai-m.user .ai-bb{background:#2c3e50}
.theme-dark .ai-form .af-head .af-icon{background:#f0f2f5;color:#2c3e50}
.theme-dark .ai-form .af-submit{background:linear-gradient(135deg,#2c3e50,#1a1a2e)}
.theme-dark .ai-m.user .ai-mav{background:#f0f2f5;color:#2c3e50}

/* 防止手机端滚动穿透 */
body.ai-chat-open{overflow:hidden;position:fixed;width:100%}
@media(min-width:481px){body.ai-chat-open{position:static;overflow:auto}}