:root {
  --chat-button-size: 3.5rem;
  --chat-offset: 1.3rem;
  --chat-z-index: 1000;
}

body.chat-maximized {
  overflow: hidden !important;
}

body:has(.chat-button) .theme-back-to-top-button,
.chat-button {
  width: var(--chat-button-size);
  height: var(--chat-button-size);
  right: var(--chat-offset);
}

body:has(.chat-button) .theme-back-to-top-button {
  bottom: calc(var(--chat-button-size) + var(--chat-offset) * 2);
}

.chat-button {
  position: fixed;
  z-index: var(--chat-z-index);
  bottom: var(--chat-offset);
  padding: 0.5em;
  border-radius: 50%;
  background: var(--ifm-color-primary);
  color: var(--ifm-color-primary-contrast-background);
  border: none;
  cursor: pointer;
  box-shadow: rgba(0, 0, 0, 0.3) 0 0.5em 1em;
  transition: filter 0.25s;
  &:hover {
    background-color: var(--ifm-color-primary-dark);
  }
  &:active {
    transform: translateY(1px);
  }
}

.chat-popup {
  --chat-popup-padding: 0.75rem;
  position: fixed;
  z-index: var(--chat-z-index);
  display: flex;
  flex-direction: column;
  body.chat-button-hidden & {
    --chat-offset-bottom: var(--chat-offset);
  }
  body:not(.chat-button-hidden) & {
    --chat-offset-bottom: calc(var(--chat-button-size) + var(--chat-offset) * 2);
  }
  bottom: var(--chat-offset-bottom);
  right: var(--chat-offset);
  top: var(--chat-offset);
  width: 768px;
  max-width: calc(100vw - var(--chat-offset) * 2);
  border-radius: 0.375rem;
  overflow: hidden;
  background: var(--ifm-color-secondary-contrast-background);
  box-shadow: 0 0 0.375rem 0.25rem rgba(0, 0, 0, 0.1);
  transition: all 0.25s;
  transform-origin: bottom right;

  &[hidden] {
    visibility: hidden;
    opacity: 0;
    transform: scale(0.875);
  }

  body.chat-maximized & {
    inset: 0;
    width: initial;
    max-width: initial;
    border-radius: initial;
  }

  button,
  input {
    &:focus {
      outline: none;
    }
    &:focus-visible {
      outline: 1px auto;
    }
  }
}

.navbar--fixed-top:hover {
  &,
  .dropdown__menu {
    z-index: calc(var(--chat-z-index) + 1);
  }
}

.chat-popup-cursor-left {
  --offset: 425px;
  right: calc(var(--chat-offset) - var(--offset));
}

.chat-popup-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: var(--chat-popup-padding);
  background: var(--ifm-color-primary);
  color: var(--ifm-color-primary-contrast-background);
  font-weight: 500;

  > :first-child {
    flex: 1;
  }
}

.chat-popup-maximize,
.chat-popup-close {
  --size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--size);
  height: var(--size);
  margin: -0.25rem;
  padding: 0;
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: inherit;
  &:hover {
    opacity: 0.8;
  }
  &:active {
    transform: scale(0.9);
  }
}

.chat-popup-maximize {
  padding-top: 2px;
}

.chat-popup-log {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: var(--chat-popup-padding);
  width: var(--ifm-container-width-xl);
  max-width: 100%;
  align-self: center;
  padding: var(--chat-popup-padding) var(--chat-popup-padding)
    calc(var(--chat-popup-padding) + 1.25em);
  overflow: auto;
  overscroll-behavior: none;
}

.chat-popup-entry {
  --chat-popup-entry-padding: 0.625em 0.75em;
  align-self: start;
  padding: var(--chat-popup-entry-padding);
  border-radius: 0.5em;
  max-width: 100%;
}

.chat-popup-entry-query,
.chat-popup-entry-loading,
.chat-popup-entry-response,
.chat-popup-entry-not-found {
  color: var(--color);
  background: var(--background-color);
}

