/* ==========================================================================
   启序 Agent 智能助手 / 二维码弹窗
   ========================================================================== */

/* ============================ 悬浮入口 ============================ */
.agent-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1100;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 18px 6px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(135deg, #101a3d 0%, #0a1022 100%);
  color: #fff;
  box-shadow: 0 20px 44px -18px rgba(9, 14, 30, 0.85);
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease), opacity 0.3s var(--ease), visibility 0.3s;
}
.agent-launcher:hover { transform: translateY(-3px); box-shadow: 0 26px 52px -18px rgba(30, 58, 138, 0.9); }
.agent-launcher.is-hidden { opacity: 0; visibility: hidden; transform: translateY(10px) scale(0.96); pointer-events: none; }

.launcher-avatar {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
/* Q 环与橙色破格一笔作为整体旋转；viewBox 已对齐真实圆心，
   旋转始终围绕圆心，且整体落在白色圆形背景内 */
.launcher-logo {
  width: 26px;
  height: auto;
  overflow: visible;
  transform-origin: 50% 50%;
  animation: logo-spin 7s linear infinite;
  will-change: transform;
}
@keyframes logo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.launcher-text {
  position: relative;
  z-index: 1;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.launcher-dot {
  position: relative;
  z-index: 1;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7ee0b0;
  box-shadow: 0 0 8px 2px rgba(126, 224, 176, 0.6);
}

/* ============================ 对话面板 ============================ */
.agent-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 1150;
  display: flex;
  flex-direction: column;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: min(632px, calc(100vh - 132px));
  border-radius: 22px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
  box-shadow: 0 40px 100px -34px rgba(8, 12, 28, 0.55);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.98);
  transform-origin: 100% 100%;
  transition: opacity 0.32s var(--ease), transform 0.32s var(--ease), visibility 0.32s;
}
.agent-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.agent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(120deg, #0d1531 0%, #131f47 100%);
  color: #fff;
}
.agent-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.agent-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  flex: none;
}
.agent-avatar img { width: 21px; height: auto; }
.agent-id strong { display: block; font-size: 14px; font-weight: 700; letter-spacing: 0.02em; }
.agent-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
  font-size: 10.8px;
  color: rgba(255, 255, 255, 0.55);
}
.agent-sub .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7ee0b0;
  box-shadow: 0 0 6px 1px rgba(126, 224, 176, 0.6);
}
.agent-head-actions { display: flex; align-items: center; gap: 2px; }
.agent-head .icon-btn { width: 32px; height: 32px; color: rgba(255, 255, 255, 0.7); }
.agent-head .icon-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.agent-head .icon-btn .icon { font-size: 16px; }

/* ---------- 模型配置 ---------- */
.agent-config {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "title title"
    "provider model"
    "key key"
    "base base"
    "actions actions"
    "warn warn";
  gap: 8px 10px;
  padding: 12px 15px 14px;
  border-bottom: 1px solid var(--line);
  background: #f4f6fd;
  max-height: 64%;
  overflow-y: auto;
}
.agent-config[hidden] { display: none; }
.config-title {
  grid-area: title;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.04em;
}
.agent-config label:nth-of-type(1) { grid-area: provider; }
.agent-config label:nth-of-type(2) { grid-area: key; }
.agent-config label:nth-of-type(3) { grid-area: model; }
.agent-config label:nth-of-type(4) { grid-area: base; }
.config-actions { grid-area: actions; }
.config-warn { grid-area: warn; }
.agent-config label { display: grid; gap: 4px; font-size: 11px; color: var(--text-3); }
.agent-config input,
.agent-config select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12.5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.agent-config input:focus,
.agent-config select:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.config-actions { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.config-hint { font-size: 10.5px; color: var(--text-3); line-height: 1.5; }
.config-warn {
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #b45309;
  font-size: 10.5px;
  line-height: 1.6;
}

/* ---------- 消息区 ---------- */
.agent-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 14px 12px;
  background:
    radial-gradient(80% 50% at 100% 0%, rgba(79, 70, 229, 0.06), transparent 70%),
    #f8f9fd;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.agent-body::-webkit-scrollbar { width: 6px; }
.agent-body::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.16); border-radius: 6px; }

.agent-messages { display: flex; flex-direction: column; gap: 14px; }
.message { display: flex; flex-direction: column; max-width: 88%; }
.message-user { align-self: flex-end; align-items: flex-end; }
.message-bot { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13.4px;
  line-height: 1.72;
  word-break: break-word;
}
.message-user .bubble {
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 10px 24px -16px rgba(79, 70, 229, 0.9);
}
.message-bot .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: #172038;
  box-shadow: 0 8px 20px -18px rgba(15, 23, 42, 0.4);
}
.bubble p + p { margin-top: 8px; }
.bubble ul { margin: 7px 0 0; display: grid; gap: 4px; }
.bubble li { position: relative; padding-left: 13px; }
.bubble li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.68em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--periwinkle);
}
.bubble strong { font-weight: 700; color: #101a3d; }
.bubble code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(79, 70, 229, 0.09);
  font-family: var(--font-mono);
  font-size: 12px;
}
.bubble pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #0d1531;
  color: #dbe3ff;
  overflow-x: auto;
  font-size: 11.5px;
  line-height: 1.6;
}
.bubble pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.bubble .bubble-link { color: var(--indigo); text-decoration: underline; text-underline-offset: 2px; }

