/* NexBot Chat Styles - Merged and Optimized */
:root {
  /* Color variables */
  --primary: #8091ff;
  --primary-hover: #9fb0fe;
  --primary-light: #2332ff1b;
  --secondary: #222;
  --text-dark: #333;
  --primary-dark: #030712;
  --primary-light-bg: #ffffff;
  
  --nexbot-primary: #1d4ed8;
  --nexbot-primary-light: #3b82f6;
  --nexbot-primary-dark: #1e40af;
  --nexbot-success: #065f46;
  --nexbot-success-bg: #d1fae5;
  --nexbot-error: #991b1b;
  --nexbot-error-bg: #fee2e2;
  --nexbot-text-on-primary: #ffffff;
  --nexbot-text: #1f2937;
  --nexbot-bg: #ffffff;
  --nexbot-border: #e5e7eb;
  --nexbot-hover: #f3f4f6;
  --nexbot-shadow: rgba(0, 0, 0, 0.1);
  --nexbot-shadow-lg: rgba(0, 0, 0, 0.15);

  /* Font variables */
  --nexbot-font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --nexbot-font-size-small: 13px;
  --nexbot-font-size-medium: 14px;
  --nexbot-font-size-large: 16px;

  /* Spacing and shape variables */
  --nexbot-radius: 0.375rem;
  --nexbot-radius-sm: 8px;
  --nexbot-radius-md: 12px;
  --nexbot-radius-lg: 16px;
  --nexbot-radius-pill: 24px;
  --nexbot-radius-circle: 50%;
  --nexbot-spacing-xs: 4px;
  --nexbot-spacing-sm: 8px;
  --nexbot-spacing-md: 12px;
  --nexbot-spacing-lg: 16px;
  --nexbot-spacing-xl: 20px;
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* Chat Container */
.nexbot-chat-container {
  position: fixed;
  bottom: 6rem;
  right: 1.5rem;
  width: 400px;
  height: min(700px, calc(100vh - 120px));
  background: var(--nexbot-bg);
  border-radius: var(--nexbot-radius-lg);
  box-shadow: 0 4px 15px var(--nexbot-shadow);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: bottom right;
  overflow: hidden;
  font-family: var(--nexbot-font-family);
  line-height: 1.5;
  font-size: var(--nexbot-font-size-medium);
}

/* Header */
.nexbot-header {
  background: var(--primary);
  color: var(--nexbot-text-on-primary);
  padding: 1rem;
  border-top-left-radius: var(--nexbot-radius);
  border-top-right-radius: var(--nexbot-radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px var(--nexbot-shadow);
}

.nexbot-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  animation: fadeIn 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: var(--nexbot-spacing-sm);
}

.nexbot-close-btn {
  background: none;
  border: none;
  color: var(--primary-dark);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: all 0.2s ease;
  border-radius: 50%;
}

.nexbot-close-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.nexbot-close-btn:active {
  transform: scale(0.95);
}

/* Status indicator */
.nexbot-status-indicator {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--nexbot-spacing-sm);
  margin-right: var(--nexbot-spacing-md);
}

.nexbot-status-indicator::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--nexbot-error);
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2);
  transition: all 0.3s ease;
}

.nexbot-status-indicator::after {
  content: 'Offline';
  font-size: 12px;
  font-weight: 500;
  color: var(--nexbot-error);
  transition: all 0.3s ease;
}

/* Online state */
.nexbot-status-indicator.online::before {
  background-color: #10b981;
  box-shadow: 
    0 0 0 2px rgba(16, 185, 129, 0.2),
    0 0 0 0 rgba(16, 185, 129, 0.6);
  animation: status-pulse 1.5s infinite;
}

.nexbot-status-indicator.online::after {
  content: 'Online';
  color: #10b981;
}

