/* =============================================================================
   AVexport Chat Widget Styles
   JivoSite-like chat widget with modern design
   ============================================================================= */

/* -----------------------------------------------------------------------------
   CSS Variables for theming
   ----------------------------------------------------------------------------- */
:root {
  --av-chat-primary: #16a34a;
  --av-chat-primary-dark: #15803d;
  --av-chat-primary-light: #22c55e;
  --av-chat-text: #1e293b;
  --av-chat-text-muted: #64748b;
  --av-chat-text-light: #94a3b8;
  --av-chat-bg: #ffffff;
  --av-chat-bg-light: #f8fafc;
  --av-chat-bg-dark: #f1f5f9;
  --av-chat-border: #e2e8f0;
  --av-chat-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --av-chat-shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --av-chat-radius: 1rem;
  --av-chat-radius-lg: 1.5rem;
  --av-chat-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* -----------------------------------------------------------------------------
   Container
   ----------------------------------------------------------------------------- */
.av-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* -----------------------------------------------------------------------------
   Floating Button
   ----------------------------------------------------------------------------- */
.av-chat-button {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--av-chat-primary) 0%, var(--av-chat-primary-dark) 100%);
  border: 3px solid var(--av-chat-bg);
  box-shadow: var(--av-chat-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--av-chat-transition);
  outline: none;
}

.av-chat-button:hover {
  transform: scale(1.1);
  background: linear-gradient(135deg, var(--av-chat-primary-light) 0%, var(--av-chat-primary) 100%);
}

.av-chat-button:active {
  transform: scale(1.05);
}

.av-chat-button svg {
  width: 28px;
  height: 28px;
  color: white;
  transition: transform var(--av-chat-transition);
}

.av-chat-button.av-chat-open svg.av-chat-icon {
  display: none;
}

.av-chat-button svg.av-chat-close-icon {
  display: none;
}

.av-chat-button.av-chat-open svg.av-chat-close-icon {
  display: block;
}

/* Pulse animation */
.av-chat-button::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--av-chat-primary);
  opacity: 0;
  animation: av-chat-pulse 2s ease-out infinite;
}

.av-chat-button.av-chat-open::before,
.av-chat-button:hover::before {
  animation: none;
  opacity: 0;
}

@keyframes av-chat-pulse {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

/* Badge for unread messages */
.av-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: #ef4444;
  color: white;
  font-size: 12px;
  font-weight: 600;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--av-chat-bg);
  opacity: 0;
  transform: scale(0);
  transition: all var(--av-chat-transition);
}

.av-chat-badge.av-chat-visible {
  opacity: 1;
  transform: scale(1);
}

/* -----------------------------------------------------------------------------
   Proactive Invitation Bubble
   ----------------------------------------------------------------------------- */
.av-chat-invitation {
  position: absolute;
  bottom: 75px;
  right: 0;
  width: 280px;
  background: var(--av-chat-bg);
  border-radius: var(--av-chat-radius);
  box-shadow: var(--av-chat-shadow);
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.95);
  transition: all var(--av-chat-transition);
}

.av-chat-invitation.av-chat-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.av-chat-invitation::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 24px;
  width: 16px;
  height: 16px;
  background: var(--av-chat-bg);
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.av-chat-invitation-content {
  position: relative;
  z-index: 1;
}

.av-chat-invitation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.av-chat-invitation-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--av-chat-primary);
}

.av-chat-invitation-operator {
  font-weight: 600;
  color: var(--av-chat-text);
  font-size: 14px;
}

.av-chat-invitation-status {
  font-size: 12px;
  color: var(--av-chat-primary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.av-chat-invitation-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--av-chat-primary);
  border-radius: 50%;
}

