/* ========================================
   Chatbot Widget - Modern Apple-Inspired Design
   Modern, Clean, Minimalist Interface
   ======================================== */

/* CSS Custom Properties for Design System */
:root {
  --chatbot-primary: #ff7a00;
  --chatbot-primary-light: #ff9630;
  --chatbot-primary-dark: #e66a00;
  --chatbot-bg-light: #ffffff;
  --chatbot-bg-secondary: #f5f5f7;
  --chatbot-bg-tertiary: #efefef;
  --chatbot-text-primary: #1d1d1f;
  --chatbot-text-secondary: #666666;
  --chatbot-text-tertiary: #999999;
  --chatbot-border: #e5e5e7;
  --chatbot-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --chatbot-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
  --chatbot-shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.15);
  --chatbot-shadow-xl: 0 16px 40px rgba(0, 0, 0, 0.18);
  --chatbot-radius-sm: 8px;
  --chatbot-radius-md: 12px;
  --chatbot-radius-lg: 16px;
  --chatbot-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --chatbot-transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Font Awesome Icon Base Styles */
.chatbot-widget i,
.chatbot-widget [class^="fa-"] {
  display: inline-block;
  line-height: 1;
  vertical-align: -0.125em;
  font-style: normal;
  font-variant: normal;
  font-weight: 900;
  font-family: "Font Awesome 6 Pro", "Font Awesome 6 Free";
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: currentColor;
}

/* Icon spacing adjustments for different contexts */
.chatbot-menu-btn i {
  margin-right: 0.625rem;
  opacity: 0.9;
  display: inline-block;
  color: currentColor;
}

.chatbot-bubble i {
  margin-right: 0.375rem;
  margin-left: 0;
}

.chatbot-header-actions i {
  margin-right: 0;
  font-size: 0.95rem;
  color: #ffffff;
  display: block;
}

.chatbot-toggle i {
  margin-right: 0;
  font-size: 1.25rem;
}

/* Ensure icons are properly centered in buttons */
.chatbot-menu-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
}

.chatbot-menu-btn i {
  flex-shrink: 0;
  min-width: 1.25em;
  text-align: center;
  opacity: 0.9;
  transition: opacity var(--chatbot-transition-fast);
}

/* Icon color and hover states */
.chatbot-menu-btn:hover i {
  opacity: 1;
}

/* Icon accessibility */
i[aria-hidden="true"] {
  display: inline-block;
  pointer-events: none;
  user-select: none;
}

/* Chatbot Container */
.chatbot-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  z-index: 9999;
  font-size: 15px;
  letter-spacing: -0.2px;
}

/* Chat Window */
.chatbot-window {
  position: fixed;
  bottom: calc(70px + 1.5rem);
  right: 1.5rem;
  width: 440px;
  max-width: 90vw;
  height: 620px;
  max-height: 80vh;
  background-color: var(--chatbot-bg-light);
  border-radius: var(--chatbot-radius-lg);
  box-shadow: var(--chatbot-shadow-xl);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.92) translateY(12px);
  transition: opacity var(--chatbot-transition), 
              visibility var(--chatbot-transition), 
              transform var(--chatbot-transition);
  pointer-events: none;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.chatbot-window.active {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* Chat Header */
.chatbot-header {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
  color: #ffffff;
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  border-radius: var(--chatbot-radius-lg) var(--chatbot-radius-lg) 0 0;
}

.chatbot-header-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.chatbot-header-subtitle {
  margin: 0.35rem 0 0 0;
  font-size: 13px;
  opacity: 0.85;
  letter-spacing: -0.2px;
  font-weight: 500;
}

.chatbot-header-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: 1rem;
}

.chatbot-tts-btn,
.chatbot-minimize-btn,
.chatbot-close-btn {
  background: rgba(255, 255, 255, 0.25);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: var(--chatbot-radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--chatbot-transition-fast);
  font-size: 14px;
  padding: 0;
}

.chatbot-tts-btn:hover,
.chatbot-minimize-btn:hover,
.chatbot-close-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.05);
}

.chatbot-tts-btn:active,
.chatbot-minimize-btn:active,
.chatbot-close-btn:active {
  transform: scale(0.95);
}

.chatbot-tts-btn:focus-visible,
.chatbot-minimize-btn:focus-visible,
.chatbot-close-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* TTS Button Muted State */
.chatbot-tts-btn.tts-muted {
  opacity: 0.65;
}

