/* WaveMill 知识库智能体浮窗 */

html.wm-agent-scroll-lock,
body.wm-agent-scroll-lock {
  overflow: hidden !important;
  overscroll-behavior: none;
}

body.wm-agent-scroll-lock {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
}

.wm-agent-backdrop {
  display: none;
}

.wm-agent-root {
  --wm-agent-ink: #1f2937;
  --wm-agent-muted: #6b7280;
  --wm-agent-line: #e5e7eb;
  --wm-agent-panel: #ffffff;
  --wm-agent-input: #f3f4f6;
  --wm-agent-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9999;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--wm-agent-ink);
}

.wm-agent-fab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  color: var(--wm-agent-ink);
}

.wm-agent-fab:focus-visible {
  outline: 2px solid #2f6fed;
  outline-offset: 4px;
  border-radius: 12px;
}

.wm-agent-orb {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background:
    conic-gradient(
      from 210deg,
      #3b82f6,
      #8b5cf6,
      #ec4899,
      #f59e0b,
      #22d3ee,
      #3b82f6
    );
  box-shadow: 0 10px 28px rgba(59, 130, 246, 0.35);
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wm-agent-orb::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.wm-agent-fab:hover .wm-agent-orb {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 14px 32px rgba(139, 92, 246, 0.4);
}

.wm-agent-fab-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
}

.wm-agent-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  width: min(380px, calc(100vw - 28px));
  height: min(620px, calc(100vh - 110px));
  background: var(--wm-agent-panel);
  border-radius: 16px;
  box-shadow: var(--wm-agent-shadow);
  border: 1px solid rgba(229, 231, 235, 0.9);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.wm-agent-root.is-open .wm-agent-panel {
  display: flex;
  animation: wm-agent-in 0.22s ease;
}

@keyframes wm-agent-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.wm-agent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--wm-agent-line);
  flex-shrink: 0;
}

.wm-agent-title {
  font-size: 15px;
  font-weight: 650;
  margin: 0;
}

.wm-agent-actions {
  display: flex;
  gap: 4px;
}

.wm-agent-icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #4b5563;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.wm-agent-icon-btn:hover {
  background: #f3f4f6;
  color: #111827;
}

.wm-agent-icon-btn svg {
  width: 18px;
  height: 18px;
}

.wm-agent-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px 12px;
  background: #fff;
}

.wm-agent-welcome {
  text-align: center;
  padding: 28px 8px 8px;
}

.wm-agent-welcome .wm-agent-orb {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  box-shadow: 0 12px 30px rgba(99, 102, 241, 0.28);
}

.wm-agent-welcome .wm-agent-orb::after {
  inset: 13px;
}

.wm-agent-hello {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  color: #111827;
}

.wm-agent-hint {
  margin: 0;
  font-size: 13px;
  color: var(--wm-agent-muted);
  line-height: 1.5;
}

.wm-agent-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
}

.wm-agent-chip {
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  color: #374151;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.wm-agent-chip:hover {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: #1d4ed8;
}

.wm-agent-msgs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wm-agent-msg {
  max-width: 92%;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.wm-agent-msg.user {
  align-self: flex-end;
  background: #2f6fed;
  color: #fff;
  padding: 10px 12px;
  border-radius: 14px 14px 4px 14px;
}

.wm-agent-msg.bot {
  align-self: flex-start;
  background: #f3f4f6;
  color: #111827;
  padding: 10px 12px;
  border-radius: 14px 14px 14px 4px;
}

.wm-agent-msg.bot a {
  color: #1d4ed8;
  text-decoration: underline;
}

.wm-agent-typing {
  align-self: flex-start;
  color: var(--wm-agent-muted);
  font-size: 13px;
  padding: 4px 2px;
}

.wm-agent-footer {
  border-top: 1px solid var(--wm-agent-line);
  padding: 12px 14px 10px;
  background: #fff;
  flex-shrink: 0;
}

.wm-agent-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--wm-agent-input);
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
}

.wm-agent-input {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  font: inherit;
  /* 16px 避免 iOS 聚焦时页面缩放 */
  font-size: 16px;
  line-height: 1.45;
  color: #111827;
  min-height: 22px;
  max-height: 96px;
  padding: 4px 0;
  -webkit-appearance: none;
  appearance: none;
}

.wm-agent-input::placeholder {
  color: #9ca3af;
}

.wm-agent-send {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #d1d5db;
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.wm-agent-send.is-ready {
  background: #2f6fed;
}

.wm-agent-send:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.wm-agent-send svg {
  width: 16px;
  height: 16px;
}

.wm-agent-disclaimer {
  margin: 8px 2px 0;
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
  line-height: 1.4;
}

/* 移动端：近全屏抽屉 + 安全区 + 键盘适配 */
@media (max-width: 720px) {
  .wm-agent-root {
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    left: auto;
  }

  .wm-agent-fab {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .wm-agent-orb {
    width: 48px;
    height: 48px;
  }

  .wm-agent-fab-label {
    font-size: 11px;
  }

  .wm-agent-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    z-index: 9998;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .wm-agent-root.is-open .wm-agent-backdrop {
    display: block;
    animation: wm-agent-fade 0.2s ease;
  }

  .wm-agent-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: none;
    height: min(92vh, 100%);
    height: min(92dvh, 100%);
    max-height: calc(100vh - env(safe-area-inset-top, 0px));
    max-height: calc(100dvh - env(safe-area-inset-top, 0px));
    border-radius: 16px 16px 0 0;
    border: 0;
    box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.22);
    z-index: 9999;
  }

  .wm-agent-root.is-open .wm-agent-panel {
    animation: wm-agent-sheet 0.26s ease;
  }

  .wm-agent-root.is-open .wm-agent-fab {
    display: none;
  }

  .wm-agent-header {
    padding: 12px 12px 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top, 0px));
  }

  .wm-agent-title {
    font-size: 16px;
  }

  .wm-agent-icon-btn {
    width: 40px;
    height: 40px;
    touch-action: manipulation;
  }

  .wm-agent-body {
    padding: 16px 14px 10px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .wm-agent-welcome {
    padding: 16px 4px 4px;
  }

  .wm-agent-welcome .wm-agent-orb {
    width: 64px;
    height: 64px;
    margin-bottom: 14px;
  }

  .wm-agent-hello {
    font-size: 17px;
  }

  .wm-agent-hint {
    font-size: 13px;
    padding: 0 8px;
  }

  .wm-agent-shortcuts {
    margin-top: 14px;
    gap: 8px;
  }

  .wm-agent-chip {
    padding: 10px 14px;
    font-size: 13px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .wm-agent-msg {
    max-width: 88%;
    font-size: 15px;
  }

  .wm-agent-footer {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .wm-agent-input-wrap {
    padding: 10px 10px 10px 14px;
    border-radius: 14px;
  }

  .wm-agent-send {
    width: 40px;
    height: 40px;
    touch-action: manipulation;
  }

  .wm-agent-disclaimer {
    font-size: 10px;
    margin-top: 6px;
  }
}

@keyframes wm-agent-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes wm-agent-sheet {
  from {
    opacity: 0.96;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 横屏手机：降低高度，避免顶栏/键盘冲突 */
@media (max-width: 900px) and (max-height: 480px) {
  .wm-agent-panel {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .wm-agent-welcome {
    padding-top: 8px;
  }

  .wm-agent-welcome .wm-agent-orb {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
  }

  .wm-agent-hello {
    font-size: 15px;
  }
}
