/* Chat Widget Styles */
.chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chat-toggle {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #262e8a 0%, #3b4096 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(38, 46, 138, 0.3);
  transition: all 0.3s ease;
  color: white;
  font-size: 24px;
}

.chat-toggle:hover {
  transform: scale(1.1);
}

.chat-toggle.active {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
}

.chat-container {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 400px;
  height: 600px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: slideInUp 0.3s ease-out;
  transition: transform 0.3s ease, bottom 0.3s ease;
}

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

.chat-container.show {
  display: flex;
}

.chat-header {
  background: linear-gradient(135deg, #262e8a 0%, #3b4096 100%);
  color: white;
  padding: 20px;
  text-align: center;
  position: relative;
}

.chat-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chat-header h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.chat-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.chat-subtitle {
  font-size: 12px;
  opacity: 0.9;
  margin: 0;
}

.status-indicator {
  position: absolute;
  top: 18px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #16a34a;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

.status-text {
  font-size: 11px;
  opacity: 0.9;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #fafafa;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
}

.message {
  display: flex;
  gap: 12px;
  animation: messageSlideIn 0.3s ease-out;
  align-items: flex-start;
}

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

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

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

.message.bot .message-avatar {
  background: linear-gradient(135deg, #262e8a 0%, #3b4096 100%);
  color: white;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #dae0dc 0%, #bec7c1 100%);
  color: white;
}

.message-content {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.bot .message-content {
  background: white;
  color: #374151;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.message.user .message-content {
  background: linear-gradient(135deg, #262e8a 0%, #3b4096 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

/* Enhanced message formatting styles */
.message-content p {
  margin: 0 0 12px 0;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul,
.message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content li {
  margin: 4px 0;
}

.message-content a {
  color: inherit;
  text-decoration: underline;
  font-weight: 500;
  transition: opacity 0.2s ease;
}

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

.message.bot .message-content a {
  color: #262e8a;
}

.message-content strong,
.message-content b {
  font-weight: 600;
}

.message-content em,
.message-content i {
  font-style: italic;
}

.message-content code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Monaco", "Consolas", monospace;
  font-size: 13px;
}

.message.user .message-content code {
  background: rgba(255, 255, 255, 0.2);
}

.message-content pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 12px;
  border-radius: 8px;
  margin: 8px 0;
  overflow-x: auto;
  border-left: 3px solid #262e8a;
}

.message.user .message-content pre {
  background: rgba(255, 255, 255, 0.1);
  border-left-color: rgba(255, 255, 255, 0.5);
}

.message-content blockquote {
  border-left: 3px solid #262e8a;
  padding-left: 12px;
  margin: 8px 0;
  font-style: italic;
  opacity: 0.9;
}

.message.user .message-content blockquote {
  border-left-color: rgba(255, 255, 255, 0.5);
}

.message-content h1,
.message-content h2,
.message-content h3 {
  font-weight: 600;
  margin: 8px 0 4px 0;
  line-height: 1.3;
}

.message-content h1 {
  font-size: 16px;
}
.message-content h2 {
  font-size: 15px;
}
.message-content h3 {
  font-size: 14px;
}

.message-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 6px;
  text-align: right;
}

.message.user .message-time {
  text-align: left;
}

.typing-indicator {
  display: flex;
  gap: 12px;
  align-items: center;
  opacity: 0;
  transform: translateY(15px);
  transition: all 0.3s ease;
}

.typing-indicator.active {
  opacity: 1;
  transform: translateY(0);
}

.typing-dots {
  display: flex;
  gap: 3px;
  padding: 12px 16px;
  background: white;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.dot {
  width: 6px;
  height: 6px;
  background: #9ca3af;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.dot:nth-child(1) {
  animation-delay: 0ms;
}
.dot:nth-child(2) {
  animation-delay: 200ms;
}
.dot:nth-child(3) {
  animation-delay: 400ms;
}

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

.chat-input-container {
  padding: 16px;
  background: white;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.chat-input-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
}

.chat-input {
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 22px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
  line-height: 1.4;
}

.chat-input:focus {
  border-color: #262e8a;
  box-shadow: 0 0 0 3px rgba(38, 46, 138, 0.1);
}

.send-button {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  color: white;
  border: none;
  border-radius: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 16px;
}

.send-button:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(22, 163, 74, 0.3);
}

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

.welcome-message {
  text-align: center;
  color: #6b7280;
  font-size: 14px;
  padding: 20px;
  background: white;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.welcome-message h3 {
  color: #262e8a;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 600;
}

.error-message {
  background: #fef2f2;
  color: #dc2626;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  border: 1px solid #fecaca;
  margin: 6px 0;
}

.chat-notification {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #f40505;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  animation: bounce 0.6s ease-in-out;
}

@keyframes bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px);
  }
  60% {
    transform: translateY(-4px);
  }
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .chat-widget {
    bottom: 10px;
    right: 10px;
  }

  .chat-container {
    width: calc(100vw - 20px);
    height: calc(100dvh - 80px);
    max-height: calc(100dvh - 80px);
    right: 0;
    bottom: 70px;
    border-radius: 12px;
  }

  .chat-toggle {
    width: 52px;
    height: 52px;
    font-size: 20px;
    box-shadow: 0 4px 16px rgba(38, 46, 138, 0.4);
  }

  .chat-header {
    padding: 16px;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
  }

  .chat-messages {
    padding: 16px;
    gap: 12px;
    max-height: calc(100dvh - 200px);
    min-height: 200px;
    overflow-y: auto;
    flex: 1;
  }

  .chat-input-container {
    padding: 12px;
    flex-shrink: 0;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
  }

  .chat-input {
    min-height: 40px;
    max-height: 80px;
    padding: 10px 14px;
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 20px;
    resize: none;
  }

  .send-button {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    font-size: 14px;
    flex-shrink: 0;
  }

  .message-content {
    max-width: 90%;
    font-size: 14px;
    padding: 10px 14px;
  }

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

  .chat-title {
    font-size: 16px;
  }

  .chat-subtitle {
    font-size: 10px;
  }

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

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

  .status-indicator {
    top: 16px;
    left: 16px;
  }

  .chat-close {
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    font-size: 20px;
  }

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

  .dot {
    width: 5px;
    height: 5px;
  }

  /* Ensure proper touch targets */
  .chat-toggle,
  .chat-close,
  .send-button {
    min-width: 44px;
    min-height: 44px;
  }

  /* Improve scrolling on mobile */
  .chat-messages::-webkit-scrollbar {
    width: 2px;
  }

  /* Better spacing for mobile messages */
  .message {
    gap: 8px;
  }

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

  /* Keyboard-aware adjustments */
  .chat-container.keyboard-active {
    height: calc(100dvh - 40px);
    max-height: calc(100dvh - 40px);
    bottom: calc(env(keyboard-inset-height, 0px) + 10px);
    transform: translateY(-20px);
    transition: transform 0.3s ease, bottom 0.3s ease;
  }

  .chat-container.keyboard-active .chat-messages {
    max-height: calc(100dvh - 200px);
  }

  .chat-container.keyboard-active .chat-input-container {
    position: sticky;
    bottom: 0;
    z-index: 1001;
    background: white;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin-bottom: env(keyboard-inset-height, 0px);
  }
}

/* Large mobile landscape */
@media (max-width: 768px) and (orientation: landscape) {
  .chat-container {
    height: calc(100dvh - 60px);
    max-height: calc(100dvh - 60px);
    width: calc(100vw - 20px);
    max-width: 500px;
  }

  .chat-messages {
    max-height: calc(100dvh - 180px);
  }

  /* Landscape keyboard handling */
  .chat-container.keyboard-active {
    height: calc(100dvh - 20px);
    max-height: calc(100dvh - 20px);
    bottom: calc(env(keyboard-inset-height, 0px) + 5px);
    transform: translateY(-10px);
  }

  .chat-container.keyboard-active .chat-messages {
    max-height: calc(100dvh - 140px);
  }

  .chat-container.keyboard-active .chat-input-container {
    position: sticky;
    bottom: 0;
    margin-bottom: env(keyboard-inset-height, 0px);
  }
}

/* Tablet responsive */
@media (max-width: 768px) and (min-width: 481px) {
  .chat-container {
    width: calc(100vw - 40px);
    height: calc(100vh - 100px);
    right: 20px;
    max-width: 400px;
  }

  .chat-messages {
    max-height: calc(100vh - 220px);
  }
}

/* Very small screens */
@media (max-width: 320px) {
  .chat-widget {
    bottom: 8px;
    right: 8px;
  }

  .chat-container {
    width: calc(100vw - 16px);
    right: 0;
  }

  .chat-toggle {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .message-content {
    max-width: 95%;
    font-size: 13px;
    padding: 8px 12px;
  }

  .chat-input {
    font-size: 16px;
    padding: 8px 12px;
  }

  /* Small screen keyboard handling */
  .chat-container.keyboard-active {
    height: calc(100dvh - 30px);
    max-height: calc(100dvh - 30px);
    bottom: calc(env(keyboard-inset-height, 0px) + 5px);
    transform: translateY(-15px);
  }

  .chat-container.keyboard-active .chat-messages {
    max-height: calc(100dvh - 150px);
  }

  .chat-container.keyboard-active .chat-input-container {
    position: sticky;
    bottom: 0;
    margin-bottom: env(keyboard-inset-height, 0px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  }
}