/* Pulse animation for online status */
@keyframes status-pulse {
  0% {
    box-shadow: 
      0 0 0 2px rgba(16, 185, 129, 0.2),
      0 0 0 0 rgba(16, 185, 129, 0.6);
  }
  70% {
    box-shadow: 
      0 0 0 2px rgba(16, 185, 129, 0.2),
      0 0 0 10px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 
      0 0 0 2px rgba(16, 185, 129, 0.2),
      0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* Messages Container */
.nexbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: #f8f9fa;
  scroll-behavior: smooth;
}

.nexbot-messages::-webkit-scrollbar {
  width: 6px;
}

.nexbot-messages::-webkit-scrollbar-track {
  background: var(--nexbot-hover);
  border-radius: 3px;
}

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

.nexbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--nexbot-primary-light);
}

/* Message Bubbles */
.nexbot-message {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  line-height: 1.4;
  word-wrap: break-word;
  animation: slideIn 0.3s ease-out;
  box-shadow: 0 1px 2px var(--nexbot-shadow);
}

.nexbot-message.user {
  background: var(--nexbot-primary);
  color: var(--nexbot-text-on-primary);
  align-self: flex-end;
  border-bottom-right-radius: 0.25rem;
}

.nexbot-message.bot {
  background: var(--nexbot-hover);
  color: var(--nexbot-text);
  align-self: flex-start;
  border-bottom-left-radius: 0.25rem;
}

.nexbot-message.error {
  background: var(--nexbot-error-bg);
  color: var(--nexbot-error);
}

.nexbot-message.success {
  background: var(--nexbot-success-bg);
  color: var(--nexbot-success);
}

/* Status indicators */
.nexbot-human-indicator {
  text-align: center;
  padding: var(--nexbot-spacing-md);
  margin: var(--nexbot-spacing-md) 0;
  background-color: rgba(40, 167, 69, 0.1);
  border-radius: var(--nexbot-radius-md);
  color: var(--nexbot-success);
  font-weight: 500;
  font-size: var(--nexbot-font-size-small);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--nexbot-spacing-sm);
}

.nexbot-waiting-indicator {
  text-align: center;
  padding: var(--nexbot-spacing-md);
  margin: var(--nexbot-spacing-md) 0;
  background-color: rgba(255, 193, 7, 0.1);
  border-radius: var(--nexbot-radius-md);
  color: #e6a100;
  font-weight: 500;
  font-size: var(--nexbot-font-size-small);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--nexbot-spacing-sm);
}

.nexbot-waiting-indicator::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: #e6a100;
  border-radius: 50%;
  animation: pulse 1s infinite;
}

.nexbot-human-indicator::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: var(--nexbot-success);
  border-radius: 50%;
}

.nexbot-name-indicator {
  text-align: center;
  padding: var(--nexbot-spacing-md);
  margin: var(--nexbot-spacing-md) 0;
  background-color: rgba(29, 78, 216, 0.1);
  border-radius: var(--nexbot-radius-md);
  color: var(--nexbot-primary);
  font-weight: 500;
  font-size: var(--nexbot-font-size-small);
}

/* Typing Indicator */
.nexbot-typing {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  align-self: flex-start;
  animation: fadeIn 0.3s ease-out;
}

.nexbot-typing span {
  width: 8px;
  height: 8px;
  background: var(--nexbot-primary);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 1s infinite;
}

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

/* Input Area */
.nexbot-input {
  border-top: 1px solid var(--nexbot-border);
  padding: 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  background: var(--nexbot-bg);
}

.nexbot-input textarea {
  flex: 1;
  border: 1px solid var(--nexbot-border);
  border-radius: 0.75rem;
  padding: 0.75rem;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  transition: border-color 0.2s ease;
}

.nexbot-input textarea:focus {
  outline: none;
  border-color: var(--nexbot-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.1);
}

.nexbot-input textarea:focus-visible {
  outline: 2px solid var(--nexbot-primary);
  outline-offset: 1px;
}

