/* ============================================================
   Agent 悬浮助手 · 样式（2026-10-28 第二版）
   ------------------------------------------------------------
   结构：.ab-shell（可拖拽，右侧锚定 + 横向 flex）
           ├ .ab-side.left    （从面板左侧向外弹出）
           ├ .ab-panel        （可上下拉伸）
           └ .ab-side.right   （从面板右侧向外弹出）
   侧栏在面板外面，不遮挡面板内容；右锚定保证整体向左生长。
   ============================================================ */

:root {
  --ab-header: #4A3F9E;
  --ab-border: #4A3F9E;
  --ab-body: #C6AEEE;
  --ab-card: #ffffff;
  --ab-text: #1c1c1a;
  --ab-muted: #6b6b66;
  --ab-line: rgba(28, 28, 26, .12);
  --ab-accent: #534AB7;
}

.ab-hidden { display: none !important; }

/* ---------- 悬浮气泡 ---------- */
.ab-bubble {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  background: transparent url('/agent/bubble.jpg') center / cover no-repeat;
  box-shadow: 0 8px 22px rgba(74, 63, 158, .32), 0 0 0 1px rgba(74, 63, 158, .18);
  cursor: grab;
  z-index: 300;
  transition: transform .16s ease, box-shadow .16s ease;
  touch-action: none;
}
.ab-bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(74, 63, 158, .42), 0 0 0 1px rgba(74, 63, 158, .25);
}
.ab-bubble:active { cursor: grabbing; transform: scale(.97); }

/* ---------- 外壳：右侧锚定 + 横向排列 ---------- */
.ab-shell {
  /* 只装面板；左右侧栏绝对定位挂在面板两侧外面，不参与高度计算，
     否则卡片一多侧栏会把整块外壳撑高、无限往下延伸 */
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 300;
  font-size: 14px;
  color: var(--ab-text);
  transition: transform .2s ease;
}
/* 右栏展开时整块往左让 272px，否则栏位会顶到屏幕外 */
.ab-shell.right-open { transform: translateX(-272px); }

