/* 1. Scope Variables to the widget only */
.n8n-chat-widget {
  --n8n-primary: #007ba4;
  --n8n-secondary: #f5f7fa;
  --n8n-bg: #ffffff;
  --n8n-text: #333333;
  --n8n-border: #e0e0e0;
  --n8n-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);

  /* Position fixed here to keep it on top */
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9990; /* Lowered slightly to avoid blocking nopCommerce admin modals */
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; /* Removed Geist unless you imported it */
}

/* 2. SAFE RESET: Only reset elements INSIDE the widget */
.n8n-chat-widget * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Fix for double media query */
@media (prefers-reduced-motion: no-preference) {
    .scroll-back-button {
        bottom: 90px !important;
    }
}

.chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--n8n-primary);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--n8n-shadow);
  transition: all 0.2s ease;
}

.chat-toggle:hover {
  transform: scale(1.05);
}

.chat-toggle svg {
  width: 24px;
  height: 24px;
  fill: white;
}

.chat-container {
  width: 360px;
  /* 3. Mobile Responsiveness: Prevent widget being wider than screen */
  max-width: calc(100vw - 40px); 
  height: 600px;
  max-height: calc(100vh - 100px); 
  
  background: var(--n8n-bg);
  border-radius: 12px;
  box-shadow: var(--n8n-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  
  /* Animation states */
  transform: translateY(20px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  
  position: absolute;
  bottom: 70px;
  right: 0;
}

.chat-container.open {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.brand-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--n8n-border);
  background: var(--n8n-bg);
}

.brand-header img {
  width: 60px;
  object-fit: cover;
}

.brand-header span {
  font-weight: 600;
  flex: 1;
  color: var(--n8n-text); /* Ensure text color applies */
}

.close-button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--n8n-text);
}

.new-conversation {
  padding: 24px;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.welcome-text {
  font-size: 18px;
  margin-bottom: 24px;
  color: var(--n8n-text);
  line-height: 1.4; /* Improve readability */
}

.new-chat-btn {
  background: var(--n8n-primary);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s ease;
  font-size: 14px;
}

.new-chat-btn:hover {
  filter: brightness(0.9); /* Simpler hover effect */
}

.response-text {
  margin-top: 16px;
  font-size: 14px;
  color: #666;
}

.chat-interface {
  display: none;
  flex-direction: column;
  height: 100%;
}

.chat-interface.active {
  display: flex;
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 14px;
  word-wrap: break-word; /* Prevent long words breaking layout */
}

.chat-message.user {
  background: var(--n8n-primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-message.bot {
  background: var(--n8n-secondary);
  color: var(--n8n-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-input {
  padding: 12px;
  border-top: 1px solid var(--n8n-border);
  display: flex;
  gap: 8px;
  background: #fff;
}

.chat-input textarea {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--n8n-border);
  border-radius: 8px;
  resize: none;
  max-height: 100px;
  outline: none;
  font-size: 14px;
  color: var(--n8n-text);
}

.chat-input button {
  background: var(--n8n-primary);
  color: white;
  border: none;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}

.chat-footer {
  padding: 8px 16px;
  font-size: 11px;
  text-align: center;
  color: #999;
  border-top: 1px solid var(--n8n-border);
  background: #fcfcfc;
}

.chat-footer a {
  color: #666;
  text-decoration: none;
}

.chat-footer a:hover {
  text-decoration: underline;
}

/* Typing Indicator Animation */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 16px; /* Match message padding */
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #666;
  border-radius: 50%;
  opacity: 0.4;
  animation: typingAnimation 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingAnimation {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}