/* 销售报价导入助手 —— 企微聊天风格 H5 */
:root {
  --bg: #ededed;
  --header-bg: #ededed;
  --bubble-user: #95ec69;
  --bubble-sys: #ffffff;
  --text-main: #191919;
  --text-sub: #8a8a8a;
  --line: #dcdcdc;
  --link: #576b95;
  --danger: #e64340;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text-main);
  font-size: 16px;
}
#app { display: flex; flex-direction: column; height: 100%; max-width: 720px; margin: 0 auto; }

/* ---------- 头部 ---------- */
.chat-header {
  display: flex; align-items: center;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.header-back { color: #191919; padding: 4px; visibility: hidden; }
.header-title { flex: 1; text-align: center; min-width: 0; }
.title-main { font-size: 17px; font-weight: 600; }
.title-sub { font-size: 12px; color: var(--text-sub); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-status { font-size: 11px; color: #09bb07; padding: 4px; }
.header-status.off { color: #b2b2b2; }

/* ---------- 消息区 ---------- */
.chat-body {
  flex: 1; overflow-y: auto;
  padding: 12px 12px 16px;
  -webkit-overflow-scrolling: touch;
}
.msg-time { text-align: center; font-size: 12px; color: var(--text-sub); margin: 8px 0 12px; }
.msg-row { display: flex; margin-bottom: 14px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }
.msg-row.sys { flex-direction: row; }

.avatar {
  width: 38px; height: 38px; border-radius: 5px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #fff;
}
.avatar-sys { background: #4a90d9; }
.avatar-user { background: #7cb342; }
.avatar .u1 { font-size: 14px; }

.msg-main { max-width: calc(100% - 96px); display: flex; flex-direction: column; }
.msg-row.user .msg-main { align-items: flex-end; }
.sender-name { font-size: 12px; color: var(--text-sub); margin: 0 8px 4px; }

.bubble {
  background: var(--bubble-sys);
  border-radius: 6px;
  padding: 10px 12px;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.04);
  font-size: 15px;
  margin: 0 8px;
}
.msg-row.user .bubble { background: var(--bubble-user); }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble .muted { color: var(--text-sub); font-size: 13px; }
.bubble a { color: var(--link); text-decoration: none; word-break: break-all; }
.bubble.err { background: #fff7f6; border: 1px solid #f3c6c5; }
.bubble.ok-title { font-weight: 600; }

/* 文件卡片 */
.file-card {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: 6px; padding: 8px 10px;
  margin: 0 8px; max-width: calc(100% - 96px);
  box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.msg-row.user .file-card { background: #8ee152; }
.file-icon {
  width: 34px; height: 34px; border-radius: 4px; flex: none;
  background: #3e8e41; color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.file-card .fmeta { min-width: 0; }
.file-card .fname { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.file-card .fsize { font-size: 12px; color: var(--text-sub); }
.msg-row.user .file-card .fsize { color: rgba(0,0,0,.45); }
.file-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.msg-row.user .file-stack { align-items: flex-end; }

/* 执行日志块 */
.log-block {
  background: #2d2d2d; color: #d8d8d8;
  font-family: Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5;
  border-radius: 4px; padding: 8px 10px;
  white-space: pre-wrap; word-break: break-all;
  max-height: 260px; overflow-y: auto; margin: 6px 0;
}
.bubble.err .log-block { background: #3a2322; }
.tag-line { font-size: 13px; }
.tag-ok { color: #09bb07; }
.tag-bad { color: var(--danger); }

/* loading 气泡 */
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #b2b2b2; animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }
.spin-note { font-size: 13px; color: var(--text-sub); margin-top: 4px; }

/* ---------- 输入区 ---------- */
.chat-inputbar {
  flex: none; background: #f7f7f7;
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + var(--safe-bottom));
}
.attach-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.attach-preview:empty { margin-bottom: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 4px; font-size: 12px; padding: 4px 8px; max-width: 100%;
}
.chip .cname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.chip .crm { color: #b2b2b2; cursor: pointer; padding: 0 2px; font-size: 14px; }
.input-row { display: flex; align-items: flex-end; gap: 8px; }
.attach-btn { display: flex; align-items: center; cursor: pointer; padding-bottom: 6px; }
.attach-btn.busy { opacity: .4; pointer-events: none; }
#textInput {
  flex: 1; border: none; outline: none; resize: none;
  background: #fff; border-radius: 6px;
  padding: 8px 10px; font-size: 15px; font-family: inherit;
  max-height: 96px; line-height: 1.4;
}
.send-btn {
  border: none; background: #07c160; color: #fff;
  font-size: 15px; border-radius: 6px; padding: 8px 16px;
  flex: none; cursor: pointer;
}
.send-btn:disabled { background: #9fd6b6; cursor: not-allowed; }
.input-tips { font-size: 11px; color: var(--text-sub); margin-top: 6px; text-align: center; }

@media (min-width: 720px) {
  .msg-main { max-width: 70%; }
}
