/* ==========================================================================
   CosmoFreq 官网智能助手「星语」· 样式
   --------------------------------------------------------------------------
   风格取自官网自身的设计变量（深空底 + 青色主色 + 宋体标题 + 等宽标签 +
   硬朗直角），全部用 var(--x, fallback) 引用：
     · 挂在官网页面上时，自动继承官网变量，视觉完全一致；
     · 万一变量缺失，也有兜底值，不会变成一坨裸样式。
   前置约定：深色面板上的文字必须显式写 color —— 只靠继承会在某些浏览器
   回退成黑色，深底黑字等于看不见。
   ========================================================================== */

.cfb-root {
  --cfb-cyan: var(--cyan, #22D3EE);
  --cfb-teal: var(--teal, #0E7490);
  --cfb-mint: var(--mint, #34D399);
  --cfb-void: var(--void, #050B14);
  --cfb-deep: var(--deep, #0B1929);
  --cfb-panel: var(--panel, #0E1B2E);
  --cfb-line: var(--line, #1A2B42);
  --cfb-ink: var(--ink, #EAF2F8);
  --cfb-ink-dim: var(--ink-dim, #8BA3B8);
  --cfb-ink-faint: var(--ink-faint, #54677D);
  --cfb-serif: var(--serif, 'Noto Serif SC', Georgia, 'Songti SC', serif);
  --cfb-mono: var(--mono, 'IBM Plex Mono', 'SF Mono', monospace);
  --cfb-sans: var(--sans, 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif);
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 9990;
  font-family: var(--cfb-sans);
  /* ── 样式隔离（改动前先读这段） ────────────────────────────────────
     本挂件是「嵌进任意宿主页面」的组件，宿主的 body / 标签级全局规则会顺着
     继承链和同名标签选择器穿透进来。已实际发生过的事故：
       · 官网 index.html `section{padding:110px 0}`
         → 命中面板（当时面板就是 <section>）⇒ 面板上下各撑出 110px 空白
       · 官网 index.html `body{line-height:1.7}`
         → 被面板继承 ⇒ 面板 line-height 变成 27.2px
     所以把会被继承、且影响布局的属性显式钉在挂件根上，不依赖宿主。
     约定：凡是可继承属性（line-height / letter-spacing / text-transform /
     font-weight / box-sizing 等）都在本根节点显式声明。 */
  line-height: 1.7;
  box-sizing: border-box;
  letter-spacing: normal;
  text-transform: none;
}

/* 挂件内部一律 border-box：不能指望宿主有没有写 `*{box-sizing:border-box}`
   （官网碰巧写了，换一个宿主就会算错宽高）。 */
.cfb-root,
.cfb-root *,
.cfb-root *::before,
.cfb-root *::after {
  box-sizing: border-box;
}

/* ───────────────────────── 悬浮启动球 ───────────────────────── */

.cfb-launcher {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(34, 211, 238, .38);
  background:
    radial-gradient(circle at 34% 30%, rgba(34, 211, 238, .26), transparent 62%),
    linear-gradient(150deg, var(--cfb-panel), var(--cfb-void));
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  box-shadow: 0 0 26px rgba(34, 211, 238, .28), 0 10px 30px rgba(0, 0, 0, .45);
  transition: transform .28s cubic-bezier(.2, .7, .2, 1), box-shadow .28s, border-color .28s;
  -webkit-tap-highlight-color: transparent;
}
.cfb-launcher:hover {
  transform: translateY(-3px) scale(1.04);
  border-color: rgba(34, 211, 238, .8);
  box-shadow: 0 0 40px rgba(34, 211, 238, .5), 0 14px 36px rgba(0, 0, 0, .5);
}
.cfb-launcher:active { transform: translateY(-1px) scale(.99); }
.cfb-launcher:focus-visible { outline: 2px solid var(--cfb-cyan); outline-offset: 3px; }

.cfb-launcher svg { width: 30px; height: 30px; display: block; }

/* 呼吸光环：两圈错峰扩散，呼应官网「波形」的律动感 */
.cfb-pulse,
.cfb-pulse::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid rgba(34, 211, 238, .55);
  animation: cfb-pulse 3.4s ease-out infinite;
  pointer-events: none;
}
.cfb-pulse::after { inset: 0; animation-delay: 1.7s; }

@keyframes cfb-pulse {
  0%   { transform: scale(1);    opacity: .55; }
  70%  { transform: scale(1.55); opacity: 0;   }
  100% { transform: scale(1.55); opacity: 0;   }
}

/* 未读小圆点 */
.cfb-dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--cfb-mint);
  border: 2px solid var(--cfb-void);
  box-shadow: 0 0 10px rgba(52, 211, 153, .9);
  animation: cfb-blink 2s ease-in-out infinite;
}
@keyframes cfb-blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ───────────────────────── 对话面板 ───────────────────────── */

.cfb-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: 578px;
  max-height: calc(100vh - 130px);
  /* 显式归零：宿主若存在标签级 `section{padding:...}` / `div{padding:...}` 规则，
     会直接命中本面板（间距不是继承来的，根节点的隔离挡不住标签选择器），
     必须在这里兜一道 —— 否则面板上下会被撑出上百 px 空白。 */
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(168deg, rgba(14, 27, 46, .97), rgba(5, 11, 20, .97));
  border: 1px solid rgba(34, 211, 238, .22);
  border-radius: 4px;                 /* 官网是直角风格，这里也只做微圆角 */
  box-shadow: 0 0 0 1px rgba(5, 11, 20, .6), 0 26px 70px rgba(0, 0, 0, .62),
              0 0 60px rgba(34, 211, 238, .12);
  backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  overflow: hidden;
  transform-origin: right bottom;
  animation: cfb-in .34s cubic-bezier(.2, .8, .25, 1) both;
}
@keyframes cfb-in {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.cfb-panel[hidden] { display: none; }

/* 顶部青色渐变线 —— 与官网 .cap::before 同一语言 */
.cfb-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1.5px;
  background: linear-gradient(90deg, transparent, var(--cfb-cyan), transparent);
  opacity: .85;
  pointer-events: none;
}

/* ── 头部 ── */
.cfb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--cfb-line);
  flex: 0 0 auto;
}
.cfb-head-id { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cfb-avatar {
  width: 34px; height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, rgba(34, 211, 238, .3), transparent 65%),
              linear-gradient(150deg, var(--cfb-panel), var(--cfb-void));
  border: 1px solid rgba(34, 211, 238, .4);
}
.cfb-avatar svg { width: 19px; height: 19px; }
.cfb-title {
  font-family: var(--cfb-serif);
  font-weight: 700;
  font-size: 16px;
  color: var(--cfb-ink);
  letter-spacing: .5px;
  line-height: 1.3;
}
.cfb-sub {
  font-family: var(--cfb-mono);
  font-size: 10px;
  color: var(--cfb-ink-faint);
  letter-spacing: 1.4px;
  text-transform: uppercase;
  margin-top: 2px;
}
.cfb-sub.is-live { color: var(--cfb-mint); }
.cfb-sub.is-down { color: #F87171; }

.cfb-iconbtn {
  width: 30px; height: 30px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--cfb-ink-dim);
  border-radius: 2px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
  transition: all .2s;
  flex: 0 0 auto;
}
.cfb-iconbtn:hover {
  color: var(--cfb-cyan);
  border-color: rgba(34, 211, 238, .3);
  background: rgba(34, 211, 238, .07);
}

/* ── 消息区 ── */
.cfb-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 211, 238, .3) transparent;
}
.cfb-body::-webkit-scrollbar { width: 6px; }
.cfb-body::-webkit-scrollbar-thumb {
  background: rgba(34, 211, 238, .28);
  border-radius: 3px;
}
.cfb-body::-webkit-scrollbar-track { background: transparent; }

.cfb-msg { display: flex; flex-direction: column; gap: 7px; animation: cfb-rise .3s ease both; }
@keyframes cfb-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.cfb-msg.is-user { align-items: flex-end; }
.cfb-msg.is-bot { align-items: flex-start; }

.cfb-bubble {
  max-width: 88%;
  padding: 11px 13px;
  font-size: 13.5px;
  line-height: 1.68;
  color: var(--cfb-ink);
  border-radius: 3px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.cfb-msg.is-user .cfb-bubble {
  background: rgba(34, 211, 238, .13);
  border: 1px solid rgba(34, 211, 238, .32);
  color: var(--cfb-ink);
}
.cfb-msg.is-bot .cfb-bubble {
  background: rgba(14, 27, 46, .78);
  border: 1px solid var(--cfb-line);
  max-width: 96%;
}

/* 助手气泡内的富文本 */
.cfb-bubble p { margin: 0 0 8px; }
.cfb-bubble p:last-child { margin-bottom: 0; }
.cfb-bubble strong { color: var(--cfb-cyan); font-weight: 600; }
.cfb-bubble em { color: var(--cfb-ink-dim); font-style: normal; }
.cfb-bubble ul, .cfb-bubble ol { margin: 6px 0 8px; padding-left: 19px; }
.cfb-bubble li { margin: 3px 0; }
.cfb-bubble h4 {
  font-family: var(--cfb-serif);
  font-size: 14px;
  color: var(--cfb-ink);
  margin: 10px 0 6px;
  font-weight: 700;
}
.cfb-bubble h4:first-child { margin-top: 0; }
.cfb-bubble code {
  font-family: var(--cfb-mono);
  font-size: 12px;
  background: rgba(34, 211, 238, .1);
  border: 1px solid rgba(34, 211, 238, .18);
  padding: 1px 5px;
  border-radius: 2px;
  color: var(--cfb-cyan);
}
.cfb-bubble hr {
  border: none;
  border-top: 1px solid var(--cfb-line);
  margin: 10px 0;
}
/* 表格：回答里常用，必须横向可滚，不能撑破面板 */
.cfb-tablewrap {
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--cfb-line);
}
.cfb-bubble table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}
.cfb-bubble th, .cfb-bubble td {
  border-bottom: 1px solid var(--cfb-line);
  border-right: 1px solid var(--cfb-line);
  padding: 6px 9px;
  text-align: left;
  white-space: nowrap;
  color: var(--cfb-ink);
}
.cfb-bubble th:last-child, .cfb-bubble td:last-child { border-right: none; }
.cfb-bubble tr:last-child td { border-bottom: none; }
.cfb-bubble th {
  background: rgba(34, 211, 238, .08);
  color: var(--cfb-cyan);
  font-family: var(--cfb-mono);
  font-size: 11px;
  letter-spacing: .6px;
  font-weight: 500;
}

/* 打字光标 */
.cfb-caret {
  display: inline-block;
  width: 7px; height: 14px;
  background: var(--cfb-cyan);
  vertical-align: -2px;
  margin-left: 2px;
  animation: cfb-caret .9s step-end infinite;
}
@keyframes cfb-caret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* 思考中 */
.cfb-thinking { display: flex; gap: 4px; align-items: center; padding: 3px 0; }
.cfb-thinking i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--cfb-cyan);
  opacity: .35;
  animation: cfb-bounce 1.3s ease-in-out infinite;
}
.cfb-thinking i:nth-child(2) { animation-delay: .16s; }
.cfb-thinking i:nth-child(3) { animation-delay: .32s; }
@keyframes cfb-bounce {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-4px); }
}

