/* ==========================================================================
   宏基建筑劳务 —— AI 客服组件样式
   跟随全站配色：工程黄 + 深板岩灰
   ========================================================================== */

/* ---------------- 浮动客服按钮 ---------------- */
.chat-fab {
  position: fixed;
  right: 22px;
  bottom: 92px;           /* 让出下方电话/返回顶部按钮的位置 */
  z-index: 96;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--yellow) 0%, var(--yellow-dark) 100%);
  color: #1a1206;
  border: 0;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(245, 166, 35, .42);
  transition: transform .22s var(--ease), box-shadow .22s var(--ease);
}
.chat-fab:hover { transform: scale(1.08); box-shadow: 0 10px 28px rgba(245, 166, 35, .5); }
.chat-fab svg { width: 25px; height: 25px; }
.chat-fab .chat-fab-close { display: none; }
.chat-fab.is-open .chat-fab-open { display: none; }
.chat-fab.is-open .chat-fab-close { display: block; }

/* 未读小红点 */
.chat-fab-dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #e5484d;
  border: 2px solid #fff;
  display: none;
}
.chat-fab-dot.is-show { display: block; }

/* 首次进入的提示气泡 */
.chat-tip {
  position: fixed;
  right: 88px;
  bottom: 104px;
  z-index: 95;
  max-width: 230px;
  padding: 11px 15px;
  border-radius: 12px 12px 3px 12px;
  background: #fff;
  color: var(--ink);
  font-size: .88rem;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  opacity: 0;
  visibility: hidden;
  transform: translateX(8px);
  transition: opacity .3s var(--ease), transform .3s var(--ease), visibility .3s var(--ease);
  cursor: pointer;
}
.chat-tip.is-show { opacity: 1; visibility: visible; transform: none; }

/* ---------------- 对话面板 ---------------- */
.chat-panel {
  position: fixed;
  right: 22px;
  bottom: 160px;
  z-index: 97;
  width: 376px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 200px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 56px rgba(20, 24, 29, .22);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.98);
  transform-origin: bottom right;
  transition: opacity .26s var(--ease), transform .26s var(--ease), visibility .26s var(--ease);
}
.chat-panel.is-open { opacity: 1; visibility: visible; transform: none; }

/* 头部 */
.chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  background: var(--bg-dark);
  color: #fff;
}
.chat-avatar {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--yellow) 0%, var(--yellow-dark) 100%);
  color: #1a1206;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 1.02rem;
}
.chat-head-info { flex: 1; min-width: 0; line-height: 1.3; }
.chat-head-name { font-size: .98rem; font-weight: 700; }
.chat-head-status {
  font-size: .76rem;
  color: #9aa6b2;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-dot-online {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #3ecf7f;
  box-shadow: 0 0 0 3px rgba(62, 207, 127, .22);
}
.chat-head-close {
  width: 32px; height: 32px;
  flex: 0 0 auto;
  border-radius: 8px;
  display: grid; place-items: center;
  color: #b9c3cd;
  cursor: pointer;
  transition: background-color .18s var(--ease), color .18s var(--ease);
}
.chat-head-close:hover { background: rgba(255, 255, 255, .12); color: #fff; }

/* 消息区 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: var(--bg-soft);
  scroll-behavior: smooth;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: #cfd6dd; border-radius: 3px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }

.chat-row { display: flex; gap: 9px; margin-bottom: 15px; }
.chat-row--me { flex-direction: row-reverse; }

.chat-bubble {
  max-width: 80%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: .92rem;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-row--bot .chat-bubble {
  background: #fff;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.chat-row--me .chat-bubble {
  background: var(--yellow);
  color: #1a1206;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.chat-bubble strong { color: var(--ink); font-weight: 700; }
.chat-row--me .chat-bubble strong { color: #1a1206; }
.chat-bubble a { color: var(--yellow-dark); font-weight: 700; text-decoration: underline; }
.chat-row--me .chat-bubble a { color: #1a1206; }

/* 打字光标 */
.chat-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--yellow-dark);
  vertical-align: text-bottom;
  animation: chatBlink 1s steps(2) infinite;
  margin-left: 1px;
}
@keyframes chatBlink { 0%,50% { opacity: 1 } 51%,100% { opacity: 0 } }

/* 等待三点 */
.chat-typing { display: flex; gap: 4px; padding: 4px 2px; }
.chat-typing i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #b3bcc6;
  animation: chatBounce 1.3s infinite;
}
.chat-typing i:nth-child(2) { animation-delay: .18s; }
.chat-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes chatBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5 }
  30% { transform: translateY(-5px); opacity: 1 }
}

/* 快捷问题 */
.chat-quick { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 15px; }
.chat-quick button {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  font-size: .83rem;
  cursor: pointer;
  transition: border-color .18s var(--ease), color .18s var(--ease), background-color .18s var(--ease);
}
.chat-quick button:hover {
  border-color: var(--yellow);
  color: var(--yellow-dark);
  background: rgba(245, 166, 35, .09);
}

/* 底部输入 */
.chat-foot {
  flex: 0 0 auto;
  padding: 12px 14px 13px;
  background: #fff;
  border-top: 1px solid var(--line);
}
.chat-input-row { display: flex; gap: 9px; align-items: flex-end; }
.chat-input {
  flex: 1;
  min-height: 42px;
  max-height: 108px;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: .92rem;
  line-height: 1.5;
  color: var(--ink);
  resize: none;
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.chat-input:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(245, 166, 35, .16);
}
.chat-input::placeholder { color: #a9b3bd; }

.chat-send {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--yellow);
  color: #1a1206;
  cursor: pointer;
  transition: background-color .18s var(--ease), opacity .18s var(--ease);
}
.chat-send:hover:not(:disabled) { background: var(--yellow-dark); }
.chat-send:disabled { opacity: .45; cursor: not-allowed; }

.chat-foot-note {
  margin-top: 8px;
  font-size: .73rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}
.chat-foot-note a { color: var(--yellow-dark); font-weight: 700; }

/* ---------------- 移动端 ---------------- */
@media (max-width: 620px) {
  .chat-fab { right: 14px; bottom: 84px; width: 52px; height: 52px; }
  .chat-tip { right: 76px; bottom: 96px; max-width: 190px; font-size: .84rem; }
  .chat-panel {
    right: 0; left: 0; bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 88vh;
    max-height: 88vh;
    border-radius: 18px 18px 0 0;
    border-left: 0; border-right: 0; border-bottom: 0;
    transform: translateY(100%);
  }
  .chat-panel.is-open { transform: none; }
  .chat-bubble { max-width: 86%; font-size: .93rem; }
}

/* 深色底区块上的可读性（若被嵌入深色区域） */
.section--dark .chat-bubble { color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  .chat-caret, .chat-typing i { animation: none; }
}
