/* ===================== 基础 ===================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --green-dark: #008069;
  --green-teal: #00a884;
  --green-bright: #25d366;
  --bg-app: #f0f2f5;
  --bg-chat: #efeae2;
  --bubble-out: #d9fdd3;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-meta: #8696a0;
  --tick-blue: #53bdeb;
  --header-bg: #f0f2f5;
}

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { border: none; background: none; cursor: pointer; padding: 0; }
a { color: var(--green-teal); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(0,0,0,.05); }
.icon-btn:active { background: rgba(0,0,0,.1); }

/* ===================== 登录页 ===================== */
#login-view {
  min-height: 100vh;
  background: #fbf5ec;
  display: flex;
  flex-direction: column;
}

.login-header { padding: 18px 0 0 40px; }

.wa-logo {
  height: 28px;
  width: auto;
  fill: #66d072;
  display: block;
}

.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 48px;
  min-height: 0;
}

.login-footer {
  width: 100%;
  padding-top: 48px;
}

/* 登录卡片 */
.login-card {
  width: 100%;
  max-width: 872px;
  margin-top: 18px;
  background: #fff;
  border: 1.5px solid #0b141a;
  border-radius: 18px;
  display: flex;
  padding: 72px 52px 48px;
  gap: 56px;
}

.login-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.login-left h1 {
  font-size: 23px;
  font-weight: 500;
  color: #111b21;
  margin-bottom: 34px;
}

.login-steps { list-style: none; }

.login-steps li {
  position: relative;
  display: flex;
  align-items: flex-start;
  padding-bottom: 26px;
}

.login-steps li:last-child { padding-bottom: 0; }

/* 圆圈间连接线 */
.login-steps li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 9.25px;
  top: 22px;
  bottom: 2px;
  width: 1.5px;
  background: #d0d5d7;
}

.login-steps li p {
  font-size: 17px;
  line-height: 1.5;
  color: #111b21;
}

.login-steps strong { font-weight: 600; }

.step-circle {
  flex: 0 0 20px;
  width: 20px; height: 20px;
  border: 1.5px solid #111b21;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 500;
  color: #111b21;
  margin: 2px 18px 0 0;
  background: #fff;
  position: relative;
  z-index: 1;
}

.inline-wa { vertical-align: -3px; }

.help-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  color: #1faa61;
  text-decoration: underline;
  margin: 22px 0 20px;
}
.help-link svg { text-decoration: none; }

.keep-signed {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: #3b4a54;
  cursor: pointer;
  user-select: none;
}

.keep-signed input { display: none; }

.keep-signed .info-icon { margin-left: 2px; cursor: pointer; }

.checkbox-box {
  width: 17px; height: 17px;
  border: 2px solid #8696a0;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
  flex: 0 0 auto;
}

.checkbox-box svg { opacity: 0; transform: scale(.4); transition: .15s; }

.keep-signed input:checked + .checkbox-box {
  background: #1faa61;
  border-color: #1faa61;
}

.keep-signed input:checked + .checkbox-box svg {
  opacity: 1;
  transform: scale(1);
}

.signup-line {
  margin-top: 0;
  text-align: center;
  font-size: 15px;
  color: #1d1f1f;
}

.signup-line a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #1faa61;
  font-weight: 500;
  text-decoration: underline;
  margin-left: 4px;
}

.footer-enc {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 32px;
  color: #667781;
  font-size: 15px;
}

.footer-terms {
  display: block;
  margin-top: 20px;
  text-align: center;
  color: #54656f;
  font-size: 14px;
  text-decoration: none;
}
.footer-terms:hover { text-decoration: underline; }