.av-chat-invitation-text {
  color: var(--av-chat-text);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.av-chat-invitation-response-time {
  font-size: 12px;
  color: var(--av-chat-text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.av-chat-invitation-response-time svg {
  width: 12px;
  height: 12px;
  color: var(--av-chat-primary);
}

.av-chat-invitation-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--av-chat-text-light);
  transition: color var(--av-chat-transition);
  border-radius: 50%;
}

.av-chat-invitation-close:hover {
  color: var(--av-chat-text);
  background: var(--av-chat-bg-dark);
}

/* -----------------------------------------------------------------------------
   Chat Window
   ----------------------------------------------------------------------------- */
.av-chat-window {
  position: absolute;
  bottom: 75px;
  right: 0;
  width: 380px;
  height: 520px;
  background: var(--av-chat-bg);
  border-radius: var(--av-chat-radius-lg);
  box-shadow: var(--av-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all var(--av-chat-transition);
}

.av-chat-window.av-chat-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.av-chat-header {
  background: linear-gradient(135deg, var(--av-chat-primary) 0%, var(--av-chat-primary-dark) 100%);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.av-chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.av-chat-header-info {
  flex: 1;
}

.av-chat-header-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}

.av-chat-header-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.av-chat-header-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 6px #4ade80;
  flex-shrink: 0;
}

.av-chat-header-status.av-chat-offline::before {
  background: #fbbf24;
  box-shadow: 0 0 6px #fbbf24;
}

.av-chat-header-response-time {
  font-size: 11px;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.av-chat-header-response-time svg {
  width: 12px;
  height: 12px;
  opacity: 0.9;
}

.av-chat-header-close {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background var(--av-chat-transition);
}

.av-chat-header-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.av-chat-header-close svg {
  width: 18px;
  height: 18px;
}

/* -----------------------------------------------------------------------------
   Contact Form Overlay
   ----------------------------------------------------------------------------- */
.av-chat-contact-form {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--av-chat-bg);
  z-index: 10;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: all var(--av-chat-transition);
}

.av-chat-contact-form.av-chat-visible {
  opacity: 1;
  visibility: visible;
}

.av-chat-contact-header {
  background: linear-gradient(135deg, var(--av-chat-primary) 0%, var(--av-chat-primary-dark) 100%);
  color: white;
  padding: 24px 20px;
  text-align: center;
}

.av-chat-contact-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.av-chat-contact-subtitle {
  font-size: 13px;
  opacity: 0.9;
}

.av-chat-contact-body {
  flex: 1;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.av-chat-contact-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.av-chat-contact-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--av-chat-text);
}

.av-chat-contact-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--av-chat-border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--av-chat-text);
  background: var(--av-chat-bg);
  transition: all var(--av-chat-transition);
  outline: none;
}

.av-chat-contact-input:focus {
  border-color: var(--av-chat-primary);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}

.av-chat-contact-input::placeholder {
  color: var(--av-chat-text-light);
}

.av-chat-contact-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.av-chat-contact-submit {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--av-chat-primary) 0%, var(--av-chat-primary-dark) 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--av-chat-transition);
}

.av-chat-contact-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

.av-chat-contact-skip {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--av-chat-text-muted);
  border: none;
  font-size: 13px;
  cursor: pointer;
  transition: color var(--av-chat-transition);
}

.av-chat-contact-skip:hover {
  color: var(--av-chat-text);
}

/* -----------------------------------------------------------------------------
   Messages Area
   ----------------------------------------------------------------------------- */
.av-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--av-chat-bg-light);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.av-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.av-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.av-chat-messages::-webkit-scrollbar-thumb {
  background: var(--av-chat-border);
  border-radius: 3px;
}

/* Message wrapper */
.av-chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: av-chat-message-in 0.3s ease-out;
}

@keyframes av-chat-message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.av-chat-message.av-chat-user {
  align-self: flex-end;
  align-items: flex-end;
}

.av-chat-message.av-chat-operator {
  align-self: flex-start;
  align-items: flex-start;
}

/* Message bubble */
.av-chat-message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.av-chat-message.av-chat-user .av-chat-message-bubble {
  background: linear-gradient(135deg, var(--av-chat-primary) 0%, var(--av-chat-primary-dark) 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.av-chat-message.av-chat-operator .av-chat-message-bubble {
  background: var(--av-chat-bg);
  color: var(--av-chat-text);
  border: 1px solid var(--av-chat-border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--av-chat-shadow-sm);
}

/* Message timestamp */
.av-chat-message-time {
  font-size: 11px;
  color: var(--av-chat-text-light);
  margin-top: 4px;
  padding: 0 4px;
}

/* -----------------------------------------------------------------------------
   Quick Replies
   ----------------------------------------------------------------------------- */
.av-chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px;
  margin-top: 4px;
  animation: av-chat-message-in 0.3s ease-out;
}

.av-chat-quick-reply {
  display: inline-flex;
  align-items: center;
  padding: 10px 16px;
  background: var(--av-chat-bg);
  color: var(--av-chat-primary);
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--av-chat-primary);
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--av-chat-transition);
  white-space: nowrap;
}

