/* © 2025 Authenti. All Rights Reserved. */

/* public/chat-widget.css */
body#widget-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #ffffff;
  font-family: sans-serif;
  padding: 20px;
  --widget-accent-color: #bd7bff;
}

.chat-widget-container {
  width: 100%;
  height: 590px;
  max-width: 350px;
  max-height: 90vh;
  border: 0px solid var(--widget-accent-color);
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: #fff;
  transition: height 0.3s ease;
  position: relative; /* z-index requires a position property to work */
  z-index: 2000; /* Higher than the button's z-index of 1000 */
}

/* MODIFICATION: Grouped online and offline states to have the same height */
.chat-widget-container.online-state,
.chat-widget-container.offline-state {
  height: 500px;
}
.chat-widget-container.form-mode-active {
  min-height: 590px;
  height: auto;
}
.chat-widget-container.form-sent-state {
  height: 250px;
}

.chat-widget-container.form-sent-state .chat-messages,
.chat-widget-container.form-sent-state .chat-input-area,
.chat-widget-container.form-sent-state #widgetTypingIndicatorContainer {
  display: none;
}

.chat-header {
  background: radial-gradient(
    circle at top right,
    color-mix(in srgb, var(--widget-accent-color) 60%, white 40%),
    var(--widget-accent-color) 70%
  );
  padding: 9px 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.chat-header .profile-pic {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.chat-header .owner-info {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  color: white;
}
.chat-header .owner-name {
  font-weight: 600;
  font-size: 0.95em;
  display: flex;
  align-items: center;
  gap: 6px;
}
#companyNameWidget {
  font-size: 0.8em;
  opacity: 0.9;
  font-weight: normal;
  margin-bottom: 2px;
}
.chat-header .owner-status {
  font-size: 0.75em;
  opacity: 0.8;
}
.owner-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.owner-status-dot.online {
  background-color: #34a853;
}
.owner-status-dot.offline {
  background-color: #ffab91;
}

.chat-messages {
  flex-grow: 1;
  padding: 15px;
  overflow-y: auto;
  background-color: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

/* --- State Visibility Rules --- */
.offline-prompt-area,
.offline-contact-form {
  display: none;
}
/* Hides the contact button when offline and in FAQ-only mode */
.chat-widget-container.offline-state.faq-only-offline .offline-prompt-area {
  display: none;
}

.chat-widget-container.offline-state .chat-input-area {
  display: none;
}
.chat-widget-container.offline-state .offline-prompt-area {
  display: flex;
}
.chat-widget-container.form-mode-active .chat-messages,
.chat-widget-container.form-mode-active #widgetTypingIndicatorContainer,
.chat-widget-container.form-mode-active .chat-input-area,
.chat-widget-container.form-mode-active .offline-prompt-area {
  display: none;
}
.chat-widget-container.form-mode-active .offline-contact-form {
  display: flex;
}

.chat-message {
  padding: 8px 12px;
  border-radius: 12px;
  word-wrap: break-word;
  font-size: 0.9em;
  line-height: 1.4;
}

.message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}
.message-wrapper.customer {
  align-self: flex-end;
  align-items: flex-end;
}
.message-wrapper.agent {
  align-self: flex-start;
  align-items: flex-start;
}
.message-wrapper.system {
  align-self: center;
  align-items: center;
}

.message-timestamp-outer {
  font-size: 0.7em;
  color: #888;
  margin-top: 2px;
  padding: 0 5px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.message-wrapper:hover .message-timestamp-outer {
  opacity: 1;
}

.message-wrapper.customer .chat-message {
  background-color: color-mix(
    in srgb,
    var(--widget-accent-color) 90%,
    white 10%
  );
  color: white;
  border-bottom-right-radius: 4px;
}

.message-wrapper.agent .chat-message {
  background-color: #f8f8fa;
  color: #444746;
  border-bottom-left-radius: 4px;
}

.message-wrapper.system .chat-message {
  background-color: transparent;
  color: #5f6368;
  font-style: italic;
  font-size: 0.8em;
  text-align: center;
}

.message-timestamp-outer {
  font-size: 0.7em;
  color: #888;
  margin-top: 2px;
  padding: 0 5px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.message-wrapper:hover .message-timestamp-outer {
  opacity: 1;
}

.chat-message a {
  color: #007bff;
  text-decoration: underline;
}

#widgetTypingIndicatorContainer {
  height: 20px;
  padding: 0 15px 2px 15px;
  box-sizing: border-box;
  background-color: #ffffff;
  flex-shrink: 0;
}
.typing-indicator {
  font-size: 0.8em;
  color: #5f6368;
  font-style: italic;
  height: 100%;
  display: flex;
  align-items: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}
.typing-indicator.active {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.3s ease;
}
.typing-indicator-text {
  margin-right: 3px;
}
.typing-ellipsis::after {
  content: "...";
  display: inline-block;
  animation: typing-ellipsis-animation 1.5s infinite;
  width: 1.2em;
  text-align: left;
  vertical-align: bottom;
}
@keyframes typing-ellipsis-animation {
  0% {
    content: ".";
  }
  33% {
    content: "..";
  }
  66% {
    content: "...";
  }
  100% {
    content: ".";
  }
}

.chat-input-area {
  display: flex;
  padding: 10px 15px 5px 15px;
  background-color: #ffffff;
  align-items: center;
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex-grow: 1;
  padding: 8px 12px;
  border: 1px solid #d1d1d1;
  border-radius: 20px;
  outline: none;
  font-size: 16px;
  margin-right: 8px;
  background-color: #ffffff;
  resize: none;
  font-family: sans-serif;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: hidden; /* This prevents the scrollbar from appearing on the first line */
  height: 40px; /* This sets the consistent, fixed initial height */
  transition: height 0.2s ease;
  color: #202124;
  box-sizing: border-box !important; /* This ensures padding is included in the height calculation */
}
.chat-input-area textarea:focus {
  border-color: var(--widget-accent-color);
  box-shadow: 0 0 0 2px
    color-mix(in srgb, var(--widget-accent-color) 25%, transparent);
}

.chat-input-area button {
  background-color: var(--widget-accent-color);
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
  transition: background-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.chat-input-area button span {
  display: inline-block;
  transition: transform 0.4s cubic-bezier(0.76, 0, 0.24, 1);
}

#sendMessageBtn:hover span,
#sendMessageBtn.typing-active span {
  transform: translateX(200%);
}

#sendMessageBtn::after {
  content: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><path d='M10 50 H85 M60 25 L85 50 L60 75' stroke='%23ffffff' stroke-width='12' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  width: 22px;
  height: 22px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateX(-40px);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.76, 0, 0.24, 1),
    opacity 0.4s cubic-bezier(0.76, 0, 0.24, 1);
}

