/* ==========================================================================
   AI 客服浮窗（仅后台开启后由 public/chat.html 引入）
   ========================================================================== */

.fwchat {
  --fwchat-brand: #2f6bff;
  --fwchat-brand-dark: #1e51d8;
  --fwchat-ink: #0e1a2b;
  --fwchat-ink-2: #4a5a72;
  --fwchat-ink-3: #7d8ca2;
  --fwchat-line: #e4e9f2;
  --fwchat-soft: #f6f9fd;
  position: fixed;
  z-index: 9000;
  bottom: 24px;
  right: 24px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--fwchat-ink-2);
  -webkit-font-smoothing: antialiased;
}

.fwchat[data-position="left"] {
  right: auto;
  left: 24px;
}

/* ---------------------------------------------------------------- 启动按钮 */

.fwchat-launcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--fwchat-brand), #5b8dff);
  color: #fff;
  box-shadow: 0 14px 30px -10px rgba(47, 107, 255, .55), 0 2px 6px rgba(14, 26, 43, .12);
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
}

.fwchat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px -10px rgba(47, 107, 255, .6), 0 2px 8px rgba(14, 26, 43, .14);
}

.fwchat-launcher:active { transform: translateY(0) scale(.97); }

.fwchat-launcher svg { width: 26px; height: 26px; }

.fwchat-launcher::after {
  /* 呼吸光圈：不抢注意力，但让人注意到是「活的」 */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(47, 107, 255, .35);
  animation: fwchat-pulse 3.2s ease-out infinite;
  pointer-events: none;
}

@keyframes fwchat-pulse {
  0%   { transform: scale(1); opacity: .8; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

.fwchat.is-open .fwchat-launcher { opacity: 0; pointer-events: none; transform: scale(.85); }
.fwchat.is-open .fwchat-launcher::after { animation: none; }

/* ---------------------------------------------------------------- 面板 */

.fwchat-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  overflow: hidden;
  border: 1px solid var(--fwchat-line);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 30px 70px -24px rgba(14, 26, 43, .4), 0 2px 10px rgba(14, 26, 43, .06);
  opacity: 0;
  transform: translateY(10px) scale(.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}

.fwchat[data-position="left"] .fwchat-panel { right: auto; left: 0; transform-origin: bottom left; }

.fwchat.is-open .fwchat-panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* 头部 */
.fwchat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 14px 14px 12px 16px;
  border-bottom: 1px solid var(--fwchat-line);
  background: #fff;
}

.fwchat-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--fwchat-brand), #6c9bff);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}

.fwchat-head-main { flex: 1; min-width: 0; }

.fwchat-title {
  display: block;
  color: var(--fwchat-ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.fwchat-sub {
  display: block;
  margin-top: 1px;
  color: var(--fwchat-ink-3);
  font-size: 11.5px;
  line-height: 1.4;
}

.fwchat-head-act { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }

.fwchat-human {
  padding: 6px 10px;
  border: 1px solid var(--fwchat-line);
  border-radius: 999px;
  background: #fff;
  color: var(--fwchat-ink-2);
  font-size: 12.5px;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
  white-space: nowrap;
}

.fwchat-human:hover {
  border-color: var(--fwchat-brand);
  background: #f5f8ff;
  color: var(--fwchat-brand-dark);
}

.fwchat-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fwchat-ink-3);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}

.fwchat-close:hover { background: var(--fwchat-soft); color: var(--fwchat-ink); }

/* 消息区 */
.fwchat-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 8px;
  background: linear-gradient(180deg, #fbfcff 0%, #fff 42%);
  scrollbar-width: thin;
}

