/* ==========================================================================
   在线客服浮标 + 对话面板（第 85 轮）
   --------------------------------------------------------------------------
   ★ 全部用逻辑属性（inset-inline-end / margin-inline-*）：阿语 RTL 自动镜像，
     不必维护两份会漂移的样式（见 front.css 的三条硬原则）。
   ★ 手机上浮标要**抬到移动端底部条之上**，否则正好压在 WhatsApp 按钮上。
     高度取 `--mobile-bar-h`（与 01-base.css 的 body 留白同一个来源）。
   ★ z-index：90 —— 高于移动端底部条（80）、低于遮罩页（独立骨架，互不影响）。
   ========================================================================== */

.chat-w {
  position: fixed;
  inset-block-end: calc(16px + env(safe-area-inset-bottom, 0px));
  inset-inline-end: 16px;
  z-index: 90;
  display: flex;
  /* ★ `column-reverse` 不是随手写的：DOM 里浮标在前、面板在后，
     用 `column` 时面板会**排在浮标下面** → 容器一撑高，浮标就被顶到上面去
     （实测：点开面板的瞬间按钮"跳"了 300px，很扎眼）。
     `column-reverse` 让先出现的浮标贴在底边，面板往上长，按钮原地不动。 */
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;            /* 只有按钮/面板吃事件，别挡住页面其它链接 */
}
.chat-w > * { pointer-events: auto; }

