/* ═══════════════════════════════════════════════════════════════
   S27Bot — Chatbot Widget (V2 Design System)
   Glass-morphism, blue accent, Sora typography
   ═══════════════════════════════════════════════════════════════ */

/* ═══ Container ═══ */
#support-chatbot {
  position: fixed;
  bottom: 0;
  right: 0;
  pointer-events: none;
  z-index: 9999;
}

#support-chatbot > * {
  pointer-events: auto;
}

/* ═══ Floating Chat Button ═══ */
.chat-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #00b4ff, #0090cc);
  border-radius: 16px;
  border: 1px solid rgba(0, 180, 255, 0.3);
  box-shadow:
    0 4px 20px rgba(0, 180, 255, 0.35),
    0 0 0 0 rgba(0, 180, 255, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: all 0.3s ease;
  animation: chat-btn-pulse 3s ease-in-out infinite;
}

.chat-button:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    0 8px 28px rgba(0, 180, 255, 0.45),
    0 0 0 0 rgba(0, 180, 255, 0);
  animation: none;
}

.chat-button svg {
  width: 26px;
  height: 26px;
  fill: white;
}

@keyframes chat-btn-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(0,180,255,0.35), 0 0 0 0 rgba(0,180,255,0.2); }
  50% { box-shadow: 0 4px 20px rgba(0,180,255,0.35), 0 0 0 8px rgba(0,180,255,0); }
}

/* ═══ Chat Window ═══ */
.chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 580px;
  border-radius: 20px;
  display: none;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255,255,255,0.04);
  animation: chat-open 0.3s ease;
}

/* Dark theme window */
[data-theme="dark"] .chat-window {
  background: rgba(10, 14, 24, 0.96);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
}

/* Light theme window */
[data-theme="light"] .chat-window {
  background: rgba(248, 250, 252, 0.98);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0,0,0,0.04);
}

.chat-window.open {
  display: flex;
}

