/* ------------------------------------------------------------------
   Live chat —— 前台悬浮客服（与站点深色 + 金铜色设计语言一致）
   入口：assets/js/chat.js   接口：/api/shop/chat/*
   ------------------------------------------------------------------ */

.twchat-fab {
  position: fixed;
  right: 18px;
  bottom: 88px;
  z-index: 71;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(232, 207, 154, .55);
  background: linear-gradient(140deg, #C9A961, #C9A961);
  color: #14110b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(0,0,0,0.175), 0 0 0 1px rgba(0,0,0,0.122) inset;
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.twchat-fab svg { width: 26px; height: 26px; display: block; }
.twchat-fab:hover { transform: translateY(-2px); filter: brightness(1.06); box-shadow: 0 18px 36px rgba(0,0,0,0.193); }
.twchat-fab:active { transform: translateY(0); }
.twchat-fab:focus-visible { outline: 2px solid var(--blue, #5B9BE0); outline-offset: 3px; }

.twchat-fab .twchat-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red, #C8202E);
  color: #fff;
  font: 700 10.5px/18px "Spline Sans Mono", monospace;
  text-align: center;
  border: 1px solid rgba(0,0,0,0.158);
  display: none;
}
.twchat-fab.has-unread .twchat-dot { display: block; }
.twchat-fab.has-unread::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1px solid rgba(201, 169, 97, .5);
  animation: twchatPulse 2.2s ease-out infinite;
}
@keyframes twchatPulse {
  0% { transform: scale(.86); opacity: .9; }
  70% { transform: scale(1.16); opacity: 0; }
  100% { opacity: 0; }
}

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

.twchat-panel {
  position: fixed;
  right: 18px;
  bottom: 152px;
  z-index: 72;
  width: min(376px, 92vw);
  height: min(560px, 72vh);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #14171D, #0D0F13);
  border: 1px solid rgba(201, 169, 97, .28);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.217);
  color: var(--frame-ink, #EEF1F6);
  font-family: 'Barlow', system-ui, sans-serif;
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(.98);
  pointer-events: none;
  transition: opacity .2s ease, transform .24s cubic-bezier(.2, .8, .2, 1);
}
.twchat-panel.on { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.twchat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  background: linear-gradient(120deg, rgba(30, 77, 140, .34), rgba(201, 169, 97, .12));
  border-bottom: 1px solid rgba(201,169,97,0.110);
}
.twchat-av {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(201, 169, 97, .16);
  border: 1px solid rgba(201, 169, 97, .45);
  color: #C9A961;
  font: 700 14px/1 "Spline Sans Mono", monospace;
}
.twchat-hid { min-width: 0; flex: 1 1 auto; }
.twchat-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.twchat-live {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3ECF8E;
  box-shadow: 0 0 0 3px rgba(62, 207, 142, .16);
}
.twchat-live.off { background: #7C8798; box-shadow: 0 0 0 3px rgba(124, 135, 152, .16); }
.twchat-sub {
  margin-top: 3px;
  font: 500 10.5px/1.2 "Spline Sans Mono", monospace;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--frame-ink3, #71809A);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.twchat-x {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(201,169,97,0.154);
  background: rgba(201,169,97,0.055);
  color: var(--frame-ink2, #A2AEC0);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.twchat-x:hover { color: #fff; border-color: rgba(201,169,97,0.330); background: rgba(201,169,97,0.110); }

/* 坐席选择（后台加了多个客服时出现） */
.twchat-agents {
  flex: 0 0 auto;
  display: flex;
  gap: 7px;
  padding: 10px 12px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(201,169,97,0.088);
  background: rgba(201,169,97,0.022);
  scrollbar-width: none;
}
.twchat-agents::-webkit-scrollbar { display: none; }
.twchat-agents[hidden] { display: none; }
.twchat-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(201,169,97,0.154);
  background: rgba(201,169,97,0.044);
  color: var(--frame-ink2, #A2AEC0);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.twchat-chip:hover { color: #fff; border-color: rgba(201,169,97,0.286); }
.twchat-chip.on {
  color: #C9A961;
  border-color: rgba(201, 169, 97, .55);
  background: rgba(201, 169, 97, .14);
}

/* 消息区 */
.twchat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 13px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(201,169,97,0.198) transparent;
}
.twchat-log::-webkit-scrollbar { width: 8px; }
.twchat-log::-webkit-scrollbar-thumb { background: rgba(201,169,97,0.176); border-radius: 8px; }

.twchat-row { display: flex; flex-direction: column; gap: 4px; max-width: 88%; }
.twchat-row.staff { align-self: flex-start; }
.twchat-row.me { align-self: flex-end; align-items: flex-end; }

.twchat-bub {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.twchat-row.staff .twchat-bub {
  background: rgba(201,169,97,0.077);
  border: 1px solid rgba(201,169,97,0.110);
  border-bottom-left-radius: 5px;
  color: var(--frame-ink, #EEF1F6);
}
.twchat-row.me .twchat-bub {
  background: linear-gradient(140deg, #C9A961, #C9A961);
  border: 1px solid rgba(232, 207, 154, .5);
  border-bottom-right-radius: 5px;
  color: #14110b;
  font-weight: 500;
}
.twchat-meta {
  font: 500 10px/1.2 "Spline Sans Mono", monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--frame-ink3, #71809A);
  padding: 0 3px;
}

.twchat-sys {
  align-self: center;
  max-width: 94%;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--frame-ink3, #71809A);
  padding: 4px 10px;
  border: 1px dashed rgba(201,169,97,0.132);
  border-radius: 999px;
}
.twchat-sys b { color: #C9A961; font-weight: 600; }

.twchat-hint {
  align-self: center;
  font-size: 11.5px;
  color: var(--frame-ink3, #71809A);
}

/* 输入区 */
.twchat-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(201,169,97,0.110);
  background: rgba(0,0,0,0.077);
}
.twchat-form textarea {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 108px;
  resize: none;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(201,169,97,0.176);
  background: rgba(201,169,97,0.055);
  color: var(--frame-ink, #EEF1F6);
  font: 400 14px/1.45 'Barlow', system-ui, sans-serif;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.twchat-form textarea::placeholder { color: var(--frame-ink3, #71809A); }
.twchat-form textarea:focus {
  border-color: rgba(201, 169, 97, .6);
  background: rgba(201,169,97,0.088);
  box-shadow: 0 0 0 3px rgba(201, 169, 97, .16);
}
.twchat-send {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid rgba(232, 207, 154, .5);
  background: linear-gradient(120deg, #C9A961, #C9A961);
  color: #14110b;
  font: 600 11px/1 "Spline Sans Mono", monospace;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter .16s, opacity .16s;
}
.twchat-send:hover { filter: brightness(1.08); }
.twchat-send:disabled { opacity: .55; cursor: default; filter: none; }

/* 商品卡 / 详情页入口按钮 */
.card .twchat-bar {
  display: flex;
  gap: 8px;
  padding: 0 14px 14px;
  margin-top: 0;
}
.card .twchat-cardbtn {
  flex: 1;
  min-height: 31px;
  border-radius: 3px;
  padding: 9px 6px;
  cursor: pointer;
  background: rgba(201, 169, 97, .1);
  border: 1px solid rgba(201, 169, 97, .42);
  color: #C9A961;
  font: 600 10.5px/1 "Spline Sans Mono", monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
  transition: background .16s, color .16s, border-color .16s;
}
.card .twchat-cardbtn:hover { background: rgba(201, 169, 97, .2); border-color: rgba(201, 169, 97, .65); }
.card .twchat-cardbtn:active { background: rgba(201, 169, 97, .26); }

.pd-chat-row { margin-top: 10px; }
.pd-chat-btn {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 8px;
  cursor: pointer;
  background: rgba(201, 169, 97, .1);
  border: 1px solid rgba(201, 169, 97, .45);
  color: #C9A961;
  font: 600 11.5px/1 "Spline Sans Mono", monospace;
  letter-spacing: .14em;
  text-transform: uppercase;
  transition: background .16s, border-color .16s, color .16s;
}
.pd-chat-btn:hover { background: rgba(201, 169, 97, .2); border-color: rgba(201, 169, 97, .7); color: #F4E4BE; }
.pd-chat-btn svg { width: 17px; height: 17px; flex: 0 0 auto; }
.pd-chat-btn .pd-chat-live {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3ECF8E;
  box-shadow: 0 0 0 3px rgba(62, 207, 142, .18);
}

/* 窄屏吸底条里的聊天入口 */
.pd-sticky-chat {
  flex: 0 0 auto;
  width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  background: rgba(201, 169, 97, .1);
  border: 1px solid rgba(201, 169, 97, .45);
  color: #C9A961;
  transition: background .16s, border-color .16s, color .16s;
}
.pd-sticky-chat:hover { background: rgba(201, 169, 97, .2); border-color: rgba(201, 169, 97, .7); color: #F4E4BE; }
.pd-sticky-chat:active { background: rgba(201, 169, 97, .26); }
.pd-sticky-chat svg { width: 18px; height: 18px; }

/* ---------------- 窄屏 ---------------- */
@media (max-width: 560px) {
  .twchat-fab { right: 14px; bottom: 80px; width: 50px; height: 50px; }
  .twchat-fab svg { width: 23px; height: 23px; }
  .twchat-panel {
    right: 8px;
    left: 8px;
    bottom: 140px;
    width: auto;
    height: auto;
    max-height: 76vh;
    border-radius: 14px;
  }
  .twchat-log { padding: 12px 11px 6px; }
  .twchat-form textarea { font-size: 16px; } /* 避免 iOS 聚焦放大 */
  .twchat-send { padding: 0 13px; }
}
