/* Chatbot Styles - Matching Website Theme */
:root {
  --chat-primary: #1e3c72;
  --chat-primary-light: #2196F3;
  --chat-primary-dark: #0d5f85;
  --chat-accent: #2196F3;
  --chat-bg: #F7F9FB;
  --chat-white: #ffffff;
  --chat-text: #222222;
  --chat-text-light: #666666;
  --chat-border: #e0e0e0;
  --chat-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  --chat-shadow-hover: 0 8px 30px rgba(30, 60, 114, 0.25);
  --chat-radius: 16px;
  --chat-radius-small: 12px;
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
}

.chatbot-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  direction: rtl;
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  animation: fadeInUp 0.5s ease-out 2s both;
  opacity: 0;
}

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

/* Toggle Button */
.chatbot-toggle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
  box-shadow: var(--chat-shadow-hover);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: visible;
}

.chatbot-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 40px rgba(30, 60, 114, 0.3);
}

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

.chatbot-toggle-icon {
  width: 36px;
  height: 36px;
  color: var(--chat-white);
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.chatbot-dot {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 12px;
  height: 12px;
  background: #4CAF50;
  border-radius: 50%;
  border: 2px solid var(--chat-white);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.1);
  }
}

/* Chat Panel */
.chatbot-panel {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 400px;
  max-height: 75vh;
  min-height: 500px;
  background: var(--chat-white);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow-hover);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(30px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid var(--chat-border);
  /* Ensure panel stays visible above other content */
  z-index: 10000;
}

.chatbot-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.chatbot-header {
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
  color: var(--chat-white);
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chatbot-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.chatbot-title-group {
  flex: 1;
}

.chatbot-title {
  font-weight: 700;
  font-size: 1.25rem;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.chatbot-subtitle {
  font-size: 0.875rem;
  opacity: 0.95;
  font-weight: 400;
}

.chatbot-close {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--chat-white);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

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

.chatbot-close svg {
  width: 18px;
  height: 18px;
}

/* Messages Area */
.chatbot-messages {
  flex: 1;
  padding: 20px;
  background: var(--chat-bg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

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

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

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

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

/* Welcome Message */
.chatbot-welcome {
  margin-bottom: 8px;
}

.welcome-bubble {
  background: linear-gradient(135deg, rgba(30, 60, 114, 0.05) 0%, rgba(33, 150, 243, 0.05) 100%);
  border: 1px solid rgba(30, 60, 114, 0.1);
  padding: 16px;
}

.welcome-icon {
  font-size: 32px;
  margin-bottom: 8px;
  text-align: center;
}

.welcome-text {
  text-align: center;
}

.welcome-text strong {
  display: block;
  font-size: 1.1rem;
  color: var(--chat-primary);
  margin-bottom: 8px;
}

.welcome-text p {
  color: var(--chat-text-light);
  font-size: 0.9rem;
  line-height: 1.6;
  margin: 0;
}

/* Message Bubbles */
.chatbot-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--chat-radius-small);
  line-height: 1.6;
  font-size: 0.95rem;
  word-wrap: break-word;
  animation: slideIn 0.3s ease-out;
  position: relative;
}

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

.chatbot-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
  color: var(--chat-white);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(30, 60, 114, 0.2);
}

.chatbot-bubble.bot {
  align-self: flex-start;
  background: var(--chat-white);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

/* Input Form */
.chatbot-form {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-white);
  align-items: center;
}

.chatbot-form input {
  flex: 1;
  border-radius: var(--chat-radius-small);
  border: 2px solid var(--chat-border);
  padding: 12px 16px;
  font-size: 0.95rem;
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  transition: all 0.2s ease;
  background: var(--chat-white);
  color: var(--chat-text);
}

.chatbot-form input:focus {
  outline: none;
  border-color: var(--chat-primary-light);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.chatbot-form input:disabled {
  background: var(--chat-bg);
  cursor: not-allowed;
  opacity: 0.6;
}

.chatbot-form input::placeholder {
  color: var(--chat-text-light);
}

.chatbot-send {
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
  border: none;
  color: var(--chat-white);
  width: 48px;
  height: 48px;
  border-radius: var(--chat-radius-small);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(30, 60, 114, 0.2);
}

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

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

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

.chatbot-send svg {
  width: 20px;
  height: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .chatbot-root {
    bottom: 16px;
    right: 16px;
  }

  .chatbot-toggle {
    width: 56px;
    height: 56px;
    margin-bottom: 0;
  }

  .chatbot-toggle-icon {
    width: 28px;
    height: 28px;
  }

  .chatbot-panel {
    width: calc(100vw - 32px);
    right: 16px;
    left: 16px;
    bottom: 88px;
    max-height: calc(100vh - 120px);
    min-height: 400px;
    /* Ensure panel stays visible when keyboard opens */
    position: fixed;
    z-index: 10000;
  }

  /* When keyboard is open, adjust panel height */
  .chatbot-panel.is-open {
    max-height: calc(100vh - 100px);
  }

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

  .chatbot-avatar {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .chatbot-title {
    font-size: 1.1rem;
  }

  .chatbot-subtitle {
    font-size: 0.8rem;
  }

  .chatbot-messages {
    padding: 16px;
  }

  .chatbot-bubble {
    max-width: 90%;
    font-size: 0.9rem;
    padding: 10px 14px;
  }

  .chatbot-form {
    padding: 12px;
  }

  .chatbot-form input {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .chatbot-send {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 480px) {
  .chatbot-panel {
    border-radius: var(--chat-radius-small);
    /* On very small screens, make it almost full screen when keyboard is open */
    max-height: calc(100vh - 80px);
    bottom: 60px;
  }

  .chatbot-header {
    padding: 14px 16px;
    /* Prevent header from shrinking */
    flex-shrink: 0;
  }

  .chatbot-messages {
    padding: 12px;
    gap: 12px;
    /* Ensure messages area can scroll */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .chatbot-bubble {
    max-width: 92%;
    font-size: 0.875rem;
  }

  /* Ensure form stays at bottom when keyboard opens */
  .chatbot-form {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--chat-white);
  }
}

/* Loading Animation */
@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

.chatbot-bubble.loading {
  position: relative;
}

.chatbot-bubble.loading::after {
  content: '...';
  animation: typing 1.4s infinite;
  display: inline-block;
  width: 20px;
}

/* Smooth transitions */
* {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