.chat-popup-entry-query {
  --color: var(--ifm-color-gray-100);
  --background-color: var(--ifm-color-gray-900);
  [data-theme='dark'] & {
    --color: var(--ifm-color-gray-900);
    --background-color: var(--ifm-color-gray-100);
  }
  align-self: end;
}

.chat-popup-entry-loading,
.chat-popup-entry-response,
.chat-popup-entry-not-found {
  --color: var(--ifm-color-gray-900);
  --background-color: var(--ifm-color-gray-200);
  [data-theme='dark'] & {
    --color: var(--ifm-color-gray-200);
    --background-color: var(--ifm-color-gray-900);
  }
}

.chat-popup-entry-loading {
  display: flex;
  align-items: center;
  justify-content: center;

  > svg {
    height: calc(var(--ifm-line-height-base) * 1em);
    margin: 0 0.25em;
  }
}

.chat-popup-entry-error {
  --background-color: var(--ifm-color-danger-darker);
  --color: var(--ifm-color-gray-100);
  display: flex;
  align-items: center;
  gap: 0.75em;
  background: var(--background-color);
  color: var(--color);
}

.chat-popup-entry-error-retry {
  margin: -0.375em;
  padding: 0.375em 0.5em;
  border: 0.5px solid var(--color);
  border-radius: 0.375rem;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-weight: 500;
  font-size: inherit;
  cursor: pointer;
  transition: all 0.25s;
  &:hover {
    background: var(--color);
    color: var(--background-color);
  }
}

.chat-popup-entry-response,
.chat-popup-entry-not-found {
  position: relative;
  margin-bottom: 36px;

  > :last-child,
  > :has(+ .chat-popup-entry-actions) {
    margin-bottom: 0;
  }

  code,
  pre {
    background: var(--ifm-color-gray-100);
  }

  code {
    color: var(--ifm-color-gray-900);
  }

  hr {
    margin-top: 0;
    margin-bottom: var(--ifm-paragraph-margin-bottom);
  }

  ol,
  ul {
    padding-left: calc(var(--ifm-list-left-padding) / 1.5);
    margin-bottom: var(--ifm-paragraph-margin-bottom);
  }

  pre {
    padding: var(--chat-popup-entry-padding);
    margin-bottom: var(--ifm-paragraph-margin-bottom);
    &:has(.hljs) {
      padding: 0;
    }
    &:not(:has(.hljs)) {
      white-space: pre-wrap;
    }
    overflow: auto;
  }

  th,
  td {
    padding: calc(var(--ifm-table-cell-padding) / 2) calc(var(--ifm-table-cell-padding) / 1.5);
  }
}

.chat-popup-entry-actions {
  display: flex;
  gap: 0.25em;
  position: absolute;
  margin: 1.125em 0 0;
  padding: 0;
  border: none;

  .chat-popup-entry-response:not(.chat-popup-entry-response-loaded) & {
    display: none;
  }

  > button {
    display: flex;
    align-items: center;
    justify-content: center;
    --size: 24px;
    width: var(--size);
    height: var(--size);
    padding: 0;
    background: none;
    border: none;
    &:hover {
      opacity: 0.625;
    }

    > svg {
      --size: 16px;
      width: var(--size);
      height: var(--size);
    }
    &.chat-popup-entry-actions-item-active > svg {
      fill: var(--ifm-color-primary);
      color: var(--ifm-color-primary-darkest);
    }
  }
  &:not([disabled]) > button {
    cursor: pointer;
  }
}

.chat-popup-footer {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  padding: var(--chat-popup-padding);
  border-top: 1px solid var(--ifm-color-secondary-dark);
}

.chat-popup-form {
  --chat-popup-control-padding-horizontal: 0.75em;
  --chat-popup-control-padding: 0.5em var(--chat-popup-control-padding-horizontal);
  display: flex;
  align-items: center;
  gap: var(--chat-popup-padding);
  position: relative;
}

.chat-popup-fieldset {
  display: flex;
  align-items: center;
  gap: var(--chat-popup-padding);
  flex: 1;
  margin: 0;
  padding: 0;
  border: none;
}

