/* Chatbot Styles - AgentEQ Theme */
.chatbot-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  font-family: "Inter", sans-serif;
}

/* n8n Chat Widget Integration Styles */
.n8n-chat-widget {
  font-family: "Inter", sans-serif !important;
  z-index: 1000 !important;
}

/* Ensure n8n widget respects AgentEQ design system */
.n8n-chat-widget * {
  font-family: "Inter", sans-serif !important;
}

/* Chatbot Button */
.chatbot-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.chatbot-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(0, 212, 255, 0.5);
}

.chatbot-button:active {
  transform: scale(0.95);
}

.chatbot-button i {
  color: white;
  font-size: 24px;
  transition: transform 0.3s ease;
}

.chatbot-button:hover i {
  transform: rotate(10deg);
}

/* Animated Text */
.chatbot-text {
  position: absolute;
  right: 70px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--gradient-primary);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  backdrop-filter: blur(10px);
  border: none;
  box-shadow: var(--shadow-glow);
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 100001;
  min-width: 120px;
  text-align: center;
  /* Ensure it's visible */
  visibility: visible;
  display: block;
}

/* Show text class for page load animation and hover */
.chatbot-text.show,
.chatbot-button:hover .chatbot-text {
  opacity: 1 !important;
}

/* Chat Window */
.chatbot-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  height: 550px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  animation: slideUp 0.3s ease-out;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 120px);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

/* Chat Header */
.chatbot-header {
  background: var(--gradient-primary);
  color: var(--text-primary);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.chatbot-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(124, 58, 237, 0.1));
  backdrop-filter: blur(10px);
}

.chatbot-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.chatbot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.chatbot-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.chatbot-subtitle {
  font-size: 12px;
  opacity: 0.8;
  margin: 0;
}

.chatbot-close {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  transition: background-color 0.2s ease;
  position: relative;
  z-index: 1;
}

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

/* Chat Messages */
.chatbot-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Message Row Container */
.chatbot-message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 4px;
  opacity: 0;
  transform: translateX(30px);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chatbot-message-row.anees-row {
  transform: translateX(-30px);
}

.chatbot-message-row.animate-in {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.chatbot-message-row.user-row {
  justify-content: flex-end;
}

/* Message Content Wrapper */
.chatbot-message-content {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  min-width: 0;
}

.chatbot-message-content.user-content {
  align-items: flex-end;
  max-width: 85%;
}

/* Small Avatar for Assistant Messages */
.chatbot-avatar-small {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.1);
}

/* Message Timestamps */
.chatbot-timestamp {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  opacity: 0;
  animation: fadeInTimestamp 0.4s ease forwards;
  animation-delay: 0.3s;
}

.chatbot-timestamp.user-timestamp {
  text-align: right;
}

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

.chatbot-message {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  min-width: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.chatbot-message.user {
  background: var(--gradient-primary);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 3px 10px rgba(0, 212, 255, 0.2);
}

.chatbot-message.user:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 212, 255, 0.3);
}

.chatbot-message.anees {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.chatbot-message.anees:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
}

.chatbot-message.typing {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  font-style: italic;
}

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

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingDot 1.4s infinite ease-in-out;
}

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

@keyframes typingDot {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.typing-text {
  margin-left: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}

/* Typing Row Specific Styling */
.chatbot-message-row.typing-row {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
}

/* Chat Input */
.chatbot-input-container {
  padding: 16px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

/* Powered by AgentEQ Label */
.chatbot-powered-label {
  padding: 8px 20px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: color 0.3s ease;
  flex-wrap: wrap;
}

.chatbot-powered-label:hover {
  color: var(--text-secondary);
}

.chatbot-powered-link {
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
}

.chatbot-powered-link:hover {
  transform: scale(1.05);
}

.chatbot-powered-link strong {
  color: var(--primary);
  font-weight: 600;
  background: var(--gradient-primary);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: all 0.3s ease;
}

.chatbot-powered-link:hover strong {
  filter: brightness(1.2);
}

.chatbot-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 12px 16px;
  font-size: 14px;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  outline: none;
  transition: border-color 0.2s ease;
  font-family: inherit;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

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

.chatbot-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chatbot-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 212, 255, 0.3);
}

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

/* Welcome Message */
.chatbot-welcome {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
}

.chatbot-welcome h3 {
  margin: 0 0 8px 0;
  color: var(--text-primary);
  font-size: 16px;
}

