/* ═══════════════════════════════════════
   熊客服 聊天元件（日系紙白調）
═══════════════════════════════════════ */
:root {
  --kc-ink: #33302a;
  --kc-paper: #fcfaf5;
  --kc-blue: #2e567f;
  --kc-blue-deep: #22405e;
  --kc-line: rgba(48, 45, 38, .12);
  --kc-dim: rgba(48, 45, 38, .62);
  --kc-ease: cubic-bezier(.16, 1, .3, 1);
  --kc-spring: cubic-bezier(.34, 1.3, .64, 1);
}

/* 讓出右下角給熊客服，回到頂部按鈕上移 */
#back-top {
  bottom: 106px !important;
}

/* jp-premium 的 body > * 會建立 z-index:2 的堆疊環境，這裡拉回最上層 */
.kc-root {
  position: relative;
  z-index: 9000 !important;
}

/* ── 浮動圈圈 ── */
.kc-launcher {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 8800;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  background: rgba(252, 250, 245, .94);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  box-shadow:
    0 14px 38px rgba(48, 45, 38, .18),
    inset 0 1px 0 rgba(255, 255, 255, .85);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition:
    transform .45s var(--kc-spring),
    box-shadow .3s ease,
    border-color .3s ease;
}
/* 首頁載入動畫期間先隱藏，進站後再彈出 */
body.is-loading .kc-launcher,
body.is-loading .kc-nudge {
  display: none;
}
@keyframes kcPopIn {
  from { opacity: 0; transform: scale(.4) translateY(14px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.kc-launcher {
  animation: kcPopIn .6s var(--kc-spring) .2s backwards;
}
/* 首頁（有 loader 的頁面）進場編排：圈圈壓軸出現 */
body.site-ready .kc-launcher {
  animation-delay: 2.55s;
}
/* 在線綠點（常駐脈動，讓訪客一眼知道有線上服務） */
.kc-launcher::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #21C063;
  border: 2.5px solid #FFFFFF;
  animation: kcOnlinePulse 2.6s cubic-bezier(.4, 0, .4, 1) infinite;
}
@keyframes kcOnlinePulse {
  0%   { box-shadow: 0 0 0 0 rgba(33, 192, 99, .4); }
  60%  { box-shadow: 0 0 0 8px rgba(33, 192, 99, 0); }
  100% { box-shadow: 0 0 0 0 rgba(33, 192, 99, 0); }
}
.kc-root.open .kc-launcher::after { display: none; }
.kc-launcher:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 20px 48px rgba(34, 64, 94, .26), inset 0 1px 0 rgba(255, 255, 255, .9);
}
.kc-launcher:active {
  transform: scale(.92);
}
.kc-launcher-logo,
.kc-launcher-x {
  grid-area: 1 / 1;
  transition: opacity .32s var(--kc-ease), transform .42s var(--kc-spring);
}
.kc-launcher-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  animation: kcBreathe 5.2s ease-in-out infinite;
}
@keyframes kcBreathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.07); }
}
.kc-launcher-x {
  position: relative;
  width: 18px;
  height: 18px;
  opacity: 0;
  transform: rotate(-90deg) scale(.5);
}
.kc-launcher-x::before,
.kc-launcher-x::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  border-radius: 2px;
  background: var(--kc-blue);
}
.kc-launcher-x::before { transform: translateY(-50%) rotate(45deg); }
.kc-launcher-x::after  { transform: translateY(-50%) rotate(-45deg); }
.kc-root.open .kc-launcher-logo {
  opacity: 0;
  transform: rotate(90deg) scale(.4);
  animation: none;
}
.kc-root.open .kc-launcher-x {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* ── 在線提示卡（訊息預覽） ── */
.kc-nudge {
  position: fixed;
  right: 96px;
  bottom: 30px;
  z-index: 8790;
  display: flex;
  align-items: center;
  gap: 11px;
  width: min(238px, calc(100vw - 120px));
  padding: 13px 34px 13px 16px;
  border-radius: 18px 18px 5px 18px;
  background: #FFFFFF;
  border: 1px solid rgba(48, 45, 38, .1);
  box-shadow:
    0 20px 52px rgba(48, 45, 38, .2),
    inset 0 1px 0 rgba(255, 255, 255, .9);
  text-align: left;
  opacity: 0;
  transform: translateY(14px) scale(.88);
  transform-origin: bottom right;
  pointer-events: none;
  cursor: pointer;
  transition: opacity .4s var(--kc-ease), transform .55s var(--kc-spring);
}
.kc-nudge.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.kc-nudge:hover {
  transform: translateY(-2px) scale(1.015);
}
.kc-nudge-body { min-width: 0; }
.kc-nudge-body b {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--kc-ink);
}
.kc-nudge-body b i {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-style: normal;
  font-size: 10.5px;
  font-weight: 700;
  color: #06c755;
  letter-spacing: .04em;
}
.kc-nudge-body b i::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #21C063;
}
.kc-nudge-body > span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--kc-dim);
}
.kc-nudge-close {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(48, 45, 38, .38);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .2s, color .2s;
}
.kc-nudge-close:hover {
  background: rgba(48, 45, 38, .07);
  color: var(--kc-ink);
}
@media (min-width: 561px) {
  .kc-nudge-close {
    display: none;
  }
}

