/* Chat Modal Styles - Enhanced UI/UX */

/* Base Modal Container */
.chat-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
  font-family: system-ui, -apple-system, sans-serif;
}

.chat-modal.open {
  display: block;
}

.chat-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}

/* Modal Window */
.chat-modal-window {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  width: 100%;
  max-width: 600px;
  /* Increased to 600px */
  height: 80vh;
  /* Increased height */
  max-height: 850px;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  /* Adjusted radius */
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.15), 0 12px 24px rgba(0, 0, 0, 0.1);
  /* Soft shadow */
  overflow: hidden;
  animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Header */
.chat-modal-header {
  background: #2563EB;
  /* Solid blue or gradient */
  background: linear-gradient(135deg, #2563EB, #1E40AF);
  color: #fff;
  padding: 20px 24px;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-modal-header::before {
  content: "🤖";
  font-size: 24px;
}

.chat-modal-close {
  position: absolute;
  top: 18px;
  right: 20px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 28px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s;
}

.chat-modal-close:hover {
  color: #fff;
}

/* Messages Area */
.chat-modal-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  padding: 0;
}

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

/* Message Bubbles */
.chat-message {
  max-width: 85%;
  padding: 18px 22px;
  /* Increased padding */
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.chat-message-bot {
  background: #F3F4F6;
  /* Gray for bot */
  color: #1F2937;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.chat-message-user {
  background: #EFF6FF;
  /* Light blue for user */
  color: #1E40AF;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
  text-align: right;
}

/* Markdown Content Styles */
.chat-message p {
  margin: 0 0 10px 0;
}

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

.chat-message ul {
  margin: 8px 0;
  padding-left: 20px;
}

.chat-message li {
  margin-bottom: 4px;
}

.chat-message strong {
  font-weight: 600;
}

/* Input Area */
.chat-modal-form {
  padding: 20px 24px;
  background: #fff;
  border-top: 1px solid #F3F4F6;
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.chat-modal-input {
  /* Input is now textarea */
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #E5E7EB;
  border-radius: 14px;
  font-size: 16px;
  font-family: inherit; /* Inherit font for textarea */
  background: #F9FAFB;
  transition: all 0.2s;
  min-height: 48px; /* Approx 1 line + padding */
  max-height: 150px; /* Limit expansion */
  line-height: 1.4;
}

.chat-modal-input:focus {
  outline: none;
  border-color: #2563EB;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.chat-modal-send {
  background: #2563EB;
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 0 24px;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.chat-modal-send:hover {
  background: #1d4ed8;
}

.chat-modal-send:active {
  transform: scale(0.96);
}

.chat-modal-send:disabled {
  background: #9CA3AF;
  cursor: not-allowed;
}

/* Floating Button */
.chat-floating-btn {
  position: fixed;
  right: 32px;
  bottom: 32px;
  z-index: 9998;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3);
  border-radius: 50%;
}

.chat-floating-btn:hover {
  transform: scale(1.1) rotate(-5deg);
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -40%) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Mobile Adaptation */
@media (max-width: 640px) {
  .chat-modal-window {
    width: 95%;
    /* 95% width on mobile */
    height: 90vh;
    /* Taller on mobile but not full screen to show backdrop */
    max-width: none;
    max-height: none;
    border-radius: 20px;
    /* Keep radius on mobile */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: modalSlideIn 0.3s ease-out;
  }

  .chat-modal-header {
    padding: 16px 20px;
  }

  .chat-modal-close {
    top: 16px;
    right: 16px;
  }

  .chat-modal-messages {
    padding: 16px;
  }

  .chat-modal-form {
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* Microphone Button */
.chat-modal-mic {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  color: #6B7280;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-modal-mic:hover {
  background-color: #F3F4F6;
  color: #2563EB;
}

.chat-modal-mic.listening {
  color: #DC2626;
  animation: pulse 1.5s infinite;
  background-color: #FEE2E2;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
  }
}

/* Safe area for iOS (notch/home bar) */
@media (max-width: 900px) {
  .chat-floating-btn {
    right: 16px;
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 16px));
  }
}

/* TTS Button */
.chat-tts-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  margin-top: 8px;
  font-size: 14px;
  color: #6B7280;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 12px;
  transition: all 0.2s;
  background-color: rgba(0, 0, 0, 0.03);
  width: fit-content;
}

.chat-tts-btn:hover {
  background-color: rgba(0, 0, 0, 0.08);
  color: #2563EB;
}

.chat-tts-btn.speaking {
  color: #2563EB;
  background-color: #DBEAFE;
}