/* Chat Widget Container */
.chat-widget {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 800px;
  height: 600px;
  background: #ffffff;
  border-radius: 24px;
  border: 1px solid #e5e7eb;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

/* Chat Header */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: #da4e29;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
}

.chat-history-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chat-history-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
  transition: background 0.3s ease;
}

.status-dot.offline {
  background: #9ca3af;
  animation: none;
}

.status-text {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
}

/* Messages Container */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #f9fafb;
}

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

.chat-messages::-webkit-scrollbar-track {
  background: #f3f4f6;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

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

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

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

/* Message Avatar */
.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  flex-shrink: 0;
}

.user-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: none; /* Hide user avatar, only show agent avatar */
}

.message-avatar span {
  text-transform: uppercase;
}

.message-avatar .avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* Message Content */
.message-content {
  flex: 0 1 auto;
  max-width: 70%;
  display: flex;
  flex-direction: column;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 6px;
}

.message-text {
  padding: 12px 16px;
  border-radius: 16px;
  background: #ffffff;
  color: #1f2937;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  border: 1px solid #e5e7eb;
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  text-align: left;
}

/* Improve formatting for lists and structured content */
.message-text ul,
.message-text ol {
  margin: 8px 0;
  padding-left: 24px;
  text-align: left;
}

.message-text li {
  margin: 4px 0;
  text-align: left;
}

.message-text p {
  margin: 8px 0;
  text-align: left;
}

.message-text p:first-child {
  margin-top: 0;
}

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

.user-message .message-content {
  text-align: left;
  align-items: flex-end;
}

.user-message .message-text {
  background: #da4e29;
  color: #ffffff;
  border-color: #da4e29;
  border-radius: 16px 16px 4px 16px;
  text-align: left;
}

.bot-message .message-content {
  align-items: flex-start;
  text-align: left;
}

.bot-message .message-text {
  text-align: left;
}

.bot-message .message-text {
  border-radius: 16px 16px 16px 4px;
}

/* Typing Indicator */
.typing-indicator .message-content {
  max-width: 80px;
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 16px 16px 16px 4px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: typingDot 1.4s infinite;
}

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

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

@keyframes typingDot {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Chat Error */
.chat-error {
  padding: 12px 16px;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 12px;
  color: #fca5a5;
  font-size: 14px;
  text-align: center;
  animation: errorShake 0.5s ease-out;
}

@keyframes errorShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* Conversation Ended Banner */
.conversation-ended-banner {
  padding: 20px;
  margin: 16px 0;
  animation: messageSlideIn 0.3s ease-out;
}

.conversation-ended-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  background: linear-gradient(135deg, #eef0f7 0%, #e0e4f0 100%);
  border: 2px solid rgba(29, 42, 103, 0.2);
  border-radius: 16px;
  text-align: center;
}

.conversation-ended-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #1d2a67;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.conversation-ended-icon svg {
  width: 28px;
  height: 28px;
}

.conversation-ended-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-ended-title {
  font-size: 18px;
  font-weight: 700;
  color: #1d2a67;
}

.conversation-ended-subtitle {
  font-size: 14px;
  color: rgba(29, 42, 103, 0.7);
  font-weight: 500;
}

.start-new-conversation-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: #da4e29;
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
}

.start-new-conversation-btn:hover {
  background: #b8401f;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.start-new-conversation-btn:active {
  transform: translateY(0);
}

.start-new-conversation-btn svg {
  width: 16px;
  height: 16px;
}

/* Conversation Rating */
.conversation-rating {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.rating-prompt {
  font-size: 14px;
  font-weight: 600;
  color: #1d2a67;
}

.rating-buttons {
  display: flex;
  gap: 16px;
}

.rating-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(29, 42, 103, 0.2);
  background: #ffffff;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rating-btn:hover {
  border-color: #da4e29;
  color: #da4e29;
  transform: scale(1.1);
}

.rating-btn.selected {
  background: #da4e29;
  border-color: #da4e29;
  color: #ffffff;
  transform: scale(1.1);
}

.rating-comment-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  animation: messageSlideIn 0.2s ease-out;
}

.rating-comment {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid rgba(29, 42, 103, 0.2);
  border-radius: 10px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  outline: none;
  color: #1d2a67;
  background: #ffffff;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.rating-comment:focus {
  border-color: #da4e29;
}