/* ── 聊天視窗 ── */
.kc-window {
  position: fixed;
  right: 26px;
  bottom: 100px;
  z-index: 8810;
  width: min(384px, calc(100vw - 40px));
  height: min(600px, calc(100dvh - 130px));
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  overflow: hidden;
  background: var(--kc-paper);
  border: 1px solid rgba(46, 86, 127, .16);
  box-shadow:
    0 34px 90px rgba(48, 45, 38, .24),
    inset 0 1px 0 rgba(255, 255, 255, .85);
  opacity: 0;
  transform: translateY(26px) scale(.86);
  transform-origin: bottom right;
  filter: blur(6px);
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity .34s var(--kc-ease),
    transform .5s var(--kc-spring),
    filter .34s var(--kc-ease),
    visibility 0s linear .34s;
}
.kc-root.open .kc-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  filter: blur(0);
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity .34s var(--kc-ease),
    transform .5s var(--kc-spring),
    filter .34s var(--kc-ease),
    visibility 0s;
}

/* 頂欄 */
.kc-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(180deg, #FFFFFF, #f2eee3);
  border-bottom: 1px solid var(--kc-line);
  flex: none;
}
.kc-head-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(46, 86, 127, .3);
  background: #fff;
  object-fit: contain;
  padding: 5px;
}
.kc-head-info { flex: 1; min-width: 0; }
.kc-head-info b {
  display: block;
  font-size: 15px;
  font-weight: 800;
  color: var(--kc-ink);
  letter-spacing: .02em;
}
.kc-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--kc-dim);
}
.kc-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #21C063;
  box-shadow: 0 0 0 3px rgba(33, 192, 99, .16);
}
.kc-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--kc-dim);
  transition: background .2s, color .2s, transform .2s;
}
.kc-close:hover { background: rgba(46, 86, 127, .1); color: var(--kc-blue); }
.kc-close:active { transform: scale(.88); }
.kc-close svg { width: 16px; height: 16px; }

/* 訊息區 */
.kc-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 90% 0%, rgba(46, 86, 127, .05), transparent 36%),
    var(--kc-paper);
}
.kc-body::-webkit-scrollbar { width: 5px; }
.kc-body::-webkit-scrollbar-thumb {
  background: rgba(48, 45, 38, .16);
  border-radius: 3px;
}

