/* 工坊AI助理：全站悬浮入口与对话面板。类名统一 ws-ai 前缀，避免影响其他页面。 */

.ws-ai {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 70;
  font-family: var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif);
}

.ws-ai__launch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 18px;
  border: 1px solid var(--accent, #047857);
  border-radius: 999px;
  background: var(--accent, #047857);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(4, 120, 87, .28);
  transition: transform .2s var(--ease, ease), box-shadow .2s var(--ease, ease);
}
.ws-ai__launch:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(4, 120, 87, .34); }
.ws-ai__launch:focus-visible { outline: 2px solid var(--accent-sec, #0A7D5C); outline-offset: 3px; }
.ws-ai__launch svg { width: 20px; height: 20px; flex: none; }
.ws-ai__launch[aria-expanded="true"] { background: var(--card, #fff); color: var(--accent, #047857); }

.ws-ai__panel {
  position: absolute;
  right: 0;
  bottom: 58px;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 120px));
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 16px;
  background: var(--card, #fff);
  box-shadow: 0 20px 48px rgba(15, 23, 42, .18), 0 2px 8px rgba(15, 23, 42, .06);
  overflow: hidden;
}
.ws-ai__panel[hidden] { display: none; }

.ws-ai__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border, #E2E8F0);
}
.ws-ai__title {
  margin: 0;
  font-family: var(--display, Georgia, serif);
  font-size: 17px;
  line-height: 1.3;
  color: var(--fg, #0F172A);
}
.ws-ai__sub { display: block; margin-top: 2px; font-size: 11px; color: var(--muted-fg, #5B6472); }
.ws-ai__close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-fg, #5B6472);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.ws-ai__close:hover { background: var(--muted, #F1F5F9); color: var(--fg, #0F172A); }
.ws-ai__close:focus-visible { outline: 2px solid var(--accent, #047857); outline-offset: 1px; }

.ws-ai__log {
  flex: 1 1 auto;
  min-height: 120px;
  padding: 12px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg, #FAFAFA);
}
.ws-ai__msg { margin: 0 0 10px; font-size: 13px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.ws-ai__msg:last-child { margin-bottom: 0; }
.ws-ai__msg--user {
  margin-left: auto;
  width: fit-content;
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px 12px 2px 12px;
  background: rgba(4, 120, 87, .1);
  color: var(--fg, #0F172A);
}
.ws-ai__msg--bot {
  padding: 9px 12px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 12px 12px 12px 2px;
  background: var(--card, #fff);
  color: var(--fg, #0F172A);
}
.ws-ai__msg--err { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
@keyframes ws-ai-rise {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}
.ws-ai__msg--bot { animation: ws-ai-rise .34s cubic-bezier(.22,.8,.3,1) both; }
.ws-ai__msg--user { animation: ws-ai-rise .26s cubic-bezier(.22,.8,.3,1) both; }
/* 逐字浮现时跟在文字后面的小光标，收尾时自动消失 */
.ws-ai__msg--writing::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: .95em;
  margin-left: 2px;
  vertical-align: -.12em;
  border-radius: 1px;
  background: var(--accent, #047857);
  opacity: .5;
  animation: ws-ai-caret .9s steps(1, end) infinite;
}
@keyframes ws-ai-caret {
  0%, 45% { opacity: .5; }
  50%, 100% { opacity: 0; }
}
.ws-ai__hello { margin: 0 0 10px; font-size: 13px; line-height: 1.7; color: var(--muted-fg, #5B6472); }
.ws-ai__hello--mem {
  padding: 8px 10px;
  border-left: 3px solid var(--accent, #047857);
  border-radius: 8px;
  background: #F1F5F9;
  color: #475569;
}
.ws-ai__typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.ws-ai__typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted-fg, #5B6472);
  opacity: .35;
  animation: ws-ai-blink 1s infinite;
}
.ws-ai__typing i:nth-child(2) { animation-delay: .15s; }
.ws-ai__typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ws-ai-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .ws-ai__typing i { animation: none; opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .ws-ai__msg--bot, .ws-ai__msg--user, .ws-ai__msg--writing::after, .ws-ai__chip { animation: none; } }
@media (prefers-reduced-motion: reduce) { .ws-ai__msg--writing::after { display: none; } }

.ws-ai__chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; }
@keyframes ws-ai-chip-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}
.ws-ai__chip {
  animation: ws-ai-chip-in .3s ease-out both;
  padding: 5px 10px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 999px;
  background: var(--card, #fff);
  color: var(--muted-fg, #5B6472);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .18s ease, color .18s ease, background .18s ease;
}
.ws-ai__chip:hover { border-color: var(--accent, #047857); color: var(--accent, #047857); }
.ws-ai__chip:focus-visible { outline: 2px solid var(--accent, #047857); outline-offset: 1px; }
.ws-ai__chip--fill { border-style: dashed; }

.ws-ai__form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px 0; }
.ws-ai__input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 110px;
  padding: 9px 11px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 10px;
  background: var(--card, #fff);
  color: var(--fg, #0F172A);
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
}
.ws-ai__input:focus { outline: 2px solid rgba(4, 120, 87, .25); border-color: var(--accent, #047857); }
.ws-ai__send {
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--accent, #047857);
  border-radius: 10px;
  background: var(--accent, #047857);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ws-ai__send:disabled { opacity: .55; cursor: default; }
.ws-ai__send:focus-visible { outline: 2px solid var(--accent-sec, #0A7D5C); outline-offset: 2px; }

.ws-ai__disc { margin: 0; padding: 8px 14px 12px; font-size: 11px; line-height: 1.7; color: var(--muted-fg, #5B6472); }

/* 历史会话：登录后才有，跟着账号走 */
.ws-ai__headacts { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
.ws-ai__histbtn {
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 999px;
  background: var(--card, #fff);
  color: var(--muted-fg, #5B6472);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.ws-ai__histbtn:hover { border-color: var(--accent, #047857); color: var(--accent, #047857); }
.ws-ai__histbtn:focus-visible { outline: 2px solid var(--accent, #047857); outline-offset: 1px; }
.ws-ai__histbtn[hidden] { display: none; }

.ws-ai__histpanel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--card, #fff);
  z-index: 2;
}
.ws-ai__histpanel[hidden] { display: none; }
.ws-ai__histhead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px 11px;
  border-bottom: 1px solid var(--border, #E2E8F0);
  font-size: 14px;
  color: var(--fg, #0F172A);
}
.ws-ai__histclose {
  margin-left: auto;
  width: 30px;
  height: 30px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-fg, #5B6472);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.ws-ai__histclose:hover { background: var(--muted, #F1F5F9); color: var(--fg, #0F172A); }
.ws-ai__histclose:focus-visible { outline: 2px solid var(--accent, #047857); outline-offset: 1px; }

.ws-ai__histtabs { display: flex; gap: 6px; padding: 9px 14px 0; }
.ws-ai__histtabs[hidden] { display: none; }
.ws-ai__histtab {
  padding: 4px 11px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 999px;
  background: var(--card, #fff);
  color: var(--muted-fg, #5B6472);
  font-size: 12px;
  cursor: pointer;
}
.ws-ai__histtab.is-on {
  border-color: var(--accent, #047857);
  background: rgba(4, 120, 87, .08);
  color: var(--accent, #047857);
}
.ws-ai__histtab:focus-visible { outline: 2px solid var(--accent, #047857); outline-offset: 1px; }

.ws-ai__histlist { flex: 1 1 auto; min-height: 120px; padding: 10px 14px; overflow-y: auto; overscroll-behavior: contain; }
.ws-ai__histmsg { margin: 0 0 8px; font-size: 12px; line-height: 1.75; color: var(--muted-fg, #5B6472); }
.ws-ai__histmsg--lead { font-size: 13px; color: var(--fg, #0F172A); }
.ws-ai__histmsg--muted { color: #94a3b8; }
.ws-ai__histmsg--err { color: #b91c1c; }

.ws-ai__histitem {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 6px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 10px;
  background: var(--card, #fff);
  overflow: hidden;
}
.ws-ai__histopen {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.ws-ai__histopen:hover { background: var(--muted, #F1F5F9); }
.ws-ai__histopen:focus-visible { outline: 2px solid var(--accent, #047857); outline-offset: -2px; }
.ws-ai__histtopic { font-size: 13px; color: var(--fg, #0F172A); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-ai__histmeta { font-size: 11px; color: var(--muted-fg, #5B6472); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-ai__histdel {
  flex: none;
  padding: 0 10px;
  border: 0;
  border-left: 1px solid var(--border, #E2E8F0);
  background: transparent;
  color: #b91c1c;
  font-size: 11px;
  cursor: pointer;
}
.ws-ai__histdel:hover { background: #fef2f2; }
.ws-ai__histdel:focus-visible { outline: 2px solid #b91c1c; outline-offset: -2px; }

.ws-ai__histfoot { padding: 10px 14px; border-top: 1px solid var(--border, #E2E8F0); }
.ws-ai__histfoot[hidden] { display: none; }
.ws-ai__histnew {
  width: 100%;
  height: 36px;
  border: 1px solid var(--accent, #047857);
  border-radius: 10px;
  background: var(--card, #fff);
  color: var(--accent, #047857);
  font-size: 13px;
  cursor: pointer;
}
.ws-ai__histnew:hover { background: rgba(4, 120, 87, .06); }

.ws-ai__histacts { display: flex; gap: 8px; margin: 10px 0 6px; }
.ws-ai__histyes {
  flex: 1 1 auto;
  height: 36px;
  border: 1px solid var(--accent, #047857);
  border-radius: 10px;
  background: var(--accent, #047857);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.ws-ai__histyes:disabled { opacity: .6; cursor: default; }
.ws-ai__histno {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 10px;
  background: var(--card, #fff);
  color: var(--muted-fg, #5B6472);
  font-size: 13px;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .ws-ai__histbtn, .ws-ai__histtab, .ws-ai__histopen, .ws-ai__histnew, .ws-ai__histyes, .ws-ai__histno { transition: none; }
}

@media (max-width: 899px) {
  .ws-ai { left: auto; right: 10px; bottom: 78px; }
  .ws-ai__panel {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 134px;
    width: auto;
    max-height: calc(100vh - 192px);
  }
  /* 小屏收成圆形图标：整条悬浮胶囊会压住卡片底部的说明文字 */
  .ws-ai__launch { width: 44px; height: 44px; padding: 0; justify-content: center; gap: 0; }
  .ws-ai__launch > span {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
  .ws-ai__log { min-height: 100px; }
}