.rating-comment::placeholder {
  color: #9ca3af;
}

.rating-submit-btn {
  align-self: flex-end;
  padding: 8px 20px;
  background: #da4e29;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}

.rating-submit-btn:hover {
  background: #b8401f;
}

.rating-thank-you {
  font-size: 14px;
  font-weight: 600;
  color: #16a34a;
  animation: messageSlideIn 0.3s ease-out;
}

/* Message Links */
.message-text a.message-link {
  color: #2563eb;
  text-decoration: underline;
  transition: all 0.2s ease;
  word-break: break-all;
}

.message-text a.message-link:hover {
  color: #1d4ed8;
  text-decoration: none;
}

.user-message .message-text a.message-link {
  color: #93c5fd;
}

.user-message .message-text a.message-link:hover {
  color: #bfdbfe;
}

/* Outlook Calendar Button */
.outlook-calendar-button-wrapper {
  display: inline-block;
  margin: 8px 0;
}

.outlook-calendar-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: #da4e29;
  color: #ffffff;
  text-decoration: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.outlook-calendar-button:hover {
  background: #b8401f;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.outlook-calendar-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Retell Link Button */
.retell-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  margin: 6px 0;
  background: #da4e29;
  color: #ffffff;
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.retell-link-btn::after {
  content: '↗';
  font-size: 12px;
  margin-left: 2px;
}

.retell-link-btn:hover {
  background: #b8401f;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  color: #ffffff;
  text-decoration: none;
}

.retell-link-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Input Container */
.chat-input-container {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  color: #1f2937;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: all 0.3s ease;
  max-height: 120px;
  overflow-y: auto;
}

.chat-input::placeholder {
  color: #9ca3af;
}

.chat-input:focus {
  background: #ffffff;
  border-color: #da4e29;
  box-shadow: 0 0 0 3px rgba(218, 78, 41, 0.15);
}

.chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send-button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #da4e29;
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.chat-send-button:hover:not(:disabled) {
  background: #b8401f;
  transform: scale(1.05);
}

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

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

.chat-send-button.processing {
  animation: buttonPulse 1s ease-in-out infinite;
}

@keyframes buttonPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Fixed starters container above input */
.chat-starters-fixed {
  background: #ffffff;
  padding: 16px 24px;
  transition: all 0.3s ease;
}

.chat-starters-fixed .example-questions {
  margin: 0;
  max-width: 100%;
}

.chat-starters-fixed .example-questions-title {
  text-align: left;
  color: #6b7280;
  font-size: 12px;
  margin-bottom: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-starters-fixed .question-chips {
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-starters-fixed .question-chip {
  background: #f3f4f6;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 20px;
  transition: all 0.2s ease;
}

.chat-starters-fixed .question-chip:hover {
  background: #da4e29;
  color: #ffffff;
  border-color: #da4e29;
  transform: translateY(-1px);
}

/* Quick Reply Dropdown */
.quick-replies-container {
  display: none;
  padding: 8px 20px 12px;
  animation: quickRepliesFadeIn 0.3s ease-out;
}

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

.quick-reply-dropdown {
  position: relative;
  width: 100%;
}

.quick-reply-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--color-white);
  color: var(--color-dark);
  border: 1.5px solid var(--color-dark);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.quick-reply-trigger svg {
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.quick-reply-dropdown.open .quick-reply-trigger {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(218, 78, 41, 0.15);
}

.quick-reply-dropdown.open .quick-reply-trigger svg {
  transform: rotate(180deg);
}

.quick-reply-trigger:hover {
  border-color: var(--color-primary);
}

.quick-reply-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-white);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 10;
}

.quick-reply-dropdown.open .quick-reply-menu {
  display: block;
  animation: menuSlideIn 0.2s ease-out;
}

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

.quick-reply-option {
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid #f3f4f6;
  color: var(--color-gray-800);
  font-size: 14px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.quick-reply-option:last-child {
  border-bottom: none;
}

.quick-reply-option:hover {
  background: var(--color-primary);
  color: var(--color-white);
}

/* Welcome Screen */
.chat-welcome-screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  border-radius: 24px;
}

/* In floating mode, remove welcome screen border-radius.
   The parent .chat-widget-container.floating already has
   border-radius + overflow:hidden, so it clips correctly.
   This eliminates the subpixel gap where the orange header peeks through. */
.floating .chat-welcome-screen {
  border-radius: 0;
}

/* When the welcome screen is visible in floating mode, hide ALL underlying
   content (header, messages, input, etc.) so nothing can bleed through the
   anti-aliased corner pixels of the outer container's border-radius.
   The welcome screen covers everything with a solid white background,
   so the underlying elements are invisible anyway.
   Using visibility:hidden keeps layout stable while preventing paint. */
.floating .chat-widget:has(.chat-welcome-screen.visible) > :not(.chat-welcome-screen) {
  visibility: hidden;
}

.chat-welcome-screen.visible {
  opacity: 1;
  visibility: visible;
}

.welcome-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
  animation: welcomeFadeUp 0.5s ease-out 0.1s both;
}

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

.welcome-avatar {
  width: 80px;
  height: 80px;
}

.welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.welcome-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: #1d2a67;
}

