/**
 * HYT Website — Chat Widget Styles
 * Design System: Global Tide
 */

/* ============ Toggle Button ============ */
.chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-teal);
  color: var(--color-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(22, 119, 211, 0.3);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  z-index: 9998;
  padding: 0;
}

.chat-toggle:hover {
  background: var(--color-teal-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(22, 119, 211, 0.4);
}

.chat-toggle:active {
  transform: scale(0.95);
}

.chat-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(22, 119, 211, 0.3), 0 4px 12px rgba(22, 119, 211, 0.3);
}

/* ============ 未读徽章 ============ */
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background: var(--color-coral);
  color: var(--color-white);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(224, 90, 51, 0.4);
  animation: badgePop 0.3s cubic-bezier(0.16, 1, 0.3, 1), badgePulse 2s ease-in-out infinite 0.3s;
}
@keyframes badgePop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes badgePulse { 0%, 100% { box-shadow: 0 2px 6px rgba(224, 90, 51, 0.4); } 50% { box-shadow: 0 2px 16px rgba(224, 90, 51, 0.7); } }

/* ============ 醒目标幅通知 ============ */
.chat-notify-banner {
  position: fixed;
  bottom: 92px;
  right: 24px;
  left: auto;
  max-width: 360px;
  background: var(--color-ocean);
  color: var(--color-white);
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 9997;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(11, 29, 74, 0.3);
  animation: bannerSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  transition: transform 0.2s;
}
.chat-notify-banner:hover { transform: translateY(-2px); }
.chat-notify-banner .banner-icon { font-size: 22px; flex-shrink: 0; }
.chat-notify-banner .banner-text { flex: 1; line-height: 1.4; opacity: 0.9; }
.chat-notify-banner .banner-action { font-size: 12px; opacity: 0.6; white-space: nowrap; }
@keyframes bannerSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ Chat Panel ============ */
.chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: var(--color-white);
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(10, 22, 40, 0.08), 0 8px 10px -6px rgba(10, 22, 40, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  animation: chatSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes chatSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-panel.hidden {
  display: none;
}

/* ============ Chat Header ============ */
.chat-header {
  background: var(--color-ocean);
  color: var(--color-white);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header-title {
  font-weight: 600;
  font-size: 1rem;
}

.chat-header-status {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* ============ Chat Messages ============ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #FAFAF9;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.chat-message-user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message-agent {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message-user .chat-bubble {
  background: var(--color-teal-light);
  color: var(--color-ocean);
  border-bottom-right-radius: 4px;
}

.chat-message-agent .chat-bubble {
  background: var(--color-white);
  color: var(--color-slate);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.chat-message-time {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* ============ Offline Banner ============ */
.chat-offline-banner {
  background: #FEF3C7;
  color: #D97706;
  text-align: center;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  margin: 8px 0;
}

/* ============ Chat Input ============ */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-white);
  flex-shrink: 0;
}

.chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
  background: #FAFAF9;
}

.chat-input:focus {
  border-color: var(--color-teal);
  box-shadow: 0 0 0 3px rgba(22, 119, 211, 0.15);
}

.chat-input::placeholder {
  color: var(--color-text-muted);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--color-teal);
  color: var(--color-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: var(--color-teal-hover);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-send-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(22, 119, 211, 0.3);
}

/* ============ Typing Indicator ============ */
.chat-typing-indicator .typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  min-width: 56px;
}

.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted);
  display: inline-block;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-bubble span:nth-child(1) { animation-delay: -0.32s; }
.typing-bubble span:nth-child(2) { animation-delay: -0.16s; }
.typing-bubble span:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ============ Sender Name ============ */
.chat-sender-name {
  font-size: 0.6875rem;
  color: var(--color-gray);
  margin-bottom: 2px;
  margin-left: 2px;
  font-weight: 500;
}

/* ============ Message Slide Animation ============ */
@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ Responsive ============ */
@media (max-width: 480px) {
  .chat-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    bottom: 80px;
    right: 8px;
    border-radius: 16px;
  }

  .chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }
}
