:root{
  --navy:#0f172a;
  --navy-2:#17233d;
  --accent:#10b981;
  --accent-dark:#059669;
  --bg:#f4f6f8;
  --card:#ffffff;
  --text:#111827;
  --muted:#8b95a5;
  --line:#edf0f4;
  --danger:#e5484d;
  --safe-top:env(safe-area-inset-top,0px);
  --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,"PingFang SC","Helvetica Neue","Microsoft YaHei",sans-serif;
  background:var(--bg);color:var(--text);
  -webkit-font-smoothing:antialiased;overscroll-behavior:none;
}
button{font-family:inherit;}
.hidden{display:none !important;}

.view{position:fixed;inset:0;display:flex;flex-direction:column;background:var(--bg);}

/* ---------- 登录 ---------- */
#loginView{
  background:radial-gradient(120% 90% at 50% 0%,#1e3a5f 0%,#0f172a 55%,#0a1120 100%);
  align-items:center;justify-content:center;padding:24px;
}
.login-wrap{width:100%;max-width:380px;margin-top:calc(var(--safe-top) * -1);}
.brand{text-align:center;margin-bottom:26px;color:#fff;}
.brand-logo{
  width:72px;height:72px;margin:0 auto 14px;border-radius:22px;
  display:flex;align-items:center;justify-content:center;color:#fff;
  background:linear-gradient(145deg,#10b981,#0ea5e9);
  box-shadow:0 12px 30px rgba(16,185,129,.35);
}
.brand h1{font-size:24px;margin:0 0 6px;letter-spacing:1px;font-weight:600;}
.brand p{margin:0;color:rgba(255,255,255,.55);font-size:13px;}
.login-form{
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.09);
  backdrop-filter:blur(12px);
  border-radius:18px;padding:22px 20px 18px;
}
.field{display:block;margin-bottom:14px;}
.field span{display:block;color:rgba(255,255,255,.6);font-size:12px;margin-bottom:7px;}
.field input{
  width:100%;height:46px;border-radius:11px;border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.08);color:#fff;padding:0 14px;font-size:15px;outline:none;
  transition:border-color .2s,background .2s;
}
.field input::placeholder{color:rgba(255,255,255,.32);}
.field input:focus{border-color:rgba(16,185,129,.7);background:rgba(255,255,255,.12);}
.primary-btn{
  width:100%;height:48px;margin-top:6px;border:none;border-radius:12px;
  background:linear-gradient(135deg,#10b981,#0ea5e9);color:#fff;font-size:16px;font-weight:600;
  letter-spacing:2px;cursor:pointer;transition:transform .12s,opacity .2s;
}
.primary-btn:active{transform:scale(.985);}
.primary-btn:disabled{opacity:.6;}
.login-error{min-height:18px;color:#ffb4b4;font-size:12.5px;margin:2px 0 10px;}
.login-tip{text-align:center;color:rgba(255,255,255,.4);font-size:12px;margin:14px 0 0;}
.version{position:absolute;bottom:calc(16px + var(--safe-bottom));color:rgba(255,255,255,.24);font-size:11px;margin:0;}

/* ---------- 顶栏 ---------- */
.topbar{
  flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;
  background:var(--navy);color:#fff;
  padding:calc(10px + var(--safe-top)) 14px 12px;
}
.topbar-left{display:flex;align-items:baseline;gap:9px;}
.topbar-left h1{font-size:19px;margin:0;font-weight:600;letter-spacing:.5px;}
.conn-state{font-size:11px;color:rgba(255,255,255,.45);}
.conn-state.online{color:#34d399;}
.conn-state.offline{color:#f87171;}
.topbar-right{display:flex;align-items:center;gap:4px;}
.icon-btn{
  position:relative;width:38px;height:38px;border:none;border-radius:10px;background:transparent;
  color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;
}
.icon-btn:active{background:rgba(255,255,255,.08);}
.dot{position:absolute;top:8px;right:8px;width:7px;height:7px;border-radius:50%;background:#f59e0b;display:none;}
.dot.show{display:block;}

.notify-banner{
  flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;gap:10px;
  background:#fff8e6;color:#8a6100;font-size:12.5px;padding:9px 14px;border-bottom:1px solid #f6e7bd;
}
.notify-banner button{
  border:none;background:#f59e0b;color:#fff;font-size:12px;padding:5px 12px;border-radius:14px;
}

/* ---------- 会话列表 ---------- */
.conv-list{flex:1 1 auto;overflow-y:auto;-webkit-overflow-scrolling:touch;}
.conv-item{
  display:flex;align-items:center;gap:12px;padding:13px 14px;background:var(--card);
  border-bottom:1px solid var(--line);cursor:pointer;transition:background .15s;
}
.conv-item:active{background:#f7f8fa;}
.conv-item.unread{background:#fffafa;}
.avatar{
  flex:0 0 auto;width:46px;height:46px;border-radius:50%;overflow:hidden;background:#e6e9ee;
  display:flex;align-items:center;justify-content:center;color:#9aa4b2;font-size:16px;font-weight:600;
}
.avatar img{width:100%;height:100%;object-fit:cover;display:block;}
.conv-main{flex:1 1 auto;min-width:0;}
.conv-top{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:4px;}
.conv-name{font-size:15px;font-weight:600;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.conv-time{flex:0 0 auto;font-size:11.5px;color:var(--muted);}
.conv-bottom{display:flex;align-items:center;justify-content:space-between;gap:8px;}
.conv-preview{
  font-size:13px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  max-width:100%;
}
.badge{
  flex:0 0 auto;min-width:19px;height:19px;padding:0 6px;border-radius:10px;background:var(--danger);
  color:#fff;font-size:11px;line-height:19px;text-align:center;font-weight:600;
}
.empty{padding:80px 20px;text-align:center;color:#aab2bf;font-size:13.5px;line-height:1.8;}

/* ---------- 聊天 ---------- */
.chat-topbar{justify-content:flex-start;gap:8px;}
.chat-title{flex:1 1 auto;min-width:0;text-align:center;}
.chat-title h2{font-size:16px;margin:0;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.chat-title span{font-size:11px;color:rgba(255,255,255,.45);}
.chat-avatar{width:34px;height:34px;border-radius:50%;overflow:hidden;background:rgba(255,255,255,.12);}
.chat-avatar img{width:100%;height:100%;object-fit:cover;display:block;}

.msg-list{
  flex:1 1 auto;overflow-y:auto;-webkit-overflow-scrolling:touch;
  padding:14px 12px 10px;background:var(--bg);
}
.msg-loading{text-align:center;color:#aab2bf;font-size:12.5px;padding:30px 0;}
.msg-row{display:flex;margin-bottom:14px;align-items:flex-end;gap:8px;}
.msg-row.me{flex-direction:row-reverse;}
.msg-bubble{
  max-width:76%;padding:9px 12px;border-radius:14px;font-size:14.5px;line-height:1.5;
  word-break:break-word;white-space:pre-wrap;background:#fff;color:var(--text);
  box-shadow:0 1px 2px rgba(15,23,42,.05);
}
.msg-row.me .msg-bubble{
  background:linear-gradient(135deg,#10b981,#0fa968);color:#fff;border-bottom-right-radius:5px;
}
.msg-row:not(.me) .msg-bubble{border-bottom-left-radius:5px;}
.msg-bubble img{max-width:170px;border-radius:9px;display:block;}
.msg-time{font-size:10.5px;color:#b3bac6;text-align:center;margin:0 0 12px;}
.msg-day{font-size:11px;color:#9aa4b2;text-align:center;margin:4px 0 14px;}
.msg-avatar{width:30px;height:30px;border-radius:50%;overflow:hidden;background:#e6e9ee;flex:0 0 auto;}
.msg-avatar img{width:100%;height:100%;object-fit:cover;}

.composer{
  flex:0 0 auto;display:flex;align-items:flex-end;gap:9px;
  padding:9px 12px calc(9px + var(--safe-bottom));
  background:#fff;border-top:1px solid var(--line);
}
.composer textarea{
  flex:1 1 auto;resize:none;border:none;outline:none;background:#f2f4f7;border-radius:19px;
  padding:10px 14px;font-size:14.5px;line-height:20px;max-height:110px;min-height:40px;
  font-family:inherit;color:var(--text);
}
.send-btn{
  flex:0 0 auto;width:40px;height:40px;border-radius:50%;border:none;color:#fff;
  background:linear-gradient(135deg,#10b981,#0ea5e9);display:flex;align-items:center;justify-content:center;
  transition:opacity .2s,transform .12s;
}
.send-btn:disabled{opacity:.45;}
.send-btn:active{transform:scale(.94);}

/* ---------- toast ---------- */
.toast{
  position:fixed;left:50%;bottom:calc(80px + var(--safe-bottom));transform:translate(-50%,10px);
  background:rgba(15,23,42,.92);color:#fff;font-size:13px;padding:10px 18px;border-radius:22px;
  opacity:0;pointer-events:none;transition:opacity .22s,transform .22s;z-index:99;max-width:80%;text-align:center;
}
.toast.show{opacity:1;transform:translate(-50%,0);}

.img-btn{flex:0 0 auto;width:40px;height:40px;border-radius:50%;border:none;background:#f2f4f7;
  color:#64748b;display:flex;align-items:center;justify-content:center;padding:0;}
.img-btn:active{background:#e6eaf0;}
.msg-bubble img{cursor:zoom-in;}

/* brand logo image */
.brand-logo{background:#fff;overflow:hidden;}
.brand-logo img{width:100%;height:100%;object-fit:cover;display:block;}

/* 撤回：长按自己的消息不触发文字选择 */
.msg-row.me{-webkit-touch-callout:none;}