@keyframes chat-open {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ═══ Header ═══ */
.chat-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

[data-theme="dark"] .chat-header {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="light"] .chat-header {
  background: rgba(255, 255, 255, 0.6);
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-lottie {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.chat-header h3 {
  margin: 0;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--heading-sub);
}

.chat-header .chat-subtitle {
  margin: 0;
  font-size: 11px;
  font-weight: 400;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-header .chat-subtitle .online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  animation: pulse-soft 2.5s ease-in-out infinite;
}

.chat-close {
  background: none;
  border: none;
  color: var(--faint);
  font-size: 22px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s;
}

.chat-close:hover {
  background: var(--glass);
  color: var(--heading-sub);
}

/* ═══ Messages ═══ */
.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

[data-theme="dark"] .chat-messages {
  background: rgba(6, 8, 13, 0.5);
}

[data-theme="light"] .chat-messages {
  background: rgba(241, 245, 249, 0.4);
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--dim);
  border-radius: 2px;
}

/* ═══ Message Bubbles ═══ */
.chat-message {
  display: flex;
  gap: 10px;
  animation: msg-in 0.3s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
  flex-direction: row-reverse;
}

.chat-message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.chat-message.assistant .chat-message-avatar {
  background: linear-gradient(135deg, #00b4ff, #0090cc);
  color: white;
}

.chat-message.user .chat-message-avatar {
  background: var(--glass-border);
  color: var(--muted);
}

.chat-message-content {
  max-width: 78%; /* overridden when inside .chat-message-body */
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.6;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 13.5px;
  font-weight: 300;
}

.chat-message-content strong {
  font-weight: 600;
}

.chat-message-content code {
  background: var(--glass);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}

.chat-message.assistant .chat-message-content {
  border-bottom-left-radius: 4px;
}

.chat-message-body .chat-message-content {
  max-width: 100%; /* parent .chat-message-body handles the constraint */
}

[data-theme="dark"] .chat-message.assistant .chat-message-content {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

[data-theme="light"] .chat-message.assistant .chat-message-content {
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
}

.chat-message.user .chat-message-content {
  background: linear-gradient(135deg, #00b4ff, #0090cc);
  color: white;
  border-bottom-right-radius: 4px;
  font-weight: 400;
}

/* ═══ Typing Indicator ═══ */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 20px 8px;
}

.typing-indicator.active {
  display: flex;
}

.typing-indicator .chat-message-avatar {
  width: 28px;
  height: 28px;
}

.typing-indicator-dots {
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

[data-theme="dark"] .typing-indicator-dots {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

[data-theme="light"] .typing-indicator-dots {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.typing-indicator-dots span {
  width: 7px;
  height: 7px;
  background: #00b4ff;
  border-radius: 50%;
  opacity: 0.5;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-indicator-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 0.8; }
}

/* ═══ Quick Actions ═══ */
.chat-quick-actions {
  padding: 10px 20px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

[data-theme="dark"] .chat-quick-actions {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .chat-quick-actions {
  background: rgba(255, 255, 255, 0.5);
}

.chat-quick-action {
  background: transparent;
  border: 1px solid var(--glass-border);
  padding: 6px 12px;
  border-radius: 20px;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.chat-quick-action:hover {
  background: rgba(0, 180, 255, 0.1);
  border-color: rgba(0, 180, 255, 0.3);
  color: #00b4ff;
}

.chat-contact-btn {
  background: rgba(0, 180, 255, 0.1) !important;
  color: #00b4ff !important;
  border-color: rgba(0, 180, 255, 0.2) !important;
}

.chat-contact-btn:hover {
  background: rgba(0, 180, 255, 0.2) !important;
  border-color: rgba(0, 180, 255, 0.4) !important;
}

/* ═══ Header Actions (TTS + Close) ═══ */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-tts-toggle {
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--faint);
  transition: all 0.2s;
}

.chat-tts-toggle:hover {
  background: var(--glass);
  color: var(--heading-sub);
}

.chat-tts-toggle.active {
  color: #00b4ff;
  background: rgba(0, 180, 255, 0.1);
  border-color: rgba(0, 180, 255, 0.2);
}

/* ═══ Mic Button ═══ */
.chat-mic {
  width: 38px;
  height: 38px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  position: relative;
  color: var(--muted);
}

.chat-mic .mic-icon {
  width: 18px;
  height: 18px;
}

.chat-mic .mic-pulse {
  display: none;
}

.chat-mic:hover:not(.listening) {
  background: rgba(0, 180, 255, 0.1);
  border-color: rgba(0, 180, 255, 0.3);
  color: #00b4ff;
}

/* Listening state */
.chat-mic.listening {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
}

.chat-mic.listening .mic-pulse {
  display: block;
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  animation: mic-pulse-anim 1.2s ease-in-out infinite;
}

@keyframes mic-pulse-anim {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.5; }
}

/* ═══ Input Area ═══ */
.chat-input-container {
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

[data-theme="dark"] .chat-input-container {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .chat-input-container {
  background: rgba(255, 255, 255, 0.5);
}

.chat-input {
  flex: 1;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 13.5px;
  font-weight: 300;
  outline: none;
  transition: border-color 0.2s;
  color: var(--text);
}

[data-theme="dark"] .chat-input {
  background: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] .chat-input {
  background: rgba(255, 255, 255, 0.8);
}

.chat-input::placeholder {
  color: var(--faint);
}

.chat-input:focus {
  border-color: rgba(0, 180, 255, 0.4);
}

.chat-send {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #00b4ff, #0090cc);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-send:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(0, 180, 255, 0.35);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send svg {
  width: 18px;
  height: 18px;
  fill: white;
}

/* ═══ Welcome Message ═══ */
.chat-welcome {
  text-align: center;
  padding: 24px 16px;
}

.chat-welcome-lottie {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
}

.chat-welcome h4 {
  margin: 0 0 8px 0;
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--heading-sub);
}

.chat-welcome p {
  margin: 0;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 300;
  color: var(--muted);
  line-height: 1.6;
}

/* ═══ Contact Form ═══ */
.chat-contact-form {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

[data-theme="dark"] .chat-contact-form {
  background: rgba(6, 8, 13, 0.5);
}

[data-theme="light"] .chat-contact-form {
  background: rgba(241, 245, 249, 0.4);
}

.contact-form-header {
  margin-bottom: 20px;
}

.contact-form-header h4 {
  margin: 0 0 6px 0;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--heading-sub);
}

.contact-form-header p {
  margin: 0;
  font-size: 13px;
  font-weight: 300;
  color: var(--muted);
}

.chat-contact-form input,
.chat-contact-form textarea {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 13.5px;
  font-weight: 300;
  outline: none;
  color: var(--text);
  transition: border-color 0.2s;
}

[data-theme="dark"] .chat-contact-form input,
[data-theme="dark"] .chat-contact-form textarea {
  background: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] .chat-contact-form input,
[data-theme="light"] .chat-contact-form textarea {
  background: rgba(255, 255, 255, 0.8);
}

.chat-contact-form input:focus,
.chat-contact-form textarea:focus {
  border-color: rgba(0, 180, 255, 0.4);
}

.chat-contact-form textarea {
  resize: vertical;
  min-height: 90px;
}

.contact-form-buttons {
  display: flex;
  gap: 8px;
}

.contact-form-buttons .btn-submit,
.contact-form-buttons .btn-cancel {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.contact-form-buttons .btn-submit {
  background: linear-gradient(135deg, #00b4ff, #0090cc);
  color: white;
}

.contact-form-buttons .btn-submit:hover {
  box-shadow: 0 4px 16px rgba(0, 180, 255, 0.35);
  transform: translateY(-1px);
}

.contact-form-buttons .btn-cancel {
  background: var(--glass);
  color: var(--muted);
  border: 1px solid var(--glass-border);
}

.contact-form-buttons .btn-cancel:hover {
  background: var(--glass-border);
  color: var(--heading-sub);
}

/* ═══ Message Body Wrapper (content + feedback) ═══ */
.chat-message-body {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

/* ═══ Feedback Thumbs ═══ */
.chat-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.feedback-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  opacity: 0.4;
  transition: all 0.2s;
  line-height: 1;
}

.feedback-btn:hover:not(:disabled) {
  opacity: 0.8;
  background: var(--glass);
  border-color: var(--glass-border);
}

.feedback-btn:disabled {
  cursor: default;
  opacity: 0.25;
}

.feedback-btn.selected {
  opacity: 1 !important;
  border-color: rgba(0, 180, 255, 0.3);
  background: rgba(0, 180, 255, 0.1);
}

/* ═══ Bot Icon SVG Animation ═══ */
.bot-icon-animated {
  display: block;
}

.bot-icon-animated .bot-ring {
  animation: bot-ring-spin 6s linear infinite;
  transform-origin: center;
}

.bot-icon-animated .bot-eye-left,
.bot-icon-animated .bot-eye-right {
  animation: bot-blink 4s ease-in-out infinite;
}

.bot-icon-animated .bot-eye-right {
  animation-delay: 0.1s;
}

.bot-icon-animated .bot-antenna {
  animation: bot-antenna-bob 2.5s ease-in-out infinite;
  transform-origin: center bottom;
}

@keyframes bot-ring-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes bot-blink {
  0%, 42%, 48%, 100% { transform: scaleY(1); }
  45% { transform: scaleY(0.1); }
}

@keyframes bot-antenna-bob {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

/* ═══ Mobile Responsive ═══ */
@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  .chat-button {
    bottom: 20px;
    right: 20px;
  }

  .chat-quick-action {
    padding: 8px 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ═══ Reduced Motion ═══ */
@media (prefers-reduced-motion: reduce) {
  .chat-button { animation: none; }
  .bot-icon-animated .bot-ring { animation: none; }
  .bot-icon-animated .bot-eye-left,
  .bot-icon-animated .bot-eye-right { animation: none; }
  .bot-icon-animated .bot-antenna { animation: none; }
  .chat-window { animation: none; }
  .chat-message { animation: none; }
}
