/* ===========================================
   残阳聊天站 - QQ聊天界面样式
   移动端优先，完整复刻QQ风格
   全设备比例通用适配
   =========================================== */

:root {
  --qq-blue: #12b7f5;
  --qq-blue-dark: #0ea8e0;
  --qq-bg: #f5f5f5;
  --qq-white: #ffffff;
  --qq-text: #333333;
  --qq-text-light: #888888;
  --qq-text-lighter: #b0b0b0;
  --qq-border: #e5e5e5;
  --qq-green: #07c160;
  --bubble-friend: #ffffff;
  --bubble-user: #12b7f5;
  --bubble-user-text: #ffffff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --header-height: 52px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  color: var(--qq-text);
  background: #e0e0e0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* ============ 主容器 ============ */
.app-container {
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--qq-bg);
  box-shadow: 0 0 30px rgba(0,0,0,0.15);
  position: relative;
  overflow: hidden;
}

@media (min-width: 501px) {
  .app-container {
    height: 100vh;
    height: 100dvh;
    border-left: 1px solid #ddd;
    border-right: 1px solid #ddd;
  }
}

/* ============ 头部信息栏 ============ */
.chat-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--qq-blue);
  display: flex;
  align-items: center;
  padding: 0 12px;
  padding-top: calc(0px + var(--safe-top));
  gap: 10px;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.header-back {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.9;
  transition: opacity 0.2s;
}

.header-back:hover { opacity: 1; }

.header-avatar-wrapper {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.6);
  cursor: pointer;
  position: relative;
  transition: transform 0.3s ease;
}

.header-avatar-wrapper:active { transform: scale(0.92); }

.header-avatar-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.header-avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  font-weight: bold;
  background: linear-gradient(135deg, #f093fb, #f5576c);
}

.header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.header-nickname {
  color: white;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 4px;
  transition: background 0.2s;
}

.header-nickname:hover { background: rgba(255,255,255,0.15); }

