/* ==========================================================
   pet-ai.css · 「问小引」AI 聊天面板（独立于宠物动画文件）
   后端：同源 /api/chat（Cloudflare Workers AI，免费额度）
   ========================================================== */

.ai-chat-btn {
  position: fixed;
  right: 30px;
  bottom: 128px;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  z-index: 2147482900;
  background: linear-gradient(145deg, #6f8cff, #4f6ef7);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(79, 110, 247, .38), inset 0 1px 0 rgba(255, 255, 255, .45);
  transition: transform .16s ease, box-shadow .16s ease;
}
.ai-chat-btn:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 22px rgba(79, 110, 247, .46); }
.ai-chat-btn:active { transform: scale(.94); }
.ai-chat-btn .ai-dot {
  position: absolute;
  right: 3px;
  top: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #35d07f;
  border: 2px solid #fff;
  box-sizing: content-box;
}

.ai-chat-panel {
  position: fixed;
  right: 26px;
  bottom: 186px;
  width: 340px;
  max-width: calc(100vw - 40px);
  max-height: min(64vh, 520px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e7e9f2;
  border-radius: 18px;
  box-shadow: 0 22px 60px rgba(20, 30, 70, .18);
  z-index: 2147482901;
  overflow: hidden;
  animation: ai-pop .18s ease-out;
}
@keyframes ai-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.ai-chat-panel[hidden] { display: none !important; }

.ai-chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #eef0f7;
  background: linear-gradient(180deg, #f8faff, #fff);
}
.ai-chat-title { font-weight: 700; font-size: 14px; color: #1c2340; }
.ai-chat-sub { display: block; font-weight: 400; font-size: 11px; color: #7b849e; margin-top: 2px; }
.ai-chat-x {
  margin-left: auto;
  border: 0;
  background: transparent;
  font-size: 16px;
  color: #98a0b8;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 8px;
}
.ai-chat-x:hover { background: #f1f3fb; color: #4f5b7d; }

.ai-chat-log {
  flex: 1;
  min-height: 90px;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fbfcff;
}
.ai-msg {
  max-width: 86%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-msg.me { align-self: flex-end; background: #4f6ef7; color: #fff; border-bottom-right-radius: 5px; }
.ai-msg.ai { align-self: flex-start; background: #fff; color: #232a42; border: 1px solid #e9ecf5; border-bottom-left-radius: 5px; }
.ai-msg.is-typing { color: #8e97b0; }

.ai-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid #eef0f7;
  background: #fff;
}
.ai-chat-form input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #e3e6f0;
  border-radius: 10px;
  font-size: 13px;
  background: #f7f8fc;
  color: #232a42;
  outline: none;
}
.ai-chat-form input:focus { border-color: #b9c6ff; background: #fff; box-shadow: 0 0 0 3px rgba(79, 110, 247, .12); }
.ai-chat-form button {
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: #4f6ef7;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ai-chat-form button:disabled { opacity: .6; cursor: default; }

/* 夜猫模式 */
html[data-theme="night"] .ai-chat-panel { background: #171b2c; border-color: #2a3049; }
html[data-theme="night"] .ai-chat-head { background: linear-gradient(180deg, #1c2233, #171b2c); border-color: #2a3049; }
html[data-theme="night"] .ai-chat-title { color: #e8ebf6; }
html[data-theme="night"] .ai-chat-log { background: #131726; }
html[data-theme="night"] .ai-msg.ai { background: #1f2438; border-color: #2f3752; color: #e8ebf6; }
html[data-theme="night"] .ai-chat-form { background: #171b2c; border-color: #2a3049; }
html[data-theme="night"] .ai-chat-form input { background: #131726; border-color: #2f3752; color: #e8ebf6; }
html[data-theme="night"] .ai-chat-btn { box-shadow: 0 8px 18px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .22); }

@media (max-width: 640px) {
  .ai-chat-btn { right: 16px; bottom: 112px; width: 42px; height: 42px; }
  .ai-chat-panel { right: 12px; left: 12px; width: auto; bottom: 164px; max-height: 62vh; }
}