.chatbot-welcome p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet Portrait and Small Desktop (768px) */
@media (max-width: 768px) {
  .chatbot-container {
    bottom: 15px;
    right: 15px;
  }
  
  .chatbot-button {
    width: 50px;
    height: 50px;
  }
  
  .chatbot-button i {
    font-size: 20px;
  }
  
  .chatbot-window {
    width: calc(100vw - 30px);
    height: calc(100vh - 100px);
    bottom: 75px;
    right: 15px;
    left: 15px;
    max-height: 650px;
    min-height: 400px;
  }
  
  .chatbot-text {
    right: 60px;
    font-size: 12px;
    padding: 8px 12px;
    min-width: 100px;
  }
  
  .chatbot-messages {
    padding: 15px;
    max-height: calc(100% - 140px);
    gap: 12px;
  }
  
  .chatbot-message-row {
    gap: 6px;
    margin-bottom: 2px;
  }
  
  .chatbot-avatar-small {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  
  .chatbot-message-content {
    max-width: 80%;
  }
  
  .chatbot-message-content.user-content {
    max-width: 90%;
  }
  
  .chatbot-message {
    padding: 10px 14px;
    font-size: 13px;
  }
  
  .chatbot-timestamp {
    font-size: 10px;
  }
  
  .chatbot-input-container {
    padding: 12px 15px;
  }
  
  .chatbot-powered-label {
    padding: 6px 15px 10px;
    font-size: 10px;
  }
}

/* Large Mobile (414px) - iPhone Plus, etc. */
@media (max-width: 414px) {
  .chatbot-container {
    bottom: 12px;
    right: 12px;
  }
  
  .chatbot-button {
    width: 48px;
    height: 48px;
  }
  
  .chatbot-button i {
    font-size: 19px;
  }
  
  .chatbot-window {
    width: calc(100vw - 24px);
    height: calc(100vh - 80px);
    bottom: 70px;
    right: 12px;
    left: 12px;
    max-height: 600px;
    min-height: 450px;
    border-radius: 16px;
  }
  
  .chatbot-text {
    display: none;
  }
  
  .chatbot-header {
    padding: 14px 16px;
  }
  
  .chatbot-avatar {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  
  .chatbot-title {
    font-size: 15px;
  }
  
  .chatbot-subtitle {
    font-size: 12px;
  }
  
  .chatbot-messages {
    padding: 14px;
    max-height: calc(100% - 130px);
    gap: 10px;
  }
  
  .chatbot-message-row {
    gap: 6px;
    margin-bottom: 2px;
  }
  
  .chatbot-avatar-small {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }
  
  .chatbot-message-content {
    max-width: 80%;
  }
  
  .chatbot-message-content.user-content {
    max-width: 85%;
  }
  
  .chatbot-message {
    font-size: 14px;
    padding: 11px 15px;
  }
  
  .chatbot-input-container {
    padding: 12px 14px;
    gap: 10px;
  }
  
  .chatbot-input {
    font-size: 14px;
    padding: 11px 15px;
    min-height: 38px;
  }
  
  .chatbot-send {
    width: 38px;
    height: 38px;
  }
  
  .chatbot-send i {
    font-size: 15px;
  }
  
  .chatbot-powered-label {
    padding: 6px 14px 10px;
    font-size: 10px;
  }
}

/* Standard Mobile (375px) - iPhone, etc. */
@media (max-width: 375px) {
  .chatbot-container {
    bottom: 10px;
    right: 10px;
  }
  
  .chatbot-button {
    width: 45px;
    height: 45px;
  }
  
  .chatbot-button i {
    font-size: 18px;
  }
  
  .chatbot-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 80px);
    bottom: 65px;
    right: 10px;
    left: 10px;
    max-height: 550px;
    min-height: 400px;
    border-radius: 14px;
  }
  
  .chatbot-header {
    padding: 12px 15px;
  }
  
  .chatbot-avatar {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }
  
  .chatbot-title {
    font-size: 14px;
  }
  
  .chatbot-subtitle {
    font-size: 11px;
  }
  
  .chatbot-messages {
    padding: 12px;
    max-height: calc(100% - 120px);
    gap: 8px;
  }
  
  .chatbot-message-row {
    gap: 5px;
    margin-bottom: 2px;
  }
  
  .chatbot-avatar-small {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  
  .chatbot-message-content {
    max-width: 85%;
  }
  
  .chatbot-message-content.user-content {
    max-width: 90%;
  }
  
  .chatbot-message {
    font-size: 13px;
    padding: 10px 14px;
  }
  
  .chatbot-timestamp {
    font-size: 10px;
  }
  
  .chatbot-input-container {
    padding: 10px 12px;
    gap: 8px;
  }
  
  .chatbot-input {
    font-size: 13px;
    padding: 10px 14px;
    min-height: 36px;
  }
  
  .chatbot-send {
    width: 36px;
    height: 36px;
  }
  
  .chatbot-send i {
    font-size: 14px;
  }
  
  .chatbot-powered-label {
    padding: 5px 12px 8px;
    font-size: 9px;
  }
}

/* Small Mobile (320px) - iPhone SE, small Android phones */
@media (max-width: 320px) {
  .chatbot-container {
    bottom: 8px;
    right: 8px;
  }
  
  .chatbot-button {
    width: 42px;
    height: 42px;
  }
  
  .chatbot-button i {
    font-size: 16px;
  }
  
  .chatbot-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 70px);
    bottom: 58px;
    right: 8px;
    left: 8px;
    max-height: 500px;
    min-height: 350px;
    border-radius: 12px;
  }
  
  .chatbot-header {
    padding: 10px 12px;
  }
  
  .chatbot-avatar {
    width: 30px;
    height: 30px;
    font-size: 13px;
  }
  
  .chatbot-title {
    font-size: 13px;
  }
  
  .chatbot-subtitle {
    font-size: 10px;
  }
  
  .chatbot-messages {
    padding: 10px;
    max-height: calc(100% - 110px);
    gap: 6px;
  }
  
  .chatbot-message-row {
    gap: 4px;
    margin-bottom: 1px;
  }
  
  .chatbot-avatar-small {
    width: 22px;
    height: 22px;
    font-size: 10px;
  }
  
  .chatbot-message-content {
    max-width: 90%;
  }
  
  .chatbot-message-content.user-content {
    max-width: 95%;
  }
  
  .chatbot-message {
    font-size: 12px;
    padding: 8px 12px;
  }
  
  .chatbot-timestamp {
    font-size: 9px;
  }
  
  .chatbot-input-container {
    padding: 8px 10px;
    gap: 6px;
  }
  
  .chatbot-input {
    font-size: 12px;
    padding: 8px 12px;
    min-height: 32px;
  }
  
  .chatbot-send {
    width: 32px;
    height: 32px;
  }
  
  .chatbot-send i {
    font-size: 12px;
  }
  
  .chatbot-powered-label {
    padding: 4px 10px 6px;
    font-size: 8px;
    gap: 2px;
  }
}

