/* ===== AI CHATBOT STYLES ===== */

/* Chatbot Toggle Button */
.chatbot-toggle {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  background: var(--accent-gradient);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  animation: pulse 2s infinite;
}

.chatbot-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
}

.chatbot-toggle.active {
  transform: rotate(90deg);
  animation: none;
}

.chatbot-toggle-icon {
  font-size: 28px;
  color: white;
  transition: transform 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatbot-toggle.active .chatbot-toggle-icon {
  transform: rotate(45deg);
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  }
  50% {
    box-shadow: 0 4px 30px rgba(102, 126, 234, 0.7);
  }
}

/* Chatbot Window */
.chatbot-window {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 400px;
  max-width: calc(100vw - 60px);
  height: 600px;
  max-height: calc(100vh - 160px);
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;
  transform: scale(0) translateY(50px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  border: 1px solid var(--border-color);
}

.chatbot-window.active {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Chatbot Header */
.chatbot-header {
  background: var(--accent-gradient);
  color: white;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 20px 20px 0 0;
}

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

.chatbot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent-primary);
}

.chatbot-header-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.chatbot-header-info p {
  margin: 0;
  font-size: 12px;
  opacity: 0.9;
}

.chatbot-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  margin-left: 5px;
  animation: blink 2s infinite;
}

.chatbot-status.is-idle {
  background: #4ade80;
}

.chatbot-status.is-manual {
  background: #f59e0b;
}

.chatbot-status.is-typing {
  background: #f97316;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.chatbot-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

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

/* Chatbot Messages */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.chatbot-messages::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}

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

/* Message Bubble */
.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeInUp 0.3s ease;
}

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

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.message.bot .message-avatar {
  background: var(--accent-gradient);
  color: white;
}

.message.user .message-avatar {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.welcome-message-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-content {
  background: var(--card-bg);
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--accent-primary);
  color: white;
  border-radius: 16px 16px 0 16px;
}

.message.bot .message-content {
  border-radius: 16px 16px 16px 0;
}

.message.system .message-content {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-style: italic;
}

.message.operator .message-content {
  border: 1px solid var(--accent-primary);
}

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

.message-content a {
  color: var(--accent-primary);
  text-decoration: underline;
}

.message.user .message-content a {
  color: white;
}

.message-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
  text-align: right;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--card-bg);
  border-radius: 16px 16px 16px 0;
  box-shadow: var(--shadow-sm);
  width: fit-content;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Chatbot Input */
.chatbot-input-container {
  padding: 16px 20px;
  background: var(--card-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
  align-items: center;
}

.chatbot-input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}

.chatbot-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.chatbot-input::placeholder {
  color: var(--text-tertiary);
}

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

