/* ============================================================
   AI 悬浮窗插件 - iOS 风格样式
   aiv.css  v3.2
   ============================================================ */

:root {
  --aiv-c:    #007AFF;
  --aiv-cl:   #409CFF;
  --aiv-cd:   #0056CC;
  --aiv-bg:   rgba(242,242,247,.94);
  --aiv-sf:   rgba(255,255,255,.90);
  --aiv-bd:   rgba(0,0,0,.08);
  --aiv-bds:  rgba(0,0,0,.14);
  --aiv-shs:  0 2px 8px rgba(0,0,0,.08),0 0 0 .5px rgba(0,0,0,.06);
  --aiv-shl:  0 20px 60px rgba(0,0,0,.18),0 4px 16px rgba(0,0,0,.10);
  --aiv-t1:   #1C1C1E;
  --aiv-t2:   #6C6C70;
  --aiv-t3:   #AEAEB2;
  --aiv-ub:   #007AFF;
  --aiv-ubt:  #FFFFFF;
  --aiv-ab:   #FFFFFF;
  --aiv-abt:  #1C1C1E;
  --aiv-rsm:  10px;
  --aiv-rmd:  16px;
  --aiv-rlg:  22px;
  --aiv-rxl:  28px;
  --aiv-f:    -apple-system,'SF Pro Text','SF Pro Display','Helvetica Neue',sans-serif;
  --aiv-m:    'SF Mono','Fira Code','JetBrains Mono',Menlo,monospace;
  --aiv-sp:   cubic-bezier(0.34,1.56,0.64,1);
  --aiv-ez:   cubic-bezier(0.32,0.72,0,1);
  --aiv-z:    999999;
}

/* ── 触发按钮 ── */
#aiv-btn {
  position: fixed;
  bottom: 28px; right: 24px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--aiv-c);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,122,255,.40),0 1px 4px rgba(0,0,0,.12),inset 0 1px 0 rgba(255,255,255,.20);
  z-index: var(--aiv-z);
  outline: none; -webkit-tap-highlight-color: transparent;
  transition: transform .35s var(--aiv-sp), box-shadow .25s ease;
}
#aiv-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0,122,255,.50),0 2px 8px rgba(0,0,0,.14),inset 0 1px 0 rgba(255,255,255,.20);
}
#aiv-btn:active { transform: scale(.93); transition-duration: .12s; }

.aiv-ti {
  position: absolute; display: flex; align-items: center; justify-content: center;
  transition: opacity .2s ease, transform .3s var(--aiv-ez);
}
.aiv-ti-chat  { opacity: 1; transform: scale(1) rotate(0deg); }
.aiv-ti-close { opacity: 0; transform: scale(.6) rotate(-90deg); }
#aiv-btn.aiv-open .aiv-ti-chat  { opacity: 0; transform: scale(.6) rotate(90deg); }
#aiv-btn.aiv-open .aiv-ti-close { opacity: 1; transform: scale(1) rotate(0deg); }

.aiv-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #FF3B30; color: #fff;
  font-size: 11px; font-weight: 700; font-family: var(--aiv-f);
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px #fff;
  animation: aiv-bpop .4s var(--aiv-sp);
}
@keyframes aiv-bpop { from{transform:scale(0)} to{transform:scale(1)} }

/* ── 主窗口 ── */
#aiv-win {
  position: fixed;
  bottom: 96px; right: 24px;
  width: 380px; height: 600px;
  min-width: 300px; min-height: 400px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 40px);
  background: var(--aiv-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-radius: var(--aiv-rxl);
  border: .5px solid var(--aiv-bds);
  box-shadow: var(--aiv-shl);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: var(--aiv-z);
  transform-origin: bottom right;
  transform: scale(.85) translateY(20px);
  opacity: 0; pointer-events: none;
  transition: transform .45s var(--aiv-sp), opacity .3s ease;
  font-family: var(--aiv-f);
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
}
#aiv-win.aiv-vis {
  transform: scale(1) translateY(0);
  opacity: 1; pointer-events: all;
}
#aiv-win.aiv-drag,
#aiv-win.aiv-rsz {
  transition: none;
  box-shadow: 0 24px 80px rgba(0,0,0,.22),0 4px 20px rgba(0,0,0,.12);
}

