.chatbot-widget {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: 9999;
  font-family: var(--font-primary);
}

.chatbot-toggle {
  width: 70px;
  height: 70px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  border: none;
  cursor: pointer;
  box-shadow: 0 0 40px rgba(37, 99, 235, 0.4), 0 0 80px rgba(37, 99, 235, 0.2), var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: visible;
  animation: floatBounce 3s ease-in-out infinite, glowPulse 3s ease-in-out infinite;
}

@keyframes floatBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  25% { transform: translateY(-10px) scale(1.05); }
  50% { transform: translateY(-18px) scale(1.08); }
  75% { transform: translateY(-10px) scale(1.05); }
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 40px rgba(37, 99, 235, 0.4), 0 0 80px rgba(37, 99, 235, 0.2), var(--shadow-lg); }
  50% { box-shadow: 0 0 60px rgba(37, 99, 235, 0.7), 0 0 100px rgba(37, 99, 235, 0.4), 0 0 140px rgba(37, 99, 235, 0.2); }
}

.chatbot-toggle:hover {
  animation: none;
  transform: scale(1.2) rotate(10deg);
  background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
  box-shadow: 0 0 80px rgba(37, 99, 235, 0.9), 0 0 120px rgba(37, 99, 235, 0.6), 0 0 160px rgba(37, 99, 235, 0.3);
}

.chatbot-toggle svg {
  width: 34px;
  height: 34px;
  fill: var(--color-text-inverse);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  position: relative;
  z-index: 1;
  animation: iconWiggle 5s ease-in-out infinite;
}

@keyframes iconWiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  10% { transform: rotate(-15deg) scale(1.15); }
  20% { transform: rotate(15deg) scale(1.15); }
  30% { transform: rotate(-12deg) scale(1.12); }
  40% { transform: rotate(0deg) scale(1); }
}

.chatbot-toggle:hover svg {
  animation: iconBounceHover 0.5s ease-in-out infinite;
}

@keyframes iconBounceHover {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.3) rotate(15deg); }
}

.chatbot-toggle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  border: 3px solid var(--color-primary);
  transform: translate(-50%, -50%);
  animation: ripple 2.5s ease-out infinite;
  opacity: 0;
}

@keyframes ripple {
  0% { width: 100%; height: 100%; opacity: 0.8; border-width: 3px; }
  100% { width: 200%; height: 200%; opacity: 0; border-width: 0; }
}

.chatbot-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: linear-gradient(135deg, var(--color-danger), #ff6b6b);
  color: var(--color-text-inverse);
  border-radius: var(--radius-full);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  animation: badgePulse 2s infinite;
  z-index: 2;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.6);
  border: 3px solid var(--color-bg-primary);
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7), 0 4px 12px rgba(239, 68, 68, 0.6); }
  50% { transform: scale(1.25); box-shadow: 0 0 0 12px rgba(239, 68, 68, 0), 0 4px 12px rgba(239, 68, 68, 0.6); }
}

.chatbot-container {
  position: fixed;
  bottom: 20px; 
  right: 20px; 
  width: 420px;
  height: 650px;
  background: var(--color-bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 100px rgba(37, 99, 235, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--color-border);
  backdrop-filter: blur(20px) saturate(180%);
  transform-origin: bottom right;
}

.chatbot-container.resizing {
  transition: none !important;
  user-select: none;
}

.chatbot-container.active {
  display: flex;
  animation: slideUpScale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUpScale {
  from { opacity: 0; transform: translateY(30px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chatbot-header {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  padding: var(--spacing-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.chatbot-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.1));
  opacity: 0.5;
}

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

.chatbot-avatar {
  width: 48px;
  height: 48px;
  background: var(--color-bg-primary);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--color-primary);
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(255, 255, 255, 0.3);
  animation: avatarPulse 3s ease-in-out infinite;
}

@keyframes avatarPulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(255, 255, 255, 0.3); }
  50% { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2), 0 0 0 5px rgba(255, 255, 255, 0.5); }
}

.chatbot-header-text h3 {
  margin: 0;
  color: var(--color-text-inverse);
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  letter-spacing: -0.3px;
}

.chatbot-header-text span {
  color: var(--color-text-inverse);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.status-dot {
  width: 9px;
  height: 9px;
  background: var(--color-success);
  border-radius: var(--radius-full);
  display: inline-block;
  animation: statusBlink 2s infinite;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

@keyframes statusBlink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.9); }
}

.chatbot-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: var(--color-text-inverse);
  cursor: pointer;
  padding: var(--spacing-xs);
  border-radius: var(--radius-md);
  transition: var(--transition-base);
  position: relative;
  z-index: 1;
  backdrop-filter: blur(10px);
}

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

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  background: linear-gradient(180deg, var(--color-bg-secondary), var(--color-bg-primary));
}

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

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

.chatbot-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--color-primary), var(--color-primary-light));
  border-radius: var(--radius-lg);
}

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