.chat-popup-directory,
.chat-popup-input,
.chat-popup-submit {
  border-radius: 0.375rem;
  font-family: inherit;
  background-color: white;
  color: var(--ifm-color-gray-900);
  [data-theme='dark'] &:not(.chat-popup-submit) {
    background-color: var(--ifm-color-gray-900);
    color: var(--ifm-color-gray-100);
  }
}

.chat-popup-directory {
  position: absolute;
  right: 0;
  top: calc(var(--chat-popup-padding) * -2);
  transform: translateY(-100%);
  font-size: smaller;
}

.chat-popup-directory {
  padding: var(--chat-popup-control-padding);
  border: 1px solid var(--ifm-color-secondary-dark);
  appearance: none;
  padding-right: 24px;
  background-position: right 6px center;
  background-repeat: no-repeat;
  background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMWVtIiBoZWlnaHQ9IjFlbSIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSIjMzQzNTM4IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMTIgMTIuNTIgNy43OTIgOC4zMTQgNi4yMDggOS44OTYgMTIgMTUuNjg4bDUuNzkyLTUuNzkyLTEuNTg0LTEuNTg0eiI+PC9wYXRoPjwvc3ZnPg==');
  [data-theme='dark'] & {
    background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMWVtIiBoZWlnaHQ9IjFlbSIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSIjZjVmNmY3IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMTIgMTIuNTIgNy43OTIgOC4zMTQgNi4yMDggOS44OTYgMTIgMTUuNjg4bDUuNzkyLTUuNzkyLTEuNTg0LTEuNTg0eiI+PC9wYXRoPjwvc3ZnPg==');
  }
}

.chat-popup-input-container {
  display: flex;
  flex: 1;
  position: relative;
  --voice-button-size: 32px;

  &:has(.chat-popup-voice:not([hidden])) .chat-popup-input {
    padding-right: calc(var(--chat-popup-control-padding-horizontal) + var(--voice-button-size));
  }
}

.chat-popup-input {
  flex: 1;
  padding: var(--chat-popup-control-padding);
  border: 1px solid var(--ifm-color-secondary-dark);
  font-size: inherit;
}

.chat-popup-voice {
  position: absolute;
  inset: 0 2px 0 auto;
  width: var(--voice-button-size);
  height: var(--voice-button-size);
  margin: auto;
  border: none;
  background: no-repeat center / 22px transparent
    url('data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjEyOCIgd2lkdGg9IjEyOCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8cGF0aCBkPSJNODcuNCA2NC40OWExOS44IDE5LjggMCAwIDEtMTkuOCAxOS44SDYwLjRhMTkuOCAxOS44IDAgMCAxLTE5Ljc4LTE5Ljh2LTQzLjdBMTkuNzkgMTkuNzkgMCAwIDEgNjAuMzkgMWg3LjIxYzEwLjk0IDAgMTkuOCA4Ljg2IDE5LjggMTkuNzl2NDMuN3oiIGZpbGw9IiMyMzIzMjMiLz4KICA8cGF0aCBkPSJNOTkuOTQgMzguNTRhNi4wNyA2LjA3IDAgMCAwLTYuMDcgNi4wN3YyNS4yNmMwIDIuNzYtLjYyIDUuMzYtMS43OSA3Ljc5YTIxLjg1IDIxLjg1IDAgMCAxLTguNjQgOS4xNyAyNy4yIDI3LjIgMCAwIDEtMTMuOSAzLjcySDU4LjQ1YTI2LjQ2IDI2LjQ2IDAgMCAxLTE3LjQ5LTYuMzIgMjAuODQgMjAuODQgMCAwIDEtNS4wNS02LjU4IDE3Ljg0IDE3Ljg0IDAgMCAxLTEuOC03Ljc4VjQ0LjYxYTYuMDcgNi4wNyAwIDEgMC0xMi4xNCAwdjI1LjI2YzAgNC42MyAxLjA4IDkuMDcgMyAxMy4wNWEzMy45OCAzMy45OCAwIDAgMCAxMy4zOCAxNC4zNWM1LjIzIDMuMTEgMTEuMzggNSAxNy45NSA1LjM1djE4Ljg4YTUuNSA1LjUgMCAwIDAgNS41MSA1LjVoNC4zNmE1LjUyIDUuNTIgMCAwIDAgNS41Mi01LjV2LTE4Ljg3YzktLjQ4IDE3LjItMy44NyAyMy4zNi05LjI4YTMyLjk0IDMyLjk0IDAgMCAwIDcuOTctMTAuNDMgMzAuMDIgMzAuMDIgMCAwIDAgMi45OS0xMy4wNVY0NC42MWE2LjA3IDYuMDcgMCAwIDAtNi4wOC02LjA3eiIgZmlsbD0iIzIzMjMyMyIvPgo8L3N2Zz4K');
  cursor: pointer;
  fieldset:not([disabled]) &:hover {
    opacity: 0.75;
  }
}

