/**
 * PowPow 聊天窗口 - 模态弹窗版
 * 美观的模态弹窗设计
 */

/* ============================================
   背景遮罩（半透明）
   ============================================ */
.powpow-chat-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease-out, visibility 0.2s ease-out;
}

.powpow-chat-backdrop.open {
  opacity: 1;
  visibility: visible;
}

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

/* ============================================
   聊天窗口（模态弹窗）
   ============================================ */
.powpow-chat-modal {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 500px;
  height: 80vh;
  max-height: 680px;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.3s ease-out;
  transform: scale(0.9);
  transition: transform 0.3s ease-out;
}

.powpow-chat-backdrop.open .powpow-chat-modal {
  transform: scale(1);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ============================================
   头部
   ============================================ */
.powpow-chat-header {
  background: linear-gradient(135deg, #B22222 0%, #8B1A1A 100%);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.powpow-chat-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.powpow-chat-header-title img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.3);
  background: white;
}

.powpow-chat-header-title h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: white;
}

.powpow-chat-header-title .status {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  gap: 6px;
}

.powpow-chat-header-title .status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #4CAF50;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
}

.powpow-chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.powpow-chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

.powpow-chat-close svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* 移动端触摸优化 */
@media (max-width: 768px) {
  .powpow-chat-close {
    width: 44px;
    height: 44px;
    /* 增大点击区域，降低误触 */
    position: relative;
  }
  .powpow-chat-close::after {
    content: '';
    position: absolute;
    top: -8px;
    right: -8px;
    bottom: -8px;
    left: -8px;
  }
  .powpow-chat-close svg {
    width: 22px;
    height: 22px;
  }
}

/* ============================================
   消息区域
   ============================================ */
.powpow-chat-messages {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  background: #f8f9fa;
  min-height: 200px;
  max-height: calc(100% - 180px);
}

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

.powpow-chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.powpow-chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.powpow-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* 消息气泡 */
.powpow-message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  animation: messageSlideIn 0.3s ease-out;
}

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

.powpow-message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.powpow-message-bubble {
  max-width: calc(100% - 48px);
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  position: relative;
}

.powpow-message.ai .powpow-message-bubble {
  background: white;
  color: #333;
  border: 1px solid #e9ecef;
  border-top-left-radius: 4px;
}

.powpow-message.user {
  flex-direction: row-reverse;
}

.powpow-message.user .powpow-message-bubble {
  background: linear-gradient(135deg, #B22222 0%, #8B1A1A 100%);
  color: white;
  border-top-right-radius: 4px;
  border-top-left-radius: 18px;
}

/* 打字指示器 */
.powpow-typing {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  background: white;
  border: 1px solid #e9ecef;
  border-radius: 18px;
  border-top-left-radius: 4px;
  max-width: fit-content;
  margin-bottom: 16px;
}

.powpow-typing-dot {
  width: 8px;
  height: 8px;
  background: #ccc;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.powpow-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.powpow-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* ============================================
   输入区域
   ============================================ */
.powpow-chat-input-container {
  padding: 16px 24px 24px;
  background: white;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.powpow-chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  outline: none;
  transition: all 0.2s ease;
  line-height: 1.5;
}

.powpow-chat-input:focus {
  border-color: #B22222;
  box-shadow: 0 0 0 3px rgba(178, 34, 34, 0.1);
}

.powpow-chat-input::placeholder {
  color: #adb5bd;
}

.powpow-chat-send {
  background: linear-gradient(135deg, #B22222 0%, #8B1A1A 100%);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  min-width: 80px;
  height: 48px;
}

.powpow-chat-send:hover {
  background: linear-gradient(135deg, #8B1A1A 0%, #6B1212 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(178, 34, 34, 0.3);
}

.powpow-chat-send:active {
  transform: translateY(0);
}

.powpow-chat-send:disabled {
  background: #e9ecef;
  cursor: not-allowed;
  transform: none;
}

/* ============================================
   响应式设计
   ============================================ */

/* 平板及以下 */
@media (max-width: 768px) {
  .powpow-chat-backdrop {
    padding: 12px;
    align-items: flex-end; /* 对话框贴近屏幕底部，更符合手机操作习惯 */
  }

  .powpow-chat-modal {
    height: auto;
    max-height: 85vh;
    min-height: 0;
    border-radius: 20px 20px 12px 12px;
    width: 100%;
    max-width: 100%;
  }

  .powpow-chat-header {
    padding: 14px 16px;
  }

  .powpow-chat-header-title img {
    width: 38px;
    height: 38px;
  }

  .powpow-chat-header-title h3 {
    font-size: 16px;
  }

  .powpow-chat-messages {
    padding: 14px 16px;
    min-height: 180px;
    max-height: calc(85vh - 170px);
  }

  .powpow-chat-input-container {
    padding: 10px 16px 16px;
  }

  .powpow-chat-input {
    min-height: 42px;
    font-size: 16px; /* 防止 iOS Safari 缩放 */
  }

  .powpow-chat-send {
    min-width: 64px;
    height: 42px;
    padding: 8px 14px;
    font-size: 13px;
  }
}

/* 手机竖屏 */
@media (max-width: 480px) {
  .powpow-chat-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .powpow-chat-modal {
    /* 全屏沉浸式，底部贴边 */
    max-height: 92vh;
    height: 92vh;
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 100%;
  }

  .powpow-chat-header {
    padding: 14px 16px;
    /* 为顶部安全区域预留空间（刘海屏） */
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .powpow-chat-header-title img {
    width: 36px;
    height: 36px;
  }

  .powpow-chat-header-title h3 {
    font-size: 15px;
  }

  .powpow-chat-messages {
    padding: 12px 14px;
    min-height: 0;
    flex: 1;
    max-height: none;
  }

  .powpow-message-avatar {
    width: 30px;
    height: 30px;
  }

  .powpow-message-bubble {
    font-size: 14px;
    padding: 10px 13px;
    max-width: calc(100% - 44px);
  }

  .powpow-chat-input-container {
    padding: 10px 14px;
    /* 为底部安全区域预留空间（iPhone X 以上）*/
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .powpow-chat-input {
    min-height: 40px;
    font-size: 16px; /* 防止 iOS 输入框自动缩放 */
    padding: 10px 12px;
  }

  .powpow-chat-send {
    min-width: 60px;
    height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }
}

/* 极小屏幕（宽度 < 360px，如旧款 Android）*/
@media (max-width: 360px) {
  .powpow-chat-header {
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .powpow-chat-header-title h3 {
    font-size: 14px;
  }

  .powpow-chat-header-title .status {
    font-size: 12px;
  }

  .powpow-chat-input-container {
    gap: 8px;
  }

  .powpow-chat-send {
    min-width: 52px;
    padding: 8px 10px;
  }
}

/* ============================================
   语言特定样式
   ============================================ */

/* 中文样式 */
[data-lang="zh"] .powpow-chat-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

/* 英文样式 */
[data-lang="en"] .powpow-chat-modal {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
}