/* 訊息列 */
.kc-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
  animation: kcMsgIn .48s var(--kc-spring) both;
}
.kc-msg.user {
  flex-direction: row-reverse;
  transform-origin: bottom right;
}
.kc-msg.bot { transform-origin: bottom left; }
@keyframes kcMsgIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.kc-msg.no-anim { animation: none; }
.kc-msg-avatar {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 8px;
  border: 1px solid var(--kc-line);
  background: #fff;
  object-fit: contain;
  padding: 3px;
}
.kc-bubble {
  max-width: 78%;
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.75;
  word-break: break-word;
}
.kc-msg.bot .kc-bubble {
  background: #FFFFFF;
  border: 1px solid var(--kc-line);
  border-radius: 16px 16px 16px 5px;
  color: var(--kc-ink);
  box-shadow: 0 4px 14px rgba(48, 45, 38, .05);
}
.kc-msg.user .kc-bubble {
  background: linear-gradient(160deg, #2e567f, #22405e);
  border-radius: 16px 16px 5px 16px;
  color: #FFFFFF;
  box-shadow: 0 6px 18px rgba(34, 64, 94, .28);
}
.kc-bubble b { font-weight: 800; }
.kc-bubble a {
  color: var(--kc-blue-deep);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 打字中 */
.kc-typing .kc-bubble {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
}
.kc-typing .kc-bubble i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(46, 86, 127, .55);
  animation: kcDot 1.15s ease-in-out infinite;
}
.kc-typing .kc-bubble i:nth-child(2) { animation-delay: .15s; }
.kc-typing .kc-bubble i:nth-child(3) { animation-delay: .3s; }
@keyframes kcDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* 快捷晶片 */
.kc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 14px 34px;
}
.kc-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(46, 86, 127, .38);
  background: rgba(46, 86, 127, .05);
  color: var(--kc-blue-deep);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  animation: kcChipIn .4s var(--kc-spring) calc(var(--i, 0) * 70ms + .12s) forwards;
  transition: background .2s, border-color .2s, transform .2s;
}
.kc-chip:hover {
  background: rgba(46, 86, 127, .12);
  border-color: var(--kc-blue);
}
.kc-chip:active { transform: scale(.94); }
@keyframes kcChipIn {
  to { opacity: 1; transform: translateY(0); }
}

/* LINE 按鈕 */
.kc-line-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  padding: 9px 18px;
  border-radius: 999px;
  background: #06C755;
  color: #FFFFFF !important;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none !important;
  box-shadow: 0 8px 20px rgba(6, 199, 85, .3);
  transition: transform .25s var(--kc-spring), box-shadow .25s;
}
.kc-line-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(6, 199, 85, .38);
}
.kc-line-btn:active { transform: scale(.95); }

/* 輸入列 */
.kc-input {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #FFFFFF;
  border-top: 1px solid var(--kc-line);
}
.kc-input input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--kc-line);
  border-radius: 999px;
  padding: 11px 18px;
  font: 13.5px/1.4 inherit;
  font-family: inherit;
  color: var(--kc-ink);
  background: var(--kc-paper);
  outline: none;
  transition: border-color .25s, box-shadow .25s;
}
.kc-input input::placeholder { color: rgba(48, 45, 38, .38); }
.kc-input input:focus {
  border-color: rgba(46, 86, 127, .55);
  box-shadow: 0 0 0 3px rgba(46, 86, 127, .12);
}
.kc-send {
  width: 42px;
  height: 42px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(160deg, #2e567f, #22405e);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(34, 64, 94, .3);
  transition: transform .3s var(--kc-spring), box-shadow .25s, opacity .2s;
}
.kc-send svg { width: 17px; height: 17px; }
.kc-send:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(34, 64, 94, .4); }
.kc-send:active { transform: scale(.86); }
.kc-send:disabled { opacity: .45; transform: none; box-shadow: none; cursor: default; }

/* 免責小字 */
.kc-foot-note {
  flex: none;
  padding: 0 16px 10px;
  background: #FFFFFF;
  font-size: 10.5px;
  color: rgba(48, 45, 38, .38);
  text-align: center;
}

/* ── 手機版：全螢幕底部展開 ── */
@media (max-width: 560px) {
  .kc-window {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: 0;
    transform: translateY(6%) scale(.98);
    transform-origin: bottom center;
  }
  .kc-root.open .kc-window { transform: translateY(0) scale(1); }
  .kc-head { padding-top: max(16px, env(safe-area-inset-top)); }
  .kc-input { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .kc-root.open .kc-launcher { opacity: 0; pointer-events: none; }
  .kc-launcher { right: 18px; bottom: 18px; }
  .kc-nudge { right: 84px; bottom: 22px; width: calc(100vw - 108px); }
  #back-top { bottom: 96px !important; right: 20px !important; }
}

/* ── 動畫降級 ── */
@media (prefers-reduced-motion: reduce) {
  .kc-launcher-logo { animation: none; }
  .kc-launcher { animation: none; }
  .kc-window {
    transition: opacity .15s ease, visibility 0s linear .15s;
    transform: none;
    filter: none;
  }
  .kc-root.open .kc-window { transition: opacity .15s ease, visibility 0s; transform: none; }
  .kc-msg { animation-duration: .01s; }
  .kc-chip { animation-duration: .01s; animation-delay: 0s; }
  .kc-typing .kc-bubble i { animation: none; }
  .kc-body { scroll-behavior: auto; }
}