/* Landscape Orientation Adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .chatbot-window {
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    bottom: 40px;
  }
  
  .chatbot-messages {
    max-height: calc(100% - 100px);
  }
  
  .chatbot-header {
    padding: 8px 15px;
  }
  
  .chatbot-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .chatbot-title {
    font-size: 13px;
  }
  
  .chatbot-subtitle {
    font-size: 10px;
  }
  
  .chatbot-input-container {
    padding: 8px 15px;
  }
  
  .chatbot-powered-label {
    padding: 4px 15px 6px;
    font-size: 9px;
  }
}


/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

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

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

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

/* Additional Mobile Optimizations */
@media (max-width: 320px) {
  .chatbot-messages::-webkit-scrollbar {
    width: 4px;
  }
}

/* Ensure text doesn't overflow on any device */
.chatbot-messages {
  overflow-x: hidden;
  overflow-y: auto;
}

/* Prevent zoom on input focus on iOS */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .chatbot-input {
    font-size: 16px !important;
  }
  
  @media (max-width: 375px) {
    .chatbot-input {
      font-size: 16px !important;
    }
  }
}

/* Touch improvements for mobile */
.chatbot-button,
.chatbot-send,
.chatbot-close {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Ensure proper viewport handling */
.chatbot-window {
  -webkit-overflow-scrolling: touch;
}

/* Prevent horizontal scroll on the body when chat is open */
body.chat-open {
  overflow-x: hidden;
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .chatbot-button {
    border: 0.5px solid rgba(255, 255, 255, 0.1);
  }
  
  .chatbot-window {
    border: 0.5px solid var(--border);
  }
}

/* Smooth transitions for all interactive elements */
.chatbot-message-row,
.chatbot-message,
.chatbot-avatar-small,
.chatbot-timestamp {
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Enhanced scroll behavior */
.chatbot-messages {
  scroll-behavior: smooth;
  scroll-padding-bottom: 20px;
}

/* Improved focus states for accessibility */
.chatbot-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
  transform: translateZ(0);
}

/* Loading state for better UX */
.chatbot-message-row.loading {
  opacity: 0.7;
  pointer-events: none;
}

/* Hover effects for better interactivity */
.chatbot-avatar-small:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 212, 255, 0.4);
}

/* Keyboard Open State */
.chatbot-window.keyboard-open {
  transition: height 0.3s ease, max-height 0.3s ease;
}

.chatbot-window.keyboard-open .chatbot-messages {
  transition: max-height 0.3s ease;
}

/* Mobile Keyboard Optimizations */
@media (max-width: 768px) {
  .chatbot-window {
    transition: height 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                max-height 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  }
  
  .chatbot-messages {
    transition: max-height 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  }
  
  /* Ensure input stays visible when keyboard opens */
  .chatbot-input-container {
    position: sticky;
    bottom: 0;
    z-index: 100;
  }
  
  /* Enhanced mobile spacing */
  .chatbot-window.keyboard-open {
    bottom: 10px !important;
  }
  
  .chatbot-window.keyboard-open .chatbot-messages {
    padding-bottom: 20px;
  }
}