.chatbot-send-btn:hover:not(:disabled) {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

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

/* Quick Actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 16px;
  background: var(--bg-secondary);
}

.quick-action-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.quick-action-btn:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

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

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

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

/* Responsive Design */
@media screen and (max-width: 768px) {
  .chatbot-toggle {
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
  }

  .chatbot-window {
    bottom: 90px;
    right: 20px;
    width: calc(100vw - 40px);
    height: calc(100vh - 140px);
  }

  .chatbot-header {
    padding: 16px;
  }

  .chatbot-messages {
    padding: 16px;
  }

  .chatbot-input-container {
    padding: 12px 16px;
  }

  .quick-actions {
    padding: 0 16px 12px;
  }
}

/* Mobile Phones - Enhanced Responsiveness */
@media screen and (max-width: 600px) {
  .chatbot-toggle {
    bottom: 16px;
    right: 16px;
    width: 60px;
    height: 60px;
  }

  /* Hide toggle button when chatbot is open so it doesn't cover the send button */
  .chatbot-toggle.active {
    display: none;
  }

  .chatbot-toggle-icon {
    font-size: 26px;
  }

  .chatbot-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height adjusts when virtual keyboard opens */
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .chatbot-header {
    padding: 16px;
    border-radius: 0;
  }

  .chatbot-avatar {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .chatbot-header-info h3 {
    font-size: 15px;
  }

  .chatbot-header-info p {
    font-size: 11px;
  }

  .chatbot-messages {
    padding: 12px;
    gap: 10px;
  }

  .message {
    max-width: 90%;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .message-content {
    padding: 10px 14px;
  }

  .message-content p {
    font-size: 13px;
    line-height: 1.4;
  }

  .message-time {
    font-size: 10px;
  }

  .typing-indicator {
    padding: 10px 14px;
  }

  .typing-dot {
    width: 7px;
    height: 7px;
  }

  .chatbot-input-container {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .chatbot-input {
    padding: 10px 14px;
    font-size: 16px; /* Prevent iOS auto-zoom on focus */
  }

  .chatbot-send-btn {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }

  .quick-actions {
    padding: 0 12px 12px;
    gap: 6px;
  }

  .quick-action-btn {
    padding: 7px 14px;
    font-size: 11px;
  }

  .welcome-message {
    padding: 30px 16px;
  }

  .welcome-message-icon {
    font-size: 40px;
  }

  .welcome-message h3 {
    font-size: 16px;
  }

  .welcome-message p {
    font-size: 13px;
  }
}

/* Extra Small Phones - Maximum Mobile Optimization */
@media screen and (max-width: 480px) {
  .chatbot-toggle {
    width: 56px;
    height: 56px;
    bottom: 14px;
    right: 14px;
  }

  .chatbot-toggle-icon {
    font-size: 24px;
  }

  .chatbot-header {
    padding: 14px 12px;
  }

  .chatbot-avatar {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .chatbot-header-info h3 {
    font-size: 14px;
  }

  .chatbot-header-info p {
    font-size: 10px;
  }

  .chatbot-close {
    width: 28px;
    height: 28px;
    font-size: 22px;
  }

  .chatbot-messages {
    padding: 10px;
    gap: 8px;
  }

  .message {
    max-width: 92%;
  }

  .message-avatar {
    width: 26px;
    height: 26px;
    font-size: 13px;
  }

  .message-content {
    padding: 9px 12px;
    border-radius: 14px;
  }

  .message.user .message-content {
    border-radius: 14px 14px 0 14px;
  }

  .message.bot .message-content {
    border-radius: 14px 14px 14px 0;
  }

  .message-content p {
    font-size: 12px;
  }

  .message-time {
    font-size: 9px;
  }

  .typing-indicator {
    padding: 9px 12px;
    border-radius: 14px 14px 14px 0;
  }

  .typing-dot {
    width: 6px;
    height: 6px;
  }

  .chatbot-input-container {
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .chatbot-input {
    padding: 9px 12px;
    font-size: 16px; /* Prevent iOS auto-zoom on focus */
    border-radius: 20px;
  }

  .chatbot-send-btn {
    width: 40px;
    height: 40px;
    font-size: 15px;
  }

  .quick-actions {
    padding: 0 10px 10px;
    gap: 5px;
  }

  .quick-action-btn {
    padding: 6px 12px;
    font-size: 10px;
    border-radius: 16px;
  }

  .welcome-message {
    padding: 24px 12px;
  }

  .welcome-message-icon {
    font-size: 36px;
    margin-bottom: 12px;
  }

  .welcome-message h3 {
    font-size: 15px;
    margin-bottom: 6px;
  }

  .welcome-message p {
    font-size: 12px;
  }

  .error-message {
    padding: 10px;
    font-size: 12px;
  }
}

/* Landscape Mode for Phones - Prevent Full Screen Takeover */
@media screen and (max-height: 600px) and (orientation: landscape) and (max-width: 768px) {
  .chatbot-window {
    bottom: 10px;
    right: 10px;
    left: auto;
    /* Width: 50% of viewport or full width minus 20px (10px margin on each side) */
    width: min(50vw, calc(100vw - 20px));
    /* Height: Full viewport minus 80px (60px toggle button + 20px spacing) */
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
    border-radius: 16px;
  }

  .chatbot-header {
    padding: 10px 12px;
    border-radius: 16px 16px 0 0;
  }

  .chatbot-messages {
    padding: 10px;
  }

  .chatbot-input-container {
    padding: 8px 10px;
  }

  .quick-actions {
    padding: 0 10px 8px;
  }

  .chatbot-toggle {
    width: 48px;
    height: 48px;
    bottom: 12px;
    right: 12px;
  }

  .chatbot-toggle-icon {
    font-size: 20px;
  }
}

/* Dark Mode Specific Adjustments */
[data-theme="dark"] .chatbot-window {
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 60px rgba(0, 212, 255, 0.06);
}

[data-theme="dark"] .chatbot-toggle {
  box-shadow: 0 4px 20px rgba(0, 212, 255, 0.35);
}

[data-theme="dark"] .chatbot-toggle:hover {
  box-shadow: 0 6px 25px rgba(0, 212, 255, 0.55);
}

/* Error Message */
.error-message {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  margin: 8px 0;
}

[data-theme="dark"] .error-message {
  background: #7f1d1d;
  color: #fecaca;
}

/* Link Styles in Messages */
.message-content a {
  font-weight: 500;
  transition: opacity 0.2s;
}

.message-content a:hover {
  opacity: 0.8;
}