.fwchat-body::-webkit-scrollbar { width: 6px; }
.fwchat-body::-webkit-scrollbar-thumb { background: #dbe3f0; border-radius: 3px; }

.fwchat-welcome {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #dbe6ff;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  background: #f4f8ff;
  color: var(--fwchat-ink-2);
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.fwchat-msg {
  display: flex;
  flex-direction: column;
  margin-bottom: 14px;
  animation: fwchat-in .2s ease;
}

@keyframes fwchat-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.fwchat-msg--me { align-items: flex-end; }
.fwchat-msg--ai { align-items: flex-start; }

.fwchat-bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.fwchat-msg--me .fwchat-bubble {
  border-bottom-right-radius: 4px;
  background: var(--fwchat-brand);
  color: #fff;
}

.fwchat-msg--ai .fwchat-bubble {
  border: 1px solid var(--fwchat-line);
  border-bottom-left-radius: 4px;
  background: #fff;
  color: var(--fwchat-ink);
  box-shadow: 0 1px 2px rgba(14, 26, 43, .04);
}

.fwchat-msg--ai .fwchat-bubble a { color: var(--fwchat-brand); text-decoration: underline; }

.fwchat-tag {
  margin-top: 5px;
  padding: 0 2px;
  color: #a3b0c4;
  font-size: 11px;
  line-height: 1.5;
}

.fwchat-tag--warn { color: #c2703a; }

/* 系统提示行：已记录联系方式等（居中小条，不带 AI 标识） */
.fwchat-sysnote {
  width: fit-content;
  max-width: 88%;
  margin: 2px auto 12px;
  padding: 7px 12px;
  border: 1px solid #c9ecd8;
  border-radius: 999px;
  background: #f0fbf4;
  color: #15803d;
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
  animation: fwchat-in .2s ease;
}

/* 打字指示 */
.fwchat-typing { display: inline-flex; align-items: center; gap: 4px; height: 20px; }

.fwchat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #b9c7de;
  animation: fwchat-blink 1.2s infinite ease-in-out;
}

.fwchat-typing i:nth-child(2) { animation-delay: .18s; }
.fwchat-typing i:nth-child(3) { animation-delay: .36s; }

@keyframes fwchat-blink {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30%           { opacity: 1; transform: translateY(-2px); }
}

/* 出错时的行动按钮 */
.fwchat-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.fwchat-actions button {
  padding: 6px 12px;
  border: 1px solid var(--fwchat-line);
  border-radius: 999px;
  background: #fff;
  color: var(--fwchat-ink-2);
  font-size: 12.5px;
  cursor: pointer;
}

.fwchat-actions button:hover { border-color: var(--fwchat-brand); color: var(--fwchat-brand-dark); }

/* 快捷问法 */
.fwchat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
  padding: 0 16px 10px;
  background: #fff;
}

.fwchat-quick button {
  padding: 6px 11px;
  border: 1px solid #e2e9f6;
  border-radius: 999px;
  background: var(--fwchat-soft);
  color: var(--fwchat-ink-2);
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
}

.fwchat-quick button:hover {
  border-color: var(--fwchat-brand);
  background: #fff;
  color: var(--fwchat-brand-dark);
}

.fwchat.is-busy .fwchat-quick { display: none; }

/* 输入区 */
.fwchat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px 12px 6px;
  border-top: 1px solid var(--fwchat-line);
  background: #fff;
}

.fwchat-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 40px;
  max-height: 108px;
  padding: 9px 12px;
  border: 1px solid var(--fwchat-line);
  border-radius: 12px;
  background: #fff;
  color: var(--fwchat-ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.55;
  resize: none;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.fwchat-input::placeholder { color: #a3b0c4; }

.fwchat-input:focus {
  border-color: var(--fwchat-brand);
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .12);
}

.fwchat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--fwchat-brand);
  color: #fff;
  cursor: pointer;
  transition: background .18s ease, opacity .18s ease;
}

.fwchat-send:hover { background: var(--fwchat-brand-dark); }
.fwchat-send:disabled { opacity: .45; cursor: not-allowed; }
.fwchat-send svg { width: 18px; height: 18px; }