/* 二维码区域 */
.login-right {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.phone-link {
  margin-top: auto;
  padding-top: 18px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 15px;
  font-weight: 500;
  color: #1faa61;
}
.phone-link:hover { text-decoration: underline; }

/* 电话号码登录视图 */
.phone-login-view { margin-top: 24px; position: relative; }
.phone-login-inner {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  padding: 40px 24px;
  text-align: center;
}
.phone-login-inner h2 {
  font-size: 26px;
  font-weight: 500;
  color: #111b21;
  margin: 0 0 8px;
}
.phone-subtitle {
  font-size: 14px;
  color: #3b4a54;
  margin: 0 0 28px;
}
.country-select {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 48px;
  padding: 0 18px;
  border: 1px solid #d1d7db;
  border-radius: 24px;
  background: #fff;
  cursor: pointer;
  font-size: 15px;
  color: #111b21;
  margin-bottom: 12px;
  box-sizing: border-box;
}
.country-flag { font-size: 20px; }
.country-name { flex: 1; text-align: left; }
.country-caret { flex-shrink: 0; }
.country-dropdown {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  width: 100%;
  min-width: 100%;
  background: #fff;
  border: none;
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(11,20,26,.16);
  overflow: hidden;
  z-index: 60;
}
.country-search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 14px 8px;
  padding: 9px 14px;
  background: #f0f2f5;
  border-radius: 22px;
}
.country-search {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  background: transparent;
  color: #111b21;
}
.country-list {
  max-height: 480px;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.country-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  cursor: pointer;
  border-radius: 10px;
}
.country-item:hover { background: #f5f6f6; }
.country-item.active { background: #f0f2f5; }
.country-item-flag { font-size: 24px; width: 30px; text-align: center; }
.country-item-text { flex: 1; text-align: left; min-width: 0; }
.country-item-zh { font-size: 16px; font-weight: 500; color: #111b21; }
.country-item-en { font-size: 14px; color: #667781; }
.country-item-code { font-size: 15px; color: #667781; flex-shrink: 0; }
.country-item-check { color: #00a884; flex-shrink: 0; }
.phone-input-wrap {
  display: flex;
  align-items: center;
  width: 100%;
  height: 48px;
  border: 1px solid #d1d7db;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  box-sizing: border-box;
}
.phone-input-wrap:focus-within { border-color: #00a884; }
.phone-prefix {
  padding: 0 12px 0 14px;
  font-size: 15px;
  color: #111b21;
  border-right: 1px solid #e9edef;
}
.phone-input {
  flex: 1;
  border: none;
  outline: none;
  height: 100%;
  padding: 0 14px;
  font-size: 15px;
  color: #111b21;
  background: transparent;
}
.phone-next-btn {
  margin-top: 28px;
  height: 44px;
  padding: 0 36px;
  border: none;
  border-radius: 22px;
  background: #00a884;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.phone-next-btn:hover { background: #008f72; }
.phone-next-btn:disabled { background: #c8d0d3; cursor: not-allowed; }
.back-to-qr {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2px;
  width: 100%;
  margin-top: 24px;
  font-size: 14px;
  color: #00a884;
  text-decoration: none;
  cursor: pointer;
}
.back-to-qr:hover { text-decoration: underline; }

/* 配对码显示 */
.pair-title { font-size: 15px; color: #3b4a54; margin: 0 0 18px; }
.pair-digits {
  font-size: 40px;
  font-weight: 600;
  letter-spacing: 8px;
  color: #111b21;
  font-family: 'SF Mono', 'Menlo', monospace;
  margin-bottom: 24px;
}
.pair-tip { font-size: 13px; color: #667781; margin: 0 0 24px; line-height: 1.6; }
.back-to-phone-input {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: #00a884;
  text-decoration: none;
}
.back-to-phone-input:hover { text-decoration: underline; }

.qr-box {
  position: relative;
  width: 224px; height: 224px;
  cursor: pointer;
  overflow: hidden;
}

#qrcode {
  width: 224px; height: 224px;
  display: flex; align-items: center; justify-content: center;
}

#qrcode img, #qrcode canvas, #qrcode table { display: block; }

.qr-logo {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 52px; height: 52px;
  background: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}

.qr-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 2;
}

.qr-overlay p { font-size: 15px; color: var(--text-primary); }

.qr-refresh-btn {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: #00a884;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.qr-refresh-btn:hover { background: #06cf9c; }

.qr-scanned { background: rgba(255,255,255,.97); }

.scan-check {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: var(--green-bright);
  display: flex; align-items: center; justify-content: center;
  animation: pop .35s ease-out;
}

@keyframes pop {
  0% { transform: scale(.4); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ===================== 加载视图 ===================== */
#loading-view {
  height: 100vh;
  background: #fbf5ec;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

#loading-view p { color: var(--text-secondary); font-size: 14px; }

.loading-bar {
  width: 220px; height: 3px;
  background: #d2d8db;
  border-radius: 2px;
  overflow: hidden;
}

.loading-progress {
  height: 100%;
  width: 40%;
  background: var(--green-teal);
  border-radius: 2px;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

/* ===================== 聊天视图 ===================== */
#chat-view {
  height: 100vh;
  display: flex;
  overflow: hidden;
  position: relative;
  padding-top: 38px;
}

/* 顶部绿条（窗口足够高时可见） */
#chat-view::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 38px;
  background: var(--green-dark);
  z-index: 2;
}

@media (max-height: 800px) {
  #chat-view { padding-top: 0; }
  #chat-view::before { display: none; }
}

#sidebar {
  width: 30%;
  min-width: 300px;
  max-width: 460px;
  background: #fff;
  border-right: 1px solid #d1d7db;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

#main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  z-index: 1;
  background: var(--bg-chat);
}

/* 侧栏头部 */
.side-header {
  height: 60px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex: 0 0 auto;
}

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  flex: 0 0 auto;
  user-select: none;
}

.avatar.me { background: #6b7c85; }

.side-icons { display: flex; align-items: center; position: relative; }

.menu-dropdown {
  position: absolute;
  top: 46px; right: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(11,20,26,.16);
  width: 180px;
  padding: 6px 0;
  z-index: 30;
}

.menu-item {
  padding: 12px 20px;
  font-size: 14.5px;
  color: var(--text-primary);
  cursor: pointer;
}
.menu-item:hover { background: #f0f2f5; }

/* 搜索 */
.search-bar {
  padding: 8px 12px;
  background: #fff;
  flex: 0 0 auto;
}

.search-box {
  background: var(--header-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 38px;
  gap: 14px;
}

.search-box input {
  border: none;
  background: none;
  outline: none;
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

.search-box input::placeholder { color: var(--text-meta); }

/* 聊天列表 */
.chat-list {
  flex: 1;
  overflow-y: auto;
  background: #fff;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 10px 14px 10px 12px;
  cursor: pointer;
  gap: 12px;
  transition: background .12s;
}

.chat-item:hover { background: #f5f6f6; }
.chat-item.active { background: #f0f2f5; }

.chat-item .avatar { width: 49px; height: 49px; font-size: 19px; }

.chat-item-body {
  flex: 1;
  min-width: 0;
  border-top: 1px solid #e9edef;
  padding: 12px 0 10px;
}
.chat-item:first-child .chat-item-body { border-top: none; }

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.chat-item-name {
  font-size: 16px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time { font-size: 12px; color: var(--text-meta); flex: 0 0 auto; margin-left: 8px; }
.chat-item-time.unread { color: var(--green-teal); font-weight: 500; }

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-item-msg {
  font-size: 13.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.chat-item-msg .tick { vertical-align: -2px; margin-right: 2px; }

.unread-badge {
  flex: 0 0 auto;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  background: var(--green-bright);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
  margin-left: 8px;
}

.chat-list-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-meta);
  font-size: 14px;
}

/* 欢迎页 */
#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  background: #f8f9fa;
  border-bottom: 6px solid var(--green-bright);
  padding: 60px 40px 0;
}

.welcome-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: auto 0;
}

.welcome-illustration {
  width: 360px;
  max-width: 80%;
  border-radius: 16px;
  margin-bottom: 40px;
}

#welcome h1 {
  font-size: 32px;
  font-weight: 300;
  color: #41525d;
  margin-bottom: 18px;
}

#welcome p {
  font-size: 14.5px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.welcome-footer {
  padding: 22px 0;
  font-size: 13.5px;
  color: var(--text-meta);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 会话窗口 */
#conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.conv-header {
  height: 60px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  flex: 0 0 auto;
}

.conv-info { flex: 1; min-width: 0; cursor: pointer; }
.conv-name { font-size: 16px; color: var(--text-primary); }
.conv-status { font-size: 13px; color: var(--text-secondary); margin-top: 1px; }
.conv-status.typing { color: var(--green-teal); }

.conv-actions { display: flex; }

/* 消息区 */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-color: var(--bg-chat);
  background-image:
    radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px),
    radial-gradient(rgba(0,0,0,.025) 1px, transparent 1px);
  background-size: 28px 28px, 28px 28px;
  background-position: 0 0, 14px 14px;
}

.date-chip {
  align-self: center;
  background: #fff;
  color: var(--text-secondary);
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(11,20,26,.08);
  margin: 6px 0 12px;
}

.msg-row {
  display: flex;
  margin-bottom: 2px;
  animation: msgIn .18s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-row.me { justify-content: flex-end; }

.bubble {
  max-width: 62%;
  padding: 7px 9px 6px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.42;
  position: relative;
  box-shadow: 0 1px 1px rgba(11,20,26,.1);
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row:not(.me) .bubble { background: #fff; border-top-left-radius: 0; }
.msg-row.me .bubble { background: var(--bubble-out); border-top-right-radius: 0; }

/* 气泡小尾巴 */
.msg-row:not(.me) .bubble::before,
.msg-row.me .bubble::before {
  content: "";
  position: absolute;
  top: 0;
  width: 0; height: 0;
  border: 4px solid transparent;
}
.msg-row:not(.me) .bubble::before {
  left: -8px;
  border-top-color: #fff;
  border-right-color: #fff;
}
.msg-row.me .bubble::before {
  right: -8px;
  border-top-color: var(--bubble-out);
  border-left-color: var(--bubble-out);
}

.msg-meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-meta);
  margin: 8px 0 0 10px;
  position: relative;
  top: 4px;
}

/* 真实头像：覆盖在首字母色块上 */
.avatar { position: relative; overflow: hidden; }
.avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* 媒体消息 */
.bubble.media-only { padding: 3px; }
.msg-img { max-width: 320px; max-height: 320px; border-radius: 6px; display: block; }
.msg-video { max-width: 320px; max-height: 320px; border-radius: 6px; display: block; background: #000; }
.msg-sticker { width: 120px; display: block; background: transparent; }
.bubble:has(.msg-sticker) { background: transparent !important; box-shadow: none; }
.bubble:has(.msg-sticker)::before { display: none; }
.msg-audio { width: 260px; max-width: 60vw; display: block; height: 40px; }
.msg-doc {
  display: inline-flex; align-items: center; gap: 8px;
  color: inherit; text-decoration: none;
  background: rgba(0,0,0,.05); padding: 10px 12px; border-radius: 6px;
}
.msg-doc:hover { background: rgba(0,0,0,.09); }
.msg-caption { display: block; margin-top: 4px; white-space: pre-wrap; }

.tick { display: inline-flex; }
.tick svg { display: block; }
.tick.read svg { color: var(--tick-blue); }
.tick:not(.read) svg { color: var(--text-meta); }

/* 输入栏 */
.input-bar {
  min-height: 62px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  padding: 6px 16px;
  gap: 8px;
  flex: 0 0 auto;
  position: relative;
}

#msg-input {
  flex: 1;
  border: none;
  outline: none;
  background: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text-primary);
}

#msg-input::placeholder { color: var(--text-meta); }

.emoji-panel {
  position: absolute;
  bottom: 66px; left: 12px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(11,20,26,.18);
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  z-index: 20;
}

.emoji-panel span {
  font-size: 24px;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
}
.emoji-panel span:hover { background: #f0f2f5; }

/* Toast */
#toast {
  position: fixed;
  bottom: 30px; left: 50%;
  transform: translateX(-50%);
  background: #1f2c34;
  color: #e9edef;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  z-index: 100;
  animation: toastIn .2s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* 滚动条 */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(11,20,26,.2); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* 小屏适配 */
@media (max-width: 900px) {
  .login-header { padding-left: 24px; }
  .login-card { flex-direction: column; text-align: center; padding: 28px 24px; gap: 18px; }
  .login-card { flex-direction: column-reverse; align-items: center; padding: 36px 28px; gap: 36px; }
  .phone-link { margin-top: 0; }
  #sidebar { width: 100%; max-width: none; }
  #main-panel { display: none; }
}
