/* ==========================================================================
   道合核销群 - app.css
   亮色主题 · 主色 蓝绿 50:50 (teal)
   兼容策略: 不用 CSS 变量/Grid/:has 等新特性, flex 与渐变均带 -webkit- 前缀;
   字号 >=16px 防 iOS 聚焦缩放; [hidden] 强制隐藏; reduced-motion 关闭动效。

   设计 token (如需改色只改这里, 值均为字面量以保证旧内核可用)
   ----------------------------------------------------------------
   --brand-deep   #134E4A   (最深 teal, 渐变终点/强调)
   --brand        #0F766E   (主色, 我方气泡/按钮/链接, 白字 5.47:1)
   --brand-soft   #115E59   (按钮渐变终点)
   --brand-ink    #0B6E69   (他人昵称文字, 白底 6.09:1)
   --text         #0F172A   (正文 深灰蓝, 白底 16.2:1)
   --text-mute    #475569   (次要文字, 白底 6.87:1)
   --wall         #EAF3F1   (聊天墙基础色, 与渐变/光斑组合成非纯色底)
   --card         #FFFFFF
   --line         #DCE7E5
   --danger       #B91C1C
   ========================================================================== */

/* ---------- 基础 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.5; color: #0F172A;
  overflow: hidden;
  -webkit-tap-highlight-color: rgba(15, 118, 110, 0.12);
}

/* ---------- 氛围背景 (非纯色 + 缓慢动效) ---------- */
#bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: -webkit-linear-gradient(155deg, #EAF3F1 0%, #E2EFED 46%, #EFF7F5 100%);
  background: linear-gradient(155deg, #EAF3F1 0%, #E2EFED 46%, #EFF7F5 100%);
}
/* 极淡 teal 点纹 (SVG data-uri, 图片由 CSP img-src data: 放行) */
#bg::after {
  content: ""; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26'%3E%3Ccircle cx='3' cy='3' r='1.6' fill='%230F766E' fill-opacity='0.055'/%3E%3C/svg%3E");
  background-size: 26px 26px;
}
.blob {
  position: absolute; border-radius: 50%;
  will-change: transform; pointer-events: none;
}
.blob-a {
  width: 46vmax; height: 46vmax; left: -14vmax; top: -12vmax;
  background: -webkit-radial-gradient(circle, rgba(13, 148, 136, 0.13), rgba(13, 148, 136, 0) 62%);
  background: radial-gradient(circle, rgba(13, 148, 136, 0.13), rgba(13, 148, 136, 0) 62%);
  -webkit-animation: driftA 46s ease-in-out infinite alternate;
  animation: driftA 46s ease-in-out infinite alternate;
}
.blob-b {
  width: 38vmax; height: 38vmax; right: -10vmax; top: 24vmax;
  background: -webkit-radial-gradient(circle, rgba(20, 184, 166, 0.13), rgba(20, 184, 166, 0) 60%);
  background: radial-gradient(circle, rgba(20, 184, 166, 0.13), rgba(20, 184, 166, 0) 60%);
  -webkit-animation: driftB 58s ease-in-out infinite alternate;
  animation: driftB 58s ease-in-out infinite alternate;
}
.blob-c {
  width: 30vmax; height: 30vmax; left: 16vmax; bottom: -14vmax;
  background: -webkit-radial-gradient(circle, rgba(15, 118, 110, 0.11), rgba(15, 118, 110, 0) 62%);
  background: radial-gradient(circle, rgba(15, 118, 110, 0.11), rgba(15, 118, 110, 0) 62%);
  -webkit-animation: driftC 64s ease-in-out infinite alternate;
  animation: driftC 64s ease-in-out infinite alternate;
}
@-webkit-keyframes driftA { from { -webkit-transform: translate3d(0,0,0) scale(1); } to { -webkit-transform: translate3d(9vmax,7vmax,0) scale(1.12); } }
@keyframes driftA    { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(9vmax,7vmax,0) scale(1.12); } }
@-webkit-keyframes driftB { from { -webkit-transform: translate3d(0,0,0) scale(1); } to { -webkit-transform: translate3d(-7vmax,-5vmax,0) scale(1.15); } }
@keyframes driftB    { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(-7vmax,-5vmax,0) scale(1.15); } }
@-webkit-keyframes driftC { from { -webkit-transform: translate3d(0,0,0) scale(1); } to { -webkit-transform: translate3d(5vmax,-6vmax,0) scale(1.1); } }
@keyframes driftC    { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(5vmax,-6vmax,0) scale(1.1); } }
@media (prefers-reduced-motion: reduce) {
  .blob { -webkit-animation: none; animation: none; }
}

