/**
 * Shanhai Fox Chat — 样式
 * 暖棕 + 米白，取自古籍卷轴质感。不覆盖站点主题，全部命名空间在 .sfc- 下。
 */

.sfc-root {
  --sfc-ink:      #3B2A1E;
  --sfc-ink-soft: #6B5847;
  --sfc-paper:    #FDF8F0;
  --sfc-line:     #E4D8C6;
  --sfc-accent:   #8B4513;
  --sfc-accent-2: #B5651D;
  --sfc-radius:   14px;

  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 99998;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--sfc-ink);
}

/* ---------- 触发按钮 ---------- */
.sfc-launcher {
  position: relative;
  width: 56px;
  height: 56px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 2px solid var(--sfc-accent);
  padding: 0;
  /* 品牌图：站点同款九尾狐（社媒头像同源），112px 供 2x 屏。
     图片缺失时回落到棕色底，不会变成空白圆。 */
  background-color: var(--sfc-accent);
  background-image: url("ling.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: #FFF6E9;
  cursor: pointer;
  display: block;
  /* 注意：这里不能加 overflow:hidden —— background-image 本身已遵循
     border-radius 裁切，而 ::after 的呼吸光环靠 inset:-4px 露在按钮外，
     一旦 hidden 就会被裁掉。 */
  box-shadow: 0 6px 20px rgba(59, 42, 30, .28), 0 2px 6px rgba(59, 42, 30, .18);
  transition: transform .18s ease, box-shadow .18s ease;
}

.sfc-launcher:hover  { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(59,42,30,.32); }
.sfc-launcher:active { transform: translateY(0); }
.sfc-launcher:focus-visible { outline: 3px solid var(--sfc-accent-2); outline-offset: 3px; }

/* 主题经常有 `img, svg { max-width:100%; height:auto }`，会让内联 SVG 高度塌陷成 0，
   按钮里就只剩一个纯色圆（这就是之前图标看不见的原因）。用 !important 锁死，
   这是 WP 插件对抗主题样式的常规做法。注意不要用 CSS 覆盖 fill——眼睛和鼻子靠
   元素上的 fill 属性区分颜色，CSS 一覆盖就全变白了。 */
.sfc-launcher svg,
/* 品牌图走 background-image，不再依赖内联 SVG，
   因此也不需要压制主题的 svg{height:auto} 规则。 */

/* 呼吸提示 */
.sfc-launcher::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(181, 101, 29, .35);
  opacity: 0;
  animation: sfc-breathe 3.6s ease-out infinite;
  pointer-events: none;
}

@keyframes sfc-breathe {
  0%   { transform: scale(.92); opacity: .7; }
  70%  { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}

/* ---------- 面板 ---------- */
.sfc-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 372px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--sfc-paper);
  border: 1px solid var(--sfc-line);
  border-radius: var(--sfc-radius);
  box-shadow: 0 18px 48px rgba(59, 42, 30, .22), 0 4px 12px rgba(59, 42, 30, .1);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(.98);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.sfc-open .sfc-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- 头部 ---------- */
.sfc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  background: linear-gradient(180deg, #F5EBDC, var(--sfc-paper));
  border-bottom: 1px solid var(--sfc-line);
  flex: 0 0 auto;
}

.sfc-head-id { display: flex; align-items: center; gap: 10px; }

.sfc-avatar {
  width: 34px;
  height: 34px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 1.5px solid var(--sfc-accent);
  padding: 0;
  background-color: var(--sfc-accent);
  background-image: url("ling.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  flex: 0 0 auto;
  overflow: hidden;
}

.sfc-head-txt { display: flex; flex-direction: column; line-height: 1.25; }
.sfc-head-txt strong { font-size: 15px; color: var(--sfc-ink); font-weight: 600; }
.sfc-head-txt em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--sfc-ink-soft);
  letter-spacing: .03em;
  text-transform: uppercase;
}

.sfc-close {
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  color: var(--sfc-ink-soft);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background .15s ease, color .15s ease;
}
.sfc-close:hover { background: rgba(139, 69, 19, .08); color: var(--sfc-accent); }