#sendMessageBtn:hover::after,
#sendMessageBtn.typing-active::after {
  transform: translate(-50%, -50%) translateX(0);
  opacity: 1;
}

.chat-input-area button:disabled {
  background-color: var(--widget-accent-color);
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-input-area button:disabled:hover span,
.chat-input-area button:disabled.typing-active span {
  transform: translateX(0);
}

.chat-input-area button:disabled:hover::after,
.chat-input-area button:disabled.typing-active::after {
  left: -40px;
}

#attachFileBtn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 5px 0 0px;
  color: #5f6368;
  opacity: 0.7;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
#attachFileBtn:hover {
  opacity: 1;
}

.chat-attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: #f1f3f4;
  padding: 8px 12px;
  border-radius: 12px;
}
.chat-attachment i {
  /* This requires Font Awesome, which is not loaded on this page by default */
  color: #5f6368;
  font-family: "Font Awesome 5 Free"; /* Basic fallback */
  font-weight: 900;
  content: "\f15b"; /* Unicode for file-alt icon */
}
.attachment-info {
  display: flex;
  flex-direction: column;
}
.attachment-info a {
  color: var(--widget-accent-color);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9em;
}
.attachment-info a:hover {
  text-decoration: underline;
}
.attachment-info .file-size {
  font-size: 0.75em;
  color: #5f6368;
}