.fwchat-foot {
  flex: 0 0 auto;
  padding: 0 16px 10px;
  background: #fff;
  color: #a3b0c4;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.fwchat-foot button {
  padding: 0;
  border: 0;
  background: none;
  color: #8b9ab1;
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
}

.fwchat-foot button:hover { color: var(--fwchat-brand-dark); }

/* ---------------------------------------------------------------- 转人工面板 */

.fwchat-sheet {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: inherit;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.fwchat.is-human .fwchat-sheet { opacity: 1; transform: none; pointer-events: auto; }

.fwchat-sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--fwchat-line);
}

.fwchat-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fwchat-soft);
  color: var(--fwchat-ink-2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.fwchat-back:hover { background: #e9effb; }

.fwchat-sheet-title { color: var(--fwchat-ink); font-size: 15px; font-weight: 700; }

.fwchat-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.fwchat-sheet-note {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--fwchat-soft);
  color: var(--fwchat-ink-2);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.fwchat-tel {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #dbe6ff;
  border-radius: 12px;
  background: #f4f8ff;
  color: var(--fwchat-ink);
  font-weight: 700;
}

.fwchat-tel:hover { color: var(--fwchat-brand-dark); border-color: var(--fwchat-brand); }
.fwchat-tel small { display: block; color: var(--fwchat-ink-3); font-size: 11.5px; font-weight: 400; }
.fwchat-tel svg { flex: 0 0 auto; width: 18px; height: 18px; color: var(--fwchat-brand); }

.fwchat-form-grid { display: grid; gap: 10px; }

.fwchat-form-grid label { display: block; color: var(--fwchat-ink-2); font-size: 12.5px; }
.fwchat-form-grid label span { color: var(--fwchat-ink-3); font-size: 11.5px; }

.fwchat-form-grid input,
.fwchat-form-grid textarea {
  width: 100%;
  margin-top: 4px;
  padding: 9px 11px;
  border: 1px solid var(--fwchat-line);
  border-radius: 10px;
  background: #fff;
  color: var(--fwchat-ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.fwchat-form-grid textarea { min-height: 76px; resize: vertical; }

.fwchat-form-grid input:focus,
.fwchat-form-grid textarea:focus {
  border-color: var(--fwchat-brand);
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .12);
}

.fwchat-submit {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  border: 0;
  border-radius: 11px;
  background: var(--fwchat-brand);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s ease, opacity .18s ease;
}

.fwchat-submit:hover { background: var(--fwchat-brand-dark); }
.fwchat-submit:disabled { opacity: .5; cursor: not-allowed; }

.fwchat-sheet-tip { margin-top: 10px; color: #a3b0c4; font-size: 11.5px; line-height: 1.6; }

/* ---------------------------------------------------------------- 移动端 */

@media (max-width: 640px) {
  .fwchat {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    bottom: calc(16px + constant(safe-area-inset-bottom, 0px));
    right: 14px;
  }

  .fwchat[data-position="left"] { left: 14px; right: auto; }

  .fwchat-panel {
    position: fixed;
    top: auto;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    width: auto;
    height: auto;
    max-height: none;
    /* 小屏优先保证键盘弹起时输入框可见 */
    height: 78vh;
    height: 78dvh;
    border-radius: 18px;
  }

  .fwchat[data-position="left"] .fwchat-panel { left: 8px; right: 8px; }

  .fwchat-bubble { max-width: 92%; }
  .fwchat-body { padding: 14px 14px 6px; }
  .fwchat-quick { padding: 0 14px 8px; overflow-x: auto; flex-wrap: nowrap; }
  .fwchat-quick button { flex: 0 0 auto; }

  /* 打开时锁住页面滚动，避免背景跟着滑 */
  body.fwchat-lock { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .fwchat-launcher::after { animation: none; }
  .fwchat-panel,
  .fwchat-sheet,
  .fwchat-launcher,
  .fwchat-msg { transition: none; animation: none; }
}
