/* ═══════════════════════════════════════════════════════════
   站内 AI 助手
   自包含：不依赖 styles.css 的变量，任何页面引入都能正常显示
   ═══════════════════════════════════════════════════════════ */

.aiw-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9998;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 12px 14px;
  border: 1px solid rgba(47, 116, 71, 0.28);
  border-radius: 999px;
  background: linear-gradient(135deg, #FFFFFF 0%, #FBF9F3 100%);
  color: #14201A;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(48, 62, 50, 0.14), 0 0 0 1px rgba(47, 116, 71, 0.04) inset;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease, opacity 0.2s ease;
}

.aiw-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 40px rgba(48, 62, 50, 0.18), 0 0 20px rgba(47, 116, 71, 0.10);
}

.aiw-launcher svg {
  width: 18px;
  height: 18px;
  color: #2F7447;
  flex: none;
}

.aiw-launcher.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(0.96);
}

/* ─────────── 面板 ─────────── */
.aiw-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - 128px));
  background: #FFFFFF;
  border: 1px solid rgba(16, 28, 22, 0.10);
  border-radius: 22px;
  box-shadow: 0 28px 70px rgba(48, 62, 50, 0.20);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px) scale(0.98);
  transition: opacity 0.24s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #14201A;
}

.aiw-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* ─────────── 头部 ─────────── */
.aiw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(16, 28, 22, 0.08);
  background: linear-gradient(180deg, rgba(47, 116, 71, 0.06), transparent);
  flex: none;
}

.aiw-head-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.aiw-head-main strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
}

.aiw-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2F7447;
  box-shadow: 0 0 0 4px rgba(47, 116, 71, 0.14);
  flex: none;
}

.aiw-model {
  display: block;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.66rem;
  color: #5F6E63;
  letter-spacing: 0.02em;
}

.aiw-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(16, 28, 22, 0.04);
  color: #5F6E63;
  cursor: pointer;
  flex: none;
  transition: background 0.2s ease, color 0.2s ease;
}

.aiw-close:hover {
  background: rgba(16, 28, 22, 0.07);
  color: #14201A;
}

.aiw-close svg {
  width: 15px;
  height: 15px;
}

/* ─────────── 消息区 ─────────── */
.aiw-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(16, 28, 22, 0.18) transparent;
}

.aiw-body::-webkit-scrollbar {
  width: 6px;
}

.aiw-body::-webkit-scrollbar-thumb {
  background: rgba(16, 28, 22, 0.16);
  border-radius: 999px;
}

.aiw-msg {
  display: flex;
  animation: aiw-in 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.aiw-msg--user {
  justify-content: flex-end;
}

.aiw-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.86rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.aiw-msg--bot .aiw-bubble {
  background: #F4F1E9;
  border: 1px solid rgba(16, 28, 22, 0.08);
  border-bottom-left-radius: 6px;
  color: #14201A;
}

.aiw-msg--user .aiw-bubble {
  background: linear-gradient(135deg, #348050, #245C38);
  color: #fff;
  font-weight: 500;
  border-bottom-right-radius: 6px;
}

.aiw-bubble--warn {
  background: rgba(180, 35, 24, 0.07) !important;
  border-color: rgba(180, 35, 24, 0.24) !important;
  color: #B42318 !important;
}

.aiw-bubble p {
  margin: 0 0 8px;
}

.aiw-bubble p:last-child {
  margin-bottom: 0;
}

.aiw-bubble ul {
  margin: 6px 0 8px;
  padding-left: 18px;
}

.aiw-bubble li {
  margin: 3px 0;
}

.aiw-bubble strong {
  color: #14201A;
  font-weight: 600;
}

.aiw-cite {
  display: inline-block;
  min-width: 15px;
  margin: 0 1px;
  padding: 0 3px;
  border-radius: 4px;
  background: rgba(47, 116, 71, 0.10);
  color: #245C38;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.68rem;
  line-height: 1.4;
  text-align: center;
  vertical-align: 1px;
}

/* ─────────── 加载动画 ─────────── */
.aiw-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px !important;
}

.aiw-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2F7447;
  opacity: 0.35;
  animation: aiw-bounce 1.15s infinite;
}

