/* ============================================
   PROFESSIONAL CHATBOT WIDGET - UX BEST PRACTICES
   Following Material Design, Apple HIG, and Nielsen Norman Group Guidelines
   ============================================ */

:root {
  --chatbot-primary: #1e3a8a;
  --chatbot-primary-hover: #1e40af;
  --chatbot-success: #059669;
  --chatbot-bg-light: #f8fafc;
  --chatbot-border: #e2e8f0;
  --chatbot-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  --chatbot-shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.15);
  --chatbot-radius: 16px;
  --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   FLOATING ACTION BUTTON (FAB)
   Following Material Design 3.0 Guidelines
   ============================================ */

.chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.chatbot-toggle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, #2563eb 100%);
  border: none;
  box-shadow: 0 4px 16px rgba(30, 58, 138, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--chatbot-transition);
  position: relative;
  overflow: hidden;
}

/* Ripple effect for Material Design */
.chatbot-toggle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition:
    width 0.6s,
    height 0.6s;
}

.chatbot-toggle:active::before {
  width: 100px;
  height: 100px;
}

.chatbot-toggle:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 8px 24px rgba(30, 58, 138, 0.4);
}

.chatbot-toggle:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(30, 58, 138, 0.2);
}

.chat-icon {
  font-size: 28px;
  line-height: 1;
  transition: transform 0.3s ease;
}

.chatbot-toggle[aria-expanded="true"] .chat-icon {
  transform: rotate(180deg);
}

/* Badge for notifications (UX: Provide clear visual feedback) */
.chatbot-toggle::after {
  content: attr(data-badge);
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  opacity: 0;
  transform: scale(0);
  transition: var(--chatbot-transition);
}

.chatbot-toggle[data-badge]:not([data-badge=""])::after {
  opacity: 1;
  transform: scale(1);
}

/* ============================================
   CHAT WINDOW
   Following Card Design Pattern & Progressive Disclosure
   ============================================ */

.chatbot-window {
  position: fixed;
  bottom: 104px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 48px);
  height: 650px;
  max-height: calc(100vh - 150px);
  background: white;
  border-radius: var(--chatbot-radius);
  box-shadow: var(--chatbot-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.9) translateY(20px);
  pointer-events: none;
  transition: var(--chatbot-transition);
  border: 1px solid var(--chatbot-border);
}

.chatbot-window:not([hidden]) {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ============================================
   HEADER - Brand Identity & Context
   ============================================ */

.chatbot-header {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, #2563eb 100%);
  color: white;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: relative;
}

.chatbot-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
}

/* Status indicator (UX: Show system status) */
.chatbot-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-top: 4px;
  opacity: 0.9;
}

.chatbot-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  animation: pulse-status 2s ease-in-out infinite;
}

@keyframes pulse-status {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.chatbot-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: var(--chatbot-transition);
  font-size: 20px;
  line-height: 1;
}

.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chatbot-close:focus {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* ============================================
   MESSAGES AREA - Conversational UI
   ============================================ */

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  background: var(--chatbot-bg-light);
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Custom scrollbar (UX: Subtle, non-intrusive) */
.chatbot-messages::-webkit-scrollbar {
  width: 8px;
}

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

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
  border: 2px solid var(--chatbot-bg-light);
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ============================================
   MESSAGE BUBBLES - Clear Visual Hierarchy
   ============================================ */

.chatbot-message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: message-appear 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 100%;
}

@keyframes message-appear {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chatbot-message-bot {
  flex-direction: row;
}

.chatbot-message-user {
  flex-direction: row-reverse;
  align-self: flex-end;
}

/* Avatar (UX: Visual identity for sender) */
.message-avatar {
  min-width: 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, #2563eb 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.2);
}

.chatbot-message-user .message-avatar {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* Message content (UX: High contrast, comfortable reading) */
.message-content {
  background: white;
  padding: 12px 16px;
  border-radius: 16px;
  max-width: calc(100% - 60px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  line-height: 1.6;
  font-size: 15px;
  color: #1f2937;
  word-wrap: break-word;
  position: relative;
}

.chatbot-message-bot .message-content {
  border-bottom-left-radius: 4px;
}

.chatbot-message-user .message-content {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, #2563eb 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

/* Links in messages (UX: Accessible, clear affordance) */
.message-content a {
  color: inherit;
  text-decoration: underline;
  font-weight: 500;
  text-underline-offset: 2px;
}

.message-content a:hover {
  text-decoration-thickness: 2px;
}

.chatbot-message-bot .message-content a {
  color: var(--chatbot-primary);
}

/* Timestamp (UX: Context without clutter) */
.message-time {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 4px;
  padding: 0 16px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chatbot-message:hover .message-time {
  opacity: 1;
}

/* ============================================
   TYPING INDICATOR - Feedback & Anticipation
   ============================================ */

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

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

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

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

/* ============================================
   INPUT AREA - Clear Affordance & Feedback
   ============================================ */

.chatbot-input-container {
  padding: 16px 20px;
  background: white;
  border-top: 1px solid var(--chatbot-border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  min-height: 72px;
}

.chatbot-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--chatbot-border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  transition: all 0.2s ease;
  background: white;
  color: #1f2937;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  line-height: 1.5;
}

.chatbot-input:focus {
  outline: none;
  border-color: var(--chatbot-primary);
  background: white;
  box-shadow: 0 0 0 4px rgba(30, 58, 138, 0.08);
}

.chatbot-input::placeholder {
  color: #9ca3af;
  opacity: 0.7;
}

/* Character counter (UX: Set expectations) */
.chatbot-input-container[data-max]::after {
  content: attr(data-count) "/" attr(data-max);
  position: absolute;
  bottom: 20px;
  right: 100px;
  font-size: 11px;
  color: #9ca3af;
}

.chatbot-send {
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, #2563eb 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: var(--chatbot-transition);
  white-space: nowrap;
  min-width: 80px;
  height: 44px;
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.2);
}

.chatbot-send:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(30, 58, 138, 0.3);
}

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

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

.chatbot-send:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(30, 58, 138, 0.2);
}

/* ============================================
   QUICK REPLIES - Guided Conversation
   ============================================ */

.chatbot-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 16px;
  animation: quick-replies-appear 0.4s ease 0.2s both;
}

@keyframes quick-replies-appear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-quick-reply-btn {
  background: white;
  color: var(--chatbot-primary);
  border: 2px solid var(--chatbot-primary);
  border-radius: 20px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--chatbot-transition);
  text-align: center;
  white-space: nowrap;
}