.message-meta { margin-top: 4px; font-size: 10px; color: var(--text-3); letter-spacing: 0.02em; }

.message-error .bubble {
  border-color: #fecdca;
  background: #fef3f2;
  color: #912018;
}
.message-error .bubble strong { color: #912018; }

.typing-dots { display: inline-flex; align-items: center; gap: 4px; padding: 4px 0; }
.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--periwinkle);
  animation: dot-bounce 1.1s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- 建议问题 ---------- */
.agent-suggest { margin-top: auto; padding-top: 6px; }
.agent-suggest > p { font-size: 10.5px; letter-spacing: 0.12em; color: var(--text-3); margin-bottom: 8px; }
.suggest-list { display: flex; flex-wrap: wrap; gap: 7px; }
.suggest-list button {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.4;
  text-align: left;
  transition: border-color 0.25s var(--ease), color 0.25s var(--ease), background 0.25s var(--ease);
}
.suggest-list button:hover {
  border-color: rgba(79, 70, 229, 0.4);
  color: var(--indigo);
  background: rgba(79, 70, 229, 0.05);
}

/* ---------- 输入区 ---------- */
.agent-composer {
  padding: 10px 13px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #fff;
}
.composer-inner { display: flex; align-items: flex-end; gap: 8px; }
.composer-inner textarea {
  flex: 1;
  min-height: 42px;
  max-height: 118px;
  padding: 10px 13px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  font-size: 13.4px;
  line-height: 1.55;
  resize: none;
  outline: none;
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.composer-inner textarea:focus {
  border-color: rgba(79, 70, 229, 0.5);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--grad-fire);
  color: #fff;
  box-shadow: 0 10px 22px -12px rgba(255, 122, 26, 0.9);
  transition: transform 0.25s var(--ease), opacity 0.25s var(--ease);
}
.send-btn .icon { font-size: 17px; }
.send-btn:hover { transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.stop-btn { background: #0d1531; box-shadow: none; }
.stop-btn span { width: 10px; height: 10px; border-radius: 2px; background: #fff; }
.composer-note {
  margin-top: 7px;
  text-align: center;
  font-size: 10px;
  color: var(--text-3);
}

/* ============================ 二维码弹窗 ============================ */
.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s var(--ease), visibility 0.28s;
}
.qr-modal.is-open { opacity: 1; visibility: visible; }
.qr-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 21, 0.72);
  backdrop-filter: blur(7px);
}
.qr-modal-card {
  position: relative;
  width: min(370px, 100%);
  padding: 30px 26px 24px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 50px 110px -40px rgba(0, 0, 0, 0.7);
  text-align: center;
  transform: translateY(14px) scale(0.97);
  transition: transform 0.32s var(--ease);
}
.qr-modal.is-open .qr-modal-card { transform: none; }
.qr-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  color: var(--text-3);
}
.qr-modal-close:hover { background: var(--paper-2); color: var(--text); }
.qr-modal-badge {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: rgba(255, 122, 26, 0.11);
  color: var(--orange);
  font-size: 21px;
}
.qr-modal-card h3 { font-size: 18px; font-weight: 800; letter-spacing: 0.01em; }
.qr-modal-card > p {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.7;
}
.qr-modal-code {
  width: fit-content;
  margin: 16px auto 12px;
  padding: 0;
  background: transparent;
}
.qr-modal-code svg {
  width: 224px;
  height: auto;
  border-radius: 18px;
  box-shadow: 0 14px 30px -18px rgba(10, 18, 45, 0.45);
}
.qr-modal-actions { display: flex; gap: 8px; }
.qr-modal-actions .btn { flex: 1; min-width: 0; padding: 0 12px; }
.qr-modal-url {
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  word-break: break-all;
}
.qr-modal-note { margin-top: 10px; font-size: 11px; color: var(--text-3); }

/* ============================ 响应式 ============================ */
@media (max-width: 560px) {
  .agent-launcher {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    padding: 5px 14px 5px 5px;
  }
  .launcher-avatar { width: 40px; height: 40px; }
  .launcher-text { display: none; }
  .agent-launcher { padding: 5px; }
  .launcher-dot { position: absolute; top: 6px; right: 6px; }

  .agent-panel {
    right: 0;
    bottom: auto;
    top: var(--vv-top, 0px);
    width: 100%;
    max-width: none;
    height: var(--vv-height, 100dvh);
    max-height: none;
    border-radius: 0;
    border: 0;
  }
  .agent-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .agent-config { max-height: 46%; }
  .agent-body { padding-bottom: 8px; }
  .qr-modal-card { padding: 28px 20px 22px; }
  .qr-modal-code svg { width: 196px; height: auto; }
  .qr-modal-actions .btn { font-size: 13.5px; }
}
