:root {
  --brand: #2b6cf6;
  --brand-dark: #1b52c9;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e6e8ec;
  --text: #16181d;
  --text-2: #6b7280;
  --text-3: #9aa1ac;
  --bubble-me: #2b6cf6;
  --bubble-me-text: #ffffff;
  --bubble-other: #ffffff;
  --bubble-other-text: #16181d;
  --danger: #e5484d;
  --ok: #12a150;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden 属性必须压过下面所有 display 声明 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 15px; }

/* ---------------- 登录 ---------------- */

.auth-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #eef3ff 0%, #f6f7f9 45%, #eef7f4 100%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 20px;
  padding: 32px 26px 26px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 26px;
}

.brand-logo {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -1px;
}

.brand-name {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: .5px;
}

.auth-tabs {
  display: flex;
  background: #f1f3f6;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 0;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  transition: all .15s;
}

.tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(16,24,40,.1);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: #fafbfc;
  transition: border-color .15s, background .15s;
}

.field input:focus {
  border-color: var(--brand);
  background: #fff;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
  transition: background .15s;
}

.btn-primary:active { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .6; }

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
}

.auth-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 4px;
  padding: 12px 0 2px;
  border-top: 1px solid var(--line);
  color: var(--brand);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity .15s;
}
.auth-download:hover { opacity: .78; }
.auth-download svg { flex: none; }
.auth-download em {
  font-style: normal;
  font-weight: 400;
  color: var(--text-3);
  font-size: 11.5px;
  margin-left: 2px;
}

/* ---------------- 主界面 ---------------- */

.app-screen {
  display: flex;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 320px;
  flex: 0 0 320px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.me { display: flex; align-items: center; gap: 10px; min-width: 0; }

.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4b8bfd, #2b6cf6);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  flex: 0 0 auto;
}

.avatar.sm { width: 34px; height: 34px; font-size: 13px; }

.me-info { min-width: 0; }
.me-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-sub { font-size: 12px; color: var(--text-3); }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--text-2);
  width: 34px; height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.icon-btn:active { background: #f1f3f6; }

.search-wrap { padding: 12px 16px 8px; }

.search-wrap input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f7f8fa;
  outline: none;
  font-size: 14px;
}

.search-wrap input:focus { border-color: var(--brand); background: #fff; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  -webkit-overflow-scrolling: touch;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.conv-item:active { background: #f4f6f9; }
.conv-item.active { background: #eef3fe; }

.conv-main { flex: 1; min-width: 0; }

.conv-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.conv-name {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time { font-size: 11.5px; color: var(--text-3); flex: 0 0 auto; }

.conv-last {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  padding: 0 5px;
  flex: 0 0 auto;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}

.foot-btn {
  width: 100%;
  padding: 10px;
  border: 1px dashed #cfd6e2;
  background: #fafbfd;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
}

.foot-btn:active { background: #eef3fe; }

/* ---------------- 聊天区 ---------------- */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  height: 100%;
}

.empty-state {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--text-3);
  gap: 10px;
}

.empty-art { font-size: 44px; opacity: .5; }

.chat-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.back-btn { display: none; }

.chat-peer { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.peer-name { font-weight: 600; font-size: 15px; }
.peer-sub { font-size: 12px; color: var(--text-3); }

.msg-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.msg-row {
  display: flex;
  gap: 8px;
  max-width: min(72%, 560px);
  align-items: flex-end;
}

.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.other { align-self: flex-start; }

.bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14.5px;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  box-shadow: 0 1px 1px rgba(16,24,40,.04);
}

.msg-row.mine .bubble {
  background: var(--bubble-me);
  color: var(--bubble-me-text);
  border-bottom-right-radius: 5px;
}

.msg-row.other .bubble {
  background: var(--bubble-other);
  color: var(--bubble-other-text);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--line);
}

.msg-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
  padding: 0 4px;
  text-align: right;
}

.msg-row.other .msg-meta { text-align: left; }

.addr {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: rgba(255,255,255,.18);
  border-radius: 6px;
  padding: 1px 5px;
  margin: 1px 1px;
  cursor: pointer;
  border-bottom: 1px dashed rgba(255,255,255,.5);
}

.msg-row.other .addr {
  background: #eef3fe;
  color: var(--brand-dark);
  border-bottom-color: #b9cdf9;
}

.msg-actions {
  display: flex;
  gap: 4px;
  opacity: .55;
}

.msg-action {
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 11.5px;
  padding: 3px 5px;
  border-radius: 6px;
  white-space: nowrap;
}

