/* General Body Style (from our original code, ensure it doesn't conflict with theme) */
/* It's generally better to let the theme handle body font if possible */
/* body {
    font-family: 'Inter', sans-serif;
} */

/* Style for the chat widget container */
#awc-chat-widget-container {
  position: fixed;
  bottom: 1.5rem; /* 24px */
  /* NOTE: 'right' or 'left' will be set by inline style from PHP */
  z-index: 1000; /* Ensure it's above other content */
  display: flex;
  flex-direction: column;
  /* NOTE: 'align-items' will be set by inline style from PHP */
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Style for the chat menu - positioned above the button */
#awc-chat-menu {
  margin-bottom: 0.75rem; /* 12px */
  width: 18rem; /* Fixed width for the menu */
  background-color: #ffffff;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
  border: 1px solid #e5e7eb;
  transition: transform 0.3s ease-out, opacity 0.3s ease-out;
  /* transform-origin will be set by JS based on position */
}

/* Default transform origin, JS will add a class to change this if needed */
#awc-chat-menu {
  transform-origin: bottom right;
}
#awc-chat-menu.awc-origin-left {
  transform-origin: bottom left;
}

.awc-widget-disabled {
  pointer-events: none;
  opacity: 0.5;
  position: relative;
}
.awc-widget-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.7);
  z-index: 9999;
  border-radius: 0.5rem;
}

/* Hidden state for the menu itself and its internal components */
.awc-hidden {
  /* This class will be toggled by JavaScript */
  display: none !important;
}

/* Animation for menu opening/closing (works when 'awc-hidden' class is removed/added) */
#awc-chat-menu.awc-hidden {
  /* This specific rule is for the animation part */
  transform: scale(0.9);
  opacity: 0;
  pointer-events: none;
}

/* Style for the main chat toggle button */
#awc-chat-toggle-button {
  /* background-color will be set by inline style from PHP options */
  color: white;
  padding: 1rem;
  border-radius: 9999px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s ease-in-out, background-color 0.2s ease-in-out;
  border: none;
  cursor: pointer;
  display: flex; /* To align icons if needed */
  align-items: center;
  justify-content: center;
}
#awc-chat-toggle-button:hover {
  transform: scale(1.1);
  /* Hover brightness will be set by inline style from PHP options */
}
#awc-chat-toggle-button:focus {
  outline: none;
  /* Focus ring will be set by inline style from PHP options */
}
#awc-chat-toggle-button svg {
  height: 1.5rem; /* h-6 */
  width: 1.5rem; /* w-6 */
}

/* Chat Menu Header */
#awc-chat-menu-header {
  padding: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  background-color: #f9fafb;
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  height: 2.5rem;
}

#awc-chat-menu-header #awc-header-back-button {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0;
  /* color will be set by inline style from PHP options */
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
}
html[dir="rtl"] #awc-chat-menu-header #awc-header-back-button {
  left: auto;
  right: 0.75rem;
}
#awc-chat-menu-header #awc-header-back-button:hover {
  text-decoration: underline;
}
#awc-chat-menu-header #awc-header-back-button svg.awc-widget-icon-small {
  height: 1rem;
  width: 1rem;
  margin-inline-end: 0.25rem;
}
html[dir="rtl"]
  #awc-chat-menu-header
  #awc-header-back-button
  svg.awc-widget-icon-small {
  transform: rotate(180deg);
}
#awc-chat-menu-header #awc-chat-menu-title {
  font-size: 1rem;
  font-weight: 600;
  color: #374151;
  display: inline-block;
  margin: 0;
}

/* Main Options Container */
#awc-main-options-container {
  padding: 0.5rem;
}
#awc-main-options-container > .awc-menu-item + .awc-menu-item,
#awc-main-options-container > a.awc-menu-item + a.awc-menu-item,
#awc-main-options-container > div.awc-menu-item + a.awc-menu-item,
#awc-main-options-container > a.awc-menu-item + div.awc-menu-item,
#awc-main-options-container > div.awc-menu-item + div.awc-menu-item {
  /* For AI chat option */
  margin-top: 0.25rem;
}

/* Style for menu items */
.awc-menu-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  transition: background-color 0.2s ease-in-out;
  cursor: pointer;
  text-decoration: none;
  color: #374151;
  font-size: 0.875rem;
}
.awc-menu-item:hover {
  background-color: #f3f4f6;
}
.awc-menu-item svg.awc-widget-icon {
  /* For main option icons */
  height: 1.25rem;
  width: 1.25rem;
  margin-inline-end: 0.75rem;
}
.awc-menu-item svg.awc-whatsapp-icon {
  /* Specific for WhatsApp icon */
  color: #22c55e;
}

/* Contact Details Container (for form, other options, and AI chat) */
#awc-contact-details-container {
  padding: 0.75rem;
  border-top: 1px solid #e5e7eb;
}
#awc-contact-details-container > div + div {
  margin-top: 0.75rem;
}

