/* 在线客服 · 访客组件（js/cs/widget.js）。设计蓝本：mockup/widget/cs-widget.css（用户已确认）。
   组件选择器都在 .csw 之下；组件外只有三处：页面底部留白（:root.csw-on .view）、手机打开时锁住背景（:root.csw-lock）、
   站内入口按钮（.csw-nav 电脑左侧导航、.csw-link 文字入口）。颜色只用方案A的 tokens。
   文件末尾「接入补充」一节是并入 ui-design/prototype-a 时加的（聊天厅输入栏让位），其余与 cs-system 版本相同。
   手机/平板（≤1023px，有底部导航）：按钮在「广告」上方，面板由下往上弹出，占 70% 高度，往下拉关闭。
   电脑（≥1024px）：按钮在右下角，面板是右下角的浮动视窗。 */

.csw { --csw-fab: 54px; --csw-gap: 16px; --csw-lift: 0px; font-family: var(--font); }
.csw *, .csw *::before, .csw *::after { box-sizing: border-box; }
.csw[hidden], .csw [hidden] { display: none !important; }
.csw button { font: inherit; }
.csw button:disabled { opacity: 1; }
.csw .csw-vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.csw svg { width: 100%; height: 100%; display: block; }

/* 手机：页面底部多留出按钮的高度，最后一行内容不会被按钮挡住（只在按钮显示时）。打开面板时锁住背景滚动。 */
@media (max-width: 1023px) {
  :root.csw-on .view { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 54px + 24px); }
  :root.csw-lock, :root.csw-lock body { overflow: hidden; }
}

/* ---------- 浮动按钮 ---------- */
.csw-fab {
  position: fixed; z-index: 80; right: var(--csw-gap);
  bottom: calc(var(--tab-h) + var(--safe-b) + var(--csw-gap));
  width: var(--csw-fab); height: var(--csw-fab); border-radius: 50%; padding: 0;
  border: 1px solid rgba(255, 255, 255, .14); background: var(--accent); color: var(--on-accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5), 0 0 0 4px rgba(245, 165, 36, .12);
  cursor: pointer; transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.csw-fab:hover { background: var(--accent-hi); }
.csw-fab:active { transform: scale(.94); }
.csw-fab:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.csw-fab-ico { width: 22px; height: 22px; }
.csw-fab-label { font-size: 12px; font-weight: 700; line-height: 1; letter-spacing: .04em; }
.csw-badge {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px; background: var(--alert); color: #fff; border: 2px solid var(--bg);
  font-family: var(--mono); font-size: 12px; font-weight: 700; line-height: 18px; text-align: center; white-space: nowrap;
}
.csw-fab.is-pulse { animation: cswPulse 900ms var(--ease) 2; }
@keyframes cswPulse { 0%, 100% { transform: none; } 30% { transform: scale(1.12); } 60% { transform: scale(.96); } }
.csw.is-open .csw-fab { visibility: hidden; }

/* ---------- 遮罩（只在手机/平板） ---------- */
.csw-backdrop {
  position: fixed; inset: 0; z-index: 940; background: rgba(4, 6, 9, .58);
  opacity: 0; transition: opacity 240ms var(--ease);
}
.csw.is-open .csw-backdrop { opacity: 1; }

/* ---------- 面板：手机/平板 = 底部弹出 70% ---------- */
.csw-panel {
  position: fixed; z-index: 950; left: 0; right: 0; bottom: var(--csw-kb, 0px);
  height: var(--csw-h, 70vh); height: var(--csw-h, 70dvh); min-height: 360px;
  display: flex; flex-direction: column;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line-2); border-bottom: 0; border-radius: 14px 14px 0 0;
  box-shadow: 0 -18px 60px rgba(0, 0, 0, .55);
  transform: translateY(105%); transition: transform 260ms var(--ease), visibility 0s linear 260ms;
  visibility: hidden;
  padding-bottom: var(--safe-b); overflow: hidden;
}
.csw.is-open .csw-panel { transform: translateY(var(--csw-drag, 0px)); visibility: visible; transition: transform 260ms var(--ease); }
.csw.is-dragging .csw-panel, .csw.is-dragging .csw-backdrop { transition: none; }
.csw-grip-zone { flex: none; touch-action: none; cursor: grab; user-select: none; }
.csw.is-dragging .csw-grip-zone { cursor: grabbing; }
.csw-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 8px auto 2px; }
.csw-grip-hint { display: block; text-align: center; font-size: 12px; color: var(--text-3); height: 0; overflow: hidden; transition: height var(--dur) var(--ease); }
.csw.is-dragging .csw-grip-hint { height: 18px; }

