/* ==========================================================================
   SOKARIS 官网 — 智能顾问浮窗
   与 site.css 共用设计 token；本文件只负责浮标 / 面板 / 气泡 / 留资表单
   前缀统一 chat-，避免和站点其它样式串味
   ========================================================================== */

.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 95;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 52px;
  padding: 0 20px 0 17px;
  border-radius: 999px;
  background: var(--accent);
  color: #0a0c0b;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 0;
  cursor: pointer;
  box-shadow: 0 10px 34px rgba(200, 239, 133, 0.24), 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease),
    background 0.3s var(--ease), opacity 0.28s var(--ease);
}
.chat-fab:hover {
  transform: translateY(-2px);
  background: var(--accent-2);
  box-shadow: 0 14px 40px rgba(200, 239, 133, 0.32), 0 2px 10px rgba(0, 0, 0, 0.5);
}
.chat-fab:active { transform: translateY(0) scale(0.985); }
.chat-fab svg { width: 19px; height: 19px; flex: none; }
.chat-fab__dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #ff5f57;
  border: 2px solid var(--bg);
  display: none;
}
.chat-fab.has-new .chat-fab__dot { display: block; }
/* 面板展开时收起浮标：否则右下角同时有按钮和面板，且留资表单下会露出半截 */
.chat-fab.is-hidden {
  opacity: 0;
  transform: translateY(10px) scale(0.9);
  pointer-events: none;
}

/* 一次性提示气泡（首次访问 14 秒后出现，9 秒后自动消失，只一次） */
.chat-hint {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 94;
  max-width: 200px;
  padding: 9px 13px;
  border-radius: 11px 11px 3px 11px;
  background: rgba(23, 32, 25, 0.97);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 0.78rem;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
}
.chat-hint.show { opacity: 1; transform: none; }

/* 面板 */
.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 90px;
  z-index: 96;
  width: 386px;
  height: min(618px, calc(100vh - 128px));
  display: flex;
  flex-direction: column;
  background: rgba(14, 18, 17, 0.97);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
  border: 1px solid rgba(238, 243, 236, 0.1);
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.62), 0 4px 16px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.26s var(--ease), transform 0.26s var(--ease);
}
.chat-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* 头部 */
.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 15px 14px 14px 17px;
  border-bottom: 1px solid var(--line-2);
  flex: none;
}
.chat-head__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), #7fae42);
  color: #0a0c0b;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex: none;
}
.chat-head__meta { flex: 1; min-width: 0; }
.chat-head__title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--dim-2);
  line-height: 1.4;
}
.chat-head__status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(200, 239, 133, 0.14);
}
.chat-head__btns { display: flex; gap: 2px; flex: none; }
.chat-iconbtn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--dim);
  transition: background 0.2s, color 0.2s;
}
.chat-iconbtn:hover { background: rgba(238, 243, 236, 0.07); color: var(--ink); }
.chat-iconbtn svg { width: 16px; height: 16px; }

/* 消息流 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(238, 243, 236, 0.18) transparent;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb {
  background: rgba(238, 243, 236, 0.16);
  border-radius: 99px;
}

.chat-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 15px;
  font-size: 0.875rem;
  line-height: 1.68;
  word-break: break-word;
  animation: chat-in 0.28s var(--ease) both;
}
@keyframes chat-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.chat-msg--bot {
  align-self: flex-start;
  background: rgba(238, 243, 236, 0.06);
  border: 1px solid var(--line-2);
  border-bottom-left-radius: 5px;
  color: var(--ink-2);
}
.chat-msg--user {
  align-self: flex-end;
  background: var(--accent);
  color: #0a0c0b;
  border-bottom-right-radius: 5px;
  font-weight: 500;
}
.chat-msg--err {
  align-self: stretch;
  max-width: 100%;
  background: rgba(255, 95, 87, 0.09);
  border: 1px solid rgba(255, 95, 87, 0.3);
  color: #ffb4ae;
  font-size: 0.82rem;
}
.chat-msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
  background: rgba(10, 12, 11, 0.45);
  padding: 1px 5px;
  border-radius: 4px;
}
.chat-msg strong { color: var(--ink); font-weight: 600; }
.chat-msg--user strong { color: #0a0c0b; }
.chat-msg a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.chat-msg--user a { color: #0a0c0b; }
.chat-msg ul { margin: 6px 0 0; padding-left: 0; }
.chat-msg li {
  position: relative;
  padding-left: 13px;
  margin-top: 3px;
}
.chat-msg li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.72em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

/* 打字指示 */
.chat-typing { display: flex; gap: 4px; padding: 4px 2px; }
.chat-typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--dim);
  animation: chat-blink 1.2s infinite ease-in-out;
}
.chat-typing i:nth-child(2) { animation-delay: 0.16s; }
.chat-typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes chat-blink {
  0%, 70%, 100% { opacity: 0.3; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-2px); }
}