/* 引用来源 */
.cfb-refs {
  border: 1px solid var(--cfb-line);
  border-left: 2px solid rgba(34, 211, 238, .5);
  background: rgba(11, 25, 41, .6);
  padding: 8px 10px;
  max-width: 96%;
  border-radius: 2px;
}
.cfb-refs summary {
  cursor: pointer;
  font-family: var(--cfb-mono);
  font-size: 10.5px;
  color: var(--cfb-ink-faint);
  letter-spacing: 1px;
  text-transform: uppercase;
  list-style: none;
  transition: color .2s;
}
.cfb-refs summary::-webkit-details-marker { display: none; }
.cfb-refs summary:hover { color: var(--cfb-cyan); }
.cfb-refs summary::before { content: '▸ '; color: var(--cfb-cyan); }
.cfb-refs[open] summary::before { content: '▾ '; }
.cfb-refs ul { margin: 8px 0 0; padding-left: 0; list-style: none; }
.cfb-refs li {
  font-size: 11.5px;
  color: var(--cfb-ink-dim);
  padding: 4px 0;
  border-top: 1px solid rgba(26, 43, 66, .7);
  line-height: 1.5;
}
.cfb-refs li:first-child { border-top: none; }
.cfb-refs .cfb-ref-path {
  display: block;
  font-family: var(--cfb-mono);
  font-size: 10px;
  color: var(--cfb-ink-faint);
  margin-top: 2px;
  word-break: break-all;
}