/* ── 顶栏（拖拽区域）── */
.aiv-hdr {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 12px;
  background: var(--aiv-sf);
  border-bottom: .5px solid var(--aiv-bd);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
  cursor: grab; position: relative;
}
.aiv-hdr:active { cursor: grabbing; }

.aiv-drag-bar {
  position: absolute;
  top: 6px; left: 50%; transform: translateX(-50%);
  width: 36px; height: 4px;
  background: rgba(0,0,0,.12); border-radius: 2px;
  pointer-events: none;
}
@media (prefers-color-scheme: dark) {
  .aiv-drag-bar { background: rgba(255,255,255,.15); }
}

.aiv-hd-av {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(145deg, var(--aiv-cl), var(--aiv-c));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,122,255,.30);
  pointer-events: none;
}
.aiv-hd-av img { width:100%; height:100%; object-fit:cover; }

.aiv-hd-info { flex:1; min-width:0; pointer-events:none; }
.aiv-hd-name { font-size:15px; font-weight:600; color:var(--aiv-t1); letter-spacing:-.2px; line-height:1.2; }
.aiv-hd-st   { display:flex; align-items:center; gap:5px; margin-top:2px; }

.aiv-sdot {
  width:7px; height:7px; border-radius:50%;
  background:#34C759; box-shadow:0 0 0 2px rgba(52,199,89,.25);
  animation: aiv-pulse 2.5s ease-in-out infinite;
}
@keyframes aiv-pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

.aiv-stxt { font-size:11.5px; color:var(--aiv-t2); }

.aiv-hd-acts { display:flex; align-items:center; gap:4px; }
.aiv-hdbtn {
  width:32px; height:32px; border-radius:50%;
  border:none; background:transparent;
  cursor:pointer; display:flex; align-items:center; justify-content:center;
  color:var(--aiv-t2);
  transition:background .15s, color .15s, transform .15s;
  outline:none; -webkit-tap-highlight-color:transparent;
  pointer-events:auto;
}
.aiv-hdbtn:hover { background:rgba(0,0,0,.06); color:var(--aiv-t1); }
.aiv-hdbtn:active { transform:scale(.88); background:rgba(0,0,0,.10); }

/* 移动端关闭按钮：桌面隐藏，移动端显示 */
.aiv-mob-close { display: none; }

/* ── 消息区 ── */
.aiv-msgs {
  flex:1; overflow-y:auto;
  padding:12px 12px 8px;
  display:flex; flex-direction:column; gap:2px;
  scroll-behavior:smooth; overscroll-behavior:contain;
  user-select:text; -webkit-user-select:text;
}
.aiv-msgs::-webkit-scrollbar { width:4px; }
.aiv-msgs::-webkit-scrollbar-track { background:transparent; }
.aiv-msgs::-webkit-scrollbar-thumb { background:rgba(0,0,0,.15); border-radius:2px; }

.aiv-divider { text-align:center; margin:10px 0 8px; }
.aiv-divider span {
  font-size:11px; color:var(--aiv-t3);
  background:rgba(0,0,0,.04); padding:3px 10px;
  border-radius:20px; font-weight:500;
}

.aiv-row {
  display:flex; align-items:flex-end; gap:8px; max-width:100%;
  animation:aiv-in .35s var(--aiv-sp) both;
}
@keyframes aiv-in {
  from{opacity:0;transform:translateY(10px) scale(.96)}
  to{opacity:1;transform:translateY(0) scale(1)}
}
.aiv-row.aiv-user { flex-direction:row-reverse; }

