/* ============================================================
   AI 数字分身浮窗  ai-chat.css
   ------------------------------------------------------------
   与博客共用 tailwind.css 里的主题变量（--primary / --background / --border …），
   所以浅色 / 深色模式自动跟随，风格与参考站右下角的 AI 分身保持一致。
   引入位置：BaseLayout.astro，紧跟 /css/polish.css 之后。
   ============================================================ */

/* ---------- 右下角悬浮按钮 ---------- */
.ai-fab {
  position: fixed;
  right: 1rem;
  bottom: 5rem;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: 9999px;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  background-image: linear-gradient(to right, var(--primary), #7c3aed);
  box-shadow: 0 20px 25px -5px rgba(99, 102, 241, 0.25), 0 8px 10px -6px rgba(99, 102, 241, 0.2);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.ai-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 25px 30px -5px rgba(99, 102, 241, 0.35);
}
.ai-fab:active {
  transform: scale(0.96);
}
.ai-fab__dot {
  position: relative;
  display: flex;
  width: 0.75rem;
  height: 0.75rem;
}
.ai-fab__dot i {
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  background: #fff;
  animation: ai-ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
}
.ai-fab__dot i + i {
  animation: none;
  opacity: 1;
}
.ai-fab__icon {
  width: 1.25rem;
  height: 1.25rem;
  transition: transform 0.25s ease;
}
.ai-fab:hover .ai-fab__icon {
  transform: rotate(12deg);
}
@keyframes ai-ping {
  75%,
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* ---------- 聊天面板 ---------- */
.ai-panel {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: calc(100vw - 2rem);
  max-width: 420px;
  height: 580px;
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  border: 1px solid color-mix(in oklab, var(--border) 80%, transparent);
  border-radius: 1.5rem;
  background: color-mix(in oklab, var(--background) 96%, transparent);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.32);
  animation: ai-pop 0.22s ease-out;
}
.ai-panel[hidden] {
  display: none;
}
@keyframes ai-pop {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (min-width: 640px) {
  .ai-panel {
    right: 1.5rem;
    bottom: 1.5rem;
  }
}
@media (min-width: 768px) {
  .ai-fab {
    bottom: 1.5rem;
  }
}

/* ---------- 面板头部 ---------- */
.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  background: color-mix(in oklab, var(--muted) 40%, transparent);
}
.ai-head__left {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}
.ai-head__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: 0.75rem;
  color: #fff;
  background-image: linear-gradient(to bottom right, var(--primary), #7c3aed);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.ai-head__avatar svg {
  width: 1rem;
  height: 1rem;
}
.ai-head__title {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--foreground);
  line-height: 1.2;
}
.ai-head__title em {
  display: inline-flex;
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 9999px;
  background: #10b981;
  font-style: normal;
}
.ai-head__sub {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.125rem;
  font-size: 11px;
  color: var(--muted-foreground);
}
.ai-head__sub svg {
  width: 0.75rem;
  height: 0.75rem;
}
.ai-head__actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.ai-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.ai-icon-btn:hover {
  background: var(--muted);
  color: var(--foreground);
}
.ai-icon-btn svg {
  width: 1rem;
  height: 1rem;
}

