@import url("https://fonts.cdnfonts.com/css/pf-square-sans-pro");

:root {
  /* Brand colors */
  --esf-chat-dark-blue: #124261;
  --esf-chat-blue: #bfdde3;
  --esf-chat-light-blue: #e5f3f5;

  /* Semantic colors */
  --esf-chat-success: #99d161;
  --esf-chat-warning: #edb95e;
  --esf-chat-error: #e23636;
  --esf-chat-info: #2d99af;

  /* Complementary colors */
  --esf-chat-green: #b7cf83;

  /* Neutral colors */
  --esf-chat-white: #ffffff;
  --esf-chat-light-gray: #f8f7f7;
  --esf-chat-gray: #d3d3d3;
  --esf-chat-dark-gray: #6e6e6e;

  --esf-chat-window-bg: var(--esf-chat-white);
  --esf-chat-window-header-bg: var(--esf-chat-green);
  --esf-chat-window-header-border: var(--esf-chat-light-gray);
  --esf-chat-window-header-shadow: rgba(129, 129, 129, 0.25);
  --esf-chat-shadow: rgba(0, 0, 0, 0.1);
  --esf-chat-text-primary: var(--esf-chat-dark-blue);
  --esf-chat-text-secondary: var(--esf-chat-dark-gray);
  --esf-chat-input-border-light: var(--esf-chat-gray);
  --esf-chat-input-border-dark: var(--esf-chat-dark-blue);
  --esf-chat-accent: #2e99af;
  --esf-chat-user-message-bg: var(--esf-chat-white);
  --esf-chat-user-message-border: var(--esf-chat-blue);
  --esf-chat-user-message-shadow: rgba(144, 144, 144, 0.25);
  --esf-chat-button-disabled: #57575d;

  --esf-chat-font-family: "PF Square Sans Pro", Helvetica, Arial, sans-serif;
  --esf-chat-font-size: 20px;
}

.esf-chat-agent-window {
  position: fixed;
  bottom: 20px;
  right: 20px;
  margin-left: 20px;
  width: 410px;
  height: 600px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  background: var(--esf-chat-window-bg);
  font-size: var(--esf-chat-font-size);
  box-shadow: 0 2px 10px var(--esf-chat-shadow);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--esf-chat-text-primary);
  z-index: 100000;
  font-family: var(--esf-chat-font-family), sans-serif;

  transition:
    width 280ms cubic-bezier(0.2, 0.7, 0.2, 1),
    height 280ms cubic-bezier(0.2, 0.7, 0.2, 1),
    border-radius 280ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.esf-chat-agent-window.esf-chat-agent-expanded {
  width: 1280px;
  height: 1280px;
  border-radius: 16px;
}

/** Media query for smaller screens */
@media (max-width: 500px) {
  .esf-chat-agent-window {
    width: 100%;
    height: 100%;
    max-height: 100%;
    max-width: 100%;
    border-radius: 0;
    bottom: 0;
    right: 0;
    margin: 0;
    /* Ensure the chat window is above WP admin bar */
    z-index: 100000;
  }

  .esf-chat-open-button {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
  }

  #esf-chat-agent-expand {
    display: none;
  }
}

.esf-chat-agent-window.esf-chat-agent-collapsed {
  height: auto;
}

.esf-chat-agent-window.esf-chat-agent-collapsed .esf-chat-agent-content,
.esf-chat-agent-window.esf-chat-agent-collapsed .esf-chat-agent-footer,
.esf-chat-agent-window.esf-chat-agent-collapsed .esf-chat-agent-header-buttons {
  display: none;
}

.esf-chat-agent-window.esf-chat-agent-collapsed .esf-chat-agent-header {
  cursor: pointer;
}

.esf-chat-open-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--esf-chat-green);
  box-shadow: 0 2px 10px var(--esf-chat-shadow);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/**
 * **********************
 * Chat Agent Header
 * **********************
 */
