/* ============================================
   NekoChat · 聊天界面重做
   干净的输入栏 + 规范的消息气泡
   ============================================ */

/* ---------- 聊天容器 ---------- */
.chat-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* 输入区固定高度变量，保证所有元素对齐 */
:root {
  --composer-h: 44px;
}

/* ============================================
   输入栏：微信风格
   ============================================ */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, .97);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* 工具按钮：圆形，与输入框等高 */
.composer-tools {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.tool-btn {
  width: var(--composer-h);
  height: var(--composer-h);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f2f7fd;
  border: 1px solid #e3eefb;
  color: #6b96bd;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, transform .12s ease;
  flex-shrink: 0;
}

.tool-btn .ico {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.tool-btn:active {
  background: #e2eefb;
  color: #3d8fd8;
  transform: scale(.93);
}

/* 输入框 */
#msgInput,
.composer textarea {
  flex: 1;
  min-width: 0;
  height: var(--composer-h);
  min-height: var(--composer-h);
  max-height: 120px;
  padding: 0 16px;
  border-radius: calc(var(--composer-h) / 2);
  background: #f4f8fd;
  border: 1.5px solid #e3eefb;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: calc(var(--composer-h) - 3px);
  outline: none;
  resize: none;
  overflow-y: auto;
  transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
  -webkit-appearance: none;
  box-sizing: border-box;
}

#msgInput::placeholder,
.composer textarea::placeholder {
  color: #9db4cc;
  font-size: 14.5px;
  line-height: inherit;
}

#msgInput:focus,
.composer textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(74, 163, 255, .13);
}

/* 发送按钮：与输入框等高，胶囊形 */
.btn-send,
.composer .btn-send {
  height: var(--composer-h);
  padding: 0 20px;
  border-radius: calc(var(--composer-h) / 2);
  background: linear-gradient(135deg, #4aa3ff, #2b7fe0);
  color: #fff;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: .3px;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .12s ease, box-shadow .18s ease, opacity .18s ease;
  box-shadow: 0 3px 12px rgba(43, 127, 224, .26);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send:active {
  transform: scale(.95);
}

.btn-send:disabled {
  opacity: .5;
  box-shadow: none;
}

/* ============================================
   消息列表
   ============================================ */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #f6fafe;
}

/* 单条消息 */
.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 100%;
  animation: msgIn .24s ease;
}

.msg.self {
  flex-direction: row-reverse;
}

/* 头像 */
.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #8fd0ff, #4aa3ff);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(74, 163, 255, .18);
  margin-top: 20px;   /* 与气泡顶部对齐（跳过 meta 行） */
}

/* 消息内容容器 */
.msg-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: min(70%, 560px);
}

.msg.self .msg-content {
  align-items: flex-end;
}

/* 昵称 + 时间 */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  padding: 0 4px;
  font-size: 12px;
  line-height: 1;
  height: 15px;
}

.msg.self .msg-meta {
  flex-direction: row-reverse;
}

.msg-nick {
  color: #5b7fa3;
  font-weight: 600;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-meta time,
.msg-meta .msg-time {
  color: #a3b8cc;
  font-size: 11px;
}

/* 气泡 */
.bubble {
  display: inline-block;
  padding: 10px 15px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #e6eff8;
  color: #123a63;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 2px 8px rgba(74, 163, 255, .07);
  border-top-left-radius: 5px;   /* 靠头像一侧收角 */
}

.msg.self .bubble {
  background: linear-gradient(135deg, #4aa3ff, #2b7fe0);
  border-color: transparent;
  color: #fff;
  border-top-left-radius: 16px;
  border-top-right-radius: 5px;
  box-shadow: 0 3px 14px rgba(43, 127, 224, .24);
}

/* 图片消息 */
.msg-image {
  max-width: min(280px, 62vw);
  border-radius: 14px;
  display: block;
  cursor: pointer;
  border: 1px solid #e6eff8;
  box-shadow: 0 2px 10px rgba(74, 163, 255, .1);
}

/* 系统消息 */
.msg-system {
  text-align: center;
  font-size: 12px;
  color: #9db4cc;
  padding: 2px 0;
  align-self: center;
}

.msg-system span {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(255, 255, 255, .8);
  border-radius: 999px;
  border: 1px solid #e9f2fa;
}

/* ============================================
   红包气泡
   ============================================ */
.rp {
  width: 220px;
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  background: linear-gradient(150deg, #ff6b6b, #e63946);
  box-shadow: 0 6px 18px rgba(230, 57, 70, .26);
  transition: transform .16s ease;
  position: relative;
}

.rp:active {
  transform: scale(.98);
}

/* ============================================
   桌面端调整
   ============================================ */
@media (min-width: 1024px) {
  :root {
    --composer-h: 46px;
  }

  .composer {
    padding: 14px 28px 14px;
  }

  .messages {
    padding: 24px 28px;
    gap: 18px;
  }

  .msg-content {
    max-width: min(62%, 620px);
  }
}

/* ============================================
   小屏手机
   ============================================ */
@media (max-width: 400px) {
  .btn-send,
  .composer .btn-send {
    padding: 0 16px;
    font-size: 14px;
  }

  .composer {
    gap: 6px;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom, 0px));
  }

  .composer-tools {
    gap: 4px;
  }

  .tool-btn {
    width: 40px;
    height: 40px;
  }

  :root {
    --composer-h: 42px;
  }
}