.chatbot-tts-btn.tts-muted:hover {
  opacity: 0.85;
}

/* Chat Messages Container */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background-color: var(--chatbot-bg-light);
}

/* Custom scrollbar for chat messages */
.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--chatbot-border);
  border-radius: 3px;
  transition: background var(--chatbot-transition-fast);
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--chatbot-text-tertiary);
}

/* Message Bubble */
.chatbot-message {
  display: flex;
  gap: 0.5rem;
  animation: slideInUp 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* User Message */
.chatbot-message.user {
  justify-content: flex-end;
}

.chatbot-message.user .chatbot-bubble {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
  color: #ffffff;
  border-radius: 18px 18px 6px 18px;
  margin-left: auto;
  box-shadow: var(--chatbot-shadow-sm);
}

/* Bot Message */
.chatbot-message.bot {
  justify-content: flex-start;
}

.chatbot-message.bot .chatbot-bubble {
  background-color: var(--chatbot-bg-secondary);
  color: var(--chatbot-text-primary);
  border-radius: 18px 18px 18px 6px;
  box-shadow: none;
}

/* Chat Bubble */
.chatbot-bubble {
  max-width: 78%;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Menu Container */
.chatbot-menu {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  overflow-y: auto;
  flex: 1;
  background-color: var(--chatbot-bg-light);
}

/* Menu Message */
.chatbot-menu-message {
  font-size: 13px;
  color: var(--chatbot-text-secondary);
  font-weight: 500;
  margin-bottom: 0.5rem;
  letter-spacing: -0.2px;
}

/* Menu Options Container */
.chatbot-menu-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Menu Buttons */
.chatbot-menu-btn {
  background: var(--chatbot-bg-secondary);
  color: var(--chatbot-text-primary);
  border: 1px solid var(--chatbot-border);
  padding: 0.875rem 1rem;
  border-radius: var(--chatbot-radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--chatbot-transition-fast);
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.4;
  white-space: normal;
  letter-spacing: -0.2px;
}

.chatbot-menu-btn:hover {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
  color: #ffffff;
  border-color: transparent;
  transform: translateY(-1px);
  box-shadow: var(--chatbot-shadow-md);
}

.chatbot-menu-btn:active {
  transform: translateY(0);
  box-shadow: var(--chatbot-shadow-sm);
}

.chatbot-menu-btn:focus-visible {
  outline: 2px solid var(--chatbot-primary);
  outline-offset: 2px;
}

/* Input Area */
.chatbot-input-area {
  display: flex;
  gap: 0.625rem;
  padding: 1rem 1.25rem;
  background-color: var(--chatbot-bg-light);
  border-top: 1px solid var(--chatbot-border);
  flex-shrink: 0;
}

/* Text Input */
.chatbot-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--chatbot-border);
  border-radius: var(--chatbot-radius-sm);
  font-family: inherit;
  font-size: 15px;
  color: var(--chatbot-text-primary);
  transition: border-color var(--chatbot-transition-fast), 
              box-shadow var(--chatbot-transition-fast);
  resize: none;
  max-height: 100px;
  line-height: 1.5;
  letter-spacing: -0.2px;
}

.chatbot-input:focus {
  outline: none;
  border-color: var(--chatbot-primary);
  box-shadow: 0 0 0 3px rgba(255, 122, 0, 0.1);
}

.chatbot-input::placeholder {
  color: var(--chatbot-text-tertiary);
}

/* Send Button */
.chatbot-send-btn {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
  color: #ffffff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--chatbot-radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--chatbot-transition-fast);
  font-size: 16px;
  flex-shrink: 0;
}

.chatbot-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--chatbot-shadow-md);
}

.chatbot-send-btn:active:not(:disabled) {
  transform: translateY(0);
}

.chatbot-send-btn:focus-visible {
  outline: 2px solid var(--chatbot-primary);
  outline-offset: 2px;
}

.chatbot-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Chat Toggle Button */
.chatbot-toggle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 60px;
  height: 60px;
  min-width: 60px;
  min-height: 60px;
  padding: 0;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all var(--chatbot-transition);
  box-shadow: var(--chatbot-shadow-lg);
  position: relative;
  z-index: 10000;
}

.chatbot-toggle:hover {
  transform: scale(1.12);
  box-shadow: var(--chatbot-shadow-xl);
}

.chatbot-toggle:active {
  transform: scale(0.96);
}

.chatbot-toggle:focus-visible {
  outline: 2px solid var(--chatbot-primary);
  outline-offset: 3px;
}