.welcome-subtitle {
  margin: 0;
  font-size: 15px;
  color: #6b7280;
  line-height: 1.5;
}

/* Language Selector */
.welcome-lang-selector {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.lang-btn:hover {
  border-color: #da4e29;
  background: #fff7f5;
}

.lang-btn.selected {
  border-color: #da4e29;
  background: #fff7f5;
  color: #da4e29;
  font-weight: 600;
}

.lang-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  position: relative;
}

.lang-coming-soon {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: #9ca3af;
  margin-top: -2px;
  letter-spacing: 0.02em;
}

.welcome-start-btn {
  margin-top: 8px;
  padding: 14px 48px;
  background: #da4e29;
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
}

.welcome-start-btn:hover {
  background: #b8401f;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(218, 78, 41, 0.3);
}

.welcome-start-btn:active {
  transform: translateY(0);
}

/* Streaming cursor animation */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #9ca3af;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s step-end infinite;
}

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

/* Tooltips */
.has-tooltip {
  position: relative;
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  background: #1f2937;
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 200;
}

.has-tooltip:hover::after {
  opacity: 1;
}

.has-tooltip.tooltip-top::after {
  top: auto;
  bottom: calc(100% + 8px);
}

/* Restart Icon Button (inside input container) */
.chat-restart-icon {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: none;
  color: #1d2a67;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  transition: all 0.2s ease;
}

.chat-restart-icon:hover {
  border-color: #1d2a67;
  background: rgba(29, 42, 103, 0.06);
}

.chat-restart-icon:active {
  transform: scale(0.93);
}

.chat-restart-icon svg {
  width: 18px;
  height: 18px;
}

/* Responsive */
@media (max-width: 768px) {
  .chat-widget {
    height: 500px;
    border-radius: 16px;
  }

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

  .chat-header h3 {
    font-size: 16px;
  }

  .chat-messages {
    padding: 16px;
    gap: 12px;
  }

  .message-content {
    max-width: 80%;
  }

  .message-text {
    font-size: 14px;
    padding: 10px 14px;
  }

  .chat-input-container {
    padding: 16px 20px;
    gap: 10px;
  }

  .chat-input {
    font-size: 14px;
    padding: 10px 14px;
  }

  .chat-send-button {
    width: 40px;
    height: 40px;
  }

  /* Outlook Calendar Button - mobile */
  .outlook-calendar-button {
    padding: 10px 20px;
    font-size: 14px;
  }

  /* Retell Link Button - mobile */
  .retell-link-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  /* Conversation ended banner - mobile */
  .conversation-ended-banner {
    padding: 12px;
    margin: 12px 0;
  }

  .conversation-ended-content {
    padding: 20px 16px;
    gap: 12px;
  }

  .conversation-ended-icon {
    width: 40px;
    height: 40px;
  }

  .conversation-ended-icon svg {
    width: 24px;
    height: 24px;
  }

  .conversation-ended-title {
    font-size: 16px;
  }

  .conversation-ended-subtitle {
    font-size: 13px;
  }

  .start-new-conversation-btn {
    padding: 10px 20px;
    font-size: 14px;
  }

  .rating-btn {
    width: 42px;
    height: 42px;
  }

  .rating-comment {
    font-size: 13px;
  }

  .chat-restart-icon {
    width: 40px;
    height: 40px;
  }
}
