* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #ededed;
  color: #222;
}
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 540px;
  margin: 0 auto;
  background: #ededed;
}
.hd {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #3a8ffe;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}
.hd-title { font-size: 17px; font-weight: 600; }
.hd-status { display: flex; align-items: center; font-size: 13px; opacity: .95; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: #38d35a; }
.dot.off { background: #ff5a5a; }

.reconnect {
  background: #ffe9a8;
  color: #8a6d00;
  font-size: 13px;
  text-align: center;
  padding: 6px;
}

.msgs {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 10px;
}
.row { display: flex; margin: 10px 0; align-items: flex-end; }
.row.me { flex-direction: row-reverse; }
.avatar {
  width: 36px; height: 36px; border-radius: 6px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #fff;
}
.row.me .avatar { background: #3a8ffe; }
.row.peer .avatar { background: #9b9b9b; }
.bubble {
  max-width: 72%;
  margin: 0 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  background: #fff;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}
.row.me .bubble { background: #95ec69; }
.bubble img { max-width: 100%; border-radius: 6px; display: block; }
.bubble .flag { color: #c0392b; font-size: 12px; }

.typing { flex: 0 0 auto; padding: 0 14px 6px; color: #999; font-size: 12px; min-height: 16px; }

.ft {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: #f7f7f7;
  border-top: 1px solid #ddd;
}
.img-btn {
  flex: 0 0 auto;
  height: 38px; padding: 0 10px;
  border: 1px solid #ccc; border-radius: 6px;
  background: #fff; font-size: 14px; color: #555;
}
#input {
  flex: 1 1 auto;
  resize: none;
  max-height: 96px;
  border: 1px solid #ccc; border-radius: 6px;
  padding: 9px 10px; font-size: 15px; line-height: 1.3;
  font-family: inherit;
  outline: none;
}
.send-btn {
  flex: 0 0 auto;
  height: 38px; padding: 0 16px;
  border: none; border-radius: 6px;
  background: #3a8ffe; color: #fff; font-size: 15px;
}

.mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.card {
  width: 80%; max-width: 320px;
  background: #fff; border-radius: 12px; padding: 20px 18px;
  text-align: center;
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; }
.card input {
  width: 100%; padding: 10px; font-size: 15px;
  border: 1px solid #ccc; border-radius: 8px; margin-bottom: 14px;
  box-sizing: border-box;
}
.card button {
  width: 100%; padding: 11px; font-size: 15px;
  border: none; border-radius: 8px; background: #3a8ffe; color: #fff;
}

/* ---------- 图片灯箱：全屏预览，点击放大 / 关闭 ---------- */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: none;
  align-items: center; justify-content: center;
  padding: 16px;
  z-index: 100;
  -webkit-tap-highlight-color: transparent;
}
.lightbox.show { display: flex; }
.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 6px;
  -webkit-user-select: none; user-select: none;
}
.lightbox-close {
  position: fixed; top: 14px; right: 18px;
  width: 38px; height: 38px; line-height: 38px;
  text-align: center;
  color: #fff; font-size: 24px;
  background: rgba(255,255,255,.18);
  border-radius: 50%;
  z-index: 101;
}
