/* ============================================
   YTC 官网 AI 助手悬浮对话框（chat-widget）
   右下角悬浮球 + 右侧悬浮窗（360px，随对话内容自动加高，上限 720px）
   ============================================ */
#ytc-ai-widget {
  position: fixed;
  inset: 0;
  z-index: 2147483647;   /* 顶层容器，确保悬浮球/面板不被页面元素盖住 */
  pointer-events: none;  /* 容器全屏但不拦截页面交互，子元素单独恢复 */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #1f2937;
}
#ytc-ai-widget .ai-ball,
#ytc-ai-widget .ai-panel {
  pointer-events: auto;
}

/* ---------- 悬浮球 ---------- */
#ytc-ai-widget .ai-ball {
  position: fixed;
  right: 22px;
  bottom: 26px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff7a2e, #ffb066);
  box-shadow: 0 8px 24px rgba(255, 122, 46, 0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}
#ytc-ai-widget .ai-ball:hover {
  transform: scale(1.08);
  box-shadow: 0 10px 30px rgba(255, 122, 46, 0.6);
}
#ytc-ai-widget .ai-ball svg {
  width: 30px;
  height: 30px;
  fill: #fff;
}
#ytc-ai-widget .ai-ball .ai-ball-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  animation: ai-pulse 1.6s ease-in-out infinite;
}
@keyframes ai-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}

/* ---------- 悬浮窗 ---------- */
#ytc-ai-widget .ai-panel {
  position: fixed;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 360px;
  height: auto;                        /* 随对话内容自动加高 */
  min-height: 480px;
  max-height: min(720px, calc(100vh - 48px));
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 48px rgba(15, 40, 80, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform-origin: right bottom;
  transform: translateY(-50%) scale(0.92);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}
#ytc-ai-widget .ai-panel.ai-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) scale(1);
}

/* ---------- 头部 ---------- */
#ytc-ai-widget .ai-header {
  background: linear-gradient(135deg, #134e8e, #1e6bc4);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#ytc-ai-widget .ai-header .ai-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 15px;
}
#ytc-ai-widget .ai-header .ai-title {
  flex: 1;
}
#ytc-ai-widget .ai-header .ai-title strong {
  font-size: 15px;
  display: block;
}
#ytc-ai-widget .ai-header .ai-title span {
  font-size: 11px;
  opacity: 0.85;
}
#ytc-ai-widget .ai-header .ai-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  padding: 4px;
}
#ytc-ai-widget .ai-header .ai-close:hover { opacity: 1; }

/* ---------- 主体 ---------- */
#ytc-ai-widget .ai-body {
  flex: 1;
  min-height: 0;                       /* 面板达上限后允许收缩，消息区内部滚动 */
  overflow: hidden;
  position: relative;
  background: #f6f8fb;
  display: flex;
  flex-direction: column;
}

/* 手机号输入视图 */
#ytc-ai-widget .ai-view-login {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}
#ytc-ai-widget .ai-view-login h3 {
  margin: 0;
  font-size: 17px;
  color: #134e8e;
  text-align: center;
}
#ytc-ai-widget .ai-view-login p.ai-tip {
  margin: 0 0 6px;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
  line-height: 1.6;
}
#ytc-ai-widget .ai-view-login input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  font-size: 15px;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  outline: none;
}
#ytc-ai-widget .ai-view-login input:focus {
  border-color: #1e6bc4;
  box-shadow: 0 0 0 3px rgba(30, 107, 196, 0.12);
}
#ytc-ai-widget .ai-view-login .ai-privacy {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 11px;
  color: #6b7280;
  line-height: 1.5;
}
#ytc-ai-widget .ai-view-login .ai-privacy input {
  width: 14px;
  height: 14px;
  margin-top: 1px;
  flex-shrink: 0;
  cursor: pointer;
}
#ytc-ai-widget .ai-btn-primary {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #ff7a2e, #ff9a5c);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
#ytc-ai-widget .ai-btn-primary:hover { opacity: 0.9; }
#ytc-ai-widget .ai-btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
#ytc-ai-widget .ai-view-login .ai-err {
  color: #dc2626;
  font-size: 12px;
  min-height: 16px;
  text-align: center;
}

