/* ============================
   聊天系統樣式
   ============================ */

/* 聊天按鈕 - 浮動在右下角 */
.chat-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #4dd0e1, #7c4dff);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(77, 208, 225, 0.4);
  transition: all 0.3s ease;
  z-index: 9998;
}

.chat-button:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 32px rgba(77, 208, 225, 0.6);
}

.chat-button:focus {
  outline: 3px solid #4dd0e1;
  outline-offset: 2px;
}

.chat-button:focus:not(:focus-visible) {
  outline: none;
}

.chat-button svg {
  color: #fff;
  width: 28px;
  height: 28px;
}

/* 未讀訊息徽章 */
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff4444;
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  border: 2px solid #0a0f1f;
}

/* 聊天視窗 */
.chat-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  height: 550px;
  background: rgba(18, 28, 58, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  backdrop-filter: blur(20px);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 聊天視窗標題列 */
.chat-header {
  background: linear-gradient(135deg, rgba(124, 77, 255, 0.3), rgba(77, 208, 225, 0.3));
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px 16px 0 0;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: #e5ecff;
}

.chat-header-title svg {
  color: #4dd0e1;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #9fb3d1;
  margin-left: auto;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}

.status-dot.status-online {
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.status-dot.status-offline {
  background: #ef4444;
}

.chat-close {
  background: transparent;
  border: none;
  color: #9fb3d1;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e5ecff;
}

.chat-close:focus {
  outline: 2px solid #4dd0e1;
  outline-offset: 2px;
}

/* 訊息區域 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(10, 15, 31, 0.4);
}

/* 自訂滾動條 */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* 歡迎訊息 */
.chat-welcome {
  text-align: center;
  padding: 32px 20px;
  color: #9fb3d1;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.welcome-text {
  font-size: 15px;
  line-height: 1.6;
}

/* 訊息氣泡 */
.chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 使用者訊息 - 靠右 */
.chat-message-user {
  align-self: flex-end;
  align-items: flex-end;
}

/* AI 訊息 - 靠左 */
.chat-message-ai {
  align-self: flex-start;
  align-items: flex-start;
}

/* 錯誤訊息 - 置中 */
.chat-message-error {
  align-self: center;
  max-width: 90%;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 14px;
}

/* 使用者訊息氣泡樣式 */
.chat-message-user .message-bubble {
  background: linear-gradient(135deg, #4dd0e1, #7c4dff);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* AI 訊息氣泡樣式 */
.chat-message-ai .message-bubble {
  background: rgba(255, 255, 255, 0.08);
  color: #e5ecff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom-left-radius: 4px;
}

/* 錯誤訊息樣式 */
.chat-message-error .message-bubble {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
  text-align: center;
  font-size: 13px;
}

/* 系統訊息樣式 */
.chat-message-system {
  align-self: center;
  max-width: 90%;
}

.chat-message-system .message-bubble {
  background: rgba(77, 208, 225, 0.1);
  color: #4dd0e1;
  border: 1px solid rgba(77, 208, 225, 0.3);
  text-align: center;
  font-size: 12px;
  font-style: italic;
}

.message-time {
  font-size: 11px;
  color: #64748b;
  padding: 0 4px;
}

/* 輸入區域 */
.chat-input-wrapper {
  padding: 16px 20px;
  background: rgba(15, 24, 48, 0.6);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0 0 16px 16px;
  display: flex;
  gap: 10px;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #e5ecff;
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
}

.chat-input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: #4dd0e1;
  box-shadow: 0 0 0 3px rgba(77, 208, 225, 0.15);
}

.chat-input::placeholder {
  color: #64748b;
}

.chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-send {
  background: linear-gradient(135deg, #4dd0e1, #7c4dff);
  border: none;
  border-radius: 10px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(77, 208, 225, 0.4);
}

.chat-send:active {
  transform: scale(0.95);
}

.chat-send:focus {
  outline: 2px solid #4dd0e1;
  outline-offset: 2px;
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chat-send svg {
  color: #fff;
}

/* 響應式設計 */
@media (max-width: 480px) {
  .chat-window {
    width: calc(100vw - 32px);
    height: calc(100vh - 140px);
    right: 16px;
    bottom: 90px;
    max-height: calc(100vh - 140px);
  }

  .chat-button {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  .chat-button svg {
    width: 24px;
    height: 24px;
  }
  
  .message-bubble {
    font-size: 13px;
    padding: 10px 14px;
  }
  
  .chat-input {
    font-size: 16px; /* 防止 iOS 自動縮放 */
  }
}

@media (max-width: 960px) and (min-width: 481px) {
  .chat-window {
    width: 360px;
  }
}

/* 防止與其他元素 z-index 衝突 */
@media print {
  .chat-button,
  .chat-window {
    display: none !important;
  }
}

/* iOS APP 橫屏模式優化 */
@media screen and (orientation: landscape) {
  /* 確保 body 和 html 填滿整個螢幕 */
  html, body {
    width: 100vw !important;
    height: 100vh !important;
    overflow-x: hidden !important;
  }
  
  /* 橫屏時調整聊天視窗 */
  .chat-window {
    height: 85vh !important;
    max-height: 85vh !important;
    width: 95vw !important;
    max-width: 700px !important;
  }
  
  .chat-messages {
    height: calc(85vh - 180px) !important;
    max-height: calc(85vh - 180px) !important;
  }
  
  /* 橫屏時調整按鈕 */
  .chat-button {
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
  }
  
  .chat-button svg {
    width: 26px;
    height: 26px;
  }
  
  /* 橫屏時輸入框調整 */
  .chat-input-container {
    padding: 12px 16px;
  }
  
  .chat-input {
    font-size: 15px;
    padding: 10px 14px;
  }
}
