/* 客服窗口保留引用回复；撤回授权与五分钟时限由服务端校验。 */
.contact-toggle { position: fixed; right: 24px; bottom: calc(24px + var(--contact-lift,0px)); z-index: 40; display: grid; place-items: center; width: 54px; height: 54px; padding: 0; border: 1px solid var(--ink,#302a23); border-radius: 50%; background: var(--ink,#302a23); color: #fffefa; box-shadow: 0 8px 20px #302a231f; transition: bottom 160ms var(--ease,cubic-bezier(.16,1,.3,1)),background 160ms,opacity 160ms; }
.contact-toggle:hover { background: #66503c; }
.contact-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.4; flex-shrink: 0; }
.contact-toggle:focus-visible { outline: 2px solid var(--accent,#765336); outline-offset: 4px; }
/* 章节正文和影片拥有自己的操作区，隐藏固定球避免遮挡商品图与原生播放器控件。 */
body[data-view]:not([data-view="home"]) .contact-toggle { opacity: 0; visibility: hidden; pointer-events: none; }
.contact-toggle.is-mobile-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.contact-window { position: fixed; inset: auto 24px 88px auto; margin: 0; width: min(402px,calc(100vw - 32px)); height: min(620px,calc(100svh - 120px)); padding: 0; border: 1px solid #d8d3c9; border-radius: 18px; background: #fff; color: var(--ink,#302a23); box-shadow: 0 24px 64px #302a2330; overflow: hidden; }
.contact-window[open] { display: flex; flex-direction: column; animation: contact-rise 260ms var(--ease,cubic-bezier(.16,1,.3,1)) both; }
.contact-window::backdrop { background: #25272233; }
.contact-head { flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 20px 16px; border-bottom: 1px solid #e0dcd4; background: #fbfaf7; }
.contact-heading { display: flex; align-items: flex-start; gap: 11px; min-width: 0; }
.contact-mark { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border: 1px solid #d8d3c9; border-radius: 50%; background: #fff; font: 400 20px/1 Georgia,serif; color: var(--ink,#302a23); }
.contact-head h2 { margin: 5px 0 0; font: 400 25px/1.15 Georgia,"Times New Roman",serif; letter-spacing: -.03em; }
.contact-thread[hidden],.contact-composer[hidden] { display:none; }
/* 无法读取会话时给出可恢复入口，沿用窗口配色，不以禁用表单代替错误处理。 */
.contact-recovery { flex:1; display:flex; flex-direction:column; align-items:flex-start; justify-content:center; gap:14px; padding:24px; overflow-y:auto; font:400 14px/1.6 Manrope,sans-serif; }
.contact-recovery p { margin:0; }
.contact-recovery a,.contact-recovery button { color:var(--ink,#302a23); font:600 14px/1.5 Manrope,sans-serif; min-height:44px; padding:10px 12px; border:1px solid #d8d3c9; border-radius:8px; background:#fff; text-decoration:none; cursor:pointer; }
.contact-recovery a:focus-visible,.contact-recovery button:focus-visible { outline:2px solid var(--accent,#765336); outline-offset:3px; }
.contact-recovery[hidden],.contact-recovery a[hidden] { display:none; }
.contact-presence { margin-top: 6px; font-size: 12px; line-height: 1.5; color: var(--muted,#625c53); }
.contact-close { display: grid; place-items: center; flex-shrink: 0; width: 40px; height: 40px; padding: 0; border: 1px solid #d8d3c9; border-radius: 50%; background: #fff; color: var(--muted,#625c53); transition: background 160ms,color 160ms,border-color 160ms; }
.contact-close:hover { color: var(--ink,#302a23); border-color: var(--ink,#302a23); }
.contact-close svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.3; }
.contact-thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 20px 20px 12px; scroll-behavior: smooth; background: #f8f7f3; }
.contact-thread.thread-empty-state { display: flex; align-items: center; justify-content: center; }
.chat-empty { margin: 0; color: var(--muted,#625c53); font-size: 14px; line-height: 1.6; text-align: center; }
/* 消息按内容收缩并为操作入口留位；气泡独立收缩，避免时间标签把短消息撑宽。 */
.chat-message { position: relative; width: fit-content; max-width: calc(100% - 44px); margin-bottom: 14px; }
.chat-message-care { margin-right: auto; }
.chat-message-user { margin-left: auto; }
/* 日期横跨整条会话，与气泡的左右归属分开；细线只作分组辅助，文字保留可读对比度。 */
.chat-date-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0 12px; color: var(--muted,#625c53); font-size: 12px; line-height: 1.5; text-align: center; }
.chat-date-divider:first-child { margin-top: 0; }
.chat-date-divider::before,.chat-date-divider::after { content: ''; flex: 1; min-width: 12px; height: 1px; background: #dcd7ce; }
.chat-date-divider time { max-width: calc(100% - 48px); overflow-wrap: anywhere; }
.chat-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.chat-message-user .chat-meta { justify-content: flex-end; }
.chat-author { font-size: 12px; font-weight: 600; color: var(--muted,#625c53); }
.chat-meta time { font-size: 12px; color: #756e63; }
.chat-text { width: fit-content; max-width: 100%; box-sizing: border-box; padding: 10px 14px; border: 1px solid #dcd7ce; border-radius: 14px 14px 14px 4px; background: #fff; color: var(--ink,#302a23); box-shadow: 0 3px 10px #302a2308; font-size: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-message-user .chat-text { margin-left: auto; border-radius: 14px 14px 4px 14px; background: var(--ink,#302a23); border-color: var(--ink,#302a23); color: #fffefa; box-shadow: 0 4px 12px #302a2320; }
/* 引用和正文分别按内容收缩；最长以当前消息宽度为界，文件名及长词仍允许换行。 */
.chat-quoted { width: fit-content; max-width: 100%; box-sizing: border-box; margin: 0 0 6px; padding: 9px 11px; border: 1px solid #ddd8cf; border-radius: 10px; background: #f4f1e9; overflow-wrap: anywhere; }
.chat-quoted[role="button"] { cursor:pointer; }
.chat-quoted[role="button"]:focus-visible,.chat-reference-highlight { outline:2px solid var(--accent,#765336);outline-offset:3px; }
.chat-quoted span { display: block; font-size: 12px; font-weight: 600; color: var(--muted,#625c53); }
.chat-quoted p { margin: 3px 0 0; font-size: 12px; line-height: 1.55; color: var(--muted,#625c53); overflow-wrap: anywhere; }
.chat-message-user .chat-quoted { margin-left: auto; border-color: #cfc8bd; background: #f7f5ef; }
/* 操作入口占气泡旁的预留空间，不另起按钮行；触屏常显，鼠标设备在悬停或键盘聚焦时显示。 */
.chat-more { position: absolute; top: 20px; right: -44px; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: var(--muted,#625c53); cursor: pointer; }
.chat-message-user .chat-more { right: auto; left: -44px; }
.chat-more svg { width: 20px; height: 20px; fill: currentColor; }
.chat-more:hover,.chat-more[aria-expanded="true"] { background: #eae6de; color: var(--ink,#302a23); }
.chat-more:focus-visible,.chat-action-panel button:focus-visible { outline: 2px solid var(--accent,#765336); outline-offset: -3px; }
@media (hover: hover) and (pointer: fine) {
  .chat-more { opacity: 0; }
  .chat-message:hover .chat-more,.chat-message:focus-within .chat-more,.chat-more[aria-expanded="true"] { opacity: 1; }
}
/* 操作层在聊天对话框内定位，独立于消息列表的滚动裁切；窄屏与大字号允许内部滚动。 */
.chat-action-panel { position: absolute; z-index: 5; width: min(240px,calc(100% - 16px)); max-height: calc(100% - 16px); overflow: auto; padding: 6px; border: 1px solid #d8d3c9; border-radius: 12px; background: #fff; color: var(--ink,#302a23); }
.chat-action-panel[hidden] { display: none; }
.chat-action-panel button { display: block; width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; color: inherit; text-align: left; font: 500 13px/1.5 Manrope,sans-serif; cursor: pointer; }
.chat-action-panel button:hover { background: #f4f1e9; }
.chat-action-panel button:disabled { opacity: .55; cursor: wait; }
.chat-action-panel .chat-action-danger { color: #8a3f2b; }
.chat-action-title { margin: 8px 12px 4px; font: 600 14px/1.5 Manrope,sans-serif; }
.chat-action-note { margin: 0 12px 8px; color: var(--muted,#625c53); font: 400 12px/1.5 Manrope,sans-serif; }
.contact-quote-row { flex:0 0 100%; min-width:0; }
.contact-quote-row:has(.contact-quote[hidden]) { display:none; }
.contact-quote { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; width: fit-content; max-width: 100%; box-sizing: border-box; margin: 0; padding: 8px; border: 1px solid #ddd8cf; border-radius: 10px; background: #f5f1e8; }
.contact-quote-label { font-size: 11px; font-weight: 600; letter-spacing: .05em; color: var(--muted,#625c53); }
.contact-quote > div { min-width: 0; }
.contact-quote-text { max-width:240px;max-height:144px;overflow:auto; margin-top: 3px; font-size: 12px; line-height: 1.55; color: var(--ink,#302a23); overflow-wrap: anywhere; }
.contact-quote-cancel { color: var(--muted,#625c53); }
.contact-composer { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid #e0dcd4; background: #fff; }
/* 附件托盘单独占行但限定高度，手机和长文件队列不能把发送操作挤出对话框。 */
.contact-attachment-tray { flex: 0 0 100%; max-height: 112px; overflow-y: auto; }
.contact-attachment-tray[hidden] { display: none; }
.contact-attachment-button { flex: 0 0 auto; display: flex; }
.contact-composer .chat-attachments-add { width: 44px; min-width: 44px; height: 48px; }
/* 以剩余宽度分配输入框，避免新附件按钮加入后把发送按钮挤到下一行。 */
.contact-composer textarea { flex: 1 1 0; min-width: 0; min-height: 48px; max-height: 100px; resize: none; border: 1px solid #d4cfc5; border-radius: 14px; background: #fff; padding: 10px 12px; color: var(--ink,#302a23); font: 14px/1.6 Manrope,sans-serif; }
.contact-composer textarea:focus { outline: none; border-color: var(--accent,#765336); box-shadow: 0 0 0 3px #7353361f; }
.contact-composer textarea::placeholder { color: #8a8276; }
.contact-send { flex: 0 0 auto; display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 1px solid var(--ink,#302a23); border-radius: 14px; background: var(--ink,#302a23); color: #fffefa; transition: background 160ms,transform 160ms; }
.contact-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.contact-send:hover { background: #66503c; transform: translateY(-1px); }
.contact-send:disabled { cursor: not-allowed; opacity: .42; }
.contact-status { min-height: 0; margin: 0 20px 4px; font-size: 12px; line-height: 1.5; color: var(--accent,#765336); }
.contact-status[data-tone="error"] { color: #8a3f2b; }
.contact-status:empty { display: none; }
/* 新消息与失败重试各自只在需要时占一行，不能覆盖消息或挤掉发送区。 */
.contact-new-messages,.contact-retry { flex: 0 0 auto; align-self: center; min-height: 44px; padding: 8px 14px; border: 0; background: #fff; color: var(--ink,#302a23); font: 600 13px/1.5 Manrope,sans-serif; text-decoration: underline; text-underline-offset: 3px; }
.contact-retry { align-self: flex-start; margin: 0 6px 4px; }
.contact-new-messages[hidden],.contact-retry[hidden],.contact-presence[hidden] { display: none; }
.contact-new-messages:focus-visible,.contact-retry:focus-visible { outline: 2px solid var(--accent,#765336); outline-offset: -3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
body.contact-open { overflow: hidden; }
/* 对话打开时收起悬浮球，避免它从窗口下方探出来。 */
body.contact-open .contact-toggle { opacity: 0; visibility: hidden; pointer-events: none; }
@keyframes contact-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (max-width: 700px) {
  .contact-toggle { right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); width: 48px; height: 48px; }
  .contact-window { inset: max(16px,env(safe-area-inset-top)) 16px max(16px,env(safe-area-inset-bottom)) 16px; width: auto; height: min(640px,calc(100svh - max(32px,env(safe-area-inset-top) + env(safe-area-inset-bottom)))); max-height: calc(100svh - max(32px,env(safe-area-inset-top) + env(safe-area-inset-bottom))); }
  .contact-head h2 { font-size: 24px; }
  .contact-head { padding: 14px 16px; }
  .contact-thread { padding: 14px 16px 8px; }
  .contact-composer { padding: 12px 16px; }
  .contact-composer textarea,.chat-text { font-size: 16px; }
  .chat-message { max-width: calc(100% - 44px); }
}
@media (prefers-reduced-motion: reduce) {
  .contact-window[open] { animation: none; }
  .contact-thread { scroll-behavior: auto; }
}