/* 聊天视图 */
#ytc-ai-widget .ai-view-chat {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}
#ytc-ai-widget .ai-view-chat.ai-active { display: flex; }

/* 历史对话视图（聊天工具式列表） */
#ytc-ai-widget .ai-view-history {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  background: #f6f8fb;
}
#ytc-ai-widget .ai-h-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  flex-shrink: 0;
}
#ytc-ai-widget .ai-h-title { font-size: 15px; font-weight: 700; color: #1f2d3d; }
#ytc-ai-widget .ai-h-new {
  border: 1px solid #1e6bc4;
  color: #1e6bc4;
  background: #fff;
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
#ytc-ai-widget .ai-h-new:hover { background: #eef4fc; }
#ytc-ai-widget .ai-history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 10px;
}
#ytc-ai-widget .ai-h-item {
  background: #fff;
  border: 1px solid #e4e9f0;
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
#ytc-ai-widget .ai-h-item:hover { border-color: #1e6bc4; }
#ytc-ai-widget .ai-h-item.ai-h-active { border-color: #1e6bc4; background: #f3f8ff; }
#ytc-ai-widget .ai-h-tt {
  font-size: 13px;
  color: #22324a;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#ytc-ai-widget .ai-h-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; font-size: 11.5px; color: #8a97a8; }
#ytc-ai-widget .ai-h-badge { color: #1e6bc4; font-weight: 600; }
#ytc-ai-widget .ai-h-empty { text-align: center; color: #9aa7b8; font-size: 13px; padding: 32px 12px; }

/* 聊天顶部返回栏 */
#ytc-ai-widget .ai-chat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #e8ecf2;
  background: #fff;
  flex-shrink: 0;
}
#ytc-ai-widget .ai-back {
  border: none;
  background: none;
  color: #1e6bc4;
  font-size: 12.5px;
  cursor: pointer;
  padding: 2px 4px;
  white-space: nowrap;
}
#ytc-ai-widget .ai-chat-title { font-size: 12.5px; color: #8a97a8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ytc-ai-widget .ai-msgs {
  flex: 1;
  min-height: 0;                       /* 面板达上限后消息区收缩并内部滚动 */
  overflow-y: auto;
  padding: 14px 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#ytc-ai-widget .ai-msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
#ytc-ai-widget .ai-msg.ai-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #134e8e, #1e6bc4);
  color: #fff;
  border-bottom-right-radius: 3px;
}
#ytc-ai-widget .ai-msg.ai-bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e5e9f0;
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 3px rgba(15, 40, 80, 0.05);
}
#ytc-ai-widget .ai-msg.ai-typing {
  color: #9ca3af;
  font-style: italic;
}
#ytc-ai-widget .ai-msg a {
  color: #1e6bc4;
  text-decoration: underline;
  word-break: break-all;
}
#ytc-ai-widget .ai-msg a:hover { color: #ff7a2e; }
#ytc-ai-widget .ai-msg.ai-user a { color: #dbeafe; }