.offline-contact-form {
  padding: 15px 20px 0px 20px;
  background-color: #ffffff;
  flex-direction: column;
  gap: 8px;
  transition: opacity 0.3s ease;
  flex-grow: 1;
  overflow-y: auto;
  min-height: 0;
}
.offline-contact-form p {
  font-size: 0.85em;
  color: #333;
  margin-top: 0;
  margin-bottom: 10px;
  line-height: 1.4;
}
.offline-contact-form label {
  font-size: 0.8em;
  font-weight: 500;
  color: #333;
  margin-bottom: 2px;
}
.offline-contact-form input[type="text"],
.offline-contact-form input[type="email"],
.offline-contact-form input[type="tel"],
.offline-contact-form textarea {
  padding: 8px 10px;
  border: 1px solid #ccc;
  /* This remains 10px as requested */
  border-radius: 10px;
  font-size: 0.85em;
  width: 100%;
  box-sizing: border-box;
  background-color: #ffffff;
}
.offline-contact-form textarea {
  resize: vertical;
  min-height: 60px;
}
.offline-contact-form button {
  background-color: var(--widget-accent-color);
  color: white;
  padding: 10px 15px;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
  margin-top: 10px;
  transition: background-color 0.2s ease;
}
.offline-contact-form button:hover {
  filter: brightness(0.9);
}
.offline-contact-form button:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
}

#backToWebsiteBtn {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 1000;
  background-color: white;
  color: var(--widget-accent-color);
  padding: 8px 16px;
  border-radius: 20px;
  text-decoration: none;
  font-family: sans-serif;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease, filter 0.2s ease;
}

#backToWebsiteBtn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.widget-footer {
  background-color: #ffffff;
  padding: 5px 15px 5px 15px;
  text-align: center;
  flex-shrink: 0;
}

.widget-footer a {
  font-size: 0.75em;
  color: #888888;
  text-decoration: none;
  margin: 0 5px;
}

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

.widget-footer span {
  display: none;
}

.faq-options-container {
  padding: 5px 15px 10px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  background-color: #ffffff;
}

.faq-option-btn {
  background-color: #eaf2fe;
  border: 1px solid #d6e0f0;
  color: #0b57d0;
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.8em;
  font-weight: 500;
  text-align: left;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  max-width: 85%;
  font-family: sans-serif;
}

.faq-option-btn:hover {
  background-color: #e5e5e5;
  border-color: #d5d5d5;
}

.offline-prompt-area {
  padding: 15px;
  background-color: #ffffff;
  flex-shrink: 0;
}

.offline-prompt-area button {
  background-color: var(--widget-accent-color);
  color: white;
  padding: 10px 0px;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
  transition: background-color 0.2s ease;
  width: 100%;
}

.offline-prompt-area button:hover {
  filter: brightness(0.9);
}

.offline-greeting {
  display: none;
  padding: 15px 20px 0;
  font-size: 0.85em;
  color: #333;
  line-height: 1.4;
  text-align: left;
  background-color: #fff;
  flex-shrink: 0;
}

.chat-widget-container.offline-state .offline-greeting {
  display: block;
}

/* ==========================================================================
   MODIFICATION: Updated Mobile Responsive Styles
   ========================================================================== */
@media (max-width: 768px) {
  body#widget-page {
    padding: 0;
    background-color: #e5e5e5;
  }

  .chat-widget-container {
    position: fixed;
    top: 10px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  .chat-widget-container.online-state,
  .chat-widget-container.offline-state,
  .chat-widget-container.form-mode-active,
  .chat-widget-container.form-sent-state {
    height: auto;
  }

  #backToWebsiteBtn {
    display: none;
  }
}

/* © 2025 Authenti. All Rights Reserved. */