.aiw-typing span:nth-child(2) { animation-delay: 0.16s; }
.aiw-typing span:nth-child(3) { animation-delay: 0.32s; }

/* ─────────── 参考来源 ─────────── */
.aiw-sources {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  width: 100%;
}

.aiw-sources-label {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5F6E63;
}

.aiw-source {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(16, 28, 22, 0.08);
  border-radius: 10px;
  background: #FFFDF8;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.aiw-source:hover {
  border-color: rgba(47, 116, 71, 0.35);
  background: rgba(47, 116, 71, 0.06);
  transform: translateX(2px);
}

.aiw-source-cite {
  flex: none;
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(47, 116, 71, 0.10);
  color: #245C38;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.66rem;
  text-align: center;
  margin-top: 1px;
}

.aiw-source-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.aiw-source-title {
  font-size: 0.79rem;
  line-height: 1.45;
  color: #3F4E44;
}

.aiw-source-meta {
  font-size: 0.68rem;
  color: #5F6E63;
}

/* ─────────── 预设问题 ─────────── */
.aiw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.aiw-chip {
  padding: 7px 11px;
  border: 1px solid rgba(16, 28, 22, 0.13);
  border-radius: 999px;
  background: #FBF9F3;
  color: #4C5B51;
  font-family: inherit;
  font-size: 0.74rem;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.aiw-chip:hover {
  border-color: rgba(47, 116, 71, 0.40);
  background: rgba(47, 116, 71, 0.07);
  color: #245C38;
}

/* ─────────── 输入区 ─────────── */
.aiw-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px 10px;
  border-top: 1px solid rgba(16, 28, 22, 0.08);
  flex: none;
}

.aiw-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid rgba(16, 28, 22, 0.12);
  border-radius: 12px;
  background: #FFFDF8;
  color: #14201A;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.aiw-input::placeholder {
  color: #7A887C;
}

.aiw-input:focus {
  border-color: rgba(47, 116, 71, 0.45);
  background: rgba(47, 116, 71, 0.04);
}

.aiw-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #348050, #245C38);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.aiw-send svg {
  width: 17px;
  height: 17px;
}

.aiw-send:hover:not(:disabled) {
  transform: translateY(-1px);
}

.aiw-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.aiw-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 16px 12px;
  font-size: 0.68rem;
  color: #7A887C;
  flex: none;
}

.aiw-foot a {
  color: #245C38;
  text-decoration: none;
  white-space: nowrap;
}

.aiw-foot a:hover {
  text-decoration: underline;
}

/* ─────────── 动画 ─────────── */
@keyframes aiw-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes aiw-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ─────────── 移动端：全屏抽屉 ─────────── */
@media (max-width: 768px) {
  .aiw-launcher {
    right: 16px;
    bottom: 16px;
    padding: 12px 16px;
    font-size: 0.82rem;
  }

  .aiw-launcher-text {
    display: none;
  }

  .aiw-launcher svg {
    width: 20px;
    height: 20px;
  }

  .aiw-panel {
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    width: auto;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
    transform: translateY(100%);
  }

  .aiw-panel.is-open {
    transform: translateY(0);
  }

  body.aiw-lock {
    overflow: hidden;
  }

  .aiw-bubble {
    max-width: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .aiw-launcher,
  .aiw-panel,
  .aiw-msg,
  .aiw-typing span {
    transition: none !important;
    animation: none !important;
  }
}

/* 气泡与来源竖排容器 */
.aiw-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 88%;
  min-width: 0;
}

.aiw-stack .aiw-bubble {
  max-width: 100%;
}

@media (max-width: 768px) {
  .aiw-stack {
    max-width: 92%;
  }
}