@keyframes chat-popup-voice-active-pulsate {
  50% {
    box-shadow: 0 0 0 5px var(--color);
  }
}

.chat-popup-voice-active {
  --color: #f08080;
  background-color: var(--color);
  border-radius: 50%;
  animation: chat-popup-voice-active-pulsate 2s ease-in-out infinite;
}

.chat-popup-submit {
  padding: var(--chat-popup-control-padding);
  border: none;
  background: var(--ifm-color-primary);
  color: var(--ifm-color-primary-contrast-background);
  font-size: inherit;
  font-weight: 500;
  transition: opacity 0.25s;
  &:active {
    transform: scale(0.98);
  }
  fieldset[disabled] & {
    opacity: 0.625;
  }
  fieldset:not([disabled]) & {
    cursor: pointer;
    &:hover {
      background-color: var(--ifm-color-primary-dark);
    }
  }
}

.chat-popup-stop {
  --size: 32px;
  --color: #f08080;
  &:not([hidden]) {
    display: flex;
  }
  align-items: center;
  justify-content: center;
  width: var(--size);
  height: var(--size);
  border: 3px solid;
  border-radius: 50%;
  background: transparent;
  color: var(--color);
  cursor: pointer;
  &:hover {
    opacity: 0.75;
  }

  &::after {
    content: '';
    --size: 12px;
    width: var(--size);
    height: var(--size);
    border-radius: 2px;
    background: var(--color);
  }
}

.chat-popup-disclaimer {
  text-align: center;
  line-height: 1.125;
  font-size: 80%;
  text-wrap: balance;
  color: var(--ifm-font-color-secondary);
}

.chat-citation {
  --size: 1.375em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--size);
  height: var(--size);
  padding: 0 0.125em;
  border: 1px solid var(--color);
  border-radius: 50%;
  font-weight: 500;
  font-family: inherit;
  font-size: 0.9em;
  color: var(--color);
  cursor: pointer;
  transition: all 0.25s;
  &:hover {
    background: var(--color);
    color: var(--background-color);
    text-decoration: none;
  }
}

.chat-prompts {
  list-style: none;
  padding-left: 0 !important;

  li:not(:last-child) {
    margin-bottom: calc(var(--ifm-paragraph-margin-bottom) / 1.5);
  }

  button {
    --vertical-padding: 0.125em;
    padding: var(--vertical-padding) 0.625em;
    border: 0.5px solid var(--color);
    line-height: inherit;
    font-family: inherit;
    font-size: 0.9rem;
    text-align: initial;
    border-radius: calc((var(--vertical-padding) * 2 + var(--ifm-line-height-base) * 1em) / 2);
    background: none;
    cursor: pointer;
    transition: all 0.25s;
    &:hover {
      background-color: var(--color);
      color: var(--background-color);
    }
    &:active {
      opacity: 0.625;
    }
  }
}

.tippy-box {
  --color: var(--ifm-color-gray-900);
  background-color: var(--color);
  .tippy-arrow {
    color: var(--color);
  }
}