/* 开场建议问题 */
.cfb-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.cfb-chip {
  font-size: 12px;
  padding: 6px 11px;
  border: 1px solid rgba(34, 211, 238, .26);
  background: rgba(34, 211, 238, .05);
  color: var(--cfb-ink-dim);
  border-radius: 2px;
  cursor: pointer;
  transition: all .2s;
  font-family: var(--cfb-sans);
}
.cfb-chip:hover {
  border-color: var(--cfb-cyan);
  color: var(--cfb-cyan);
  background: rgba(34, 211, 238, .11);
  transform: translateY(-1px);
}

/* ── 输入区 ── */
.cfb-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--cfb-line);
  padding: 11px 13px 12px;
  background: rgba(5, 11, 20, .5);
}
.cfb-inputrow { display: flex; gap: 8px; align-items: flex-end; }
.cfb-input {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  height: 40px;
  max-height: 108px;
  padding: 11px 12px;
  font-size: 13.5px;
  line-height: 1.45;
  font-family: var(--cfb-sans);
  color: var(--cfb-ink);
  background: rgba(14, 27, 46, .85);
  border: 1px solid var(--cfb-line);
  border-radius: 3px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  box-sizing: border-box;
}
.cfb-input::placeholder { color: var(--cfb-ink-faint); }
.cfb-input:focus {
  border-color: rgba(34, 211, 238, .55);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, .1);
}
.cfb-send {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 3px;
  border: none;
  background: var(--cfb-cyan);
  color: var(--cfb-void);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all .2s;
}
.cfb-send svg { width: 17px; height: 17px; }
.cfb-send:hover:not(:disabled) {
  box-shadow: 0 0 20px rgba(34, 211, 238, .6);
  transform: translateY(-1px);
}
.cfb-send:disabled { opacity: .35; cursor: not-allowed; }
.cfb-tip {
  font-size: 10.5px;
  color: var(--cfb-ink-faint);
  margin-top: 7px;
  font-family: var(--cfb-mono);
  letter-spacing: .4px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* ───────────────────────── 移动端 ───────────────────────── */

@media (max-width: 640px) {
  .cfb-root { right: 16px; bottom: 16px; }
  .cfb-launcher { width: 52px; height: 52px; }
  .cfb-launcher svg { width: 26px; height: 26px; }
  .cfb-panel {
    position: fixed;
    right: 0; left: 0; bottom: 0; top: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  .cfb-bubble { max-width: 94%; font-size: 14px; }
}

/* 尊重系统「减少动效」偏好 */
@media (prefers-reduced-motion: reduce) {
  .cfb-root *, .cfb-root *::before, .cfb-root *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