/* ---------- 选项卡片（入口三选项 / 问卷选项，点击即发送） ---------- */
#ytc-ai-widget .ai-options {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
/* 入口三选项：一排三列等宽，居中显示 */
#ytc-ai-widget .ai-options-entry {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
#ytc-ai-widget .ai-options-entry .ai-option {
  text-align: center;
  padding: 8px 4px;
  white-space: nowrap;
}
#ytc-ai-widget .ai-option {
  border: 1px solid #bcd3ee;
  background: #f3f8ff;
  color: #134e8e;
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 12.5px;
  line-height: 1.4;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#ytc-ai-widget .ai-option:hover {
  background: #134e8e;
  border-color: #134e8e;
  color: #fff;
}
#ytc-ai-widget .ai-option:active { transform: scale(0.98); }
#ytc-ai-widget .ai-option:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- 产品图片卡片（AI 回复产品链接时异步渲染） ---------- */
#ytc-ai-widget .ai-products {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
#ytc-ai-widget .ai-product {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  background: #fafbfd;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, background 0.15s;
}
#ytc-ai-widget .ai-product:hover {
  border-color: #1e6bc4;
  background: #f3f8ff;
}
#ytc-ai-widget .ai-product-img {
  width: 100%;
  height: 64px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #eef1f5;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ytc-ai-widget .ai-product-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#ytc-ai-widget .ai-product-name {
  font-size: 12px;
  color: #33465f;
  line-height: 1.3;
  text-align: center;
  word-break: break-all;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  max-width: 100%;
}
#ytc-ai-widget .ai-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e8ecf2;
  flex-shrink: 0;
}
#ytc-ai-widget .ai-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  min-height: 34px;                    /* 单行基准高度 */
  max-height: 96px;                    /* 随输入自动加高，超过后内部滚动 */
  overflow-y: auto;
  box-sizing: border-box;
}
#ytc-ai-widget .ai-input-row textarea:focus {
  border-color: #1e6bc4;
  box-shadow: 0 0 0 3px rgba(30, 107, 196, 0.1);
}
#ytc-ai-widget .ai-input-row .ai-mic {
  width: 36px;
  flex-shrink: 0;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  background: #fff;
  color: #1e6bc4;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  outline: none;
}
#ytc-ai-widget .ai-input-row .ai-mic:hover { background: #eef4fc; }
#ytc-ai-widget .ai-input-row .ai-mic svg { width: 17px; height: 17px; fill: currentColor; }
#ytc-ai-widget .ai-input-row .ai-mic.ai-mic-press {
  background: #1e6bc4;
  border-color: #1e6bc4;
  color: #fff;
}
#ytc-ai-widget .ai-input-row .ai-mic.ai-mic-on {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  animation: ai-mic-pulse 1s ease-in-out infinite;
}
@keyframes ai-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0.15); }
}
/* 按住说话按钮（语音模式下替代输入框） */
#ytc-ai-widget .ai-input-row .ai-voice-btn {
  display: none;
  flex: 1;
  height: 38px;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  background: #f3f6fb;
  color: #374151;
  font-size: 14px;
  font-family: inherit;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;          /* 防止按住时页面滚动/手势干扰 */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#ytc-ai-widget .ai-input-row .ai-voice-btn.ai-recording {
  background: #eef2f8;
  color: #1e6bc4;
}
#ytc-ai-widget .ai-input-row .ai-voice-btn.ai-cancel {
  background: #fee2e2;
  color: #dc2626;
}
#ytc-ai-widget .ai-input-row .ai-send {
  width: 62px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #ff7a2e, #ff9a5c);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
#ytc-ai-widget .ai-input-row .ai-send:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- 底部状态提示栏 ---------- */
#ytc-ai-widget .ai-footer {
  flex-shrink: 0;
  padding: 6px 12px;
  background: #fafbfc;
  border-top: 1px solid #eef1f5;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ytc-ai-widget .ai-footer .ai-status {
  font-size: 11.5px;
  color: #6b7280;
  min-height: 14px;
}

/* ---------- 历史提示条 ---------- */
#ytc-ai-widget .ai-hint {
  align-self: flex-start;
  max-width: 92%;
  font-size: 11.5px;
  color: #6b7280;
  background: #eef4fc;
  border: 1px dashed #b9d3f0;
  border-radius: 8px;
  padding: 7px 10px;
  line-height: 1.6;
}

@media (max-width: 640px) {
  #ytc-ai-widget .ai-panel {
    right: 8px;
    left: 8px;
    width: auto;
    height: auto;
    min-height: 340px;
    max-height: calc(100vh - 24px);
    top: 50%;
  }
}
