/* Base styles for Site Assistant */
:root {
  --sa-primary: #0055aa;
  --sa-accent: #ffaa00;
}

/*
 * Dark mode styles
 *
 * When the sa-dark-mode class is present on the root element, we adjust
 * colours and backgrounds for improved contrast in low‑light environments.
 * Primary and accent colours are slightly adjusted to maintain sufficient
 * contrast. Components inherit from these variables automatically.
 */
.sa-dark-mode {
  --sa-primary: #004488; /* darker primary colour for dark theme */
  --sa-accent: #ffcc33;  /* brighter accent colour for dark theme */
}

/* Modal and bubble backgrounds for dark mode */
.sa-dark-mode .sa-modal {
  background-color: #222;
  border-color: #444;
  color: #eee;
}

.sa-dark-mode .sa-modal-header {
  background-color: var(--sa-primary);
  color: #fff;
}

.sa-dark-mode .sa-messages {
  background-color: #333;
}

.sa-dark-mode .sa-message {
  color: #eee;
}

.sa-dark-mode .sa-user {
  background-color: var(--sa-accent);
  color: #000;
}

.sa-dark-mode .sa-assistant {
  background-color: #444;
  color: #eee;
}

.sa-dark-mode .sa-input-wrapper {
  border-top: 1px solid #555;
}

.sa-dark-mode .sa-input {
  background-color: #333;
  color: #eee;
  border: none;
}

.sa-dark-mode .sa-send-btn {
  background-color: var(--sa-primary);
  color: #fff;
}

.sa-dark-mode .sa-chat-bubble {
  background-color: var(--sa-primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Responsive adjustments for small screens */
@media (max-width: 600px) {
  .sa-modal {
    width: 95%;
    left: 0.25rem;
    right: 0.25rem;
    bottom: 4rem;
    max-height: 70vh;
  }
  .sa-chat-bubble {
    bottom: 0.75rem;
    right: 0.75rem;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.2rem;
  }
  .sa-input {
    min-height: 2rem;
  }
  .sa-send-btn, .sa-record-btn {
    padding: 0 0.5rem;
    font-size: 0.85rem;
  }
}

.sa-chat-bubble {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background-color: var(--sa-primary);
  color: #fff;
  font-size: 1.5rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  z-index: 9999;
}

.sa-modal {
  position: fixed;
  bottom: 5rem;
  right: 1rem;
  /* Slightly wider modal to accommodate form fields comfortably */
  width: 24rem;
  max-height: 60vh;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 0.5rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10000;
}

.sa-hidden {
  display: none;
}

.sa-modal-header {
  background-color: var(--sa-primary);
  color: #fff;
  padding: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sa-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

/* Container for header controls (close & dark mode buttons) */
.sa-controls {
  display: flex;
  gap: 0.25rem;
}

/* Dark mode toggle button styling */
.sa-dark-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

/* Ensure dark toggle maintains contrast in dark mode */
.sa-dark-mode .sa-dark-toggle {
  color: #fff;
}

/* Clear chat button styling */
.sa-clear-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}
.sa-dark-mode .sa-clear-btn {
  color: #fff;
}

/*
 * Messages container
 *
 * Use a max-height to ensure that, regardless of the overall modal height, the
 * messages area will always allow vertical scrolling when the conversation
 * grows. We also explicitly set overflow-x to hidden to prevent horizontal
 * scrollbars from appearing and ensure the element can shrink within its
 * parent flex container by resetting min-height. Setting max-height to a
 * percentage of the viewport height guarantees a scroll bar appears on all
 * browsers, even if other CSS rules (or themes) override our .sa-hidden class.
 */
.sa-messages {
  flex: 1;
  /* Allow the messages area to shrink but not grow indefinitely */
  min-height: 0;
  /* Always allow vertical scrolling when content exceeds the max height */
  overflow-y: auto;
  /* Hide horizontal overflow */
  overflow-x: hidden;
  /* Limit the maximum height to 40% of the viewport; adjust if needed */
  max-height: 40vh;
  padding: 0.5rem;
  background-color: #f5f5f5;
}

/* Container for chat messages and input; uses flex column to allow messages to expand */
.sa-chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.sa-message {
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
  border-radius: 0.25rem;
  max-width: 90%;
  word-wrap: break-word;
  line-height: 1.4;
}

.sa-user {
  background-color: var(--sa-accent);
  color: #000;
  align-self: flex-end;
}

.sa-assistant {
  background-color: #e0e0e0;
  color: #000;
  align-self: flex-start;
}

.sa-input-wrapper {
  display: flex;
  border-top: 1px solid #ddd;
}

/* Textarea/input fields: allow them to grow but prevent shrinking */
.sa-input {
  flex: 1;
  border: none;
  padding: 0.5rem;
  resize: vertical;
  min-height: 3rem;
  outline: none;
}

.sa-send-btn {
  background-color: var(--sa-primary);
  border: none;
  color: #fff;
  padding: 0 1rem;
  cursor: pointer;
  /* Prevent shrinking when space is limited */
  flex-shrink: 0;
}

/* Voice recording button */
.sa-speak-btn {
  background-color: var(--sa-accent);
  border: none;
  color: #000;
  padding: 0 0.5rem;
  cursor: pointer;
  margin-left: 0.25rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Maintain contrast for speak button in dark mode */
.sa-dark-mode .sa-speak-btn {
  background-color: var(--sa-accent);
  color: #000;
}

/* Voice recording button (visible only in Leave Message mode) */
.sa-record-btn {
  background-color: var(--sa-accent);
  border: none;
  color: #000;
  padding: 0 0.5rem;
  cursor: pointer;
  margin-left: 0.25rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  /* Expand the record button to full width in leave mode so it aligns nicely with the send button */
  width: 100%;
}
/* Ensure record button maintains contrast in dark mode */
.sa-dark-mode .sa-record-btn {
  background-color: var(--sa-accent);
  color: #000;
}

/* Navigation tabs container */
.sa-nav {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ddd;
}

/* Tab buttons */
.sa-tab {
  flex: 1;
  border: none;
  background: #f5f5f5;
  padding: 0.5rem;
  cursor: pointer;
  text-align: center;
  font-weight: 600;
  color: #333;
}
.sa-dark-mode .sa-tab {
  background: #333;
  color: #eee;
}

/* Active tab indicator */
.sa-tab.sa-active {
  border-bottom: 2px solid var(--sa-primary);
}

/* Leave message form styling */
.sa-leave-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
}
/* Style inputs in the leave panel (name and email) */
.sa-leave-panel input.sa-input {
  width: 100%;
  height: 2.5rem;
  padding: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.sa-leave-send-btn {
  background-color: var(--sa-primary);
  border: none;
  color: #fff;
  padding: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  /* Expand the send button to full width for better alignment */
  width: 100%;
  text-align: center;
}
.sa-dark-mode .sa-leave-send-btn {
  background-color: var(--sa-primary);
  color: #fff;
}