.aiv-av {
  width:28px; height:28px; border-radius:50%; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  background:linear-gradient(145deg,var(--aiv-cl),var(--aiv-c));
  overflow:hidden;
}
.aiv-av.aiv-uav { background:linear-gradient(145deg,#5E5CE6,#3634A3); }
.aiv-av img { width:100%; height:100%; object-fit:cover; }

.aiv-ct { max-width:78%; display:flex; flex-direction:column; gap:4px; }
.aiv-row.aiv-user .aiv-ct { align-items:flex-end; }

.aiv-bbl {
  padding:10px 14px;
  border-radius:var(--aiv-rmd);
  font-size:15px; line-height:1.5;
  color:var(--aiv-abt); background:var(--aiv-ab);
  box-shadow:var(--aiv-shs);
  word-break:break-word; overflow-wrap:break-word;
}
.aiv-row.aiv-user .aiv-bbl {
  background:var(--aiv-ub); color:var(--aiv-ubt);
  border-bottom-right-radius:4px;
  box-shadow:0 2px 12px rgba(0,122,255,.30),0 0 0 .5px rgba(0,0,0,.06);
}
.aiv-row.aiv-ai .aiv-bbl { border-bottom-left-radius:4px; }

.aiv-time { font-size:10.5px; color:var(--aiv-t3); margin:0 4px; }

/* ── Markdown ── */
.aiv-bbl p { margin:0 0 8px; }
.aiv-bbl p:last-child { margin-bottom:0; }
.aiv-bbl h1,.aiv-bbl h2,.aiv-bbl h3,.aiv-bbl h4,.aiv-bbl h5,.aiv-bbl h6 {
  font-weight:700; margin:12px 0 6px; line-height:1.3;
}
.aiv-bbl h1{font-size:19px} .aiv-bbl h2{font-size:17px}
.aiv-bbl h3{font-size:15px} .aiv-bbl h4,.aiv-bbl h5,.aiv-bbl h6{font-size:14px}
.aiv-bbl ul,.aiv-bbl ol { margin:6px 0; padding-left:20px; }
.aiv-bbl li { margin-bottom:4px; line-height:1.5; }
.aiv-bbl blockquote {
  margin:8px 0; padding:6px 12px;
  border-left:3px solid var(--aiv-c);
  background:rgba(0,122,255,.06);
  border-radius:0 6px 6px 0;
  color:var(--aiv-t2); font-style:italic;
}
.aiv-bbl a {
  color:var(--aiv-c);
  text-decoration:underline; text-decoration-style:dotted;
  text-underline-offset:2px;
}
.aiv-bbl hr { border:none; border-top:.5px solid var(--aiv-bd); margin:10px 0; }
.aiv-bbl table { width:100%; border-collapse:collapse; margin:8px 0; font-size:13.5px; }
.aiv-bbl thead th {
  background:rgba(0,0,0,.05); padding:7px 10px;
  text-align:left; font-weight:600; border-bottom:.5px solid rgba(0,0,0,.1);
}
.aiv-bbl tbody td { padding:6px 10px; border-bottom:.5px solid rgba(0,0,0,.06); }
.aiv-bbl tbody tr:last-child td { border-bottom:none; }

/* ── 打字指示器 ── */
.aiv-typing { display:flex; align-items:flex-end; gap:8px; padding:2px 0; animation:aiv-in .3s ease both; }
.aiv-typ-bbl {
  background:var(--aiv-ab);
  border-radius:var(--aiv-rmd); border-bottom-left-radius:4px;
  padding:12px 16px; box-shadow:var(--aiv-shs);
  display:flex; align-items:center; gap:5px;
}
.aiv-dot {
  width:7px; height:7px; border-radius:50%;
  background:var(--aiv-t3);
  animation:aiv-bnc 1.4s ease-in-out infinite;
}
.aiv-dot:nth-child(1){animation-delay:0s}
.aiv-dot:nth-child(2){animation-delay:.2s}
.aiv-dot:nth-child(3){animation-delay:.4s}
@keyframes aiv-bnc {
  0%,60%,100%{transform:translateY(0);opacity:.4}
  30%{transform:translateY(-6px);opacity:1}
}

/* ── 输入区 ── */
.aiv-inp-area {
  padding:10px 12px 12px;
  background:var(--aiv-sf);
  border-top:.5px solid var(--aiv-bd);
  backdrop-filter:blur(20px); -webkit-backdrop-filter:blur(20px);
  flex-shrink:0;
}
.aiv-inp-wrap {
  display:flex; align-items:flex-end; gap:8px;
  background:rgba(118,118,128,.12);
  border-radius:var(--aiv-rlg);
  padding:8px 8px 8px 14px;
  border:1px solid transparent;
  transition:border-color .2s, background .2s;
}
.aiv-inp-wrap:focus-within {
  background:rgba(255,255,255,.95);
  border-color:var(--aiv-c);
  box-shadow:0 0 0 3px rgba(0,122,255,.12);
}
.aiv-ta {
  flex:1; border:none; outline:none; background:transparent;
  font-size:15px; font-family:var(--aiv-f); color:var(--aiv-t1);
  line-height:1.5; resize:none;
  max-height:120px; min-height:22px; height:22px;
  overflow-y:auto; padding:0; -webkit-appearance:none;
  user-select:text; -webkit-user-select:text;
}
.aiv-ta::placeholder { color:var(--aiv-t3); }
.aiv-ta::-webkit-scrollbar { width:3px; }
.aiv-ta::-webkit-scrollbar-thumb { background:rgba(0,0,0,.15); border-radius:2px; }

.aiv-send {
  width:34px; height:34px; border-radius:50%;
  border:none; background:var(--aiv-c); color:#fff;
  cursor:pointer; display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
  transition:transform .2s var(--aiv-sp), background .2s, opacity .2s;
  outline:none; -webkit-tap-highlight-color:transparent;
  box-shadow:0 2px 8px rgba(0,122,255,.35);
}
.aiv-send:disabled { background:var(--aiv-t3); box-shadow:none; cursor:not-allowed; opacity:.6; }
.aiv-send:not(:disabled):hover { transform:scale(1.08); background:var(--aiv-cd); }
.aiv-send:not(:disabled):active { transform:scale(.88); }
.aiv-send.aiv-stp { background:#FF3B30; box-shadow:0 2px 8px rgba(255,59,48,.35); }
.aiv-send.aiv-stp:not(:disabled):hover { background:#CC2D21; }

.aiv-hint { text-align:center; font-size:10.5px; color:var(--aiv-t3); margin-top:7px; }

/* ── 缩放手柄 ── */
.aiv-rh { position:absolute; z-index:1; }
.aiv-rn { top:0; left:40px; height:6px; right:40px; cursor:n-resize; }
.aiv-rs { bottom:0; left:40px; height:6px; right:20px; cursor:s-resize; }
.aiv-re { top:40px; right:0; width:6px; bottom:20px; cursor:e-resize; }
.aiv-rw { top:40px; left:0; width:6px; bottom:20px; cursor:w-resize; }
.aiv-rne { top:0; right:0; width:20px; height:20px; cursor:ne-resize; }
.aiv-rnw { top:0; left:0; width:20px; height:20px; cursor:nw-resize; }
.aiv-rse { bottom:0; right:0; width:20px; height:20px; cursor:se-resize; }
.aiv-rsw { bottom:0; left:0; width:20px; height:20px; cursor:sw-resize; }

.aiv-rse::after {
  content:''; position:absolute; bottom:5px; right:5px;
  width:10px; height:10px;
  background-image:linear-gradient(135deg,
    transparent 33%,rgba(0,0,0,.18) 33%,rgba(0,0,0,.18) 44%,transparent 44%,
    transparent 55%,rgba(0,0,0,.18) 55%,rgba(0,0,0,.18) 66%,transparent 66%,
    transparent 77%,rgba(0,0,0,.18) 77%,rgba(0,0,0,.18) 88%,transparent 88%
  ); border-radius:1px;
}

/* ── 错误提示 ── */
.aiv-err {
  display:flex; align-items:center; gap:8px;
  background:rgba(255,59,48,.08); border:.5px solid rgba(255,59,48,.20);
  border-radius:var(--aiv-rmd);
  padding:10px 12px; font-size:13.5px; color:#FF3B30;
  animation:aiv-in .3s ease both;
}
.aiv-err button {
  margin-left:auto; background:none; border:none;
  color:var(--aiv-c); font-size:13px; font-family:var(--aiv-f);
  cursor:pointer; padding:2px 6px; border-radius:6px; font-weight:500;
  white-space:nowrap; transition:background .15s;
}
.aiv-err button:hover { background:rgba(0,122,255,.08); }

/* ── 清空确认 ── */
.aiv-confirm {
  position:absolute; inset:0;
  background:rgba(242,242,247,.96);
  backdrop-filter:blur(20px); -webkit-backdrop-filter:blur(20px);
  display:flex; flex-direction:column;
  align-items:center; justify-content:center; gap:12px;
  z-index:10; border-radius:var(--aiv-rxl);
  animation:aiv-fi .2s ease;
}
@keyframes aiv-fi { from{opacity:0} to{opacity:1} }
.aiv-cf-ico {
  width:56px; height:56px; border-radius:50%;
  background:rgba(255,59,48,.12);
  display:flex; align-items:center; justify-content:center; color:#FF3B30;
}
.aiv-cf-title { font-size:17px; font-weight:600; color:var(--aiv-t1); letter-spacing:-.3px; }
.aiv-cf-desc  { font-size:13.5px; color:var(--aiv-t2); text-align:center; max-width:200px; line-height:1.4; }
.aiv-cf-btns  { display:flex; gap:10px; margin-top:4px; }
.aiv-btn {
  padding:9px 22px; border-radius:var(--aiv-rmd);
  border:none; font-size:15px; font-family:var(--aiv-f);
  font-weight:500; cursor:pointer;
  transition:transform .15s, opacity .15s; outline:none;
}
.aiv-btn:active { transform:scale(.94); opacity:.8; }
.aiv-btn-c { background:rgba(0,0,0,.07); color:var(--aiv-t1); }
.aiv-btn-d { background:#FF3B30; color:#fff; box-shadow:0 2px 8px rgba(255,59,48,.30); }

/* ── 暗色模式 ── */
@media (prefers-color-scheme: dark) {
  :root {
    --aiv-bg:  rgba(28,28,30,.94);
    --aiv-sf:  rgba(44,44,46,.90);
    --aiv-bd:  rgba(255,255,255,.08);
    --aiv-bds: rgba(255,255,255,.12);
    --aiv-shs: 0 2px 8px rgba(0,0,0,.30),0 0 0 .5px rgba(255,255,255,.06);
    --aiv-shl: 0 20px 60px rgba(0,0,0,.55),0 4px 16px rgba(0,0,0,.30);
    --aiv-t1:  #F2F2F7;
    --aiv-t2:  #98989D;
    --aiv-t3:  #636366;
    --aiv-ab:  #2C2C2E;
    --aiv-abt: #F2F2F7;
  }
  .aiv-inp-wrap:focus-within { background:rgba(58,58,60,.98); }
  .aiv-confirm { background:rgba(28,28,30,.97); }
  .aiv-cf-ico { background:rgba(255,59,48,.18); }
  .aiv-btn-c { background:rgba(255,255,255,.10); color:var(--aiv-t1); }
  .aiv-bbl thead th { background:rgba(255,255,255,.05); }
  .aiv-rse::after {
    background-image:linear-gradient(135deg,
      transparent 33%,rgba(255,255,255,.25) 33%,rgba(255,255,255,.25) 44%,transparent 44%,
      transparent 55%,rgba(255,255,255,.25) 55%,rgba(255,255,255,.25) 66%,transparent 66%,
      transparent 77%,rgba(255,255,255,.25) 77%,rgba(255,255,255,.25) 88%,transparent 88%
    );
  }
}

/* ── 移动端 ── */
@media (max-width: 600px) {
  #aiv-win {
    right:0; left:0; bottom:0;
    width:100%!important; max-width:100%;
    height:80vh!important; max-height:80vh;
    border-radius:var(--aiv-rxl) var(--aiv-rxl) 0 0;
    transform-origin:bottom center;
    min-width:unset;
  }
  #aiv-btn { bottom:20px; right:16px; }
  .aiv-rh { display:none; }
  .aiv-hdr { cursor:default; }

  /* 移动端显示关闭按钮 */
  .aiv-mob-close { display:flex !important; }
}