.esf-chat-agent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--esf-chat-window-header-bg);
  padding: 18px 24px;
  border-bottom: 1px solid var(--esf-chat-window-header-border);
  box-shadow: 0 2px 5px 0 var(--esf-chat-window-header-shadow);
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.esf-chat-agent-header h2 {
  margin: 0;
  font-size: 1.4em;
}

.esf-chat-agent-header-buttons {
  display: flex;
  gap: 8px;
}

.esf-chat-agent-header button {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  width: 30px;
  height: 30px;
}

svg.esf-chat-agent-expand-icon .arrow-tr,
svg.esf-chat-agent-expand-icon .arrow-bl {
  transition: transform 450ms linear;
  transform-origin: center;
  transform-box: fill-box;
  transform: rotate(0deg);
}

.esf-chat-agent-expanded svg.esf-chat-agent-expand-icon .arrow-tr {
  transform: rotate(-180deg);
}
.esf-chat-agent-expanded svg.esf-chat-agent-expand-icon .arrow-bl {
  transform: rotate(180deg);
}

/**
 * **********************
 * Chat Agent Content
 * **********************
 */

.esf-chat-content-wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-height: 0;
  position: relative;
}

.esf-chat-agent-content-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: none;
}

.esf-chat-agent-content {
  display: flex;
  flex-grow: 1;
  overflow-y: auto;
  min-height: 0;
  flex-direction: column;
}

.esf-chat-overlay-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 24px;
  background: var(--esf-chat-window-bg);
}

.esf-chat-overlay-content {
  text-align: center;
  width: 100%;
}

.esf-chat-overlay-button {
  width: 100%;
  text-align: center;
  padding: 12px 20px;
  border-radius: 4px;
}

.esf-chat-overlay-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.esf-chat-overlay-button-primary {
  background: var(--esf-chat-dark-blue);
  color: var(--esf-chat-window-bg);
  border: none;
  cursor: pointer;
  margin-top: 16px;
}

.esf-chat-overlay-button-secondary {
  background: transparent;
  color: var(--esf-chat-dark-blue);
  border: none;
  cursor: pointer;
  margin-top: 16px;
}

