/* ==========================================================================
   LuYouDa storefront - AI chat widget
   右下角浮窗客服，样式前缀 .lychat-，配色沿用 site.css 的设计令牌
   ========================================================================== */

.lychat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 900;
  font-family: var(--font);
}

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

.lychat__launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 56px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--blue) 0%, #4d78ff 52%, var(--blue-dark) 100%);
  color: #fff;
  font: inherit;
  font-size: 13.5px;
  font-weight: 750;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: 0 22px 44px -20px rgba(43, 89, 255, .7), 0 0 0 1px rgba(255, 255, 255, .08) inset;
  transition: transform .22s cubic-bezier(.22, 1, .36, 1), box-shadow .22s ease, opacity .2s ease;
}

.lychat__launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 28px 52px -22px rgba(43, 89, 255, .78);
}

.lychat__launcher:active { transform: translateY(0) scale(.985); }

.lychat__launcher svg { flex: none; }

.lychat__launcher-dot {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6ff0b9;
  box-shadow: 0 0 0 3px rgba(111, 240, 185, .22);
}

.lychat__unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 6px 14px -6px rgba(255, 90, 31, .8);
}

.lychat.is-open .lychat__launcher { opacity: 0; pointer-events: none; transform: scale(.9); }

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

.lychat__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(388px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 130px));
  /* dvh 跟着真实可视区走：手机地址栏收起、Windows 显示缩放异常时比 100vh 准 */
  height: min(620px, calc(100dvh - 130px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  border-radius: 22px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 44px 96px -44px rgba(7, 12, 24, .55), 0 2px 6px rgba(7, 12, 24, .04);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.98);
  transform-origin: 100% 100%;
  transition: opacity .2s ease, transform .26s cubic-bezier(.22, 1, .36, 1), visibility .2s;
}

.lychat.is-open .lychat__panel {
  opacity: 1;
  visibility: visible;
  transform: none;
}

/* 窗口不够高或不够宽时（含桌面窄窗、分屏、缩放异常）：
   改用相对视口的固定定位 + 上下留白，任何窗口尺寸下都不会被边缘裁掉 */
.lychat.is-fit .lychat__panel {
  position: fixed;
  left: auto;
  right: 12px;
  top: 12px;
  bottom: 12px;
  width: min(388px, calc(100vw - 24px));
  height: auto;
  max-height: none;
}

/* ---------- 头部 ---------- */

.lychat__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 15px 16px;
  background:
    radial-gradient(320px 120px at 88% -30%, rgba(77, 120, 255, .55), transparent 70%),
    linear-gradient(135deg, var(--ink) 0%, var(--navy) 100%);
  color: #fff;
}

.lychat__badge {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 12px;
  background: linear-gradient(140deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, .06));
  border: 1px solid rgba(255, 255, 255, .18);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
}

.lychat__title { min-width: 0; }

.lychat__title b {
  display: block;
  font-size: 14px;
  font-weight: 750;
  letter-spacing: -.01em;
}

.lychat__title span {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, .66);
}

.lychat__live {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6ff0b9;
  box-shadow: 0 0 0 3px rgba(111, 240, 185, .18);
}

.lychat__close {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  cursor: pointer;
  transition: background .16s ease;
}

.lychat__close:hover { background: rgba(255, 255, 255, .2); }

/* ---------- 消息区 ---------- */

.lychat__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 6px;
  background:
    radial-gradient(420px 220px at 100% 0%, rgba(43, 89, 255, .05), transparent 70%),
    var(--paper);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}

.lychat__body::-webkit-scrollbar { width: 6px; }
.lychat__body::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }

.lychat-msg { display: flex; gap: 8px; align-items: flex-start; }
.lychat-msg--user { justify-content: flex-end; }

.lychat-msg__avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-top: 2px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--navy), var(--blue));
  color: #fff;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .02em;
}

.lychat-msg__bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.lychat-msg--bot .lychat-msg__bubble {
  background: var(--mist);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: #1d2939;
}