/* ---------- 消息区 ---------- */
.ai-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-size: 0.875rem;
}
.ai-msg {
  display: flex;
  flex-direction: column;
}
.ai-msg--user {
  align-items: flex-end;
}
.ai-msg--assistant {
  align-items: flex-start;
}
.ai-bubble {
  max-width: 88%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  line-height: 1.7;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.ai-msg--user .ai-bubble {
  background: var(--primary);
  color: var(--primary-foreground);
  border-top-right-radius: 0;
}
.ai-msg--assistant .ai-bubble {
  background: color-mix(in oklab, var(--muted) 70%, transparent);
  color: var(--foreground);
  border: 1px solid color-mix(in oklab, var(--border) 40%, transparent);
  border-top-left-radius: 0;
}
.ai-bubble p {
  margin: 0 0 0.5rem;
}
.ai-bubble p:last-child {
  margin-bottom: 0;
}
.ai-bubble ul,
.ai-bubble ol {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.25rem;
}
.ai-bubble li {
  margin: 0.125rem 0;
}
.ai-bubble code {
  padding: 0.1rem 0.32rem;
  border-radius: 0.375rem;
  background: color-mix(in oklab, var(--foreground) 10%, transparent);
  font-family: var(--font-geist-mono);
  font-size: 0.82em;
}
.ai-bubble pre {
  margin: 0.5rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 0.65rem;
  background: color-mix(in oklab, var(--foreground) 8%, transparent);
  overflow-x: auto;
}
.ai-bubble pre code {
  padding: 0;
  background: none;
  font-size: 0.78rem;
  line-height: 1.6;
}
.ai-cursor {
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: currentColor;
  opacity: 0.55;
  animation: ai-blink 1s steps(2, start) infinite;
}
@keyframes ai-blink {
  50% {
    opacity: 0;
  }
}

/* ---------- 深度思考过程（可折叠） ---------- */
.ai-think {
  margin-bottom: 0.625rem;
  padding: 0.625rem;
  border: 1px solid color-mix(in oklab, var(--primary) 20%, transparent);
  border-radius: 0.75rem;
  background: color-mix(in oklab, var(--primary) 5%, transparent);
  font-size: 0.75rem;
  color: var(--muted-foreground);
}
.ai-think__toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-family: var(--font-geist-mono);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.ai-think__toggle:hover {
  text-decoration: underline;
}
.ai-think__label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.ai-think__toggle svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}
.ai-think__content {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  max-height: 9rem;
  overflow-y: auto;
  border-top: 1px solid color-mix(in oklab, var(--border) 30%, transparent);
  font-family: var(--font-geist-mono);
  font-size: 11px;
  line-height: 1.65;
  white-space: pre-wrap;
  opacity: 0.8;
}
.ai-think__content[hidden] {
  display: none;
}

/* ---------- 参考文章 ---------- */
.ai-refs {
  margin-top: 0.75rem;
  padding-top: 0.625rem;
  border-top: 1px solid color-mix(in oklab, var(--border) 50%, transparent);
}
.ai-refs__label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted-foreground);
}
.ai-refs__list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.ai-refs a {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--primary);
  text-decoration: none;
}
.ai-refs a:hover {
  text-decoration: underline;
}
.ai-refs a svg {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
}

/* ---------- 推荐问题 ---------- */
.ai-suggest {
  padding: 0 1rem 0.5rem;
}
.ai-suggest__label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted-foreground);
}
.ai-suggest__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}
.ai-suggest button {
  padding: 0.25rem 0.625rem;
  border: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  border-radius: 9999px;
  background: color-mix(in oklab, var(--muted) 40%, transparent);
  color: color-mix(in oklab, var(--foreground) 80%, transparent);
  font-size: 0.75rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ai-suggest button:hover {
  border-color: color-mix(in oklab, var(--primary) 40%, transparent);
  background: color-mix(in oklab, var(--primary) 10%, transparent);
  color: var(--primary);
}

/* ---------- 输入区 ---------- */
.ai-foot {
  padding: 0.75rem;
  border-top: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  background: color-mix(in oklab, var(--muted) 20%, transparent);
}
.ai-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ai-input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--background);
  color: var(--foreground);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
}
.ai-input::placeholder {
  color: var(--muted-foreground);
}
.ai-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.ai-input:disabled {
  opacity: 0.5;
}
.ai-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  border: 0;
  border-radius: 0.75rem;
  background: var(--primary);
  color: var(--primary-foreground);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.ai-send:hover:not(:disabled) {
  transform: scale(1.06);
}
.ai-send:active:not(:disabled) {
  transform: scale(0.94);
}
.ai-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ai-send svg {
  width: 1rem;
  height: 1rem;
}
.ai-body::-webkit-scrollbar,
.ai-think__content::-webkit-scrollbar {
  width: 6px;
}
.ai-body::-webkit-scrollbar-thumb,
.ai-think__content::-webkit-scrollbar-thumb {
  border-radius: 9999px;
  background: color-mix(in oklab, var(--muted-foreground) 35%, transparent);
}