.esf-chat-agent-messages {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.esf-chat-agent-messages > * {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
}

.esf-chat-agent-content p:last-child {
  margin-bottom: 0;
}

.esf-chat-message {
  white-space: normal;
}

.esf-chat-message-sources {
  gap: 5px;
  display: flex;
  flex-wrap: wrap;
}

.esf-chat-message-sources a {
  display: inline-block;
  color: var(--esf-chat-text-primary);
  background: var(--esf-chat-light-blue);
  padding: 0 12px;
  font-size: 0.8em;
  text-decoration: none;
  border-radius: 20px;
}

.esf-chat-message-sources a:hover {
  background: var(--esf-chat-blue);
  text-decoration: none;
}

.esf-chat-message-follow-ups,
.esf-chat-message-redirect {
  margin-top: 8px;
}

.esf-chat-message-follow-ups {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.esf-chat-message-follow-ups button {
  appearance: none;
  border: 1px solid var(--esf-chat-light-blue);
  border-radius: 20px;
  background: #fff;
  color: var(--esf-chat-text-primary);
  cursor: pointer;
  font: inherit;
  font-size: 0.85em;
  padding: 6px 12px;
}

.esf-chat-message-follow-ups button:hover {
  background: var(--esf-chat-light-blue);
}

.esf-chat-message-redirect a {
  color: var(--esf-chat-blue);
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

.esf-chat-agent-response {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: 1rem;
}

.esf-chat-agent-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.esf-chat-agent-info .esf-chat-agent-name {
  font-weight: 500;
}

.esf-chat-agent-avatar {
  position: relative;
  top: -2px;
}

.esf-chat-agent-avatar-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--esf-chat-accent);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.esf-chat-user {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  padding: 1rem;
}

.esf-chat-user-message {
  display: flex;
  max-width: 80%;
  border-radius: 8px 8px 0 8px;
  border: 1px solid var(--esf-chat-user-message-border);
  padding: 8px 16px;
  background: var(--esf-chat-user-message-bg);
}

/**
 * **********************
 * Chat Agent Feedback
 * **********************
 */

.esf-chat-feedback-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.esf-chat-feedback-score {
  display: flex;
  align-items: center;
  justify-content: center;
}

.esf-chat-feedback-score .esf-chat-feedback-score-option label {
  display: inline-block;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  padding: 10px;
  border-radius: 4px;
}

.esf-chat-feedback-score .esf-chat-feedback-score-option label:hover {
  background: var(--esf-chat-light-blue);
}

.esf-chat-feedback-score .esf-chat-feedback-score-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.esf-chat-feedback-score .esf-chat-feedback-score-option input:checked + label {
  background: var(--esf-chat-light-blue);
}

.esf-chat-feedback-comment textarea {
  width: 100%;
  padding: 16px;
  border: 1px solid var(--esf-chat-input-border-light);
  border-radius: 4px;
  resize: none;
  color: var(--esf-chat-text-primary);
  line-height: 1.4;
  min-height: 60px;
}

/**
 * **********************
 * Chat Agent Footer
 * **********************
 */

.esf-chat-agent-footer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
  align-items: center;
  padding: 24px 24px 0 24px;
  gap: 0.2rem;
}

.esf-chat-agent-input-container {
  display: flex;
  width: 100%;
  flex-shrink: 0;
  align-items: stretch;
  gap: 0.2rem;
}

.esf-chat-agent-footer .esf-chat-agent-disclaimer {
  font-size: 0.65em;
  color: var(--esf-chat-text-secondary);
  cursor: default;
  margin-bottom: 8px;
  text-align: center;
}

.esf-chat-agent-footer textarea {
  flex: 1;
  padding: 16px;
  border: 1px solid var(--esf-chat-input-border-light);
  border-radius: 0.2rem;
  resize: none;
  font-family: inherit;
  font-size: inherit;
  color: var(--esf-chat-text-primary);
  line-height: 1.4;
  height: calc(1.4em + 32px);
  max-height: calc(1.4em * 4 + 32px);
  overflow-y: hidden;
  transition: height 0.2s ease;
}

.esf-chat-agent-footer textarea:focus {
  border: 1px solid var(--esf-chat-input-border-dark);
  outline: none;
}

button.esf-chat-agent-send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--esf-chat-text-primary);
  color: var(--esf-chat-window-bg);
  border: none;
  cursor: pointer;
  border-radius: 0.2rem;
  padding: 0 10px;
  width: 60px;
  height: 60px;
}

button.esf-chat-agent-send-button:disabled {
  display: none;
  background: var(--esf-chat-button-disabled);
}

/**
 * **********************
 * Loading Spinner
 * **********************
 */
.esf-spinner {
  margin: 0 24px;
}

.esf-spinner > div {
  width: 5px;
  height: 5px;
  margin-left: 3px;
  background-color: var(--esf-chat-text-primary);

  border-radius: 100%;
  display: inline-block;
  -webkit-animation: esf-bounce-delay 1.4s infinite ease-in-out both;
  animation: esf-bounce-delay 1.4s infinite ease-in-out both;
}

.esf-spinner .esf-bounce1 {
  -webkit-animation-delay: -0.32s;
  animation-delay: -0.32s;
}

.esf-spinner .esf-bounce2 {
  -webkit-animation-delay: -0.16s;
  animation-delay: -0.16s;
}

@-webkit-keyframes esf-bounce-delay {
  0%,
  80%,
  100% {
    -webkit-transform: scale(0);
  }
  40% {
    -webkit-transform: scale(1);
  }
}

@keyframes esf-bounce-delay {
  0%,
  80%,
  100% {
    -webkit-transform: scale(0);
    transform: scale(0);
  }
  40% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }
}
