/* ============================================
   AI 客服浮動聊天視窗
   ============================================ */

.chatbot-toggle {
  position: fixed;
  bottom: 90px;
  right: 20px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--matte-gold, #F59E0B);
  color: #fff;
  border: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chatbot-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}
.chatbot-toggle .badge-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid #fff;
}

/* --- 聊天視窗 --- */
.chatbot-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  z-index: 10000;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: 70vh;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.chatbot-window.open {
  display: flex;
  animation: chatSlideUp 0.3s ease-out;
}

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

/* --- Header --- */
.chatbot-header {
  background: var(--navy-blue, #0F172A);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chatbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--matte-gold, #F59E0B);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.chatbot-header-text h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}
.chatbot-header-text span {
  font-size: 11px;
  opacity: 0.8;
}
.chatbot-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.chatbot-close:hover { opacity: 1; }

/* --- 訊息區 --- */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
}
.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.bot {
  align-self: flex-start;
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--navy-blue, #0F172A);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
  color: #9ca3af;
  font-style: italic;
}

/* --- 快速問題按鈕 --- */
.chatbot-quick-actions {
  padding: 8px 16px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  background: #f8f9fa;
  border-top: 1px solid #e5e7eb;
}
.quick-btn {
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.quick-btn:hover {
  background: var(--matte-gold, #F59E0B);
  color: #fff;
  border-color: var(--matte-gold, #F59E0B);
}

/* --- 輸入區 --- */
.chatbot-input {
  display: flex;
  padding: 12px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  gap: 8px;
  flex-shrink: 0;
}
.chatbot-input input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 24px;
  padding: 8px 16px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.chatbot-input input:focus {
  border-color: var(--matte-gold, #F59E0B);
}
.chatbot-input button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--matte-gold, #F59E0B);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.2s;
}
.chatbot-input button:hover {
  background: #d97706;
}
.chatbot-input button:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

/* --- 回答滿意度按鈕 --- */
.chat-feedback {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 10px 2px;
  font-size: 0.78rem;
  color: #6b7280;
}
.chat-feedback .fb-q { margin-right: 4px; }
.chat-feedback .fb-btn {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  color: #374151;
  padding: 3px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.78rem;
  transition: all 0.15s;
}
.chat-feedback .fb-btn:hover { background: #e5e7eb; }
.chat-feedback .fb-yes:hover { background: #d1fae5; border-color: #10b981; color: #065f46; }
.chat-feedback .fb-no:hover  { background: #fee2e2; border-color: #ef4444; color: #991b1b; }
.chat-feedback .fb-done { color: #10b981; font-weight: 600; }

/* --- 人工客服表單 --- */
.support-form {
  background: #fffaf0 !important;
  border-left: 3px solid #f59e0b !important;
}
.support-form input,
.support-form textarea {
  width: 100%;
  padding: 8px 10px;
  margin-top: 6px;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
}
.support-form textarea { resize: vertical; min-height: 60px; }
.support-form .support-submit {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}
.support-form .support-submit:hover:not(:disabled) {
  background: linear-gradient(135deg, #d97706, #b45309);
}
.support-form .support-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.support-form .support-status {
  margin-top: 10px;
  padding: 10px;
  border-radius: 6px;
  background: #fff;
  font-size: 0.85rem;
  line-height: 1.6;
}
.support-form .support-ok {
  color: #065f46;
  font-weight: 600;
  margin-bottom: 6px;
}
.support-form .support-ok code {
  background: #d1fae5;
  padding: 2px 6px;
  border-radius: 4px;
}
.support-form .support-note { color: #374151; margin-bottom: 4px; }
.support-form .support-hint { color: #6b7280; font-size: 0.78rem; }

/* --- 串流中的游標效果 --- */
.chat-msg.typing-live::after {
  content: '▋';
  display: inline-block;
  animation: blink 1s infinite;
  margin-left: 2px;
  color: #9ca3af;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* --- 手機版調整 --- */
@media (max-width: 480px) {
  .chatbot-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    bottom: 8px;
    right: 8px;
    border-radius: 12px;
  }
  .chatbot-toggle {
    bottom: 80px;
    right: 16px;
  }
}