/* 快捷问题 */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 16px 4px;
  flex: none;
}
.chat-chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-2);
  font-size: 0.76rem;
  line-height: 1.4;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.chat-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(200, 239, 133, 0.06);
}

/* 留资提示条 */
.chat-leadbar {
  display: none;
  align-items: center;
  gap: 10px;
  margin: 0 16px 6px;
  padding: 10px 12px;
  border-radius: 11px;
  background: rgba(200, 239, 133, 0.08);
  border: 1px solid rgba(200, 239, 133, 0.28);
  font-size: 0.78rem;
  color: var(--accent);
  flex: none;
}
.chat-leadbar.show { display: flex; }
.chat-leadbar span { flex: 1; line-height: 1.45; }
.chat-leadbar button {
  flex: none;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--accent);
  color: #0a0c0b;
  font-size: 0.76rem;
  font-weight: 600;
}

/* 输入区 */
.chat-form {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 11px 13px 11px 15px;
  border-top: 1px solid var(--line-2);
  background: rgba(10, 12, 11, 0.4);
}
.chat-input {
  flex: 1;
  min-width: 0;
  max-height: 108px;
  padding: 9px 0;
  background: none;
  border: 0;
  resize: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.6;
  outline: none;
}
.chat-input::placeholder { color: var(--dim-2); }
.chat-send {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #0a0c0b;
  display: grid;
  place-items: center;
  transition: background 0.2s, transform 0.2s, opacity 0.2s;
}
.chat-send:hover:not(:disabled) { background: var(--accent-2); transform: scale(1.05); }
.chat-send:disabled { opacity: 0.32; cursor: default; }
.chat-send svg { width: 15px; height: 15px; }

.chat-foot {
  flex: none;
  padding: 0 15px 10px;
  font-size: 0.66rem;
  line-height: 1.5;
  color: var(--dim-2);
  text-align: center;
}
.chat-foot__sep { opacity: 0.5; }
.chat-foot a { color: var(--dim); text-decoration: underline; text-underline-offset: 2px; }
.chat-foot a:hover { color: var(--accent); }

/* 留资表单（面板内切换视图） */
.chat-lead {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  background: rgba(14, 18, 17, 0.99);
  border-radius: inherit;
}
.chat-lead.is-open { display: flex; }
.chat-lead__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 14px 13px 18px;
  border-bottom: 1px solid var(--line-2);
  flex: none;
}
.chat-lead__head h4 { font-size: 0.92rem; font-weight: 600; }
.chat-lead__body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.chat-lead__desc {
  font-size: 0.8rem;
  color: var(--dim);
  line-height: 1.6;
  margin-bottom: 2px;
}
.chat-field { display: flex; flex-direction: column; gap: 6px; }
.chat-field label {
  font-size: 0.72rem;
  color: var(--dim);
  letter-spacing: 0.02em;
}
.chat-field label em { color: var(--accent); font-style: normal; }
.chat-field input,
.chat-field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(10, 12, 11, 0.55);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.55;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
.chat-field textarea { resize: vertical; min-height: 74px; }
.chat-field input:focus,
.chat-field textarea:focus {
  border-color: var(--accent);
  background: rgba(10, 12, 11, 0.8);
}
.chat-lead__submit {
  margin-top: 4px;
  padding: 12px;
  border-radius: 11px;
  background: var(--accent);
  color: #0a0c0b;
  font-weight: 600;
  font-size: 0.88rem;
  transition: background 0.2s, opacity 0.2s;
}
.chat-lead__submit:hover:not(:disabled) { background: var(--accent-2); }
.chat-lead__submit:disabled { opacity: 0.5; cursor: default; }
.chat-lead__err {
  /* 占住剩余空间，把「提交」稳定压在面板底部，不随字段多少上下跳 */
  margin-top: auto;
  font-size: 0.78rem;
  color: #ffb4ae;
  min-height: 1.2em;
}
.chat-lead__done {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 40px 30px;
  flex: 1;
}
.chat-lead__done.show { display: flex; }
.chat-lead__done .ok {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(200, 239, 133, 0.14);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 1.3rem;
}
.chat-lead__done p { font-size: 0.86rem; color: var(--ink-2); line-height: 1.65; }

/* ---------- 移动端：整屏 ---------- */
@media (max-width: 560px) {
  .chat-fab {
    right: 16px;
    bottom: 16px;
    height: 48px;
    padding: 0 17px 0 15px;
    font-size: 0.85rem;
  }
  .chat-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    transform-origin: center;
  }
  .chat-msg { max-width: 90%; font-size: 0.9rem; }
  .chat-body { padding: 16px 14px 8px; }
  .chat-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  body.chat-lock { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel, .chat-msg, .chat-fab { transition: none; animation: none; }
}