.msg-action:active { background: #e9ecf2; }

.day-sep {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-3);
  background: rgba(255,255,255,.7);
  padding: 3px 10px;
  border-radius: 10px;
  margin: 4px 0;
}

/* ---------------- 输入区 ---------------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px 15px;
  max-height: 120px;
  outline: none;
  background: #f7f8fa;
  line-height: 1.45;
  transition: border-color .15s, background .15s;
}

.composer textarea:focus { border-color: var(--brand); background: #fff; }

.btn-send {
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  transition: transform .1s, background .15s;
}

.btn-send:active { transform: scale(.94); background: var(--brand-dark); }
.btn-send:disabled { opacity: .5; }

/* ---------------- 弹窗 ---------------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .42);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  animation: fade .15s ease;
}

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
  width: 100%;
  max-width: 460px;
  max-height: 84vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(16,24,40,.24);
}

.modal h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.modal .modal-sub {
  font-size: 13px;
  color: var(--text-2);
  margin: 0 0 16px;
}

.modal-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.modal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #f7f8fa;
  cursor: pointer;
}

.modal-item:active { background: #eef3fe; }
.modal-item .nm { font-weight: 600; font-size: 14px; }
.modal-item .sb { font-size: 12px; color: var(--text-3); }
.modal-item .grow { flex: 1; min-width: 0; }

.modal input[type=text], .modal input[type=password], .modal textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #fafbfc;
  font-size: 14px;
}

.modal textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  min-height: 220px;
  line-height: 1.5;
  resize: vertical;
}

.modal label.fl { display: block; margin-bottom: 12px; }
.modal label.fl > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-ghost, .btn-solid {
  flex: 1;
  padding: 10px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.btn-solid {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-solid:active { background: var(--brand-dark); }

.qr-box {
  display: grid;
  place-items: center;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.qr-box img { width: 240px; height: 240px; display: block; }

.qr-addr {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-2);
  word-break: break-all;
  text-align: center;
  background: #f7f8fa;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
  cursor: pointer;
}

.hint {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.6;
  background: #f6f8fb;
  border-left: 3px solid #c3d4f7;
  padding: 9px 11px;
  border-radius: 6px;
  margin-bottom: 12px;
}

/* ---------------- 提示 ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: rgba(22, 24, 29, .9);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 20px;
  z-index: 90;
  animation: fade .15s ease;
  max-width: 80vw;
  text-align: center;
}

/* ---------------- 移动端 ---------------- */

@media (max-width: 760px) {
  .sidebar {
    width: 100%;
    flex: 1 1 100%;
    border-right: 0;
  }

  .app-screen.show-chat .sidebar { display: none; }
  .app-screen:not(.show-chat) .chat { display: none; }

  .chat { flex: 1 1 100%; }

  .back-btn { display: grid; }

  .msg-row { max-width: 86%; }

  .msg-scroll { padding: 14px 12px 6px; }
}

/* 地址替换表单 */
.rule-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.rule-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  outline: none;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.rule-row input:focus { border-color: var(--brand); background: #fff; }

.rule-arrow { color: var(--text-3); font-size: 13px; flex: 0 0 auto; }

.rule-del {
  border: 0;
  background: #f1f3f6;
  color: var(--text-2);
  width: 28px;
  height: 28px;
  border-radius: 7px;
  font-size: 16px;
  line-height: 1;
  flex: 0 0 auto;
}

.rule-del:active { background: #fde8e8; color: var(--danger); }


/* ---------------- 群聊 ---------------- */

.foot-row { display: flex; gap: 8px; }
.foot-row .foot-btn { flex: 1; }
.foot-row .foot-btn:last-child { flex: 0 0 86px; }

.avatar.grp {
  background: linear-gradient(135deg, #22c55e, #12a37a);
  font-size: 13px;
}

.msg-sender {
  font-size: 11.5px;
  color: var(--text-3);
  margin: 0 0 3px 2px;
}

.msg-row.other .msg-sender { text-align: left; }

.pick-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fafbfc;
}

.pick-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 14px;
}
.pick-row:active { background: #eef3fe; }
.pick-row input { width: 16px; height: 16px; flex: 0 0 auto; }

.member-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 9px;
  background: #f7f8fa;
}
.member-row .nm { font-size: 13.5px; font-weight: 600; }
.member-row .sb { font-size: 11.5px; color: var(--text-3); }

.sm-del {
  flex: 0 0 auto;
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 7px;
  color: #dc2626;
  border-color: #f3d0d0;
  background: #fff7f7;
}

.danger-text { color: #dc2626; border-color: #f3d0d0; background: #fff7f7; }

/* 兜底：hidden 属性必须真的隐藏，不被 display 规则覆盖 */
[hidden] { display: none !important; }
