/* ==================================================================
   恆健藥廠 · 在線諮詢樣式
   ================================================================== */

/* ---------------- 懸浮球 ---------------- */
.chat-fab {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 900;
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green-800);
  color: #fff;
  border-radius: 0;
  box-shadow: 0 8px 26px rgba(7, 61, 44, 0.32);
  transition: background 0.3s var(--ease), transform 0.3s var(--ease);
}

.chat-fab:hover {
  background: var(--teal-600);
  transform: translateY(-3px);
}

/* 後台上傳了 Logo 圖時，諮詢球顯示品牌圖標；沒圖則保持上面的氣泡圖標。
   加白底是為了讓深色 logo 在深綠按鈕上也能看清。 */
.chat-fab__logo {
  display: block;
  width: 42%;
  height: 42%;
  object-fit: contain;
  background: #fff;
  border-radius: 3px;
  padding: 3px;
  box-sizing: content-box;
}

.chat-fab svg {
  width: 25px;
  height: 25px;
}

.chat-fab__badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  font-family: var(--font-num);
}

.chat-fab__badge.is-on {
  display: flex;
}

/* ---------------- 首次提示 ---------------- */
.chat-teaser {
  position: fixed;
  right: 26px;
  bottom: 98px;
  z-index: 899;
  max-width: 262px;
  padding: 15px 36px 15px 18px;
  background: #fff;
  border-left: 3px solid var(--green-800);
  box-shadow: 0 10px 32px rgba(7, 61, 44, 0.16);
  font-size: 13px;
  line-height: 1.75;
  color: var(--gray-700);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.4s var(--ease);
  cursor: pointer;
}

.chat-teaser.is-on {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.chat-teaser__close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  font-size: 17px;
  line-height: 1;
  color: var(--gray-400);
}

.chat-teaser__close:hover {
  color: var(--gray-700);
}

/* ---------------- 面板 ---------------- */
.chat-panel {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 950;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 0 18px 56px rgba(7, 61, 44, 0.24);
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.32s var(--ease), transform 0.32s var(--ease), visibility 0.32s;
  overflow: hidden;
}

.chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

/* 頭部 */
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  background: var(--green-800);
  color: #fff;
  flex-shrink: 0;
}

.chat-head__avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: 500;
  color: var(--lime-400);
}

.chat-head__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-head__meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.chat-head__meta b {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.chat-head__meta span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.68);
}

#chatDot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lime-400);
  flex-shrink: 0;
}

#chatDot.is-human {
  background: #ffd166;
}

.chat-head__close {
  width: 28px;
  height: 28px;
  font-size: 21px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.72);
  flex-shrink: 0;
}

.chat-head__close:hover {
  color: #fff;
}

/* 訊息區 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: var(--gray-050);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: msgIn 0.28s var(--ease);
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg--visitor {
  align-self: flex-end;
  align-items: flex-end;
}

.msg--ai,
.msg--agent {
  align-self: flex-start;
  align-items: flex-start;
}

.msg__role {
  font-size: 11px;
  color: var(--gray-400);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

.msg__bubble {
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.78;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg__bubble strong {
  font-weight: 600;
}

.msg--visitor .msg__bubble {
  background: var(--green-800);
  color: #fff;
}

.msg--ai .msg__bubble {
  background: #fff;
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}

.msg--agent .msg__bubble {
  background: var(--lime-100);
  color: var(--green-900);
  border: 1px solid var(--lime-300);
}

.msg__time {
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--gray-400);
  font-family: var(--font-num);
  letter-spacing: 0.06em;
}

/* 系統提示 */
.chat-sys {
  align-self: center;
  padding: 5px 14px;
  font-size: 11.5px;
  color: var(--gray-500);
  background: rgba(0, 0, 0, 0.04);
}

/* 輸入中 */
.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 13px 15px;
  background: #fff;
  border: 1px solid var(--gray-200);
}

.typing i {
  width: 6px;
  height: 6px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: blink 1.3s infinite;
}

.typing i:nth-child(2) {
  animation-delay: 0.18s;
}
.typing i:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* 快捷問句 */
.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 4px;
  background: #fff;
  border-top: 1px solid var(--gray-100);
  flex-shrink: 0;
}

.chat-quick button {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--teal-600);
  border: 1px solid var(--gray-200);
  background: #fff;
  transition: all 0.25s var(--ease);
  letter-spacing: 0.02em;
}

.chat-quick button:hover {
  background: var(--green-050);
  border-color: var(--green-800);
  color: var(--green-800);
}

/* 輸入框 */
.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px 12px;
  background: #fff;
  flex-shrink: 0;
}

.chat-input textarea {
  flex: 1;
  min-height: 40px;
  max-height: 92px;
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--gray-050);
  border: 1px solid var(--gray-200);
  border-radius: 0;
  outline: none;
  resize: none;
  font-family: inherit;
  transition: border-color 0.25s var(--ease);
}

.chat-input textarea:focus {
  border-color: var(--green-800);
  background: #fff;
}

.chat-input textarea::placeholder {
  color: var(--gray-400);
}

.chat-input button {
  height: 40px;
  padding: 0 18px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--green-800);
  letter-spacing: 0.04em;
  transition: background 0.25s var(--ease);
  flex-shrink: 0;
}

.chat-input button:hover {
  background: var(--teal-600);
}

.chat-input button:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

/* 底部 */
.chat-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 11px;
  font-size: 11px;
  color: var(--gray-400);
  background: #fff;
  border-top: 1px solid var(--gray-100);
  flex-shrink: 0;
}

.chat-foot button {
  font-size: 11.5px;
  color: var(--teal-600);
  border-bottom: 1px solid transparent;
  transition: border-color 0.25s var(--ease);
}

.chat-foot button:hover {
  border-bottom-color: var(--teal-600);
}

.chat-foot button:disabled {
  color: var(--gray-400);
  cursor: default;
}

/* ---------------- 移動端 ---------------- */
@media (max-width: 640px) {
  .chat-fab {
    right: 16px;
    bottom: 16px;
    width: 52px;
    height: 52px;
  }

  .chat-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    transform: translateY(24px);
  }

  .chat-teaser {
    right: 16px;
    bottom: 80px;
    max-width: calc(100vw - 32px);
  }
}