/* ---------- 浮标 ---------- */
.chat-w__fab {
  position: relative;
  width: 54px; height: 54px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: var(--primary);
  color: var(--on-accent, #fff);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  cursor: pointer;
  transition: transform .15s ease, background-color .15s ease;
}
.chat-w__fab:hover { background: var(--primary-hover); }
.chat-w__fab:active { transform: scale(.96); }
.chat-w__fab:focus-visible { outline: 3px solid var(--primary-border); outline-offset: 2px; }
.chat-w__fab-ico { display: block; }

.chat-w__badge {
  position: absolute;
  inset-block-start: -2px;
  inset-inline-end: -2px;
  min-width: 19px; height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  background: #C0392B;
  color: #fff;
  font-size: 11px; line-height: 19px; font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.chat-w__badge[hidden] { display: none; }

/* ---------- 面板 ---------- */
.chat-w__panel {
  width: min(340px, calc(100vw - 32px));
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg, #fff);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
}
.chat-w__panel[hidden] { display: none; }

.chat-w__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-block-end: 1px solid var(--line);
  background: var(--bg-soft);
}
.chat-w__title { font-size: .9375rem; color: var(--ink-1, #1F2328); }
.chat-w__close {
  border: 0; background: none; cursor: pointer;
  font-size: 22px; line-height: 1;
  color: var(--ink-2);
  padding: 0 4px;
}
.chat-w__close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.chat-w__log {
  flex: 1 1 auto;
  min-height: 160px;
  overflow-y: auto;
  overscroll-behavior: contain;    /* 滚到底不要连带滚整页 */
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}

.chat-w__empty {
  margin: auto;
  color: var(--ink-2);
  font-size: .875rem;
  text-align: center;
}

/* ---------- 消息气泡 ---------- */
.chat-w__msg {
  max-width: 84%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-w__msg--buyer { align-self: flex-end; align-items: flex-end; }
.chat-w__msg--admin { align-self: flex-start; align-items: flex-start; }
.chat-w__msg--system { align-self: center; align-items: center; max-width: 100%; }

.chat-w__body {
  margin: 0;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: .9375rem;
  line-height: 1.5;
  white-space: pre-wrap;         /* 保留买家输入的换行 */
  overflow-wrap: anywhere;       /* 长网址/长型号不撑破面板 */
}
.chat-w__msg--buyer .chat-w__body {
  background: var(--primary);
  color: var(--on-accent, #fff);
  border-end-end-radius: 4px;
}
.chat-w__msg--admin .chat-w__body {
  background: var(--bg-soft);
  color: var(--ink-1, #1F2328);
  border-end-start-radius: 4px;
}

/* 系统消息（改单/状态变化）：居中、小字、不抢眼 —— 它是"通知"不是"对话" */
.chat-w__sys {
  margin: 0;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: .8125rem;
  line-height: 1.45;
  text-align: center;
}

.chat-w__img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
}

.chat-w__at {
  font-size: 11px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* ★ 第 110 轮：按天分隔的日期条。
   业主原话：「聊天记录的时间……只有时钟分钟……浏览历史记录会感到困惑」。
   `align-self: center` 靠的是 `.chat-w__log` 的 flex column；不要改成 margin auto。 */
.chat-w__day {
  align-self: center;
  margin: 4px 0 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

/* ---------- 输入 ---------- */
.chat-w__form {
  position: relative;          /* 第 89 轮：状态浮层的定位父级（不改变布局） */
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px;
  border-block-start: 1px solid var(--line);
  background: var(--bg-soft);
}
.chat-w__form[hidden] { display: none; }

.chat-w__input {
  flex: 1 1 auto;
  min-height: 36px;
  max-height: 96px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg, #fff);
  color: inherit;
  font: inherit;
  font-size: .9375rem;
  resize: none;
}
.chat-w__input:focus { outline: 2px solid var(--primary-border); outline-offset: 1px; }

.chat-w__attach {
  display: inline-flex; align-items: center; gap: 4px;
  flex: 0 0 auto;
  height: 36px; padding: 0 6px;
  color: var(--ink-2);
  cursor: pointer;
  border-radius: 8px;
}
.chat-w__attach:hover { background: var(--line); }
.chat-w__attach-name {
  max-width: 70px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px;
}

.chat-w__send {
  flex: 0 0 auto;
  height: 36px; padding: 0 14px;
  border: 0; border-radius: 10px;
  background: var(--primary);
  color: var(--on-accent, #fff);
  font: inherit; font-size: .875rem; font-weight: 600;
  cursor: pointer;
}
.chat-w__send:hover { background: var(--primary-hover); }

.chat-w__guest {
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 12px; align-items: flex-start;
  color: var(--ink-2);
  font-size: .9375rem; line-height: 1.55;
}
.chat-w__guest[hidden] { display: none; }
.chat-w__guest p { margin: 0; }

.chat-w__err {
  margin: 0;
  padding: 6px 12px 10px;
  color: #B3261E;
  font-size: .8125rem;
}
.chat-w__err[hidden] { display: none; }

/* ---------- 手机：抬高到底部条之上，面板占满可用宽度 ---------- */
@media (max-width: 899px) {
  .chat-w {
    inset-block-end: calc(var(--mobile-bar-h) + 12px + env(safe-area-inset-bottom, 0px));
    inset-inline-end: 12px;
  }
  .chat-w__panel {
    width: min(340px, calc(100vw - 24px));
    max-height: min(62vh, 460px);
  }
}

/* ---------- 订单卡片（第 86 轮：订单页"咨询此订单"发的那条） ----------
   与文字气泡同宽逻辑，但内容是"一个可点的凭据"：单号必须能一眼看清。
   ★ 三行竖排（标签/单号/金额），不写死 left/right —— 阿语 RTL 下自动镜像。 */
.chat-w__order {
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* ★ 必须给确定性宽度：父级是 `align-items: flex-end` 的 column flex，
     子项按 fit-content 收缩 —— 不给 width 时单号会被挤成两行（真机量出来的）。 */
  width: 220px;
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line, #E4E7EC);
  background: var(--surface, #fff);
  color: var(--ink-1, #1F2328);
  text-decoration: none;
  border-end-end-radius: 4px;
}
.chat-w__msg--admin .chat-w__order { border-end-end-radius: 12px; border-end-start-radius: 4px; }
.chat-w__order:hover { border-color: var(--primary); }
.chat-w__order-k { font-size: .75rem; color: var(--ink-2, #6B7280); }
.chat-w__order-no {
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: .8125rem;
  letter-spacing: .01em;
  word-break: normal;
  overflow-wrap: anywhere;   /* 只有真放不下才断，别为了对齐把单号硬切开 */
}
.chat-w__order-total { font-size: .8125rem; font-weight: 600; color: var(--primary); }

/* ---------- 上传进度浮层（第 87 轮 / 第 89 轮改绝对定位） ----------
   图片上限 8MB，慢网要好几秒，没有提示 = 用户以为没点上 = 重复发。
   ★ 必须是 `position: absolute`：这一行只要占文档流，出现/消失就会把
     输入框和发送按钮整行顶一下（业主原话"非常不雅观"）。
   纯文字消息不提示 —— 按钮灰着已经说明在发了。 */
.chat-w__state {
  position: absolute;
  inset-inline-end: 12px;
  bottom: calc(100% + 6px);
  z-index: 2;
  margin: 0;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .6875rem;
  line-height: 1.45;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 2px 8px rgb(0 0 0 / .16);
  pointer-events: none;        /* 不挡底下的消息与缩略图 */
}
.chat-w__state[hidden] { display: none; }

.chat-w__send:disabled {
  opacity: .6;
  cursor: progress;
}

/* 命中 5 秒兜底窗口时闪一下那张已存在的卡片，否则"点了没反应" */
.chat-w__msg.is-flash .chat-w__order {
  animation: chat-w-flash .9s ease-out 1;
}
@keyframes chat-w-flash {
  0%   { box-shadow: 0 0 0 0 var(--primary); }
  40%  { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 45%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- 图片点击放大（第 87 轮） ----------
   单例遮罩，JS 挂到 body。z-index 高于浮标(90)与面板，低于任何系统弹层。 */
.chat-w__img { cursor: zoom-in; }

.chat-w__lb {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vh 3vw;
  background: rgba(15, 18, 22, .84);
}
.chat-w__lb[hidden] { display: none; }
.chat-w__lb img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  cursor: zoom-out;
}
.chat-w__lb-x {
  position: absolute;
  inset-block-start: 12px;
  inset-inline-end: 16px;
  width: 34px; height: 34px;
  border: 1px solid rgba(255, 255, 255, .45);
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  font-size: 20px; line-height: 1;
  cursor: pointer;
}