.message {
  display: flex;
  gap: var(--spacing-sm);
  animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.message.client {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-inverse);
  font-size: 14px;
  font-weight: bold;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.message.bot .message-avatar {
  background: linear-gradient(135deg, var(--color-secondary), #a78bfa);
}

.message-content {
  max-width: 70%;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  position: relative;
  box-shadow: var(--shadow-sm);
}

.message.client .message-content {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  color: #f1f5f9;
  border-bottom-right-radius: var(--radius-sm);
}

.message.bot .message-content {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: var(--radius-sm);
}

.message-text {
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
}

.message-text a {
  color: var(--color-primary);
  text-decoration: underline;
  word-break: break-all;
  font-weight: 500;
}

.message-text a:hover {
    color: var(--color-primary-dark);
    text-decoration: none;
}

.message.client .message-text a {
  color: var(--color-text-inverse);
}

.message-time {
  font-size: 11px;
  color: var(--color-text-tertiary);
  margin-top: 6px;
  opacity: 0.7;
}

.message.client .message-time {
  color: rgba(255, 255, 255, 0.9);
  opacity: 1;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm);
}

.typing-dots {
  display: flex;
  gap: 5px;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.typing-dots span {
  width: 10px;
  height: 10px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  animation: typingBounce 1.4s infinite;
}

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

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

.chatbot-input {
  padding: var(--spacing-lg);
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
}

.input-wrapper {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  background: var(--color-bg-primary);
  border-radius: calc(var(--radius-xl) + 4px);
  padding: 6px 6px 6px 22px;
  border: 2px solid var(--color-border);
  transition: var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12), var(--shadow-md);
  transform: translateY(-2px);
}

#chatbot-message {
  flex: 1;
  background: none;
  border: none;
  color: var(--color-text-primary);
  font-size: 15px;
  outline: none;
  padding: 10px 0;
  font-family: var(--font-primary);
}

#chatbot-message::placeholder {
  color: var(--color-text-tertiary);
}

.chatbot-send {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.chatbot-send:hover:not(:disabled) {
  transform: scale(1.15) rotate(15deg);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.5);
  background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
}

.chatbot-send:active:not(:disabled) {
  transform: scale(0.95);
}

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

.chatbot-send svg {
  width: 22px;
  height: 22px;
  fill: var(--color-text-inverse);
}

.error-message {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.05));
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--color-danger);
  padding: 14px;
  border-radius: var(--radius-lg);
  margin: var(--spacing-sm);
  font-size: 14px;
  text-align: center;
  font-weight: 500;
}

.welcome-message {
  text-align: center;
  padding: var(--spacing-xl) var(--spacing-lg);
  color: var(--color-text-secondary);
  font-size: 15px;
  line-height: 1.7;
}

.welcome-message h4 {
  color: var(--color-primary);
  margin-bottom: var(--spacing-sm);
  font-size: 20px;
  font-weight: 700;
}

.chatbot-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%; 
  height: 14px; 
  cursor: ns-resize; 
  z-index: 20;
  background: transparent;
}

.chatbot-resize-handle::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  transition: background 0.3s;
}

.chatbot-resize-handle:hover::before {
  background: rgba(255, 255, 255, 0.6);
}

.chatbot-widget *:focus { 
    outline: 2px solid var(--color-primary); 
    outline-offset: 2px; 
}

@media (max-width: 480px) {
  .chatbot-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100% !important; 
    height: 100% !important; 
    max-width: none;
    border-radius: 0;
    z-index: 9999;
  }
  
  .chatbot-toggle {
    bottom: 20px;
    right: 20px;
    width: 64px;
    height: 64px;
    z-index: 9998;
  }
  
  .chatbot-widget {
    bottom: 20px;
    right: 20px;
  }

  .chatbot-resize-handle {
    display: none;
  }
  
  #chatbot-mic {
      width: 40px;
      height: 40px;
      font-size: 1.2rem;
  }
  
  .message-voice-btn {
      width: 26px;
      height: 26px;
      font-size: 0.95rem;
  }
}

.takeover-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    margin: 12px 8px;
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border: 1px solid #6ee7b7;
    border-radius: 20px;
    color: #047857;
    font-size: 0.8rem;
    font-weight: 600;
    animation: slideInNotice 0.4s ease-out;
}

[data-theme="dark"] .takeover-notice {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(5, 150, 105, 0.1));
    border-color: rgba(16, 185, 129, 0.4);
    color: #34d399;
}

.takeover-notice i {
    font-size: 0.9rem;
}

@keyframes slideInNotice {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.bot.admin-message {
    --admin-color: #059669;
    --admin-color-light: #10b981;
}

.message.bot.admin-message .message-avatar {
    background: linear-gradient(135deg, var(--admin-color-light), var(--admin-color));
    color: #fff;
    font-weight: 700;
    font-size: 0.75rem;
}

.message.bot.admin-message .message-bubble {
    background: #fff;
    border: 2px solid #d1fae5;
    border-radius: 18px 18px 18px 4px;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.1);
}

[data-theme="dark"] .message.bot.admin-message .message-bubble {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
}

.message.bot.admin-message .admin-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border-bottom: 1px solid #a7f3d0;
}

[data-theme="dark"] .message.bot.admin-message .admin-header {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.15));
    border-bottom-color: rgba(16, 185, 129, 0.3);
}

.message.bot.admin-message .admin-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    color: #047857;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

[data-theme="dark"] .message.bot.admin-message .admin-label {
    color: #34d399;
}

.message.bot.admin-message .admin-label i {
    font-size: 0.7rem;
}

.message.bot.admin-message .message-text {
    padding: 10px 12px;
    color: var(--color-text-primary);
    font-size: 0.9rem;
    line-height: 1.5;
    background: transparent;
}

.message.bot.admin-message .message-time {
    padding: 0 12px 8px;
    font-size: 0.7rem;
    color: var(--color-text-tertiary);
}

.message.bot.admin-message .tts-btn {
    margin: 0 12px 8px;
}
