/* ==========================================================================
   站内助手 · 悬浮入口与对话面板
   —— 浮层属于「导航/控制层」：玻璃主题下允许玻璃，扁平主题下用实色+描边
   —— 面板内所有文字色都走语义令牌，深浅色自动成立
   ========================================================================== */

.as-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 72;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(145deg, var(--color-primary) 0%, #5e5ce6 100%);
  box-shadow: 0 10px 26px rgba(0, 122, 255, 0.32), 0 2px 6px rgba(0, 0, 0, 0.12);
  transition: transform 0.18s cubic-bezier(0.32, 0.72, 0, 1), box-shadow 0.18s ease;
}

.as-launcher:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 32px rgba(0, 122, 255, 0.38), 0 3px 8px rgba(0, 0, 0, 0.14);
}

.as-launcher:active {
  transform: scale(0.96);
}

.as-launcher svg {
  width: 25px;
  height: 25px;
}

.as-launcher[aria-expanded="true"] {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

/* --------------------------------------------------------------- 面板骨架 */

.as-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 73;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: min(660px, calc(100dvh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 22px;
  background: var(--color-surface);
  box-shadow: var(--shadow-3);
  opacity: 0;
  transform: translateY(12px) scale(0.985);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.as-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

html[data-design="glass"] .as-panel {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border-color: var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-edge-top), var(--glass-edge-bottom), var(--shadow-3);
}

.as-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.as-avatar {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(145deg, var(--color-primary) 0%, #5e5ce6 100%);
}

.as-avatar svg {
  width: 19px;
  height: 19px;
}

.as-id {
  min-width: 0;
  flex: 1;
}

.as-name {
  display: block;
  font-size: var(--text-body-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: -0.01em;
}

.as-engine {
  display: block;
  margin-top: 1px;
  font-size: var(--text-caption);
  color: var(--color-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.as-close {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.as-close:hover {
  background: var(--color-hover);
  color: var(--color-text-primary);
}

.as-close svg {
  width: 16px;
  height: 16px;
}

/* --------------------------------------------------------------- 消息流 */

.as-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}

.as-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: as-in 0.22s ease both;
}

.as-row.is-user {
  flex-direction: row-reverse;
}

@keyframes as-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.as-mini {
  flex: none;
  width: 26px;
  height: 26px;
  margin-top: 2px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(145deg, var(--color-primary) 0%, #5e5ce6 100%);
}

.as-mini svg {
  width: 15px;
  height: 15px;
}

.as-row.is-user .as-mini {
  display: none;
}

.as-bubble {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 15px;
  font-size: var(--text-body-sm);
  line-height: 1.62;
  color: var(--color-text-primary);
  background: var(--color-surface-sunken);
  word-break: break-word;
}

.as-row.is-user .as-bubble {
  background: var(--color-primary-solid);
  color: var(--color-on-primary);
  border-bottom-right-radius: 5px;
}

.as-row.is-bot .as-bubble {
  border-bottom-left-radius: 5px;
}

.as-bubble p {
  margin: 0;
}

.as-bubble p + p {
  margin-top: 8px;
}

.as-bubble ul {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.as-bubble li {
  position: relative;
  padding-left: 13px;
  margin-top: 4px;
}

.as-bubble li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.66em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-text-tertiary);
}

.as-bubble strong {
  font-weight: 600;
}

.as-bubble code {
  padding: 1px 5px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--color-surface-sunken-strong);
  color: var(--color-text-primary);
}

.as-row.is-user .as-bubble code {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* 答案下方的工具/页面入口 */
.as-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.as-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-size: var(--text-caption);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.as-action:hover {
  background: var(--color-primary-soft);
  border-color: transparent;
  color: var(--color-primary);
}

.as-action:active {
  transform: scale(0.97);
}

.as-action svg {
  width: 13px;
  height: 13px;
  opacity: 0.8;
}

.as-intro {
  align-self: stretch;
  margin: 0 2px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--color-surface-sunken);
}

.as-intro-title {
  margin: 0 0 6px;
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--color-text-secondary);
}

.as-intro ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.as-intro li {
  position: relative;
  padding-left: 13px;
  margin-top: 3px;
  font-size: var(--text-caption);
  line-height: 1.65;
  color: var(--color-text-secondary);
}

.as-intro li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.72em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-primary);
  opacity: 0.7;
}

/* 打字指示 */
.as-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 2px;
}

.as-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-tertiary);
  animation: as-blink 1.1s infinite ease-in-out;
}

.as-typing i:nth-child(2) {
  animation-delay: 0.16s;
}

.as-typing i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes as-blink {
  0%, 80%, 100% {
    opacity: 0.25;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* --------------------------------------------------------------- 输入区 */

.as-foot {
  flex: none;
  border-top: 1px solid var(--color-border);
  padding: 10px 12px 12px;
}

.as-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 2px 9px;
  scrollbar-width: none;
}

.as-chips::-webkit-scrollbar {
  display: none;
}

.as-chip {
  flex: none;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--text-caption);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.as-chip:hover {
  background: var(--color-primary-soft);
  border-color: transparent;
  color: var(--color-primary);
}

.as-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  background: var(--color-surface);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.as-form:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.as-input {
  flex: 1;
  min-height: 28px;
  max-height: 96px;
  padding: 4px 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--color-text-primary);
  font-family: inherit;
  font-size: var(--text-body-sm);
  line-height: 1.5;
}

.as-input::placeholder {
  color: var(--color-text-placeholder);
}

.as-send {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 11px;
  background: var(--color-primary-solid);
  color: var(--color-on-primary);
  cursor: pointer;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.as-send:disabled {
  opacity: 0.4;
  cursor: default;
}

.as-send:not(:disabled):active {
  transform: scale(0.94);
}

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

.as-tip {
  margin-top: 7px;
  text-align: center;
  font-size: var(--text-micro);
  color: var(--color-text-tertiary);
}

/* --------------------------------------------------------------- 移动端 */

@media (max-width: 560px) {
  .as-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 50px;
    height: 50px;
  }

  /* 移动端是整屏抽屉：玻璃透出底下的页面会干扰阅读，直接用实色 */
  html[data-design="glass"] .as-panel {
    background: var(--color-surface);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border-color: var(--color-border);
    box-shadow: var(--shadow-3);
  }

  .as-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: min(88dvh, 720px);
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    transform: translateY(24px);
  }

  .as-panel.is-open {
    transform: none;
  }

  .as-bubble {
    max-width: 88%;
  }

  .as-foot {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .as-panel,
  .as-launcher,
  .as-row {
    transition: none;
    animation: none;
  }
}