/* ---------- 通用视图框架 ---------- */
.view { position: fixed; inset: 0; }
#view-chat {
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-orient: vertical; -webkit-flex-direction: column; flex-direction: column;
  background: transparent;
}

/* ================= 登录视图 ================= */
#view-login {
  overflow-y: auto;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center;
  padding: 24px 16px 24px; /* 旧内核回退(先声明) */
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); /* 支持安全区时覆盖 */
}
.login-card {
  width: 100%; max-width: 400px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #DCE7E5;
  border-radius: 24px;
  box-shadow: 0 18px 50px -18px rgba(15, 118, 110, 0.35);
  padding: 34px 28px 28px;
  -webkit-animation: cardIn .45s ease-out both;
  animation: cardIn .45s ease-out both;
}
@-webkit-keyframes cardIn { from { opacity: 0; -webkit-transform: translateY(14px); } to { opacity: 1; -webkit-transform: none; } }
@keyframes cardIn    { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .login-card { -webkit-animation: none; animation: none; } }

.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo { width: 88px; height: 88px; margin-bottom: 10px; }
.login-brand h1 { font-size: 24px; font-weight: 700; color: #0F172A; letter-spacing: .5px; }
.login-sub { margin-top: 6px; font-size: 14px; color: #475569; }
.login-hint { margin-top: 16px; text-align: center; font-size: 13px; color: #5A6B7A; }

.field { margin-bottom: 14px; }
.field label {
  display: block; margin-bottom: 6px;
  font-size: 14px; font-weight: 600; color: #0F172A;
}
.field input {
  width: 100%; min-height: 48px; padding: 0 14px;
  font-size: 16px; color: #0F172A;
  background: #FFFFFF; border: 1.5px solid #C9DAD7; border-radius: 12px;
  outline: none;
  -webkit-transition: border-color .15s, box-shadow .15s;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: #0F766E; box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18); }
.code-input {
  text-align: center; letter-spacing: 0.9em; font-weight: 700; font-size: 22px !important;
  font-variant-numeric: tabular-nums;
}
.form-error {
  background: #FEF2F2; color: #B91C1C; border: 1px solid #FECACA;
  border-radius: 10px; padding: 8px 12px; margin-bottom: 12px;
  font-size: 14px;
}

/* ---------- 按钮 ---------- */
.btn-primary {
  display: block; width: 100%; min-height: 50px; border: none;
  border-radius: 14px; cursor: pointer;
  font-size: 17px; font-weight: 600; color: #FFFFFF;
  background: -webkit-linear-gradient(135deg, #0F766E 0%, #115E59 100%);
  background: linear-gradient(135deg, #0F766E 0%, #115E59 100%);
  box-shadow: 0 10px 22px -10px rgba(15, 118, 110, 0.9);
  -webkit-transition: -webkit-transform .1s, box-shadow .15s;
  transition: transform .1s, box-shadow .15s;
}
.btn-primary:active { -webkit-transform: scale(.985); transform: scale(.985); box-shadow: 0 6px 14px -8px rgba(15,118,110,.9); }
.btn-ghost {
  min-height: 44px; padding: 0 18px; border: 1.5px solid #C9DAD7;
  border-radius: 12px; background: #FFFFFF; color: #0F172A;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-lg { width: 100%; }
.btn-primary:disabled, .btn-ghost:disabled, .send-btn:disabled { opacity: .55; cursor: default; }
button:focus-visible, .send-btn:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.55); outline-offset: 2px;
}

/* ================= 聊天视图 ================= */
.chat-head {
  -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid #DCE7E5;
  padding-top: 0; /* 旧内核回退: 无安全区 (先声明) */
  padding-top: env(safe-area-inset-top); /* 支持时覆盖 (刘海屏) */
  z-index: 5;
}
.chat-head-inner {
  max-width: 840px; margin: 0 auto;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  gap: 12px; padding: 8px 12px;
}
.head-logo { width: 38px; height: 38px; -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }
.head-text { -webkit-box-flex: 1; -webkit-flex: 1 1 auto; flex: 1 1 auto; min-width: 0; }
.head-text h2 { font-size: 17px; font-weight: 700; line-height: 1.25; color: #0F172A; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-meta { font-size: 12px; color: #475569; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-meta b { color: #0B6E69; font-weight: 700; }
.head-actions { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-align: center; -webkit-align-items: center; align-items: center; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px; border: none; background: transparent;
  border-radius: 50%; color: #0B6E69; cursor: pointer;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center;
}
.icon-btn:hover { background: rgba(15, 118, 110, 0.08); }
.icon-btn svg, .composer-btn svg, .send-btn svg { width: 22px; height: 22px; }

/* 消息墙 */
.msgs-wrap {
  -webkit-box-flex: 1; -webkit-flex: 1 1 auto; flex: 1 1 auto;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  position: relative;
}
.msgs {
  list-style: none; max-width: 840px; margin: 0 auto;
  padding: 16px 12px 20px;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-orient: vertical; -webkit-flex-direction: column; flex-direction: column;
}
.msgs > li { -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }

/* 消息气泡 (Telegram 风格)
   结构: <li.msg-item[.msg-gap]> > .msg-row[.msg-them|.msg-mine] > .bubble-box (无头像)
   行间距必须作用于 li (兄弟节点); 分组连续消息(同发送者且<5分钟)以 .msg-gap 收紧 */
.msgs > li.msg-item { margin-top: 12px; }
.msgs > li.msg-item.msg-gap { margin-top: 3px; }
.msg-row {
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: end; -webkit-align-items: flex-end; align-items: flex-end;
}
/* 左右对齐作用于实际 flex 容器 .msg-row (JS 把 mine/them 类加在 rowEl 上) */
.msg-them { -webkit-box-pack: start; -webkit-justify-content: flex-start; justify-content: flex-start; }
.msg-mine { -webkit-box-pack: end; -webkit-justify-content: flex-end; justify-content: flex-end; }

/* 无头像布局; 为气泡右侧常显复制按钮预留宽度, 防长消息溢出 */
.bubble-box { min-width: 0; max-width: 100%; }
/* 自己消息: margin-left:auto 双保险右对齐 (即使 justify 异常也被顶到最右) */
.msg-mine .bubble-box { margin-left: auto; }
/* 他人消息需为右侧复制按钮预留宽度 */
.msg-them .bubble-box { margin-right: 0; max-width: -webkit-calc(100% - 34px); max-width: calc(100% - 34px); }
.msg-mine .bubble-box { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: vertical; -webkit-flex-direction: column; flex-direction: column; -webkit-box-align: end; -webkit-align-items: flex-end; align-items: flex-end; }
.msg-them .bubble-box { display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: vertical; -webkit-flex-direction: column; flex-direction: column; -webkit-box-align: start; -webkit-align-items: flex-start; align-items: flex-start; }
.msg-them .sender {
  font-size: 12px; font-weight: 700; color: #0B6E69;
  margin: 0 0 2px 2px;
}
/* 分组后续行不重复显示昵称 */
.msg-row.grouped .sender { display: none; }

.bubble {
  display: inline-block; position: relative;
  padding: 7px 11px 6px;
  border-radius: 16px;
  font-size: 13px; line-height: 1.45; color: #0F172A;
  white-space: pre-wrap; word-break: break-word;
  max-width: 100%;
}
.msg-mine .bubble {
  background: #EFFDDE;
  color: #444444;
  border-top-right-radius: 6px;
}
.msg-them .bubble {
  background: #FFFFFF; border: 1px solid #E0EBE9;
  border-top-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(15, 118, 110, 0.06);
}
/* 正文独立一行 */
.bubble .msg-c { display: block; min-width: 0; }
/* 时间: 气泡内右下角, 独立一行(不与正文同行), 常规文档流, 不可能被正文遮挡 */
.bubble .msg-t {
  display: block;
  text-align: right;
  font-size: 10px;
  line-height: 1.3;
  margin-top: 3px;
  white-space: nowrap;
  -webkit-user-select: none; -moz-user-select: none; user-select: none;
}
.msg-them .msg-t { color: #A0ACB6; }
.msg-mine .msg-t { color: #86C2A6; }

/* 复制按钮: 常显, 位于气泡右侧外面 */
.copy-btn {
  border: none; cursor: pointer;
  color: #0B6E69;
  width: 25px; height: 25px; margin: 0 0 0 4px;
  -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center;
  border-radius: 8px;
  background: rgba(15, 118, 110, 0.07);
  -webkit-transition: background .12s;
  transition: background .12s;
}
.copy-btn svg { width: 15px; height: 15px; display: block; }
.copy-btn:hover { background: rgba(15, 118, 110, 0.16); }
.copy-btn:active { background: rgba(15, 118, 110, 0.22); }

/* 日期分隔 */
.day-chip {
  -webkit-align-self: center; align-self: center;
  margin: 14px 0 10px; padding: 3px 14px;
  background: rgba(15, 118, 110, 0.1); color: #115E59;
  font-size: 13px; font-weight: 600; border-radius: 999px;
}

/* 空状态 */
.empty-hint {
  position: absolute; left: 0; right: 0; top: 34%;
  text-align: center; color: #5A6B7A;
}
.empty-hint svg { width: 44px; height: 44px; opacity: .5; margin-bottom: 8px; }
.empty-hint p { font-size: 15px; line-height: 1.8; }

/* 底部输入区 */
.composer {
  -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid #DCE7E5;
  padding: 8px 12px 10px; /* 旧内核回退(先声明) */
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); /* 支持安全区时覆盖 */
  z-index: 5;
}
.composer-inner {
  max-width: 840px; margin: 0 auto;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: end; -webkit-align-items: flex-end; align-items: flex-end;
  gap: 8px;
}
.composer-btn {
  width: 46px; height: 46px; -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto;
  border: none; border-radius: 50%; cursor: pointer;
  background: #E6F2F0; color: #0B6E69;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center;
}
.composer-btn:active { background: #D6E9E6; }
#in-msg {
  -webkit-box-flex: 1; -webkit-flex: 1 1 auto; flex: 1 1 auto;
  min-height: 46px; max-height: 130px;
  resize: none; overflow-y: auto;
  padding: 12px 14px;
  font: inherit; font-size: 16px; line-height: 1.4; color: #0F172A;
  background: #F2F7F6; border: 1.5px solid #C9DAD7; border-radius: 18px;
  outline: none;
}
#in-msg:focus { border-color: #0F766E; background: #FFFFFF; }
.send-btn {
  width: 46px; height: 46px; -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto;
  border: none; border-radius: 50%; cursor: pointer;
  background: -webkit-linear-gradient(135deg, #0F766E, #115E59);
  background: linear-gradient(135deg, #0F766E, #115E59);
  color: #FFFFFF; box-shadow: 0 6px 14px -6px rgba(15, 118, 110, 0.9);
}
.composer-note {
  max-width: 840px; margin: 4px auto 0; text-align: center;
  font-size: 12px; color: #5A6B7A;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%;
  bottom: 96px; /* 旧内核回退(先声明) */
  bottom: calc(90px + env(safe-area-inset-bottom)); /* 支持安全区时覆盖 */
  -webkit-transform: translateX(-50%); transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92); color: #FFFFFF;
  padding: 10px 18px; border-radius: 12px;
  font-size: 15px; z-index: 60;
  -webkit-animation: toastIn .18s ease-out;
  animation: toastIn .18s ease-out;
  max-width: 86vw; text-align: center;
}
@-webkit-keyframes toastIn { from { opacity: 0; -webkit-transform: translate(-50%, 8px); } to { opacity: 1; -webkit-transform: translate(-50%, 0); } }
@keyframes toastIn    { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  width: 100%; max-width: 360px;
  background: #FFFFFF; border-radius: 18px;
  padding: 20px 18px 16px;
  box-shadow: 0 24px 60px -20px rgba(15, 23, 42, 0.5);
}
.modal-card h3 { font-size: 17px; color: #0F172A; margin-bottom: 6px; }
.modal-desc { font-size: 14px; color: #475569; margin-bottom: 10px; }
.modal-card textarea {
  width: 100%; min-height: 76px; padding: 10px 12px;
  font: inherit; font-size: 16px; color: #0F172A;
  border: 1.5px solid #C9DAD7; border-radius: 12px; resize: vertical;
  outline: none; background: #FFFFFF;
}
.modal-card textarea:focus { border-color: #0F766E; }
.modal-actions {
  margin-top: 14px;
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-pack: end; -webkit-justify-content: flex-end; justify-content: flex-end;
  gap: 10px;
}
/* 弹层内按钮改为自适应宽度 (全局 .btn-primary 默认 100%) */
.modal-actions .btn-primary,
.modal-actions .btn-ghost { width: auto; padding: 0 22px; }

/* ---------- 安装到桌面引导 ---------- */
.install-head {
  display: -webkit-box; display: -webkit-flex; display: flex;
  -webkit-box-align: center; -webkit-align-items: center; align-items: center;
  gap: 12px; margin-bottom: 10px;
}
.install-logo { width: 52px; height: 52px; border-radius: 12px; -webkit-box-flex: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }
.install-head h3 { margin: 0 0 3px; font-size: 17px; color: #0F172A; }
.install-head .modal-desc { margin: 0; }
.install-steps {
  margin: 6px 0 2px 20px; padding: 0;
  color: #0F172A; font-size: 15px; line-height: 1.9;
}
.install-steps li::marker { color: #0F766E; font-weight: 700; }

/* ---------- 响应式: 桌面端留出更宽裕的气泡上限 ---------- */
@media (min-width: 720px) {
  .bubble-box { max-width: 66%; }
}
@media (max-width: 420px) {
  .login-card { padding: 26px 20px 22px; border-radius: 20px; }
  .login-logo { width: 76px; height: 76px; }
}