/* ---------- 面板 ---------- */
.ab-panel {
  position: relative;
  width: 404px;
  height: 660px;
  min-height: 380px;
  background: var(--ab-body);
  border: 2px solid var(--ab-border);
  border-radius: 18px;
  box-shadow: 0 22px 54px rgba(40, 30, 90, .28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 0 0 auto;
}

/* ---------- 头部（同时是拖拽把手） ---------- */
.ab-head {
  height: 52px;
  flex: 0 0 52px;
  background: var(--ab-header);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  cursor: grab;
  user-select: none;
}
.ab-head.dragging { cursor: grabbing; }
.ab-head .ab-title {
  flex: 1;
  color: rgba(255, 255, 255, .94);
  font-size: 13px;
  letter-spacing: .3px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ab-iconbtn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .12s;
}
.ab-iconbtn:hover { background: rgba(255, 255, 255, .16); }
.ab-iconbtn.on { background: rgba(255, 255, 255, .26); }

/* ---------- 消息区 ---------- */
.ab-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ab-body::-webkit-scrollbar { width: 6px; }
.ab-body::-webkit-scrollbar-thumb { background: rgba(74, 63, 158, .28); border-radius: 3px; }

.ab-msg { max-width: 92%; }
.ab-msg.user { align-self: flex-end; }
.ab-msg.user .ab-bubbletext {
  background: var(--ab-accent);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 10px 13px;
  white-space: pre-wrap;
  word-break: break-word;
}
.ab-msg.bot { align-self: flex-start; width: 92%; }
/* 助手回答不再套气泡（Taylor 2026-10-28 要求，参考豆包）：直接平铺整块文字 */
.ab-msg.bot .ab-bubbletext {
  width: 100%;
  background: transparent;
  border-radius: 0;
  padding: 0;
  line-height: 1.75;
  box-shadow: none;
  word-break: break-word;
}
.ab-msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.ab-msg.bot { display: flex; flex-direction: column; align-items: flex-start; }

/* ---------- 消息底部：时间 + 复制 / 赞 / 踩 ---------- */
.ab-meta {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 3px;
  height: 22px;
  opacity: 0;
  transition: opacity .12s ease;
}
.ab-msg.bot .ab-meta { opacity: 1; }
.ab-msg.user:hover .ab-meta { opacity: 1; }
.ab-meta .t {
  font-size: 11px;
  color: rgba(58, 48, 120, .55);
  margin: 0 4px;
  white-space: nowrap;
}
.ab-meta button {
  width: 24px; height: 24px;
  border: 0; padding: 0;
  background: transparent;
  border-radius: 6px;
  color: rgba(58, 48, 120, .55);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.ab-meta button:hover { background: rgba(74, 63, 158, .10); color: var(--ab-accent); }
.ab-meta button.on { color: var(--ab-accent); background: rgba(74, 63, 158, .14); }
.ab-meta button svg { width: 14px; height: 14px; }
.ab-meta .ok { color: #2F7A3F; }

.ab-bubbletext p { margin: 0 0 8px; }
.ab-bubbletext p:last-child { margin-bottom: 0; }
.ab-bubbletext ul { margin: 4px 0 8px; padding-left: 18px; }
.ab-bubbletext li { margin: 3px 0; }
.ab-bubbletext strong { font-weight: 600; }
.ab-sec {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  padding: 2px 8px;
  border-radius: 999px;
  margin: 2px 0 6px;
}
.ab-sec.data { background: #E8F0DC; color: #3B6D11; }
.ab-sec.judge { background: #FDF0D8; color: #8A5A00; }

.ab-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.ab-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(74, 63, 158, .55);
  animation: ab-blink 1.1s infinite ease-in-out;
}
.ab-typing i:nth-child(2) { animation-delay: .18s; }
.ab-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes ab-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.ab-note { font-size: 12px; color: var(--ab-muted); margin-top: 6px; }

/* ---------- 空态 ---------- */
.ab-empty { margin: auto 0; padding: 0 6px 12px; color: #2c2350; }
.ab-empty h4 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.ab-empty p { margin: 0 0 16px; font-size: 13px; line-height: 1.6; color: #3d3363; }
.ab-chips { display: flex; flex-direction: column; gap: 8px; }
.ab-chip {
  text-align: left;
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--ab-text);
  cursor: pointer;
  transition: background .12s, transform .12s;
}
.ab-chip:hover { background: #fff; transform: translateX(2px); }

/* ---------- 输入卡 ---------- */
.ab-composer {
  flex: 0 0 auto;
  margin: 10px 12px 12px;
  background: var(--ab-card);
  border-radius: 16px;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(40, 30, 90, .10);
}
.ab-input {
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  font: inherit;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ab-text);
  background: transparent;
  min-height: 46px;
  max-height: 120px;
  padding: 2px 2px 8px;
}
.ab-input::placeholder { color: #9a96a8; }
.ab-tools { display: flex; align-items: center; justify-content: space-between; }
.ab-attach {
  width: 30px; height: 30px;
  border: 0; background: transparent;
  color: var(--ab-text);
  font-size: 20px; line-height: 1;
  cursor: pointer; border-radius: 8px;
  display: grid; place-items: center;
}
.ab-attach:hover { background: #f0eefb; }
.ab-send {
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: var(--ab-accent);
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  transition: opacity .12s, transform .12s;
}
.ab-send:disabled { opacity: .35; cursor: not-allowed; }
.ab-send:not(:disabled):hover { transform: scale(1.05); }

/* ---------- 上下拉伸把手 ---------- */
.ab-resize {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 9px;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  z-index: 4;
}
.ab-resize::after {
  content: '';
  width: 42px;
  height: 3px;
  border-radius: 2px;
  background: rgba(74, 63, 158, .30);
  transition: background .12s;
}
.ab-resize:hover::after { background: rgba(74, 63, 158, .65); }

/* ---------- 左右拉伸把手（面板左缘） ---------- */
.ab-resize-x {
  position: absolute;
  left: 0; top: 56px; bottom: 12px;
  width: 9px;
  cursor: ew-resize;
  z-index: 4;
  touch-action: none;
}
.ab-resize-x::after {
  content: '';
  position: absolute;
  left: 3px; top: 50%;
  width: 3px; height: 46px;
  margin-top: -23px;
  border-radius: 2px;
  background: rgba(74, 63, 158, .18);
  transition: background .12s;
}
.ab-resize-x:hover::after { background: rgba(74, 63, 158, .6); }

/* ---------- 待发送附件 ---------- */
.ab-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ab-filechip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #EEEDFE; color: #3C3489;
  border-radius: 8px; padding: 4px 6px 4px 9px;
  font-size: 12px; max-width: 100%;
}
.ab-filechip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
.ab-filechip em { font-style: normal; color: #7F77DD; font-size: 11px; }
.ab-filechip button {
  border: 0; background: transparent; cursor: pointer;
  color: #7F77DD; font-size: 14px; line-height: 1; padding: 0 2px;
}
.ab-filechip button:hover { color: #3C3489; }

/* ---------- 产出物里的下载链接 ---------- */
.ab-dl {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 8px; color: var(--ab-accent);
  font-size: 12px; font-weight: 500; text-decoration: none;
  border: 1px solid rgba(83, 74, 183, .35);
  border-radius: 7px; padding: 4px 9px;
}
.ab-dl:hover { background: #EEEDFE; }

/* ---------- 左右侧栏：在面板外侧 ---------- */
.ab-side {
  /* index.html 有一条全局 aside{height:100vh;position:sticky} —— 这里用 div，
     再显式钉一遍定位，防止被主框架的侧栏规则带跑 */
  position: absolute;
  top: 0;
  bottom: 0;
  padding: 0;
  box-sizing: border-box;
  width: 0;
  opacity: 0;
  overflow: hidden;
  background: #ffffff;
  border: 2px solid var(--ab-border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  transition: width .2s ease, opacity .16s ease;
}
.ab-side.left  { right: calc(100% + 10px); }
.ab-side.right { left: calc(100% + 10px); }
.ab-side.show { width: 246px; opacity: 1; }
.ab-side.right.show { width: 262px; }

.ab-side-inner { width: 246px; height: 100%; display: flex; flex-direction: column; }
.ab-side.right .ab-side-inner { width: 262px; }

.ab-side-head {
  padding: 12px;
  border-bottom: 1px solid var(--ab-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ab-muted);
  flex: 0 0 auto;
}
.ab-newchat {
  width: 100%;
  border: 1px solid var(--ab-accent);
  background: var(--ab-accent);
  color: #fff;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}
.ab-newchat:hover { filter: brightness(1.06); }
.ab-side-body { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }

.ab-session {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  color: var(--ab-text);
  cursor: pointer;
  margin-bottom: 2px;
}
.ab-session:hover { background: #f4f2fd; }
.ab-session.on { background: #EEEDFE; color: var(--ab-accent); font-weight: 600; }
.ab-session small { display: block; color: #9a96a8; font-size: 11px; margin-top: 2px; font-weight: 400; }

.ab-artifact {
  border: 1px solid var(--ab-line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  font-size: 12px;
}
.ab-artifact h5 { margin: 0 0 2px; font-size: 12px; font-weight: 600; }
.ab-artifact .sub { color: #9a96a8; font-size: 11px; margin-bottom: 6px; }
.ab-artifact .line { color: #3d3363; line-height: 1.7; }
.ab-empty-side { color: #9a96a8; font-size: 12px; padding: 16px 8px; text-align: center; line-height: 1.7; }

/* ---------- 小提示 ---------- */
.ab-toast {
  position: absolute;
  left: 50%;
  bottom: 108px;
  transform: translateX(-50%);
  background: rgba(28, 28, 26, .88);
  color: #fff;
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 8px;
  z-index: 5;
  max-width: 80%;
  text-align: center;
}

/* ---------- 窄屏：侧栏改为压在面板上，避免横向溢出 ---------- */
@media (max-width: 780px) {
  .ab-shell { right: 8px; left: 8px; }
  .ab-shell.right-open { transform: none; }
  .ab-panel { width: 100%; }
  .ab-side { transition: width .2s ease, opacity .16s ease; }
  .ab-side.left { right: auto; left: 0; }
  .ab-side.right { left: auto; right: 0; }
}