.header-status {
  color: rgba(255,255,255,0.85);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.header-btn:hover { background: rgba(255,255,255,0.35); }
.header-btn:active { background: rgba(255,255,255,0.45); }

/* ============ 聊天消息区域 ============ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
  background: var(--qq-bg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12);
  border-radius: 2px;
}
.chat-messages::-webkit-scrollbar-track { background: transparent; }

/* ============ 时间标签 ============ */
.time-divider {
  text-align: center;
  padding: 10px 0 6px;
  font-size: 12px;
  color: var(--qq-text-lighter);
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

/* ============ 系统消息 ============ */
.system-message {
  text-align: center;
  padding: 6px 0;
  font-size: 12px;
  color: var(--qq-text-lighter);
  flex-shrink: 0;
}

/* ============ 消息行 ============ */
.message-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
  animation: messageIn 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.message-row.friend { flex-direction: row; }
.message-row.user { flex-direction: row-reverse; }

@keyframes messageIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ 头像 ============ */
.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.message-avatar:active { transform: scale(0.9); }

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message-avatar .avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  font-weight: bold;
}

.message-avatar .avatar-fallback.friend-fb { background: linear-gradient(135deg, #667eea, #764ba2); }
.message-avatar .avatar-fallback.user-fb { background: linear-gradient(135deg, #43e97b, #38f9d7); }

/* ============ 消息气泡包装 ============ */
.message-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  min-width: 20px;
}

.message-row.friend .message-bubble-wrap { align-items: flex-start; }
.message-row.user .message-bubble-wrap { align-items: flex-end; }

/* ============ 消息气泡 ============ */
.message-bubble {
  padding: 10px 13px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
  position: relative;
  white-space: pre-wrap;
}

.message-row.friend .message-bubble {
  background: var(--bubble-friend);
  border-radius: 4px 16px 16px 16px;
  color: var(--qq-text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.message-row.user .message-bubble {
  background: var(--bubble-user);
  border-radius: 16px 4px 16px 16px;
  color: var(--bubble-user-text);
}

.message-row.friend .message-bubble::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 10px;
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 6px solid var(--bubble-friend);
}

.message-row.user .message-bubble::before {
  content: '';
  position: absolute;
  right: -6px;
  top: 10px;
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid var(--bubble-user);
}

/* ============ 消息时间 ============ */
.message-time {
  font-size: 10px;
  color: var(--qq-text-lighter);
  margin-top: 3px;
  padding: 0 4px;
}

/* ============ 输入中状态 ============ */
.typing-indicator {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 14px 8px;
  flex-shrink: 0;
  animation: fadeInUp 0.3s ease;
}

.typing-indicator .typing-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.typing-indicator .typing-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.typing-indicator .typing-avatar .avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  font-weight: bold;
  background: linear-gradient(135deg, #667eea, #764ba2);
}

.typing-bubble {
  background: var(--bubble-friend);
  border-radius: 4px 16px 16px 16px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  position: relative;
}

.typing-bubble::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 10px;
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 6px solid var(--bubble-friend);
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c0c0c0;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-8px); opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ 底部输入区域 ============ */
.chat-input-area {
  flex-shrink: 0;
  background: var(--qq-white);
  border-top: 1px solid var(--qq-border);
  padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
  z-index: 10;
}

.input-wrapper {
  flex: 1;
  min-width: 0;
  position: relative;
}

.chat-input {
  width: 100%;
  min-height: 36px;
  max-height: 120px;
  border: none;
  outline: none;
  background: #f5f5f5;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  font-family: inherit;
  color: var(--qq-text);
  transition: background 0.2s;
  -webkit-user-select: text;
  user-select: text;
}

.chat-input:focus { background: #eeeeee; }
.chat-input::placeholder { color: #c0c0c0; }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--qq-blue);
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.send-btn:hover { background: var(--qq-blue-dark); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled {
  background: #cccccc;
  cursor: not-allowed;
  opacity: 0.55;
}

/* ============ 欢迎区域 ============ */
.welcome-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 30px;
  text-align: center;
  overflow-y: auto;
}

.welcome-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  flex-shrink: 0;
}

.welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.welcome-nickname {
  font-size: 22px;
  font-weight: 600;
  color: var(--qq-text);
  margin-bottom: 6px;
}

.welcome-hint {
  font-size: 13px;
  color: var(--qq-text-light);
  margin-bottom: 20px;
}

.welcome-openers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 320px;
}

.welcome-opener-btn {
  padding: 8px 18px;
  border-radius: 18px;
  border: 1px solid var(--qq-border);
  background: var(--qq-white);
  color: var(--qq-text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.welcome-opener-btn:hover { background: var(--qq-blue); color: white; border-color: var(--qq-blue); }
.welcome-opener-btn:active { transform: scale(0.95); }

/* ============ 弹窗/遮罩 ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--qq-white);
  border-radius: 14px;
  width: 90%;
  max-width: 320px;
  overflow: hidden;
  animation: modalIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
  padding: 18px 20px 10px;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  color: var(--qq-text);
}

.modal-body { padding: 10px 20px 18px; }

.modal-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--qq-border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  text-align: center;
  font-family: inherit;
  transition: border-color 0.2s;
  -webkit-user-select: text;
  user-select: text;
}

.modal-input:focus { border-color: var(--qq-blue); }

.modal-actions {
  display: flex;
  border-top: 1px solid var(--qq-border);
}

.modal-btn {
  flex: 1;
  padding: 14px;
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
  color: var(--qq-text);
  -webkit-tap-highlight-color: transparent;
}

.modal-btn:hover { background: #f5f5f5; }
.modal-btn.confirm { color: var(--qq-blue); font-weight: 600; }
.modal-btn + .modal-btn { border-left: 1px solid var(--qq-border); }

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.78);
  color: white;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  pointer-events: none;
  animation: toastInOut 1.8s ease forwards;
}

@keyframes toastInOut {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
}

/* ============ 头像选择弹窗 ============ */
.avatar-options {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 8px 0;
}

.avatar-option {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.2s, transform 0.2s;
}

.avatar-option:hover { transform: scale(1.08); }
.avatar-option.active { border-color: var(--qq-blue); }

.avatar-option img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============ 隐藏元素 ============ */
.hidden-file-input { display: none; }

/* ============ 头像切换动画 ============ */
.avatar-switching {
  animation: avatarSwitch 0.45s ease;
}

@keyframes avatarSwitch {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(0.3); opacity: 0.4; }
  60% { transform: scale(0.3); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

/* ============ 回到底部按钮 ============ */
.scroll-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--qq-white);
  border: 1px solid var(--qq-border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #888;
  z-index: 5;
  transition: all 0.2s;
  animation: fadeInUp 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.scroll-bottom-btn:hover { background: #f5f5f5; }
.scroll-bottom-btn:active { transform: scale(0.9); }

/* ============ 全局响应式适配 ============ */

/* ---- 超小屏 (≤360px) ---- */
@media (max-width: 360px) {
  .chat-messages { padding: 8px 6px; }
  .message-avatar { width: 30px; height: 30px; }
  .message-bubble {
    font-size: 14px;
    padding: 7px 10px;
    line-height: 1.45;
  }
  .message-bubble-wrap { max-width: 80%; }
  .message-row { gap: 6px; margin-bottom: 6px; }
  .chat-input { font-size: 14px; padding: 7px 12px; }
  .send-btn { width: 34px; height: 34px; }
  .chat-input-area { padding: 6px 8px; padding-bottom: calc(6px + var(--safe-bottom)); gap: 6px; }
  .header-nickname { font-size: 15px; }
  .header-avatar-wrapper { width: 30px; height: 30px; }
  :root { --header-height: 46px; }
  .typing-indicator .typing-avatar { width: 30px; height: 30px; }
  .typing-bubble { padding: 10px 12px; }
  .time-divider { font-size: 11px; padding: 8px 0 4px; }
  .welcome-avatar { width: 64px; height: 64px; }
  .welcome-nickname { font-size: 18px; }
  .welcome-opener-btn { padding: 6px 14px; font-size: 12px; }
}

/* ---- 小屏 (361px-420px) 手机主流 ---- */
@media (min-width: 361px) and (max-width: 420px) {
  .message-avatar { width: 34px; height: 34px; }
  .message-bubble { font-size: 14.5px; padding: 8px 12px; }
  .message-bubble-wrap { max-width: 78%; }
  .message-row { gap: 7px; }
  .chat-input { font-size: 14.5px; }
  .typing-indicator .typing-avatar { width: 34px; height: 34px; }
  .typing-indicator { padding: 4px 10px 8px; }
}

/* ---- 中屏 (421px-500px) 大屏手机 ---- */
@media (min-width: 421px) and (max-width: 500px) {
  .message-bubble-wrap { max-width: 75%; }
}

/* ---- 平板竖屏 (501px-768px) ---- */
@media (min-width: 501px) and (max-width: 768px) {
  .message-bubble-wrap { max-width: 68%; }
  .chat-messages { padding: 14px 18px; }
  .chat-input { font-size: 15px; }
}

/* ---- 平板横屏 / 小桌面 (769px-1024px) ---- */
@media (min-width: 769px) and (max-width: 1024px) {
  .app-container { max-width: 520px; }
  .message-bubble-wrap { max-width: 65%; }
  .chat-messages { padding: 16px 22px; }
  .message-bubble { font-size: 15px; padding: 10px 14px; }
}

/* ---- 桌面大屏 (1025px+) ---- */
@media (min-width: 1025px) {
  .app-container { max-width: 540px; }
  .message-bubble-wrap { max-width: 60%; }
  .chat-messages { padding: 18px 26px; }
  .message-bubble { font-size: 15px; }
  .chat-input { font-size: 15px; }
  .welcome-avatar { width: 88px; height: 88px; }
  .welcome-nickname { font-size: 24px; }
}

/* ---- 超宽屏 (1440px+) ---- */
@media (min-width: 1440px) {
  .app-container { max-width: 560px; }
  .message-bubble-wrap { max-width: 55%; }
}

/* ---- 横屏手机适配 ---- */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --header-height: 42px; }
  .header-nickname { font-size: 14px; }
  .header-avatar-wrapper { width: 28px; height: 28px; }
  .message-avatar { width: 28px; height: 28px; }
  .message-bubble { font-size: 13px; padding: 6px 10px; line-height: 1.4; }
  .message-bubble-wrap { max-width: 75%; }
  .chat-input { min-height: 30px; max-height: 60px; font-size: 13px; padding: 6px 12px; }
  .send-btn { width: 30px; height: 30px; }
  .chat-input-area { padding: 5px 8px; padding-bottom: calc(5px + var(--safe-bottom)); gap: 6px; }
  .chat-messages { padding: 8px 12px; }
  .time-divider { padding: 6px 0 4px; font-size: 10px; }
  .typing-indicator .typing-avatar { width: 28px; height: 28px; }
  .typing-bubble { padding: 8px 10px; }
  .typing-dot { width: 5px; height: 5px; }
  .scroll-bottom-btn { bottom: 60px; right: 10px; width: 28px; height: 28px; font-size: 14px; }
}

/* ============ 暗色滚动条 ============ */
@media (hover: hover) {
  .chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }
}

/* ============ 隐藏uni-app tabbar ============ */
.uni-tabbar-bottom { display: none !important; }