/* Form specific styles */
#awc-contact-form-section label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
}
#awc-contact-form-section input[type="text"],
#awc-contact-form-section input[type="email"],
#awc-contact-form-section textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
  box-sizing: border-box;
}
#awc-contact-form-section input[type="text"]:focus,
#awc-contact-form-section input[type="email"]:focus,
#awc-contact-form-section textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}
#awc-contact-form-section .awc-form-field-group {
  margin-bottom: 0.75rem;
}
#awc-contact-form-section button[type="submit"] {
  /* Also applies to AI send button via inline style */
  width: 100%;
  padding: 0.625rem 1rem;
  margin-top: 0.75rem;
  color: white;
  font-weight: 600;
  border-radius: 0.375rem;
  transition: background-color 0.2s ease-in-out, filter 0.2s ease-in-out;
  border: none;
  cursor: pointer;
}
#awc-widget-form-status {
  /* Class for the p tag */
  font-size: 0.875rem;
  margin-top: 0.5rem;
  text-align: center;
  min-height: 1.2em;
}
#awc-widget-form-status.awc-success,
.awc-ai-chat-status-text.awc-success {
  /* Updated for AI */
  color: #16a34a;
}
#awc-widget-form-status.awc-error,
.awc-ai-chat-status-text.awc-error {
  /* Updated for AI */
  color: #dc2626;
}

/* Other Contact Options Section */
#awc-other-contact-section {
  font-size: 0.875rem;
  color: #374151;
}
#awc-other-contact-section > .awc-contact-link + .awc-contact-link {
  margin-top: 0.5rem;
  display: block;
}
#awc-other-contact-section .awc-widget-icon-small,
#awc-other-contact-section span {
  vertical-align: middle;
}

.awc-contact-link {
  display: flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}
.awc-contact-link:hover {
  color: #2563eb;
}
.awc-contact-link svg.awc-widget-icon-small {
  height: 1rem;
  width: 1rem;
  margin-inline-end: 0.5rem;
}

/* AI Chat Section Styles */
#awc-ai-chat-section {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.awc-ai-chat-message-area {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0.5rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
  min-height: 9rem;
  background-color: #f9fafb;
  max-height: 18rem;
  overflow-y: auto;
  overflow-x: hidden;
}
.awc-ai-chat-message-area .awc-user-message,
.awc-ai-chat-message-area .awc-ai-message {
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  max-width: 85%;
  font-size: 0.875rem;
  line-height: 1.4;
  padding: 0.375rem 0.75rem;
  scroll-margin: 2.25rem;
}

.awc-ai-message *:first-child {
  margin-top: 0;
}
.awc-ai-message *:last-child {
  margin-bottom: 0;
}

.awc-ai-chat-message-area .awc-user-message {
  /* Background color and color will be set by inline style from PHP */
  margin-left: auto;
  text-align: right;
  position: relative;
  z-index: 1;
}
.awc-ai-chat-message-area .awc-user-message::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  opacity: 0.2;
}
.awc-ai-chat-message-area .awc-ai-message {
  background-color: #e5e7eb; /* gray-200 */
  color: #374151; /* gray-700 */
  margin-right: auto;
}

@keyframes awc-bounce {
  0%,
  100% {
    transform: translateY(-25%);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: none;
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

.awc-animate-bounce {
  animation: awc-bounce 1s infinite;
}

.awc-ai-chat-message-area .awc-ai-pending-message {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  width: fit-content;
  font-size: 0.375rem;
}
.awc-ai-chat-message-area .awc-ai-pending-message svg {
  width: 6px;
  height: 6px;
}
.awc-ai-chat-message-area .awc-ai-pending-message svg:nth-child(2) {
  animation-delay: 0.1s;
}
.awc-ai-chat-message-area .awc-ai-pending-message svg:nth-child(3) {
  animation-delay: 0.2s;
}

.awc-ai-chat-input-area {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
#awc-ai-chat-input {
  flex-grow: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  resize: none;
  min-height: 40px;
}
html[dir="rtl"] {
  #awc-ai-chat-input {
    text-align: right;
    direction: rtl;
  }
  #awc-ai-chat-input::placeholder {
    text-align: right;
  }
}
#awc-ai-chat-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}
#awc-ai-chat-send-button {
  padding: 0.5rem 1rem;
  color: white;
  font-weight: 600;
  border-radius: 0.375rem;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease-in-out;
  /* Background color set by inline style from PHP */
}
#awc-ai-chat-send-button[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}
html[dir="rtl"] #awc-ai-chat-send-button svg {
  transform: rotate(180deg);
}

#awc-ai-chat-send-button svg {
  width: 1rem;
}
.awc-ai-chat-status-text {
  /* Class for the p tag */
  font-size: 0.8rem;
  margin-top: 0.25rem;
  color: #6b7280; /* gray-500 */
  text-align: center;
  min-height: 1.2em;
}

.awc-ai-response-external-link {
  color: #3b82f6 !important;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.awc-ai-response-external-link:hover {
  text-decoration: underline;
  color: #2567d2 !important;
}

/* Ensure icons in toggle button switch correctly */
#awc-chat-toggle-button svg#awc-chat-icon {
  display: block;
}
#awc-chat-toggle-button svg#awc-close-icon {
  display: none;
}
#awc-chat-toggle-button svg#awc-chat-icon.awc-hidden {
  display: none !important;
}
#awc-chat-toggle-button svg#awc-close-icon.awc-hidden {
  display: none !important;
}
#awc-chat-toggle-button svg#awc-close-icon:not(.awc-hidden) {
  display: block !important;
}

/* Style for the Powered By Atira Chat */
.awc-powered-by {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border-top: 1px solid #e5e7eb;
  margin: -0.5rem;
  margin-top: 0.5rem;
}
.awc-powered-by span {
  color: #4a90e2;
}
.awc-powered-by a {
  color: #0fe1cf;
  text-decoration: none;
  transition: all 0.2s ease-in-out;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
.awc-powered-by a:hover {
  filter: brightness(0.9);
}
.awc-powered-by img {
  width: 20px;
  height: 20px;
}

@media (min-width: 640px) {
  #awc-chat-menu {
    width: 24rem;
  }
}
