/* ============================================
   AI 聊天界面样式
   ============================================ */

/* 浮标：头像 + 名牌 */
.ai-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: grab;
  user-select: none;
  /* 触屏上拖她的时候别把页面也跟着滚了 */
  touch-action: none;
}

.ai-launcher.dragging {
  cursor: grabbing;
}

/* 聊天开着的时候藏起来。不用 display:none —— 那样测不到它的位置，
   面板和窗口缩放都要靠这个坐标 */
.ai-launcher.hidden {
  opacity: 0;
  visibility: hidden;
}

/* 拖动时停掉漂浮动画，不然跟手会发抖 */
.ai-launcher.dragging .ai-chat-bubble {
  animation: none;
  transform: none;
}

.ai-launcher-label {
  font-size: 13px;
  letter-spacing: 0.02em;
  color: #6f5a9a;
  background: rgba(255, 250, 243, 0.92);
  border: 1px solid rgba(143, 123, 184, 0.22);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(74, 55, 100, 0.1);
  transition: opacity 0.3s, transform 0.3s;
}

.ai-launcher:hover .ai-launcher-label {
  transform: translateX(-2px);
}

/* 聊天气泡按钮 */
.ai-chat-bubble {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8f7bb8, #b59ad6);
  box-shadow: 0 8px 24px rgba(143, 123, 184, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  transition: transform 0.3s, box-shadow 0.3s;
  user-select: none;
  animation: float 3s ease-in-out infinite;
  overflow: hidden;
  flex: none;
}

/* 首次来访的招呼 */
.ai-greeting {
  position: fixed;
  right: 28px;
  bottom: 104px;
  z-index: 999;
  max-width: 268px;
  padding: 14px 34px 14px 16px;
  background: rgba(255, 250, 243, 0.98);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(143, 123, 184, 0.22);
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 16px 40px rgba(74, 55, 100, 0.16);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.ai-greeting.show {
  opacity: 1;
  transform: translateY(0);
}

/* 浮标被拖到左半边时，气泡的小角要跟着翻过去 */
.ai-greeting.anchor-left {
  border-radius: 18px 18px 18px 4px;
}

.ai-greeting p {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  color: #2a2438;
}

.ai-greeting-close {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: none;
  font-size: 17px;
  line-height: 1;
  color: #7a738c;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0.6;
}

.ai-greeting-close:hover {
  opacity: 1;
}

.ai-chat-bubble img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-chat-bubble:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(143, 123, 184, 0.45);
}

.ai-chat-bubble.minimized {
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* 聊天窗口 */
.ai-chat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 380px;
  max-width: calc(100vw - 56px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: rgba(255, 250, 243, 0.98);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(74, 55, 100, 0.18);
  border: 1px solid rgba(143, 123, 184, 0.2);
  display: none;
  flex-direction: column;
  z-index: 998;
  animation: slideUp 0.3s ease;
}

.ai-chat-window.active {
  display: flex;
}

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

/* 聊天头部 */
.ai-chat-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(143, 123, 184, 0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8f7bb8, #b59ad6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  overflow: hidden;
}

.ai-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-chat-info h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--lilac-deep, #6f5a9a);
  margin: 0;
}

.ai-chat-status {
  font-size: 12px;
  color: var(--ink-soft, #7a738c);
  margin: 2px 0 0 0;
}

.ai-chat-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-soft, #7a738c);
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.ai-chat-close:hover {
  background: rgba(143, 123, 184, 0.1);
  color: var(--lilac-deep, #6f5a9a);
}

.ai-chat-clear {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-soft, #7a738c);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.ai-chat-clear:hover {
  background: rgba(232, 160, 176, 0.1);
  color: var(--rose, #e8a0b0);
}

/* 聊天消息区域 */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(143, 123, 184, 0.3);
  border-radius: 3px;
}

/* 消息气泡 */
.ai-message {
  display: flex;
  gap: 10px;
  animation: messageIn 0.3s ease;
}

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

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

.ai-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  overflow: hidden;
}

.ai-message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-message.assistant .ai-message-avatar {
  background: linear-gradient(135deg, #8f7bb8, #b59ad6);
}

.ai-message.user .ai-message-avatar {
  background: linear-gradient(135deg, #e8a0b0, #f5b8c5);
}

.ai-message-content {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.ai-message.assistant .ai-message-content {
  background: rgba(143, 123, 184, 0.12);
  color: var(--ink, #2a2438);
  border-bottom-left-radius: 4px;
}

.ai-message.user .ai-message-content {
  background: linear-gradient(135deg, #8f7bb8, #b59ad6);
  color: white;
  border-bottom-right-radius: 4px;
}

/* 欢迎消息 */
.ai-welcome {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft, #7a738c);
}

.ai-welcome-icon {
  font-size: 48px;
  margin-bottom: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.ai-welcome-icon img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
}

.ai-welcome h4 {
  font-size: 18px;
  font-weight: 600;
  color: var(--lilac-deep, #6f5a9a);
  margin: 0 0 8px 0;
}

.ai-welcome p {
  font-size: 14px;
  margin: 0;
}

/* 快捷问题 */
.ai-quick-questions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 20px 20px;
}

.ai-quick-question {
  padding: 10px 14px;
  background: rgba(143, 123, 184, 0.08);
  border: 1px solid rgba(143, 123, 184, 0.2);
  border-radius: 12px;
  font-size: 13px;
  color: var(--ink, #2a2438);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.ai-quick-question:hover {
  background: rgba(143, 123, 184, 0.15);
  border-color: rgba(143, 123, 184, 0.35);
  transform: translateX(4px);
}

/* 正在输入 */
.ai-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: rgba(143, 123, 184, 0.12);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lilac, #8f7bb8);
  animation: typing 1.4s infinite;
}

.ai-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-6px);
  }
}

/* 输入区域 */
.ai-chat-input {
  padding: 16px 20px;
  border-top: 1px solid rgba(143, 123, 184, 0.15);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-input-wrapper {
  flex: 1;
  position: relative;
}

.ai-chat-textarea {
  width: 100%;
  min-height: 42px;
  max-height: 100px;
  padding: 10px 14px;
  border: 1px solid rgba(143, 123, 184, 0.25);
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink, #2a2438);
  background: white;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.ai-chat-textarea:focus {
  border-color: var(--lilac, #8f7bb8);
}

.ai-chat-textarea::placeholder {
  color: var(--ink-soft, #7a738c);
  opacity: 0.6;
}

.ai-chat-send {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #8f7bb8, #b59ad6);
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.ai-chat-send:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(143, 123, 184, 0.35);
}

.ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 错误提示 */
.ai-error-message {
  background: rgba(232, 160, 176, 0.15);
  color: #c56b7f;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  border-left: 3px solid var(--rose, #e8a0b0);
}

/* 任务消息样式 */
.ai-task-message .ai-message-content {
  background: linear-gradient(135deg, rgba(143, 123, 184, 0.08), rgba(232, 160, 176, 0.08));
  border: 1px solid rgba(143, 123, 184, 0.25);
}

.task-badge {
  display: inline-block;
  padding: 4px 10px;
  background: rgba(143, 123, 184, 0.2);
  color: var(--lilac-deep, #6f5a9a);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.task-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(143, 123, 184, 0.15);
}

.task-action-btn {
  padding: 6px 12px;
  background: white;
  border: 1px solid rgba(143, 123, 184, 0.3);
  border-radius: 8px;
  font-size: 12px;
  color: var(--lilac-deep, #6f5a9a);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.task-action-btn:hover {
  background: rgba(143, 123, 184, 0.1);
  border-color: var(--lilac, #8f7bb8);
  transform: translateY(-1px);
}

/* 移动端适配 */
@media (max-width: 900px) {
  /* 页面内容别被右下角浮标挡住 */
  body {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
}

@media (max-width: 520px) {
  .ai-launcher {
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    right: 16px;
  }

  /* 窄屏放不下名牌，招呼语里她会自报家门 */
  .ai-launcher-label {
    display: none;
  }

  .ai-chat-bubble {
    width: 56px;
    height: 56px;
    font-size: 26px;
  }

  .ai-greeting {
    right: 16px;
    bottom: 88px;
    max-width: calc(100vw - 32px);
  }

  .ai-chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: min(100vh, 100dvh);
    max-height: min(100vh, 100dvh);
    border-radius: 0;
  }

  .ai-message-content {
    max-width: 85%;
  }

  .task-actions {
    flex-direction: column;
  }

  .task-action-btn {
    width: 100%;
  }
}