.nexbot-send-btn {
  background: var(--primary);
  color: var(--nexbot-text-on-primary);
  border: none;
  border-radius: 0.75rem;
  padding: 0.75rem 1.25rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nexbot-send-btn:hover {
  background: var(--primary-hover)  ;
  transform: translateY(-1px);
}

.nexbot-send-btn:active {
  transform: translateY(1px);
}

.nexbot-send-btn svg {
  width: 16px;
  height: 16px;
}

.nexbot-send-btn:focus-visible,
.nexbot-close-btn:focus-visible,
.nexbot-fab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Fab Button */
.nexbot-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: var(--primary);
  color: var(--nexbot-text-on-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 6px var(--nexbot-shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9998;
}

.nexbot-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 15px var(--nexbot-shadow-lg);
  background: var(--primary-hover);
}

.nexbot-fab:active {
  transform: scale(0.95);
}

.nexbot-fab svg {
  width: 24px;
  height: 24px;
  transition: transform 0.3s ease;
}

.nexbot-fab:hover svg {
  transform: scale(1.1);
}

/* Human mode styling */
.nexbot-chat-container.human-mode .nexbot-header {
  background-color: var(--nexbot-success);
}

.nexbot-chat-container.human-mode .nexbot-message.bot {
  background-color: #d4edda;
  border-left: 3px solid var(--nexbot-success);
}

/* State Classes */
.bpOpen {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bpClose {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s 0.3s;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .nexbot-chat-container {
    width: 100%;
    height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }

  .nexbot-header {
    border-radius: 0;
    padding: 1rem;
  }

  .nexbot-input {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .nexbot-fab {
    bottom: 1rem;
    right: 1rem;
    width: 3.5rem;
    height: 3.5rem;
  }

  .nexbot-send-btn {
    padding: 0.75rem 1rem;
  }

  body:has(.bpOpen) {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  .bpOpen {
    transform: translateY(0) !important;
  }

  .bpClose {
    transform: translateY(100%) !important;
  }
}

/* More specific mobile adjustments */
@media (max-width: 480px) {
  .nexbot-chat-container {
    width: calc(100% - 32px);
    height: calc(100% - 100px);
    bottom: 80px;
    right: 16px;
    left: 16px;
    border-radius: var(--nexbot-radius-md);
  }

  .nexbot-fab {
    width: 55px;
    height: 55px;
    bottom: 16px;
    right: 16px;
  }

  .nexbot-message {
    max-width: 90%;
    padding: var(--nexbot-spacing-sm) var(--nexbot-spacing-md);
  }

  .nexbot-header {
    padding: var(--nexbot-spacing-sm) var(--nexbot-spacing-md);
  }

  .nexbot-input {
    padding: var(--nexbot-spacing-sm);
  }

  .nexbot-input textarea {
    padding: var(--nexbot-spacing-sm) var(--nexbot-spacing-md);
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --nexbot-bg: #1f2937;
    --nexbot-text: #f3f4f6;
    --nexbot-border: #374151;
    --nexbot-hover: #374151;
    --nexbot-shadow: rgba(0, 0, 0, 0.3);
    --nexbot-shadow-lg: rgba(0, 0, 0, 0.4);
  }

  .nexbot-message.bot {
    background: #2d3748;
  }

  .nexbot-input textarea {
    background: var(--primary-dark);
    color: var(--nexbot-text);
  }

  .nexbot-messages {
    background-color: #2d3238;
  }

  .nexbot-message.bot.error {
    background-color: #721c24;
    color: #f8d7da;
  }

  .nexbot-human-indicator {
    background-color: rgba(40, 167, 69, 0.2);
  }

  .nexbot-waiting-indicator {
    background-color: rgba(255, 193, 7, 0.2);
    color: #ffc107;
  }

  .nexbot-name-indicator {
    background-color: rgba(29, 78, 216, 0.2);
  }
}
