/* 沿用會員中心 ui-lite / member-pages-refresh 的設計語彙（見 member-pages-refresh.css 的 --mp-* 變量），
   本檔案只負責 .uc-contact-support 卡片內部的聊天介面樣式。 */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.support-subtitle {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--mp-text-soft, #5f738c);
  margin: -0.5rem 0 1.1rem 1.25rem;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 260px);
  min-height: 460px;
  background: #fff;
  border: 1px solid var(--mp-border, #dce6f4);
  border-radius: 16px;
  box-shadow: var(--mp-shadow-soft, 0 8px 20px rgba(30, 41, 59, 0.08));
  overflow: hidden;
}

/* 消息列表包装器 */
.messages-wrapper {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  scroll-behavior: smooth;
  /* 关闭浏览器原生滚动锚定：上拉加载历史消息时，JS 会自行按锚点校正 scrollTop，
     若同时启用 overflow-anchor，浏览器会自动做一次它自己的调整，两者互相打架导致位置计算错误 */
  overflow-anchor: none;
}

.messages-list::-webkit-scrollbar {
  width: 6px;
}

.messages-list::-webkit-scrollbar-thumb {
  background: var(--mp-border, #dce6f4);
  border-radius: 999px;
}

/* 消息基础样式 */
.message {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 1.15rem;
  animation: contactMessageIn 0.3s ease-out;
}

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

.message-avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  margin-top: 0.1rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  background: var(--mp-accent, #2ea8a2);
}

/* 消息内容列：發送人名稱（上）、氣泡、時間（下）*/
.message-body {
  display: flex;
  flex-direction: column;
  max-width: 68%;
}

/* 用户消息（右对齐）*/
.message-user {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.message-user .message-body {
  align-items: flex-end;
}

.message-user .message-avatar {
  background: #334b67;
}

.message-user .bubble {
  background: var(--mp-accent, #2ea8a2);
  color: #fff;
  border-radius: 14px 14px 3px 14px;
}

/* 客服消息（左对齐）*/
.message-admin {
  justify-content: flex-start;
}

.message-admin .message-body {
  align-items: flex-start;
}

.message-admin .bubble {
  background: #f0f4f9;
  color: #223550;
  border-radius: 14px 14px 14px 3px;
}

/* 消息气泡 */
.bubble {
  padding: 0.6rem 0.85rem;
  word-wrap: break-word;
  word-break: break-word;
}

.message-sender {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-bottom: 0.3rem;
  padding: 0 0.15rem;
  color: var(--mp-text-soft, #5f738c);
}

.message-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message-time {
  font-size: 0.7rem;
  color: var(--mp-text-soft, #5f738c);
  margin-top: 0.3rem;
  padding: 0 0.15rem;
}

/* 消息中的图片 */
.message-images {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.message-image {
  width: 5.2rem;
  height: 5.2rem;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.message-image:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 16px rgba(30, 41, 59, 0.18);
}

/* 输入区域 */
.input-area {
  border-top: 1px solid var(--mp-border, #dce6f4);
  padding: 0.9rem 1.1rem 1rem;
  background: #fafcfe;
}

.input-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
}

.message-input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--mp-border, #dce6f4);
  border-radius: 14px;
  resize: none;
  font-size: 0.9rem;
  font-family: inherit;
  color: #1f2937;
  max-height: 6rem;
  overflow-y: auto;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.message-input::placeholder {
  color: var(--mp-text-soft, #5f738c);
}

.message-input:focus {
  outline: none;
  border-color: var(--mp-accent, #2ea8a2);
  box-shadow: 0 0 0 3px rgba(46, 168, 162, 0.14);
}

.btn-icon {
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border: 1.5px solid var(--mp-border, #dce6f4);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}

.btn-icon:hover {
  background: #eef8f7;
  border-color: var(--mp-accent, #2ea8a2);
}

.btn-icon:focus-visible {
  outline: 2px solid rgba(72, 169, 166, 0.75);
  outline-offset: 2px;
}

.btn-primary {
  flex: none;
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: 14px;
  background: var(--mp-accent, #2ea8a2);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.btn-primary:hover:not(:disabled) {
  background: #26938e;
}

.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary:disabled {
  background: #c3cdd8;
  cursor: not-allowed;
}

.btn-primary:focus-visible {
  outline: 2px solid rgba(72, 169, 166, 0.75);
  outline-offset: 2px;
}

/* 图片预览区域 */
.image-previews {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.image-preview {
  position: relative;
  width: 3.75rem;
  height: 3.75rem;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--mp-border, #dce6f4);
}

.remove-btn {
  position: absolute;
  top: -0.4rem;
  right: -0.4rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: #e0344c;
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.remove-btn:hover {
  background: #b8253a;
}

.remove-btn:focus-visible {
  outline: 2px solid #b8253a;
  outline-offset: 2px;
}

/* 图片预览 Modal */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
}

.image-modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.72);
  cursor: pointer;
}

.modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  z-index: 1;
}

.modal-content img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.close-btn {
  position: absolute;
  top: -2.75rem;
  right: 0;
  width: 2.35rem;
  height: 2.35rem;
  background: rgba(255, 255, 255, 0.95);
  border: none;
  border-radius: 50%;
  font-size: 1.35rem;
  color: #1f2937;
  cursor: pointer;
  transition: background 0.2s;
  line-height: 1;
}

.close-btn:hover {
  background: #fff;
}

.close-btn:focus-visible {
  outline: 2px solid #1f2937;
  outline-offset: 2px;
}

/* 欢迎 / 空状态 */
.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 0 2rem;
}

.welcome-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: #eef8f7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  margin-bottom: 1.1rem;
}

.welcome-message h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 0.4rem 0;
  color: #223550;
}

.welcome-message p {
  font-size: 0.85rem;
  margin: 0;
  color: var(--mp-text-soft, #5f738c);
  line-height: 1.6;
}

/* 加载状态 */
.loading-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  height: 100%;
  color: var(--mp-text-soft, #5f738c);
  font-size: 0.82rem;
}

.loading-spinner {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 2.5px solid var(--mp-border, #dce6f4);
  border-top-color: var(--mp-accent, #2ea8a2);
  animation: contactSpin 0.7s linear infinite;
}

@keyframes contactSpin {
  to {
    transform: rotate(360deg);
  }
}

/* 上拉加载更多历史消息的指示器 */
.load-more-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 0;
  color: var(--mp-text-soft, #5f738c);
  font-size: 0.78rem;
}

.load-more-indicator .loading-spinner {
  width: 1.1rem;
  height: 1.1rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .chat-container {
    height: calc(100vh - 220px);
    min-height: 400px;
  }

  .bubble {
    max-width: 100%;
  }

  .message-body {
    max-width: 80%;
  }

  .input-row {
    flex-wrap: nowrap;
  }

  .btn-primary {
    padding: 0.65rem 1.1rem;
  }

  .modal-content {
    max-width: 95%;
  }
}
