input,
textarea,
select {
  font-size: 16px;
}
body {
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom); /* iPhone 底部工具列留白 */
  margin: 0;
  font-family: "Noto Sans TC", sans-serif;
  background-color: #ffffff;
  background-image: url("/bg.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  opacity: 0.9; /* 調整這個數值來控制淡化程度 */
  z-index: -1;
}

.chat-wrapper {
  width: 90%;
  max-width: 500px;
  margin: 30px auto;
  border-radius: 16px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  background-color: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 90vh;
  position: relative;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #b6b6b6 !important; /* 灰色背景 */
  padding: 16px;
  color: white;
}

.left-info {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap; /* 🔥 關鍵：避免換行 */
  flex: 1; /* 吃滿左側寬度 */
}

#chatTitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap; /* 🔥 關鍵：不允許換行 */
  max-width: 120px; /* ✅ 視情況可調 */
}

.icon {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.icon i {
  color: white;
  transition: color 0.2s ease;
}

.icon:hover i {
  color: #fcd34d; /* amber-300，或你自己想要的顏色 */
}

.chat-header h1 {
  margin: 0;
  font-size: 20px;
}

.chat-header p {
  margin: 4px 0 0 0;
  font-size: 14px;
  opacity: 0.85;
}

.chat-messages {
  flex: 1;
  background-color: #ffffff;
  padding: 16px;
  /* height: 100%; */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-row {
  display: flex;
}

.message {
  max-width: 100%;
  padding: 1px 12px;
  border-radius: 18px;
  animation: fadeIn 0.3s ease-in-out;
  word-wrap: break-word;
}

.user-message {
  margin-left: 5px;
  background: linear-gradient(to right, #ff6b6b, #ffa726);
  color: white;
  border-radius: 10px 18px 4px 18px;
  max-width: 300px;
}

.other-message {
  background-color: #f8f4eb;
  color: #301b11;
  border-radius: 18px 18px 18px 4px;
  max-width: 300px;
}

.chat-input {
  border-top: 1px solid #f0efef;
  background-color: #f5f5f5;
  display: flex;
  padding: 12px;
  gap: 8px;
  min-height: 48px;
}

.chat-input textarea {
  flex: 1;
  padding: 10px 10px;
  border: 1px solid #d6d6d6;
  border-radius: 15px;
  outline: none;
  background-color: white;
  font-size: 16px;
  font-family: auto;
}

.chat-input button {
  padding: 10px 16px;
  border: none;
  border-radius: 30px;
  background: linear-gradient(to right, #ff6b6b, #ffa726);
  color: white;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.chat-input button:hover {
  transform: scale(1.05);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 傳訊文字泡泡與時間排列位置 */
.message-row {
  display: flex;
  justify-content: flex-start;
  margin: 4px 0;
}

.message-row.right {
  justify-content: flex-end;
}

.bubble-group {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.bubble-group.reverse {
  flex-direction: row-reverse;
}

.message-time {
  font-size: 12px;
  color: #999;
  flex-shrink: 0;
}

/* 垂直拉桿 */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 2px;
}

/* 回到最下端 */
.scroll-button-wrapper {
  position: absolute;
  bottom: 70px; /* 距離輸入框上方 */
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background-color: transparent;
}

.scroll-button {
  background-color: rgba(224, 224, 224, 0.5);
  color: #333;
  border: none;
  padding: 8px 16px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background-color 0.2s;
  font-size: 14px;
}

.scroll-button:hover {
  background-color: rgba(224, 224, 224, 0.7);
}

.scroll-button i {
  opacity: 0.4; /* 這裡是淡化 icon 的關鍵 */
  transition: opacity 0.3s ease;
}

.scroll-button:hover i {
  opacity: 0.8;
}

/* h1 並排 */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px; /* 兩個 h1 中間的間距 */
  background: linear-gradient(to right, #ff6b6b, #ffa726);
  padding: 16px;
  color: white;
}

.send-btn {
  background-color: orange;
  color: white;
  border-radius: 999px;
  padding: 0.5em 1em;
  transition: background-color 0.2s ease;
}

.send-btn:disabled {
  background: #a3a0a0 !important; /* 灰色背景 */
  color: white;
  cursor: not-allowed;
  opacity: 1; /* 不要透明就設為1 */
}

@media (max-width: 768px) {
  .chat-wrapper {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
  .grecaptcha-badge {
    visibility: hidden; /* 或 display: none; */
  }

  .user-message {
    margin-left: 5px;
    background: linear-gradient(to right, #ff6b6b, #ffa726);
    color: white;
    border-radius: 10px 18px 4px 18px;
    max-width: 60vw;
  }

  .other-message {
    background-color: #fdece6;
    color: #7d4b32;
    border-radius: 18px 18px 18px 4px;
    max-width: 60vw;
  }
}

.message-read {
  font-size: 12px;
  color: #999;
  display: block; /* ✅ 強制換行 */
  text-align: right;
  margin-bottom: 2px; /* 與時間間距 */
  line-height: 1.2;
}
.time-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-bottom: 4px;
}

.message-read,
.message-time {
  font-size: 12px;
  color: #999;
  line-height: 1.2;
}

@media (max-width: 1200px) {
  .chat-wrapper {
    width: 100vw !important;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
    max-width: 100vw !important;
  }

  body {
    background-image: none !important;
    background-color: #ffffff !important;
    overflow-y: hidden !important; /* 禁止垂直滾動條 */
  }

  body::before {
    display: none;
  }
  .grecaptcha-badge {
    visibility: hidden; /* 或 display: none; */
  }
}

/* sweetAlert */
.swal-btn-gray {
  background-color: #4b5563; /* Tailwind 的 gray-600 */
  color: white;
  border: none;
  padding: 12px 28px !important;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 500;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s ease;
}

.swal-btn-gray:hover {
  background-color: #374151; /* gray-700 */
}

.swal-btn-cancel {
  background-color: #e5e7eb; /* gray-200 */
  color: #374151; /* gray-700 */
  border: none;
  padding: 12px 28px !important;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 500;
  margin-left: 8px;
  transition: background-color 0.3s ease;
}

.swal-btn-cancel:hover {
  background-color: #d1d5db; /* gray-300 */
}

/* 系統訊息 */
.system-message {
  background-color: #b1a5a5; /* 深灰底 */
  color: #fff; /* 白色文字 */
  padding: 0px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 80%;
  margin: 6px auto; /* 置中顯示 */
  text-align: left;
}
/* AI訊息 */
.ai-message {
  background: linear-gradient(to right, #9dad6e, rgb(200, 226, 122));
  color: #fff; /* 白色文字 */
  padding: 0px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 80%;
  margin: 6px auto; /* 置中顯示 */
  text-align: left;
  padding-right: 20px;
  padding-left: 20px;
}

/* 純圖片訊息：去掉泡泡外框與內距 */
.message.image-only {
  background: transparent !important; /* 蓋掉 user-message 的漸層或 other-message 的底色 */
  box-shadow: none;
  padding: 0; /* 拿掉內距 */
  border-radius: 0; /* 不需要泡泡的圓角 */
  max-width: 100%; /* 讓圖片能更寬一些（可選） */
}

/* 縮圖本身保留圓角與上下邊距 */
.chat-thumb {
  display: block;
  width: 100%;
  height: auto;
  max-width: 360px; /* 依你的版面調整 */
  border-radius: 14px;
  margin: 8px 0; /* ↑↑ 這裡就是你要的上下邊界 */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* 時間/已讀仍照原本位置，不需改；若想更貼近圖片，可微調 */
.bubble-group .time-group + .message.image-only {
  margin-top: 2px; /* 可選：時間到圖片之間的距離 */
}

/* 禁止頁面捲動 */
.no-scroll {
  overflow: hidden !important;
}

/* 整個 Swal 容器佔滿螢幕、不能滾動 */
.full-image-container {
  position: fixed !important;
  inset: 0 !important;
  width: 100dvw !important;
  height: 100dvh !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
}

/* popup 也全滿、去掉任何內距 */
.full-image-popup {
  background: transparent !important;
  width: 100dvw !important;
  height: 100dvh !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  box-shadow: none !important;
}

/* 取消 SweetAlert2 內部 html 容器的預設 padding/overflow */
.full-image-popup .swal2-html-container {
  padding: 0 !important;
  margin: 0 !important;
  overflow: visible !important;
}

/* 承載圖片的容器：置中且不產生滾動 */
.full-image-wrapper {
  position: relative;
  width: 100dvw;
  height: 100dvh;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* 防止任何子元素外溢 */
}

/* 圖片等比縮放，永遠不超出螢幕 → 不會觸發捲軸 */
.full-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

/* 右下角下載、右上角關閉 */
.download-btn,
.close-btn {
  position: absolute;
  z-index: 2;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  text-decoration: none;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.download-btn {
  right: 16px;
  bottom: 16px;
}
.close-btn {
  right: 16px;
  top: 16px;
}

.download-btn:hover,
.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

#loadingOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.loading-spinner {
  border: 4px solid #f3f3f3; /* 外圍淡色 */
  border-top: 4px solid #3498db; /* 上方藍色 */
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
.swal-input-label {
  display: block;
  padding: 0 10px; /* 左右留白 */
  text-align: center;
  font-size: 18px;
  line-height: 1.6;
  color: #555;
}

/* 發言者名稱 */
.speaker-name {
  color: #9ca3af;
  font-size: 0.75rem; /* 你想更小可調成 .625rem */
  line-height: 1.2;
  margin: 0 8px 2px;
  white-space: nowrap;
  max-width: 85%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.speaker-name.left {
  text-align: left;
  align-self: flex-start;
}
.speaker-name.right {
  text-align: right;
  align-self: flex-end;
}