.lychat-msg--user .lychat-msg__bubble {
  background: linear-gradient(135deg, var(--blue) 0%, #4a74ff 100%);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 12px 26px -16px rgba(43, 89, 255, .85);
}

.lychat-msg--error .lychat-msg__bubble {
  background: #fff5f4;
  border-color: #fecdca;
  color: #b42318;
}

/* 打字中的三点 */
.lychat-typing { display: inline-flex; align-items: center; gap: 4px; padding: 3px 0; }

.lychat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-2);
  animation: lychat-blink 1.15s infinite ease-in-out;
}

.lychat-typing i:nth-child(2) { animation-delay: .16s; }
.lychat-typing i:nth-child(3) { animation-delay: .32s; }

@keyframes lychat-blink {
  0%, 80%, 100% { opacity: .28; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- 快捷选项 ---------- */

.lychat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 6px 34px;
}

.lychat-chips:empty { display: none; }

.lychat-chip {
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  color: #344054;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  transition: border-color .16s ease, color .16s ease, background .16s ease;
}

.lychat-chip:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-soft);
}

/* ---------- 留联系方式卡片 ---------- */

.lychat-form {
  margin: 2px 0 4px 34px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, #f8faff, #fff);
  border: 1px solid #dbe4ff;
  box-shadow: 0 18px 36px -30px rgba(43, 89, 255, .8);
}

.lychat-form__title {
  margin: 0 0 3px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -.01em;
}

.lychat-form__hint {
  margin: 0 0 10px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--muted);
}

.lychat-form__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lychat-form__grid .lychat-form__full { grid-column: 1 / -1; }

.lychat-field {
  display: block;
  width: 100%;
  min-height: 38px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #fff;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  transition: border-color .16s ease, box-shadow .16s ease;
}

.lychat-field::placeholder { color: var(--muted-2); }

.lychat-field:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(43, 89, 255, .12);
}

.lychat-form__submit {
  grid-column: 1 / -1;
  height: 40px;
  margin-top: 2px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--ink), var(--navy));
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 750;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease;
}

.lychat-form__submit:hover { box-shadow: 0 16px 28px -18px rgba(7, 12, 24, .9); }
.lychat-form__submit:disabled { opacity: .6; cursor: progress; }

.lychat-form__msg {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 11.5px;
  color: #b42318;
}

.lychat-form__msg.is-ok { color: #067647; }

/* ---------- 输入区 ---------- */

.lychat__foot {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.lychat__inputrow { display: flex; align-items: flex-end; gap: 8px; }

.lychat__input {
  flex: 1;
  min-height: 44px;
  max-height: 112px;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--mist);
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  resize: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.lychat__input::placeholder { color: var(--muted-2); }

.lychat__input:focus {
  outline: none;
  background: #fff;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(43, 89, 255, .12);
}

.lychat__send {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 14px 26px -16px rgba(43, 89, 255, .9);
  transition: transform .16s ease, opacity .16s ease;
}

.lychat__send:hover { transform: translateY(-1px); }
.lychat__send:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.lychat__note {
  margin: 8px 0 0;
  font-size: 10.5px;
  line-height: 1.5;
  text-align: center;
  color: var(--muted-2);
}

/* 未就绪时禁用输入 */
.lychat.is-busy .lychat__send { opacity: .45; pointer-events: none; }

/* ---------- 移动端：整屏抽屉 ---------- */

@media (max-width: 560px) {
  .lychat { right: 14px; bottom: 14px; }

  .lychat__launcher { height: 52px; padding: 0 17px; }
  .lychat__launcher-label { display: none; }

  .lychat__panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    border: 0;
  }

  .lychat__head { padding-top: max(15px, env(safe-area-inset-top)); }

  .lychat__foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }

  .lychat-form { margin-left: 0; }
  .lychat-chips { padding-left: 0; }
}

@media print {
  .lychat { display: none; }
}
