/* 客服系统 V2 · 访客端 */
*, *::before, *::after { box-sizing: border-box; }
/* hidden 属性优先于任何 display，否则 flex/grid 会把它覆盖掉 */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #eef1f6;
  color: #1f2329;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
.app {
  height: 100%;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #f2f4f8;
  position: relative;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: #409eff;
  color: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .12);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,.22);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600;
}
.meta .name { font-size: 16px; font-weight: 600; line-height: 1.2; }
.meta .status { font-size: 11px; opacity: .9; display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #52e08a; display: inline-block; }

.icon-btn {
  border: 0; background: transparent; color: inherit;
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; cursor: pointer;
  opacity: .75; transition: .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.14); opacity: 1; }
.icon-btn.on { opacity: 1; background: rgba(255,255,255,.2); }

/* ---------- 消息区 ---------- */
.chat {
  flex: 1;
  min-height: 0;          /* 关键：不加这个，flex 子项压不下去，输入框会被挤出屏幕 */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.day { text-align: center; font-size: 11px; color: #9aa3af; margin: 6px 0; }
.row { display: flex; gap: 8px; max-width: 100%; }
.row.me { flex-direction: row-reverse; }
.row.sys { justify-content: center; }
.avt {
  flex: none;
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  background: #dfe5ee; color: #5a6473;
}
.row.me .avt { background: #409eff; color: #fff; }
.body { max-width: 76%; display: flex; flex-direction: column; }
.row.me .body { align-items: flex-end; }
.bubble {
  padding: 9px 13px;
  border-radius: 4px 14px 14px 14px;
  background: #fff;
  font-size: 15px; line-height: 1.55;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(20, 30, 50, .06);
}
.row.me .bubble {
  background: #409eff; color: #fff;
  border-radius: 14px 4px 14px 14px;
}
.sys-bubble {
  font-size: 12px; color: #8b95a3;
  background: rgba(0,0,0,.04);
  padding: 5px 12px; border-radius: 12px;
  max-width: 84%; text-align: center; line-height: 1.5;
}
.time { font-size: 10px; color: #a8b0bd; margin-top: 4px; padding: 0 2px; }

/* 图片 */
.pic {
  max-width: 190px; max-height: 240px;
  border-radius: 10px;
  display: block; cursor: zoom-in;
  box-shadow: 0 1px 3px rgba(20,30,50,.12);
  background: #fff;
}

/* 文件卡片 */
.filecard {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 12px;
  padding: 10px 12px;
  text-decoration: none; color: inherit;
  box-shadow: 0 1px 2px rgba(20,30,50,.06);
  min-width: 210px;
}
.row.me .filecard { background: #409eff; color: #fff; }
.ficon {
  flex: none; width: 38px; height: 38px; border-radius: 9px;
  background: #eef4ff; color: #409eff;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
}
.row.me .ficon { background: rgba(255,255,255,.24); color: #fff; }
.fmeta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fmeta b { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fmeta i { font-size: 11px; font-style: normal; opacity: .6; margin-top: 2px; }
.fdl { flex: none; font-size: 12px; opacity: .8; }

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 9px 12px;
  padding-bottom: calc(9px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #e8ecf2;
}
.composer .plus { color: #6b7480; width: 34px; height: 34px; }
#input {
  flex: 1;
  border: 1px solid #e2e7ef;
  background: #f6f8fb;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 15px; line-height: 1.4;
  font-family: inherit;
  resize: none;
  max-height: 110px;
  outline: none;
  transition: .15s;
}
#input:focus { border-color: #409eff; background: #fff; }
.send {
  flex: none;
  border: 0; border-radius: 10px;
  background: #409eff; color: #fff;
  font-size: 14px; font-weight: 500;
  padding: 9px 16px; height: 38px;
  cursor: pointer;
}
.send:active { background: #337ecc; }

/* ---------- 附件面板 ---------- */
/* 附件面板：常驻在输入框上方、默认收起来；展开时撑开把输入框推下去 */
.sheet {
  flex: none;
  max-height: 0;
  overflow: hidden;
  background: #fff;
  padding: 0 16px;
  border-top: 1px solid transparent;
  transition: max-height .2s ease, padding .2s ease, border-color .2s ease;
}
.sheet.show {
  max-height: 130px;
  padding: 16px;
  border-top-color: #e8ecf2;
}
.sheet-inner { display: flex; gap: 26px; }
.sheet-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 12px; color: #5a6473; cursor: pointer;
}
.sheet-item svg { color: #409eff; }

/* ---------- 图片查看器 ---------- */
/* ★ 2026-10-26 同后台：grid 会被大图撑开导致 max-height 失效，改 flex + min-height:0 */
.viewer {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.88);
  display: none; z-index: 40; padding: 20px;
  align-items: center; justify-content: center;
  overflow: hidden;
}
.viewer.show { display: flex; }
.viewer img {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 6px;
  min-width: 0; min-height: 0;
}

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: 96px;
  transform: translate(-50%, 10px);
  background: rgba(30,36,48,.92); color: #fff;
  font-size: 13px; padding: 9px 16px; border-radius: 20px;
  opacity: 0; pointer-events: none; transition: .2s;
  z-index: 50; max-width: 80%; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 上传进度气泡 ---------- */
.upbubble { min-width: 210px; max-width: 260px; }
.upbubble .uname {
  font-size: 12.5px; margin-bottom: 8px;
  word-break: break-all; line-height: 1.4;
}
.upbubble .ubar {
  height: 5px; background: rgba(0,0,0,.1);
  border-radius: 3px; overflow: hidden;
}
.upbubble .ubar i {
  display: block; height: 100%; width: 0;
  background: #409eff; border-radius: 3px;
  transition: width .25s ease;
}
.row.me .upbubble .ubar { background: rgba(255,255,255,.32); }
.row.me .upbubble .ubar i { background: #fff; }
.upbubble .umeta {
  font-size: 10.5px; opacity: .72; margin-top: 6px;
  line-height: 1.4; font-variant-numeric: tabular-nums;
}

/* 文件库链接卡片 */
.filecard.is-link .ficon { background: #e8f7ef; color: #1a9a5c; }
.row.me .filecard.is-link .ficon { background: rgba(255,255,255,.24); color: #fff; }

/* 发送中 / 发送失败（乐观发送） */
.row.pending .bubble { opacity: .55; }
.row.pending .time { color: #a8b0bd; }
.row.failed .bubble { background: #e34d59 !important; color: #fff !important; }
.row.failed .time { color: #e34d59; cursor: pointer; }

/* ---------- 正文里的可点链接（2026-10-27） ---------- */
.bubble .msg-link {
  color: #1a73e8; text-decoration: underline;
  text-decoration-color: rgba(26,115,232,.45);
  text-underline-offset: 2px; word-break: break-all;
}
.row.me .bubble .msg-link { color: #fff; text-decoration-color: rgba(255,255,255,.6); }
