/* ============ 小恪 · AI 法律顾问（浮动客服） ============ */
.kg-ai-fab {
  position: fixed;
  right: 22px;
  bottom: 30px;
  z-index: 99990;
  border: none;
  background: none;
  padding: 0;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
  transition: left 0.35s cubic-bezier(0.22, 1, 0.36, 1), top 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.kg-ai-fab.dragging { cursor: grabbing; transition: none; }
.kg-ai-fab.dragging .kg-orb { animation-play-state: paused; }
/* 球体容器：光环与投影都以它为基准 */
.kg-wrap { position: relative; display: block; }
/* 立体球体：白环 + 多层阴影 + 3D 浮动 */
.kg-ai-fab .kg-orb {
  position: relative;
  display: block;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  overflow: hidden;
  transform-style: preserve-3d;
  animation: kgFloat 4s ease-in-out infinite;
  box-shadow:
    0 14px 30px rgba(38, 35, 31, 0.30),
    0 4px 10px rgba(38, 35, 31, 0.18),
    0 0 0 3px #fffdf9,
    0 0 0 5px rgba(179, 39, 29, 0.28);
}
.kg-ai-fab .kg-orb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* 球面高光 —— 增强立体感 */
.kg-ai-fab .kg-orb::before {
  content: "";
  position: absolute;
  left: 12%;
  top: 5%;
  width: 55%;
  height: 38%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.55), rgba(255,255,255,0));
  pointer-events: none;
  z-index: 2;
}
/* 底部椭圆投影 */
.kg-wrap::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -13px;
  width: 56px;
  height: 10px;
  transform: translateX(-50%);
  background: radial-gradient(50% 50% at 50% 50%, rgba(38,35,31,0.22), transparent 70%);
  animation: kgShadow 4s ease-in-out infinite;
  pointer-events: none;
}
/* 呼吸光环 */
.kg-ai-fab .kg-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(179, 39, 29, 0.35);
  animation: kgPulse 2.2s ease-out infinite;
  pointer-events: none;
}
@keyframes kgFloat {
  0%, 100% { transform: perspective(320px) rotateY(-7deg) rotateX(2deg) translateY(0); }
  50%      { transform: perspective(320px) rotateY(7deg)  rotateX(-2deg) translateY(-8px); }
}
@keyframes kgShadow {
  0%, 100% { transform: translateX(-50%) scale(1);   opacity: 0.9; }
  50%      { transform: translateX(-50%) scale(0.7); opacity: 0.45; }
}
@keyframes kgPulse {
  0%   { transform: scale(1);    opacity: 0.7; }
  70%  { transform: scale(1.45); opacity: 0; }
  100% { transform: scale(1.45); opacity: 0; }
}
.kg-ai-fab:hover .kg-orb,
.kg-ai-fab:focus .kg-orb {
  animation-play-state: paused;
  transform: perspective(320px) rotateY(0) rotateX(0) scale(1.08);
}
/* 球下方的名称牌 */
.kg-ai-fab .kg-badge {
  position: static;
  display: block;
  background: linear-gradient(135deg, #b3271d, #8f1d13);
  color: #fff;
  font-size: 11.5px;
  letter-spacing: 0.5px;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 9px;
  box-shadow: 0 3px 10px rgba(143, 29, 19, 0.35);
  white-space: nowrap;
  pointer-events: none;
}
/* 拖动提示小点 */
.kg-ai-fab .kg-grip {
  display: block;
  color: #9a9284;
  font-size: 10px;
  letter-spacing: 2px;
  line-height: 1;
  opacity: 0.75;
  pointer-events: none;
}

/* ============ 对话面板 ============ */
.kg-ai-panel {
  position: fixed;
  right: 18px;
  bottom: 122px;
  z-index: 99991;
  width: min(380px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 150px));
  display: none;
  flex-direction: column;
  background: #fffdf9;
  border: 1px solid rgba(179, 39, 29, 0.25);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(38, 35, 31, 0.28);
  overflow: hidden;
  font-family: var(--sans, inherit);
}
.kg-ai-panel.show { display: flex; animation: kgUp 0.28s ease; }
@keyframes kgUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.kg-ai-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #b3271d, #8f1d13);
  color: #fff;
  flex-shrink: 0;
}
.kg-ai-head img { width: 40px; height: 40px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.75); object-fit: cover; }
.kg-ai-head .kg-t { flex: 1; min-width: 0; }
.kg-ai-head .kg-t b { display: block; font-size: 15px; }
.kg-ai-head .kg-t span { font-size: 11.5px; opacity: 0.85; display: flex; align-items: center; gap: 5px; }
.kg-ai-head .kg-dot { width: 7px; height: 7px; border-radius: 50%; background: #7ee08a; box-shadow: 0 0 0 3px rgba(126,224,138,0.25); display: inline-block; }
.kg-ai-close {
  border: none; background: rgba(255,255,255,0.16); color: #fff;
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1;
}
.kg-ai-close:hover { background: rgba(255,255,255,0.3); }

.kg-ai-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(60% 40% at 90% 0%, rgba(179,39,29,0.04), transparent 70%),
    #fbf8f3;
}
.kg-msg { max-width: 84%; font-size: 13.5px; line-height: 1.75; }
.kg-msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #eee5d6;
  border-left: 3px solid rgba(179,39,29,0.5);
  color: #26231f;
  padding: 10px 13px;
  border-radius: 3px 12px 12px 12px;
  box-shadow: 0 2px 8px rgba(38,35,31,0.05);
  white-space: pre-line;
}
.kg-msg.user {
  align-self: flex-end;
  background: #b3271d;
  color: #fff;
  padding: 9px 13px;
  border-radius: 12px 3px 12px 12px;
}
.kg-msg.report {
  align-self: stretch;
  max-width: 100%;
  background: #fffdf9;
  border: 1px solid rgba(179,39,29,0.35);
  box-shadow: inset 0 0 0 3px #fffdf9, inset 0 0 0 4px rgba(179,39,29,0.3);
  padding: 14px 15px;
  border-radius: 3px;
}
.kg-msg.report b.rp { font-size: 21px; color: #b3271d; display: block; margin: 2px 0; }
.kg-msg.report .rp-lv { font-size: 13px; color: #8f1d13; font-weight: 700; }
.kg-msg.report .rp-d { font-size: 12.5px; color: #6b6459; margin-top: 8px; }
.kg-msg.report .rp-tip { font-size: 11.5px; color: #9a9284; margin-top: 8px; border-top: 1px dashed #e8e2d6; padding-top: 8px; }

.kg-opts { align-self: flex-start; display: flex; flex-direction: column; gap: 7px; max-width: 88%; }
.kg-opt {
  text-align: left;
  border: 1px solid rgba(179,39,29,0.4);
  background: #fff;
  color: #26231f;
  font-size: 13px;
  padding: 9px 13px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.kg-opt:hover { background: rgba(179,39,29,0.07); border-color: #b3271d; transform: translateX(3px); }
.kg-opt.skip { border-style: dashed; border-color: #d8d0c0; color: #9a9284; font-size: 12px; padding: 6px 13px; }
.kg-opt.skip:hover { transform: none; background: #f6f1e7; }
.kg-progress { align-self: center; font-size: 11px; color: #9a9284; letter-spacing: 1px; }

/* 留电表单 */
.kg-form { align-self: stretch; background: #fff; border: 1px solid #eee5d6; border-radius: 10px; padding: 12px; }
.kg-form input {
  width: 100%; box-sizing: border-box; border: 1px solid #ddd3c2; border-radius: 6px;
  padding: 9px 11px; font-size: 13.5px; margin-bottom: 8px; font-family: inherit; background: #fffdf9;
}
.kg-form input:focus { outline: none; border-color: #b3271d; }
.kg-form .kg-err { font-size: 12px; color: #b3271d; min-height: 16px; margin-bottom: 4px; }
.kg-form button {
  width: 100%; border: none; background: linear-gradient(135deg, #b3271d, #8f1d13);
  color: #fff; font-size: 14px; padding: 11px; border-radius: 8px; cursor: pointer; font-family: inherit;
}
.kg-form button:hover { filter: brightness(1.08); }
.kg-typing { align-self: flex-start; display: none; gap: 4px; padding: 10px 14px; background: #fff; border: 1px solid #eee5d6; border-radius: 3px 12px 12px 12px; }
.kg-typing.show { display: inline-flex; }
.kg-typing i { width: 6px; height: 6px; border-radius: 50%; background: #b3271d; opacity: 0.4; animation: kgTyp 1s infinite; }
.kg-typing i:nth-child(2) { animation-delay: 0.18s; }
.kg-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes kgTyp { 0%,100% { transform: translateY(0); opacity: 0.35; } 50% { transform: translateY(-4px); opacity: 1; } }

@media (max-width: 640px) {
  /* 避开 iPhone 底部 Home 指示条 */
  .kg-ai-panel {
    right: 10px;
    bottom: calc(104px + var(--safe-b, 0px));
    height: calc(100vh - 130px - var(--safe-b, 0px));
    height: calc(100dvh - 130px - var(--safe-b, 0px));
  }
  .kg-ai-fab {
    right: 12px;
    bottom: calc(20px + var(--safe-b, 0px));
  }
  .kg-ai-fab .kg-orb {
    width: 64px;
    height: 64px;
  }
  .kg-ai-fab .kg-badge {
    font-size: 12px;
    padding: 5px 10px;
  }
  .kg-ai-fab .kg-grip {
    display: none;
  }
  .kg-msg {
    font-size: 14px;
    max-width: 90%;
  }
  .kg-opts {
    max-width: 94%;
  }
  /* 触控更友好 */
  .kg-opt {
    padding: 11px 14px;
    font-size: 14px;
  }
}

/* 隐私与用途说明（留电表单上方） */
.kg-privacy {
  font-size: 11.5px;
  line-height: 1.75;
  color: #8a8378;
  background: #faf8f4;
  border: 1px dashed #e2d9cc;
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 10px;
}
.kg-privacy strong { color: #6d675e; }