.csw-head { display: flex; align-items: center; gap: 10px; padding: 4px 10px 10px 6px; border-bottom: 1px solid var(--line); }
.csw-icon-btn {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: var(--r-2); background: transparent; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.csw-icon-btn:hover { background: var(--panel-2); color: var(--text); }
.csw-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.csw-icon-btn .csw-i { width: 22px; height: 22px; }
.csw-agent { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.csw-avatars { display: flex; flex: none; }
.csw-av {
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: #1D2A3A; color: #CFE3FF; font-size: 14px; font-weight: 700; border: 2px solid var(--panel); flex: none;
}
.csw-av + .csw-av { margin-left: -10px; background: #2A2111; color: var(--accent-hi); }
.csw-agent-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.csw-agent-text strong { font-size: 15px; line-height: 1.2; outline: none; }
.csw-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.csw-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); flex: none; box-shadow: 0 0 0 3px rgba(47, 217, 143, .15); }
.csw.is-offline .csw-dot { background: var(--text-3); box-shadow: none; }

/* 推送断开时的提示条 */
.csw-conn { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 14px; font-size: 12px; color: var(--accent-hi); background: var(--accent-soft); border-bottom: 1px solid var(--accent-line); }
.csw-conn-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: cswBlink 1.2s infinite ease-in-out; }
@keyframes cswBlink { 50% { opacity: .3; } }