.chatbot-quick-reply-btn:hover {
  background: var(--chatbot-primary);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(30, 58, 138, 0.2);
}

.chatbot-quick-reply-btn:active {
  transform: translateY(0);
}

/* ============================================
   FORMS - Progressive Disclosure & Validation
   ============================================ */

.chatbot-form {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: white;
  border-radius: 12px;
  margin: 0 20px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.chatbot-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chatbot-form-field label {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.chatbot-form-field input,
.chatbot-form-field textarea {
  padding: 12px 14px;
  border: 2px solid var(--chatbot-border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  transition: all 0.2s ease;
  background: var(--chatbot-bg-light);
}

.chatbot-form-field input:focus,
.chatbot-form-field textarea:focus {
  outline: none;
  border-color: var(--chatbot-primary);
  background: white;
  box-shadow: 0 0 0 4px rgba(30, 58, 138, 0.08);
}

.chatbot-form-field input:invalid:not(:placeholder-shown),
.chatbot-form-field textarea:invalid:not(:placeholder-shown) {
  border-color: #ef4444;
}

.chatbot-submit-btn {
  background: var(--chatbot-primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--chatbot-transition);
  margin-top: 8px;
}

.chatbot-submit-btn:hover {
  background: var(--chatbot-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(30, 58, 138, 0.3);
}

/* ============================================
   RESPONSIVE DESIGN - Mobile-First
   ============================================ */

@media (max-width: 640px) {
  .chatbot-window {
    bottom: 96px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    height: calc(100vh - 140px);
    max-height: none;
    border-radius: 16px 16px 0 0;
  }

  .chatbot-toggle {
    width: 56px;
    height: 56px;
    bottom: 20px;
    right: 20px;
  }

  .chatbot-widget {
    bottom: 20px;
    right: 20px;
  }

  .message-content {
    font-size: 14px;
    max-width: calc(100% - 50px);
  }

  .chatbot-input-container {
    padding: 12px 16px;
    gap: 8px;
  }

  .chatbot-send {
    padding: 12px 16px;
    min-width: 70px;
  }

  .chatbot-header {
    padding: 16px 20px;
  }

  .chatbot-messages {
    padding: 16px;
  }
}

/* ============================================
   ACCESSIBILITY - WCAG 2.1 AA Compliant
   ============================================ */

/* Focus visible for keyboard navigation */
.chatbot-toggle:focus-visible,
.chatbot-close:focus-visible,
.chatbot-send:focus-visible,
.chatbot-quick-reply-btn:focus-visible,
.chatbot-submit-btn:focus-visible {
  outline: 3px solid var(--chatbot-primary);
  outline-offset: 2px;
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .chatbot-toggle,
  .chatbot-send,
  .chatbot-submit-btn {
    border: 2px solid currentColor;
  }

  .message-content {
    border: 1px solid currentColor;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .chatbot-window {
    background: #1f2937;
    border-color: #374151;
  }

  .chatbot-messages {
    background: #111827;
  }

  .message-content {
    background: #374151;
    color: #f3f4f6;
  }

  .chatbot-input-container {
    background: #1f2937;
    border-color: #374151;
  }

  .chatbot-input {
    background: #111827;
    border-color: #374151;
    color: #f3f4f6;
  }

  .chatbot-form {
    background: #374151;
  }

  .chatbot-form-field input,
  .chatbot-form-field textarea {
    background: #111827;
    color: #f3f4f6;
    border-color: #4b5563;
  }

  .chatbot-quick-reply-btn {
    background: #374151;
    color: white;
    border-color: #4b5563;
  }

  .typing-indicator {
    background: #374151;
  }
}

/* ============================================
   LOADING STATES - User Feedback
   ============================================ */

.chatbot-loading {
  pointer-events: none;
  opacity: 0.6;
}

.chatbot-loading .chatbot-send::after {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  margin-left: 8px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Error state */
.chatbot-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 0 20px 16px;
  font-size: 14px;
  border-left: 4px solid #ef4444;
}

/* Success state */
.chatbot-success {
  background: #d1fae5;
  color: #065f46;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 0 20px 16px;
  font-size: 14px;
  border-left: 4px solid #10b981;
}
