:root {
  --chat-bg: #f2f3f5;
  --panel: #ffffff;
  --line: #e7e9ec;
  --text: #14181d;
  --sub: #98a1aa;
  --me-bubble: #b6d8f8;
  --me-text: #0f2338;
  --other-bubble: #ffffff;
  --brand: #4c8fd6;
  --danger: #e0574d;
  --avatar-yao-a: #8fbbf2;
  --avatar-yao-b: #4a86d8;
  --avatar-lin-a: #f7b0c4;
  --avatar-lin-b: #e0688d;
}

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

/* 关键：让 hidden 属性始终生效（否则 .screen{display:flex} 会盖掉它） */
[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", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--chat-bg);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

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

.login-screen {
  background: linear-gradient(170deg, #eef4fc 0%, #f7f8fa 45%, #fdf3f6 100%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  padding: 30px 24px 22px;
  box-shadow: 0 18px 44px rgba(35, 62, 100, 0.12);
  text-align: center;
}

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

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  flex: 0 0 auto;
  user-select: none;
  box-shadow: 0 2px 6px rgba(40, 60, 90, 0.14);
}

.avatar-yao { background: linear-gradient(145deg, var(--avatar-yao-a), var(--avatar-yao-b)); }
.avatar-lin { background: linear-gradient(145deg, var(--avatar-lin-a), var(--avatar-lin-b)); }

.brand-heart {
  color: #e2748f;
  font-size: 15px;
  animation: beat 2.4s ease-in-out infinite;
}

@keyframes beat {
  0%, 100% { transform: scale(1); opacity: .75; }
  50% { transform: scale(1.22); opacity: 1; }
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 2px;
}

.login-sub {
  margin: 8px 0 22px;
  font-size: 13px;
  color: var(--sub);
  letter-spacing: .5px;
}

.field { margin-bottom: 12px; }

.field input {
  width: 100%;
  height: 46px;
  border: 1px solid #e3e7ec;
  background: #fbfcfd;
  border-radius: 13px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color .18s, box-shadow .18s, background .18s;
}

.field input::placeholder { color: #b3bac2; }

.field input:focus {
  border-color: #a9c9ec;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(76, 143, 214, 0.12);
}

.primary-btn {
  width: 100%;
  height: 46px;
  margin-top: 6px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(135deg, #5b9ae0, #3f7fc9);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(63, 127, 201, 0.28);
  transition: transform .1s, opacity .2s;
}

.primary-btn:active { transform: scale(.985); }
.primary-btn:disabled { opacity: .6; box-shadow: none; }
.primary-btn.small { width: auto; height: 38px; padding: 0 18px; font-size: 15px; margin: 0; border-radius: 10px; }

.login-error {
  margin: 2px 2px 10px;
  font-size: 13px;
  color: var(--danger);
  text-align: left;
}

.login-tips {
  margin: 18px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: #a8b0b8;
}

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: #59636d;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
}

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

.title-block {
  flex: 1;
  min-width: 0;
  text-align: center;
  line-height: 1.15;
}

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

.title-status {
  margin-top: 2px;
  font-size: 11px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title-status.typing { color: #6f9fd0; }
.title-status.offline { color: #b8bfc6; }

/* ---------------------------------------------------------------- 消息 */

.scroll-area {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px 14px;
  background: var(--chat-bg);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100%;
  justify-content: flex-end;
}

.time-sep {
  align-self: center;
  font-size: 12px;
  color: #a5adb5;
  padding: 2px 0 0;
  letter-spacing: .3px;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: rowIn .18s ease-out;
}

.row.me { flex-direction: row-reverse; }

@keyframes rowIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: calc(100% - 58px);
  min-width: 0;
}

.row.me .bubble-wrap { align-items: flex-end; }

.bubble {
  position: relative;
  padding: 9px 12px;
  border-radius: 13px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 1px rgba(20, 30, 45, 0.05);
  user-select: text;
}

.row.other .bubble {
  background: var(--other-bubble);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

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

.bubble a { color: #2f6fae; }

.meta {
  margin-top: 4px;
  padding: 0 2px;
  font-size: 11px;
  color: #a8b0b7;
  letter-spacing: .3px;
}

.meta.is-unread { color: #c2c8ce; }

.empty-state {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  text-align: center;
  color: #b7bec5;
  font-size: 14px;
  line-height: 1.7;
  pointer-events: none;
}

.empty-heart {
  font-size: 30px;
  color: #f0c3cf;
  margin-bottom: 8px;
}

.jump-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(72px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: rgba(255, 255, 255, 0.96);
  color: var(--brand);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(40, 60, 90, 0.14);
  font-family: inherit;
  z-index: 6;
}

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

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  position: relative;
  z-index: 7;
}

.composer-icon { flex: 0 0 auto; padding: 6px; }

.input-shell {
  flex: 1 1 auto;
  min-width: 0;
  background: #f2f3f5;
  border-radius: 18px;
  padding: 6px 12px;
  transition: background .18s;
}

.input-shell:focus-within { background: #eef0f3; }

.input-shell textarea {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.42;
  max-height: 108px;
  padding: 4px 0;
  color: var(--text);
}

.input-shell textarea::placeholder { color: #b3bac2; }

.send-btn {
  flex: 0 0 auto;
  height: 34px;
  margin: 0 2px 3px;
  padding: 0 15px;
  border: 0;
  border-radius: 17px;
  background: linear-gradient(135deg, #5b9ae0, #3f7fc9);
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .18s, transform .1s;
}

.send-btn:disabled {
  background: #d2d9e0;
  color: #fff;
  cursor: default;
}

.send-btn:active:not(:disabled) { transform: scale(.97); }

/* ---------------------------------------------------------------- 表情 */

.emoji-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(56px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  z-index: 8;
  box-shadow: 0 -6px 18px rgba(40, 60, 90, 0.07);
  max-height: 42vh;
  overflow-y: auto;
}

.emoji-panel button {
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  padding: 6px 0;
  border-radius: 8px;
  cursor: pointer;
}

.emoji-panel button:active { background: #f0f2f4; }

/* ---------------------------------------------------------------- 弹层 */

.sheet-mask, .dialog-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 22, 30, 0.38);
  z-index: 20;
  animation: fadeIn .16s ease-out;
}

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

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  background: #f7f8fa;
  border-radius: 16px 16px 0 0;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: sheetUp .2s ease-out;
}

@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

.sheet-item {
  border: 0;
  background: #fff;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  padding: 14px 12px;
  border-radius: 11px;
  cursor: pointer;
}

.sheet-item:active { background: #f0f2f4; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { margin-top: 4px; color: var(--sub); }

.sheet-version {
  text-align: center;
  font-size: 11px;
  color: #b3bac2;
  padding: 4px 0 2px;
}

.dialog-mask {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 30;
}

.dialog {
  width: 100%;
  max-width: 330px;
  background: #fff;
  border-radius: 18px;
  padding: 22px 20px 18px;
  box-shadow: 0 20px 50px rgba(20, 30, 45, 0.22);
}

.dialog h2 {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

.dialog-hint {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.7;
  color: #98a1aa;
  text-align: left;
}

.dialog .field input { height: 42px; font-size: 15px; border-radius: 11px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.ghost-btn {
  border: 0;
  background: transparent;
  color: var(--sub);
  font-size: 15px;
  font-family: inherit;
  padding: 8px 10px;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(28, 34, 42, 0.9);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  z-index: 40;
  max-width: 78vw;
  text-align: center;
  animation: fadeIn .15s ease-out;
}

/* ---------------------------------------------------------------- 图片消息 */

.bubble.image {
  padding: 0;
  background: transparent;
  box-shadow: none;
  line-height: 0;
  overflow: hidden;
  border-radius: 12px;
}

.row.me .bubble.image { background: transparent; }

.bubble.image img {
  display: block;
  max-width: min(58vw, 210px);
  max-height: 280px;
  width: auto;
  height: auto;
  border-radius: 12px;
  background: #eef0f2;
  cursor: zoom-in;
  box-shadow: 0 1px 2px rgba(20, 30, 45, .08);
}

.bubble.image.uploading img { opacity: .55; }

.bubble.image .uploading-tip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
  background: rgba(20, 28, 38, .35);
  border-radius: 10px;
  line-height: 1;
}

.bubble.image img.loading {
  background: linear-gradient(100deg, #eceff3 30%, #f6f8fa 50%, #eceff3 70%);
  background-size: 200% 100%;
  animation: shimmer 1.1s ease-in-out infinite;
  min-width: 90px;
  min-height: 90px;
}

@keyframes shimmer {
  from { background-position: 150% 0; }
  to { background-position: -50% 0; }
}

.bubble.image.broken {
  min-width: 160px;
  min-height: 100px;
  background: #eef0f3;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #cfd6dd;
}

.broken-tip {
  font-size: 12px;
  line-height: 1.6;
  color: #98a1aa;
  text-align: center;
  white-space: pre-line;
  padding: 16px 14px;
}

.bubble.image { position: relative; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 10, 14, .95);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .15s ease-out;
}

.lightbox img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 14px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

/* 桌面浏览器：居中一个手机大小的框，别铺满全屏 */
@media (min-width: 720px) {
  body { background: #e8ebef; }
  .screen {
    position: relative;
    margin: 0 auto;
    height: 100vh;
    max-width: 460px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 24px 60px rgba(30, 45, 70, 0.16);
    background: var(--chat-bg);
  }
  .login-screen { max-width: none; box-shadow: none; background: linear-gradient(170deg, #eef4fc 0%, #f7f8fa 45%, #fdf3f6 100%); }
  .sheet { max-width: 460px; left: 50%; transform: translateX(-50%); }
  @keyframes sheetUp { from { transform: translate(-50%, 100%); } to { transform: translateX(-50%); } }
}