/* 离线留言提示 */
.csw-offline { flex: none; padding: 10px 14px; background: var(--panel-3); border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.6; color: var(--text-2); }
.csw-offline b { color: var(--text); }
.csw-contact { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.csw-contact-line { display: flex; gap: 8px; align-items: center; }
.csw-contact label { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.csw-contact input {
  flex: 1; min-width: 0; height: 36px; padding: 0 10px; border-radius: var(--r-2);
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text); font-size: 13px; outline: none;
}
.csw-contact input:focus { border-color: var(--accent); }
.csw-contact-state { font-size: 12px; color: var(--live); }
.csw-contact-state.is-error { color: var(--alert-soft); }

/* ---------- 消息列表 ---------- */
.csw-list { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 6px; }
.csw-list:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.csw-sys { align-self: center; max-width: 92%; text-align: center; font-size: 12px; line-height: 1.6; color: var(--text-3); padding: 2px 8px; overflow-wrap: anywhere; }
.csw-sys.is-notice { background: var(--panel-3); border: 1px solid var(--line-soft); border-radius: var(--r-2); color: var(--text-2); padding: 8px 10px; }
.csw-sys.is-error { color: var(--alert-soft); }
.csw-more {
  align-self: center; min-height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 16px;
  background: transparent; color: var(--text-2); font-size: 12px; cursor: pointer;
}
.csw-more:hover { color: var(--text); background: var(--panel-2); }
.csw-more:disabled { color: var(--text-3); cursor: default; }
.csw-day { align-self: center; font-size: 12px; color: var(--text-3); padding: 6px 0 2px; }
.csw-new-sep { display: flex; align-items: center; gap: 8px; color: var(--alert-soft); font-size: 12px; margin: 6px 0; }
.csw-new-sep::before, .csw-new-sep::after { content: ''; flex: 1; height: 1px; background: var(--alert-line); }

.csw-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.csw-msg.is-agent { align-self: flex-start; }
.csw-msg.is-me { align-self: flex-end; flex-direction: row-reverse; }
.csw-msg .csw-av { width: 28px; height: 28px; font-size: 12px; border: 0; }
.csw-msg .csw-av.is-ghost { visibility: hidden; }
.csw-col { display: flex; flex-direction: column; gap: 3px; min-width: 0; max-width: min(78vw, 300px); }
.csw-msg.is-me .csw-col { align-items: flex-end; }
.csw-name { font-size: 12px; color: var(--text-3); padding: 0 4px; }
.csw-bubble {
  padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.csw-msg.is-agent .csw-bubble { background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.csw-msg.is-me .csw-bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }
.csw-meta { font-size: 12px; color: var(--text-3); padding: 0 4px; display: flex; gap: 6px; align-items: center; }
.csw-meta .is-read { color: var(--live); }
.csw-meta .is-fail { color: var(--alert-soft); }
.csw-retry { border: 0; background: none; color: var(--alert-soft); text-decoration: underline; cursor: pointer; padding: 0 4px; min-height: 24px; font-size: 12px; }

/* ---------- 表情 ---------- */
.csw-emoji {
  flex: none; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 8px 10px;
  border-top: 1px solid var(--line); background: var(--panel-3); max-height: 132px; overflow-y: auto;
}
.csw-emoji button { height: 40px; border: 0; border-radius: var(--r-2); background: transparent; font-size: 22px; cursor: pointer; padding: 0; }
.csw-emoji button:hover, .csw-emoji button:focus-visible { background: var(--panel-2); outline: none; }

/* ---------- 输入区 ---------- */
.csw-compose { flex: none; display: flex; align-items: flex-end; gap: 4px; padding: 8px 8px 6px; border-top: 1px solid var(--line); background: var(--panel); }
.csw-compose .csw-icon-btn { width: 40px; height: 44px; }
.csw-compose .csw-icon-btn.is-on { color: var(--accent); }
.csw-input-wrap { flex: 1; min-width: 0; position: relative; }
.csw-input {
  width: 100%; height: 44px; min-height: 44px; max-height: 112px; resize: none; display: block; overflow-y: auto;
  padding: 11px 12px; border-radius: 22px; border: 1px solid var(--line-2);
  background: var(--panel-3); color: var(--text); font: inherit; font-size: 14px; line-height: 20px; outline: none;
}
.csw-input::placeholder { color: var(--text-3); }
.csw-input:focus { border-color: var(--accent); }
.csw-count { position: absolute; right: 12px; top: -18px; font-size: 12px; font-family: var(--mono); color: var(--text-3); }
.csw-count.is-over { color: var(--alert-soft); }
.csw-send {
  width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center;
}
.csw-send:disabled { background: var(--panel-2); color: var(--text-3); cursor: default; }
.csw-send:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.csw-send .csw-i { width: 20px; height: 20px; }
.csw-foot { flex: none; text-align: center; font-size: 12px; color: var(--text-3); padding: 0 12px 8px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.csw-foot .csw-i { width: 13px; height: 13px; flex: none; }

/* ---------- 更多菜单 ---------- */
.csw-menu {
  position: absolute; z-index: 3; right: 10px; top: 62px; min-width: 180px; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r-2); box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}
.csw-menu button {
  width: 100%; min-height: 44px; padding: 0 10px; border: 0; border-radius: var(--r-1); background: transparent;
  color: var(--text); font-size: 13px; text-align: left; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.csw-menu button:hover, .csw-menu button:focus-visible { background: var(--panel); outline: none; }
.csw-menu .is-danger { color: var(--alert-soft); }
.csw-menu button:disabled { color: var(--text-3); cursor: default; background: transparent; }

/* ---------- 组件内提示 ---------- */
.csw-toast {
  position: absolute; left: 50%; top: 70px; transform: translateX(-50%); z-index: 4; max-width: 90%;
  padding: 8px 12px; border-radius: var(--r-2); background: var(--text); color: var(--bg); font-size: 13px; font-weight: 700;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .45); text-align: center;
}

/* ---------- 电脑：右下角浮动视窗 ---------- */
@media (min-width: 1024px) {
  .csw { --csw-fab: 58px; --csw-gap: 24px; }
  /* 九法专区右下角有「客户端入口」浮条：客服按钮和面板往上让开。 */
  :root:has(.pg-jiufa .jf-float) .csw { --csw-lift: 64px; }
  .csw-fab { bottom: calc(var(--csw-gap) + var(--csw-lift)); right: var(--csw-gap); }
  .csw.is-open .csw-fab { visibility: visible; }
  .csw-backdrop { display: none !important; }
  .csw-panel {
    left: auto; right: var(--csw-gap); bottom: calc(var(--csw-gap) + var(--csw-lift) + var(--csw-fab) + 14px);
    width: 380px; height: min(620px, calc(100vh - 130px - var(--csw-lift))); min-height: 420px;
    border: 1px solid var(--line-2); border-radius: 14px; padding-bottom: 0;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
    transform: translateY(16px) scale(.98); opacity: 0; pointer-events: none;
    transition: transform 200ms var(--ease), opacity 200ms var(--ease), visibility 0s linear 200ms;
  }
  .csw.is-open .csw-panel { transform: none; opacity: 1; pointer-events: auto; transition: transform 200ms var(--ease), opacity 200ms var(--ease); }
  .csw-grip-zone { cursor: default; touch-action: auto; }
  .csw-grip, .csw-grip-hint { display: none; }
  .csw-head { padding-top: 8px; }
  .csw-col { max-width: 260px; }
  .csw-menu button { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .csw-panel, .csw-backdrop, .csw-fab { transition: none !important; animation: none !important; }
  .csw-conn-dot { animation: none; }
}

/* ---------- 站内入口 ---------- */
/* 电脑左侧导航「在线客服」（app.js 渲染；按钮套用 .nav-item 的样式）。 */
.nav-item.csw-nav { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; font: inherit; font-size: var(--fs-md); }
.nav-item.csw-nav:hover { background: var(--panel); color: var(--text); }
.csw-nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--alert); color: #fff;
  font-family: var(--mono); font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}
/* 文字中的「联系客服」入口（例如九法专区公告）。 */
.csw-link { display: inline; border: 0; padding: 0; margin: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; }
.csw-link:hover { color: var(--accent-hi); text-decoration: underline; }

/* ---------- 接入补充（ui-design/prototype-a 2026-10-25）---------- */
/* 聊天厅（#/chat）本身是全屏对话页，输入栏贴在底部导航上方：手机/平板在这一页不显示客服浮动按钮（页内的「联系客服」
   入口照常可用），也不加按钮留白，页面高度保持一屏，按钮永远不会盖住输入栏。 */
@media (max-width: 1023px) {
  :root:has(.pg-chat .chat-main) .csw:not(.is-open) .csw-fab { display: none; }
  :root.csw-on .view:has(.pg-chat .chat-main) { padding-bottom: calc(var(--tab-h) + var(--safe-b)); }
}
/* 未读徽章与站内其他徽章（chat.css .msg-badge）同一种红，白字对比度 4.8:1。 */
.csw-badge, .csw-nav-badge { background: #D92D2D; }