/* Ensure icon inside toggle doesn't stretch the button and is centered */
.chatbot-toggle i,
.chatbot-toggle svg {
  display: inline-block;
  line-height: 1;
  max-width: 55%;
  max-height: 55%;
  color: #ffffff;
}

/* Unread Badge */
.chatbot-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444;
  color: #ffffff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  border: 2.5px solid #ffffff;
  letter-spacing: -0.3px;
}

/* Typing Indicator */
.chatbot-typing {
  display: flex;
  gap: 5px;
  align-items: center;
}

.chatbot-typing-dot {
  width: 8px;
  height: 8px;
  background-color: currentColor;
  border-radius: 50%;
  animation: typingAnimation 1.4s infinite;
}

.chatbot-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbot-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingAnimation {
  0%, 60%, 100% {
    opacity: 0.5;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-8px);
  }
}

/* Mobile Responsive - Tablets */
@media (max-width: 768px) {
  .chatbot-widget {
    bottom: 1rem;
    right: 1rem;
  }

  .chatbot-window {
    width: calc(100vw - 2rem);
    height: 70vh;
    max-height: calc(100vh - 120px);
    border-radius: var(--chatbot-radius-lg);
  }

  .chatbot-toggle {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    font-size: 1.125rem;
  }

  .chatbot-bubble {
    max-width: 82%;
  }

  .chatbot-menu-btn {
    font-size: 14px;
    padding: 0.8rem 0.9rem;
  }

  .chatbot-header-title {
    font-size: 16px;
  }
}

/* Mobile - Small screens */
@media (max-width: 480px) {
  .chatbot-widget {
    bottom: 0.75rem;
    right: 0.75rem;
  }

  .chatbot-window {
    width: calc(100vw - 1.5rem);
    height: calc(100vh - 80px);
    bottom: calc(66px + 0.75rem);
    right: 0;
    border-radius: var(--chatbot-radius-lg);
    max-height: none;
  }

  .chatbot-toggle {
    width: 56px;
    height: 56px;
    font-size: 1.125rem;
  }

  .chatbot-header {
    padding: 1rem 1.25rem;
  }

  .chatbot-header-title {
    font-size: 16px;
  }

  .chatbot-header-subtitle {
    font-size: 12px;
  }

  .chatbot-messages {
    padding: 0.875rem 1rem;
    gap: 0.625rem;
  }

  .chatbot-menu {
    padding: 0.875rem 1rem;
    gap: 0.5rem;
  }

  .chatbot-menu-btn {
    font-size: 13px;
    padding: 0.75rem 0.875rem;
    min-height: 40px;
  }

  .chatbot-bubble {
    max-width: 85%;
    font-size: 14px;
  }

  .chatbot-input-area {
    padding: 0.875rem 1rem;
    gap: 0.5rem;
  }

  .chatbot-input {
    font-size: 14px;
    padding: 0.65rem 0.9rem;
  }

  .chatbot-send-btn {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }
}

/* Accessibility - Focus visible */
.chatbot-toggle:focus-visible,
.chatbot-minimize-btn:focus-visible,
.chatbot-close-btn:focus-visible,
.chatbot-send-btn:focus-visible,
.chatbot-menu-btn:focus-visible {
  outline: 2px solid var(--chatbot-primary);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .chatbot-window,
  .chatbot-message,
  .chatbot-toggle,
  .chatbot-typing-dot,
  .chatbot-menu-btn,
  .chatbot-minimize-btn,
  .chatbot-close-btn,
  .chatbot-send-btn {
    animation: none !important;
    transition: none !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: more) {
  .chatbot-menu-btn {
    border-width: 1.5px;
  }

  .chatbot-window {
    border-width: 1.5px;
  }

  .chatbot-header {
    border: 1.5px solid var(--chatbot-primary);
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --chatbot-bg-light: #1d1d1f;
    --chatbot-bg-secondary: #424245;
    --chatbot-bg-tertiary: #545456;
    --chatbot-text-primary: #f5f5f7;
    --chatbot-text-secondary: #a1a1a6;
    --chatbot-text-tertiary: #86868b;
    --chatbot-border: #424245;
  }

  .chatbot-message.bot .chatbot-bubble {
    box-shadow: var(--chatbot-shadow-sm);
  }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .chatbot-widget i,
  .chatbot-widget [class^="fa-"] {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* Print styles */
@media print {
  .chatbot-widget {
    display: none;
  }
}