/* ---------- 对话区 ---------- */
.sfc-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  scroll-behavior: smooth;
}

.sfc-log { display: flex; flex-direction: column; gap: 10px; }

.sfc-msg { display: flex; }
.sfc-user { justify-content: flex-end; }

.sfc-bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 13px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14.5px;
}

.sfc-bot .sfc-bubble {
  background: #fff;
  border: 1px solid var(--sfc-line);
  border-bottom-left-radius: 4px;
  color: var(--sfc-ink);
}

.sfc-user .sfc-bubble {
  background: var(--sfc-accent);
  color: #FFF6E9;
  border-bottom-right-radius: 4px;
}

.sfc-link {
  color: var(--sfc-accent-2);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
}
.sfc-link:hover { color: var(--sfc-accent); }
.sfc-user .sfc-link { color: #FFE9C9; }

/* 打字指示 */
.sfc-typing .sfc-bubble { display: flex; gap: 4px; align-items: center; padding: 13px; }
.sfc-typing .sfc-bubble span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--sfc-ink-soft);
  opacity: .45;
  animation: sfc-dot 1.2s infinite ease-in-out;
}
.sfc-typing .sfc-bubble span:nth-child(2) { animation-delay: .18s; }
.sfc-typing .sfc-bubble span:nth-child(3) { animation-delay: .36s; }

@keyframes sfc-dot {
  0%, 60%, 100% { transform: translateY(0);    opacity: .35; }
  30%           { transform: translateY(-4px); opacity: .9; }
}

/* ---------- 输入区 ---------- */
.sfc-form {
  display: flex;
  gap: 8px;
  padding: 11px 12px;
  border-top: 1px solid var(--sfc-line);
  background: #fff;
  flex: 0 0 auto;
}

/* 合规披露条：常驻在输入区下方，不折叠 */
.sfc-note {
  flex: 0 0 auto;
  padding: 5px 12px 8px;
  background: #fff;
  font-size: 10.5px;
  line-height: 1.45;
  color: #A79782;
  text-align: center;
}
.sfc-note a { color: var(--sfc-accent); text-decoration: underline; }
.sfc-note a:hover { color: var(--sfc-accent-2); }

.sfc-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--sfc-line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--sfc-ink);
  background: var(--sfc-paper);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.sfc-input:focus {
  outline: none;
  border-color: var(--sfc-accent-2);
  box-shadow: 0 0 0 3px rgba(181, 101, 29, .14);
}
.sfc-input::placeholder { color: #A79782; }

.sfc-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--sfc-accent);
  color: #FFF6E9;
  font-size: 17px;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.sfc-send:hover:not(:disabled)  { background: var(--sfc-accent-2); transform: translateY(-1px); }
.sfc-send:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 移动端 ---------- */
@media (max-width: 480px) {
  .sfc-root { right: 14px; bottom: 14px; }

  /* 移动端面板是全屏 fixed，浮窗按钮仍是 root 的子元素且 DOM 在后，
     会浮在输入区上方压住发送键 —— 打开时直接收起来。
     关闭走面板头部的 ×，不依赖 launcher。 */
  .sfc-open .sfc-launcher { display: none; }

  .sfc-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    /* dvh：移动浏览器地址栏伸缩时不留下顶部空白，不支持的浏览器回退到 100% */
    height: 100dvh;
    max-width: 100%;
    max-height: 100%;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  /* 底部安全区：iPhone 横条 / 安卓手势条不能压住输入框 */
  .sfc-form { padding-bottom: calc(11px + env(safe-area-inset-bottom, 0px)); }

  .sfc-launcher { width: 52px; height: 52px; }
  .sfc-bubble { max-width: 90%; }
}

/* ---------- 减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  .sfc-launcher,
  .sfc-panel,
  .sfc-input,
  .sfc-send { transition: none; }
  .sfc-launcher::after { animation: none; display: none; }
  .sfc-typing .sfc-bubble span { animation: none; opacity: .6; }
  .sfc-body { scroll-behavior: auto; }
}