.av-chat-quick-reply:hover {
  background: var(--av-chat-primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}

.av-chat-quick-reply:active {
  transform: translateY(0);
}

.av-chat-quick-reply svg {
  width: 14px;
  height: 14px;
  margin-right: 6px;
  flex-shrink: 0;
}

/* -----------------------------------------------------------------------------
   Inline Contact Form
   ----------------------------------------------------------------------------- */
.av-chat-inline-form {
  background: var(--av-chat-bg);
  border: 1px solid var(--av-chat-border);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 8px 0;
  box-shadow: var(--av-chat-shadow-sm);
  animation: av-chat-message-in 0.3s ease-out;
}

.av-chat-inline-form-label {
  font-size: 13px;
  color: var(--av-chat-text-muted);
  margin-bottom: 10px;
}

.av-chat-inline-form-row {
  display: flex;
  gap: 8px;
}

.av-chat-inline-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--av-chat-border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--av-chat-text);
  background: var(--av-chat-bg-light);
  outline: none;
  transition: all var(--av-chat-transition);
}

.av-chat-inline-input:focus {
  border-color: var(--av-chat-primary);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}

.av-chat-inline-input.av-chat-error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.av-chat-inline-input::placeholder {
  color: var(--av-chat-text-light);
}

.av-chat-inline-submit {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  background: var(--av-chat-primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all var(--av-chat-transition);
}

.av-chat-inline-submit:hover {
  background: var(--av-chat-primary-dark);
  transform: scale(1.05);
}

.av-chat-inline-submit svg {
  width: 20px;
  height: 20px;
}

/* -----------------------------------------------------------------------------
   Typing Indicator
   ----------------------------------------------------------------------------- */
.av-chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--av-chat-bg);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: var(--av-chat-shadow-sm);
  max-width: 120px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--av-chat-transition);
}

.av-chat-typing.av-chat-visible {
  opacity: 1;
  visibility: visible;
}

.av-chat-typing-dots {
  display: flex;
  gap: 4px;
}

.av-chat-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--av-chat-text-light);
  border-radius: 50%;
  animation: av-chat-typing-bounce 1.4s ease-in-out infinite;
}

.av-chat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.av-chat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes av-chat-typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

/* -----------------------------------------------------------------------------
   Input Area
   ----------------------------------------------------------------------------- */
.av-chat-input-area {
  padding: 16px;
  background: var(--av-chat-bg);
  border-top: 1px solid var(--av-chat-border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.av-chat-input-wrapper {
  flex: 1;
  position: relative;
}

.av-chat-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--av-chat-border);
  border-radius: 20px;
  font-size: 14px;
  color: var(--av-chat-text);
  background: var(--av-chat-bg-light);
  resize: none;
  outline: none;
  transition: all var(--av-chat-transition);
  max-height: 120px;
  min-height: 44px;
  height: 44px;
  line-height: 1.4;
  font-family: inherit;
  overflow-y: hidden;
}

.av-chat-input.av-chat-multiline {
  border-radius: 16px;
  overflow-y: auto;
}

.av-chat-input:focus {
  border-color: var(--av-chat-primary);
  background: var(--av-chat-bg);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}

.av-chat-input::placeholder {
  color: var(--av-chat-text-light);
}

.av-chat-send-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--av-chat-primary) 0%, var(--av-chat-primary-dark) 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all var(--av-chat-transition);
}

.av-chat-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

.av-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.av-chat-send-btn svg {
  width: 20px;
  height: 20px;
}

/* -----------------------------------------------------------------------------
   Mobile Responsive
   ----------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .av-chat-widget {
    bottom: 16px;
    right: 16px;
  }

  .av-chat-button {
    width: 56px;
    height: 56px;
  }

  .av-chat-button svg {
    width: 24px;
    height: 24px;
  }

  .av-chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  .av-chat-invitation {
    width: calc(100vw - 90px);
    right: -8px;
    bottom: 70px;
  }
}

/* -----------------------------------------------------------------------------
   Dark Mode Support (optional)
   ----------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  .av-chat-widget[data-theme="auto"] {
    --av-chat-bg: #1e293b;
    --av-chat-bg-light: #0f172a;
    --av-chat-bg-dark: #334155;
    --av-chat-text: #f1f5f9;
    --av-chat-text-muted: #94a3b8;
    --av-chat-text-light: #64748b;
    --av-chat-border: #334155;
  }
}

/* -----------------------------------------------------------------------------
   Utilities
   ----------------------------------------------------------------------------- */
.av-chat-hidden {
  display: none !important;
}

.av-chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
