/* ====== AI 聊天组件样式 ====== */

/* 悬浮按钮 */
#ai-chat-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #E6B85C;
  color: #5C4A32;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

#ai-chat-button:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  background: #d4a84a;
}

#ai-chat-button:active {
  transform: scale(0.95);
}

#ai-chat-button svg {
  width: 28px;
  height: 28px;
  stroke-width: 2;
}

/* 新消息红点 */
#ai-chat-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e53e3e;
  display: none;
}

/* 聊天窗口 */
#ai-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-height: 520px;
  background: #F5E6C8;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: column;
  z-index: 9999;
  overflow: hidden;
  border: 1px solid #D9D2C3;
}

#ai-chat-window.open {
  display: flex;
}

/* 头部 */
.ai-chat-header {
  background: #FFF3CD;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #D9D2C3;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
}

.ai-chat-header:active {
  cursor: grabbing;
}

#ai-chat-window.dragging {
  transition: none !important;
}

.ai-chat-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #5C4A32;
  margin: 0;
}

.ai-chat-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #5C4A32;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  transition: background 0.2s;
}

.ai-chat-close:hover {
  background: rgba(0, 0, 0, 0.06);
}

/* 消息区域 */
#ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

#ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}

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

#ai-chat-messages::-webkit-scrollbar-thumb {
  background: #D9D2C3;
  border-radius: 10px;
}

/* 消息气泡 */
.ai-chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  animation: bubbleIn 0.25s ease-out;
}

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

.ai-chat-bubble.ai {
  align-self: flex-start;
  background: #FFF3CD;
  color: #5C4A32;
  border-bottom-left-radius: 4px;
}

/* Markdown 元素样式 */
.ai-chat-bubble.ai h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 8px 0 4px;
  color: #5C4A32;
}

.ai-chat-bubble.ai h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 6px 0 3px;
  color: #5C4A32;
}

.ai-chat-bubble.ai strong {
  color: #4a3820;
}

.ai-chat-bubble.ai ul {
  margin: 4px 0;
  padding-left: 16px;
}

.ai-chat-bubble.ai li {
  margin-bottom: 2px;
}

.ai-chat-bubble.ai code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: #8B6914;
}

/* 思考过程折叠区 */
.ai-reasoning {
  align-self: flex-start;
  width: 100%;
  margin-bottom: 4px;
}

.ai-reasoning-toggle {
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: #8a7560;
  transition: background 0.15s;
}

.ai-reasoning-toggle:hover {
  background: rgba(0, 0, 0, 0.04);
}

.ai-reasoning-arrow {
  transition: transform 0.2s;
  flex-shrink: 0;
}

.ai-reasoning.collapsed .ai-reasoning-arrow {
  transform: rotate(-90deg);
}

.ai-reasoning-content {
  font-size: 13px;
  line-height: 1.6;
  color: #8a7560;
  background: rgba(255, 255, 255, 0.4);
  border-left: 2px solid #D9D2C3;
  padding: 6px 12px;
  margin: 4px 0 0 8px;
  border-radius: 0 6px 6px 0;
  max-height: 80vh;
  overflow-y: auto;
  word-break: break-word;
}

.ai-reasoning.collapsed .ai-reasoning-content {
  display: none;
}

.ai-chat-bubble.user {
  align-self: flex-end;
  background: #E6B85C;
  color: #5C4A32;
  border-bottom-right-radius: 4px;
}

/* 打字指示器 */
.ai-chat-typing {
  display: none;
  align-self: flex-start;
  background: #FFF3CD;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  margin: 0 16px;
}

.ai-chat-typing.active {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8a7560;
  animation: typingBounce 1.2s infinite;
}

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

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

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

/* 输入区域 */
.ai-chat-input {
  padding: 12px 16px;
  border-top: 1px solid #D9D2C3;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: #F5E6C8;
}

#ai-chat-input {
  flex: 1;
  border: 1.5px solid #D9D2C3;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  color: #5C4A32;
  background: #fff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

#ai-chat-input::placeholder {
  color: #bfb8a8;
}

#ai-chat-input:focus {
  border-color: #E6B85C;
  box-shadow: 0 0 0 3px rgba(230, 184, 92, 0.2);
}

#ai-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #E6B85C;
  color: #5C4A32;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}

#ai-chat-send:hover {
  background: #d4a84a;
}

#ai-chat-send:active {
  transform: scale(0.92);
}

#ai-chat-send:disabled {
  background: #D9D2C3;
  color: #bfb8a8;
  cursor: not-allowed;
}

#ai-chat-send.stop {
  background: #e53e3e;
  color: #fff;
}

#ai-chat-send.stop:hover {
  background: #c53030;
}

#ai-chat-send svg {
  width: 18px;
  height: 18px;
}

/* 错误提示 */
.ai-chat-error {
  align-self: center;
  font-size: 12px;
  color: #c53030;
  background: #fed7d7;
  padding: 8px 14px;
  border-radius: 10px;
  animation: bubbleIn 0.25s ease-out;
}

/* ====== 响应式 ====== */

/* 平板 */
@media (max-width: 768px) {
  #ai-chat-window {
    width: calc(100vw - 32px);
    max-height: 60vh;
    right: 16px;
    bottom: 88px;
  }

  #ai-chat-button {
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
  }

  #ai-chat-button svg {
    width: 24px;
    height: 24px;
  }
}

/* 手机 */
@media (max-width: 480px) {
  #ai-chat-window {
    width: 100vw;
    max-height: 100vh;
    right: 0;
    bottom: 0;
    border-radius: 0;
    border: none;
  }

  #ai-chat-button {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }

  #ai-chat-button svg {
    width: 22px;
    height: 22px;
  }

  .ai-chat-header {
    padding: 12px 16px;
  }

  #ai-chat-input {
    padding: 8px 14px;
    font-size: 16px; /* 防止 iOS 缩放 */
  }
}
