.purands-chat-button,
.purands-chat-container,
.purands-chat-container *,
.purands-chat-overlay {
  font-family: Arial, sans-serif !important;
}

/* — Floating chat button — */
.purands-chat-button svg {
  width: 40px;
  height: 40px;
  fill: none;
}

.purands-chat-button {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: #1f2937;
  color: #fff;
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25);
  transition: all .2s ease;
  padding: 0;
  margin: 0;
}

.purands-chat-button:hover,
.purands-chat-button:focus {
  background: #374151;
  transform: scale(1.05);
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.3);
}

/* — Chat container — */
.purands-chat-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  max-width: 384px;
  width: calc(100% - 2rem);
  height: calc(100vh - 9rem);
  max-height: 700px;
  display: none;
  flex-direction: column;
  background: linear-gradient(#fff, #f8fafc);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif;
  z-index: 9999;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* Prevent horizontal scroll on all elements */
* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

@media (max-width: 480px) {
  .purands-chat-container {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
    /* Use dynamic viewport height to account for mobile browser UI */
    height: 100dvh !important;
    max-height: 100dvh !important;
  }

  /* Ensure all child elements respect container bounds */
  .purands-chat-container * {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Fix header */
  .purands-chat-header {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    flex-shrink: 0;
    padding: 12px 16px !important;
  }

  /* Fix messages area */
  .purands-chat-messages {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    flex: 1;
    min-height: 0;
    /* Important for flex children */
    padding: 12px 16px !important;
  }

  /* Fix input wrapper - make it sticky and compact */
  .purands-chat-input-wrapper {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 10 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 12px 16px !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    background: #fff !important;
    border-top: 1px solid #e5e7eb !important;
  }

  .purands-chat-input-container {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 8px 12px !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    background: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 24px !important;
  }

  /* Critical fix for input field */
  .purands-chat-input-field {
    flex: 1 !important;
    width: 0 !important;
    /* Force flex to work properly */
    min-width: 0 !important;
    /* Allow shrinking below content size */
    max-width: 100% !important;
    box-sizing: border-box !important;
    border: none !important;
    outline: none !important;
    padding: 8px 0 !important;
    margin: 0 !important;
    background: transparent !important;
    font-size: 16px !important;
    /* Prevent zoom on iOS */
    -webkit-appearance: none !important;
    -webkit-border-radius: 0 !important;
  }

  /* Fix send button */
  .purands-chat-send-button {
    flex-shrink: 0 !important;
    width: 32px !important;
    height: 32px !important;
    margin: 0 !important;
  }

  /* Fix footer */
  .purands-chat-footer {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 8px 16px !important;
    flex-shrink: 0 !important;
  }

  /* Prevent any text or content from causing overflow */
  .purands-chat-message-content {
    max-width: calc(100% - 48px) !important;
    /* Account for avatar and gaps */
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }

  .purands-chat-bubble {
    max-width: 100% !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }
}

/* Support for newer browsers with dynamic viewport units */
@supports (height: 100dvh) {
  @media (max-width: 480px) {
    .purands-chat-container {
      height: 100dvh !important;
      max-height: 100dvh !important;
    }
  }
}

/* Overlay that sits under the chat on mobile full-screen */
.purands-chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9998;
  display: none;
}

/* When chat is open on mobile, prevent body scroll */
body.purands-chat-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* — Header — */
.purands-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.purands-chat-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #111827;
}

.purands-chat-description {
  margin: 4px 0 0;
  font-size: 14px;
  color: #4b5563;
}

.purands-chat-close-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 400;
  line-height: 1;
  transition: all .2s;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
  font-family: Arial, sans-serif;
  /* Use a consistent font */
  text-align: center;

  /* Additional centering fixes */
  vertical-align: middle;
  box-sizing: border-box;
}

.purands-chat-close-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #374151;
}

.purands-chat-close-btn:focus {
  background: rgba(0, 0, 0, 0.1);
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* — Messages — */
.purands-chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
  /* Important for flex children */
}

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

.purands-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}

.purands-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* — Message bubbles — */
.purands-chat-message {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  max-width: 100%;
}

.purands-chat-message-user {
  justify-content: flex-end;
}

.purands-chat-message-ai {
  justify-content: flex-start;
}

.purands-chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.purands-chat-avatar svg {
  width: 16px;
  height: 16px;
  fill: rgb(255, 255, 255);
}

.purands-chat-avatar-bot {
  background: #111827;
  color: #fff;
}

.purands-chat-avatar-user {
  background: #4b5563;
  color: #fff;
}

.purands-chat-message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 75%;
  min-width: 0;
  /* Allow shrinking */
}

.purands-chat-bubble {
  border-radius: 1rem;
  padding: 8px 16px;
  font-size: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.purands-chat-bubble-user {
  background: #1f2937;
  color: #fff;
  border-top-right-radius: 4px;
}

.purands-chat-bubble-bot {
  background: #f3f4f6;
  color: #111827;
  border-top-left-radius: 4px;
}

.purands-chat-timestamp {
  font-size: 10px;
  color: #94a3b8;
  padding: 0 8px;
}

/* — Typing indicator — */
@keyframes purands-typing-blink {

  0%,
  80%,
  100% {
    opacity: 0.4;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.purands-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px;
}

.purands-typing-dot {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  opacity: .6;
  animation: purands-typing-blink 1.2s infinite ease-in-out;
}

.purands-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

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

/* — Input area — */
.purands-chat-input-wrapper {
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 16px;
  flex-shrink: 0;
}

.purands-chat-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 9999px;
  width: 100%;
  box-sizing: border-box;
  padding: 5px 10px;
}

.purands-chat-input-container:focus-within {
  border-color: #9c9faf;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.purands-chat-input-field {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  box-shadow: none;
  color: inherit;
  padding: 0;
  font-size: 14px;
  min-width: 0;
  /* Allow shrinking below content size */
}

.purands-chat-input-field::placeholder {
  color: #94a3b8;
}

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

/* Prevent grey hover on input wrapper */
.purands-chat-input-container:hover {
  background-color: #f8fafc !important;
}

/* Make sure the text input itself stays transparent on hover */
.purands-chat-input-field:hover {
  background-color: transparent !important;
}

.purands-chat-send-button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #1f2937;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: all .2s;
  flex-shrink: 0;
  padding: 0;
}

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

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

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

/* — Footer — */
.purands-chat-footer {
  text-align: center;
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 4px;
  flex-shrink: 0;
}

.purands-chat-footer a {
  color: #111827;
  text-decoration: none;
}

.purands-chat-footer a:hover {
  text-decoration: underline;
}